FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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