DimensionedFieldFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "DimensionedScalarField.H"
30 
31 #define TEMPLATE template<class Type, class GeoMesh>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
40 
41 template<class Type, class GeoMesh, direction r>
43 pow
44 (
45  const DimensionedField<Type, GeoMesh>& f1,
47 );
48 
49 template<class Type, class GeoMesh, direction r>
51 pow
52 (
53  const tmp<DimensionedField<Type, GeoMesh>>& tf1,
55 );
56 
57 template<class Type, class GeoMesh>
59 sqr(const DimensionedField<Type, GeoMesh>& f1);
60 
61 template<class Type, class GeoMesh>
63 sqr(const tmp<DimensionedField<Type, GeoMesh>>& tf1);
64 
65 template<class Type, class GeoMesh>
67 magSqr(const DimensionedField<Type, GeoMesh>& f1);
68 
69 template<class Type, class GeoMesh>
71 magSqr(const tmp<DimensionedField<Type, GeoMesh>>& tf1);
72 
73 template<class Type, class GeoMesh>
75 mag(const DimensionedField<Type, GeoMesh>& f1);
76 
77 template<class Type, class GeoMesh>
79 mag(const tmp<DimensionedField<Type, GeoMesh>>& tf1);
80 
81 template<class Type, class GeoMesh>
82 tmp
83 <
84  DimensionedField
85  <
87  GeoMesh
88  >
89 >
90 cmptAv(const DimensionedField<Type, GeoMesh>& f1);
91 
92 template<class Type, class GeoMesh>
93 tmp
94 <
95  DimensionedField
96  <
98  GeoMesh
99  >
100 >
101 cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tf1);
102 
103 
104 // Forward to FieldFunction via gFunc()
105 #define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \
106  \
107 template<class Type, class GeoMesh> \
108 dimensioned<ReturnType> Func \
109 ( \
110  const DimensionedField<Type, GeoMesh>& f1, \
111  const label comm = UPstream::worldComm \
112 ); \
113 template<class Type, class GeoMesh> \
114 dimensioned<ReturnType> Func \
115 ( \
116  const tmp<DimensionedField<Type, GeoMesh>>& tf1, \
117  const label comm = UPstream::worldComm \
118 );
119 
126 
128 
129 #undef UNARY_REDUCTION_FUNCTION
130 
131 
132 BINARY_FUNCTION(Type, Type, Type, max)
133 BINARY_FUNCTION(Type, Type, Type, min)
134 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
135 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
136 
137 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
138 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
139 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
140 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
141 
142 
143 // ------------------------------------------------------------------------- //
144 
145 // Clamp Methods
146 
147 template<class Type, class GeoMesh>
148 void clamp
149 (
150  DimensionedField<Type, GeoMesh>& result,
151  const DimensionedField<Type, GeoMesh>& f1,
153 );
154 
155 template<class Type, class GeoMesh>
156 tmp<DimensionedField<Type, GeoMesh>>
157 clamp
158 (
159  const DimensionedField<Type, GeoMesh>& f1,
161 );
162 
163 template<class Type, class GeoMesh>
164 tmp<DimensionedField<Type, GeoMesh>>
165 clamp
166 (
167  const tmp<DimensionedField<Type, GeoMesh>>& tf1,
169 );
170 
171 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
177 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
178 
179 
180 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
181 
182 UNARY_OPERATOR(Type, Type, -, negate, transform)
183 
184 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
185 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
186 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
187 
188 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
189 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
190 
191 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
197  \
198 template<class Type1, class Type2, class GeoMesh> \
199 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
200 operator Op \
201 ( \
202  const DimensionedField<Type1, GeoMesh>& f1, \
203  const DimensionedField<Type2, GeoMesh>& f2 \
204 ); \
205  \
206 template<class Type1, class Type2, class GeoMesh> \
207 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
208 operator Op \
209 ( \
210  const DimensionedField<Type1, GeoMesh>& f1, \
211  const tmp<DimensionedField<Type2, GeoMesh>>& tf2 \
212 ); \
213  \
214 template<class Type1, class Type2, class GeoMesh> \
215 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
216 operator Op \
217 ( \
218  const tmp<DimensionedField<Type1, GeoMesh>>& tf1, \
219  const DimensionedField<Type2, GeoMesh>& f2 \
220 ); \
221  \
222 template<class Type1, class Type2, class GeoMesh> \
223 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
224 operator Op \
225 ( \
226  const tmp<DimensionedField<Type1, GeoMesh>>& tf1, \
227  const tmp<DimensionedField<Type2, GeoMesh>>& tf2 \
228 ); \
229  \
230 template<class Form, class Type, class GeoMesh> \
231 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
232 operator Op \
233 ( \
234  const DimensionedField<Type, GeoMesh>& f1, \
235  const dimensioned<Form>& dvs \
236 ); \
237  \
238 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
239 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
240 operator Op \
241 ( \
242  const DimensionedField<Type, GeoMesh>& f1, \
243  const VectorSpace<Form,Cmpt,nCmpt>& vs \
244 ); \
245  \
246 template<class Form, class Type, class GeoMesh> \
247 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
248 operator Op \
249 ( \
250  const tmp<DimensionedField<Type, GeoMesh>>& tf1, \
251  const dimensioned<Form>& dvs \
252 ); \
253  \
254 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
255 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
256 operator Op \
257 ( \
258  const tmp<DimensionedField<Type, GeoMesh>>& tf1, \
259  const VectorSpace<Form,Cmpt,nCmpt>& vs \
260 ); \
261  \
262 template<class Form, class Type, class GeoMesh> \
263 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
264 operator Op \
265 ( \
266  const dimensioned<Form>& dvs, \
267  const DimensionedField<Type, GeoMesh>& f2 \
268 ); \
269  \
270 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
271 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
272 operator Op \
273 ( \
274  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
275  const DimensionedField<Type, GeoMesh>& f2 \
276 ); \
277  \
278 template<class Form, class Type, class GeoMesh> \
279 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
280 operator Op \
281 ( \
282  const dimensioned<Form>& dvs, \
283  const tmp<DimensionedField<Type, GeoMesh>>& tf2 \
284 ); \
285  \
286 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
287 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
288 operator Op \
289 ( \
290  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
291  const tmp<DimensionedField<Type, GeoMesh>>& tf2 \
292 );
293 
294 PRODUCT_OPERATOR(typeOfSum, +, add)
295 PRODUCT_OPERATOR(typeOfSum, -, subtract)
296 
297 PRODUCT_OPERATOR(outerProduct, *, outer)
298 PRODUCT_OPERATOR(crossProduct, ^, cross)
299 PRODUCT_OPERATOR(innerProduct, &, dot)
300 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
301 
302 #undef PRODUCT_OPERATOR
303 
304 
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 
307 } // End namespace Foam
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 #include "undefFieldFunctionsM.H"
312 
313 // ************************************************************************* //
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
type
Types of root.
Definition: Roots.H:52
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:97
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Type gMin(const FieldField< Field, Type > &f)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
Field< Type >::cmptType cmptType
Component type of the field elements.
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:54
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
Type gSum(const FieldField< Field, Type > &f)
#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
#define PRODUCT_OPERATOR(product, Op, OpFunc)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
Type gMax(const FieldField< Field, Type > &f)
scalarMinMax gMinMaxMag(const FieldField< Field, Type > &f)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
typeOfMag< Type >::type gSumMag(const FieldField< Field, Type > &f)
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
Definition: pTraits.H:51
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc)
Scalar specific part of the implementation of DimensionedField.
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
Definition: dimensionSet.C:271
pTraits< typename pTraits< arg1 >::cmptType >::magType type
Definition: products.H:96