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

GeometricScalarField.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 "GeometricScalarField.H"
00028 
00029 #define TEMPLATE template<template<class> class PatchField, class GeoMesh>
00030 #include "GeometricFieldFunctionsM.C"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00038 
00039 template<template<class> class PatchField, class GeoMesh>
00040 void stabilise
00041 (
00042     GeometricField<scalar, PatchField, GeoMesh>& result,
00043     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
00044     const dimensioned<scalar>& ds
00045 )
00046 {
00047     stabilise(result.internalField(), gsf.internalField(), ds.value());
00048     stabilise(result.boundaryField(), gsf.boundaryField(), ds.value());
00049 }
00050 
00051 
00052 template<template<class> class PatchField, class GeoMesh>
00053 tmp<GeometricField<scalar, PatchField, GeoMesh> > stabilise
00054 (
00055     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
00056     const dimensioned<scalar>& ds
00057 )
00058 {
00059     tmp<GeometricField<scalar, PatchField, GeoMesh> > tRes
00060     (
00061         new GeometricField<scalar, PatchField, GeoMesh>
00062         (
00063             IOobject
00064             (
00065                 "stabilise(" + gsf.name() + ',' + ds.name() + ')',
00066                 gsf.instance(),
00067                 gsf.db(),
00068                 IOobject::NO_READ,
00069                 IOobject::NO_WRITE
00070             ),
00071             gsf.mesh(),
00072             ds.dimensions() + gsf.dimensions()
00073         )
00074     );
00075 
00076     stabilise(tRes(), gsf, ds);
00077 
00078     return tRes;
00079 }
00080 
00081 
00082 template<template<class> class PatchField, class GeoMesh>
00083 tmp<GeometricField<scalar, PatchField, GeoMesh> > stabilise
00084 (
00085     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
00086     const dimensioned<scalar>& ds
00087 )
00088 {
00089     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
00090 
00091     tmp<GeometricField<scalar, PatchField, GeoMesh> > tRes
00092     (
00093         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
00094         (
00095             tgsf,
00096             "stabilise(" + gsf.name() + ',' + ds.name() + ')',
00097             ds.dimensions() + gsf.dimensions()
00098         )
00099     );
00100 
00101     stabilise(tRes(), gsf, ds);
00102 
00103     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
00104 
00105     return tRes;
00106 }
00107 
00108 
00109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00110 
00111 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, '+', add)
00112 BINARY_TYPE_OPERATOR(scalar, scalar, scalar, -, '-', subtract)
00113 
00114 BINARY_OPERATOR(scalar, scalar, scalar, *, '*', multiply)
00115 BINARY_OPERATOR(scalar, scalar, scalar, /, '|', divide)
00116 
00117 BINARY_TYPE_OPERATOR_SF(scalar, scalar, scalar, /, '|', divide)
00118 
00119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00120 
00121 template<template<class> class PatchField, class GeoMesh>
00122 void pow
00123 (
00124     GeometricField<scalar, PatchField, GeoMesh>& Pow,
00125     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
00126     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
00127 )
00128 {
00129     pow(Pow.internalField(), gsf1.internalField(), gsf2.internalField());
00130     pow(Pow.boundaryField(), gsf1.boundaryField(), gsf2.boundaryField());
00131 }
00132 
00133 
00134 template<template<class> class PatchField, class GeoMesh>
00135 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00136 (
00137     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
00138     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
00139 )
00140 {
00141     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00142     (
00143         new GeometricField<scalar, PatchField, GeoMesh>
00144         (
00145             IOobject
00146             (
00147                 "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
00148                 gsf1.instance(),
00149                 gsf1.db(),
00150                 IOobject::NO_READ,
00151                 IOobject::NO_WRITE
00152             ),
00153             gsf1.mesh(),
00154             pow
00155             (
00156                 gsf1.dimensions(),
00157                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
00158             )
00159         )
00160     );
00161 
00162     pow(tPow(), gsf1, gsf2);
00163 
00164     return tPow;
00165 }
00166 
00167 
00168 template<template<class> class PatchField, class GeoMesh>
00169 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00170 (
00171     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf1,
00172     const GeometricField<scalar, PatchField, GeoMesh>& gsf2
00173 )
00174 {
00175     const GeometricField<scalar, PatchField, GeoMesh>& gsf1 = tgsf1();
00176 
00177     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00178     (
00179         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
00180         (
00181             tgsf1,
00182             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
00183             pow
00184             (
00185                 gsf1.dimensions(),
00186                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
00187             )
00188         )
00189     );
00190 
00191     pow(tPow(), gsf1, gsf2);
00192 
00193     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf1);
00194 
00195     return tPow;
00196 }
00197 
00198 
00199 template<template<class> class PatchField, class GeoMesh>
00200 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00201 (
00202     const GeometricField<scalar, PatchField, GeoMesh>& gsf1,
00203     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf2
00204 )
00205 {
00206     const GeometricField<scalar, PatchField, GeoMesh>& gsf2 = tgsf2();
00207 
00208     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00209     (
00210         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
00211         (
00212             tgsf2,
00213             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
00214             pow
00215             (
00216                 gsf1.dimensions(),
00217                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
00218             )
00219         )
00220     );
00221 
00222     pow(tPow(), gsf1, gsf2);
00223 
00224     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf2);
00225 
00226     return tPow;
00227 }
00228 
00229 template<template<class> class PatchField, class GeoMesh>
00230 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00231 (
00232     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf1,
00233     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf2
00234 )
00235 {
00236     const GeometricField<scalar, PatchField, GeoMesh>& gsf1 = tgsf1();
00237     const GeometricField<scalar, PatchField, GeoMesh>& gsf2 = tgsf2();
00238 
00239     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00240     (
00241         reuseTmpTmpGeometricField
00242             <scalar, scalar, scalar, scalar, PatchField, GeoMesh>::New
00243         (
00244             tgsf1,
00245             tgsf2,
00246             "pow(" + gsf1.name() + ',' + gsf2.name() + ')',
00247             pow
00248             (
00249                 gsf1.dimensions(),
00250                 dimensionedScalar("1", gsf2.dimensions(), 1.0)
00251             )
00252         )
00253     );
00254 
00255     pow(tPow(), gsf1, gsf2);
00256 
00257     reuseTmpTmpGeometricField
00258         <scalar, scalar, scalar, scalar, PatchField, GeoMesh>
00259         ::clear(tgsf1, tgsf2);
00260 
00261     return tPow;
00262 }
00263 
00264 
00265 template<template<class> class PatchField, class GeoMesh>
00266 void pow
00267 (
00268     GeometricField<scalar, PatchField, GeoMesh>& tPow,
00269     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
00270     const dimensioned<scalar>& ds
00271 )
00272 {
00273     pow(tPow.internalField(), gsf.internalField(), ds.value());
00274     pow(tPow.boundaryField(), gsf.boundaryField(), ds.value());
00275 }
00276 
00277 
00278 template<template<class> class PatchField, class GeoMesh>
00279 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00280 (
00281     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
00282     const dimensionedScalar& ds
00283 )
00284 {
00285     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00286     (
00287         new GeometricField<scalar, PatchField, GeoMesh>
00288         (
00289             IOobject
00290             (
00291                 "pow(" + gsf.name() + ',' + ds.name() + ')',
00292                 gsf.instance(),
00293                 gsf.db(),
00294                 IOobject::NO_READ,
00295                 IOobject::NO_WRITE
00296             ),
00297             gsf.mesh(),
00298             pow(gsf.dimensions(), ds)
00299         )
00300     );
00301 
00302     pow(tPow(), gsf, ds);
00303 
00304     return tPow;
00305 }
00306 
00307 template<template<class> class PatchField, class GeoMesh>
00308 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00309 (
00310     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
00311     const dimensionedScalar& ds
00312 )
00313 {
00314     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
00315 
00316     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00317     (
00318         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
00319         (
00320             tgsf,
00321             "pow(" + gsf.name() + ',' + ds.name() + ')',
00322             pow(gsf.dimensions(), ds)
00323         )
00324     );
00325 
00326     pow(tPow(), gsf, ds);
00327 
00328     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
00329 
00330     return tPow;
00331 }
00332 
00333 template<template<class> class PatchField, class GeoMesh>
00334 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00335 (
00336     const GeometricField<scalar, PatchField, GeoMesh>& gsf,
00337     const scalar& s
00338 )
00339 {
00340     return pow(gsf, dimensionedScalar(s));
00341 }
00342 
00343 template<template<class> class PatchField, class GeoMesh>
00344 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00345 (
00346     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf,
00347     const scalar& s
00348 )
00349 {
00350     return pow(tgsf, dimensionedScalar(s));
00351 }
00352 
00353 
00354 template<template<class> class PatchField, class GeoMesh>
00355 void pow
00356 (
00357     GeometricField<scalar, PatchField, GeoMesh>& tPow,
00358     const dimensioned<scalar>& ds,
00359     const GeometricField<scalar, PatchField, GeoMesh>& gsf
00360 )
00361 {
00362     pow(tPow.internalField(), ds.value(), gsf.internalField());
00363     pow(tPow.boundaryField(), ds.value(), gsf.boundaryField());
00364 }
00365 
00366 
00367 template<template<class> class PatchField, class GeoMesh>
00368 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00369 (
00370     const dimensionedScalar& ds,
00371     const GeometricField<scalar, PatchField, GeoMesh>& gsf
00372 )
00373 {
00374     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00375     (
00376         new GeometricField<scalar, PatchField, GeoMesh>
00377         (
00378             IOobject
00379             (
00380                 "pow(" + ds.name() + ',' + gsf.name() + ')',
00381                 gsf.instance(),
00382                 gsf.db(),
00383                 IOobject::NO_READ,
00384                 IOobject::NO_WRITE
00385             ),
00386             gsf.mesh(),
00387             pow(ds, gsf.dimensions())
00388         )
00389     );
00390 
00391     pow(tPow(), ds, gsf);
00392 
00393     return tPow;
00394 }
00395 
00396 
00397 template<template<class> class PatchField, class GeoMesh>
00398 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00399 (
00400     const dimensionedScalar& ds,
00401     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf
00402 )
00403 {
00404     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();
00405 
00406     tmp<GeometricField<scalar, PatchField, GeoMesh> > tPow
00407     (
00408         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New
00409         (
00410             tgsf,
00411             "pow(" + ds.name() + ',' + gsf.name() + ')',
00412             pow(ds, gsf.dimensions())
00413         )
00414     );
00415 
00416     pow(tPow(), ds, gsf);
00417 
00418     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::clear(tgsf);
00419 
00420     return tPow;
00421 }
00422 
00423 template<template<class> class PatchField, class GeoMesh>
00424 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00425 (
00426     const scalar& s,
00427     const GeometricField<scalar, PatchField, GeoMesh>& gsf
00428 )
00429 {
00430     return pow(dimensionedScalar(s), gsf);
00431 }
00432 
00433 template<template<class> class PatchField, class GeoMesh>
00434 tmp<GeometricField<scalar, PatchField, GeoMesh> > pow
00435 (
00436     const scalar& s,
00437     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf
00438 )
00439 {
00440     return pow(dimensionedScalar(s), tgsf);
00441 }
00442 
00443 
00444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00445 
00446 UNARY_FUNCTION(scalar, scalar, pow3, pow3)
00447 UNARY_FUNCTION(scalar, scalar, pow4, pow4)
00448 UNARY_FUNCTION(scalar, scalar, pow5, pow5)
00449 UNARY_FUNCTION(scalar, scalar, pow6, pow6)
00450 UNARY_FUNCTION(scalar, scalar, sqrt, sqrt)
00451 UNARY_FUNCTION(scalar, scalar, sign, sign)
00452 UNARY_FUNCTION(scalar, scalar, pos, pos)
00453 UNARY_FUNCTION(scalar, scalar, neg, neg)
00454 
00455 UNARY_FUNCTION(scalar, scalar, exp, trans)
00456 UNARY_FUNCTION(scalar, scalar, log, trans)
00457 UNARY_FUNCTION(scalar, scalar, log10, trans)
00458 UNARY_FUNCTION(scalar, scalar, sin, trans)
00459 UNARY_FUNCTION(scalar, scalar, cos, trans)
00460 UNARY_FUNCTION(scalar, scalar, tan, trans)
00461 UNARY_FUNCTION(scalar, scalar, asin, trans)
00462 UNARY_FUNCTION(scalar, scalar, acos, trans)
00463 UNARY_FUNCTION(scalar, scalar, atan, trans)
00464 UNARY_FUNCTION(scalar, scalar, sinh, trans)
00465 UNARY_FUNCTION(scalar, scalar, cosh, trans)
00466 UNARY_FUNCTION(scalar, scalar, tanh, trans)
00467 UNARY_FUNCTION(scalar, scalar, asinh, trans)
00468 UNARY_FUNCTION(scalar, scalar, acosh, trans)
00469 UNARY_FUNCTION(scalar, scalar, atanh, trans)
00470 UNARY_FUNCTION(scalar, scalar, erf, trans)
00471 UNARY_FUNCTION(scalar, scalar, erfc, trans)
00472 UNARY_FUNCTION(scalar, scalar, lgamma, trans)
00473 UNARY_FUNCTION(scalar, scalar, j0, trans)
00474 UNARY_FUNCTION(scalar, scalar, j1, trans)
00475 UNARY_FUNCTION(scalar, scalar, y0, trans)
00476 UNARY_FUNCTION(scalar, scalar, y1, trans)
00477 
00478 
00479 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00480 
00481 #define BesselFunc(func)                                                     \
00482                                                                             \
00483 template<template<class> class PatchField, class GeoMesh>                   \
00484 void func                                                                   \
00485 (                                                                           \
00486     GeometricField<scalar, PatchField, GeoMesh>& gsf,                       \
00487     const int n,                                                            \
00488     const GeometricField<scalar, PatchField, GeoMesh>& gsf1                 \
00489 )                                                                           \
00490 {                                                                           \
00491     func(gsf.internalField(), n, gsf1.internalField());                     \
00492     func(gsf.boundaryField(), n, gsf1.boundaryField());                     \
00493 }                                                                           \
00494                                                                             \
00495 template<template<class> class PatchField, class GeoMesh>                   \
00496 tmp<GeometricField<scalar, PatchField, GeoMesh> > func                      \
00497 (                                                                           \
00498     const int n,                                                            \
00499     const GeometricField<scalar, PatchField, GeoMesh>& gsf                  \
00500 )                                                                           \
00501 {                                                                           \
00502     if (!gsf.dimensions().dimensionless())                                  \
00503     {                                                                       \
00504         FatalErrorIn                                                        \
00505         (                                                                   \
00506             #func"(const int n, "                                           \
00507             "const GeometricField<scalar, PatchField, GeoMesh>& gsf)"       \
00508         )   << "gsf not dimensionless"                                      \
00509             << abort(FatalError);                                           \
00510     }                                                                       \
00511                                                                             \
00512     tmp<GeometricField<scalar, PatchField, GeoMesh> > tFunc                 \
00513     (                                                                       \
00514         new GeometricField<scalar, PatchField, GeoMesh>                     \
00515         (                                                                   \
00516             IOobject                                                        \
00517             (                                                               \
00518                 #func "(" + gsf.name() + ')',                               \
00519                 gsf.instance(),                                             \
00520                 gsf.db(),                                                   \
00521                 IOobject::NO_READ,                                          \
00522                 IOobject::NO_WRITE                                          \
00523             ),                                                              \
00524             gsf.mesh(),                                                     \
00525             dimless                                                         \
00526         )                                                                   \
00527     );                                                                      \
00528                                                                             \
00529     func(tFunc(), n, gsf);                                                  \
00530                                                                             \
00531     return tFunc;                                                           \
00532 }                                                                           \
00533                                                                             \
00534 template<template<class> class PatchField, class GeoMesh>                   \
00535 tmp<GeometricField<scalar, PatchField, GeoMesh> > func                      \
00536 (                                                                           \
00537     const int n,                                                            \
00538     const tmp<GeometricField<scalar, PatchField, GeoMesh> >& tgsf           \
00539 )                                                                           \
00540 {                                                                           \
00541     const GeometricField<scalar, PatchField, GeoMesh>& gsf = tgsf();        \
00542                                                                             \
00543     if (!gsf.dimensions().dimensionless())                                  \
00544     {                                                                       \
00545         FatalErrorIn                                                        \
00546         (                                                                   \
00547             #func"(const int n, "                                           \
00548             "const tmp<GeometricField<scalar, PatchField, GeoMesh> >& gsf)" \
00549         )   << " : gsf not dimensionless"                                   \
00550             << abort(FatalError);                                           \
00551     }                                                                       \
00552                                                                             \
00553     tmp<GeometricField<scalar, PatchField, GeoMesh> > tFunc                 \
00554     (                                                                       \
00555         reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>::New    \
00556         (                                                                   \
00557             tgsf,                                                           \
00558             #func "(" + gsf.name() + ')',                                   \
00559             dimless                                                         \
00560         )                                                                   \
00561     );                                                                      \
00562                                                                             \
00563     func(tFunc(), n, gsf);                                                  \
00564                                                                             \
00565     reuseTmpGeometricField<scalar, scalar, PatchField, GeoMesh>             \
00566     ::clear(tgsf);                                                          \
00567                                                                             \
00568     return tFunc;                                                           \
00569 }
00570 
00571 BesselFunc(jn)
00572 BesselFunc(yn)
00573 
00574 #undef BesselFunc
00575 
00576 
00577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00578 
00579 } // End namespace Foam
00580 
00581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00582 
00583 #include "undefFieldFunctionsM.H"
00584 
00585 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd