OpenLB 1.7
Loading...
Searching...
No Matches
indicComb3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Albert Mink, Jan E. Marquardt, Anna Husfeldt
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 INDIC_COMB_3D_HH
25#define INDIC_COMB_3D_HH
26
27#include "indicComb3D.h"
28
29namespace olb {
30
31
32template <typename S, template<typename U> class F>
33IndicComb3D<S,F>::IndicComb3D(std::shared_ptr<IndicatorF3D<S>> f, std::shared_ptr<IndicatorF3D<S>> g)
34 : _f(f), _g(g)
35{ }
36
37template <typename S, template<typename U> class F>
38bool IndicComb3D<S,F>::operator()( bool output[], const S input[3])
39{
40 // componentwise operation on equidimensional functors
41 bool* outputF = output;
42 _f->operator()(outputF, input);
43
44 bool outputG[this->getTargetDim()];
45 _g->operator()(outputG, input);
46
47 for (int i = 0; i < this->getTargetDim(); i++) {
48 output[i] = F<S>()(outputF[i], outputG[i]);
49 }
50 return output;
51}
52
53template <typename S>
54IndicPlus3D<S>::IndicPlus3D(std::shared_ptr<IndicatorF3D<S>> f, std::shared_ptr<IndicatorF3D<S>> g)
55 : IndicComb3D<S,util::plus>(f, g)
56{
57 for ( int i=0; i<3; i++) {
58 this->_myMin[i] = util::min(this->_f->getMin()[i], this->_g->getMin()[i]);
59 this->_myMax[i] = util::max(this->_f->getMax()[i], this->_g->getMax()[i]);
60 }
61}
62
63template <typename S>
65{
66 return sdf::unify(this->_f->signedDistance(input), this->_g->signedDistance(input));
67}
68
69
70template <typename S>
71IndicMinus3D<S>::IndicMinus3D(std::shared_ptr<IndicatorF3D<S>> f, std::shared_ptr<IndicatorF3D<S>> g)
72 : IndicComb3D<S,util::minus>(f, g)
73{
74 // TODO: Improve
75 for ( int i=0; i<3; i++) {
76 this->_myMin[i] = this->_f->getMin()[i];
77 this->_myMax[i] = this->_f->getMax()[i];
78 }
79}
80
81template <typename S>
83{
84 return sdf::subtraction(this->_f->signedDistance(input), this->_g->signedDistance(input));
85}
86
87
88template <typename S>
90 : IndicComb3D<S,util::multiplies>(f, g)
91{
92 for ( int i=0; i<3; i++) {
93 this->_myMin[i] = util::max(this->_f->getMin()[i], this->_g->getMin()[i]);
94 this->_myMax[i] = util::min(this->_f->getMax()[i], this->_g->getMax()[i]);
95 }
96}
97
98template <typename S>
100{
101 return sdf::intersection(this->_f->signedDistance(input), this->_g->signedDistance(input));
102}
103
104
106template<typename S, template <typename U> class F1, template <typename V> class F2,
107 typename>
108std::shared_ptr<IndicatorF3D<S>> operator+(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
109{
110 return std::make_shared<IndicPlus3D<S>>(lhs, rhs);
111}
112
113template<typename S, template <typename U> class F1, template <typename V> class F2,
114 typename>
115std::shared_ptr<IndicatorF3D<S>> operator-(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
116{
117 return std::make_shared<IndicMinus3D<S>>(rhs, lhs);
118}
119
120template<typename S, template <typename U> class F1, template <typename V> class F2,
121 typename>
122std::shared_ptr<IndicatorF3D<S>> operator*(std::shared_ptr<F1<S>> lhs, std::shared_ptr<F2<S>> rhs)
123{
124 return std::make_shared<IndicMultiplication3D<S>>(lhs, rhs);
125}
126
127// template specialization for indicatorIdentity
128template<typename S, template <typename U> class F1, template <typename V> class F2,
129 typename>
130std::shared_ptr<IndicatorF3D<S>> operator+(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
131{
132 return lhs._f + rhs;
133}
134
135template<typename S, template <typename U> class F1, template <typename V> class F2,
136 typename>
137std::shared_ptr<IndicatorF3D<S>> operator-(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
138{
139 return lhs._f - rhs;
140}
141
142template<typename S, template <typename U> class F1, template <typename V> class F2,
143 typename>
144std::shared_ptr<IndicatorF3D<S>> operator*(F1<S> & lhs, std::shared_ptr<F2<S>> rhs)
145{
146 return lhs._f * rhs;
147}
148
149
150} // end namespace olb
151
152#endif
IndicComb3D //////////////////////////////// arithmetic helper class for Indicator 3d functors.
Definition indicComb3D.h:43
std::shared_ptr< IndicatorF3D< S > > _f
Definition indicComb3D.h:46
IndicComb3D(std::shared_ptr< IndicatorF3D< S > > f, std::shared_ptr< IndicatorF3D< S > > g)
bool operator()(bool output[], const S input[3])
S signedDistance(const Vector< S, 3 > &input) override
Returns signed distance to the nearest point on the indicator surface.
IndicMinus3D(std::shared_ptr< IndicatorF3D< S > > f, std::shared_ptr< IndicatorF3D< S > > g)
IndicMultiplication3D(std::shared_ptr< IndicatorF3D< S > > f, std::shared_ptr< IndicatorF3D< S > > g)
S signedDistance(const Vector< S, 3 > &input) override
Returns signed distance to the nearest point on the indicator surface.
S signedDistance(const Vector< S, 3 > &input) override
Returns signed distance to the nearest point on the indicator surface.
IndicPlus3D(std::shared_ptr< IndicatorF3D< S > > f, std::shared_ptr< IndicatorF3D< S > > g)
IndicatorF3D is an application from .
Vector< S, 3 > _myMin
Vector< S, 3 > _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