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-2026 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 
31 #define TEMPLATE
32 #include "FieldFunctionsM.C"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 template<>
42 tmp<scalarField> scalarField::component(const direction) const
43 {
44  return *this;
45 }
46 
48 {
49  sf = f;
50 }
51 
52 
53 template<>
54 void scalarField::replace(const direction, const UList<scalar>& sf)
55 {
56  *this = sf;
57 }
58 
59 template<>
60 void scalarField::replace(const direction, const scalar& s)
61 {
62  *this = s;
63 }
64 
65 
66 void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
67 {
69  (
70  scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf
71  )
72 }
73 
75 {
76  tmp<scalarField> tRes(new scalarField(sf.size()));
77  stabilise(tRes.ref(), sf, s);
78  return tRes;
79 }
80 
82 {
83  tmp<scalarField> tRes(new scalarField(sf.size()));
84  stabilise(tRes.ref(), sf, s);
85  return tRes;
86 }
87 
88 tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
89 {
90  tmp<scalarField> tRes = New(tsf);
91  stabilise(tRes.ref(), tsf(), s);
92  tsf.clear();
93  return tRes;
94 }
95 
96 
98 (
99  const scalar start,
100  const scalar end,
101  const label n
102 )
103 {
104  return start + (end - start)*linearSequence01(n);
105 }
106 
108 {
109  tmp<scalarField> tRes(new scalarField(n));
110  scalarField& res = tRes.ref();
111  forAll(res, i)
112  {
113  res[i] = scalar(i)/(n - 1);
114  }
115  return tRes;
116 }
117 
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 template<>
122 scalar sumProd(const UList<scalar>& f1, const UList<scalar>& f2)
123 {
124  if (f1.size() && (f1.size() == f2.size()))
125  {
126  scalar SumProd = 0.0;
127  TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, scalar, f1, *, scalar, f2)
128  return SumProd;
129  }
130  else
131  {
132  return 0.0;
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add)
140 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, subtract)
141 
142 BINARY_OPERATOR(scalar, scalar, scalar, *, multiply)
143 BINARY_OPERATOR(scalar, scalar, scalar, /, divide)
144 
145 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, divide)
146 
147 BINARY_FUNCTION(scalar, scalar, scalar, pow)
148 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
149 BINARY_FUNCTION(scalar, scalar, label, integerPow)
150 BINARY_TYPE_FUNCTION_FS(scalar, scalar, label, integerPow)
151 BINARY_FUNCTION(scalar, scalar, label, integerRoot)
152 BINARY_TYPE_FUNCTION_FS(scalar, scalar, label, integerRoot)
153 
154 BINARY_FUNCTION(scalar, scalar, scalar, atan2)
155 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 UNARY_FUNCTION(scalar, scalar, pow3)
161 UNARY_FUNCTION(scalar, scalar, pow4)
162 UNARY_FUNCTION(scalar, scalar, pow5)
163 UNARY_FUNCTION(scalar, scalar, pow6)
164 UNARY_FUNCTION(scalar, scalar, pow025)
165 UNARY_FUNCTION(scalar, scalar, sqrt)
166 UNARY_FUNCTION(scalar, scalar, cbrt)
167 UNARY_FUNCTION(scalar, scalar, sign)
168 UNARY_FUNCTION(scalar, scalar, pos)
169 UNARY_FUNCTION(scalar, scalar, pos0)
170 UNARY_FUNCTION(scalar, scalar, neg)
171 UNARY_FUNCTION(scalar, scalar, neg0)
172 UNARY_FUNCTION(scalar, scalar, posPart)
173 UNARY_FUNCTION(scalar, scalar, negPart)
174 UNARY_FUNCTION(scalar, scalar, exp)
175 UNARY_FUNCTION(scalar, scalar, log)
176 UNARY_FUNCTION(scalar, scalar, log10)
177 UNARY_FUNCTION(scalar, scalar, sin)
178 UNARY_FUNCTION(scalar, scalar, cos)
179 UNARY_FUNCTION(scalar, scalar, tan)
180 UNARY_FUNCTION(scalar, scalar, asin)
181 UNARY_FUNCTION(scalar, scalar, acos)
182 UNARY_FUNCTION(scalar, scalar, atan)
183 UNARY_FUNCTION(scalar, scalar, sinh)
184 UNARY_FUNCTION(scalar, scalar, cosh)
185 UNARY_FUNCTION(scalar, scalar, tanh)
186 UNARY_FUNCTION(scalar, scalar, asinh)
187 UNARY_FUNCTION(scalar, scalar, acosh)
188 UNARY_FUNCTION(scalar, scalar, atanh)
189 UNARY_FUNCTION(scalar, scalar, erf)
190 UNARY_FUNCTION(scalar, scalar, erfc)
191 UNARY_FUNCTION(scalar, scalar, lgamma)
192 UNARY_FUNCTION(scalar, scalar, j0)
193 UNARY_FUNCTION(scalar, scalar, j1)
194 UNARY_FUNCTION(scalar, scalar, y0)
195 UNARY_FUNCTION(scalar, scalar, y1)
196 
197 #define BesselFunc(func) \
198 void func(scalarField& res, const int n, const UList<scalar>& sf) \
199 { \
200  TFOR_ALL_F_OP_FUNC_S_F(scalar, res, =, ::Foam::func, int, n, scalar, sf) \
201 } \
202  \
203 tmp<scalarField> func(const int n, const UList<scalar>& sf) \
204 { \
205  tmp<scalarField> tRes(new scalarField(sf.size())); \
206  func(tRes.ref(), n, sf); \
207  return tRes; \
208 } \
209  \
210 tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
211 { \
212  tmp<scalarField> tRes = New(tsf); \
213  func(tRes.ref(), n, tsf()); \
214  tsf.clear(); \
215  return tRes; \
216 }
217 
220 
221 #undef BesselFunc
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace Foam
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 #include "undefFieldFunctionsM.H"
231 
232 // ************************************************************************* //
#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
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:486
Pre-declare related SubField type.
Definition: SubField.H:63
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:253
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
volScalarField scalarField(fieldObject, mesh)
volScalarField sf(fieldObject, mesh)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
void subtract(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dimensionedScalar pos(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)
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
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dimensionedScalar lgamma(const dimensionedScalar &ds)
dimensionedScalar j1(const dimensionedScalar &ds)
dimensionedScalar y0(const dimensionedScalar &ds)
dimensionedScalar cosh(const dimensionedScalar &ds)
void pow025(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
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)
tmp< DimensionedField< scalar, GeoMesh, Field > > stabilise(const DimensionedField< scalar, GeoMesh, PrimitiveField > &dsf, const dimensioned< scalar > &ds)
scalar sumProd(const UList< scalar > &f1, const UList< scalar > &f2)
Definition: scalarField.C:122
void pow4(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
void divide(pointPatchField< Type > &f, const pointPatchField< Type > &f1, const pointPatchField< scalar > &f2)
void pow6(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensionedScalar log(const dimensionedScalar &ds)
void component(scalarField &sf, const UList< scalar > &f, const direction)
Definition: scalarField.C:47
dimensionedScalar y1(const dimensionedScalar &ds)
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar acosh(const dimensionedScalar &ds)
tmp< scalarField > linearSequence01(const label n)
Definition: scalarField.C:107
tmp< scalarField > stabilise(const tmp< scalarField > &tsf, const scalar s)
Definition: scalarField.C:88
void pow5(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< scalarField > jn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:218
void pow3(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensionedScalar neg(const dimensionedScalar &ds)
void cbrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensionedScalar atanh(const dimensionedScalar &ds)
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< scalar, GeoMesh, Field > > atan2(const DimensionedField< scalar, GeoMesh, PrimitiveField1 > &dsf1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &dsf2)
void multiply(pointPatchField< Type > &f, const pointPatchField< scalar > &f1, const pointPatchField< Type > &f2)
dimensionedScalar neg0(const dimensionedScalar &ds)
tmp< scalarField > linearSequence(const scalar start, const scalar end, const label n)
Definition: scalarField.C:98
tmp< scalarField > yn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:219
dimensionedScalar atan(const dimensionedScalar &ds)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
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)
dimensionedScalar asinh(const dimensionedScalar &ds)
labelList f(nPoints)
#define BesselFunc(func)
Definition: scalarField.C:197