1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Single floating point number
33 \*---------------------------------------------------------------------------*/
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // template specialisation for pTraits<Scalar>
48 typedef Scalar cmptType;
54 dim = 3, // Dimensionality of space
55 rank = 0, // Rank of Scalar is 0
56 nComponents = 1 // Number of components in Scalar is 1
60 // Static data members
62 static const char* const typeName;
63 static const char* componentNames[];
64 static const Scalar zero;
65 static const Scalar one;
66 static const Scalar max;
67 static const Scalar min;
72 //- Construct from Scalar
73 pTraits(const Scalar s)
78 //- Construct from Istream
84 operator Scalar() const
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 //- Return a string representation of a Scalar
99 word name(const Scalar);
102 inline Scalar& setComponent(Scalar& s, const direction)
107 inline Scalar component(const Scalar s, const direction)
112 inline Scalar sign(const Scalar s)
114 return (s >= 0)? 1: -1;
117 inline Scalar pos(const Scalar s)
119 return (s >= 0)? 1: 0;
122 inline Scalar neg(const Scalar s)
124 return (s < 0)? 1: 0;
127 inline bool equal(const Scalar& s1, const Scalar& s2)
129 return mag(s1 - s2) <= ScalarVSMALL;
132 inline bool notEqual(const Scalar s1, const Scalar s2)
134 return mag(s1 - s2) > ScalarVSMALL;
137 inline Scalar limit(const Scalar s1, const Scalar s2)
139 return (mag(s1) < mag(s2)) ? s1: 0.0;
142 inline Scalar minMod(const Scalar s1, const Scalar s2)
144 return (mag(s1) < mag(s2)) ? s1: s2;
147 inline Scalar magSqr(const Scalar s)
152 inline Scalar sqr(const Scalar s)
157 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
159 Scalar maga = mag(a);
160 Scalar magb = mag(b);
164 return maga*sqrt(1.0 + sqr(magb/maga));
168 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
172 inline Scalar pow3(const Scalar s)
177 inline Scalar pow4(const Scalar s)
182 inline Scalar pow5(const Scalar s)
187 inline Scalar pow6(const Scalar s)
192 inline Scalar inv(const Scalar s)
197 inline Scalar dot(const Scalar s1, const Scalar s2)
202 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
207 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
212 inline Scalar cmptSumMultiply(const Scalar s1, const Scalar s2)
217 inline Scalar cmptMax(const Scalar s)
222 inline Scalar cmptMin(const Scalar s)
227 inline Scalar cmptAv(const Scalar s)
232 inline Scalar cmptMag(const Scalar s)
238 // Standard C++ transcendental functions
257 // Standard ANSI-C (but not in <cmath>) transcendental functions
270 // Stabilisation around zero for division
271 inline Scalar stabilise(const Scalar s, const Scalar small)
284 inline Scalar cmptStabilise
293 return sign(s)*value;
302 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
304 Scalar readScalar(Istream&);
305 Istream& operator>>(Istream&, Scalar&);
306 Ostream& operator<<(Ostream&, const Scalar);
309 // ************************************************************************* //