1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Single floating point number
34 \*---------------------------------------------------------------------------*/
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // template specialisation for pTraits<Scalar>
47 typedef Scalar cmptType;
53 dim = 3, // Dimensionality of space
54 rank = 0, // Rank of Scalar is 0
55 nComponents = 1 // Number of components in Scalar is 1
58 // Static data members
60 static const char* const typeName;
61 static const char* componentNames[];
62 static const Scalar zero;
63 static const Scalar one;
64 static const Scalar max;
65 static const Scalar min;
69 //- Construct from Scalar
70 pTraits(const Scalar s)
75 //- Construct from Istream
81 operator Scalar() const
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 //- Return a string representation of a Scalar
91 word name(const Scalar);
94 inline Scalar& setComponent(Scalar& s, const direction)
99 inline Scalar component(const Scalar s, const direction)
104 inline Scalar sign(const Scalar s)
106 return (s >= 0)? 1: -1;
109 inline Scalar pos(const Scalar s)
111 return (s >= 0)? 1: 0;
114 inline Scalar neg(const Scalar s)
116 return (s < 0)? 1: 0;
119 inline bool equal(const Scalar& s1, const Scalar& s2)
121 return mag(s1 - s2) <= ScalarVSMALL;
124 inline bool notEqual(const Scalar s1, const Scalar s2)
126 return mag(s1 - s2) > ScalarVSMALL;
129 inline Scalar limit(const Scalar s1, const Scalar s2)
131 return (mag(s1) < mag(s2)) ? s1: 0.0;
134 inline Scalar minMod(const Scalar s1, const Scalar s2)
136 return (mag(s1) < mag(s2)) ? s1: s2;
139 inline Scalar magSqr(const Scalar s)
144 inline Scalar sqr(const Scalar s)
149 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
151 Scalar maga = mag(a);
152 Scalar magb = mag(b);
156 return maga*sqrt(1.0 + sqr(magb/maga));
160 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
164 inline Scalar pow3(const Scalar s)
169 inline Scalar pow4(const Scalar s)
174 inline Scalar pow5(const Scalar s)
179 inline Scalar pow6(const Scalar s)
184 inline Scalar inv(const Scalar s)
189 inline Scalar dot(const Scalar s1, const Scalar s2)
194 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
199 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
204 inline Scalar cmptMax(const Scalar s)
209 inline Scalar cmptMin(const Scalar s)
214 inline Scalar cmptAv(const Scalar s)
219 inline Scalar cmptMag(const Scalar s)
225 // Standard C++ transcendental functions
244 // Standard ANSI-C (but not in <cmath>) transcendental functions
257 // Stabilisation around zero for division
258 inline Scalar stabilise(const Scalar s, const Scalar small)
271 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
273 Scalar readScalar(Istream&);
274 Istream& operator>>(Istream&, Scalar&);
275 Ostream& operator<<(Ostream&, const Scalar);
278 // ************************************************************************* //