scalarField.C
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-2017 OpenFOAM Foundation
9  Copyright (C) 2019 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 Description
28  Specialisation of Field<T> for scalar.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "scalarField.H"
33 #include "unitConversion.H"
34 
35 #define TEMPLATE
36 #include "FieldFunctionsM.C"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 template<>
46 tmp<scalarField> scalarField::component(const direction) const
47 {
48  return *this;
49 }
50 
51 void component(scalarField& sf, const UList<scalar>& f, const direction)
52 {
53  sf = f;
54 }
55 
56 template<>
57 void scalarField::replace(const direction, const UList<scalar>& sf)
58 {
59  *this = sf;
60 }
61 
62 template<>
63 void scalarField::replace(const direction, const scalar& s)
64 {
65  *this = s;
66 }
67 
68 
69 void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
70 {
72  (
73  scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf
74  )
75 }
76 
77 tmp<scalarField> stabilise(const UList<scalar>& sf, const scalar s)
78 {
79  auto tresult = tmp<scalarField>::New(sf.size());
80  stabilise(tresult.ref(), sf, s);
81  return tresult;
82 }
83 
84 tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
85 {
86  tmp<scalarField> tresult = New(tsf);
87  stabilise(tresult.ref(), tsf(), s);
88  tsf.clear();
89  return tresult;
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 template<>
96 float sumProd(const UList<float>& f1, const UList<float>& f2)
97 {
98  float result = 0.0;
99  if (f1.size() && (f1.size() == f2.size()))
100  {
101  TFOR_ALL_S_OP_F_OP_F(float, result, +=, float, f1, *, float, f2)
102  }
103  return result;
104 }
105 
106 
107 template<>
108 double sumProd(const UList<double>& f1, const UList<double>& f2)
109 {
110  double result = 0.0;
111  if (f1.size() && (f1.size() == f2.size()))
112  {
113  TFOR_ALL_S_OP_F_OP_F(double, result, +=, double, f1, *, double, f2)
114  }
115  return result;
116 }
117 
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add)
122 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, subtract)
123 
124 BINARY_OPERATOR(scalar, scalar, scalar, *, multiply)
125 BINARY_OPERATOR(scalar, scalar, scalar, /, divide)
126 
127 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, divide)
128 
129 BINARY_FUNCTION(scalar, scalar, scalar, pow)
130 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
131 
132 BINARY_FUNCTION(scalar, scalar, scalar, atan2)
133 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
134 
135 BINARY_FUNCTION(scalar, scalar, scalar, hypot)
136 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, hypot)
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 UNARY_FUNCTION(scalar, scalar, pow3)
141 UNARY_FUNCTION(scalar, scalar, pow4)
142 UNARY_FUNCTION(scalar, scalar, pow5)
143 UNARY_FUNCTION(scalar, scalar, pow6)
144 UNARY_FUNCTION(scalar, scalar, pow025)
145 UNARY_FUNCTION(scalar, scalar, sqrt)
146 UNARY_FUNCTION(scalar, scalar, cbrt)
147 UNARY_FUNCTION(scalar, scalar, sign)
148 UNARY_FUNCTION(scalar, scalar, pos)
149 UNARY_FUNCTION(scalar, scalar, pos0)
150 UNARY_FUNCTION(scalar, scalar, neg)
151 UNARY_FUNCTION(scalar, scalar, neg0)
152 UNARY_FUNCTION(scalar, scalar, posPart)
153 UNARY_FUNCTION(scalar, scalar, negPart)
154 UNARY_FUNCTION(scalar, scalar, exp)
155 UNARY_FUNCTION(scalar, scalar, log)
156 UNARY_FUNCTION(scalar, scalar, log10)
157 UNARY_FUNCTION(scalar, scalar, sin)
158 UNARY_FUNCTION(scalar, scalar, cos)
159 UNARY_FUNCTION(scalar, scalar, tan)
160 UNARY_FUNCTION(scalar, scalar, asin)
161 UNARY_FUNCTION(scalar, scalar, acos)
162 UNARY_FUNCTION(scalar, scalar, atan)
163 UNARY_FUNCTION(scalar, scalar, sinh)
164 UNARY_FUNCTION(scalar, scalar, cosh)
165 UNARY_FUNCTION(scalar, scalar, tanh)
166 UNARY_FUNCTION(scalar, scalar, asinh)
167 UNARY_FUNCTION(scalar, scalar, acosh)
168 UNARY_FUNCTION(scalar, scalar, atanh)
169 UNARY_FUNCTION(scalar, scalar, erf)
170 UNARY_FUNCTION(scalar, scalar, erfc)
171 UNARY_FUNCTION(scalar, scalar, lgamma)
172 UNARY_FUNCTION(scalar, scalar, j0)
173 UNARY_FUNCTION(scalar, scalar, j1)
174 UNARY_FUNCTION(scalar, scalar, y0)
175 UNARY_FUNCTION(scalar, scalar, y1)
176 
177 UNARY_FUNCTION(scalar, scalar, degToRad)
178 UNARY_FUNCTION(scalar, scalar, radToDeg)
179 UNARY_FUNCTION(scalar, scalar, atmToPa)
180 UNARY_FUNCTION(scalar, scalar, barToPa)
181 UNARY_FUNCTION(scalar, scalar, paToAtm)
182 UNARY_FUNCTION(scalar, scalar, paToBar)
183 
184 
185 #define BesselFunc(func) \
186 void func(scalarField& res, const int n, const UList<scalar>& sf) \
187 { \
188  TFOR_ALL_F_OP_FUNC_S_F(scalar, res, =, ::Foam::func, int, n, scalar, sf) \
189 } \
190  \
191 tmp<scalarField> func(const int n, const UList<scalar>& sf) \
192 { \
193  auto tresult = tmp<scalarField>::New(sf.size()); \
194  func(tresult.ref(), n, sf); \
195  return tresult; \
196 } \
197  \
198 tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
199 { \
200  tmp<scalarField> tresult = New(tsf); \
201  func(tresult.ref(), n, tsf()); \
202  tsf.clear(); \
203  return tresult; \
204 }
205 
208 
209 #undef BesselFunc
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace Foam
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 #include "undefFieldFunctionsM.H"
219 
220 // ************************************************************************* //
BINARY_TYPE_OPERATOR_SF
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:522
BINARY_OPERATOR
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:412
Foam::subtract
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:940
Foam::tan
dimensionedScalar tan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:266
UNARY_FUNCTION
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
Definition: DimensionedFieldFunctionsM.C:33
Foam::tmp::clear
void clear() const noexcept
Definition: tmpI.H:291
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::cosh
dimensionedScalar cosh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:271
Foam::y1
dimensionedScalar y1(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:282
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
scalarField.H
Foam::yn
tmp< scalarField > yn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:207
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::posPart
dimensionedScalar posPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:221
Foam::atan2
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:312
Foam::neg0
dimensionedScalar neg0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:210
BINARY_TYPE_OPERATOR
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:674
undefFieldFunctionsM.H
unitConversion.H
Unit conversion functions.
BesselFunc
#define BesselFunc(func)
Definition: scalarField.C:185
Foam::pos0
dimensionedScalar pos0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:188
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:261
BINARY_FUNCTION
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Definition: DimensionedFieldFunctionsM.C:141
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::erf
dimensionedScalar erf(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:276
Foam::jn
tmp< scalarField > jn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:206
Foam::divide
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Foam::pow025
dimensionedScalar pow025(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:133
Foam::hypot
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:327
Foam::atanh
dimensionedScalar atanh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:275
Foam::lgamma
dimensionedScalar lgamma(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:278
Foam::pow4
dimensionedScalar pow4(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:100
Foam::pow6
dimensionedScalar pow6(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:122
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::atmToPa
constexpr scalar atmToPa(const scalar atm) noexcept
Conversion from atm to Pa.
Definition: unitConversion.H:98
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::tanh
dimensionedScalar tanh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:272
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::paToAtm
constexpr scalar paToAtm(const scalar pa) noexcept
Conversion from Pa to atm.
Definition: unitConversion.H:111
Foam::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:43
Foam::log10
dimensionedScalar log10(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:263
Foam::y0
dimensionedScalar y0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:281
Foam::erfc
dimensionedScalar erfc(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:277
Foam::radToDeg
constexpr scalar radToDeg(const scalar rad) noexcept
Conversion from radians to degrees.
Definition: unitConversion.H:54
Foam::asinh
dimensionedScalar asinh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:273
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:75
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::pow5
dimensionedScalar pow5(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:111
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
TFOR_ALL_S_OP_F_OP_F
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:389
Foam::Field< scalar >::component
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:551
BINARY_TYPE_FUNCTION
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
Definition: DimensionedFieldFunctionsM.C:405
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::acosh
dimensionedScalar acosh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:274
Foam::barToPa
constexpr scalar barToPa(const scalar bar) noexcept
Conversion from bar to Pa.
Definition: unitConversion.H:104
Foam::negPart
dimensionedScalar negPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:232
TFOR_ALL_F_OP_FUNC_S_F
#define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2)
Definition: FieldM.H:219
Foam::component
void component(scalarField &sf, const UList< scalar > &f, const direction)
Definition: scalarField.C:51
f
labelList f(nPoints)
Foam::paToBar
constexpr scalar paToBar(const scalar pa) noexcept
Conversion from Pa to bar.
Definition: unitConversion.H:117
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::j0
dimensionedScalar j0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:279
Foam::acos
dimensionedScalar acos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:268
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
FieldFunctionsM.C
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::atan
dimensionedScalar atan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:269
Foam::sumProd
double sumProd(const UList< double > &f1, const UList< double > &f2)
Sum product for double.
Definition: scalarField.C:108
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::multiply
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Foam::cbrt
dimensionedScalar cbrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:155
Foam::j1
dimensionedScalar j1(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:280
Foam::neg
dimensionedScalar neg(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:199
Foam::asin
dimensionedScalar asin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:267
Foam::stabilise
tmp< scalarField > stabilise(const tmp< scalarField > &tsf, const scalar s)
Definition: scalarField.C:84
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177
Foam::sinh
dimensionedScalar sinh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:270