Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / dimensionedTypes / dimensionedScalar / dimensionedScalar.C
blob44a4f6c89501cb9e68c6e9167760e52d483e703f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dimensionedScalar.H"
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 namespace Foam
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 dimensionedScalar operator+(const dimensionedScalar& ds1, const scalar s2)
37     return ds1 + dimensionedScalar(s2);
40 dimensionedScalar operator+(const scalar s1, const dimensionedScalar& ds2)
42     return dimensionedScalar(s1) + ds2;
45 dimensionedScalar operator-(const dimensionedScalar& ds1, const scalar s2)
47     return ds1 - dimensionedScalar(s2);
50 dimensionedScalar operator-(const scalar s1, const dimensionedScalar& ds2)
52     return dimensionedScalar(s1) - ds2;
55 dimensionedScalar operator*(const dimensionedScalar& ds1, const scalar s2)
57     return ds1 * dimensionedScalar(s2);
60 dimensionedScalar operator/(const scalar s1, const dimensionedScalar& ds2)
62     return dimensionedScalar(s1)/ds2;
66 dimensionedScalar pow
68     const dimensionedScalar& ds,
69     const dimensionedScalar& expt
72     return dimensionedScalar
73     (
74         "pow(" + ds.name() + ',' + expt.name() + ')',
75         pow(ds.dimensions(), expt),
76         ::pow(ds.value(), expt.value())
77     );
80 dimensionedScalar pow3(const dimensionedScalar& ds)
82     return dimensionedScalar
83     (
84         "pow3(" + ds.name() + ')',
85         pow3(ds.dimensions()),
86         pow3(ds.value())
87     );
90 dimensionedScalar pow4(const dimensionedScalar& ds)
92     return dimensionedScalar
93     (
94         "pow4(" + ds.name() + ')',
95         pow4(ds.dimensions()),
96         pow4(ds.value())
97     );
100 dimensionedScalar pow5(const dimensionedScalar& ds)
102     return dimensionedScalar
103     (
104         "pow5(" + ds.name() + ')',
105         pow5(ds.dimensions()),
106         pow5(ds.value())
107     );
110 dimensionedScalar pow6(const dimensionedScalar& ds)
112     return dimensionedScalar
113     (
114         "pow6(" + ds.name() + ')',
115         pow6(ds.dimensions()),
116         pow6(ds.value())
117     );
120 dimensionedScalar sqrt(const dimensionedScalar& ds)
122     return dimensionedScalar
123     (
124         "sqrt(" + ds.name() + ')',
125         pow(ds.dimensions(), dimensionedScalar("0.5", dimless, 0.5)),
126         ::sqrt(ds.value())
127     );
130 dimensionedScalar cbrt(const dimensionedScalar& ds)
132     return dimensionedScalar
133     (
134         "cbrt(" + ds.name() + ')',
135         pow(ds.dimensions(), dimensionedScalar("(1|3)", dimless, 1.0/3.0)),
136         ::cbrt(ds.value())
137     );
140 dimensionedScalar hypot
142     const dimensionedScalar& x,
143     const dimensionedScalar& y
146     return dimensionedScalar
147     (
148         "hypot(" + x.name() + ',' + y.name() + ')',
149         x.dimensions() + y.dimensions(),
150         ::hypot(x.value(), y.value())
151     );
154 dimensionedScalar sign(const dimensionedScalar& ds)
156     return dimensionedScalar
157     (
158         "sign(" + ds.name() + ')',
159         sign(ds.dimensions()),
160         ::Foam::sign(ds.value())
161     );
164 dimensionedScalar pos(const dimensionedScalar& ds)
166     return dimensionedScalar
167     (
168         "pos(" + ds.name() + ')',
169         pos(ds.dimensions()),
170         ::Foam::pos(ds.value())
171     );
174 dimensionedScalar neg(const dimensionedScalar& ds)
176     return dimensionedScalar
177     (
178         "neg(" + ds.name() + ')',
179         neg(ds.dimensions()),
180         ::Foam::neg(ds.value())
181     );
185 #define transFunc(func)                                                    \
186 dimensionedScalar func(const dimensionedScalar& ds)                        \
187 {                                                                          \
188     if (!ds.dimensions().dimensionless())                                  \
189     {                                                                      \
190         FatalErrorIn(#func "(const dimensionedScalar& ds)")                \
191             << "ds not dimensionless"                                      \
192             << abort(FatalError);                                          \
193     }                                                                      \
194                                                                            \
195     return dimensionedScalar                                               \
196     (                                                                      \
197         #func "(" + ds.name() + ')',                                       \
198         dimless,                                                           \
199         ::func(ds.value())                                                 \
200     );                                                                     \
203 transFunc(exp)
204 transFunc(log)
205 transFunc(log10)
206 transFunc(sin)
207 transFunc(cos)
208 transFunc(tan)
209 transFunc(asin)
210 transFunc(acos)
211 transFunc(atan)
212 transFunc(sinh)
213 transFunc(cosh)
214 transFunc(tanh)
215 transFunc(asinh)
216 transFunc(acosh)
217 transFunc(atanh)
218 transFunc(erf)
219 transFunc(erfc)
220 transFunc(lgamma)
221 transFunc(j0)
222 transFunc(j1)
223 transFunc(y0)
224 transFunc(y1)
226 #undef transFunc
229 #define transFunc(func)                                                    \
230 dimensionedScalar func(const int n, const dimensionedScalar& ds)           \
231 {                                                                          \
232     if (!ds.dimensions().dimensionless())                                  \
233     {                                                                      \
234         FatalErrorIn(#func "(const int n, const dimensionedScalar& ds)")   \
235             << "ds not dimensionless"                                      \
236             << abort(FatalError);                                          \
237     }                                                                      \
238                                                                            \
239     return dimensionedScalar                                               \
240     (                                                                      \
241         #func "(" + name(n) + ',' + ds.name() + ')',                      \
242         dimless,                                                           \
243         ::func(n, ds.value())                                              \
244     );                                                                     \
247 transFunc(jn)
248 transFunc(yn)
250 #undef transFunc
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 } // End namespace Foam
257 // ************************************************************************* //