VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbGyroidThirdOrderLong.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34
36
37#ifdef VF_BOOST
38
40
43
44#include <boost/math/tools/roots.hpp>
45
46
47using namespace std;
48using boost::math::tools::bisect;
49
50// Konstruktor
51GbGyroidThirdOrderLong::GbGyroidThirdOrderLong() //: GbObject3D()
52{
53
54}
55/*=======================================================*/
56// Konstruktor
57GbGyroidThirdOrderLong::GbGyroidThirdOrderLong(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b, const double& edgeLength, const double& dx, const double& thickness) :GbObject3D()
58{
59 this->p1 = new GbPoint3D(x1a, x2a, x3a);
60 this->p2 = new GbPoint3D(x1b, x2b, x3b);
61 this->p1->addObserver(this);
62 this->p2->addObserver(this);
63
64 this->p3 = new GbPoint3D(x1a, x2a, x3a);
65 this->p4 = new GbPoint3D(x1b, x2b, x3b);
66 this->p3->addObserver(this);
67 this->p4->addObserver(this);
68
69 this->edgeLength = edgeLength;
70 this->dx = dx;
71 this->thickness = thickness;
72}
73/*=======================================================*/
74GbGyroidThirdOrderLong::GbGyroidThirdOrderLong(GbGyroidThirdOrderLong * imp)
75{
76}
77/*=======================================================*/
78// Destruktor
79GbGyroidThirdOrderLong::~GbGyroidThirdOrderLong()
80{
81 if (this->p1)
82 this->p1->removeObserver(this);
83 if (this->p2)
84 this->p2->removeObserver(this);
85 if (this->p3)
86 this->p3->removeObserver(this);
87 if (this->p4)
88 this->p4->removeObserver(this);
89}
90/*=======================================================*/
92 bool operator() (double min, double max) {
93 return abs(min - max) <= 10e-10;
94 }
95};
96/*============================================M-===========*/
98 double x, y, z;
99 double dir1, dir2, dir3, L;
100 double operator() (double q) {
101 return sin(2.*M_PI / L*(x + q*dir1))*cos(2.*M_PI / L*(y + q*dir2)) + sin(2.*M_PI / L*(y + q*dir2))*cos(2.*M_PI / L*(z + q*dir3)) + sin(2.*M_PI / L*(z + q*dir3))*cos(2.*M_PI / L*(x + q*dir1));
102 }
103};
104/*=======================================================*/
106 double x, y, z;
107 double dir1, dir2, dir3, L;
108 double h;
109
110 double t17, t3, t2, t18, t20, t8, t13, t5, t9, t6, t11, t14;
112
114 double T1, T2, T3, T4, T5, T6, T7, T8, T9, Gyroidh;
115
116 double operator() (double q) {
117 //sins and cosines combinations
118 t2 = sin((2. * M_PI*(x+q*dir1)) / L)*sin((2. * M_PI*(y+q*dir2)) / L);
119 t3 = sin((2. * M_PI*(x+q*dir1)) / L)*sin((2. * M_PI*(z+q*dir3)) / L);
120 t5 = cos((2. * M_PI*(y+q*dir2)) / L)*sin((2. * M_PI*(x+q*dir1)) / L);
121 t6 = cos((2. * M_PI*(z+q*dir3)) / L)*sin((2. * M_PI*(x+q*dir1)) / L);
122 t8 = sin((2. * M_PI*(y+q*dir2)) / L)*sin((2. * M_PI*(z+q*dir3)) / L);
123 t9 = cos((2. * M_PI*(x+q*dir1)) / L)*sin((2. * M_PI*(y+q*dir2)) / L);
124 t11 = cos((2. * M_PI*(z+q*dir3)) / L)*sin((2. * M_PI*(y+q*dir2)) / L);
125 t13 = cos((2. * M_PI*(x+q*dir1)) / L)*sin((2. * M_PI*(z+q*dir3)) / L);
126 t14 = cos((2. * M_PI*(y+q*dir2)) / L)*sin((2. * M_PI*(z+q*dir3)) / L);
127 t17 = cos((2. * M_PI*(x+q*dir1)) / L)*cos((2. * M_PI*(y+q*dir2)) / L);
128 t18 = cos((2. * M_PI*(x+q*dir1)) / L)*cos((2. * M_PI*(z+q*dir3)) / L);
129 t20 = cos((2. * M_PI*(y+q*dir2)) / L)*cos((2. * M_PI*(z+q*dir3)) / L);
130
131 //Gyroid third order derivatives
132 f300 = (8. * pow(M_PI, 3.)*(-t17 + t3)) / pow(L, 3.);
133 f210 = (8. * pow(M_PI, 3.)*t2) / pow(L, 3.);
134 f201 = (-8. * pow(M_PI, 3.)*t18) / pow(L, 3.);
135 f120 = (-8. * pow(M_PI, 3.)*t17) / pow(L, 3.);
136 f102 = (8. * pow(M_PI, 3.)*t3) / pow(L, 3.);
137 f030 = (8. * pow(M_PI, 3.)*(t2 - t20)) / pow(L, 3.);
138 f021 = (8. * pow(M_PI, 3.)*t8) / pow(L, 3.);
139 f012 = (-8. * pow(M_PI, 3.)*t20) / pow(L, 3.);
140 f003 = (8. * pow(M_PI, 3.)*(-t18 + t8)) / pow(L, 3.);
141
142 //Gyroid second order derivatives
143 f200 = (-4. * pow(M_PI, 2.)*(t13 + t5)) / pow(L, 2.);
144 f110 = (-4. * pow(M_PI, 2.)*t9) / pow(L, 2.);
145 f101 = (-4. * pow(M_PI, 2.)*t6) / pow(L, 2.);
146 f020 = (-4. * pow(M_PI, 2.)*(t11 + t5)) / pow(L, 2.);
147 f011 = (-4. * pow(M_PI, 2.)*t14) / pow(L, 2.);
148 f002 = (-4. * pow(M_PI, 2.)*(t11 + t13)) / pow(L, 2.);
149
150 //Gyroid first order derivatives
151 f100 = (2. * M_PI*(t17 - t3)) / L;
152 f010 = (2. * M_PI*(-t2 + t20)) / L;
153 f001 = (2. * M_PI*(t18 - t8)) / L;
154
155 //Gyroid
156 f000 = t11 + t13 + t5;
157
160
161 T1 = f001*f002 + f010*f011 + f100*f101;
162 T2 = f001*f011 + f010*f020 + f100*f110;
163 T3 = f001*f101 + f010*f110 + f100*f200;
167 T7 = f001*f002*h + f010*f011*h + f100*f101*h;
168 T8 = f001*f011*h + f010*f020*h + f100*f110*h;
169 T9 = f001*f101*h + f010*f110*h + f100*f200*h;
170
171
172 Gyroidh = 2 * h*sqrt(pow(f001 - (T1*h) / (2.*repeatedTermRoot), 2) + pow(f010 - (T2*h) / (2.*repeatedTermRoot), 2) + pow(f100 - (T3*h) / (2.*repeatedTermRoot), 2))
173 - (3 * h*sqrt(pow(f001 - (T1*h) / (3.*repeatedTermRoot), 2) + pow(f010 - (T2*h) / (3.*repeatedTermRoot), 2) + pow(f100 - (T3*h) / (3.*repeatedTermRoot), 2))) / 2.
174 - (3 * h*sqrt(pow(f001 - (T1*h) / (3.*repeatedTermRoot) + (h*((T7 - 3 * f001*repeatedTermRoot)*
175 (4 * pow(T1, 2)*h - 4 * (pow(f002, 2) + f001*f003 + pow(f011, 2) + f010*f012 + pow(f101, 2) + f100*f102)*h*repeatedTerm + 12 * f002*pow(repeatedTerm, 1.5)) +
176 (T8 - 3 * f010*repeatedTermRoot)*(4 * T1*T2*h - 4 * (T4)*h*repeatedTerm + 12 * f011*pow(repeatedTerm, 1.5)) +
177 (T9 - 3 * f100*repeatedTermRoot)*(4 * T1*T3*h - 4 * (T5)*h*repeatedTerm + 12 * f101*pow(repeatedTerm, 1.5)))) /
178 (108.*sqrt(pow(f001 - (T1*h) / (3.*repeatedTermRoot), 2) + pow(f010 - (T2*h) / (3.*repeatedTermRoot), 2) + pow(f100 - (T3*h) / (3.*repeatedTermRoot), 2))*
179 pow(repeatedTerm, 2)), 2) + pow(f010 - (T2*h) / (3.*repeatedTermRoot) +
180 (h*((T7 - 3 * f001*repeatedTermRoot)*(4 * T1*T2*h - 4 * (T4)*h*repeatedTerm + 12 * f011*pow(repeatedTerm, 1.5)) +
181 (T8 - 3 * f010*repeatedTermRoot)*(4 * pow(T2, 2)*h - 4 * (pow(f011, 2) + pow(f020, 2) + f001*f021 + f010*f030 + pow(f110, 2) + f100*f120)*h*repeatedTerm + 12 * f020*pow(repeatedTerm, 1.5)) +
182 (T9 - 3 * f100*repeatedTermRoot)*(4 * T2*T3*h - 4 * (T6)*h*repeatedTerm + 12 * f110*pow(repeatedTerm, 1.5)))) /
183 (108.*sqrt(pow(f001 - (T1*h) / (3.*repeatedTermRoot), 2) + pow(f010 - (T2*h) / (3.*repeatedTermRoot), 2) + pow(f100 - (T3*h) / (3.*repeatedTermRoot), 2))*
184 pow(repeatedTerm, 2)), 2) + pow(f100 - (T3*h) / (3.*repeatedTermRoot) +
185 (h*((T7 - 3 * f001*repeatedTermRoot)*(4 * T1*T3*h - 4 * (T5)*h*repeatedTerm + 12 * f101*pow(repeatedTerm, 1.5)) +
186 (T8 - 3 * f010*repeatedTermRoot)*(4 * T2*T3*h - 4 * (T6)*h*repeatedTerm + 12 * f110*pow(repeatedTerm, 1.5)) +
187 (T9 - 3 * f100*repeatedTermRoot)*(4 * pow(T3, 2)*h - 4 * (pow(f101, 2) + pow(f110, 2) + pow(f200, 2) + f001*f201 + f010*f210 + f100*f300)*h*repeatedTerm + 12 * f200*pow(repeatedTerm, 1.5)))) /
188 (108.*sqrt(pow(f001 - (T1*h) / (3.*repeatedTermRoot), 2) + pow(f010 - (T2*h) / (3.*repeatedTermRoot), 2) + pow(f100 - (T3*h) / (3.*repeatedTermRoot), 2))*
189 pow(repeatedTerm, 2)), 2))) / 2. + f000;
190
191 return Gyroidh;
192 }
193};
194/*==========================================================*/
195bool GbGyroidThirdOrderLong::isPointInGbObject3D(const double& x1, const double& x2, const double& x3)
196{
197 //double f = sin(2.*M_PI*x1/edgeLength)*cos(2.*M_PI*x2 / edgeLength) + sin(2.*M_PI*x2 / edgeLength)*cos(2.*M_PI*x3 / edgeLength) + sin(2.*M_PI*x3 / edgeLength)*cos(2.*M_PI*x1 / edgeLength);
198 //evaluateImplicitFunction(x1,x2,x3, 0., 0., 0.)
199 double f1 = evaluateImplicitFunction(x1, x2, x3, 1.);
200 double f2 = evaluateImplicitFunction(x1, x2, x3, -1.);
202}
203
204/*==========================================================*/
205double GbGyroidThirdOrderLong::getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3)
206{
207 double from = 0; // The solution must lie in the interval [from, to], additionally f(from) <= 0 && f(to) >= 0
208 double to = dx*sqrt(rx1*rx1+ rx2*rx2+ rx3*rx3);
210 f.x =x1 ;
211 f.y =x2 ;
212 f.z =x3 ;
213 f.dir1 = rx1;
214 f.dir2 = rx2;
215 f.dir3 = rx3;
216 f.L = edgeLength;
217 f.h = thickness;
218 if (f(from)*f(to)<0)
219 {
220 std::pair<double, double> result = bisect(f, from, to, TerminationCondition());
221 double root = (result.first + result.second) / 2;
222 return root;
223 }
224 f.h = -thickness;
225 if (f(from)*f(to) < 0)
226 {
227 std::pair<double, double> result = bisect(f, from, to, TerminationCondition());
228 double root = (result.first + result.second) / 2;
229 return root;
230 }
231 else
232 {
233 return 999;
234 }
235
236}
237/*=======================================================*/
238double GbGyroidThirdOrderLong::evaluateImplicitFunction(const double& x1, const double& x2, const double& x3, const double& position)
239{
240 double to = 0.;
242 f.x = x1;
243 f.y = x2;
244 f.z = x3;
245 f.dir1 = 0.;
246 f.dir2 = 0.;
247 f.dir3 = 0.;
248 f.L = edgeLength;
249 f.h = position*thickness;
250 return f(to);
251}
252/*=======================================================*/
253double GbGyroidThirdOrderLong::getX1Centroid()
254{
255 return (0.5*(p1->x1 + p2->x1));
256}
257/*=======================================================*/
258double GbGyroidThirdOrderLong::getX1Minimum()
259{
260 return (this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1);
261}
262/*=======================================================*/
263double GbGyroidThirdOrderLong::getX1Maximum()
264{
265 return (this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1);
266}
267/*=======================================================*/
268double GbGyroidThirdOrderLong::getX2Centroid()
269{
270 return (0.5*(p1->x2 + p2->x2));
271}
272/*=======================================================*/
273double GbGyroidThirdOrderLong::getX2Minimum()
274{
275 return (this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2);
276}
277/*=======================================================*/
278double GbGyroidThirdOrderLong::getX2Maximum()
279{
280 return (this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2);
281}
282/*=======================================================*/
283double GbGyroidThirdOrderLong::getX3Centroid()
284{
285 return (0.5*(p1->x3 + p2->x3));
286}
287/*=======================================================*/
288double GbGyroidThirdOrderLong::getX3Minimum()
289{
290 return (this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3);
291}
292/*=======================================================*/
293double GbGyroidThirdOrderLong::getX3Maximum()
294{
295 return (this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3);
296}
297/*=======================================================*/
298bool GbGyroidThirdOrderLong::isCellInsideGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
299{
300 if (this->isPointInGbObject3D(x1a, x2a, x3a)
301 && this->isPointInGbObject3D(x1b, x2a, x3a)
302 && this->isPointInGbObject3D(x1b, x2b, x3a)
303 && this->isPointInGbObject3D(x1a, x2b, x3a)
304 && this->isPointInGbObject3D(x1a, x2a, x3b)
305 && this->isPointInGbObject3D(x1b, x2a, x3b)
306 && this->isPointInGbObject3D(x1b, x2b, x3b)
307 && this->isPointInGbObject3D(x1a, x2b, x3b))
308 {
309 return true;
310 }
311 return false;
312}
313/*=======================================================*/
314bool GbGyroidThirdOrderLong::isCellInsideOrCuttingGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
315{
316 if ((this->isPointInGbObject3D(x1a, x2a, x3a) == false)
317 && (this->isPointInGbObject3D(x1b, x2a, x3a) == false)
318 && (this->isPointInGbObject3D(x1b, x2b, x3a) == false)
319 && (this->isPointInGbObject3D(x1a, x2b, x3a) == false)
320 && (this->isPointInGbObject3D(x1a, x2a, x3b) == false)
321 && (this->isPointInGbObject3D(x1b, x2a, x3b) == false)
322 && (this->isPointInGbObject3D(x1b, x2b, x3b) == false)
323 && (this->isPointInGbObject3D(x1a, x2b, x3b) == false))
324 {
325 return false;
326 }
327 return true;
328}
329/*=======================================================*/
330bool GbGyroidThirdOrderLong::isCellCuttingGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
331{
332 if (!this->isCellInsideGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b)
333 && this->isCellInsideOrCuttingGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b))
334 {
335 return true;
336 }
337 return false;
338}
339/*==========================================================*/
340void GbGyroidThirdOrderLong::objectChanged(UbObservable *changedObject)
341{
342 GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject);
343 if (!point || (this->p1 != point && this->p2 != point && this->p3 != point && this->p4 != point))
344 return;
345
346 this->notifyObserversObjectChanged();
347}
348/*==========================================================*/
349void GbGyroidThirdOrderLong::objectWillBeDeleted(UbObservable *objectForDeletion)
350{
351 if (this->p1) {
352 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p1);
354 this->p1 = NULL;
355 }
356 }
357 if (this->p2) {
358 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p2);
360 this->p2 = NULL;
361 }
362 }
363 if (this->p3) {
364 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p3);
365 if (objectForDeletion == observedObj) {
366 this->p3 = NULL;
367 }
368 }
369 if (this->p4) {
370 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p4);
371 if (objectForDeletion == observedObj) {
372 this->p4 = NULL;
373 }
374 }
375}
376
377#endif
378
This Interface provides basic 3D geometry objects methods.
Definition GbObject3D.h:64
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
Observable object.
std::shared_ptr< T > SPtr
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
const real dx
bool greaterEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:223
bool lessEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:209
(q) for second order Boundary Conditions (BCs)