OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

floatScalar.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Typedef
00026     Foam::floatScalar
00027 
00028 Description
00029     single floating point number identical to float
00030 
00031 SourceFiles
00032     floatScalar.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef floatScalar_H
00037 #define floatScalar_H
00038 
00039 #include "label.H"
00040 #include "word.H"
00041 
00042 #include <cmath>
00043 
00044 #ifdef ibm
00045     float lgamma(float);
00046 #endif
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 // Define floatScalar as a float
00050 
00051 namespace Foam
00052 {
00053     typedef float floatScalar;
00054 }
00055 
00056 /*
00057 // Define floatScalar as a float
00058 
00059 namespace Foam
00060 {
00061     typedef float floatScalar;
00062 
00063     // Largest and smallest floatScalar values allowed in certain parts of the code
00064     // (6 is the number of significant figures in an
00065     //  IEEE single precision number.  See limits.h or float.h)
00066     static const floatScalar GREAT = 1.0e+6;
00067     static const floatScalar VGREAT = 1.0e+37;
00068     static const floatScalar SMALL = 1.0e-6;
00069     static const floatScalar VSMALL = 1.0e-37;
00070 }
00071 */
00072 
00073 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00074 
00075 #include "pTraits.H"
00076 #include "products.H"
00077 #include "direction.H"
00078 
00079 namespace Foam
00080 {
00081 
00082 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00083 
00084 // template specialisation for pTraits<floatScalar>
00085 template<>
00086 class pTraits<floatScalar>
00087 {
00088     floatScalar p_;
00089 
00090 public:
00091 
00092     //- Component type
00093     typedef floatScalar cmptType;
00094 
00095     // Member constants
00096 
00097         enum
00098         {
00099             dim = 3,         // Dimensionality of space
00100             rank = 0,        // Rank od floatScalar is 0
00101             nComponents = 1  // Number of components in floatScalar is 1
00102         };
00103 
00104     // Static data members
00105 
00106         static const char* const typeName;
00107         static const char* componentNames[];
00108         static const floatScalar zero;
00109         static const floatScalar one;
00110 
00111     // Constructors
00112 
00113         //- Construct from Istream
00114         pTraits(Istream& is);
00115 
00116     // Member Functions
00117 
00118         operator floatScalar() const
00119         {
00120             return p_;
00121         }
00122 };
00123 
00124 
00125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00126 
00127 //template<class Cmpt>
00128 //class typeOfRank<Cmpt, 0>
00129 //{
00130 //public:
00131 //
00132 //    typedef Cmpt type;
00133 //};
00134 
00135 
00136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00137 
00138 // Return a string representation of a floatScalar
00139 word name(const floatScalar s)
00140 {
00141     return name(scalar(s));
00142 }
00143 
00144 #define MAXMINPOW(retType, type1, type2)          \
00145                                                   \
00146 MAXMIN(retType, type1, type2)                     \
00147                                                   \
00148 inline float pow(const type1 s, const type2 e)   \
00149 {                                                 \
00150     return ::pow(float(s), float(e));           \
00151 }
00152 
00153 
00154 //MAXMINPOW(float, float, float)
00155 //MAXMINPOW(float, float, int)
00156 //MAXMINPOW(float, int, float)
00157 //MAXMINPOW(float, float, long)
00158 //MAXMINPOW(float, long, float)
00159 //MAXMINPOW(float, float, int)
00160 //MAXMINPOW(float, int, float)
00161 //MAXMINPOW(float, float, long)
00162 //MAXMINPOW(float, long, float)
00163 
00164 #undef MAXMINPOW
00165 
00166 
00167 inline floatScalar mag(const floatScalar s)
00168 {
00169     return ::fabs(s);
00170 }
00171 
00172 inline floatScalar sign(const floatScalar s)
00173 {
00174     return (s >= 0)? 1: -1;
00175 }
00176 
00177 inline floatScalar pos(const floatScalar s)
00178 {
00179     return (s >= 0)? 1: 0;
00180 }
00181 
00182 inline floatScalar neg(const floatScalar s)
00183 {
00184     return (s < 0)? 1: 0;
00185 }
00186 
00187 inline floatScalar limit(const floatScalar s1, const floatScalar s2)
00188 {
00189     return (mag(s1) < mag(s2))? s1: 0.0;
00190 }
00191 
00192 inline floatScalar magSqr(const floatScalar s)
00193 {
00194     return s*s;
00195 }
00196 
00197 inline floatScalar sqr(const floatScalar s)
00198 {
00199     return s*s;
00200 }
00201 
00202 inline floatScalar pow3(const floatScalar s)
00203 {
00204     return s*s*s;
00205 }
00206 
00207 inline floatScalar pow4(const floatScalar s)
00208 {
00209     return sqr(sqr(s));
00210 }
00211 
00212 inline floatScalar cmptAv(const floatScalar s)
00213 {
00214     return s;
00215 }
00216 
00217 inline floatScalar cmptMag(const floatScalar s)
00218 {
00219     return mag(s);
00220 }
00221 
00222 inline floatScalar scale(const floatScalar s, const floatScalar d)
00223 {
00224     return s*d;
00225 }
00226 
00227 
00228 #define transFunc(func)            \
00229 inline floatScalar func(const floatScalar s) \
00230 {                                  \
00231     return ::func(s);              \
00232 }
00233 
00234 // Standard C++ transcendental functions
00235 transFunc(sqrt)
00236 transFunc(exp)
00237 transFunc(log)
00238 transFunc(log10)
00239 transFunc(sin)
00240 transFunc(cos)
00241 transFunc(tan)
00242 transFunc(asin)
00243 transFunc(acos)
00244 transFunc(atan)
00245 transFunc(sinh)
00246 transFunc(cosh)
00247 transFunc(tanh)
00248 transFunc(asinh)
00249 transFunc(acosh)
00250 transFunc(atanh)
00251 
00252 // Standard ANSI-C (but not in <cmath>) transcendental functions
00253 transFunc(erf)
00254 transFunc(erfc)
00255 transFunc(lgamma)
00256 transFunc(j0)
00257 transFunc(j1)
00258 transFunc(y0)
00259 transFunc(y1)
00260 
00261 #undef transFunc
00262 
00263 // Stabilisation around zero for division
00264 inline floatScalar stabilise(const floatScalar s, const floatScalar 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 //floatScalar readScalar(Istream& is);
00280 Istream& operator>>(Istream&, floatScalar&);
00281 Ostream& operator<<(Ostream&, const floatScalar);
00282 
00283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00284 
00285 } // End namespace Foam
00286 
00287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00288 
00289 #endif
00290 
00291 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd