Scalar.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 | Copyright (C) 2011-2015 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 Typedef
25  Foam::Scalar
26 
27 Description
28  Single floating point number (float or double)
29 
30 SourceFiles
31  Scalar.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 // template specialisation for pTraits<Scalar>
43 template<>
45 {
47 
48 public:
49 
50  //- Component type
51  typedef Scalar cmptType;
52 
53  //- Equivalent type of labels used for valid component indexing
54  typedef label labelType;
55 
56  // Member constants
57 
58  enum
59  {
60  dim = 3,
61  rank = 0,
62  nComponents = 1
63  };
64 
65  // Static data members
66 
67  static const char* const typeName;
68  static const char* componentNames[];
69  static const Scalar zero;
70  static const Scalar one;
71  static const Scalar max;
72  static const Scalar min;
73  static const Scalar rootMax;
74  static const Scalar rootMin;
75 
76  // Constructors
77 
78  //- Construct from primitive
79  explicit pTraits(const Scalar&);
80 
81  //- Construct from Istream
82  pTraits(Istream&);
83 
84 
85  // Member Functions
86 
87  //- Access to the Scalar value
88  operator Scalar() const
89  {
90  return p_;
91  }
92 
93  //- Access to the Scalar value
94  operator Scalar&()
95  {
96  return p_;
97  }
98 };
99 
100 
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 
103 //- Return a string representation of a Scalar
104 word name(const Scalar);
105 
106 
108 {
109  return s;
110 }
111 
112 
113 inline Scalar component(const Scalar s, const direction)
114 {
115  return s;
116 }
117 
118 
119 inline Scalar sign(const Scalar s)
120 {
121  return (s >= 0)? 1: -1;
122 }
123 
124 
125 inline Scalar pos(const Scalar s)
126 {
127  return (s >= 0)? 1: 0;
128 }
129 
130 
131 inline Scalar neg(const Scalar s)
132 {
133  return (s < 0)? 1: 0;
134 }
135 
136 
137 inline Scalar posPart(const Scalar s)
138 {
139  return (s > 0)? s: 0;
140 }
141 
142 
143 inline Scalar negPart(const Scalar s)
144 {
145  return (s < 0)? s: 0;
146 }
147 
148 
149 inline bool equal(const Scalar& s1, const Scalar& s2)
150 {
151  return mag(s1 - s2) <= ScalarVSMALL;
152 }
153 
154 
155 inline bool notEqual(const Scalar s1, const Scalar s2)
156 {
157  return mag(s1 - s2) > ScalarVSMALL;
158 }
159 
160 
161 inline Scalar limit(const Scalar s1, const Scalar s2)
162 {
163  return (mag(s1) < mag(s2)) ? s1: 0.0;
164 }
165 
166 
167 inline Scalar minMod(const Scalar s1, const Scalar s2)
168 {
169  return (mag(s1) < mag(s2)) ? s1: s2;
170 }
171 
172 
173 inline Scalar magSqr(const Scalar s)
174 {
175  return s*s;
176 }
177 
178 
179 inline Scalar sqr(const Scalar s)
180 {
181  return s*s;
182 }
183 
184 
185 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
186 {
187  Scalar maga = mag(a);
188  Scalar magb = mag(b);
189 
190  if (maga > magb)
191  {
192  return maga*sqrt(1.0 + sqr(magb/maga));
193  }
194  else
195  {
196  return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
197  }
198 }
199 
200 
201 inline Scalar pow3(const Scalar s)
202 {
203  return s*sqr(s);
204 }
205 
206 
207 inline Scalar pow4(const Scalar s)
208 {
209  return sqr(sqr(s));
210 }
211 
212 
213 inline Scalar pow5(const Scalar s)
214 {
215  return s*pow4(s);
216 }
217 
218 
219 inline Scalar pow6(const Scalar s)
220 {
221  return pow3(sqr(s));
222 }
223 
224 
225 inline Scalar pow025(const Scalar s)
226 {
227  return sqrt(sqrt(s));
228 }
229 
230 
231 inline Scalar inv(const Scalar s)
232 {
233  return 1.0/s;
234 }
235 
236 
237 inline Scalar dot(const Scalar s1, const Scalar s2)
238 {
239  return s1*s2;
240 }
241 
242 
243 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
244 {
245  return s1*s2;
246 }
247 
248 
249 inline Scalar cmptPow(const Scalar s1, const Scalar s2)
250 {
251  return pow(s1, s2);
252 }
253 
254 
255 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
256 {
257  return s1/s2;
258 }
259 
260 
261 inline Scalar cmptMax(const Scalar s)
262 {
263  return s;
264 }
265 
266 
267 inline Scalar cmptMin(const Scalar s)
268 {
269  return s;
270 }
271 
272 
273 inline Scalar cmptAv(const Scalar s)
274 {
275  return s;
276 }
277 
278 
279 inline Scalar cmptMag(const Scalar s)
280 {
281  return mag(s);
282 }
283 
284 
285 // Standard C++ transcendental functions
288 transFunc(exp)
289 transFunc(log)
291 transFunc(sin)
292 transFunc(cos)
293 transFunc(tan)
303 
304 // Standard ANSI-C (but not in <cmath>) transcendental functions
305 
306 transFunc(erf)
309 
310 transFunc(j0)
311 transFunc(j1)
312 
313 transFunc(y0)
314 transFunc(y1)
315 
316 
317 // Stabilisation around zero for division
318 inline Scalar stabilise(const Scalar s, const Scalar small)
319 {
320  if (s >= 0)
321  {
322  return s + small;
323  }
324  else
325  {
326  return s - small;
327  }
328 }
329 
330 
331 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
332 
333 Scalar readScalar(Istream&);
334 Istream& operator>>(Istream&, Scalar&);
335 Ostream& operator<<(Ostream&, const Scalar);
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 } // End namespace Foam
340 
341 // ************************************************************************* //
Foam::sqrtSumSqr
Scalar sqrtSumSqr(const Scalar a, const Scalar b)
Definition: Scalar.H:185
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:79
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::pTraits< Scalar >::labelType
label labelType
Equivalent type of labels used for valid component indexing.
Definition: Scalar.H:54
Foam::tan
dimensionedScalar tan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:257
Foam::cmptPow
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:249
Foam::cosh
dimensionedScalar cosh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::y1
dimensionedScalar y1(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:273
Foam::pTraits< Scalar >::cmptType
Scalar cmptType
Component type.
Definition: Scalar.H:51
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:255
Foam::posPart
dimensionedScalar posPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:212
Foam::dot
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:875
Foam::pTraits< Scalar >::min
static const Scalar min
Definition: Scalar.H:72
Scalar
Definition: Test-Dictionary.C:65
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:252
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:179
Foam::erf
dimensionedScalar erf(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:267
Scalar
#define Scalar
Definition: doubleScalar.C:33
Foam::pow025
dimensionedScalar pow025(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:131
Foam::cmptMin
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:269
Foam::cmptMag
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:359
Foam::atanh
dimensionedScalar atanh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:266
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:224
Foam::lgamma
dimensionedScalar lgamma(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:269
Foam::pow4
dimensionedScalar pow4(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:98
Foam::pow6
dimensionedScalar pow6(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:120
ScalarVSMALL
#define ScalarVSMALL
Definition: doubleScalar.C:35
Foam::label
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
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::tanh
dimensionedScalar tanh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:263
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:87
Foam::stabilise
tmp< DimensionedField< scalar, GeoMesh > > stabilise(const DimensionedField< scalar, GeoMesh > &dsf, const dimensioned< scalar > &ds)
Definition: DimensionedScalarField.C:40
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::pTraits< Scalar >::typeName
static const char *const typeName
Definition: Scalar.H:67
Foam::pTraits::pTraits
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
Foam::log10
dimensionedScalar log10(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:254
Foam::y0
dimensionedScalar y0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:272
Foam::erfc
dimensionedScalar erfc(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:268
Foam::asinh
dimensionedScalar asinh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::pTraits< Scalar >::rootMax
static const Scalar rootMax
Definition: Scalar.H:73
Foam::transFunc
transFunc(sqrt) transFunc(cbrt) transFunc(exp) transFunc(log) transFunc(log10) transFunc(sin) transFunc(cos) transFunc(tan) transFunc(asin) transFunc(acos) transFunc(atan) transFunc(sinh) transFunc(cosh) transFunc(tanh) transFunc(asinh) transFunc(acosh) transFunc(atanh) transFunc(erf) transFunc(erfc) transFunc(lgamma) transFunc(j0) transFunc(j1) transFunc(y0) transFunc(y1) inline Scalar stabilise(const Scalar s
Foam::pow5
dimensionedScalar pow5(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:109
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:253
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
s
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))
Foam::small
const Scalar small
Definition: Scalar.H:319
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::pTraits< Scalar >::one
static const Scalar one
Definition: Scalar.H:70
Foam::acosh
dimensionedScalar acosh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::negPart
dimensionedScalar negPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:223
Foam::cmptAv
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:252
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::minMod
Scalar minMod(const Scalar s1, const Scalar s2)
Definition: Scalar.H:167
Foam::pTraits< Scalar >::max
static const Scalar max
Definition: Scalar.H:71
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::j0
dimensionedScalar j0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:270
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::acos
dimensionedScalar acos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:259
Foam::limit
complex limit(const complex &, const complex &)
Definition: complexI.H:211
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::atan
dimensionedScalar atan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:260
Foam::pTraits< Scalar >::rootMin
static const Scalar rootMin
Definition: Scalar.H:74
Foam::cbrt
dimensionedScalar cbrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:153
Foam::j1
dimensionedScalar j1(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:271
Foam::equal
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:78
Foam::notEqual
bool notEqual(const Scalar s1, const Scalar s2)
Definition: Scalar.H:155
Foam::neg
dimensionedScalar neg(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:201
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::pTraits< Scalar >::zero
static const Scalar zero
Definition: Scalar.H:69
Foam::asin
dimensionedScalar asin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:258
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::pTraits< Scalar >::p_
Scalar p_
Definition: Scalar.H:46
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190
Foam::sinh
dimensionedScalar sinh(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:261