00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <OpenFOAM/DimensionedFieldReuseFunctions.H>
00027
00028 #define TEMPLATE template<class Type, class GeoMesh>
00029 #include <OpenFOAM/DimensionedFieldFunctionsM.C>
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038 template<class Type, class GeoMesh, int r>
00039 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh> >
00040 pow
00041 (
00042 const DimensionedField<Type, GeoMesh>& df,
00043 typename powProduct<Type, r>::type
00044 )
00045 {
00046 typedef typename powProduct<Type, r>::type powProductType;
00047
00048 tmp<DimensionedField<powProductType, GeoMesh> > tPow
00049 (
00050 new DimensionedField<powProductType, GeoMesh>
00051 (
00052 IOobject
00053 (
00054 "pow(" + df.name() + ',' + name(r) + ')',
00055 df.instance(),
00056 df.db()
00057 ),
00058 df.mesh(),
00059 pow(df.dimensions(), r)
00060 )
00061 );
00062
00063 pow<Type, r, GeoMesh>(tPow().field(), df.field());
00064
00065 return tPow;
00066 }
00067
00068
00069 template<class Type, class GeoMesh, int r>
00070 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh> >
00071 pow
00072 (
00073 const tmp<DimensionedField<Type, GeoMesh> >& tdf,
00074 typename powProduct<Type, r>::type
00075 )
00076 {
00077 typedef typename powProduct<Type, r>::type powProductType;
00078
00079 const DimensionedField<Type, GeoMesh>& df = tdf();
00080
00081 tmp<DimensionedField<powProductType, GeoMesh> > tPow =
00082 reuseTmpDimensionedField<powProductType, Type, GeoMesh>::New
00083 (
00084 tdf,
00085 "pow(" + df.name() + ',' + name(r) + ')',
00086 pow(df.dimensions(), r)
00087 );
00088
00089 pow<Type, r, GeoMesh>(tPow().field(), df.field());
00090
00091 reuseTmpDimensionedField<powProductType, Type, GeoMesh>::clear(tdf);
00092
00093 return tPow;
00094 }
00095
00096 template<class Type, class GeoMesh>
00097 tmp<DimensionedField<typename outerProduct<Type, Type>::type, GeoMesh> >
00098 sqr(const DimensionedField<Type, GeoMesh>& df)
00099 {
00100 typedef typename outerProduct<Type, Type>::type outerProductType;
00101
00102 tmp<DimensionedField<outerProductType, GeoMesh> > tSqr
00103 (
00104 new DimensionedField<outerProductType, GeoMesh>
00105 (
00106 IOobject
00107 (
00108 "sqr(" + df.name() + ')',
00109 df.instance(),
00110 df.db()
00111 ),
00112 df.mesh(),
00113 sqr(df.dimensions())
00114 )
00115 );
00116
00117 sqr(tSqr().field(), df.field());
00118
00119 return tSqr;
00120 }
00121
00122 template<class Type, class GeoMesh>
00123 tmp<DimensionedField<typename outerProduct<Type, Type>::type, GeoMesh> >
00124 sqr(const tmp<DimensionedField<Type, GeoMesh> >& tdf)
00125 {
00126 typedef typename outerProduct<Type, Type>::type outerProductType;
00127
00128 const DimensionedField<Type, GeoMesh>& df = tdf();
00129
00130 tmp<DimensionedField<outerProductType, GeoMesh> > tSqr =
00131 reuseTmpDimensionedField<outerProductType, Type, GeoMesh>::New
00132 (
00133 tdf,
00134 "sqr(" + df.name() + ')',
00135 sqr(df.dimensions())
00136 );
00137
00138 sqr(tSqr().field(), df.field());
00139
00140 reuseTmpDimensionedField<outerProductType, Type, GeoMesh>::clear(tdf);
00141
00142 return tSqr;
00143 }
00144
00145
00146 template<class Type, class GeoMesh>
00147 tmp<DimensionedField<scalar, GeoMesh> > magSqr
00148 (
00149 const DimensionedField<Type, GeoMesh>& df
00150 )
00151 {
00152 tmp<DimensionedField<scalar, GeoMesh> > tMagSqr
00153 (
00154 new DimensionedField<scalar, GeoMesh>
00155 (
00156 IOobject
00157 (
00158 "magSqr(" + df.name() + ')',
00159 df.instance(),
00160 df.db()
00161 ),
00162 df.mesh(),
00163 sqr(df.dimensions())
00164 )
00165 );
00166
00167 magSqr(tMagSqr().field(), df.field());
00168
00169 return tMagSqr;
00170 }
00171
00172 template<class Type, class GeoMesh>
00173 tmp<DimensionedField<scalar, GeoMesh> > magSqr
00174 (
00175 const tmp<DimensionedField<Type, GeoMesh> >& tdf
00176 )
00177 {
00178 const DimensionedField<Type, GeoMesh>& df = tdf();
00179
00180 tmp<DimensionedField<scalar, GeoMesh> > tMagSqr =
00181 reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
00182 (
00183 tdf,
00184 "magSqr(" + df.name() + ')',
00185 sqr(df.dimensions())
00186 );
00187
00188 magSqr(tMagSqr().field(), df.field());
00189
00190 reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
00191
00192 return tMagSqr;
00193 }
00194
00195
00196 template<class Type, class GeoMesh>
00197 tmp<DimensionedField<scalar, GeoMesh> > mag
00198 (
00199 const DimensionedField<Type, GeoMesh>& df
00200 )
00201 {
00202 tmp<DimensionedField<scalar, GeoMesh> > tMag
00203 (
00204 new DimensionedField<scalar, GeoMesh>
00205 (
00206 IOobject
00207 (
00208 "mag(" + df.name() + ')',
00209 df.instance(),
00210 df.db()
00211 ),
00212 df.mesh(),
00213 df.dimensions()
00214 )
00215 );
00216
00217 mag(tMag().field(), df.field());
00218
00219 return tMag;
00220 }
00221
00222 template<class Type, class GeoMesh>
00223 tmp<DimensionedField<scalar, GeoMesh> > mag
00224 (
00225 const tmp<DimensionedField<Type, GeoMesh> >& tdf
00226 )
00227 {
00228 const DimensionedField<Type, GeoMesh>& df = tdf();
00229
00230 tmp<DimensionedField<scalar, GeoMesh> > tMag =
00231 reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
00232 (
00233 tdf,
00234 "mag(" + df.name() + ')',
00235 df.dimensions()
00236 );
00237
00238 mag(tMag().field(), df.field());
00239
00240 reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
00241
00242 return tMag;
00243 }
00244
00245
00246 template<class Type, class GeoMesh>
00247 tmp
00248 <
00249 DimensionedField
00250 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
00251 >
00252 cmptAv(const DimensionedField<Type, GeoMesh>& df)
00253 {
00254 typedef typename DimensionedField<Type, GeoMesh>::cmptType cmptType;
00255
00256 tmp<DimensionedField<cmptType, GeoMesh> > CmptAv
00257 (
00258 new DimensionedField<scalar, GeoMesh>
00259 (
00260 IOobject
00261 (
00262 "cmptAv(" + df.name() + ')',
00263 df.instance(),
00264 df.db()
00265 ),
00266 df.mesh(),
00267 df.dimensions()
00268 )
00269 );
00270
00271 cmptAv(CmptAv().field(), df.field());
00272
00273 return CmptAv;
00274 }
00275
00276 template<class Type, class GeoMesh>
00277 tmp
00278 <
00279 DimensionedField
00280 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
00281 >
00282 cmptAv(const tmp<DimensionedField<Type, GeoMesh> >& tdf)
00283 {
00284 typedef typename DimensionedField<Type, GeoMesh>::cmptType
00285 cmptType;
00286
00287 const DimensionedField<Type, GeoMesh>& df = tdf();
00288
00289 tmp<DimensionedField<cmptType, GeoMesh> > CmptAv =
00290 reuseTmpDimensionedField<cmptType, Type, GeoMesh>::New
00291 (
00292 tdf,
00293 "cmptAv(" + df.name() + ')',
00294 df.dimensions()
00295 );
00296
00297 cmptAv(CmptAv().field(), df.field());
00298
00299 reuseTmpDimensionedField<cmptType, Type, GeoMesh>::clear(tdf);
00300
00301 return CmptAv;
00302 }
00303
00304 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
00305 \
00306 template<class Type, class GeoMesh> \
00307 dimensioned<returnType> func \
00308 ( \
00309 const DimensionedField<Type, GeoMesh>& df \
00310 ) \
00311 { \
00312 return dimensioned<Type> \
00313 ( \
00314 #func "(" + df.name() + ')', \
00315 df.dimensions(), \
00316 dfunc(df.field()) \
00317 ); \
00318 } \
00319 \
00320 template<class Type, class GeoMesh> \
00321 dimensioned<returnType> func \
00322 ( \
00323 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
00324 ) \
00325 { \
00326 dimensioned<returnType> res = func(tdf1()); \
00327 tdf1.clear(); \
00328 return res; \
00329 }
00330
00331 UNARY_REDUCTION_FUNCTION(Type, max, gMax)
00332 UNARY_REDUCTION_FUNCTION(Type, min, gMin)
00333 UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
00334 UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
00335 UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
00336
00337 #undef UNARY_REDUCTION_FUNCTION
00338
00339
00340 BINARY_FUNCTION(Type, Type, Type, max)
00341 BINARY_FUNCTION(Type, Type, Type, min)
00342 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
00343 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
00344
00345 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
00346 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
00347 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
00348 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
00349
00350
00351
00352
00353 UNARY_OPERATOR(Type, Type, -, negate, transform)
00354
00355 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
00356 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
00357 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
00358
00359 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
00360 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
00361
00362 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
00363
00364
00365
00366
00367 #define PRODUCT_OPERATOR(product, op, opFunc) \
00368 \
00369 template<class Type1, class Type2, class GeoMesh> \
00370 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
00371 operator op \
00372 ( \
00373 const DimensionedField<Type1, GeoMesh>& df1, \
00374 const DimensionedField<Type2, GeoMesh>& df2 \
00375 ) \
00376 { \
00377 typedef typename product<Type1, Type2>::type productType; \
00378 tmp<DimensionedField<productType, GeoMesh> > tRes \
00379 ( \
00380 new DimensionedField<productType, GeoMesh> \
00381 ( \
00382 IOobject \
00383 ( \
00384 '(' + df1.name() + #op + df2.name() + ')', \
00385 df1.instance(), \
00386 df1.db() \
00387 ), \
00388 df1.mesh(), \
00389 df1.dimensions() op df2.dimensions() \
00390 ) \
00391 ); \
00392 \
00393 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
00394 \
00395 return tRes; \
00396 } \
00397 \
00398 template<class Type1, class Type2, class GeoMesh> \
00399 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
00400 operator op \
00401 ( \
00402 const DimensionedField<Type1, GeoMesh>& df1, \
00403 const tmp<DimensionedField<Type2, GeoMesh> >& tdf2 \
00404 ) \
00405 { \
00406 typedef typename product<Type1, Type2>::type productType; \
00407 \
00408 const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
00409 \
00410 tmp<DimensionedField<productType, GeoMesh> > tRes = \
00411 reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
00412 ( \
00413 tdf2, \
00414 '(' + df1.name() + #op + df2.name() + ')', \
00415 df1.dimensions() op df2.dimensions() \
00416 ); \
00417 \
00418 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
00419 \
00420 reuseTmpDimensionedField<productType, Type2, GeoMesh>::clear(tdf2); \
00421 \
00422 return tRes; \
00423 } \
00424 \
00425 template<class Type1, class Type2, class GeoMesh> \
00426 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
00427 operator op \
00428 ( \
00429 const tmp<DimensionedField<Type1, GeoMesh> >& tdf1, \
00430 const DimensionedField<Type2, GeoMesh>& df2 \
00431 ) \
00432 { \
00433 typedef typename product<Type1, Type2>::type productType; \
00434 \
00435 const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
00436 \
00437 tmp<DimensionedField<productType, GeoMesh> > tRes = \
00438 reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
00439 ( \
00440 tdf1, \
00441 '(' + df1.name() + #op + df2.name() + ')', \
00442 df1.dimensions() op df2.dimensions() \
00443 ); \
00444 \
00445 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
00446 \
00447 reuseTmpDimensionedField<productType, Type1, GeoMesh>::clear(tdf1); \
00448 \
00449 return tRes; \
00450 } \
00451 \
00452 template<class Type1, class Type2, class GeoMesh> \
00453 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
00454 operator op \
00455 ( \
00456 const tmp<DimensionedField<Type1, GeoMesh> >& tdf1, \
00457 const tmp<DimensionedField<Type2, GeoMesh> >& tdf2 \
00458 ) \
00459 { \
00460 typedef typename product<Type1, Type2>::type productType; \
00461 \
00462 const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
00463 const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
00464 \
00465 tmp<DimensionedField<productType, GeoMesh> > tRes = \
00466 reuseTmpTmpDimensionedField \
00467 <productType, Type1, Type1, Type2, GeoMesh>::New \
00468 ( \
00469 tdf1, \
00470 tdf2, \
00471 '(' + df1.name() + #op + df2.name() + ')', \
00472 df1.dimensions() op df2.dimensions() \
00473 ); \
00474 \
00475 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
00476 \
00477 reuseTmpTmpDimensionedField \
00478 <productType, Type1, Type1, Type2, GeoMesh>::clear(tdf1, tdf2); \
00479 \
00480 return tRes; \
00481 } \
00482 \
00483 template<class Form, class Type, class GeoMesh> \
00484 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh> > \
00485 operator op \
00486 ( \
00487 const DimensionedField<Type, GeoMesh>& df1, \
00488 const dimensioned<Form>& dvs \
00489 ) \
00490 { \
00491 typedef typename product<Type, Form>::type productType; \
00492 \
00493 tmp<DimensionedField<productType, GeoMesh> > tRes \
00494 ( \
00495 new DimensionedField<productType, GeoMesh> \
00496 ( \
00497 IOobject \
00498 ( \
00499 '(' + df1.name() + #op + dvs.name() + ')', \
00500 df1.instance(), \
00501 df1.db() \
00502 ), \
00503 df1.mesh(), \
00504 df1.dimensions() op dvs.dimensions() \
00505 ) \
00506 ); \
00507 \
00508 Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
00509 \
00510 return tRes; \
00511 } \
00512 \
00513 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
00514 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00515 operator op \
00516 ( \
00517 const DimensionedField<Type, GeoMesh>& df1, \
00518 const VectorSpace<Form,Cmpt,nCmpt>& vs \
00519 ) \
00520 { \
00521 return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
00522 } \
00523 \
00524 \
00525 template<class Form, class Type, class GeoMesh> \
00526 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh> > \
00527 operator op \
00528 ( \
00529 const tmp<DimensionedField<Type, GeoMesh> >& tdf1, \
00530 const dimensioned<Form>& dvs \
00531 ) \
00532 { \
00533 typedef typename product<Type, Form>::type productType; \
00534 \
00535 const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
00536 \
00537 tmp<DimensionedField<productType, GeoMesh> > tRes = \
00538 reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
00539 ( \
00540 tdf1, \
00541 '(' + df1.name() + #op + dvs.name() + ')', \
00542 df1.dimensions() op dvs.dimensions() \
00543 ); \
00544 \
00545 Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
00546 \
00547 reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
00548 \
00549 return tRes; \
00550 } \
00551 \
00552 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
00553 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00554 operator op \
00555 ( \
00556 const tmp<DimensionedField<Type, GeoMesh> >& tdf1, \
00557 const VectorSpace<Form,Cmpt,nCmpt>& vs \
00558 ) \
00559 { \
00560 return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
00561 } \
00562 \
00563 \
00564 template<class Form, class Type, class GeoMesh> \
00565 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00566 operator op \
00567 ( \
00568 const dimensioned<Form>& dvs, \
00569 const DimensionedField<Type, GeoMesh>& df1 \
00570 ) \
00571 { \
00572 typedef typename product<Form, Type>::type productType; \
00573 tmp<DimensionedField<productType, GeoMesh> > tRes \
00574 ( \
00575 new DimensionedField<productType, GeoMesh> \
00576 ( \
00577 IOobject \
00578 ( \
00579 '(' + dvs.name() + #op + df1.name() + ')', \
00580 df1.instance(), \
00581 df1.db() \
00582 ), \
00583 df1.mesh(), \
00584 dvs.dimensions() op df1.dimensions() \
00585 ) \
00586 ); \
00587 \
00588 Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
00589 \
00590 return tRes; \
00591 } \
00592 \
00593 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
00594 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00595 operator op \
00596 ( \
00597 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
00598 const DimensionedField<Type, GeoMesh>& df1 \
00599 ) \
00600 { \
00601 return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
00602 } \
00603 \
00604 template<class Form, class Type, class GeoMesh> \
00605 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00606 operator op \
00607 ( \
00608 const dimensioned<Form>& dvs, \
00609 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
00610 ) \
00611 { \
00612 typedef typename product<Form, Type>::type productType; \
00613 \
00614 const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
00615 \
00616 tmp<DimensionedField<productType, GeoMesh> > tRes = \
00617 reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
00618 ( \
00619 tdf1, \
00620 '(' + dvs.name() + #op + df1.name() + ')', \
00621 dvs.dimensions() op df1.dimensions() \
00622 ); \
00623 \
00624 Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
00625 \
00626 reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
00627 \
00628 return tRes; \
00629 } \
00630 \
00631 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
00632 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
00633 operator op \
00634 ( \
00635 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
00636 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
00637 ) \
00638 { \
00639 return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
00640 }
00641
00642 PRODUCT_OPERATOR(typeOfSum, +, add)
00643 PRODUCT_OPERATOR(typeOfSum, -, subtract)
00644
00645 PRODUCT_OPERATOR(outerProduct, *, outer)
00646 PRODUCT_OPERATOR(crossProduct, ^, cross)
00647 PRODUCT_OPERATOR(innerProduct, &, dot)
00648 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
00649
00650 #undef PRODUCT_OPERATOR
00651
00652
00653
00654
00655 }
00656
00657
00658
00659 #include <OpenFOAM/undefFieldFunctionsM.H>
00660
00661