OpenLB 1.7
Loading...
Searching...
No Matches
blockCalcF3D.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, Mathias J. Krause,
4 * Albert Mink, 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 BLOCK_CALC_F_3D_HH
26#define BLOCK_CALC_F_3D_HH
27
28#include "blockCalcF3D.h"
29
30namespace olb {
31
32
33template <typename T, template<typename> class F>
35 : BlockF3D<T>(
36 f.getBlockStructure(),
37 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
38 _f(f), _g(g),
39 _glob{}, _fIsBlock(true), _gIsBlock(true)
40{
41 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
42 std::swap(f._ptrCalcC, this->_ptrCalcC);
43}
44
45template <typename T, template<typename> class F>
47 : BlockF3D<T>(
48 f.getBlockStructure(),
49 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
50 _f(f), _g(g),
51 _glob(glob), _fIsBlock(true), _gIsBlock(false)
52{
53 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
54 std::swap(f._ptrCalcC, this->_ptrCalcC);
55}
56
57template <typename T, template<typename> class F>
60 g.getBlockStructure(),
61 f.getTargetDim() > g.getTargetDim() ? f.getTargetDim() : g.getTargetDim()),
62 _f(f), _g(g),
63 _glob(glob), _fIsBlock(false), _gIsBlock(true)
64{
65 this->getName() = "(" + f.getName() + F<T>::symbol + g.getName() + ")";
66 std::swap(f._ptrCalcC, this->_ptrCalcC);
67}
68
69template <typename T, template<typename> class F>
70bool BlockCalcF3D<T,F>::operator()(T output[], const int input[])
71{
72 T* outputF = output;
73 T outputG[this->getTargetDim()];
74
75 if ( this->_fIsBlock && this->_gIsBlock ) {
76 this->_f(outputF, input);
77 this->_g(outputG, input);
78 }
79 else {
80 const int superInput[4] = {
81 this->_glob,
82 input[0], input[1], input[2]
83 };
84
85 if ( this->_fIsBlock ) {
86 this->_f(outputF, input);
87 this->_g(outputG, superInput);
88 }
89 else {
90 this->_f(outputF, superInput);
91 this->_g(outputG, input);
92 }
93 }
94
95 if ( _f.getTargetDim() == 1 || _g.getTargetDim() == 1 ) {
96 // scalar operation
97 if ( _f.getTargetDim() == 1 ) {
98 // apply the scalar f to possibly multidimensional g
99 for (int i = 1; i < this->getTargetDim(); i++) {
100 outputF[i] = outputF[0];
101 }
102 }
103 else if ( _g.getTargetDim() == 1 ) {
104 // apply scalar g to possibly multidimensional f
105 for (int i = 1; i < this->getTargetDim(); i++) {
106 outputG[i] = outputG[0];
107 }
108 }
109 }
110
111 for (int i = 0; i < this->getTargetDim(); i++) {
112 output[i] = F<T>()(outputF[i], outputG[i]);
113 }
114
115 return true;
116}
117
118
120
121template <typename T>
123{
124 auto tmp = std::make_shared< BlockCalcPlus3D<T> >(*this,rhs);
125 this->_ptrCalcC = tmp;
126 return *tmp;
127}
128
129template <typename T>
131{
132 auto tmp = std::make_shared< BlockCalcMinus3D<T> >(*this,rhs);
133 this->_ptrCalcC = tmp;
134 return *tmp;
135}
136
137template <typename T>
139{
140 auto tmp = std::make_shared< BlockCalcMultiplication3D<T> >(*this,rhs);
141 this->_ptrCalcC = tmp;
142 return *tmp;
143}
144
145template <typename T>
147{
148 auto tmp = std::make_shared< BlockCalcDivision3D<T> >(*this,rhs);
149 this->_ptrCalcC = tmp;
150 return *tmp;
151}
152
153
154} // end namespace olb
155
156#endif
bool operator()(T output[], const int input[]) override
has to be implemented for 'every' derived class
BlockCalcF3D(BlockF3D< T > &f, BlockF3D< T > &g)
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
BlockF3D< T > & operator-(BlockF3D< T > &rhs)
BlockF3D< T > & operator+(BlockF3D< T > &rhs)
BlockF3D< T > & operator/(BlockF3D< T > &rhs)
BlockF3D< T > & operator*(BlockF3D< 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.