OpenLB 1.7
Loading...
Searching...
No Matches
indicCalc2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014-2016 Mathias J. Krause, Cyril Masquelier,
4 * Benjamin Förster, Albert Mink
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef INDIC_CALC_2D_HH
26#define INDIC_CALC_2D_HH
27
28#include "indicCalc2D.h"
29
30namespace olb {
31
32
34template <typename S>
36 : _f(f), _g(g)
37{
38 this->_myMin[0] = util::min(f.getMin()[0], g.getMin()[0]);
39 this->_myMax[0] = util::max(f.getMax()[0], g.getMax()[0]);
40 std::swap(f._ptrCalcC, this->_ptrCalcC);
41}
42
43
44template <typename S>
48
49// returns 1 if( f==1 || g==1 ) UNION
50template <typename S>
51bool IndicPlus1D<S>::operator() (bool output[], const S input[])
52{
53 this->_f(output, input);
54 bool tmp;
55 this->_g(&tmp, input);
56 output[0] |= tmp;
57 return true;
58}
59
60
61template <typename S>
65
66// returns 1 if( f==1 && g==0 ) WITHOUT
67template <typename S>
68bool IndicMinus1D<S>::operator()(bool output[], const S input[])
69{
70 this->_f(output, input);
71 bool tmp;
72 this->_g(&tmp, input);
73 output[0] &= !tmp;
74 return true;
75}
76
77
78
79template <typename S>
83
84// returns 1 if( f==1 && g==1 ) INTERSECTION
85template <typename S>
86bool IndicMultiplication1D<S>::operator() (bool output[], const S input[])
87{
88 this->_f(output, input);
89 bool tmp;
90 this->_g(&tmp, input);
91 output[0] &= tmp;
92 return true;
93}
94
95
96
97template <typename S>
99{
100 auto tmp = std::make_shared< IndicPlus1D<S> >(*this,rhs);
101 this->_ptrCalcC = tmp;
102 return *tmp;
103}
104
105template <typename S>
107{
108 auto tmp = std::make_shared< IndicMinus1D<S> >(*this,rhs);
109 this->_ptrCalcC = tmp;
110 return *tmp;
111}
112
113template <typename S>
115{
116 auto tmp = std::make_shared< IndicMultiplication1D<S> >(*this,rhs);
117 this->_ptrCalcC = tmp;
118 return *tmp;
119}
120
121
122
123
125template <typename S, template<typename U> class F>
126IndicCalc2D<S,F>::IndicCalc2D(std::shared_ptr<IndicatorF2D<S>> f, std::shared_ptr<IndicatorF2D<S>> g)
127 : _f(f), _g(g)
128{ }
129
130template <typename S, template<typename U> class F>
131bool IndicCalc2D<S,F>::operator()( bool output[], const S input[2])
132{
133 // componentwise operation on equidimensional functors
134 bool* outputF = output;
135 _f->operator()(outputF, input);
136
137 bool outputG[this->getTargetDim()];
138 _g->operator()(outputG, input);
139
140 for (int i = 0; i < this->getTargetDim(); i++) {
141 output[i] = F<S>()(outputF[i], outputG[i]);
142 }
143 return output;
144}
145
146template <typename S>
147IndicPlus2D<S>::IndicPlus2D(std::shared_ptr<IndicatorF2D<S>> f, std::shared_ptr<IndicatorF2D<S>> g)
148 : IndicCalc2D<S,util::plus>(f, g)
149{
150 for ( int i=0; i<2; i++) {
151 this->_myMin[i] = util::min(this->_f->getMin()[i], this->_g->getMin()[i]);
152 this->_myMax[i] = util::max(this->_f->getMax()[i], this->_g->getMax()[i]);
153 }
154}
155
156template <typename S>
158{
159 return sdf::unify(this->_f->signedDistance(input), this->_g->signedDistance(input));
160}
161
162
163template <typename S>
164IndicMinus2D<S>::IndicMinus2D(std::shared_ptr<IndicatorF2D<S>> f, std::shared_ptr<IndicatorF2D<S>> g)
165 : IndicCalc2D<S,util::minus>(f, g)
166{
167 // TODO: Improve
168 for ( int i=0; i<2; i++) {
169 this->_myMin[i] = this->_f->getMin()[i];
170 this->_myMax[i] = this->_f->getMax()[i];
171 }
172}
173
174template <typename S>
176{
177 return sdf::subtraction(this->_f->signedDistance(input), this->_g->signedDistance(input));
178}
179
180
181template <typename S>
183 : IndicCalc2D<S,util::multiplies>(f, g)
184{
185 for ( int i=0; i<2; i++) {
186 this->_myMin[i] = util::max(this->_f->getMin()[i], this->_g->getMin()[i]);
187 this->_myMax[i] = util::min(this->_f->getMax()[i], this->_g->getMax()[i]);
188 }
189}
190
191template <typename S>
193{
194 return sdf::intersection(this->_f->signedDistance(input), this->_g->signedDistance(input));
195}
196
197
198
199
200
202template<typename S, template <typename U> class F1, template <typename V> class F2,
203 typename>
204std::shared_ptr<IndicatorF2D<S>> operator+(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
205{
206 return std::make_shared<IndicPlus2D<S>>(lhs, rhs);
207}
208
209template<typename S, template <typename U> class F1, template <typename V> class F2,
210 typename>
211std::shared_ptr<IndicatorF2D<S>> operator-(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
212{
213 return std::make_shared<IndicMinus2D<S>>(lhs, rhs);
214}
215
216template<typename S, template <typename U> class F1, template <typename V> class F2,
217 typename>
218std::shared_ptr<IndicatorF2D<S>> operator*(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
219{
220 return std::make_shared<IndicMultiplication2D<S>>(lhs, rhs);
221}
222
223// template specialization for indicatorIdentity
224template<typename S, template <typename U> class F1, template <typename V> class F2,
225 typename>
226std::shared_ptr<IndicatorF2D<S>> operator+(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
227{
228 return lhs._f + rhs;
229}
230
231template<typename S, template <typename U> class F1, template <typename V> class F2,
232 typename>
233std::shared_ptr<IndicatorF2D<S>> operator-(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
234{
235 return lhs._f - rhs;
236}
237
238template<typename S, template <typename U> class F1, template <typename V> class F2,
239 typename>
240std::shared_ptr<IndicatorF2D<S>> operator*(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
241{
242 return lhs._f * rhs;
243}
244
245
246} // end namespace olb
247
248#endif
std::shared_ptr< GenericF< T, S > > _ptrCalcC
memory management, frees resouces (calcClass)
Definition genericF.h:71
IndicCalc1D //////////////////////////////// arithmetic helper class for Indicator 1d functors.
Definition indicCalc2D.h:44
IndicCalc1D(IndicatorF1D< S > &f, IndicatorF1D< S > &g)
indicCalc2D //////////////////////////////// arithmetic helper class for Indicator 2D functors
Definition indicCalc2D.h:82
std::shared_ptr< IndicatorF2D< S > > _f
Definition indicCalc2D.h:85
bool operator()(bool output[], const S input[3])
IndicCalc2D(std::shared_ptr< IndicatorF2D< S > > f, std::shared_ptr< IndicatorF2D< S > > g)
IndicMinus1D(IndicatorF1D< S > &f, IndicatorF1D< S > &g)
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
IndicMinus2D(std::shared_ptr< IndicatorF2D< S > > f, std::shared_ptr< IndicatorF2D< S > > g)
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
IndicMultiplication1D(IndicatorF1D< S > &f, IndicatorF1D< S > &g)
IndicMultiplication2D(std::shared_ptr< IndicatorF2D< S > > f, std::shared_ptr< IndicatorF2D< S > > g)
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
IndicPlus1D(IndicatorF1D< S > &f, IndicatorF1D< S > &g)
bool operator()(bool output[], const S input[]) override
has to be implemented for 'every' derived class
IndicPlus2D(std::shared_ptr< IndicatorF2D< S > > f, std::shared_ptr< IndicatorF2D< S > > g)
S signedDistance(const Vector< S, 2 > &input) override
Returns signed distance to the nearest point on the indicator surface.
IndicatorF1D is an application from .
IndicatorF1D< S > & operator-(IndicatorF1D< S > &rhs)
Vector< S, 1 > _myMin
IndicatorF1D< S > & operator*(IndicatorF1D< S > &rhs)
Vector< S, 1 > _myMax
virtual Vector< S, 1 > & getMin()
virtual Vector< S, 1 > & getMax()
IndicatorF1D< S > & operator+(IndicatorF1D< S > &rhs)
IndicatorF2D is an application from .
Vector< S, 2 > _myMin
Vector< S, 2 > _myMax
Plain old scalar vector.
Definition vector.h:47
T intersection(T a, T b) any_platform
Volume which is shared by a and b creates a new object.
Definition sdf.h:341
T unify(T a, T b) any_platform
Volume of a and volume of b are combined as a new object.
Definition sdf.h:329
T subtraction(T a, T b) any_platform
Volume of a is subtracted from b.
Definition sdf.h:317
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:124
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
Top level namespace for all of OpenLB.
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator-(U a, const ScalarVector< T, D, IMPL > &b) any_platform
Definition vector.h:297
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator+(U a, const ScalarVector< T, D, IMPL > &b) any_platform
Definition vector.h:265
constexpr meta::enable_if_arithmetic_t< U, Vector< decltype(T{} *U{}), D > > operator*(U a, const ScalarVector< T, D, IMPL > &b) any_platform
Definition vector.h:329