initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / dimensionedTypes / dimensionedScalar / dimensionedScalar.C
blob8761396a0ff0cef0c55fe96f587d58a7d11ba03a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "dimensionedScalar.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 dimensionedScalar operator+(const dimensionedScalar& ds1, const scalar s2)
38     return ds1 + dimensionedScalar(s2);
41 dimensionedScalar operator+(const scalar s1, const dimensionedScalar& ds2)
43     return dimensionedScalar(s1) + ds2;
46 dimensionedScalar operator-(const dimensionedScalar& ds1, const scalar s2)
48     return ds1 - dimensionedScalar(s2);
51 dimensionedScalar operator-(const scalar s1, const dimensionedScalar& ds2)
53     return dimensionedScalar(s1) - ds2;
56 dimensionedScalar operator*(const dimensionedScalar& ds1, const scalar s2)
58     return ds1 * dimensionedScalar(s2);
61 dimensionedScalar operator/(const scalar s1, const dimensionedScalar& ds2)
63     return dimensionedScalar(s1)/ds2;
67 dimensionedScalar pow
69     const dimensionedScalar& ds,
70     const dimensionedScalar& expt
73     return dimensionedScalar
74     (
75         "pow(" + ds.name() + ',' + expt.name() + ')',
76         pow(ds.dimensions(), expt),
77         ::pow(ds.value(), expt.value())
78     );
81 dimensionedScalar pow3(const dimensionedScalar& ds)
83     return dimensionedScalar
84     (
85         "pow3(" + ds.name() + ')',
86         pow3(ds.dimensions()),
87         pow3(ds.value())
88     );
91 dimensionedScalar pow4(const dimensionedScalar& ds)
93     return dimensionedScalar
94     (
95         "pow4(" + ds.name() + ')',
96         pow4(ds.dimensions()),
97         pow4(ds.value())
98     );
101 dimensionedScalar pow5(const dimensionedScalar& ds)
103     return dimensionedScalar
104     (
105         "pow5(" + ds.name() + ')',
106         pow5(ds.dimensions()),
107         pow5(ds.value())
108     );
111 dimensionedScalar pow6(const dimensionedScalar& ds)
113     return dimensionedScalar
114     (
115         "pow6(" + ds.name() + ')',
116         pow6(ds.dimensions()),
117         pow6(ds.value())
118     );
121 dimensionedScalar sqrt(const dimensionedScalar& ds)
123     return dimensionedScalar
124     (
125         "sqrt(" + ds.name() + ')',
126         pow(ds.dimensions(), dimensionedScalar("0.5", dimless, 0.5)),
127         ::sqrt(ds.value())
128     );
131 dimensionedScalar cbrt(const dimensionedScalar& ds)
133     return dimensionedScalar
134     (
135         "cbrt(" + ds.name() + ')',
136         pow(ds.dimensions(), dimensionedScalar("(1/3)", dimless, 1.0/3.0)),
137         ::cbrt(ds.value())
138     );
141 dimensionedScalar hypot
143     const dimensionedScalar& x,
144     const dimensionedScalar& y
147     return dimensionedScalar
148     (
149         "hypot(" + x.name() + ',' + y.name() + ')',
150         x.dimensions() + y.dimensions(),
151         ::hypot(x.value(), y.value())
152     );
155 dimensionedScalar sign(const dimensionedScalar& ds)
157     return dimensionedScalar
158     (
159         "sign(" + ds.name() + ')',
160         sign(ds.dimensions()),
161         ::Foam::sign(ds.value())
162     );
165 dimensionedScalar pos(const dimensionedScalar& ds)
167     return dimensionedScalar
168     (
169         "pos(" + ds.name() + ')',
170         pos(ds.dimensions()),
171         ::Foam::pos(ds.value())
172     );
175 dimensionedScalar neg(const dimensionedScalar& ds)
177     return dimensionedScalar
178     (
179         "neg(" + ds.name() + ')',
180         neg(ds.dimensions()),
181         ::Foam::neg(ds.value())
182     );
186 #define transFunc(func)                                                    \
187 dimensionedScalar func(const dimensionedScalar& ds)                        \
188 {                                                                          \
189     if (!ds.dimensions().dimensionless())                                  \
190     {                                                                      \
191         FatalErrorIn(#func "(const dimensionedScalar& ds)")                \
192             << "ds not dimensionless"                                      \
193             << abort(FatalError);                                          \
194     }                                                                      \
195                                                                            \
196     return dimensionedScalar                                               \
197     (                                                                      \
198         #func "(" + ds.name() + ')',                                       \
199         dimless,                                                           \
200         ::func(ds.value())                                                 \
201     );                                                                     \
204 transFunc(exp)
205 transFunc(log)
206 transFunc(log10)
207 transFunc(sin)
208 transFunc(cos)
209 transFunc(tan)
210 transFunc(asin)
211 transFunc(acos)
212 transFunc(atan)
213 transFunc(sinh)
214 transFunc(cosh)
215 transFunc(tanh)
216 transFunc(asinh)
217 transFunc(acosh)
218 transFunc(atanh)
219 transFunc(erf)
220 transFunc(erfc)
221 transFunc(lgamma)
222 transFunc(j0)
223 transFunc(j1)
224 transFunc(y0)
225 transFunc(y1)
227 #undef transFunc
230 #define transFunc(func)                                                    \
231 dimensionedScalar func(const int n, const dimensionedScalar& ds)           \
232 {                                                                          \
233     if (!ds.dimensions().dimensionless())                                  \
234     {                                                                      \
235         FatalErrorIn(#func "(const int n, const dimensionedScalar& ds)")   \
236             << "ds not dimensionless"                                      \
237             << abort(FatalError);                                          \
238     }                                                                      \
239                                                                            \
240     return dimensionedScalar                                               \
241     (                                                                      \
242         #func "(" + name(n) + ',' + ds.name() + ')',                      \
243         dimless,                                                           \
244         ::func(n, ds.value())                                              \
245     );                                                                     \
248 transFunc(jn)
249 transFunc(yn)
251 #undef transFunc
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 } // End namespace Foam
258 // ************************************************************************* //