OpenLB 1.8.1
Loading...
Searching...
No Matches
analyticCalcF.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012-2018 Lukas Baron, Tim Dornieden, 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 ANALYTICAL_CALC_F_HH
26#define ANALYTICAL_CALC_F_HH
27
28
29#include "analyticCalcF.h"
30#include "analyticalF.h"
31#include "core/olbDebug.h"
32
33namespace olb {
34
35
36template <unsigned D, typename T, typename S, template<typename> class F>
39 : AnalyticalF<D,T,S>(f->getTargetDim()),
40 _f(std::move(f)),
41 _g(std::move(g))
42{
43 if (g->getTargetDim() != f->getTargetDim()) {
44 throw std::invalid_argument("Functor target dimensions must be equal");
45 }
46 std::swap(f->_ptrCalcC, this->_ptrCalcC);
47 this->getName() = "(" + _f->getName() + F<T>::symbol + _g->getName() + ")";
48}
49
50template <unsigned D, typename T, typename S, template<typename> class F>
53 std::unique_ptr<AnalyticalF<D,T,S>>(
54 new AnalyticalConst<D,T,S>(std::vector<T>(g->getTargetDim(), scalar))),
55 std::forward<decltype(g)>(g))
56{ }
58template <unsigned D, typename T, typename S, template<typename> class F>
61 std::forward<decltype(f)>(f),
62 std::unique_ptr<AnalyticalF<D,T,S>>(
63 new AnalyticalConst<D,T,S>(std::vector<T>(f->getTargetDim(), scalar))))
64{ }
65
66template <unsigned D, typename T, typename S, template<typename> class F>
67bool AnalyticCalcF<D,T,S,F>::operator()(T output[], const S input[])
68{
69 T outputTmp[this->_g->getTargetDim()];
70 this->_g(outputTmp, input);
71 this->_f(output, input);
72 for (int i = 0; i < this->_f->getTargetDim(); ++i) {
73 output[i] = F<T>()(output[i], outputTmp[i]);
74 }
75 return true;
76}
77
78
79template <unsigned D, typename T, typename S>
80std::shared_ptr<AnalyticalF<D,T,S>> operator+(std::shared_ptr<AnalyticalF<D,T,S>> lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
81{
82 return std::shared_ptr<AnalyticalF<D,T,S>>(
83 new AnalyticCalcPlus<D,T,S>(std::move(lhs), std::move(rhs)));
84}
85
86template <unsigned D, typename T, typename S>
87std::shared_ptr<AnalyticalF<D,T,S>> operator+(std::shared_ptr<AnalyticalF<D,T,S>> lhs, T rhs)
88{
89 return std::shared_ptr<AnalyticalF<D,T,S>>(
90 new AnalyticCalcPlus<D,T,S>(std::move(lhs), rhs));
91}
92
93template <unsigned D, typename T, typename S>
94std::shared_ptr<AnalyticalF<D,T,S>> operator+(T lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
95{
96 return std::shared_ptr<AnalyticalF<D,T,S>>(
97 new AnalyticCalcPlus<D,T,S>(lhs, std::move(rhs)));
98}
99
100template <unsigned D, typename T, typename S>
101std::shared_ptr<AnalyticalF<D,T,S>> operator-(std::shared_ptr<AnalyticalF<D,T,S>> lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
102{
103 return std::shared_ptr<AnalyticalF<D,T,S>>(
104 new AnalyticCalcMinus<D,T,S>(std::move(lhs), std::move(rhs)));
105}
106
107template <unsigned D, typename T, typename S>
108std::shared_ptr<AnalyticalF<D,T,S>> operator-(std::shared_ptr<AnalyticalF<D,T,S>> lhs, T rhs)
109{
110 return std::shared_ptr<AnalyticalF<D,T,S>>(
111 new AnalyticCalcMinus<D,T,S>(std::move(lhs), rhs));
112}
113
114template <unsigned D, typename T, typename S>
115std::shared_ptr<AnalyticalF<D,T,S>> operator-(T lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
116{
117 return std::shared_ptr<AnalyticalF<D,T,S>>(
118 new AnalyticCalcMinus<D,T,S>(lhs, std::move(rhs)));
119}
120
121template <unsigned D, typename T, typename S>
122std::shared_ptr<AnalyticalF<D,T,S>> operator*(std::shared_ptr<AnalyticalF<D,T,S>> lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
123{
124 return std::shared_ptr<AnalyticalF<D,T,S>>(
125 new AnalyticCalcMultiplication<D,T,S>(std::move(lhs), std::move(rhs)));
126}
127
128template <unsigned D, typename T, typename S>
129std::shared_ptr<AnalyticalF<D,T,S>> operator*(std::shared_ptr<AnalyticalF<D,T,S>> lhs, T rhs)
130{
131 return std::shared_ptr<AnalyticalF<D,T,S>>(
132 new AnalyticCalcMultiplication<D,T,S>(std::move(lhs), rhs));
133}
134
135template <unsigned D, typename T, typename S>
136std::shared_ptr<AnalyticalF<D,T,S>> operator*(T lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
137{
138 return std::shared_ptr<AnalyticalF<D,T,S>>(
139 new AnalyticCalcMultiplication<D,T,S>(lhs, std::move(rhs)));
140}
141
142template <unsigned D, typename T, typename S>
143std::shared_ptr<AnalyticalF<D,T,S>> operator/(std::shared_ptr<AnalyticalF<D,T,S>> lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
144{
145 return std::shared_ptr<AnalyticalF<D,T,S>>(
146 new AnalyticCalcDivision<D,T,S>(std::move(lhs), std::move(rhs)));
147}
148
149template <unsigned D, typename T, typename S>
150std::shared_ptr<AnalyticalF<D,T,S>> operator/(std::shared_ptr<AnalyticalF<D,T,S>> lhs, T rhs)
151{
152 return std::shared_ptr<AnalyticalF<D,T,S>>(
153 new AnalyticCalcDivision<D,T,S>(std::move(lhs), rhs));
154}
155
156template <unsigned D, typename T, typename S>
157std::shared_ptr<AnalyticalF<D,T,S>> operator/(T lhs, std::shared_ptr<AnalyticalF<D,T,S>> rhs)
158{
159 return std::shared_ptr<AnalyticalF<D,T,S>>(
160 new AnalyticCalcDivision<D,T,S>(lhs, std::move(rhs)));
161}
162
164template <unsigned D, typename T, typename S>
166{
167 auto tmp = std::make_shared< AnalyticCalcPlus<D,T,S> >(*this,rhs);
168 this->_ptrCalcC = tmp;
169 return *tmp;
170}
171
172template <unsigned D, typename T, typename S>
174{
175 auto tmp = std::make_shared< AnalyticCalcMinus<D,T,S> >(*this,rhs);
176 this->_ptrCalcC = tmp;
177 return *tmp;
178}
179
180template <unsigned D, typename T, typename S>
182{
183 auto tmp = std::make_shared< AnalyticCalcMultiplication<D,T,S> >(*this,rhs);
184 this->_ptrCalcC = tmp;
185 return *tmp;
186}
187
188template <unsigned D, typename T, typename S>
190{
191 auto tmp = std::make_shared< AnalyticCalcDivision<D,T,S> >(*this,rhs);
192 this->_ptrCalcC = tmp;
193 return *tmp;
194}
195
196
197} // end namespace olb
198
199#endif
arithmetic helper class for analytical functors
AnalyticCalcF(FunctorPtr< AnalyticalF< D, T, S > > &&f, FunctorPtr< AnalyticalF< D, T, S > > &&g)
FunctorPtr< AnalyticalF< D, T, S > > _g
bool operator()(T output[], const S input[]) override
has to be implemented for 'every' derived class
FunctorPtr< AnalyticalF< D, T, S > > _f
AnalyticalConst: DD -> XD, where XD is defined by value.size()
AnalyticalF are applications from DD to XD, where X is set by the constructor.
AnalyticalF< D, T, S > & operator*(AnalyticalF< D, T, S > &rhs)
AnalyticalF< D, T, S > & operator/(AnalyticalF< D, T, S > &rhs)
AnalyticalF< D, T, S > & operator+(AnalyticalF< D, T, S > &rhs)
AnalyticalF< D, T, S > & operator-(AnalyticalF< D, T, S > &rhs)
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
Top level namespace for all of OpenLB.
AnalyticCalcF< D, T, S, util::minus > AnalyticCalcMinus
subtraction functor
Expr operator/(Expr lhs, Expr rhs)
Definition expr.cpp:186
AnalyticCalcF< D, T, S, util::multiplies > AnalyticCalcMultiplication
multiplication functor
Expr operator*(Expr lhs, Expr rhs)
Definition expr.cpp:181
AnalyticCalcF< D, T, S, util::divides > AnalyticCalcDivision
division functor
AnalyticCalcF< D, T, S, util::plus > AnalyticCalcPlus
addition functor
Expr operator+(Expr lhs, Expr rhs)
Definition expr.cpp:171
Expr operator-(Expr lhs, Expr rhs)
Definition expr.cpp:176