24#ifndef INDICATOR_F_2D_HH
25#define INDICATOR_F_2D_HH
33#define M_PI 3.14159265358979323846
35#define M_PI2 1.57079632679489661923
43 : _indicator3D(indicator3D)
45 this->
_myMin[0] = _indicator3D.getMin()[0];
46 this->
_myMin[1] = _indicator3D.getMin()[1];
47 this->
_myMax[0] = _indicator3D.getMax()[0];
48 this->
_myMax[1] = _indicator3D.getMax()[1];
55 input3D[0] = input[0];
56 input3D[1] = input[1];
57 input3D[2] = (_indicator3D.getMax()[2] - _indicator3D.getMin()[2]) * 0.5 + _indicator3D.getMin()[2];
58 _indicator3D(output, input3D);
68 : _center(origin + S(.5)*extend), _xLength(extend[0]), _yLength(extend[1]), _theta(theta)
72 this->
_myMax = origin + extend;
77 : _center(center), _xLength(xLength), _yLength(yLength), _theta(-theta)
79 this->
_myMin = {_center[0] - _xLength/S(2), _center[1] - _yLength/S(2)};
80 this->
_myMax = {_center[0] + _xLength/S(2), _center[1] + _yLength/S(2)};
90 x = _center[0] + (input[0] - _center[0])*
util::cos(_theta) - (input[1] - _center[1])*
util::sin(_theta);
91 y = _center[1] + (input[0] - _center[0])*
util::sin(_theta) + (input[1] - _center[1])*
util::cos(_theta);
126 Vector<S,2> ptransl = {input[0]-_center[0], input[1]-_center[1]};
144 std::stringstream xmlCenter( params.
getAttribute(
"center") );
145 xmlCenter >> center[0] >> center[1];
146 std::stringstream xmlRadius( params.
getAttribute(
"length") );
147 xmlRadius >> xLength >> yLength;
157 _radius2(radius*radius)
159 this->
_myMin = _center - radius;
160 this->
_myMax = _center + radius;
179 output[0] = (
util::pow(_center[0] - input[0],2) +
util::pow(_center[1] - input[1], 2) <= _radius2 );
187 S a = direction[0]*direction[0] + direction[1]*direction[1];
197 S b = 2.*((origin[0] - _center[0])*direction[0] +
198 (origin[1] - _center[1])*direction[1])/a;
199 S c = -_radius2 + (origin[0] - _center[0])*(origin[0] - _center[0])
200 + (origin[1] - _center[1])*(origin[1] - _center[1]);
212 if ((x1<0.) || (x2<0.)) {
236 if (!(distance(dist, origin, direction, iC)) ) {
242 normal = intresection - _center;
263 std::stringstream xmlCenter( params.
getAttribute(
"center") );
264 xmlCenter >> center[0] >> center[1];
265 std::stringstream xmlRadius( params.
getAttribute(
"radius") );
305 output[0] = (
sdf::triangle({input[0], input[1]}, _a, _b, _c) <= 0 );
329 xmlb >> b[0] >> b[1];
331 xmlc >> c[0] >> c[1];
340 _a({center[0], center[1]+radius}),
341_b({center[0]-
util::sqrt(3)/S(2)*radius, center[1]-S(0.5)*radius}),
342_c({center[0]+
util::sqrt(3)/S(2)*radius, center[1]-S(0.5)*radius})
384 output[0] = (
sdf::triangle({input[0], input[1]}, _a, _b, _c) <= 0 );
404 std::stringstream xmlCenter( params.
getAttribute(
"center") );
405 xmlCenter>> center[0] >> center[1];
406 std::stringstream xmlRadius( params.
getAttribute(
"radius") );
416 : _blockData(blockData), _deltaR(deltaR), _invert(invert)
421 OLB_ASSERT(extend[2]-origin[2] == 1,
"extend[2]-origin[2] must be 1.")
428 S xDist = input[0] - this->_myMin[0];
429 S yDist = input[1] - this->_myMin[1];
431 int x = ((this->_myMin[0] + xDist)/_deltaR)+0.5;
432 int y = ((this->_myMin[1] + yDist)/_deltaR)+0.5;
434 if (x >= 0 && x < _blockData.getNx() && y >= 0 && y < _blockData.getNy()) {
436 if (_blockData.get(input) > std::numeric_limits<S>::epsilon()) {
463 : _indicatorF(indicatorF), _layerSize(layerSize)
467 OLB_ASSERT( (this->
_myMax[0]-this->
_myMin[0]) > std::numeric_limits<S>::epsilon(),
"Indicator reduced to zero-set in x direction");
468 OLB_ASSERT( (this->
_myMax[1]-this->
_myMin[1]) > std::numeric_limits<S>::epsilon(),
"Indicator reduced to zero-set in y direction");
469 _isPositive = std::signbit(layerSize);
476 output[0] = !_isPositive;
478 for (
int iX =- 1; iX < 2; ++iX) {
479 for (
int iY =- 1; iY < 2; ++iY) {
480 r[0] = input[0] + iX*_layerSize;
481 r[1] = input[1] + iY*_layerSize;
482 _indicatorF(output,r);
483 if (output[0] == !_isPositive) {
500 output[0] = _f(input) <= 0.0;
IndicatorBlockData2D(BlockData< 3, S, S > &blockData, Vector< S, 3 > extend, Vector< S, 3 > origin, S deltaR, bool invert)
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
indicator function for a 2D circle
bool normal(Vector< S, 2 > &normal, const Vector< S, 2 > &origin, const Vector< S, 2 > &direction, int iC=-1) override
returns true and the normal if there was one found for an given origin and direction
IndicatorCircle2D(Vector< S, 2 > center, S radius)
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
S const getRadius() const
bool distance(S &distance, const Vector< S, 2 > &origin, const Vector< S, 2 > &direction, int iC=-1) override
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
Vector< S, 2 > const & getCenter() const
indicator function for a 2D-cuboid, parallel to the planes x=0, y=0; theta rotates cuboid around its ...
bool operator()(bool output[], const S input[]) override
returns true if input is inside, otherwise false
S const getxLength() const
S const getyLength() const
Vector< S, 2 > const & getCenter() const
IndicatorCuboid2D(Vector< S, 2 > extend, Vector< S, 2 > origin, S theta=0)
constructs an cuboid with x axis dimension 0 to extend[0], ...
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
indicator function for a 2D equilateral triangle
S const getRadius() const
Vector< S, 2 > const & getCenter() const
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
Vector< S, 2 > const & getVertexA() const
IndicatorEquiTriangle2D(Vector< S, 2 > center, S radius)
Vector< S, 2 > const & getVertexB() const
Vector< S, 2 > const & getVertexC() const
IndicatorF2D is an application from .
virtual Vector< S, 2 > & getMin()
virtual Vector< S, 2 > & getMax()
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
IndicatorF2DfromIndicatorF3D(IndicatorF3D< S > &indicator3D)
IndicatorF3D is an application from .
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
IndicatorLayer2D(IndicatorF2D< S > &indicatorF, S layerSize)
IndicatorSDF2D(std::function< T(Vector< T, 2 >)> f)
bool operator()(bool output[], const T input[]) override
indicator function for a 2D triangle
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
Vector< S, 2 > const & getVertexC() const
IndicatorTriangle2D(Vector< S, 2 > a, Vector< S, 2 > b, Vector< S, 2 > c)
Vector< S, 2 > const & getVertexA() const
Vector< S, 2 > const & getVertexB() const
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
class for marking output with some text
std::string getAttribute(const std::string &aName) const
void setWarningsOn(bool warnings) const
switch warnings on/off
This file contains indicator functions.
T triangle(Vector< T, 2 > p, Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c) any_platform
Exact signed distance to the surface of two-dimensional triangle.
T sphere(Vector< T, D > p, T r) any_platform
Exact signed distance to the surface of circle (in 2D) or sphere (in 3D).
T box(Vector< T, 2 > p, Vector< T, 2 > b) any_platform
Exact signed distance to the surface of two-dimensional cuboid.
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
bool approxEqual(T a, U b, W epsilon)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
ADf< T, DIM > sin(const ADf< T, DIM > &a)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
bool nearZero(const ADf< T, DIM > &a)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
IndicatorCuboid2D< S > * createIndicatorCuboid2D(XMLreader const ¶ms, bool verbose=false)
IndicatorEquiTriangle2D< S > * createIndicatorEquiTriangle2D(XMLreader const ¶ms, bool verbose)
IndicatorCircle2D< S > * createIndicatorCircle2D(XMLreader const ¶ms, bool verbose=false)
IndicatorTriangle2D< S > * createIndicatorTriangle2D(XMLreader const ¶ms, bool verbose)
#define OLB_ASSERT(COND, MESSAGE)