OpenLB 1.7
Loading...
Searching...
No Matches
indicatorBaseF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014-2016 Cyril Masquelier, Mathias J. Krause, Benjamin Förster
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef INDICATOR_BASE_F_2D_HH
25#define INDICATOR_BASE_F_2D_HH
26
27#include "utilities/omath.h"
28#include "indicatorBaseF2D.h"
29#include "math.h"
30
31namespace olb {
32
33
34#ifndef M_PI
35#define M_PI 3.14159265358979323846
36#endif
37
38template <typename S>
40 : GenericF<bool,S>(1, 1)
41{ }
42
43template <typename S>
45{
46 return _myMin;
47}
48
49template <typename S>
52 return _myMax;
53}
54
55template <typename S>
56bool IndicatorF1D<S>::operator() (const S input[])
57{
58 bool output{};
59 this->operator()(&output, input);
60 return output;
62
63template <typename S>
65 : GenericF<bool,S>(1, 2)
66{ }
67
68template <typename S>
70{
71 return _myMin;
73
74template <typename S>
76{
77 return _myMax;
80template <typename S>
81bool IndicatorF2D<S>::distance(S& distance, const Vector<S,2>& origin, S precision, const Vector<S,2>& direction)
82{
83 return util::distance(distance, origin, direction, precision,
84 [&](const Vector<S,2> input) {
85 return this->signedDistance(input);
86 },
87 [&](const Vector<S,2>& pos) {
88 return isInsideBox(pos);
89 });
90}
91
92template <typename S>
93bool IndicatorF2D<S>::distance(S& distance, const Vector<S,2>& origin, const Vector<S,2>& direction, S precision, S pitch)
95 return util::distance(distance, origin, direction, precision, pitch,
96 [&](bool output[1], const S input[2]) {
97 return (*this)(output, input);
98 },
99 [&](const Vector<S,2>& pos) {
100 return isInsideBox(pos);
101 });
103
104template <typename S>
105bool IndicatorF2D<S>::distance(S& distance, const Vector<S,2>& origin, const Vector<S,2>& direction, int iC)
106{
107 S precision = .0001;
108 S pitch = 0.5;
109 return this->distance(distance, origin, direction, precision, pitch);
110}
112template <typename S>
113bool IndicatorF2D<S>::distance(S& distance, const Vector<S,2>& origin)
114{
115 S input[3] = {origin[0],origin[1],origin[2]};
116 return this->distance(distance, input);
117}
118
119template <typename S>
120bool IndicatorF2D<S>::distance(S& distance, const S input[])
121{
122 distance = util::abs(signedDistance(input));
123 return true;
124}
125
126
127// given origin (inside) and direction first calculate distance to surface
128// go -90� to direction using POS as origin and check if inside/outside
129// if inside rotate outward, if outside rotate inward
130// iterate until close enough to surface, then store point1
131// repeat for 90� and store point2
132// use point1 and point2 on surface to calculate normal
133template <typename S>
134bool IndicatorF2D<S>::normal(Vector<S,2>& normal, const Vector<S,2>& origin, const Vector<S,2>& direction, int iC)
135{
136 //OstreamManager clout(std::cout,"normal");
137 //clout << "Calculating IndicatorF2D Normal " << std::endl;
138 bool originValue;
139 (*this)(&originValue, origin.data());
140 Vector<S,2> currentPoint(origin);
141
142 S precision = .0001;
143
144 S dist;
145 distance(dist, origin, direction, iC);
146
147
148 Vector<S,2> POS(origin + dist*direction*(1/norm(direction))); //Point on Surface
149
150 Vector<S,2> point1;
151 Vector<S,2> point2;
152
153 bool currentValue;
154
155 for (int n: {
156 -90,90
157 }) { //std::range<int> n = {-90, 90};
158 S rotate(n);
159 S pitch(rotate/2.);
160 while (util::abs(pitch) >= precision) {
161 S theta( util::degreeToRadian(rotate) );
162
163 Vector<S,2> vec(util::cos(theta)*direction[0]+util::sin(theta)*direction[1],-util::sin(theta)*direction[0]+util::cos(theta)*direction[1]);
164 currentPoint = POS + vec;
165 (*this)(&currentValue, currentPoint.data());
166
167 if (currentValue == originValue) {
168 rotate -= pitch;
169 }
170 else {
171 rotate += pitch;
172 }
173 pitch /= 2.;
174 }
175
176 if (n == -90) {
177 point1 = currentPoint;
178 }
179 else if (n == 90) {
180 point2 = currentPoint;
181 }
182 }
183 // Calculate Normal from point1 and point2
184 normal = Vector<S,2>((point2[1] - point1[1]), (-1)*(point2[0] - point1[0]));
185
186
187 //S dist;
188 //Vector<S,2> dist;
189 //distance(dist, origin, direction, iC);
190 //normal = Vector<S,2>(dist);
191 return true;
192}
193
194template <typename S>
196{
197 return point >= _myMin && point <= _myMax;
198}
199
200template <typename S>
201bool IndicatorF2D<S>::operator() (const S input[])
202{
203 return this->signedDistance(input) <= 0;
204}
205
206template <typename S>
208 : _f(f)
209{
210 this->_myMin = _f->getMin();
211 this->_myMax = _f->getMax();
212}
213
214template <typename S>
216{
217 // TODO: Add fallback algorithm here
218 assert(false);
219 return std::numeric_limits<double>::quiet_NaN();
220}
221
222template <typename S>
224{
225 return util::surfaceNormal(pos, meshSize,
226 [&](const Vector<S,2>& pos) {
227 return this->signedDistance(pos);
228 });
229}
230
231template <typename S>
233 std::function<Vector<S,2>(const Vector<S,2>&)> transformPos)
234{
235 return this->surfaceNormal(transformPos(pos), meshSize);
236}
237
238template <typename S>
239bool IndicatorF2D<S>::operator() (bool output[1], const S input[2])
240{
241 output[0] = this->operator()(input);
242 return output[0];
243}
244
245
246template <typename S>
247bool IndicatorIdentity2D<S>::operator() (bool output[1], const S input[2])
248{
249 return (_f)->operator()(output, input);
250}
251
252} // namespace olb
253
254#endif
GenericF is a base class, that can represent continuous as well as discrete functions.
Definition genericF.h:50
virtual bool operator()(const S input[])
Indicator specific function operator overload.
virtual Vector< S, 1 > & getMin()
virtual Vector< S, 1 > & getMax()
IndicatorF2D is an application from .
virtual bool distance(S &distance, const Vector< S, 2 > &origin, S precision, const Vector< S, 2 > &direction)
returns false or true and pos. distance if there was one found for an given origin and direction
Vector< S, 2 > _myMin
Vector< S, 2 > _myMax
virtual Vector< S, 2 > surfaceNormal(const Vector< S, 2 > &pos, const S meshSize)
Return surface normal.
virtual Vector< S, 2 > & getMin()
virtual bool operator()(bool output[1], const S input[2])
Returns true if input is inside the indicator.
virtual bool normal(Vector< S, 2 > &normal, const Vector< S, 2 > &origin, const Vector< S, 2 > &direction, int iC=-1)
returns true and the normal if there was one found for an given origin and direction
virtual Vector< S, 2 > & getMax()
virtual S signedDistance(const Vector< S, 2 > &input)
Returns signed distance to the nearest point on the indicator surface.
bool isInsideBox(Vector< S, 2 > point)
Returns true if point is inside a cube with corners _myMin and _myMax
IndicatorIdentity2D(std::shared_ptr< IndicatorF2D< S > > f)
bool operator()(bool output[1], const S input[2])
Returns true if input is inside the indicator.
std::shared_ptr< IndicatorF2D< S > > _f
Plain old scalar vector.
Definition vector.h:47
constexpr const T * data() const any_platform
Definition vector.h:161
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
bool distance(S &distance, const Vector< S, D > &origin, const Vector< S, D > &direction, S precision, S pitch, F1 isInside, F2 isInsideBoundingBox)
Vector< S, D > surfaceNormal(const Vector< S, D > &pos, const S meshSize, F1 sdf)
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
decltype(Vector< decltype(util::sqrt(T())), D >()) degreeToRadian(const Vector< T, D > &angle)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578
Top level namespace for all of OpenLB.
constexpr T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.