scalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Specialisation of Field<T> for scalar.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "scalarField.H"
30 #include "unitConversion.H"
31 
32 #define TEMPLATE
33 #include "FieldFunctionsM.C"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 template<>
43 tmp<scalarField> scalarField::component(const direction) const
44 {
45  return *this;
46 }
47 
49 {
50  sf = f;
51 }
52 
53 
54 template<>
55 void scalarField::replace(const direction, const UList<scalar>& sf)
56 {
57  *this = sf;
58 }
59 
60 template<>
61 void scalarField::replace(const direction, const scalar& s)
62 {
63  *this = s;
64 }
65 
66 
67 void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
68 {
70  (
71  scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf
72  )
73 }
74 
76 {
77  tmp<scalarField> tRes(new scalarField(sf.size()));
78  stabilise(tRes.ref(), sf, s);
79  return tRes;
80 }
81 
82 tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
83 {
84  tmp<scalarField> tRes = New(tsf);
85  stabilise(tRes.ref(), tsf(), s);
86  tsf.clear();
87  return tRes;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 template<>
94 scalar sumProd(const UList<scalar>& f1, const UList<scalar>& f2)
95 {
96  if (f1.size() && (f1.size() == f2.size()))
97  {
98  scalar SumProd = 0.0;
99  TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, scalar, f1, *, scalar, f2)
100  return SumProd;
101  }
102  else
103  {
104  return 0.0;
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add)
112 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, subtract)
113 
114 BINARY_OPERATOR(scalar, scalar, scalar, *, multiply)
115 BINARY_OPERATOR(scalar, scalar, scalar, /, divide)
116 
117 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, divide)
118 
119 BINARY_FUNCTION(scalar, scalar, scalar, pow)
120 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
121 BINARY_FUNCTION(scalar, scalar, label, integerPow)
122 BINARY_TYPE_FUNCTION_FS(scalar, scalar, label, integerPow)
123 BINARY_FUNCTION(scalar, scalar, label, integerRoot)
124 BINARY_TYPE_FUNCTION_FS(scalar, scalar, label, integerRoot)
125 
126 BINARY_FUNCTION(scalar, scalar, scalar, atan2)
127 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 UNARY_FUNCTION(scalar, scalar, pow3)
133 UNARY_FUNCTION(scalar, scalar, pow4)
134 UNARY_FUNCTION(scalar, scalar, pow5)
135 UNARY_FUNCTION(scalar, scalar, pow6)
136 UNARY_FUNCTION(scalar, scalar, pow025)
137 UNARY_FUNCTION(scalar, scalar, sqrt)
138 UNARY_FUNCTION(scalar, scalar, cbrt)
139 UNARY_FUNCTION(scalar, scalar, sign)
140 UNARY_FUNCTION(scalar, scalar, pos)
141 UNARY_FUNCTION(scalar, scalar, pos0)
142 UNARY_FUNCTION(scalar, scalar, neg)
143 UNARY_FUNCTION(scalar, scalar, neg0)
144 UNARY_FUNCTION(scalar, scalar, posPart)
145 UNARY_FUNCTION(scalar, scalar, negPart)
146 UNARY_FUNCTION(scalar, scalar, exp)
147 UNARY_FUNCTION(scalar, scalar, log)
148 UNARY_FUNCTION(scalar, scalar, log10)
149 UNARY_FUNCTION(scalar, scalar, sin)
150 UNARY_FUNCTION(scalar, scalar, cos)
151 UNARY_FUNCTION(scalar, scalar, tan)
152 UNARY_FUNCTION(scalar, scalar, asin)
153 UNARY_FUNCTION(scalar, scalar, acos)
154 UNARY_FUNCTION(scalar, scalar, atan)
155 UNARY_FUNCTION(scalar, scalar, sinh)
156 UNARY_FUNCTION(scalar, scalar, cosh)
157 UNARY_FUNCTION(scalar, scalar, tanh)
158 UNARY_FUNCTION(scalar, scalar, asinh)
159 UNARY_FUNCTION(scalar, scalar, acosh)
160 UNARY_FUNCTION(scalar, scalar, atanh)
161 UNARY_FUNCTION(scalar, scalar, erf)
162 UNARY_FUNCTION(scalar, scalar, erfc)
163 UNARY_FUNCTION(scalar, scalar, lgamma)
164 UNARY_FUNCTION(scalar, scalar, j0)
165 UNARY_FUNCTION(scalar, scalar, j1)
166 UNARY_FUNCTION(scalar, scalar, y0)
167 UNARY_FUNCTION(scalar, scalar, y1)
168 
169 UNARY_FUNCTION(scalar, scalar, degToRad)
170 UNARY_FUNCTION(scalar, scalar, radToDeg)
171 UNARY_FUNCTION(scalar, scalar, atmToPa)
172 UNARY_FUNCTION(scalar, scalar, paToAtm)
173 
174 
175 #define BesselFunc(func) \
176 void func(scalarField& res, const int n, const UList<scalar>& sf) \
177 { \
178  TFOR_ALL_F_OP_FUNC_S_F(scalar, res, =, ::Foam::func, int, n, scalar, sf) \
179 } \
180  \
181 tmp<scalarField> func(const int n, const UList<scalar>& sf) \
182 { \
183  tmp<scalarField> tRes(new scalarField(sf.size())); \
184  func(tRes.ref(), n, sf); \
185  return tRes; \
186 } \
187  \
188 tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
189 { \
190  tmp<scalarField> tRes = New(tsf); \
191  func(tRes.ref(), n, tsf()); \
192  tsf.clear(); \
193  return tRes; \
194 }
195 
198 
199 #undef BesselFunc
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #include "undefFieldFunctionsM.H"
209 
210 // ************************************************************************* //
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:376
#define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2)
Definition: FieldM.H:210
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:455
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
A class for managing temporary objects.
Definition: tmp.H:55
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:237
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
volScalarField scalarField(fieldObject, mesh)
volScalarField sf(fieldObject, mesh)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Namespace for OpenFOAM.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
scalar integerRoot(const scalar x, const label e)
Compute the power of the number x to the reciprocal integer 1/e.
Definition: scalarI.H:55
dimensionedScalar erfc(const dimensionedScalar &ds)
dimensionedScalar asin(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
dimensionedScalar tan(const dimensionedScalar &ds)
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionedScalar lgamma(const dimensionedScalar &ds)
dimensionedScalar j1(const dimensionedScalar &ds)
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensionedScalar y0(const dimensionedScalar &ds)
dimensionedScalar cosh(const dimensionedScalar &ds)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar tanh(const dimensionedScalar &ds)
dimensionedScalar erf(const dimensionedScalar &ds)
dimensionedScalar sinh(const dimensionedScalar &ds)
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
dimensionedScalar log10(const dimensionedScalar &ds)
scalar sumProd(const UList< scalar > &f1, const UList< scalar > &f2)
Definition: scalarField.C:94
dimensionedScalar log(const dimensionedScalar &ds)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void component(scalarField &sf, const UList< scalar > &f, const direction)
Definition: scalarField.C:48
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensionedScalar y1(const dimensionedScalar &ds)
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar acosh(const dimensionedScalar &ds)
tmp< scalarField > stabilise(const tmp< scalarField > &tsf, const scalar s)
Definition: scalarField.C:82
dimensionedScalar sqrt(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar pow4(const dimensionedScalar &ds)
tmp< scalarField > jn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:196
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionedScalar atanh(const dimensionedScalar &ds)
scalar atmToPa(const scalar atm)
Conversion from atm to Pa.
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
tmp< scalarField > yn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:197
dimensionedScalar atan(const dimensionedScalar &ds)
scalar paToAtm(const scalar pa)
Conversion from atm to Pa.
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar posPart(const dimensionedScalar &ds)
uint8_t direction
Definition: direction.H:45
dimensionedScalar acos(const dimensionedScalar &ds)
dimensionedScalar j0(const dimensionedScalar &ds)
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
dimensionedScalar pow025(const dimensionedScalar &ds)
dimensionedScalar asinh(const dimensionedScalar &ds)
labelList f(nPoints)
#define BesselFunc(func)
Definition: scalarField.C:175
Unit conversion functions.