1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 \*---------------------------------------------------------------------------*/
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // template specialisation for pTraits<Scalar>
49 typedef Scalar cmptType;
55 dim = 3, // Dimensionality of space
56 rank = 0, // Rank of Scalar is 0
57 nComponents = 1 // Number of components in Scalar is 1
61 // Static data members
63 static const char* const typeName;
64 static const char* componentNames[];
65 static const Scalar zero;
66 static const Scalar one;
67 static const Scalar max;
68 static const Scalar min;
73 //- Construct from Scalar
74 pTraits(const Scalar s)
79 //- Construct from Istream
85 operator Scalar() const
97 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99 //- Return a string representation of a Scalar
100 word name(const Scalar);
103 inline Scalar& setComponent(Scalar& s, const direction)
108 inline Scalar component(const Scalar s, const direction)
113 inline Scalar sign(const Scalar s)
115 return (s >= 0)? 1: -1;
118 inline Scalar pos(const Scalar s)
120 return (s >= 0)? 1: 0;
123 inline Scalar neg(const Scalar s)
125 return (s < 0)? 1: 0;
128 inline bool equal(const Scalar& s1, const Scalar& s2)
130 return mag(s1 - s2) <= ScalarVSMALL;
133 inline bool notEqual(const Scalar s1, const Scalar s2)
135 return mag(s1 - s2) > ScalarVSMALL;
138 inline Scalar limit(const Scalar s1, const Scalar s2)
140 return (mag(s1) < mag(s2)) ? s1: 0.0;
143 inline Scalar minMod(const Scalar s1, const Scalar s2)
145 return (mag(s1) < mag(s2)) ? s1: s2;
148 inline Scalar magSqr(const Scalar s)
153 inline Scalar sqr(const Scalar s)
158 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
160 Scalar maga = mag(a);
161 Scalar magb = mag(b);
165 return maga*sqrt(1.0 + sqr(magb/maga));
169 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
173 inline Scalar pow3(const Scalar s)
178 inline Scalar pow4(const Scalar s)
183 inline Scalar pow5(const Scalar s)
188 inline Scalar pow6(const Scalar s)
193 inline Scalar inv(const Scalar s)
198 inline Scalar dot(const Scalar s1, const Scalar s2)
203 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
208 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
213 inline Scalar cmptSumMultiply(const Scalar s1, const Scalar s2)
218 inline Scalar cmptMax(const Scalar s)
223 inline Scalar cmptMin(const Scalar s)
228 inline Scalar cmptAv(const Scalar s)
233 inline Scalar cmptMag(const Scalar s)
239 // Standard C++ transcendental functions
258 // Standard ANSI-C (but not in <cmath>) transcendental functions
271 // Stabilisation around zero for division
272 inline Scalar stabilise(const Scalar s, const Scalar small)
285 inline Scalar cmptStabilise
294 return sign(s)*value;
303 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
305 Scalar readScalar(Istream&);
306 Istream& operator>>(Istream&, Scalar&);
307 Ostream& operator<<(Ostream&, const Scalar);
310 // ************************************************************************* //