OpenLB 1.7
Loading...
Searching...
No Matches
blockCalcF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2013-2017 Albert Mink, Lukas Baron, 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#ifndef BLOCK_CALC_F_2D_HH
25#define BLOCK_CALC_F_2D_HH
26
27#include "blockCalcF2D.h"
28
29namespace olb {
30
31
32template <typename T, template<typename> class F>
34 : BlockF2D<T>(
35 g.getBlockStructure(),
36 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
37 _f(f), _g(g),
38 _glob{}, _fIsBlock(true), _gIsBlock(true)
39{
40 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
41 std::swap(f._ptrCalcC, this->_ptrCalcC);
42}
43
44template <typename T, template<typename> class F>
46 : BlockF2D<T>(
47 f.getBlockStructure(),
48 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
49 _f(f), _g(g),
50 _glob(glob), _fIsBlock(true), _gIsBlock(false)
51{
52 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
53 std::swap(f._ptrCalcC, this->_ptrCalcC);
54}
55
56template <typename T, template<typename> class F>
58 : BlockF2D<T>(
59 g.getBlockStructure(),
60 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
61 _f(f), _g(g),
62 _glob(glob), _fIsBlock(false), _gIsBlock(true)
64 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
65 std::swap(f._ptrCalcC, this->_ptrCalcC);
66}
67
68template <typename T, template<typename> class F>
69bool BlockCalcF2D<T,F>::operator()(T output[], const int input[])
70{
71 T* outputF = output;
72 T outputG[this->getTargetDim()];
73
74 if ( this->_fIsBlock && this->_gIsBlock ) {
75 this->_f(outputF, input);
76 this->_g(outputG, input);
77 }
78 else {
79 const int superInput[3] = { this->_glob, input[0], input[1] };
80
81 if ( this->_fIsBlock ) {
82 this->_f(outputF, input);
83 this->_g(outputG, superInput);
84 }
85 else {
86 this->_f(outputF, superInput);
87 this->_g(outputG, input);
88 }
89 }
90
91 if ( _f.getTargetDim() == 1 || _g.getTargetDim() == 1 ) {
92 // scalar operation
93 if ( _f.getTargetDim() == 1 ) {
94 // apply the scalar f to possibly multidimensional g
95 for (int i = 1; i < this->getTargetDim(); i++) {
96 outputF[i] = outputF[0];
97 }
98 }
99 else if ( _g.getTargetDim() == 1 ) {
100 // apply scalar g to possibly multidimensional f
101 for (int i = 1; i < this->getTargetDim(); i++) {
102 outputG[i] = outputG[0];
103 }
104 }
105 }
106
107 for (int i = 0; i < this->getTargetDim(); i++) {
108 output[i] = F<T>()(outputF[i], outputG[i]);
109 }
110
111 return true;
112}
113
114
116template <typename T>
118{
119 auto tmp = std::make_shared< BlockCalcPlus2D<T> >(*this,rhs);
120 this->_ptrCalcC = tmp;
121 return *tmp;
122}
123
124template <typename T>
126{
127 auto tmp = std::make_shared< BlockCalcMinus2D<T> >(*this,rhs);
128 this->_ptrCalcC = tmp;
129 return *tmp;
130}
131
132template <typename T>
134{
135 auto tmp = std::make_shared< BlockCalcMultiplication2D<T> >(*this,rhs);
136 this->_ptrCalcC = tmp;
137 return *tmp;
138}
139
140template <typename T>
142{
143 auto tmp = std::make_shared< BlockCalcDivision2D<T> >(*this,rhs);
144 this->_ptrCalcC = tmp;
145 return *tmp;
146}
147
148
149} // end namespace olb
150
151#endif
bool operator()(T output[], const int input[]) override
has to be implemented for 'every' derived class
BlockCalcF2D(BlockF2D< T > &f, BlockF2D< T > &g)
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
BlockF2D< T > & operator+(BlockF2D< T > &rhs)
BlockF2D< T > & operator*(BlockF2D< T > &rhs)
BlockF2D< T > & operator-(BlockF2D< T > &rhs)
BlockF2D< T > & operator/(BlockF2D< T > &rhs)
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
Top level namespace for all of OpenLB.