1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
59 // Static data members
61 static const char* const typeName;
62 static const char* componentNames[];
63 static const Scalar zero;
64 static const Scalar one;
65 static const Scalar max;
66 static const Scalar min;
71 //- Construct from Scalar
72 pTraits(const Scalar s)
77 //- Construct from Istream
83 operator Scalar() const
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 //- Return a string representation of a Scalar
98 word name(const Scalar);
101 inline Scalar& setComponent(Scalar& s, const direction)
106 inline Scalar component(const Scalar s, const direction)
111 inline Scalar sign(const Scalar s)
113 return (s >= 0)? 1: -1;
116 inline Scalar pos(const Scalar s)
118 return (s >= 0)? 1: 0;
121 inline Scalar neg(const Scalar s)
123 return (s < 0)? 1: 0;
126 inline bool equal(const Scalar& s1, const Scalar& s2)
128 return mag(s1 - s2) <= ScalarVSMALL;
131 inline bool notEqual(const Scalar s1, const Scalar s2)
133 return mag(s1 - s2) > ScalarVSMALL;
136 inline Scalar limit(const Scalar s1, const Scalar s2)
138 return (mag(s1) < mag(s2)) ? s1: 0.0;
141 inline Scalar minMod(const Scalar s1, const Scalar s2)
143 return (mag(s1) < mag(s2)) ? s1: s2;
146 inline Scalar magSqr(const Scalar s)
151 inline Scalar sqr(const Scalar s)
156 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
158 Scalar maga = mag(a);
159 Scalar magb = mag(b);
163 return maga*sqrt(1.0 + sqr(magb/maga));
167 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
171 inline Scalar pow3(const Scalar s)
176 inline Scalar pow4(const Scalar s)
181 inline Scalar pow5(const Scalar s)
186 inline Scalar pow6(const Scalar s)
191 inline Scalar inv(const Scalar s)
196 inline Scalar dot(const Scalar s1, const Scalar s2)
201 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
206 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
211 inline Scalar cmptMax(const Scalar s)
216 inline Scalar cmptMin(const Scalar s)
221 inline Scalar cmptAv(const Scalar s)
226 inline Scalar cmptMag(const Scalar s)
232 // Standard C++ transcendental functions
251 // Standard ANSI-C (but not in <cmath>) transcendental functions
264 // Stabilisation around zero for division
265 inline Scalar stabilise(const Scalar s, const Scalar small)
278 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
280 Scalar readScalar(Istream&);
281 Istream& operator>>(Istream&, Scalar&);
282 Ostream& operator<<(Ostream&, const Scalar);
285 // ************************************************************************* //