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

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