1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 od 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;
67 //- Construct from Istream
72 operator Scalar() const
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 // Return a string representation of a Scalar
82 word name(const Scalar s);
85 inline Scalar& setComponent(Scalar& s, const direction)
90 inline Scalar component(const Scalar s, const direction)
95 inline Scalar sign(const Scalar s)
97 return (s >= 0)? 1: -1;
100 inline Scalar pos(const Scalar s)
102 return (s >= 0)? 1: 0;
105 inline Scalar neg(const Scalar s)
107 return (s < 0)? 1: 0;
110 inline bool equal(const Scalar& s1, const Scalar& s2)
112 return mag(s1 - s2) <= ScalarVSMALL;
115 inline bool notEqual(const Scalar s1, const Scalar s2)
117 return mag(s1 - s2) > ScalarVSMALL;
120 inline Scalar limit(const Scalar s1, const Scalar s2)
122 return (mag(s1) < mag(s2)) ? s1: 0.0;
125 inline Scalar minMod(const Scalar s1, const Scalar s2)
127 return (mag(s1) < mag(s2)) ? s1: s2;
130 inline Scalar magSqr(const Scalar s)
135 inline Scalar sqr(const Scalar s)
140 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
142 Scalar maga = mag(a);
143 Scalar magb = mag(b);
147 return maga*sqrt(1.0 + sqr(magb/maga));
151 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
155 inline Scalar pow3(const Scalar s)
160 inline Scalar pow4(const Scalar s)
165 inline Scalar pow5(const Scalar s)
170 inline Scalar pow6(const Scalar s)
175 inline Scalar inv(const Scalar s)
180 inline Scalar dot(const Scalar s1, const Scalar s2)
185 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
190 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
195 inline Scalar cmptMax(const Scalar s)
200 inline Scalar cmptMin(const Scalar s)
205 inline Scalar cmptAv(const Scalar s)
210 inline Scalar cmptMag(const Scalar s)
216 // Standard C++ transcendental functions
235 // Standard ANSI-C (but not in <cmath>) transcendental functions
248 // Stabilisation around zero for division
249 inline Scalar stabilise(const Scalar s, const Scalar small)
262 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
264 Scalar readScalar(Istream& is);
265 Istream& operator>>(Istream&, Scalar&);
266 Ostream& operator<<(Ostream&, const Scalar);
269 // ************************************************************************* //