Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / DimensionedFields / DimensionedScalarField / DimensionedScalarField.C
blob89a5fdec0edcf45b78f77053b265d2311b3f2172
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "DimensionedScalarField.H"
28 #define TEMPLATE template<class GeoMesh>
29 #include "DimensionedFieldFunctionsM.C"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
38 template<class GeoMesh>
39 tmp<DimensionedField<scalar, GeoMesh> > stabilise
41     const DimensionedField<scalar, GeoMesh>& dsf,
42     const dimensioned<scalar>& ds
45     tmp<DimensionedField<scalar, GeoMesh> > tRes
46     (
47         new DimensionedField<scalar, GeoMesh>
48         (
49             IOobject
50             (
51                 "stabilise(" + dsf.name() + ',' + ds.name() + ')',
52                 dsf.instance(),
53                 dsf.db()
54             ),
55             dsf.mesh(),
56             dsf.dimensions() + ds.dimensions()
57         )
58     );
60     stabilise(tRes().field(), dsf.field(), ds.value());
62     return tRes;
66 template<class GeoMesh>
67 tmp<DimensionedField<scalar, GeoMesh> > stabilise
69     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
70     const dimensioned<scalar>& ds
73     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
75     tmp<DimensionedField<scalar, GeoMesh> > tRes =
76         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
77         (
78             tdsf,
79             "stabilise(" + dsf.name() + ',' + ds.name() + ')',
80             dsf.dimensions() + ds.dimensions()
81         );
83     stabilise(tRes().field(), dsf.field(), ds.value());
85     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
87     return tRes;
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, '+', add)
94 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, '-', subtract)
96 BINARY_OPERATOR(scalar, scalar, scalar, *, '*', multiply)
97 BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide)
99 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide)
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 template<class GeoMesh>
104 tmp<DimensionedField<scalar, GeoMesh> > pow
106     const DimensionedField<scalar, GeoMesh>& dsf1,
107     const DimensionedField<scalar, GeoMesh>& dsf2
110     tmp<DimensionedField<scalar, GeoMesh> > tPow
111     (
112         new DimensionedField<scalar, GeoMesh>
113         (
114             IOobject
115             (
116                 "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
117                 dsf1.instance(),
118                 dsf1.db()
119             ),
120             dsf1.mesh(),
121             pow
122             (
123                 dsf1.dimensions(),
124                 dimensionedScalar("1", 1.0, dsf2.dimensions())
125             )
126         )
127     );
129     pow(tPow().field(), dsf1.field(), dsf2.field());
131     return tPow;
135 template<class GeoMesh>
136 tmp<DimensionedField<scalar, GeoMesh> > pow
138     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
139     const DimensionedField<scalar, GeoMesh>& dsf2
142     const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
144     tmp<DimensionedField<scalar, GeoMesh> > tPow =
145         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
146         (
147             tdsf1,
148             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
149             pow
150             (
151                 dsf1.dimensions(),
152                 dimensionedScalar("1", 1.0, dsf2.dimensions())
153             )
154         );
156     pow(tPow().field(), dsf1.field(), dsf2.field());
158     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf1);
160     return tPow;
164 template<class GeoMesh>
165 tmp<DimensionedField<scalar, GeoMesh> > pow
167     const DimensionedField<scalar, GeoMesh>& dsf1,
168     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf2
171     const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
173     tmp<DimensionedField<scalar, GeoMesh> > tPow =
174         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
175         (
176             tdsf2,
177             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
178             pow
179             (
180                 dsf1.dimensions(),
181                 dimensionedScalar("1", 1.0, dsf2.dimensions())
182             )
183         );
185     pow(tPow().field(), dsf1.field(), dsf2.field());
187     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf2);
189     return tPow;
192 template<class GeoMesh>
193 tmp<DimensionedField<scalar, GeoMesh> > pow
195     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf1,
196     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf2
199     const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
200     const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
202     tmp<DimensionedField<scalar, GeoMesh> > tPow =
203         reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::
204         New
205         (
206             tdsf1,
207             tdsf2,
208             "pow(" + dsf1.name() + ',' + dsf2.name() + ')',
209             pow
210             (
211                 dsf1.dimensions(),
212                 dimensionedScalar("1", 1.0, dsf2.dimensions())
213             )
214         );
216     pow(tPow().field(), dsf1.field(), dsf2.field());
218     reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::clear
219     (
220         tdsf1,
221         tdsf2
222     );
224     return tPow;
228 template<class GeoMesh>
229 tmp<DimensionedField<scalar, GeoMesh> > pow
231     const DimensionedField<scalar, GeoMesh>& dsf,
232     const dimensionedScalar& ds
235     tmp<DimensionedField<scalar, GeoMesh> > tPow
236     (
237         new DimensionedField<scalar, GeoMesh>
238         (
239             IOobject
240             (
241                 "pow(" + dsf.name() + ',' + ds.name() + ')',
242                 dsf.instance(),
243                 dsf.db()
244             ),
245             dsf.mesh(),
246             pow(dsf.dimensions(), ds)
247         )
248     );
250     pow(tPow().field(), dsf.field(), ds.value());
252     return tPow;
255 template<class GeoMesh>
256 tmp<DimensionedField<scalar, GeoMesh> > pow
258     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
259     const dimensionedScalar& ds
262     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
264     tmp<DimensionedField<scalar, GeoMesh> > tPow =
265         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
266         (
267             tdsf,
268             "pow(" + dsf.name() + ',' + ds.name() + ')',
269             pow(dsf.dimensions(), ds)
270         );
272     pow(tPow().field(), dsf.field(), ds.value());
274     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
276     return tPow;
279 template<class GeoMesh>
280 tmp<DimensionedField<scalar, GeoMesh> > pow
282     const DimensionedField<scalar, GeoMesh>& dsf,
283     const scalar& s
286     return pow(dsf, dimensionedScalar(s));
289 template<class GeoMesh>
290 tmp<DimensionedField<scalar, GeoMesh> > pow
292     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf,
293     const scalar& s
296     return pow(tdsf, dimensionedScalar(s));
300 template<class GeoMesh>
301 tmp<DimensionedField<scalar, GeoMesh> > pow
303     const dimensionedScalar& ds,
304     const DimensionedField<scalar, GeoMesh>& dsf
307     tmp<DimensionedField<scalar, GeoMesh> > tPow
308     (
309         new DimensionedField<scalar, GeoMesh>
310         (
311             IOobject
312             (
313                 "pow(" + ds.name() + ',' + dsf.name() + ')',
314                 dsf.instance(),
315                 dsf.db()
316             ),
317             dsf.mesh(),
318             pow(ds, dsf.dimensions())
319         )
320     );
322     pow(tPow().field(), ds.value(), dsf.field());
324     return tPow;
328 template<class GeoMesh>
329 tmp<DimensionedField<scalar, GeoMesh> > pow
331     const dimensionedScalar& ds,
332     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf
335     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
337     tmp<DimensionedField<scalar, GeoMesh> > tPow =
338         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
339         (
340             tdsf,
341             "pow(" + ds.name() + ',' + dsf.name() + ')',
342             pow(ds, dsf.dimensions())
343         );
345     pow(tPow().field(), ds.value(), dsf.field());
347     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
349     return tPow;
352 template<class GeoMesh>
353 tmp<DimensionedField<scalar, GeoMesh> > pow
355     const scalar& s,
356     const DimensionedField<scalar, GeoMesh>& dsf
359     return pow(dimensionedScalar(s), dsf);
362 template<class GeoMesh>
363 tmp<DimensionedField<scalar, GeoMesh> > pow
365     const scalar& s,
366     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf
369     return pow(dimensionedScalar(s), tdsf);
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 UNARY_FUNCTION(scalar, scalar, pow3, pow3)
375 UNARY_FUNCTION(scalar, scalar, pow4, pow4)
376 UNARY_FUNCTION(scalar, scalar, pow5, pow5)
377 UNARY_FUNCTION(scalar, scalar, pow6, pow6)
378 UNARY_FUNCTION(scalar, scalar, pow025, pow025)
379 UNARY_FUNCTION(scalar, scalar, sqrt, sqrt)
380 UNARY_FUNCTION(scalar, scalar, sign, sign)
381 UNARY_FUNCTION(scalar, scalar, pos, pos)
382 UNARY_FUNCTION(scalar, scalar, neg, neg)
384 UNARY_FUNCTION(scalar, scalar, exp, trans)
385 UNARY_FUNCTION(scalar, scalar, log, trans)
386 UNARY_FUNCTION(scalar, scalar, log10, trans)
387 UNARY_FUNCTION(scalar, scalar, sin, trans)
388 UNARY_FUNCTION(scalar, scalar, cos, trans)
389 UNARY_FUNCTION(scalar, scalar, tan, trans)
390 UNARY_FUNCTION(scalar, scalar, asin, trans)
391 UNARY_FUNCTION(scalar, scalar, acos, trans)
392 UNARY_FUNCTION(scalar, scalar, atan, trans)
393 UNARY_FUNCTION(scalar, scalar, sinh, trans)
394 UNARY_FUNCTION(scalar, scalar, cosh, trans)
395 UNARY_FUNCTION(scalar, scalar, tanh, trans)
396 UNARY_FUNCTION(scalar, scalar, asinh, trans)
397 UNARY_FUNCTION(scalar, scalar, acosh, trans)
398 UNARY_FUNCTION(scalar, scalar, atanh, trans)
399 UNARY_FUNCTION(scalar, scalar, erf, trans)
400 UNARY_FUNCTION(scalar, scalar, erfc, trans)
401 UNARY_FUNCTION(scalar, scalar, lgamma, trans)
402 UNARY_FUNCTION(scalar, scalar, j0, trans)
403 UNARY_FUNCTION(scalar, scalar, j1, trans)
404 UNARY_FUNCTION(scalar, scalar, y0, trans)
405 UNARY_FUNCTION(scalar, scalar, y1, trans)
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 #define BesselFunc(func)                                                    \
411                                                                             \
412 template<class GeoMesh>                                                     \
413 tmp<DimensionedField<scalar, GeoMesh> > func                                \
414 (                                                                           \
415     const int n,                                                            \
416     const DimensionedField<scalar, GeoMesh>& dsf                            \
417 )                                                                           \
418 {                                                                           \
419     if (!dsf.dimensions().dimensionless())                                  \
420     {                                                                       \
421         FatalErrorIn                                                        \
422         (                                                                   \
423             #func"(const int n, "                                           \
424             "const DimensionedField<scalar, GeoMesh>& dsf)"                 \
425         )   << "dsf not dimensionless"                                      \
426             << abort(FatalError);                                           \
427     }                                                                       \
428                                                                             \
429     tmp<DimensionedField<scalar, GeoMesh> > tFunc                           \
430     (                                                                       \
431         new DimensionedField<scalar, GeoMesh>                               \
432         (                                                                   \
433             IOobject                                                        \
434             (                                                               \
435                 #func "(" + name(n) + ',' + dsf.name() + ')',               \
436                 dsf.instance(),                                             \
437                 dsf.db()                                                    \
438             ),                                                              \
439             dsf.mesh(),                                                     \
440             dimless                                                         \
441         )                                                                   \
442     );                                                                      \
443                                                                             \
444     func(tFunc().field(), n, dsf.field());                                  \
445                                                                             \
446     return tFunc;                                                           \
447 }                                                                           \
448                                                                             \
449 template<class GeoMesh>                                                     \
450 tmp<DimensionedField<scalar, GeoMesh> > func                                \
451 (                                                                           \
452     const int n,                                                            \
453     const tmp<DimensionedField<scalar, GeoMesh> >& tdsf                     \
454 )                                                                           \
455 {                                                                           \
456     const DimensionedField<scalar, GeoMesh>& dsf = tdsf();                  \
457                                                                             \
458     if (!dsf.dimensions().dimensionless())                                  \
459     {                                                                       \
460         FatalErrorIn                                                        \
461         (                                                                   \
462             #func"(const int n, "                                           \
463             "const tmp<DimensionedField<scalar, GeoMesh> >& dsf)"           \
464         )   << " : dsf not dimensionless"                                   \
465             << abort(FatalError);                                           \
466     }                                                                       \
467                                                                             \
468     tmp<DimensionedField<scalar, GeoMesh> > tFunc                           \
469     (                                                                       \
470         reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New              \
471         (                                                                   \
472             tdsf,                                                           \
473             #func "(" + name(n) + ',' + dsf.name() + ')',                   \
474             dimless                                                         \
475         )                                                                   \
476     );                                                                      \
477                                                                             \
478     func(tFunc().field(), n, dsf.field());                                  \
479                                                                             \
480     reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);         \
481                                                                             \
482     return tFunc;                                                           \
485 BesselFunc(jn)
486 BesselFunc(yn)
488 #undef BesselFunc
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
493 } // End namespace Foam
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 #include "undefFieldFunctionsM.H"
499 // ************************************************************************* //