initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricScalarField / GeometricScalarField.C
blobfa6a2a58d0a2874f56b6ed7db2e7bc15af060f4c
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 "GeometricScalarField.H"
29 #define TEMPLATE template<template<class> class PatchField, class GeoMesh>
30 #include "GeometricFieldFunctionsM.C"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 template<template<class> class PatchField, class GeoMesh>
40 void stabilise
42     GeometricField<scalar, PatchField, GeoMesh>& result,
43     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
44     const dimensioned<scalar>& ds
47     stabilise(result.internalField(), gsf.internalField(), ds.value());
48     stabilise(result.boundaryField(), gsf.boundaryField(), ds.value());
52 template<template<class> class PatchField, class GeoMesh>
53 tmp<GeometricField<scalar, PatchField, GeoMesh> > stabilise
55     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
56     const dimensioned<scalar>& ds
59     tmp<GeometricField<scalar, PatchField, GeoMesh> > tRes
60     (
61         new GeometricField<scalar, PatchField, GeoMesh>
62         (
63             IOobject
64             (
65                 "stabilise(" + gsf.name() + ',' + ds.name() + ')',
66                 gsf.instance(),
67                 gsf.db(),
68                 IOobject::NO_READ,
69                 IOobject::NO_WRITE
70             ),
71             gsf.mesh(),
72             ds.dimensions() + gsf.dimensions()
73         )
74     );
76     stabilise(tRes(), gsf, ds);
78     return tRes;
82 template<template<class> class PatchField, class GeoMesh>
83 tmp<GeometricField<scalar, PatchField, GeoMesh> > stabilise
85     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
86     const dimensioned<scalar>& ds
89     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
91     tmp<GeometricField<scalar, PatchField, GeoMesh> > tRes
92     (
93         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
94         (
95             tgsf,
96             "stabilise(" + gsf.name() + ',' + ds.name() + ')',
97             ds.dimensions() + gsf.dimensions()
98         )
99     );
101     stabilise(tRes(), gsf, ds);
103     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
105     return tRes;
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, '+', add)
112 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, '-', subtract)
114 BINARY_OPERATOR(scalar, scalar, scalar, *, '*', multiply)
115 BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide)
117 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide)
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 template<template<class> class PatchField, class GeoMesh>
122 void pow
124     GeometricField<scalar, PatchField, GeoMesh>& Pow,
125     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
126     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
129     pow(Pow.internalField(), gsf1.internalField(), gsf2.internalField());
130     pow(Pow.boundaryField(), gsf1.boundaryField(), gsf2.boundaryField());
134 template<template<class> class PatchField, class GeoMesh>
135 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
137     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
138     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
141     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
142     (
143         new GeometricField<scalar, PatchField, GeoMesh>
144         (
145             IOobject
146             (
147                 "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
148                 gsf1.instance(),
149                 gsf1.db(),
150                 IOobject::NO_READ,
151                 IOobject::NO_WRITE
152             ),
153             gsf1.mesh(),
154             pow
155             (
156                 gsf1.dimensions(),
157                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
158             )
159         )
160     );
162     pow(tPow(), gsf1, gsf2);
164     return tPow;
168 template<template<class> class PatchField, class GeoMesh>
169 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
171     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf1,
172     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
175     const GeometricField<scalar, PatchField, GeoMesh>& gsf1 = tgsf1();
177     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
178     (
179         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
180         (
181             tgsf1,
182             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
183             pow
184             (
185                 gsf1.dimensions(),
186                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
187             )
188         )
189     );
191     pow(tPow(), gsf1, gsf2);
193     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf1);
195     return tPow;
199 template<template<class> class PatchField, class GeoMesh>
200 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
202     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
203     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf2
206     const GeometricField<scalar, PatchField, GeoMesh>& gsf2 = tgsf2();
208     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
209     (
210         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
211         (
212             tgsf2,
213             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
214             pow
215             (
216                 gsf1.dimensions(),
217                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
218             )
219         )
220     );
222     pow(tPow(), gsf1, gsf2);
224     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf2);
226     return tPow;
229 template<template<class> class PatchField, class GeoMesh>
230 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
232     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf1,
233     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf2
236     const GeometricField<scalar, PatchField, GeoMesh>& gsf1 = tgsf1();
237     const GeometricField<scalar, PatchField, GeoMesh>& gsf2 = tgsf2();
239     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
240     (
241         reuseTmpTmpGeometricField
242             <scalar, scalar, scalar, scalar, PatchField, GeoMesh>::New
243         (
244             tgsf1,
245             tgsf2,
246             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
247             pow
248             (
249                 gsf1.dimensions(),
250                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
251             )
252         )
253     );
255     pow(tPow(), gsf1, gsf2);
257     reuseTmpTmpGeometricField
258         <scalar, scalar, scalar, scalar, PatchField, GeoMesh>
259         ::clear(tgsf1, tgsf2);
261     return tPow;
265 template<template<class> class PatchField, class GeoMesh>
266 void pow
268     GeometricField<scalar, PatchField, GeoMesh>& tPow,
269     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
270     const dimensioned<scalar>& ds
273     pow(tPow.internalField(), gsf.internalField(), ds.value());
274     pow(tPow.boundaryField(), gsf.boundaryField(), ds.value());
278 template<template<class> class PatchField, class GeoMesh>
279 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
281     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
282     const dimensionedScalar& ds
285     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
286     (
287         new GeometricField<scalar, PatchField, GeoMesh>
288         (
289             IOobject
290             (
291                 "pow(" + gsf.name() + ',' + ds.name() + ')',
292                 gsf.instance(),
293                 gsf.db(),
294                 IOobject::NO_READ,
295                 IOobject::NO_WRITE
296             ),
297             gsf.mesh(),
298             pow(gsf.dimensions(), ds)
299         )
300     );
302     pow(tPow(), gsf, ds);
304     return tPow;
307 template<template<class> class PatchField, class GeoMesh>
308 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
310     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
311     const dimensionedScalar& ds
314     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
316     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
317     (
318         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
319         (
320             tgsf,
321             "pow(" + gsf.name() + ',' + ds.name() + ')',
322             pow(gsf.dimensions(), ds)
323         )
324     );
326     pow(tPow(), gsf, ds);
328     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
330     return tPow;
333 template<template<class> class PatchField, class GeoMesh>
334 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
336     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
337     const scalar& s
340     return pow(gsf, dimensionedScalar(s));
343 template<template<class> class PatchField, class GeoMesh>
344 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
346     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
347     const scalar& s
350     return pow(tgsf, dimensionedScalar(s));
354 template<template<class> class PatchField, class GeoMesh>
355 void pow
357     GeometricField<scalar, PatchField, GeoMesh>& tPow,
358     const dimensioned<scalar>& ds,
359     const GeometricField<scalar, PatchField, GeoMesh>& gsf
362     pow(tPow.internalField(), ds.value(), gsf.internalField());
363     pow(tPow.boundaryField(), ds.value(), gsf.boundaryField());
367 template<template<class> class PatchField, class GeoMesh>
368 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
370     const dimensionedScalar& ds,
371     const GeometricField<scalar, PatchField, GeoMesh>& gsf
374     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
375     (
376         new GeometricField<scalar, PatchField, GeoMesh>
377         (
378             IOobject
379             (
380                 "pow(" + ds.name() + ',' + gsf.name() + ')',
381                 gsf.instance(),
382                 gsf.db(),
383                 IOobject::NO_READ,
384                 IOobject::NO_WRITE
385             ),
386             gsf.mesh(),
387             pow(ds, gsf.dimensions())
388         )
389     );
391     pow(tPow(), ds, gsf);
393     return tPow;
397 template<template<class> class PatchField, class GeoMesh>
398 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
400     const dimensionedScalar& ds,
401     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf
404     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
406     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
407     (
408         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
409         (
410             tgsf,
411             "pow(" + ds.name() + ',' + gsf.name() + ')',
412             pow(ds, gsf.dimensions())
413         )
414     );
416     pow(tPow(), ds, gsf);
418     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
420     return tPow;
423 template<template<class> class PatchField, class GeoMesh>
424 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
426     const scalar& s,
427     const GeometricField<scalar, PatchField, GeoMesh>& gsf
430     return pow(dimensionedScalar(s), gsf);
433 template<template<class> class PatchField, class GeoMesh>
434 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
436     const scalar& s,
437     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf
440     return pow(dimensionedScalar(s), tgsf);
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 UNARY_FUNCTION(scalar, scalar, pow3, pow3)
447 UNARY_FUNCTION(scalar, scalar, pow4, pow4)
448 UNARY_FUNCTION(scalar, scalar, pow5, pow5)
449 UNARY_FUNCTION(scalar, scalar, pow6, pow6)
450 UNARY_FUNCTION(scalar, scalar, sqrt, sqrt)
451 UNARY_FUNCTION(scalar, scalar, sign, sign)
452 UNARY_FUNCTION(scalar, scalar, pos, pos)
453 UNARY_FUNCTION(scalar, scalar, neg, neg)
455 UNARY_FUNCTION(scalar, scalar, exp, trans)
456 UNARY_FUNCTION(scalar, scalar, log, trans)
457 UNARY_FUNCTION(scalar, scalar, log10, trans)
458 UNARY_FUNCTION(scalar, scalar, sin, trans)
459 UNARY_FUNCTION(scalar, scalar, cos, trans)
460 UNARY_FUNCTION(scalar, scalar, tan, trans)
461 UNARY_FUNCTION(scalar, scalar, asin, trans)
462 UNARY_FUNCTION(scalar, scalar, acos, trans)
463 UNARY_FUNCTION(scalar, scalar, atan, trans)
464 UNARY_FUNCTION(scalar, scalar, sinh, trans)
465 UNARY_FUNCTION(scalar, scalar, cosh, trans)
466 UNARY_FUNCTION(scalar, scalar, tanh, trans)
467 UNARY_FUNCTION(scalar, scalar, asinh, trans)
468 UNARY_FUNCTION(scalar, scalar, acosh, trans)
469 UNARY_FUNCTION(scalar, scalar, atanh, trans)
470 UNARY_FUNCTION(scalar, scalar, erf, trans)
471 UNARY_FUNCTION(scalar, scalar, erfc, trans)
472 UNARY_FUNCTION(scalar, scalar, lgamma, trans)
473 UNARY_FUNCTION(scalar, scalar, j0, trans)
474 UNARY_FUNCTION(scalar, scalar, j1, trans)
475 UNARY_FUNCTION(scalar, scalar, y0, trans)
476 UNARY_FUNCTION(scalar, scalar, y1, trans)
479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 #define BesselFunc(func)                                                     \
482                                                                             \
483 template<template<class> class PatchField, class GeoMesh>                   \
484 void func                                                                   \
485 (                                                                           \
486     GeometricField<scalar, PatchField, GeoMesh>& gsf,                       \
487     const int n,                                                            \
488     const GeometricField<scalar, PatchField, GeoMesh>& gsf1                 \
489 )                                                                           \
490 {                                                                           \
491     func(gsf.internalField(), n, gsf1.internalField());                     \
492     func(gsf.boundaryField(), n, gsf1.boundaryField());                     \
493 }                                                                           \
494                                                                             \
495 template<template<class> class PatchField, class GeoMesh>                   \
496 tmp<GeometricField<scalar, PatchField, GeoMesh> > func                      \
497 (                                                                           \
498     const int n,                                                            \
499     const GeometricField<scalar, PatchField, GeoMesh>& gsf                  \
500 )                                                                           \
501 {                                                                           \
502     if (!gsf.dimensions().dimensionless())                                  \
503     {                                                                       \
504         FatalErrorIn                                                        \
505         (                                                                   \
506             #func"(const int n, "                                           \
507             "const GeometricField<scalar, PatchField, GeoMesh>& gsf)"       \
508         )   << "gsf not dimensionless"                                      \
509             << abort(FatalError);                                           \
510     }                                                                       \
511                                                                             \
512     tmp<GeometricField<scalar, PatchField, GeoMesh> > tFunc                 \
513     (                                                                       \
514         new GeometricField<scalar, PatchField, GeoMesh>                     \
515         (                                                                   \
516             IOobject                                                        \
517             (                                                               \
518                 #func "(" + gsf.name() + ')',                               \
519                 gsf.instance(),                                             \
520                 gsf.db(),                                                   \
521                 IOobject::NO_READ,                                          \
522                 IOobject::NO_WRITE                                          \
523             ),                                                              \
524             gsf.mesh(),                                                     \
525             dimless                                                         \
526         )                                                                   \
527     );                                                                      \
528                                                                             \
529     func(tFunc(), n, gsf);                                                  \
530                                                                             \
531     return tFunc;                                                           \
532 }                                                                           \
533                                                                             \
534 template<template<class> class PatchField, class GeoMesh>                   \
535 tmp<GeometricField<scalar, PatchField, GeoMesh> > func                      \
536 (                                                                           \
537     const int n,                                                            \
538     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf           \
539 )                                                                           \
540 {                                                                           \
541     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();        \
542                                                                             \
543     if (!gsf.dimensions().dimensionless())                                  \
544     {                                                                       \
545         FatalErrorIn                                                        \
546         (                                                                   \
547             #func"(const int n, "                                           \
548             "const tmp<GeometricField<scalar, PatchField, GeoMesh> >& gsf)" \
549         )   << " : gsf not dimensionless"                                   \
550             << abort(FatalError);                                           \
551     }                                                                       \
552                                                                             \
553     tmp<GeometricField<scalar, PatchField, GeoMesh> > tFunc                 \
554     (                                                                       \
555         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New    \
556         (                                                                   \
557             tgsf,                                                           \
558             #func "(" + gsf.name() + ')',                                   \
559             dimless                                                         \
560         )                                                                   \
561     );                                                                      \
562                                                                             \
563     func(tFunc(), n, gsf);                                                  \
564                                                                             \
565     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>             \
566     ::clear(tgsf);                                                          \
567                                                                             \
568     return tFunc;                                                           \
571 BesselFunc(jn)
572 BesselFunc(yn)
574 #undef BesselFunc
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
579 } // End namespace Foam
581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
583 #include "undefFieldFunctionsM.H"
585 // ************************************************************************* //