OpenLB 1.7
Loading...
Searching...
No Matches
superBaseF3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012-2017 Lukas Baron, Tim Dornieden, Mathias J. Krause,
4 * Albert Mink, Benjamin Förster, 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_BASE_F_3D_HH
26#define SUPER_BASE_F_3D_HH
27
28#include "superBaseF3D.h"
29#include "blockBaseF3D.h"
30
31namespace olb {
32
33template <typename T, typename W>
34SuperF3D<T,W>::SuperF3D(SuperStructure<T,3>& superStructure, int targetDim)
35 : GenericF<W,int>(targetDim,4), _superStructure(superStructure) { }
36
37template <typename T, typename W>
39{
40 return _superStructure;
41}
42
43template <typename T, typename W>
45{
46 OLB_ASSERT(_blockF.size() < INT32_MAX,
47 "cast from std::size_t to int unsafe");
48 return _blockF.size();
49}
50
51template <typename T, typename W>
53{
54 OLB_ASSERT(iCloc < int(_blockF.size()) && iCloc >= 0,
55 "block functor index outside bounds");
56 return *(_blockF[iCloc]);
57}
59template <typename T, typename W>
60bool SuperF3D<T,W>::operator()(W output[], const int input[])
61{
62
63 LoadBalancer<T>& load = _superStructure.getLoadBalancer();
64
65 if (load.isLocal(input[0])) {
66 const int loc = load.loc(input[0]);
67
68 return this->getBlockF(loc)(output, &input[1]);
69 }
70 else {
71 return false;
72 }
73
74}
75
76
77template <typename T, typename BaseType>
79 : SuperF3D<T,BaseType>(superData, superData.getDataSize()),
80 _superData(superData)
81{
82 for (int iC = 0; iC < _superData.getLoadBalancer().size(); ++iC) {
83 this->_blockF.emplace_back(new BlockDataF3D<T,BaseType>(_superData.getBlock(iC)));
84 }
85}
86
87template <typename T, typename BaseType>
88bool SuperDataF3D<T,BaseType>::operator() (BaseType output[], const int input[])
89{
90 const auto& load = _superData.getLoadBalancer();
91 if (load.rank(input[0]) == singleton::mpi().getRank()) {
92 return this->getBlockF(load.loc(input[0]))(output, &input[1]);
93 }
94 else {
95 return false;
96 }
97}
98
99template <typename T, typename BaseType>
104
105
106
107template <typename T, typename W>
109 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
110 _f(std::move(f))
111{
112 this->getName() = "Id(" + _f->getName() + ")";
114 for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
115 this->_blockF.emplace_back(
116 new BlockIdentity3D<W>(_f->getBlockF(iC)));
117 }
118}
119
120template <typename T, typename W>
121bool SuperIdentity3D<T,W>::operator()(W output[], const int input[])
122{
123 return _f(output, input);
127
128template <typename T, typename W>
130 FunctorPtr<SuperF3D<T,W>>&& f, int extractDim)
131 : SuperF3D<T,W>(f->getSuperStructure(), 1),
132 _f(std::move(f)),
133 _extractDim(extractDim)
134{
135 this->getName() = _f->getName();
136
137 for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
138 this->_blockF.emplace_back(
139 new BlockExtractComponentF3D<W>(_f->getBlockF(iC), extractDim));
140 }
141}
142
143template <typename T, typename W>
145{
146 return _extractDim;
147}
148
149template <typename T, typename W>
150bool SuperExtractComponentF3D<T,W>::operator()(W output[], const int input[])
151{
152 std::vector<T> outTmp(_f->getTargetDim(), T{});
153 _f(outTmp.data(), input);
154 output[0] = outTmp[_extractDim];
155 return true;
156}
157
158
159template <typename T, typename W>
161 FunctorPtr<SuperF3D<T,W>>&& f, int extractDim,
162 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
163 : SuperExtractComponentF3D<T,W>(std::forward<decltype(f)>(f), extractDim),
164 _indicatorF(std::move(indicatorF))
165{
166 this->getName() = f->getName();
167
168 for (int iC = 0; iC < f->getBlockFSize(); ++iC) {
169 this->_blockF.emplace_back(
171 f->getBlockF(iC), extractDim,
172 _indicatorF->getBlockIndicatorF(iC))
173 );
174 }
175}
176
177template <typename T, typename W>
178bool SuperExtractComponentIndicatorF3D<T,W>::operator()(W output[], const int input[])
179{
180 output[0] = W{};
181 if (_indicatorF(input)) {
182 return SuperExtractComponentF3D<T,W>::operator()(output, input);
183 }
184 return true;
185}
186
188template <typename T, typename W>
191 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
192 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
193 _f(std::move(f)),
194 _indicatorF(std::move(indicatorF))
195{
196 this->getName() = _f->getName();
197
198 for (int iC = 0; iC < f->getBlockFSize(); ++iC) {
199 this->_blockF.emplace_back(
201 f->getBlockF(iC),
202 _indicatorF->getBlockIndicatorF(iC))
203 );
204 }
205}
206
207template <typename T, typename W>
208bool SuperExtractIndicatorF3D<T,W>::operator()(W output[], const int input[])
209{
210 for (int i = 0; i < this->getTargetDim(); ++i) {
211 output[i] = W{};
212 }
213 if (_indicatorF(input)) {
214 _f(output, input);
215 }
216 return true;
217}
218
219
220template <typename T, typename W, typename W2>
223 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
224 _f(std::move(f))
225{
226 this->getName() = _f->getName();
227
228 for (int iC = 0; iC < f->getBlockFSize(); ++iC) {
229 this->_blockF.emplace_back(
231 f->getBlockF(iC))
232 );
233 }
234}
235
236template <typename T, typename W, typename W2>
237bool SuperTypecastF3D<T,W,W2>::operator()(W output[], const int input[])
238{
239 W2 result[this->getTargetDim()];
240 _f(result, input);
241 for (int i = 0; i < this->getTargetDim(); ++i) {
242 output[i] = static_cast<W>(result[i]);
243 }
244 return true;
245}
246
247
248template <typename T, typename W>
250 SuperIndicatorF3D<T>& indicatorF,
251 W defaultValue)
252 : SuperF3D<T,W>(f.getSuperStructure(),f.getTargetDim() ),
253 _f(f),
254 _indicatorF(indicatorF),
255 _defaultValue(defaultValue)
256{
257 this->getName() = _f.getName() + std::string("_on_") + _indicatorF.getName();
258 std::swap( _f._ptrCalcC, this->_ptrCalcC );
259}
260
261template <typename T, typename W>
262bool SuperIdentityOnSuperIndicatorF3D<T,W>::operator()(W output[], const int input[])
263{
264 bool indic;
265 _indicatorF(&indic, input);
266 if (indic) {
267 _f(output, input);
268 }
269 else {
270 for (int i=0; i<_f.getTargetDim(); i++) {
271 output[i] = _defaultValue;
272 }
273 }
274 return true;
275}
276
277
278template <typename T, typename DESCRIPTOR>
280 int targetDim)
281 : SuperF3D<T,T>(superLattice, targetDim), _sLattice(superLattice) { }
282
283template <typename T, typename DESCRIPTOR>
288
289template<typename T, typename DESCRIPTOR>
291 T output[], const int input[])
292{
293 auto& load = this->_sLattice.getLoadBalancer();
294
295 if (load.isLocal(input[0])) {
296 const int loc = load.loc(input[0]);
297
298 return this->getBlockF(loc)(output, &input[1]);
299 }
300 else {
301 return false;
302 }
303}
304
305template <typename T, typename DESCRIPTOR>
308 : SuperLatticeF3D<T,DESCRIPTOR>(f->getSuperLattice(), f->getTargetDim()),
309 _f(std::move(f))
310{
311 this->getName() = "Id(" + _f->getName() + ")";
312
313 for (int iC = 0; iC < _f->getBlockFSize(); ++iC) {
314 this->_blockF.emplace_back(
316 static_cast<BlockLatticeF3D<T,DESCRIPTOR>&>(_f->getBlockF(iC))));
317 }
318}
319
320template <typename T, typename DESCRIPTOR>
321bool SuperLatticeIdentity3D<T,DESCRIPTOR>::operator()(T output[], const int input[])
322{
323 return _f(output, input);
324}
325
326template <typename T, typename DESCRIPTOR>
329 int targetDim)
330 : SuperLatticeF3D<T,DESCRIPTOR>(sLattice, targetDim), _converter(converter) { }
331
332template <typename T, typename DESCRIPTOR>
334{
335 return this->_converter;
336}
337template <typename T, typename DESCRIPTOR, typename TDESCRIPTOR>
340 int targetDim)
341 : SuperLatticeF3D<T,TDESCRIPTOR>(sLattice, targetDim), _converter(converter) { }
342
343template <typename T, typename DESCRIPTOR, typename TDESCRIPTOR>
348
349template <typename T, typename DESCRIPTOR>
353 : SuperLatticeF3D<T,DESCRIPTOR>(f0.getSuperLattice(), 3), _f0(f0), _f1(f1), _f2(f2)
354{
355 this->getName() = "composedSuperLatticeF3D";
356}
357
358template <typename T, typename DESCRIPTOR>
359bool ComposedSuperLatticeF3D<T,DESCRIPTOR>::operator() (T output[], const int input[])
360{
361 T tmp[3] = {};
362 SuperIdentity3D<T,T> ff0(_f0), ff1(_f1), ff2(_f2);
363 _f0(tmp,input);
364 output[0]=tmp[0];
365 _f1(tmp,input);
366 output[1]=tmp[0];
367 _f2(tmp,input);
368 output[2]=tmp[0];
369 return true;
370}
371
372
373} // end namespace olb
374
375#endif
BlockDataF3D can store data of any BlockFunctor3D.
functor to extract one component
functor to extract one component inside an indicator
functor to extract data inside an indicator
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
identity functor
represents all functors that operate on a DESCRIPTOR in general, e.g. getVelocity(),...
perform explicit typecast from output type T2 to T
bool operator()(T output[], const int x[]) override
ComposedSuperLatticeF3D(SuperLatticeF3D< T, DESCRIPTOR > &f0, SuperLatticeF3D< T, DESCRIPTOR > &f1, SuperLatticeF3D< T, DESCRIPTOR > &f2)
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
GenericF is a base class, that can represent continuous as well as discrete functions.
Definition genericF.h:50
std::shared_ptr< GenericF< T, S > > _ptrCalcC
memory management, frees resouces (calcClass)
Definition genericF.h:71
std::string & getName()
read and write access to name
Definition genericF.hh:51
Base class for all LoadBalancer.
bool isLocal(const int &glob)
returns whether glob is on this process
int loc(const int &glob)
SuperDataF3D(SuperData< 3, T, BaseType > &superData)
Constructor from SuperData3D - stores _superData reference.
bool operator()(BaseType output[], const int input[])
Operator for this functor - copies data from _superData object into output.
SuperData< 3, T, BaseType > & getSuperData()
Getter for _superData
functor to extract one component
SuperExtractComponentF3D(FunctorPtr< SuperF3D< T, W > > &&f, int extractDim)
bool operator()(W output[], const int input[])
FunctorPtr< SuperF3D< T, W > > _f
SuperExtractComponentIndicatorF3D(FunctorPtr< SuperF3D< T, W > > &&f, int extractDim, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
FunctorPtr< SuperIndicatorF3D< T > > _indicatorF
bool operator()(W output[], const int input[]) override
functor to extract data inside an indicator
SuperExtractIndicatorF3D(FunctorPtr< SuperF3D< T, W > > &&f, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
represents all functors that operate on a SuperStructure<T,3> in general
SuperStructure< T, 3 > & getSuperStructure()
int getBlockFSize() const
BlockF3D< W > & getBlockF(int iCloc)
SuperF3D(SuperStructure< T, 3 > &superStructure, int targetDim)
bool operator()(W output[], const int input[])
std::vector< std::unique_ptr< BlockF3D< W > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
identity functor for memory management
FunctorPtr< SuperF3D< T, W > > _f
bool operator()(W output[], const int input[]) override
SuperIdentity3D(FunctorPtr< SuperF3D< T, W > > &&f)
SuperIdentityOnSuperIndicatorF3D(SuperF3D< T, W > &f, SuperIndicatorF3D< T > &indicatorF, W defaultValue=0.)
SuperIndicatorF3D< T > & _indicatorF
bool operator()(W output[], const int input[])
Base indicator functor (discrete)
represents all functors that operate on a SuperLattice in general, e.g. getVelocity(),...
SuperLattice< T, DESCRIPTOR > & getSuperLattice()
SuperLatticeF3D(SuperLattice< T, DESCRIPTOR > &superLattice, int targetDim)
bool operator()(T output[], const int input[])
FunctorPtr< SuperLatticeF3D< T, DESCRIPTOR > > _f
bool operator()(T output[], const int input[]) override
SuperLatticeIdentity3D(FunctorPtr< SuperLatticeF3D< T, DESCRIPTOR > > &&f)
UnitConverter< T, DESCRIPTOR > const & getConverter() const
SuperLatticePhysF3D(SuperLattice< T, DESCRIPTOR > &sLattice, const UnitConverter< T, DESCRIPTOR > &converter, int targetDim)
ThermalUnitConverter< T, DESCRIPTOR, TDESCRIPTOR > const & getConverter() const
SuperLatticeThermalPhysF3D(SuperLattice< T, TDESCRIPTOR > &sLattice, const ThermalUnitConverter< T, DESCRIPTOR, TDESCRIPTOR > &converter, int targetDim)
Super class maintaining block lattices for a cuboid decomposition.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
perform explicit typecast from output type W2 to W
FunctorPtr< SuperF3D< T, W2 > > _f
bool operator()(W output[], const int input[])
has to be implemented for 'every' derived class
Conversion between physical and lattice units, as well as discretization specialized for thermal appl...
Conversion between physical and lattice units, as well as discretization.
int getRank() const
Returns the process ID.
MpiManager & mpi()
Top level namespace for all of OpenLB.
typename util::BaseTypeHelper< T >::type BaseType
Definition baseType.h:59
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45