FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

Scalar_.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Typedef
00025     Foam::Scalar
00026 
00027 Description
00028     Single floating point number
00029 
00030 SourceFiles
00031     Scalar.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 // template specialisation for pTraits<Scalar>
00038 template<>
00039 class pTraits<Scalar>
00040 {
00041     Scalar p_;
00042 
00043 public:
00044 
00045     //- Component type
00046     typedef Scalar cmptType;
00047 
00048     // Member constants
00049 
00050         enum
00051         {
00052             dim = 3,         // Dimensionality of space
00053             rank = 0,        // Rank of Scalar is 0
00054             nComponents = 1  // Number of components in Scalar is 1
00055         };
00056 
00057 
00058     // Static data members
00059 
00060         static const char* const typeName;
00061         static const char* componentNames[];
00062         static const Scalar zero;
00063         static const Scalar one;
00064         static const Scalar max;
00065         static const Scalar min;
00066 
00067 
00068     // Constructors
00069 
00070         //- Construct from Scalar
00071         pTraits(const Scalar s)
00072         {
00073             p_ = s;
00074         }
00075 
00076         //- Construct from Istream
00077         pTraits(Istream&);
00078 
00079 
00080     // Member operators
00081 
00082         operator Scalar() const
00083         {
00084             return p_;
00085         }
00086 
00087         operator Scalar&()
00088         {
00089             return p_;
00090         }
00091 };
00092 
00093 
00094 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00095 
00096 //- Return a string representation of a Scalar
00097 word name(const Scalar);
00098 
00099 
00100 inline Scalar& setComponent(Scalar& s, const direction)
00101 {
00102     return s;
00103 }
00104 
00105 inline Scalar component(const Scalar s, const direction)
00106 {
00107     return s;
00108 }
00109 
00110 inline Scalar sign(const Scalar s)
00111 {
00112     return (s >= 0)? 1: -1;
00113 }
00114 
00115 inline Scalar pos(const Scalar s)
00116 {
00117     return (s >= 0)? 1: 0;
00118 }
00119 
00120 inline Scalar neg(const Scalar s)
00121 {
00122     return (s < 0)? 1: 0;
00123 }
00124 
00125 inline bool equal(const Scalar& s1, const Scalar& s2)
00126 {
00127     return mag(s1 - s2) <= ScalarVSMALL;
00128 }
00129 
00130 inline bool notEqual(const Scalar s1, const Scalar s2)
00131 {
00132     return mag(s1 - s2) > ScalarVSMALL;
00133 }
00134 
00135 inline Scalar limit(const Scalar s1, const Scalar s2)
00136 {
00137     return (mag(s1) < mag(s2)) ? s1: 0.0;
00138 }
00139 
00140 inline Scalar minMod(const Scalar s1, const Scalar s2)
00141 {
00142     return (mag(s1) < mag(s2)) ? s1: s2;
00143 }
00144 
00145 inline Scalar magSqr(const Scalar s)
00146 {
00147     return s*s;
00148 }
00149 
00150 inline Scalar sqr(const Scalar s)
00151 {
00152     return s*s;
00153 }
00154 
00155 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
00156 {
00157     Scalar maga = mag(a);
00158     Scalar magb = mag(b);
00159 
00160     if (maga > magb)
00161     {
00162         return maga*sqrt(1.0 + sqr(magb/maga));
00163     }
00164     else
00165     {
00166         return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
00167     }
00168 }
00169 
00170 inline Scalar pow3(const Scalar s)
00171 {
00172     return s*sqr(s);
00173 }
00174 
00175 inline Scalar pow4(const Scalar s)
00176 {
00177     return sqr(sqr(s));
00178 }
00179 
00180 inline Scalar pow5(const Scalar s)
00181 {
00182     return s*pow4(s);
00183 }
00184 
00185 inline Scalar pow6(const Scalar s)
00186 {
00187     return pow3(sqr(s));
00188 }
00189 
00190 inline Scalar inv(const Scalar s)
00191 {
00192     return 1.0/s;
00193 }
00194 
00195 inline Scalar dot(const Scalar s1, const Scalar s2)
00196 {
00197     return s1*s2;
00198 }
00199 
00200 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
00201 {
00202     return s1*s2;
00203 }
00204 
00205 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
00206 {
00207     return s1/s2;
00208 }
00209 
00210 inline Scalar cmptMax(const Scalar s)
00211 {
00212     return s;
00213 }
00214 
00215 inline Scalar cmptMin(const Scalar s)
00216 {
00217     return s;
00218 }
00219 
00220 inline Scalar cmptAv(const Scalar s)
00221 {
00222     return s;
00223 }
00224 
00225 inline Scalar cmptMag(const Scalar s)
00226 {
00227     return mag(s);
00228 }
00229 
00230 
00231 // Standard C++ transcendental functions
00232 transFunc(sqrt)
00233 transFunc(cbrt)
00234 transFunc(exp)
00235 transFunc(log)
00236 transFunc(log10)
00237 transFunc(sin)
00238 transFunc(cos)
00239 transFunc(tan)
00240 transFunc(asin)
00241 transFunc(acos)
00242 transFunc(atan)
00243 transFunc(sinh)
00244 transFunc(cosh)
00245 transFunc(tanh)
00246 transFunc(asinh)
00247 transFunc(acosh)
00248 transFunc(atanh)
00249 
00250 // Standard ANSI-C (but not in <cmath>) transcendental functions
00251 
00252 transFunc(erf)
00253 transFunc(erfc)
00254 transFunc(lgamma)
00255 
00256 transFunc(j0)
00257 transFunc(j1)
00258 
00259 transFunc(y0)
00260 transFunc(y1)
00261 
00262 
00263 // Stabilisation around zero for division
00264 inline Scalar stabilise(const Scalar s, const Scalar small)
00265 {
00266     if (s >= 0)
00267     {
00268         return s + small;
00269     }
00270     else
00271     {
00272         return s - small;
00273     }
00274 }
00275 
00276 
00277 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00278 
00279 Scalar readScalar(Istream&);
00280 Istream& operator>>(Istream&, Scalar&);
00281 Ostream& operator<<(Ostream&, const Scalar);
00282 
00283 
00284 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines