VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbCylinderImplicit.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
35#include <GbCylinderImplicit.h>
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
51/*=======================================================*/
52GbCylinderImplicit::GbCylinderImplicit()
53{
54
55}
56/*=======================================================*/
57// Konstruktor
58GbCylinderImplicit::GbCylinderImplicit(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b ,const double& dx, const double& OuterRadius, const double& InnerRadius) :GbObject3D()
59{
60 this->p1 = new GbPoint3D(x1a, x2a, x3a);
61 this->p2 = new GbPoint3D(x1b, x2b, x3b);
62 this->p1->addObserver(this);
63 this->p2->addObserver(this);
64
65 //this->p3 = new GbPoint3D(x1Lbound, x2Lbound, x3Lbound);
66 //this->p4 = new GbPoint3D(x1Ubound, x2Ubound, x3Ubound);
67
68 this->dx = dx;
69 this->OuterRadius=OuterRadius;
70 this->InnerRadius=InnerRadius;
71
72
73 this->f.x0 = x1a;
74 this->f.y0 = x2a;
75 this->f.z0 = x3a;
76 this->f.x1 = x1b;
77 this->f.y1 = x2b;
78 this->f.z1 = x3b;
79 this->f.r=InnerRadius;
80 this->f.R=OuterRadius;
81
82 this-> f.init();
83 this->cylinderLengthSquared = pow(x1a - x1b,2) + pow(x2a - x2b,2) + pow(x3a - x3b,2);
84 //base-circles local coordinate system
85 this->e1x = (pow(x2a - x2b,2) + pow(x3a - x3b,2) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b))/(this->cylinderLengthSquared*sqrt(2 + (2*(-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b)))/
87
88
89
90 this->e1y= (pow(x1a,2) + pow(x1b,2) + x1b*(x2a - x2b) + x1a*(-2*x1b - x2a + x2b) + (x3a - x3b)*(-x2a + x2b + x3a - x3b))/(this->cylinderLengthSquared*sqrt(2 + (2*(-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b)))/
92
93
94
95 this->e1z = (pow(x1a,2) + pow(x1b,2) + x1b*(x3a - x3b) + x1a*(-2*x1b - x3a + x3b) + (x2a - x2b)*(x2a - x2b - x3a + x3b))/(this->cylinderLengthSquared*sqrt(2 + (2*(-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b)))/
97
98
99
100 this->e2x = (-x2a + x2b + x3a - x3b)/(sqrt(2)*sqrt(this->cylinderLengthSquared)*
101 sqrt(1 + (-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b))/(this->cylinderLengthSquared)));
102
103
104
105 this->e2y= (x1a - x1b - x3a + x3b)/(sqrt(2)*sqrt(this->cylinderLengthSquared)*
106 sqrt(1 + (-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b))/(this->cylinderLengthSquared)));
107
108
109
110
111 this->e2z = (-x1a + x1b + x2a - x2b)/(sqrt(2)*sqrt(this->cylinderLengthSquared)*
112 sqrt(1 + (-((x2a - x2b)*(x3a - x3b)) + x1b*(x2a - x2b + x3a - x3b) + x1a*(-x2a + x2b - x3a + x3b))/(this->cylinderLengthSquared)));
113
114
115
116
117
118}
119/*=======================================================*/
120GbCylinderImplicit::GbCylinderImplicit(GbCylinderImplicit * imp)
121{
122}
123/*=======================================================*/
124// Destruktor
125GbCylinderImplicit::~GbCylinderImplicit()
126{
127 if (this->p1)
128 this->p1->removeObserver(this);
129 if (this->p2)
130 this->p2->removeObserver(this);
131 if (this->p3)
132 this->p3->removeObserver(this);
133 if (this->p4)
134 this->p4->removeObserver(this);
135}
136/*=======================================================*/
137// struct TerminationCondition {
138// bool operator() (double min, double max) {
139// return abs(min - max) <= 10e-10;
140// }
141// };
142// /*=======================================================*/
143// struct FunctionOfImplicitCylinder {
144// double x, y, z;
145// double x0, y0, z0;
146// double x1, y1, z1;
147// double r;
148
149// double l = sqrt(pow(x0 - x1,2) + pow(y0 - y1,2) + pow(z0 - z1,2));
150
151// double f1 = pow(x - x0,2) + pow(y - y0,2) + pow(z - z0,2) -
152// (pow(r,2) + pow((x - x0)*(x0 - x1) + (y - y0)*(y0 - y1) + (z - z0)*(z0 - z1),2)/(l*l));
153// double f2= -(
154// sqrt(pow(x0,2) + pow(y0,2) + pow(z0,2)) + (x*(-x0 + x1) + y*(-y0 + y1) + z*(-z0 + z1))/l );
155
156// double f3=(x*(-x0 + x1) + y*(-y0 + y1) + z*(-z0 + z1))/l - sqrt(pow(x1,2) + pow(y1,2) + pow(z1,2));
157
158
159
160
161// bool operator() () {
162// // return pow(x - x0,2) + pow(y - y0,2) + pow(z - z0,2) <=
163// // pow(r,2) + pow((x - x0)*(x0 - x1) + (y - y0)*(y0 - y1) + (z - z0)*(z0 - z1),2)/(l*l) &&
164// // sqrt(pow(x0,2) + pow(y0,2) + pow(z0,2)) + (x*(-x0 + x1) + y*(-y0 + y1) + z*(-z0 + z1))/l >= 0 &&
165// // (x*(-x0 + x1) + y*(-y0 + y1) + z*(-z0 + z1))/l <= sqrt(pow(x1,2) + pow(y1,2) + pow(z1,2));
166// return f1<=0 && f2<=0 && f3<=0;
167
168// }
169// };
170/*==========================================================*/
171bool GbCylinderImplicit::isPointInGbObject3D(const double& x1, const double& x2, const double& x3)
172{
173 this->f.x = x1;
174 this->f.y = x2;
175 this->f.z = x3;
176
177 double t1=this->f.f1(0);
178 //double t2=this->f.f2(0);
179 //double t3=this->f.f3(0);
180
181 return t1<=0 ;
182 //return t1<=0 && t2<=0 && t3<=0;
183}
184/*==========================================================*/
185bool GbCylinderImplicit::isPointInGbObject3D(const double& x1, const double& x2, const double& x3, bool &pointIsOnBoundary)
186{
187 this->f.x = x1;
188 this->f.y = x2;
189 this->f.z = x3;
190
191 double t1=this->f.f1(0);
192 //double t2=this->f.f2(0);
193 //double t3=this->f.f3(0);
194
195
196 //pointIsOnBoundary = ub_math::equal(t1,0.) && ub_math::equal(t2,0.) && ub_math::equal(t3,0.);
198
199
200 return t1<=0 ;
201 //return t1<=0 && t2<=0 && t3<=0;
202
203}
204/*==========================================================*/
205double GbCylinderImplicit::getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3)
206{
207 //return 1.;
208 double from = 0; // The solution must lie in the interval [from, to], additionally f(from) <= 0 && f(to) >= 0
209 double to = dx/* *sqrt(rx1*rx1+ rx2*rx2+ rx3*rx3) */;
210 //FunctionOfImplicitCylinder g=this->f;
211 f.x =x1 ;
212 f.y =x2 ;
213 f.z =x3 ;
214
215 f.dir1 = rx1/sqrt(rx1*rx1+ rx2*rx2+ rx3*rx3);
216 f.dir2 = rx2/sqrt(rx1*rx1+ rx2*rx2+ rx3*rx3);
217 f.dir3 = rx3/sqrt(rx1*rx1+ rx2*rx2+ rx3*rx3);
218
219 double f1= f.f1(0);
220 //double f2=f.f2(0);
221 //double f3=f.f3(0);
222
223
224 double g1= f.f1(to);
225 //double g2= f.f2(to);
226 //double g3= f.f3(to);
227
228//int ss=std::signbit(f1);
229
230//bool test1 = f1<0 && f2<0 && f3<0;
231//bool test2 = g1<0 && g2<0 && g3<0;
232//bool test3 = f1>0 && f2>0 && f3>0;
233//bool test4 = g1>0 && g2>0 && g3>0;
234
235
236//if(test1 || test2 || test3 || test4)
237//{
238
239
240
241double p1=f1*g1;
242//double p2=f2*g2;
243//double p3=f3*g3;
244if (p1>0) {
245 return 999.;
246}
247else {
248std::pair<double, double> result1 = bisect(f.f1, from, to, TerminationCondition());
249 double root1 = (result1.first + result1.second) / 2;
250 return root1;
251}
252
253
254// if (p1<0) {
255// if (p2 < 0) {
256// //std::cout << "f1&f2" << std::endl;
257// std::pair<double, double> result1 = bisect(f.f1, from, to, TerminationCondition());
258// double root1 = (result1.first + result1.second) / 2;
259// std::pair<double, double> result2 = bisect(f.f2, from, to, TerminationCondition());
260// double root2 = (result2.first + result2.second) / 2;
261// return UbMath::max(root1,root2);
262// } else if (p3 < 0) {
263// //std::cout << "f1&f3" << std::endl;
264// std::pair<double, double> result1 = bisect(f.f1, from, to, TerminationCondition());
265// double root1 = (result1.first + result1.second) / 2;
266// std::pair<double, double> result2 = bisect(f.f3, from, to, TerminationCondition());
267// double root2 = (result2.first + result2.second) / 2;
268// return UbMath::max(root1,root2);
269// } else {
270// //std::cout << "f1" << std::endl;
271// std::pair<double, double> result1 = bisect(f.f1, from, to, TerminationCondition());
272// double root1 = (result1.first + result1.second) / 2;
273// return root1;
274// }
275// } else {
276// if (p3 < 0) {
277// //std::cout << "f3" << std::endl;
278// //std::pair<double, double> result1 = bisect(f.f2, from, to, TerminationCondition());
279// //double root1 = (result1.first + result1.second) / 2;
280// std::pair<double, double> result2 = bisect(f.f3, from, to, TerminationCondition());
281// double root2 = (result2.first + result2.second) / 2;
282// return root2;
283// } else if (p2 < 0) {
284// //std::cout << "f2" << std::endl;
285// std::pair<double, double> result1 = bisect(f.f2, from, to, TerminationCondition());
286// double root1 = (result1.first + result1.second) / 2;
287// return root1;
288// } else {
289// //std::cout << "1" << std::endl;
290// return 999.;
291// }
292// }
293// }
294// else
295// {
296// return 999.;
297// }
298}
299/*=======================================================*/
300// double GbCylinderImplicit::evaluateImplicitFunction(const double& x1, const double& x2, const double& x3)
301// {
302// FunctionOfImplicitCylinder f;
303// f.x = x1;
304// f.y = x2;
305// f.z = x3;
306
307// // f.x0 = p1->x1;
308// // f.y0 = p1->x2;
309// // f.z0 = p1->x3;
310// // f.x1 = p2->x1;
311// // f.y1 = p2->x2;
312// // f.z1 = p2->x3;
313
314// return f();
315// }
316/*=======================================================*/
317double GbCylinderImplicit::getX1Centroid()
318{
319 return (0.5*(p1->x1 + p2->x1));
320}
321/*=======================================================*/
322double GbCylinderImplicit::getX1Minimum()
323{
324 //return (this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1);
325 //return this->p3->x1;
326 return ub_math::min(-(sqrt(pow(e1x,2) + pow(e2x,2))*this->OuterRadius) + p1->x1,
327 -(sqrt(pow(e1x,2) + pow(e2x,2))*this->OuterRadius) + p2->x1);
328}
329/*=======================================================*/
330double GbCylinderImplicit::getX1Maximum()
331{
332 //return (this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1);
333 //return this->p4->x1;
334 return ub_math::max(sqrt(pow(e1x,2) + pow(e2x,2))*this->OuterRadius + p1->x1,
335 sqrt(pow(e1x,2) + pow(e2x,2))*this->OuterRadius + p2->x1);
336
337}
338/*=======================================================*/
339double GbCylinderImplicit::getX2Centroid()
340{
341 return (0.5*(p1->x2 + p2->x2));
342}
343/*=======================================================*/
344double GbCylinderImplicit::getX2Minimum()
345{
346 //return (this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2);
347 //return this->p3->x2;
348 return ub_math::min(-(sqrt(pow(e1y,2) + pow(e2y,2))*this->OuterRadius) + p1->x2,
349 -(sqrt(pow(e1y,2) + pow(e2y,2))*this->OuterRadius) + p2->x2);
350
351}
352/*=======================================================*/
353double GbCylinderImplicit::getX2Maximum()
354{
355 //return (this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2);
356 //return this->p4->x2;
357 return ub_math::max(sqrt(pow(e1y,2) + pow(e2y,2))*this->OuterRadius + p1->x2,
358 sqrt(pow(e1y,2) + pow(e2y,2))*this->OuterRadius + p2->x2);
359
360}
361/*=======================================================*/
362double GbCylinderImplicit::getX3Centroid()
363{
364 return (0.5*(p1->x3 + p2->x3));
365}
366/*=======================================================*/
367double GbCylinderImplicit::getX3Minimum()
368{
369 //return (this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3);
370 //return this->p3->x3;
371 return ub_math::min(-(sqrt(pow(e1z,2) + pow(e2z,2))*this->OuterRadius) + p1->x3,
372 -(sqrt(pow(e1z,2) + pow(e2z,2))*this->OuterRadius) + p2->x3);
373
374
375}
376/*=======================================================*/
377double GbCylinderImplicit::getX3Maximum()
378{
379 //return (this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3);
380 //return this->p4->x3;
381 return ub_math::max(sqrt(pow(e1z,2) + pow(e2z,2))*this->OuterRadius + p1->x3,
382 sqrt(pow(e1z,2) + pow(e2z,2))*this->OuterRadius + p2->x3);
383}
384/*=======================================================*/
385bool GbCylinderImplicit::isCellInsideGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
386{
387 if (this->isPointInGbObject3D(x1a, x2a, x3a)
388 && this->isPointInGbObject3D(x1b, x2a, x3a)
389 && this->isPointInGbObject3D(x1b, x2b, x3a)
390 && this->isPointInGbObject3D(x1a, x2b, x3a)
391 && this->isPointInGbObject3D(x1a, x2a, x3b)
392 && this->isPointInGbObject3D(x1b, x2a, x3b)
393 && this->isPointInGbObject3D(x1b, x2b, x3b)
394 && this->isPointInGbObject3D(x1a, x2b, x3b)
395 )
396 {
397 return true;
398 }
399 return false;
400}
401/*=======================================================*/
402bool GbCylinderImplicit::isCellInsideOrCuttingGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
403{
404 if ((this->isPointInGbObject3D(x1a, x2a, x3a) == false)
405 && (this->isPointInGbObject3D(x1b, x2a, x3a) == false)
406 && (this->isPointInGbObject3D(x1b, x2b, x3a) == false)
407 && (this->isPointInGbObject3D(x1a, x2b, x3a) == false)
408 && (this->isPointInGbObject3D(x1a, x2a, x3b) == false)
409 && (this->isPointInGbObject3D(x1b, x2a, x3b) == false)
410 && (this->isPointInGbObject3D(x1b, x2b, x3b) == false)
411 && (this->isPointInGbObject3D(x1a, x2b, x3b) == false)
412 )
413 {
414 return false;
415 }
416 return true;
417}
418/*=======================================================*/
419bool GbCylinderImplicit::isCellCuttingGbObject3D(const double& x1a, const double& x2a, const double& x3a, const double& x1b, const double& x2b, const double& x3b)
420{
421 if (!this->isCellInsideGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b)
422 && this->isCellInsideOrCuttingGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b))
423 {
424 return true;
425 }
426 return false;
427}
428/*==========================================================*/
429void GbCylinderImplicit::objectChanged(UbObservable *changedObject)
430{
431 GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject);
432 if (!point || (this->p1 != point && this->p2 != point && this->p3 != point && this->p4 != point))
433 return;
434
435 this->notifyObserversObjectChanged();
436}
437/*==========================================================*/
438void GbCylinderImplicit::objectWillBeDeleted(UbObservable *objectForDeletion)
439{
440 if (this->p1) {
441 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p1);
443 this->p1 = NULL;
444 }
445 }
446 if (this->p2) {
447 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p2);
449 this->p2 = NULL;
450 }
451 }
452 if (this->p3) {
453 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p3);
454 if (objectForDeletion == observedObj) {
455 this->p3 = NULL;
456 }
457 }
458 if (this->p4) {
459 UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p4);
460 if (objectForDeletion == observedObj) {
461 this->p4 = NULL;
462 }
463 }
464 // ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo
465}
466
467#endif
468
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
const real dx
const T & min(const T &a1, const T &a2)
Definition UbMath.h:389
bool equal(const T1 &value, const T2 &reference)
Definition UbMath.h:189
const T & max(const T &a1, const T &a2)
Definition UbMath.h:371
(q) for second order Boundary Conditions (BCs)