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

FieldFunctions.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 "PstreamReduceOps.H"
00028 #include "FieldReuseFunctions.H"
00029 
00030 #define TEMPLATE template<class Type>
00031 #include "FieldFunctionsM.C"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 /* * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * */
00039 
00040 template<class Type>
00041 void component
00042 (
00043     Field<typename Field<Type>::cmptType>& res,
00044     const UList<Type>& f,
00045     const direction d
00046 )
00047 {
00048     typedef typename Field<Type>::cmptType cmptType;
00049     TFOR_ALL_F_OP_F_FUNC_S
00050     (
00051         cmptType, res, =, Type, f, .component, const direction, d
00052     )
00053 }
00054 
00055 
00056 template<class Type>
00057 void T(Field<Type>& res, const UList<Type>& f)
00058 {
00059     TFOR_ALL_F_OP_F_FUNC(Type, res, =, Type, f, T)
00060 }
00061 
00062 
00063 template<class Type, int r>
00064 void pow
00065 (
00066     Field<typename powProduct<Type, r>::type>& res,
00067     const UList<Type>& vf
00068 )
00069 {
00070     typedef typename powProduct<Type, r>::type powProductType;
00071     TFOR_ALL_F_OP_FUNC_F_S
00072     (
00073         powProductType, res, =, pow, Type, vf, powProductType,
00074         pTraits<powProductType>::zero
00075     )
00076 }
00077 
00078 template<class Type, int r>
00079 tmp<Field<typename powProduct<Type, r>::type> >
00080 pow
00081 (
00082     const UList<Type>& f,
00083     typename powProduct<Type, r>::type
00084 )
00085 {
00086     typedef typename powProduct<Type, r>::type powProductType;
00087     tmp<Field<powProductType> > tRes
00088     (
00089         new Field<powProductType>(f.size())
00090     );
00091     pow<Type, r>(tRes(), f);
00092     return tRes;
00093 }
00094 
00095 template<class Type, int r>
00096 tmp<Field<typename powProduct<Type, r>::type> >
00097 pow
00098 (
00099     const tmp<Field<Type> >& tf,
00100     typename powProduct<Type, r>::type
00101 )
00102 {
00103     typedef typename powProduct<Type, r>::type powProductType;
00104     tmp<Field<powProductType> > tRes = reuseTmp<powProductType, Type>::New(tf);
00105     pow<Type, r>(tRes(), tf());
00106     reuseTmp<powProductType, Type>::clear(tf);
00107     return tRes;
00108 }
00109 
00110 
00111 template<class Type>
00112 void sqr
00113 (
00114     Field<typename outerProduct<Type, Type>::type>& res,
00115     const UList<Type>& vf
00116 )
00117 {
00118     typedef typename outerProduct<Type, Type>::type outerProductType;
00119     TFOR_ALL_F_OP_FUNC_F(outerProductType, res, =, sqr, Type, vf)
00120 }
00121 
00122 template<class Type>
00123 tmp<Field<typename outerProduct<Type, Type>::type> >
00124 sqr(const UList<Type>& f)
00125 {
00126     typedef typename outerProduct<Type, Type>::type outerProductType;
00127     tmp<Field<outerProductType> > tRes
00128     (
00129         new Field<outerProductType>(f.size())
00130     );
00131     sqr(tRes(), f);
00132     return tRes;
00133 }
00134 
00135 template<class Type>
00136 tmp<Field<typename outerProduct<Type, Type>::type> >
00137 sqr(const tmp<Field<Type> >& tf)
00138 {
00139     typedef typename outerProduct<Type, Type>::type outerProductType;
00140     tmp<Field<outerProductType> > tRes =
00141         reuseTmp<outerProductType, Type>::New(tf);
00142     sqr(tRes(), tf());
00143     reuseTmp<outerProductType, Type>::clear(tf);
00144     return tRes;
00145 }
00146 
00147 
00148 template<class Type>
00149 void magSqr(Field<scalar>& res, const UList<Type>& f)
00150 {
00151     TFOR_ALL_F_OP_FUNC_F(scalar, res, =, magSqr, Type, f)
00152 }
00153 
00154 template<class Type>
00155 tmp<Field<scalar> > magSqr(const UList<Type>& f)
00156 {
00157     tmp<Field<scalar> > tRes(new Field<scalar>(f.size()));
00158     magSqr(tRes(), f);
00159     return tRes;
00160 }
00161 
00162 template<class Type>
00163 tmp<Field<scalar> > magSqr(const tmp<Field<Type> >& tf)
00164 {
00165     tmp<Field<scalar> > tRes = reuseTmp<scalar, Type>::New(tf);
00166     magSqr(tRes(), tf());
00167     reuseTmp<scalar, Type>::clear(tf);
00168     return tRes;
00169 }
00170 
00171 
00172 template<class Type>
00173 void mag(Field<scalar>& res, const UList<Type>& f)
00174 {
00175     TFOR_ALL_F_OP_FUNC_F(scalar, res, =, mag, Type, f)
00176 }
00177 
00178 template<class Type>
00179 tmp<Field<scalar> > mag(const UList<Type>& f)
00180 {
00181     tmp<Field<scalar> > tRes(new Field<scalar>(f.size()));
00182     mag(tRes(), f);
00183     return tRes;
00184 }
00185 
00186 template<class Type>
00187 tmp<Field<scalar> > mag(const tmp<Field<Type> >& tf)
00188 {
00189     tmp<Field<scalar> > tRes = reuseTmp<scalar, Type>::New(tf);
00190     mag(tRes(), tf());
00191     reuseTmp<scalar, Type>::clear(tf);
00192     return tRes;
00193 }
00194 
00195 
00196 template<class Type>
00197 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f)
00198 {
00199     typedef typename Field<Type>::cmptType cmptType;
00200     TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMax, Type, f)
00201 }
00202 
00203 template<class Type>
00204 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const UList<Type>& f)
00205 {
00206     typedef typename Field<Type>::cmptType cmptType;
00207     tmp<Field<cmptType> > tRes(new Field<cmptType>(f.size()));
00208     cmptMax(tRes(), f);
00209     return tRes;
00210 }
00211 
00212 template<class Type>
00213 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const tmp<Field<Type> >& tf)
00214 {
00215     typedef typename Field<Type>::cmptType cmptType;
00216     tmp<Field<cmptType> > tRes = reuseTmp<cmptType, Type>::New(tf);
00217     cmptMax(tRes(), tf());
00218     reuseTmp<cmptType, Type>::clear(tf);
00219     return tRes;
00220 }
00221 
00222 
00223 template<class Type>
00224 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f)
00225 {
00226     typedef typename Field<Type>::cmptType cmptType;
00227     TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMin, Type, f)
00228 }
00229 
00230 template<class Type>
00231 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const UList<Type>& f)
00232 {
00233     typedef typename Field<Type>::cmptType cmptType;
00234     tmp<Field<cmptType> > tRes(new Field<cmptType>(f.size()));
00235     cmptMin(tRes(), f);
00236     return tRes;
00237 }
00238 
00239 template<class Type>
00240 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const tmp<Field<Type> >& tf)
00241 {
00242     typedef typename Field<Type>::cmptType cmptType;
00243     tmp<Field<cmptType> > tRes = reuseTmp<cmptType, Type>::New(tf);
00244     cmptMin(tRes(), tf());
00245     reuseTmp<cmptType, Type>::clear(tf);
00246     return tRes;
00247 }
00248 
00249 
00250 template<class Type>
00251 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f)
00252 {
00253     typedef typename Field<Type>::cmptType cmptType;
00254     TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptAv, Type, f)
00255 }
00256 
00257 template<class Type>
00258 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const UList<Type>& f)
00259 {
00260     typedef typename Field<Type>::cmptType cmptType;
00261     tmp<Field<cmptType> > tRes(new Field<cmptType>(f.size()));
00262     cmptAv(tRes(), f);
00263     return tRes;
00264 }
00265 
00266 template<class Type>
00267 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const tmp<Field<Type> >& tf)
00268 {
00269     typedef typename Field<Type>::cmptType cmptType;
00270     tmp<Field<cmptType> > tRes = reuseTmp<cmptType, Type>::New(tf);
00271     cmptAv(tRes(), tf());
00272     reuseTmp<cmptType, Type>::clear(tf);
00273     return tRes;
00274 }
00275 
00276 
00277 template<class Type>
00278 void cmptMag(Field<Type>& res, const UList<Type>& f)
00279 {
00280     TFOR_ALL_F_OP_FUNC_F(Type, res, =, cmptMag, Type, f)
00281 }
00282 
00283 template<class Type>
00284 tmp<Field<Type> > cmptMag(const UList<Type>& f)
00285 {
00286     tmp<Field<Type> > tRes(new Field<Type>(f.size()));
00287     cmptMag(tRes(), f);
00288     return tRes;
00289 }
00290 
00291 template<class Type>
00292 tmp<Field<Type> > cmptMag(const tmp<Field<Type> >& tf)
00293 {
00294     tmp<Field<Type> > tRes = reuseTmp<Type, Type>::New(tf);
00295     cmptMag(tRes(), tf());
00296     reuseTmp<Type, Type>::clear(tf);
00297     return tRes;
00298 }
00299 
00300 
00301 #define TMP_UNARY_FUNCTION(ReturnType, Func)                                  \
00302                                                                               \
00303 template<class Type>                                                          \
00304 ReturnType Func(const tmp<Field<Type> >& tf1)                                 \
00305 {                                                                             \
00306     ReturnType res = Func(tf1());                                             \
00307     tf1.clear();                                                              \
00308     return res;                                                               \
00309 }
00310 
00311 template<class Type>
00312 Type max(const UList<Type>& f)
00313 {
00314     if (f.size())
00315     {
00316         Type Max(f[0]);
00317         TFOR_ALL_S_OP_FUNC_F_S(Type, Max, =, max, Type, f, Type, Max)
00318         return Max;
00319     }
00320     else
00321     {
00322         return pTraits<Type>::min;
00323     }
00324 }
00325 
00326 TMP_UNARY_FUNCTION(Type, max)
00327 
00328 template<class Type>
00329 Type min(const UList<Type>& f)
00330 {
00331     if (f.size())
00332     {
00333         Type Min(f[0]);
00334         TFOR_ALL_S_OP_FUNC_F_S(Type, Min, =, min, Type, f, Type, Min)
00335         return Min;
00336     }
00337     else
00338     {
00339         return pTraits<Type>::max;
00340     }
00341 }
00342 
00343 TMP_UNARY_FUNCTION(Type, min)
00344 
00345 template<class Type>
00346 Type sum(const UList<Type>& f)
00347 {
00348     if (f.size())
00349     {
00350         Type Sum = pTraits<Type>::zero;
00351         TFOR_ALL_S_OP_F(Type, Sum, +=, Type, f)
00352         return Sum;
00353     }
00354     else
00355     {
00356         return pTraits<Type>::zero;
00357     }
00358 }
00359 
00360 TMP_UNARY_FUNCTION(Type, sum)
00361 
00362 
00363 template<class Type>
00364 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2)
00365 {
00366     if (f1.size() && (f1.size() == f2.size()))
00367     {
00368         scalar SumProd = 0.0;
00369         TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, *, Type, f2)
00370         return SumProd;
00371     }
00372     else
00373     {
00374         return 0.0;
00375     }
00376 }
00377 
00378 
00379 template<class Type>
00380 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
00381 {
00382     if (f1.size() && (f1.size() == f2.size()))
00383     {
00384         Type SumProd = pTraits<Type>::zero;
00385         TFOR_ALL_S_OP_FUNC_F_F(Type, SumProd, +=, cmptMultiply, Type, f1, Type, f2)
00386         return SumProd;
00387     }
00388     else
00389     {
00390         return pTraits<Type>::zero;
00391     }
00392 }
00393 
00394 
00395 template<class Type>
00396 scalar sumSqr(const UList<Type>& f)
00397 {
00398     if (f.size())
00399     {
00400         scalar SumSqr = 0.0;
00401         TFOR_ALL_S_OP_FUNC_F(scalar, SumSqr, +=, sqr, Type, f)
00402         return SumSqr;
00403     }
00404     else
00405     {
00406         return 0.0;
00407     }
00408 }
00409 
00410 TMP_UNARY_FUNCTION(scalar, sumSqr)
00411 
00412 template<class Type>
00413 scalar sumMag(const UList<Type>& f)
00414 {
00415     if (f.size())
00416     {
00417         scalar SumMag = 0.0;
00418         TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, mag, Type, f)
00419         return SumMag;
00420     }
00421     else
00422     {
00423         return 0.0;
00424     }
00425 }
00426 
00427 TMP_UNARY_FUNCTION(scalar, sumMag)
00428 
00429 
00430 template<class Type>
00431 Type sumCmptMag(const UList<Type>& f)
00432 {
00433     if (f.size())
00434     {
00435         Type SumMag = pTraits<Type>::zero;
00436         TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, cmptMag, Type, f)
00437         return SumMag;
00438     }
00439     else
00440     {
00441         return pTraits<Type>::zero;
00442     }
00443 }
00444 
00445 TMP_UNARY_FUNCTION(Type, sumCmptMag)
00446 
00447 template<class Type>
00448 Type average(const UList<Type>& f)
00449 {
00450     if (f.size())
00451     {
00452         Type avrg = sum(f)/f.size();
00453 
00454         return avrg;
00455     }
00456     else
00457     {
00458         WarningIn("average(const UList<Type>&)")
00459             << "empty field, returning zero" << endl;
00460 
00461         return pTraits<Type>::zero;
00462     }
00463 }
00464 
00465 TMP_UNARY_FUNCTION(Type, average)
00466 
00467 
00468 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)                      \
00469                                                                               \
00470 template<class Type>                                                          \
00471 ReturnType gFunc(const UList<Type>& f)                                        \
00472 {                                                                             \
00473     ReturnType res = Func(f);                                                 \
00474     reduce(res, rFunc##Op<Type>());                                           \
00475     return res;                                                               \
00476 }                                                                             \
00477 TMP_UNARY_FUNCTION(ReturnType, gFunc)
00478 
00479 G_UNARY_FUNCTION(Type, gMax, max, max)
00480 G_UNARY_FUNCTION(Type, gMin, min, min)
00481 G_UNARY_FUNCTION(Type, gSum, sum, sum)
00482 G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
00483 G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
00484 G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum)
00485 
00486 #undef G_UNARY_FUNCTION
00487 
00488 template<class Type>
00489 scalar gSumProd(const UList<Type>& f1, const UList<Type>& f2)
00490 {
00491     scalar SumProd = sumProd(f1, f2);
00492     reduce(SumProd, sumOp<Type>());
00493     return SumProd;
00494 }
00495 
00496 template<class Type>
00497 Type gSumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
00498 {
00499     Type SumProd = sumCmptProd(f1, f2);
00500     reduce(SumProd, sumOp<Type>());
00501     return SumProd;
00502 }
00503 
00504 template<class Type>
00505 Type gAverage(const UList<Type>& f)
00506 {
00507     label n = f.size();
00508     reduce(n, sumOp<label>());
00509 
00510     if (n > 0)
00511     {
00512         Type avrg = gSum(f)/n;
00513 
00514         return avrg;
00515     }
00516     else
00517     {
00518         WarningIn("gAverage(const UList<Type>&)")
00519             << "empty field, returning zero." << endl;
00520 
00521         return pTraits<Type>::zero;
00522     }
00523 }
00524 
00525 TMP_UNARY_FUNCTION(Type, gAverage)
00526 
00527 #undef TMP_UNARY_FUNCTION
00528 
00529 
00530 BINARY_FUNCTION(Type, Type, Type, max)
00531 BINARY_FUNCTION(Type, Type, Type, min)
00532 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
00533 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
00534 
00535 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
00536 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
00537 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
00538 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
00539 
00540 
00541 /* * * * * * * * * * * * * * * * Global operators  * * * * * * * * * * * * * */
00542 
00543 UNARY_OPERATOR(Type, Type, -, negate)
00544 
00545 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
00546 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
00547 BINARY_OPERATOR(Type, Type, scalar, /, divide)
00548 
00549 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
00550 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
00551 
00552 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
00553 
00554 
00555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00556 
00557 #define PRODUCT_OPERATOR(product, Op, OpFunc)                                 \
00558                                                                               \
00559 template<class Type1, class Type2>                                            \
00560 void OpFunc                                                                   \
00561 (                                                                             \
00562     Field<typename product<Type1, Type2>::type>& res,                         \
00563     const UList<Type1>& f1,                                                   \
00564     const UList<Type2>& f2                                                    \
00565 )                                                                             \
00566 {                                                                             \
00567     typedef typename product<Type1, Type2>::type productType;                 \
00568     TFOR_ALL_F_OP_F_OP_F(productType, res, =, Type1, f1, Op, Type2, f2)       \
00569 }                                                                             \
00570                                                                               \
00571 template<class Type1, class Type2>                                            \
00572 tmp<Field<typename product<Type1, Type2>::type> >                             \
00573 operator Op(const UList<Type1>& f1, const UList<Type2>& f2)                   \
00574 {                                                                             \
00575     typedef typename product<Type1, Type2>::type productType;                 \
00576     tmp<Field<productType> > tRes(new Field<productType>(f1.size()));         \
00577     OpFunc(tRes(), f1, f2);                                                   \
00578     return tRes;                                                              \
00579 }                                                                             \
00580                                                                               \
00581 template<class Type1, class Type2>                                            \
00582 tmp<Field<typename product<Type1, Type2>::type> >                             \
00583 operator Op(const UList<Type1>& f1, const tmp<Field<Type2> >& tf2)            \
00584 {                                                                             \
00585     typedef typename product<Type1, Type2>::type productType;                 \
00586     tmp<Field<productType> > tRes = reuseTmp<productType, Type2>::New(tf2);   \
00587     OpFunc(tRes(), f1, tf2());                                                \
00588     reuseTmp<productType, Type2>::clear(tf2);                                 \
00589     return tRes;                                                              \
00590 }                                                                             \
00591                                                                               \
00592 template<class Type1, class Type2>                                            \
00593 tmp<Field<typename product<Type1, Type2>::type> >                             \
00594 operator Op(const tmp<Field<Type1> >& tf1, const UList<Type2>& f2)            \
00595 {                                                                             \
00596     typedef typename product<Type1, Type2>::type productType;                 \
00597     tmp<Field<productType> > tRes = reuseTmp<productType, Type1>::New(tf1);   \
00598     OpFunc(tRes(), tf1(), f2);                                                \
00599     reuseTmp<productType, Type1>::clear(tf1);                                 \
00600     return tRes;                                                              \
00601 }                                                                             \
00602                                                                               \
00603 template<class Type1, class Type2>                                            \
00604 tmp<Field<typename product<Type1, Type2>::type> >                             \
00605 operator Op(const tmp<Field<Type1> >& tf1, const tmp<Field<Type2> >& tf2)     \
00606 {                                                                             \
00607     typedef typename product<Type1, Type2>::type productType;                 \
00608     tmp<Field<productType> > tRes =                                           \
00609         reuseTmpTmp<productType, Type1, Type1, Type2>::New(tf1, tf2);         \
00610     OpFunc(tRes(), tf1(), tf2());                                             \
00611     reuseTmpTmp<productType, Type1, Type1, Type2>::clear(tf1, tf2);           \
00612     return tRes;                                                              \
00613 }                                                                             \
00614                                                                               \
00615 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00616 void OpFunc                                                                   \
00617 (                                                                             \
00618     Field<typename product<Type, Form>::type>& res,                           \
00619     const UList<Type>& f1,                                                    \
00620     const VectorSpace<Form,Cmpt,nCmpt>& vs                                    \
00621 )                                                                             \
00622 {                                                                             \
00623     typedef typename product<Type, Form>::type productType;                   \
00624     TFOR_ALL_F_OP_F_OP_S                                                      \
00625         (productType, res, =,Type, f1, Op, Form, static_cast<const Form&>(vs))\
00626 }                                                                             \
00627                                                                               \
00628 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00629 tmp<Field<typename product<Type, Form>::type> >                               \
00630 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs)    \
00631 {                                                                             \
00632     typedef typename product<Type, Form>::type productType;                   \
00633     tmp<Field<productType> > tRes(new Field<productType>(f1.size()));         \
00634     OpFunc(tRes(), f1, static_cast<const Form&>(vs));                         \
00635     return tRes;                                                              \
00636 }                                                                             \
00637                                                                               \
00638 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00639 tmp<Field<typename product<Type, Form>::type> >                               \
00640 operator Op                                                                   \
00641 (                                                                             \
00642     const tmp<Field<Type> >& tf1,                                             \
00643     const VectorSpace<Form,Cmpt,nCmpt>& vs                                    \
00644 )                                                                             \
00645 {                                                                             \
00646     typedef typename product<Type, Form>::type productType;                   \
00647     tmp<Field<productType> > tRes = reuseTmp<productType, Type>::New(tf1);    \
00648     OpFunc(tRes(), tf1(), static_cast<const Form&>(vs));                      \
00649     reuseTmp<productType, Type>::clear(tf1);                                  \
00650     return tRes;                                                              \
00651 }                                                                             \
00652                                                                               \
00653 template<class Form, class Cmpt, int nCmpt, class Type>                       \
00654 void OpFunc                                                                   \
00655 (                                                                             \
00656     Field<typename product<Form, Type>::type>& res,                           \
00657     const VectorSpace<Form,Cmpt,nCmpt>& vs,                                   \
00658     const UList<Type>& f1                                                     \
00659 )                                                                             \
00660 {                                                                             \
00661     typedef typename product<Form, Type>::type productType;                   \
00662     TFOR_ALL_F_OP_S_OP_F                                                      \
00663         (productType, res, =,Form,static_cast<const Form&>(vs), Op, Type, f1) \
00664 }                                                                             \
00665                                                                               \
00666 template<class Form, class Cmpt, int nCmpt, class Type>                       \
00667 tmp<Field<typename product<Form, Type>::type> >                               \
00668 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1)    \
00669 {                                                                             \
00670     typedef typename product<Form, Type>::type productType;                   \
00671     tmp<Field<productType> > tRes(new Field<productType>(f1.size()));         \
00672     OpFunc(tRes(), static_cast<const Form&>(vs), f1);                         \
00673     return tRes;                                                              \
00674 }                                                                             \
00675                                                                               \
00676 template<class Form, class Cmpt, int nCmpt, class Type>                       \
00677 tmp<Field<typename product<Form, Type>::type> >                               \
00678 operator Op                                                                   \
00679 (                                                                             \
00680     const VectorSpace<Form,Cmpt,nCmpt>& vs, const tmp<Field<Type> >& tf1      \
00681 )                                                                             \
00682 {                                                                             \
00683     typedef typename product<Form, Type>::type productType;                   \
00684     tmp<Field<productType> > tRes = reuseTmp<productType, Type>::New(tf1);    \
00685     OpFunc(tRes(), static_cast<const Form&>(vs), tf1());                      \
00686     reuseTmp<productType, Type>::clear(tf1);                                  \
00687     return tRes;                                                              \
00688 }
00689 
00690 PRODUCT_OPERATOR(typeOfSum, +, add)
00691 PRODUCT_OPERATOR(typeOfSum, -, subtract)
00692 
00693 PRODUCT_OPERATOR(outerProduct, *, outer)
00694 PRODUCT_OPERATOR(crossProduct, ^, cross)
00695 PRODUCT_OPERATOR(innerProduct, &, dot)
00696 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
00697 
00698 #undef PRODUCT_OPERATOR
00699 
00700 
00701 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00702 
00703 } // End namespace Foam
00704 
00705 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00706 
00707 #include "undefFieldFunctionsM.H"
00708 
00709 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd