OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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-2007 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 Type
00026     Scalar
00027 
00028 Description
00029     Single floating point number
00030 
00031 SourceFiles
00032     Scalar.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 // template specialisation for pTraits<Scalar>
00039 template<>
00040 class pTraits<Scalar>
00041 {
00042     Scalar p_;
00043 
00044 public:
00045 
00046     //- Component type
00047     typedef Scalar cmptType;
00048 
00049     // Member constants
00050 
00051         enum
00052         {
00053             dim = 3,         // Dimensionality of space
00054             rank = 0,        // Rank od Scalar is 0
00055             nComponents = 1  // Number of components in Scalar is 1
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 
00065     // Constructors
00066 
00067         //- Construct from Istream
00068         pTraits(Istream& is);
00069 
00070     // Member Functions
00071 
00072         operator Scalar() const
00073         {
00074             return p_;
00075         }
00076 };
00077 
00078 
00079 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00080 
00081 // Return a string representation of a Scalar
00082 word name(const Scalar s);
00083 
00084 
00085 inline Scalar& setComponent(Scalar& s, const direction)
00086 {
00087     return s;
00088 }
00089 
00090 inline Scalar component(const Scalar s, const direction)
00091 {
00092     return s;
00093 }
00094 
00095 inline Scalar sign(const Scalar s)
00096 {
00097     return (s >= 0)? 1: -1;
00098 }
00099 
00100 inline Scalar pos(const Scalar s)
00101 {
00102     return (s >= 0)? 1: 0;
00103 }
00104 
00105 inline Scalar neg(const Scalar s)
00106 {
00107     return (s < 0)? 1: 0;
00108 }
00109 
00110 inline bool equal(const Scalar& s1, const Scalar& s2)
00111 {
00112     return mag(s1 - s2) <= ScalarVSMALL;
00113 }
00114 
00115 inline bool notEqual(const Scalar s1, const Scalar s2)
00116 {
00117     return mag(s1 - s2) > ScalarVSMALL;
00118 }
00119 
00120 inline Scalar limit(const Scalar s1, const Scalar s2)
00121 {
00122     return (mag(s1) < mag(s2)) ? s1: 0.0;
00123 }
00124 
00125 inline Scalar minMod(const Scalar s1, const Scalar s2)
00126 {
00127     return (mag(s1) < mag(s2)) ? s1: s2;
00128 }
00129 
00130 inline Scalar magSqr(const Scalar s)
00131 {
00132     return s*s;
00133 }
00134 
00135 inline Scalar sqr(const Scalar s)
00136 {
00137     return s*s;
00138 }
00139 
00140 inline Scalar pow3(const Scalar s)
00141 {
00142     return s*s*s;
00143 }
00144 
00145 inline Scalar pow4(const Scalar s)
00146 {
00147     return sqr(sqr(s));
00148 }
00149 
00150 inline Scalar cmptMax(const Scalar s)
00151 {
00152     return s;
00153 }
00154 
00155 inline Scalar cmptMin(const Scalar s)
00156 {
00157     return s;
00158 }
00159 
00160 inline Scalar cmptAv(const Scalar s)
00161 {
00162     return s;
00163 }
00164 
00165 inline Scalar cmptMag(const Scalar s)
00166 {
00167     return mag(s);
00168 }
00169 
00170 inline Scalar scale(const Scalar s, const Scalar d)
00171 {
00172     return s*d;
00173 }
00174 
00175 
00176 // Standard C++ transcendental functions
00177 transFunc(sqrt)
00178 transFunc(cbrt)
00179 transFunc(exp)
00180 transFunc(log)
00181 transFunc(log10)
00182 transFunc(sin)
00183 transFunc(cos)
00184 transFunc(tan)
00185 transFunc(asin)
00186 transFunc(acos)
00187 transFunc(atan)
00188 transFunc(sinh)
00189 transFunc(cosh)
00190 transFunc(tanh)
00191 transFunc(asinh)
00192 transFunc(acosh)
00193 transFunc(atanh)
00194 
00195 // Standard ANSI-C (but not in <cmath>) transcendental functions
00196 
00197 transFunc(erf)
00198 transFunc(erfc)
00199 transFunc(lgamma)
00200 
00201 transFunc(j0)
00202 transFunc(j1)
00203 
00204 transFunc(y0)
00205 transFunc(y1)
00206 
00207 
00208 // Stabilisation around zero for division
00209 inline Scalar stabilise(const Scalar s, const Scalar small)
00210 {
00211     if (s >= 0)
00212     {
00213         return s + small;
00214     }
00215     else
00216     {
00217         return s - small;
00218     }
00219 }
00220 
00221 
00222 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00223 
00224 Scalar readScalar(Istream& is);
00225 Istream& operator>>(Istream&, Scalar&);
00226 Ostream& operator<<(Ostream&, const Scalar);
00227 
00228 
00229 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd