OpenLB 1.7
Loading...
Searching...
No Matches
superCalcF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014-2017 Albert Mink, Mathias J. Krause,
4 * Adrian Kummerlaender
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 SUPER_CALC_F_2D_HH
26#define SUPER_CALC_F_2D_HH
27
28#include "superCalcF2D.h"
29#include "blockCalcF2D.h"
30#include "superConst2D.h"
31
32namespace olb {
33
34
35template <typename T, typename W, template<typename> class F>
38 : SuperF2D<T,W>(
39 f->getSuperStructure(),
40 f->getTargetDim() > g->getTargetDim() ? f->getTargetDim() : g->getTargetDim()),
41 _f(std::move(f)),
42 _g(std::move(g))
43{
45 _f->getTargetDim() == _g->getTargetDim() || _f->getTargetDim() == 1 || _g->getTargetDim() == 1,
46 "Componentwise operation must be well defined.");
47
48 this->getName() = "(" + _f->getName() + F<T>::symbol + _g->getName() + ")";
49
50 std::swap(_f->_ptrCalcC, this->_ptrCalcC);
51
52 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
53
54 if ( _f->getBlockFSize() == load.size() ) {
55 if ( _g->getBlockFSize() == load.size() ) {
56 // both functors expose the correct count of block level functors
57 for (int iC = 0; iC < load.size(); ++iC) {
58 this->_blockF.emplace_back(
59 new BlockCalcF2D<W,F>(_f->getBlockF(iC), _g->getBlockF(iC))
60 );
61 }
62 }
63 else {
64 // operate on super functor `g` and block level functors provided by `f`
65 for (int iC = 0; iC < load.size(); ++iC) {
66 this->_blockF.emplace_back(
67 new BlockCalcF2D<W,F>(_f->getBlockF(iC), *g, load.glob(iC))
68 );
69 }
70 }
71 }
72 else if ( _g->getBlockFSize() == load.size() ) {
73 // operate on block level functors provided by `f` and super functor `g`
74 for (int iC = 0; iC < load.size(); ++iC) {
75 this->_blockF.emplace_back(
76 new BlockCalcF2D<W,F>(*f, load.glob(iC), _g->getBlockF(iC))
77 );
78 }
79 }
80}
81
82template <typename T, typename W, template<typename> class F>
85 std::unique_ptr<SuperF2D<T,W>>(new SuperConst2D<T,W>(g->getSuperStructure(), scalar)),
86 std::forward<decltype(g)>(g))
87{ }
88
89template <typename T, typename W, template<typename> class F>
92 std::forward<decltype(f)>(f),
93 std::unique_ptr<SuperF2D<T,W>>(new SuperConst2D<T,W>(f->getSuperStructure(), scalar)))
94{ }
95
96template <typename T, typename W, template<typename> class F>
97bool SuperCalcF2D<T,W,F>::operator()(W output[], const int input[])
98{
99 if ( _f->getTargetDim() == 1 || _g->getTargetDim() == 1 ) {
100 // scalar operation
101 W scalar;
102 if ( _f->getTargetDim() == 1 ) {
103 // apply the scalar f to possibly multidimensional g
104 _f(&scalar, input);
105 _g(output, input);
106
107 for (int i = 0; i < this->getTargetDim(); i++) {
108 output[i] = F<T>()(scalar, output[i]);
109 }
110 }
111 else {
112 // apply scalar g to possibly multidimensional f
113 _f(output, input);
114 _g(&scalar, input);
115
116 for (int i = 0; i < this->getTargetDim(); i++) {
117 output[i] = F<T>()(output[i], scalar);
118 }
119 }
120 }
121 else {
122 // componentwise operation on equidimensional functors
123 W* outputF = output;
124 W outputG[this->getTargetDim()];
125
126 _f(outputF, input);
127 _g(outputG, input);
128
129 for (int i = 0; i < this->getTargetDim(); i++) {
130 output[i] = F<T>()(outputF[i], outputG[i]);
131 }
132 }
133 return true;
134}
135
136
137template <typename T, typename W>
138std::shared_ptr<SuperF2D<T,W>> operator+(std::shared_ptr<SuperF2D<T,W>> lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
139{
140 return std::shared_ptr<SuperF2D<T,W>>(
141 new SuperCalcPlus2D<T,W>(std::move(lhs), std::move(rhs)));
142}
143
144template <typename T, typename W>
145std::shared_ptr<SuperF2D<T,W>> operator+(std::shared_ptr<SuperF2D<T,W>> lhs, W rhs)
146{
147 return std::shared_ptr<SuperF2D<T,W>>(
148 new SuperCalcPlus2D<T,W>(std::move(lhs), rhs));
149}
150
151template <typename T, typename W>
152std::shared_ptr<SuperF2D<T,W>> operator+(W lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
153{
154 return std::shared_ptr<SuperF2D<T,W>>(
155 new SuperCalcPlus2D<T,W>(lhs, std::move(rhs)));
156}
157
158template <typename T, typename W>
159std::shared_ptr<SuperF2D<T,W>> operator-(std::shared_ptr<SuperF2D<T,W>> lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
160{
161 return std::shared_ptr<SuperF2D<T,W>>(
162 new SuperCalcMinus2D<T,W>(std::move(lhs), std::move(rhs)));
163}
164
165template <typename T, typename W>
166std::shared_ptr<SuperF2D<T,W>> operator-(std::shared_ptr<SuperF2D<T,W>> lhs, W rhs)
167{
168 return std::shared_ptr<SuperF2D<T,W>>(
169 new SuperCalcMinus2D<T,W>(std::move(lhs), rhs));
170}
171
172template <typename T, typename W>
173std::shared_ptr<SuperF2D<T,W>> operator-(W lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
174{
175 return std::shared_ptr<SuperF2D<T,W>>(
176 new SuperCalcMinus2D<T,W>(lhs, std::move(rhs)));
177}
178
179template <typename T, typename W>
180std::shared_ptr<SuperF2D<T,W>> operator*(std::shared_ptr<SuperF2D<T,W>> lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
181{
182 return std::shared_ptr<SuperF2D<T,W>>(
183 new SuperCalcMultiplication2D<T,W>(std::move(lhs), std::move(rhs)));
184}
185
186template <typename T, typename W>
187std::shared_ptr<SuperF2D<T,W>> operator*(std::shared_ptr<SuperF2D<T,W>> lhs, W rhs)
188{
189 return std::shared_ptr<SuperF2D<T,W>>(
190 new SuperCalcMultiplication2D<T,W>(std::move(lhs), rhs));
191}
192
193template <typename T, typename W>
194std::shared_ptr<SuperF2D<T,W>> operator*(W lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
195{
196 return std::shared_ptr<SuperF2D<T,W>>(
197 new SuperCalcMultiplication2D<T,W>(lhs, std::move(rhs)));
198}
199
200template <typename T, typename W>
201std::shared_ptr<SuperF2D<T,W>> operator/(std::shared_ptr<SuperF2D<T,W>> lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
202{
203 return std::shared_ptr<SuperF2D<T,W>>(
204 new SuperCalcDivision2D<T,W>(std::move(lhs), std::move(rhs)));
205}
206
207template <typename T, typename W>
208std::shared_ptr<SuperF2D<T,W>> operator/(std::shared_ptr<SuperF2D<T,W>> lhs, W rhs)
209{
210 return std::shared_ptr<SuperF2D<T,W>>(
211 new SuperCalcDivision2D<T,W>(std::move(lhs), rhs));
212}
213
214template <typename T, typename W>
215std::shared_ptr<SuperF2D<T,W>> operator/(W lhs, std::shared_ptr<SuperF2D<T,W>> rhs)
216{
217 return std::shared_ptr<SuperF2D<T,W>>(
218 new SuperCalcDivision2D<T,W>(lhs, std::move(rhs)));
219}
220
221
222template <typename T, typename W>
224{
225 auto tmp = std::make_shared< SuperCalcPlus2D<T,W> >(*this,rhs);
226 this->_ptrCalcC = tmp;
227 return *tmp;
228}
229
230template <typename T, typename W>
232{
233 auto tmp = std::make_shared< SuperCalcMinus2D<T,W> >(*this,rhs);
234 this->_ptrCalcC = tmp;
235 return *tmp;
236}
237
238template <typename T, typename W>
240{
241 auto tmp = std::make_shared< SuperCalcMultiplication2D<T,W> >(*this,rhs);
242 this->_ptrCalcC = tmp;
243 return *tmp;
244}
245
246template <typename T, typename W>
248{
249 auto tmp = std::make_shared< SuperCalcDivision2D<T,W> >(*this,rhs);
250 this->_ptrCalcC = tmp;
251 return *tmp;
252}
253
254
255} // end namespace olb
256
257#endif
Block level arithmetic operations for BlockF2D functors.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
std::string & getName()
read and write access to name
Definition genericF.hh:51
Base class for all LoadBalancer.
int glob(int loc) const
Arithmetic operations for SuperF2D functors.
FunctorPtr< SuperF2D< T, W > > _g
SuperCalcF2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperF2D< T, W > > &&g)
bool operator()(W output[], const int input[]) override
has to be implemented for 'every' derived class
FunctorPtr< SuperF2D< T, W > > _f
Functor returning a constant vector for all inputs.
represents all functors that operate on a SuperStructure<T,2> in general
SuperF2D< T, W > & operator-(SuperF2D< T, W > &rhs)
SuperF2D< T, W > & operator+(SuperF2D< T, W > &rhs)
SuperF2D< T, W > & operator*(SuperF2D< T, W > &rhs)
std::vector< std::unique_ptr< BlockF2D< W > > > _blockF
Super functors may consist of several BlockF2D<W> derived functors.
SuperF2D< T, W > & operator/(SuperF2D< T, W > &rhs)
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
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator/(const ScalarVector< T, D, IMPL > &a, U b) any_platform
Definition vector.h:357
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45