VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Sphere.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#include "Sphere.h"
35
36#include <algorithm> // std::min
37#include <float.h>
38#include <cmath>
39
41
42namespace vf::gpu {
43
44Sphere::Sphere(const double& centerX, const double& centerY, const double& centerZ, const double& radius)
45 : centerX(centerX), centerY(centerY), centerZ(centerZ), radius(radius)
46{
47
48}
49
50SPtr<Sphere> Sphere::makeShared(double centerX, double centerY, double centerZ, double radius)
51{
52 return std::make_shared<Sphere>(centerX, centerY, centerZ, radius);
53}
54
56{
57 return std::make_shared<Sphere>(centerX, centerY, centerZ, radius);
58}
59
61{
62 return centerX;
63}
64
66{
67 return centerX - radius;
68}
69
71{
72 return centerX + radius;
73}
74
76{
77 return centerY;
78}
79
81{
82 return centerY - radius;
83}
84
86{
87 return centerY + radius;
88}
89
91{
92 return centerZ;
93}
94
96{
97 return centerZ - radius;
98}
99
101{
102 return centerZ + radius;
103}
104
105bool Sphere::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset,
106 const double& maxOffset)
107{
108 double offset = maxOffset;
109 if (x1 < centerX || x2 < centerY || x3 < centerZ)
110 offset = minOffset;
111
112
113 const double deltaX1 = x1 - centerX;
114 const double deltaX2 = x2 - centerY;
115 const double deltaX3 = x3 - centerZ;
116
117 return (deltaX1*deltaX1 + deltaX2*deltaX2 + deltaX3*deltaX3) < ((this->radius - offset) * (this->radius - offset));
118}
119
120
122{
123 this->radius += delta;
124}
125
127{
128
129 Vertex relativePoint( point.x - this->centerX,
130 point.y - this->centerY,
131 point.z - this->centerZ );
132
133 real directionSquare = direction.x * direction.x
134 + direction.y * direction.y
135 + direction.z * direction.z;
136
137 real p = 2* ( relativePoint.x * direction.x
138 + relativePoint.y * direction.y
139 + relativePoint.z * direction.z )
141
145 - (real)this->radius * (real)this->radius )
146 / directionSquare;
147
148 real discriminant = 0.25 * p * p - q;
149
150
151 if( discriminant < 0.0 ) return 1;
152
153 real result1 = - 0.5 * p + std::sqrt( discriminant );
154 real result2 = - 0.5 * p - std::sqrt( discriminant );
155
156 if( result1 < 0.0 && result2 < 0.0 ) return 1;
157
158 if (result1 < 0.0)
160 if (result2 < 0.0)
162
163 real t = std::min( result1, result2 );
164
165 pointOnObject.x = point.x + t * direction.x;
166 pointOnObject.y = point.y + t * direction.y;
167 pointOnObject.z = point.z + t * direction.z;
168
169 qVal = t;
170
171 return 0;
172}
173
174}
175
double getX3Centroid() const override
Definition Sphere.cpp:90
double getX1Maximum() const override
Definition Sphere.cpp:70
int getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal) override
Definition Sphere.cpp:126
static SPtr< Sphere > makeShared(double centerX, double centerY, double centerZ, double radius)
Definition Sphere.cpp:50
double getX3Minimum() const override
Definition Sphere.cpp:95
double getX1Minimum() const override
Definition Sphere.cpp:65
double getX2Minimum() const override
Definition Sphere.cpp:80
double centerZ
Definition Sphere.h:73
double radius
Definition Sphere.h:75
double getX2Centroid() const override
Definition Sphere.cpp:75
void changeSizeByDelta(double delta) override
Definition Sphere.cpp:121
Sphere(const double &centerX, const double &centerY, const double &centerZ, const double &radius)
Definition Sphere.cpp:44
double getX3Maximum() const override
Definition Sphere.cpp:100
double centerY
Definition Sphere.h:72
double getX2Maximum() const override
Definition Sphere.cpp:85
double centerX
Definition Sphere.h:71
SPtr< Object > clone() const override
Definition Sphere.cpp:55
double getX1Centroid() const override
Definition Sphere.cpp:60
bool isPointInObject(const double &x1, const double &x2, const double &x3, const double &minOffset, const double &maxOffset) override
Definition Sphere.cpp:105
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42