OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
olb::IndicatorF3D< S > Class Template Reference

IndicatorF3D is an application from $ \Omega \subset R^3 \to \{0,1\} $. More...

#include <indicatorBaseF3D.h>

+ Inheritance diagram for olb::IndicatorF3D< S >:
+ Collaboration diagram for olb::IndicatorF3D< S >:

Public Member Functions

virtual Vector< S, 3 > & getMin ()
 
virtual Vector< S, 3 > & getMax ()
 
virtual bool distance (S &distance, const Vector< S, 3 > &origin, S precision, const Vector< S, 3 > &direction)
 
virtual bool distance (S &distance, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, S precision, S pitch)
 
virtual bool distance (S &distance, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1)
 
virtual bool distance (S &distance, const Vector< S, 3 > &origin)
 
virtual bool distance (S &distance, const S input[])
 
virtual bool normal (Vector< S, 3 > &normal, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1)
 returns true and the normal if there was one found for an given origin and direction
 
virtual bool rotOnAxis (Vector< S, 3 > &vec_rot, const Vector< S, 3 > &vec, const Vector< S, 3 > &axis, S &theta)
 Rotate vector around axis by angle theta.
 
virtual bool operator() (bool output[1], const S input[3])
 Returns true if input is inside the indicator.
 
virtual S signedDistance (const Vector< S, 3 > &input)
 Returns signed distance to the nearest point on the indicator surface.
 
virtual Vector< S, 3 > surfaceNormal (const Vector< S, 3 > &pos, const S meshSize)
 Return surface normal.
 
Vector< S, 3 > surfaceNormal (const Vector< S, 3 > &pos, const S meshSize, std::function< Vector< S, 3 >(const Vector< S, 3 > &)> transformPos)
 Return surface normal after possible translation and rotation.
 
bool isInsideBox (Vector< S, 3 > point)
 Returns true if point is inside a cube with corners _myMin and _myMax
 
virtual Vector< S, 3 > getSample (const std::function< S()> &randomness) const
 
- Public Member Functions inherited from olb::GenericF< bool, S >
virtual ~GenericF ()=default
 
int getSourceDim () const
 read only access to member variable _m
 
int getTargetDim () const
 read only access to member variable _n
 
std::string & getName ()
 read and write access to name
 
std::string const & getName () const
 read only access to name
 
virtual bool operator() (bool output[], const S input[])=0
 has to be implemented for 'every' derived class
 
bool operator() (bool output[])
 wrapper that call the pure virtual operator() (T output[], const S input[]) from above
 
bool operator() (bool output[], S input0)
 
bool operator() (bool output[], S input0, S input1)
 
bool operator() (bool output[], S input0, S input1, S input2)
 
bool operator() (bool output[], S input0, S input1, S input2, S input3)
 

Protected Member Functions

 IndicatorF3D ()
 
- Protected Member Functions inherited from olb::GenericF< bool, S >
 GenericF (int targetDim, int sourceDim)
 

Protected Attributes

Vector< S, 3 > _myMin
 
Vector< S, 3 > _myMax
 

Additional Inherited Members

- Public Types inherited from olb::GenericF< bool, S >
using targetType
 
using sourceType
 
- Public Attributes inherited from olb::GenericF< bool, S >
std::shared_ptr< GenericF< bool, S > > _ptrCalcC
 memory management, frees resouces (calcClass)
 

Detailed Description

template<typename S>
class olb::IndicatorF3D< S >

IndicatorF3D is an application from $ \Omega \subset R^3 \to \{0,1\} $.

Parameters
_myMinholds minimal(component wise) vector of the domain $ \Omega $.
_myMaxholds maximal(component wise) vector of the domain $ \Omega $.

Definition at line 42 of file indicatorBaseF3D.h.

Constructor & Destructor Documentation

◆ IndicatorF3D()

template<typename S >
olb::IndicatorF3D< S >::IndicatorF3D ( )
protected

Definition at line 41 of file indicatorBaseF3D.hh.

41 : GenericF<bool,S>(1, 3)
42{}

Member Function Documentation

◆ distance() [1/5]

template<typename S >
bool olb::IndicatorF3D< S >::distance ( S & distance,
const S input[] )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 97 of file indicatorBaseF3D.hh.

98{
100 return true;
101}
virtual bool distance(S &distance, const Vector< S, 3 > &origin, S precision, const Vector< S, 3 > &direction)
virtual S signedDistance(const Vector< S, 3 > &input)
Returns signed distance to the nearest point on the indicator surface.
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019

References olb::util::abs().

+ Here is the call graph for this function:

◆ distance() [2/5]

template<typename S >
bool olb::IndicatorF3D< S >::distance ( S & distance,
const Vector< S, 3 > & origin )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 90 of file indicatorBaseF3D.hh.

91{
92 S input[3] = {origin[0],origin[1],origin[2]};
93 return this->distance(distance, input);
94}

◆ distance() [3/5]

template<typename S >
bool olb::IndicatorF3D< S >::distance ( S & distance,
const Vector< S, 3 > & origin,
const Vector< S, 3 > & direction,
int iC = -1 )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >, and olb::IndicatorSphere3D< S >.

Definition at line 81 of file indicatorBaseF3D.hh.

82{
83 S precision = .0001;
84 S pitch = 0.5;
85
86 return this->distance(distance, origin, direction, precision, pitch);
87}

◆ distance() [4/5]

template<typename S >
bool olb::IndicatorF3D< S >::distance ( S & distance,
const Vector< S, 3 > & origin,
const Vector< S, 3 > & direction,
S precision,
S pitch )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 69 of file indicatorBaseF3D.hh.

70{
71 return util::distance(distance, origin, direction, precision, pitch,
72 [&](bool output[1], const S input[3]) {
73 return (*this)(output, input);
74 },
75 [&](const Vector<S,3>& pos) {
76 return isInsideBox(pos);
77 });
78}
bool isInsideBox(Vector< S, 3 > point)
Returns true if point is inside a cube with corners _myMin and _myMax
bool distance(S &distance, const Vector< S, D > &origin, const Vector< S, D > &direction, S precision, S pitch, F1 isInside, F2 isInsideBoundingBox)

◆ distance() [5/5]

template<typename S >
bool olb::IndicatorF3D< S >::distance ( S & distance,
const Vector< S, 3 > & origin,
S precision,
const Vector< S, 3 > & direction )
virtual
Returns
false or true and pos. distance if there was one found for a given origin and direction. Mind that the default computation is done by a numerical approximation which searches .. [TODO: CYRIL]

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 57 of file indicatorBaseF3D.hh.

58{
59 return util::distance(distance, origin, direction, precision,
60 [&](const Vector<S,3> input) {
61 return this->signedDistance(input);
62 },
63 [&](const Vector<S,3>& pos) {
64 return isInsideBox(pos);
65 });
66}

References olb::util::distance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMax()

template<typename S >
Vector< S, 3 > & olb::IndicatorF3D< S >::getMax ( )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >, and olb::IndicatorTranslate3D< S >.

Definition at line 51 of file indicatorBaseF3D.hh.

52{
53 return _myMax;
54}
Vector< S, 3 > _myMax
+ Here is the caller graph for this function:

◆ getMin()

template<typename S >
Vector< S, 3 > & olb::IndicatorF3D< S >::getMin ( )
virtual

Reimplemented in olb::RegularCachedIndicatorF3D< S >, and olb::IndicatorTranslate3D< S >.

Definition at line 45 of file indicatorBaseF3D.hh.

46{
47 return _myMin;
48}
Vector< S, 3 > _myMin
+ Here is the caller graph for this function:

◆ getSample()

template<typename S >
virtual Vector< S, 3 > olb::IndicatorF3D< S >::getSample ( const std::function< S()> & randomness) const
inlinevirtual
Parameters
randomnessCallable returning uniformly sampled values in [0,1]

Reimplemented in olb::IndicatorCylinder3D< S >, and olb::IndicatorCuboid3D< S >.

Definition at line 81 of file indicatorBaseF3D.h.

81 {
82 throw std::runtime_error("Indicator doesn't support random sampling");
83 }

◆ isInsideBox()

template<typename S >
bool olb::IndicatorF3D< S >::isInsideBox ( Vector< S, 3 > point)

Returns true if point is inside a cube with corners _myMin and _myMax

Definition at line 305 of file indicatorBaseF3D.hh.

306{
307 return point >= _myMin && point <= _myMax;
308}

◆ normal()

template<typename S >
bool olb::IndicatorF3D< S >::normal ( Vector< S, 3 > & normal,
const Vector< S, 3 > & origin,
const Vector< S, 3 > & direction,
int iC = -1 )
virtual

returns true and the normal if there was one found for an given origin and direction

(mind that the default computation is done by a numerical approximation which searches .. [TODO])

find perpendicular vector to direction

Loop 3 times to find three points on the surface to use for normal calc. orthogonal to direction vector 120 degree to each other

rotate directionPerpN through 3 angles {0,120,240}

Find 'positive' angle

Calculate Normal

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 129 of file indicatorBaseF3D.hh.

130{
131 //OstreamManager clout(std::cout,"IndicatorF3D");
132#ifdef OLB_DEBUG
133 std::cout << "Calculating IndicatorF3D Normal" << std::endl;
134#endif
135
136 bool originValue;
137 (*this)(&originValue, origin.data());
138 Vector<S,3> currentPoint(origin);
139
140 S precision = .0001;
141
142 S dist;
143 distance(dist, origin, direction, iC);
144
145 S dirMag = norm(direction);
146#ifdef OLB_DEBUG
147 std::cout << "magnitude = " << dirMag << std::endl;
148#endif
149
150 //Vector<S,3> POS(origin + dist*direction*(1/const_cast<Vector<S,3>&> (direction).norm())); //Point on Surface
151 //direction = direction*(1/const_cast<Vector<S,3>&> (direction).norm());
152 Vector<S,3> directionN(direction*(1/dirMag));
153 Vector<S,3> POS(origin + dist*directionN); //Point on Surface
154
156 Vector<S,3> directionPerp;
157 if ( (util::nearZero(directionN[0]) && util::nearZero(directionN[1]) && !util::nearZero(directionN[2]))
158 || (util::nearZero(directionN[0]) && !util::nearZero(directionN[1]) && util::nearZero(directionN[2])) ) {
159 directionPerp[0] = 1;
160 directionPerp[1] = 0;
161 directionPerp[2] = 0;
162 }
163 else if ( !util::nearZero(directionN[0]) && util::nearZero(directionN[1]) && util::nearZero(directionN[2]) ) {
164 directionPerp[0] = 0;
165 directionPerp[1] = 0;
166 directionPerp[2] = 1;
167 }
168 else if ( ( !util::nearZero(directionN[0]) || !util::nearZero(directionN[1]) ) && !util::nearZero(directionN[2]) ) {
169 directionPerp[0] = directionN[0];
170 directionPerp[1] = directionN[1];
171 directionPerp[2] = -(directionN[0] + directionN[1])/directionN[2];
172 }
173 else if ( ( !util::nearZero(directionN[0]) || !util::nearZero(directionN[1]) ) && util::nearZero(directionN[2]) ) {
174 directionPerp[0] = directionN[0];
175 directionPerp[1] = -(directionN[0] + directionN[2])/directionN[1];
176 directionPerp[2] = directionN[2];
177 }
178 else {
179 std::cout << "Error: unknown case for perpendicular check" << std::endl;
180 return false;
181 }
182
183 Vector<S,3> directionPerpN(directionPerp*(dirMag/norm(directionPerp)));
184
185
186 Vector<S,3> point1;
187 Vector<S,3> point2;
188 Vector<S,3> point3;
189
190 bool currentValue;
191
194
195
196 for (int n: {
197 0,120,240
198 }) {
199 S thetaMain = util::degreeToRadian(n);
200
202 Vector<S,3> perp;
203 rotOnAxis(perp, directionPerpN, directionN, thetaMain);
204 Vector<S,3> perpPoint(POS + perp);
205
206 //std::cout << "perp = [" << perp[0] << "," << perp[1] << "," << perp[2] << "]" << std::endl;
207
208 //S rotate = 90.;
209 S rotate = 179.;
210 S pitch = rotate/2.;
211
212 Vector<S,3> vec(perp);
213
214 Vector<S,3> rotAxis;
215
216 //rotAxis = cross(perp,directionN);
217 rotAxis[0] = perp[1]*directionN[2] - perp[2]*directionN[1];
218 rotAxis[1] = perp[2]*directionN[0] - perp[0]*directionN[2];
219 rotAxis[2] = perp[0]*directionN[1] - perp[1]*directionN[0];
220
221 //normal = rotAxis;
222 //return true;
223 //std::cout << "rotAxis = [" << rotAxis[0] << "," << rotAxis[1] << "," << rotAxis[2] << "]" << std::endl;
224
226 Vector<S,3> testPOS;
227 S testAngle(0.25*M_PI);
228 rotOnAxis(testPOS, perp, rotAxis, testAngle);
229 Vector<S,3> testPoint( POS + testPOS);
230 //std::cout << "testPOS = [" << testPOS[0] << "," << testPOS[1] << "," << testPOS[2] << "]" << std::endl;
231 //std::cout << "testPoint = [" << testPoint[0] << "," << testPoint[1] << "," << testPoint[2] << "]" << std::endl;
232
233 S distTestPoint = norm(testPoint - origin);
234 S distPerpPoint = norm(perpPoint - origin);
235
236 S mod = 0;
237 if (distTestPoint < distPerpPoint) { // pos. angle rotates towards
238 mod = -1;
239 }
240 else {
241 mod = 1;
242 }
243
244 while (util::abs(pitch) >= precision) {
245
246 S theta(util::degreeToRadian(pitch));
247
248 currentPoint = POS + vec;
249 (*this)(&currentValue, currentPoint.data());
250
251 S temp;
252 if (currentValue == originValue) {
253 temp = mod*theta;
254 rotOnAxis(vec, vec, rotAxis, temp);
255 }
256 else {
257 temp = -mod*theta;
258 rotOnAxis(vec, vec, rotAxis, temp);
259 }
260 pitch /= 2.;
261
262
263
264 }
265
266 if (n == 0) {
267 point1 = currentPoint;
268 }
269 else if (n == 120) {
270 point2 = currentPoint;
271 }
272 else if (n == 240) {
273 point3 = currentPoint;
274 }
275 else {
276 std::cout << "Something broke" << std::endl;
277 return false;
278 }
279
280 }
281
283 Vector<S,3> vec1 (point1 - point2);
284 Vector<S,3> vec2 (point1 - point3);
285
286 normal[0] = -(vec1[1]*vec2[2] - vec1[2]*vec2[1]);
287 normal[1] = -(vec1[2]*vec2[0] - vec1[0]*vec2[2]);
288 normal[2] = -(vec1[0]*vec2[1] - vec1[1]*vec2[0]);
289
291
292
293 //S dist;
294 //Vector<S,3> dist;
295 //distance(dist, origin, direction, iC);
296 //normal = Vector<S,3>(dist);
297 //normal = POS;
298 //normal = directionPerpN;
299 //normal = directionN;
300 return true;
301
302}
#define M_PI
virtual bool normal(Vector< S, 3 > &normal, const Vector< S, 3 > &origin, const Vector< S, 3 > &direction, int iC=-1)
returns true and the normal if there was one found for an given origin and direction
virtual bool rotOnAxis(Vector< S, 3 > &vec_rot, const Vector< S, 3 > &vec, const Vector< S, 3 > &axis, S &theta)
Rotate vector around axis by angle theta.
constexpr const T * data() const any_platform
Definition vector.h:161
decltype(Vector< decltype(util::sqrt(T())), D >()) degreeToRadian(const Vector< T, D > &angle)
bool nearZero(const ADf< T, DIM > &a)
Definition aDiff.h:1087
constexpr T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:245

References olb::util::abs(), olb::Vector< T, D >::data(), olb::util::degreeToRadian(), M_PI, olb::util::nearZero(), olb::norm(), and olb::normalize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator()()

template<typename S >
bool olb::IndicatorF3D< S >::operator() ( bool output[1],
const S input[3] )
virtual

Returns true if input is inside the indicator.

Reimplemented in olb::IndicatorIdentity3D< S >, and olb::RegularCachedIndicatorF3D< S >.

Definition at line 334 of file indicatorBaseF3D.hh.

335{
336 output[0] = this->signedDistance(input) <= 0;
337 return output[0];
338}

◆ rotOnAxis()

template<typename S >
bool olb::IndicatorF3D< S >::rotOnAxis ( Vector< S, 3 > & vec_rot,
const Vector< S, 3 > & vec,
const Vector< S, 3 > & axis,
S & theta )
virtual

Rotate vector around axis by angle theta.

http://mathworld.wolfram.com/RodriguesRotationFormula.html https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 104 of file indicatorBaseF3D.hh.

105{
107
108 //Vector<S,3> axisN(axis*(1/(axis).norm())); // normalize rotation axis
109 Vector<S,3> axisN(axis*(1/norm(axis))); // normalize rotation axis
110
111 vec_rot = vec ;
112
113 Vector<S,3> crossProd;
114
115 crossProd[0] = axisN[1]*vec[2] - axisN[2]*vec[1];
116 crossProd[1] = axisN[2]*vec[0] - axisN[0]*vec[2];
117 crossProd[2] = axisN[0]*vec[1] - axisN[1]*vec[0];
118
119 S dotProd = axisN[0]*vec[0] + axisN[1]*vec[1] + axisN[2]*vec[2];
120
121 //v_rot = util::cos(theta)*vec + (crossProd)*util::sin(theta) + axisN*(dotProduct3D(axisN,vec))*(1 - util::cos(theta));
122 vec_rot = util::cos(theta)*vec + (crossProd)*util::sin(theta) + axisN*(dotProd)*(1 - util::cos(theta));
123
124 return true;
125
126}
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578

References olb::util::cos(), olb::norm(), and olb::util::sin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ signedDistance()

template<typename S >
S olb::IndicatorF3D< S >::signedDistance ( const Vector< S, 3 > & input)
virtual

◆ surfaceNormal() [1/2]

template<typename S >
Vector< S, 3 > olb::IndicatorF3D< S >::surfaceNormal ( const Vector< S, 3 > & pos,
const S meshSize )
virtual

Return surface normal.

Reimplemented in olb::RegularCachedIndicatorF3D< S >.

Definition at line 319 of file indicatorBaseF3D.hh.

320{
321 return util::surfaceNormal(pos, meshSize, [&](const Vector<S,3>& pos) {
322 return this->signedDistance(pos);
323 });
324}
Vector< S, D > surfaceNormal(const Vector< S, D > &pos, const S meshSize, F1 sdf)

References olb::util::surfaceNormal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ surfaceNormal() [2/2]

template<typename S >
Vector< S, 3 > olb::IndicatorF3D< S >::surfaceNormal ( const Vector< S, 3 > & pos,
const S meshSize,
std::function< Vector< S, 3 >(const Vector< S, 3 > &)> transformPos )

Return surface normal after possible translation and rotation.

Definition at line 327 of file indicatorBaseF3D.hh.

329{
330 return this->surfaceNormal(transformPos(pos), meshSize);
331}
virtual Vector< S, 3 > surfaceNormal(const Vector< S, 3 > &pos, const S meshSize)
Return surface normal.

Member Data Documentation

◆ _myMax

template<typename S >
Vector<S,3> olb::IndicatorF3D< S >::_myMax
protected

Definition at line 46 of file indicatorBaseF3D.h.

◆ _myMin

template<typename S >
Vector<S,3> olb::IndicatorF3D< S >::_myMin
protected

Definition at line 45 of file indicatorBaseF3D.h.


The documentation for this class was generated from the following files: