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

dimensionedScalar.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "dimensionedScalar.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 dimensionedScalar operator+(const dimensionedScalar& ds1, const scalar s2)
00037 {
00038     return ds1 + dimensionedScalar(s2);
00039 }
00040 
00041 dimensionedScalar operator+(const scalar s1, const dimensionedScalar& ds2)
00042 {
00043     return dimensionedScalar(s1) + ds2;
00044 }
00045 
00046 dimensionedScalar operator-(const dimensionedScalar& ds1, const scalar s2)
00047 {
00048     return ds1 - dimensionedScalar(s2);
00049 }
00050 
00051 dimensionedScalar operator-(const scalar s1, const dimensionedScalar& ds2)
00052 {
00053     return dimensionedScalar(s1) - ds2;
00054 }
00055 
00056 dimensionedScalar operator*(const dimensionedScalar& ds1, const scalar s2)
00057 {
00058     return ds1 * dimensionedScalar(s2);
00059 }
00060 
00061 dimensionedScalar operator/(const scalar s1, const dimensionedScalar& ds2)
00062 {
00063     return dimensionedScalar(s1)/ds2;
00064 }
00065 
00066 
00067 dimensionedScalar pow
00068 (
00069     const dimensionedScalar& ds,
00070     const dimensionedScalar& expt
00071 )
00072 {
00073     return dimensionedScalar
00074     (
00075         "pow(" + ds.name() + ',' + expt.name() + ')',
00076         pow(ds.dimensions(), expt),
00077         ::pow(ds.value(), expt.value())
00078     );
00079 }
00080 
00081 dimensionedScalar pow3(const dimensionedScalar& ds)
00082 {
00083     return dimensionedScalar
00084     (
00085         "pow3(" + ds.name() + ')',
00086         pow3(ds.dimensions()),
00087         pow3(ds.value())
00088     );
00089 }
00090 
00091 dimensionedScalar pow4(const dimensionedScalar& ds)
00092 {
00093     return dimensionedScalar
00094     (
00095         "pow4(" + ds.name() + ')',
00096         pow4(ds.dimensions()),
00097         pow4(ds.value())
00098     );
00099 }
00100 
00101 dimensionedScalar pow5(const dimensionedScalar& ds)
00102 {
00103     return dimensionedScalar
00104     (
00105         "pow5(" + ds.name() + ')',
00106         pow5(ds.dimensions()),
00107         pow5(ds.value())
00108     );
00109 }
00110 
00111 dimensionedScalar pow6(const dimensionedScalar& ds)
00112 {
00113     return dimensionedScalar
00114     (
00115         "pow6(" + ds.name() + ')',
00116         pow6(ds.dimensions()),
00117         pow6(ds.value())
00118     );
00119 }
00120 
00121 dimensionedScalar sqrt(const dimensionedScalar& ds)
00122 {
00123     return dimensionedScalar
00124     (
00125         "sqrt(" + ds.name() + ')',
00126         pow(ds.dimensions(), dimensionedScalar("0.5", dimless, 0.5)),
00127         ::sqrt(ds.value())
00128     );
00129 }
00130 
00131 dimensionedScalar cbrt(const dimensionedScalar& ds)
00132 {
00133     return dimensionedScalar
00134     (
00135         "cbrt(" + ds.name() + ')',
00136         pow(ds.dimensions(), dimensionedScalar("(1/3)", dimless, 1.0/3.0)),
00137         ::cbrt(ds.value())
00138     );
00139 }
00140 
00141 dimensionedScalar hypot
00142 (
00143     const dimensionedScalar& x,
00144     const dimensionedScalar& y
00145 )
00146 {
00147     return dimensionedScalar
00148     (
00149         "hypot(" + x.name() + ',' + y.name() + ')',
00150         x.dimensions() + y.dimensions(),
00151         ::hypot(x.value(), y.value())
00152     );
00153 }
00154 
00155 dimensionedScalar sign(const dimensionedScalar& ds)
00156 {
00157     return dimensionedScalar
00158     (
00159         "sign(" + ds.name() + ')',
00160         sign(ds.dimensions()),
00161         ::Foam::sign(ds.value())
00162     );
00163 }
00164 
00165 dimensionedScalar pos(const dimensionedScalar& ds)
00166 {
00167     return dimensionedScalar
00168     (
00169         "pos(" + ds.name() + ')',
00170         pos(ds.dimensions()),
00171         ::Foam::pos(ds.value())
00172     );
00173 }
00174 
00175 dimensionedScalar neg(const dimensionedScalar& ds)
00176 {
00177     return dimensionedScalar
00178     (
00179         "neg(" + ds.name() + ')',
00180         neg(ds.dimensions()),
00181         ::Foam::neg(ds.value())
00182     );
00183 }
00184 
00185 
00186 #define transFunc(func)                                                    \
00187 dimensionedScalar func(const dimensionedScalar& ds)                        \
00188 {                                                                          \
00189     if (!ds.dimensions().dimensionless())                                  \
00190     {                                                                      \
00191         FatalErrorIn(#func "(const dimensionedScalar& ds)")                \
00192             << "ds not dimensionless"                                      \
00193             << abort(FatalError);                                          \
00194     }                                                                      \
00195                                                                            \
00196     return dimensionedScalar                                               \
00197     (                                                                      \
00198         #func "(" + ds.name() + ')',                                       \
00199         dimless,                                                           \
00200         ::func(ds.value())                                                 \
00201     );                                                                     \
00202 }
00203 
00204 transFunc(exp)
00205 transFunc(log)
00206 transFunc(log10)
00207 transFunc(sin)
00208 transFunc(cos)
00209 transFunc(tan)
00210 transFunc(asin)
00211 transFunc(acos)
00212 transFunc(atan)
00213 transFunc(sinh)
00214 transFunc(cosh)
00215 transFunc(tanh)
00216 transFunc(asinh)
00217 transFunc(acosh)
00218 transFunc(atanh)
00219 transFunc(erf)
00220 transFunc(erfc)
00221 transFunc(lgamma)
00222 transFunc(j0)
00223 transFunc(j1)
00224 transFunc(y0)
00225 transFunc(y1)
00226 
00227 #undef transFunc
00228 
00229 
00230 #define transFunc(func)                                                    \
00231 dimensionedScalar func(const int n, const dimensionedScalar& ds)           \
00232 {                                                                          \
00233     if (!ds.dimensions().dimensionless())                                  \
00234     {                                                                      \
00235         FatalErrorIn(#func "(const int n, const dimensionedScalar& ds)")   \
00236             << "ds not dimensionless"                                      \
00237             << abort(FatalError);                                          \
00238     }                                                                      \
00239                                                                            \
00240     return dimensionedScalar                                               \
00241     (                                                                      \
00242         #func "(" + name(n) + ',' + ds.name() + ')',                      \
00243         dimless,                                                           \
00244         ::func(n, ds.value())                                              \
00245     );                                                                     \
00246 }
00247 
00248 transFunc(jn)
00249 transFunc(yn)
00250 
00251 #undef transFunc
00252 
00253 
00254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00255 
00256 } // End namespace Foam
00257 
00258 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd