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-2018 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 
48 void component(scalarField& sf, const UList<scalar>& f, const direction)
49 {
50  sf = f;
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 
74 tmp<scalarField> stabilise(const UList<scalar>& sf, const scalar s)
75 {
76  tmp<scalarField> tRes(new scalarField(sf.size()));
77  stabilise(tRes.ref(), sf, s);
78  return tRes;
79 }
80 
81 tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
82 {
83  tmp<scalarField> tRes = New(tsf);
84  stabilise(tRes.ref(), tsf(), s);
85  tsf.clear();
86  return tRes;
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 template<>
93 scalar sumProd(const UList<scalar>& f1, const UList<scalar>& f2)
94 {
95  if (f1.size() && (f1.size() == f2.size()))
96  {
97  scalar SumProd = 0.0;
98  TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, scalar, f1, *, scalar, f2)
99  return SumProd;
100  }
101  else
102  {
103  return 0.0;
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add)
111 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, subtract)
112 
113 BINARY_OPERATOR(scalar, scalar, scalar, *, multiply)
114 BINARY_OPERATOR(scalar, scalar, scalar, /, divide)
115 
116 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, divide)
117 
118 BINARY_FUNCTION(scalar, scalar, scalar, pow)
119 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
120 
121 BINARY_FUNCTION(scalar, scalar, scalar, atan2)
122 BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 UNARY_FUNCTION(scalar, scalar, pow3)
127 UNARY_FUNCTION(scalar, scalar, pow4)
128 UNARY_FUNCTION(scalar, scalar, pow5)
129 UNARY_FUNCTION(scalar, scalar, pow6)
130 UNARY_FUNCTION(scalar, scalar, pow025)
131 UNARY_FUNCTION(scalar, scalar, sqrt)
132 UNARY_FUNCTION(scalar, scalar, cbrt)
133 UNARY_FUNCTION(scalar, scalar, sign)
134 UNARY_FUNCTION(scalar, scalar, pos)
135 UNARY_FUNCTION(scalar, scalar, pos0)
136 UNARY_FUNCTION(scalar, scalar, neg)
137 UNARY_FUNCTION(scalar, scalar, neg0)
138 UNARY_FUNCTION(scalar, scalar, posPart)
139 UNARY_FUNCTION(scalar, scalar, negPart)
140 UNARY_FUNCTION(scalar, scalar, exp)
141 UNARY_FUNCTION(scalar, scalar, log)
142 UNARY_FUNCTION(scalar, scalar, log10)
143 UNARY_FUNCTION(scalar, scalar, sin)
144 UNARY_FUNCTION(scalar, scalar, cos)
145 UNARY_FUNCTION(scalar, scalar, tan)
146 UNARY_FUNCTION(scalar, scalar, asin)
147 UNARY_FUNCTION(scalar, scalar, acos)
148 UNARY_FUNCTION(scalar, scalar, atan)
149 UNARY_FUNCTION(scalar, scalar, sinh)
150 UNARY_FUNCTION(scalar, scalar, cosh)
151 UNARY_FUNCTION(scalar, scalar, tanh)
152 UNARY_FUNCTION(scalar, scalar, asinh)
153 UNARY_FUNCTION(scalar, scalar, acosh)
154 UNARY_FUNCTION(scalar, scalar, atanh)
155 UNARY_FUNCTION(scalar, scalar, erf)
156 UNARY_FUNCTION(scalar, scalar, erfc)
157 UNARY_FUNCTION(scalar, scalar, lgamma)
158 UNARY_FUNCTION(scalar, scalar, j0)
159 UNARY_FUNCTION(scalar, scalar, j1)
160 UNARY_FUNCTION(scalar, scalar, y0)
161 UNARY_FUNCTION(scalar, scalar, y1)
162 
163 UNARY_FUNCTION(scalar, scalar, degToRad)
164 UNARY_FUNCTION(scalar, scalar, radToDeg)
165 UNARY_FUNCTION(scalar, scalar, atmToPa)
166 UNARY_FUNCTION(scalar, scalar, paToAtm)
167 
168 
169 #define BesselFunc(func) \
170 void func(scalarField& res, const int n, const UList<scalar>& sf) \
171 { \
172  TFOR_ALL_F_OP_FUNC_S_F(scalar, res, =, ::Foam::func, int, n, scalar, sf) \
173 } \
174  \
175 tmp<scalarField> func(const int n, const UList<scalar>& sf) \
176 { \
177  tmp<scalarField> tRes(new scalarField(sf.size())); \
178  func(tRes.ref(), n, sf); \
179  return tRes; \
180 } \
181  \
182 tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
183 { \
184  tmp<scalarField> tRes = New(tsf); \
185  func(tRes.ref(), n, tsf()); \
186  tsf.clear(); \
187  return tRes; \
188 }
189 
192 
193 #undef BesselFunc
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #include "undefFieldFunctionsM.H"
203 
204 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionedScalar tanh(const dimensionedScalar &ds)
dimensionedScalar acos(const dimensionedScalar &ds)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:237
dimensionedScalar log(const dimensionedScalar &ds)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Unit conversion functions.
uint8_t direction
Definition: direction.H:45
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
dimensionedScalar y0(const dimensionedScalar &ds)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensionedScalar neg(const dimensionedScalar &ds)
scalar f1
Definition: createFields.H:15
dimensionedScalar asin(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
#define BesselFunc(func)
Definition: scalarField.C:169
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
dimensionedScalar j1(const dimensionedScalar &ds)
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
tmp< scalarField > jn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:190
tmp< scalarField > yn(const int n, const tmp< scalarField > &tsf)
Definition: scalarField.C:191
void component(scalarField &sf, const UList< scalar > &f, const direction)
Definition: scalarField.C:48
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedScalar acosh(const dimensionedScalar &ds)
scalar atmToPa(const scalar atm)
Conversion from atm to Pa.
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
dimensionedScalar asinh(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar atanh(const dimensionedScalar &ds)
dimensionedScalar y1(const dimensionedScalar &ds)
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:455
volScalarField scalarField(fieldObject, mesh)
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar sin(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar erf(const dimensionedScalar &ds)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:376
labelList f(nPoints)
volScalarField sf(fieldObject, mesh)
#define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2)
Definition: FieldM.H:210
dimensionedScalar lgamma(const dimensionedScalar &ds)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar pow3(const dimensionedScalar &ds)
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
dimensionedScalar erfc(const dimensionedScalar &ds)
scalar paToAtm(const scalar pa)
Conversion from atm to Pa.
dimensionedScalar sinh(const dimensionedScalar &ds)
scalar sumProd(const UList< scalar > &f1, const UList< scalar > &f2)
Definition: scalarField.C:93
dimensionedScalar atan(const dimensionedScalar &ds)
tmp< scalarField > stabilise(const tmp< scalarField > &tsf, const scalar s)
Definition: scalarField.C:81
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar cosh(const dimensionedScalar &ds)
A class for managing temporary objects.
Definition: PtrList.H:53
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
dimensionedScalar tan(const dimensionedScalar &ds)
dimensionedScalar j0(const dimensionedScalar &ds)
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedScalar log10(const dimensionedScalar &ds)
Namespace for OpenFOAM.
dimensionedScalar negPart(const dimensionedScalar &ds)