diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C index c5fffefcb8..c282ecb900 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C @@ -88,7 +88,7 @@ pow pow(tPow().field(), df.field()); - reuseTmpDimensionedField::clear(tdf); + tdf.clear(); return tPow; } @@ -137,7 +137,7 @@ sqr(const tmp>& tdf) sqr(tSqr().field(), df.field()); - reuseTmpDimensionedField::clear(tdf); + tdf.clear(); return tSqr; } @@ -187,7 +187,7 @@ tmp> magSqr magSqr(tMagSqr().field(), df.field()); - reuseTmpDimensionedField::clear(tdf); + tdf.clear(); return tMagSqr; } @@ -237,7 +237,7 @@ tmp> mag mag(tMag().field(), df.field()); - reuseTmpDimensionedField::clear(tdf); + tdf.clear(); return tMag; } @@ -296,7 +296,7 @@ cmptAv(const tmp>& tdf) cmptAv(CmptAv().field(), df.field()); - reuseTmpDimensionedField::clear(tdf); + tdf.clear(); return CmptAv; } @@ -417,7 +417,7 @@ operator op \ \ Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf2); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -444,7 +444,7 @@ operator op \ \ Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ @@ -474,8 +474,8 @@ operator op \ \ Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpTmpDimensionedField \ - ::clear(tdf1, tdf2); \ + tdf1.clear(); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -544,7 +544,7 @@ operator op \ \ Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ @@ -623,7 +623,7 @@ operator op \ \ Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C index 743ea0de38..6da09d945c 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.C @@ -75,7 +75,7 @@ tmp> Func \ \ Func(tRes.ref().field(), df1.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } @@ -131,7 +131,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), df1.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } @@ -189,7 +189,7 @@ tmp> Func \ \ Func(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf2); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -215,7 +215,7 @@ tmp> Func \ \ Func(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ @@ -244,8 +244,8 @@ tmp> Func \ \ Func(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpTmpDimensionedField \ - ::clear(tdf1, tdf2); \ + tdf1.clear(); \ + tdf2.clear(); \ \ return tRes; \ } @@ -314,7 +314,7 @@ tmp> Func \ \ Func(tRes.ref().field(), dt1.value(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf2); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -391,7 +391,7 @@ tmp> Func \ \ Func(tRes.ref().field(), df1.field(), dt2.value()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ @@ -464,7 +464,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf2); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -490,7 +490,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ @@ -519,8 +519,8 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \ \ - reuseTmpTmpDimensionedField:: \ - clear(tdf1, tdf2); \ + tdf1.clear(); \ + tdf2.clear(); \ \ return tRes; \ } @@ -589,7 +589,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), dt1.value(), tdf2().field()); \ \ - reuseTmpDimensionedField::clear(tdf2); \ + tdf2.clear(); \ \ return tRes; \ } \ @@ -666,7 +666,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref().field(), tdf1().field(), dt2.value()); \ \ - reuseTmpDimensionedField::clear(tdf1); \ + tdf1.clear(); \ \ return tRes; \ } \ diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H index b56adf3805..513efc44e5 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldReuseFunctions.H @@ -33,6 +33,43 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template +tmp> New +( + const tmp>& tdf1, + const word& name, + const dimensionSet& dimensions +) +{ + DimensionedField& df1 = + const_cast& >(tdf1()); + + if (tdf1.isTmp()) + { + df1.rename(name); + df1.dimensions().reset(dimensions); + return tdf1; + } + else + { + return tmp> + ( + new DimensionedField + ( + IOobject + ( + name, + df1.instance(), + df1.db() + ), + df1.mesh(), + dimensions + ) + ); + } +} + + template class reuseTmpDimensionedField { @@ -62,11 +99,6 @@ public: ) ); } - - static void clear(const tmp>& tdf1) - { - tdf1.clear(); - } }; @@ -109,11 +141,6 @@ public: ); } } - - static void clear(const tmp>& tdf1) - { - tdf1.clear(); - } }; @@ -147,16 +174,6 @@ public: ) ); } - - static void clear - ( - const tmp>& tdf1, - const tmp>& tdf2 - ) - { - tdf1.clear(); - tdf2.clear(); - } }; @@ -201,16 +218,6 @@ public: ); } } - - static void clear - ( - const tmp>& tdf1, - const tmp>& tdf2 - ) - { - tdf1.clear(); - tdf2.clear(); - } }; @@ -254,16 +261,6 @@ public: ); } } - - static void clear - ( - const tmp>& tdf1, - const tmp>& tdf2 - ) - { - tdf1.clear(); - tdf2.clear(); - } }; @@ -315,16 +312,6 @@ public: ); } } - - static void clear - ( - const tmp>& tdf1, - const tmp>& tdf2 - ) - { - tdf1.clear(); - tdf2.clear(); - } }; diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C index f8e3c8047e..9eb3fcf53f 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedScalarField/DimensionedScalarField.C @@ -72,17 +72,16 @@ tmp> stabilise { const DimensionedField& dsf = tdsf(); - tmp> tRes = - reuseTmpDimensionedField::New - ( - tdsf, - "stabilise(" + dsf.name() + ',' + ds.name() + ')', - dsf.dimensions() + ds.dimensions() - ); + tmp> tRes = New + ( + tdsf, + "stabilise(" + dsf.name() + ',' + ds.name() + ')', + dsf.dimensions() + ds.dimensions() + ); stabilise(tRes.ref().field(), dsf.field(), ds.value()); - reuseTmpDimensionedField::clear(tdsf); + tdsf.clear(); return tRes; } @@ -141,21 +140,20 @@ tmp> pow { const DimensionedField& dsf1 = tdsf1(); - tmp> tPow = - reuseTmpDimensionedField::New + tmp> tPow = New + ( + tdsf1, + "pow(" + dsf1.name() + ',' + dsf2.name() + ')', + pow ( - tdsf1, - "pow(" + dsf1.name() + ',' + dsf2.name() + ')', - pow - ( - dsf1.dimensions(), - dimensionedScalar("1", 1.0, dsf2.dimensions()) - ) - ); + dsf1.dimensions(), + dimensionedScalar("1", 1.0, dsf2.dimensions()) + ) + ); pow(tPow.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpDimensionedField::clear(tdsf1); + tdsf1.clear(); return tPow; } @@ -170,21 +168,20 @@ tmp> pow { const DimensionedField& dsf2 = tdsf2(); - tmp> tPow = - reuseTmpDimensionedField::New + tmp> tPow = New + ( + tdsf2, + "pow(" + dsf1.name() + ',' + dsf2.name() + ')', + pow ( - tdsf2, - "pow(" + dsf1.name() + ',' + dsf2.name() + ')', - pow - ( - dsf1.dimensions(), - dimensionedScalar("1", 1.0, dsf2.dimensions()) - ) - ); + dsf1.dimensions(), + dimensionedScalar("1", 1.0, dsf2.dimensions()) + ) + ); pow(tPow.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpDimensionedField::clear(tdsf2); + tdsf2.clear(); return tPow; } @@ -215,11 +212,8 @@ tmp> pow pow(tPow.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpTmpDimensionedField::clear - ( - tdsf1, - tdsf2 - ); + tdsf1.clear(); + tdsf2.clear(); return tPow; } @@ -261,17 +255,16 @@ tmp> pow { const DimensionedField& dsf = tdsf(); - tmp> tPow = - reuseTmpDimensionedField::New - ( - tdsf, - "pow(" + dsf.name() + ',' + ds.name() + ')', - pow(dsf.dimensions(), ds) - ); + tmp> tPow = New + ( + tdsf, + "pow(" + dsf.name() + ',' + ds.name() + ')', + pow(dsf.dimensions(), ds) + ); pow(tPow.ref().field(), dsf.field(), ds.value()); - reuseTmpDimensionedField::clear(tdsf); + tdsf.clear(); return tPow; } @@ -334,17 +327,16 @@ tmp> pow { const DimensionedField& dsf = tdsf(); - tmp> tPow = - reuseTmpDimensionedField::New - ( - tdsf, - "pow(" + ds.name() + ',' + dsf.name() + ')', - pow(ds, dsf.dimensions()) - ); + tmp> tPow = New + ( + tdsf, + "pow(" + ds.name() + ',' + dsf.name() + ')', + pow(ds, dsf.dimensions()) + ); pow(tPow.ref().field(), ds.value(), dsf.field()); - reuseTmpDimensionedField::clear(tdsf); + tdsf.clear(); return tPow; } @@ -409,17 +401,16 @@ tmp> atan2 { const DimensionedField& dsf1 = tdsf1(); - tmp> tAtan2 = - reuseTmpDimensionedField::New - ( - tdsf1, - "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', - atan2(dsf1.dimensions(), dsf2.dimensions()) - ); + tmp> tAtan2 = New + ( + tdsf1, + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + atan2(dsf1.dimensions(), dsf2.dimensions()) + ); atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpDimensionedField::clear(tdsf1); + tdsf1.clear(); return tAtan2; } @@ -434,17 +425,16 @@ tmp> atan2 { const DimensionedField& dsf2 = tdsf2(); - tmp> tAtan2 = - reuseTmpDimensionedField::New - ( - tdsf2, - "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', - atan2(dsf1.dimensions(), dsf2.dimensions()) - ); + tmp> tAtan2 = New + ( + tdsf2, + "atan2(" + dsf1.name() + ',' + dsf2.name() + ')', + atan2(dsf1.dimensions(), dsf2.dimensions()) + ); atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpDimensionedField::clear(tdsf2); + tdsf2.clear(); return tAtan2; } @@ -471,11 +461,8 @@ tmp> atan2 atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field()); - reuseTmpTmpDimensionedField::clear - ( - tdsf1, - tdsf2 - ); + tdsf1.clear(); + tdsf2.clear(); return tAtan2; } @@ -517,17 +504,16 @@ tmp> atan2 { const DimensionedField& dsf = tdsf(); - tmp> tAtan2 = - reuseTmpDimensionedField::New - ( - tdsf, - "atan2(" + dsf.name() + ',' + ds.name() + ')', - atan2(dsf.dimensions(), ds) - ); + tmp> tAtan2 = New + ( + tdsf, + "atan2(" + dsf.name() + ',' + ds.name() + ')', + atan2(dsf.dimensions(), ds) + ); atan2(tAtan2.ref().field(), dsf.field(), ds.value()); - reuseTmpDimensionedField::clear(tdsf); + tdsf.clear(); return tAtan2; } @@ -590,17 +576,16 @@ tmp> atan2 { const DimensionedField& dsf = tdsf(); - tmp> tAtan2 = - reuseTmpDimensionedField::New - ( - tdsf, - "atan2(" + ds.name() + ',' + dsf.name() + ')', - atan2(ds, dsf.dimensions()) - ); + tmp> tAtan2 = New + ( + tdsf, + "atan2(" + ds.name() + ',' + dsf.name() + ')', + atan2(ds, dsf.dimensions()) + ); atan2(tAtan2.ref().field(), ds.value(), dsf.field()); - reuseTmpDimensionedField::clear(tdsf); + tdsf.clear(); return tAtan2; } @@ -721,7 +706,7 @@ tmp> func \ \ tmp> tFunc \ ( \ - reuseTmpDimensionedField::New \ + New \ ( \ tdsf, \ #func "(" + name(n) + ',' + dsf.name() + ')', \ @@ -731,7 +716,7 @@ tmp> func \ \ func(tFunc.ref().field(), n, dsf.field()); \ \ - reuseTmpDimensionedField::clear(tdsf); \ + tdsf.clear(); \ \ return tFunc; \ } diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index 1b705e2b8d..14e1d79ff3 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C @@ -103,7 +103,7 @@ pow reuseTmpFieldField::New(tf) ); pow(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -144,7 +144,7 @@ sqr(const tmp>& tf) reuseTmpFieldField::New(tf) ); sqr(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -179,7 +179,7 @@ tmp> magSqr(const tmp>& tf) ); magSqr(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -214,7 +214,7 @@ tmp> mag(const tmp>& tf) ); mag(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -259,7 +259,7 @@ tmp::cmptType>> cmptMax reuseTmpFieldField::New(tf) ); cmptMax(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -304,7 +304,7 @@ tmp::cmptType>> cmptMin reuseTmpFieldField::New(tf) ); cmptMin(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -349,7 +349,7 @@ tmp::cmptType>> cmptAv reuseTmpFieldField::New(tf) ); cmptAv(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -387,12 +387,9 @@ tmp> cmptMag const tmp>& tf ) { - tmp> tRes - ( - reuseTmpFieldField::New(tf) - ); + tmp> tRes(New(tf)); cmptMag(tRes.ref(), tf()); - reuseTmpFieldField::clear(tf); + tf.clear(); return tRes; } @@ -685,7 +682,7 @@ operator op \ reuseTmpFieldField::New(tf2) \ ); \ opFunc(tRes.ref(), f1, tf2()); \ - reuseTmpFieldField::clear(tf2); \ + tf2.clear(); \ return tRes; \ } \ \ @@ -733,7 +730,7 @@ operator op \ reuseTmpFieldField::New(tf1) \ ); \ opFunc(tRes.ref(), tf1(), f2); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } \ \ @@ -758,8 +755,8 @@ operator op \ (tf1, tf2) \ ); \ opFunc(tRes.ref(), tf1(), tf2()); \ - reuseTmpTmpFieldField::clear \ - (tf1, tf2); \ + tf1.clear(); \ + tf2.clear(); \ return tRes; \ } \ \ @@ -811,7 +808,7 @@ operator op \ reuseTmpFieldField::New(tf1) \ ); \ opFunc(tRes.ref(), tf1(), static_cast(vs)); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } \ \ @@ -863,7 +860,7 @@ operator op \ reuseTmpFieldField::New(tf1) \ ); \ opFunc(tRes.ref(), static_cast(vs), tf1()); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C index 1d4b59cbf3..a32972d21a 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctionsM.C @@ -63,12 +63,9 @@ tmp> Func \ const tmp>& tf \ ) \ { \ - tmp> tRes \ - ( \ - reuseTmpFieldField::New(tf) \ - ); \ + tmp> tRes(New(tf)); \ Func(tRes.ref(), tf()); \ - reuseTmpFieldField::clear(tf); \ + tf.clear(); \ return tRes; \ } @@ -110,12 +107,9 @@ tmp> operator Op \ const tmp>& tf \ ) \ { \ - tmp> tRes \ - ( \ - reuseTmpFieldField::New(tf) \ - ); \ + tmp> tRes(New(tf)); \ OpFunc(tRes.ref(), tf()); \ - reuseTmpFieldField::clear(tf); \ + tf.clear(); \ return tRes; \ } @@ -165,7 +159,7 @@ tmp> Func \ reuseTmpFieldField::New(tf2) \ ); \ Func(tRes.ref(), f1, tf2()); \ - reuseTmpFieldField::clear(tf2); \ + tf2.clear(); \ return tRes; \ } \ \ @@ -181,7 +175,7 @@ tmp> Func \ reuseTmpFieldField::New(tf1) \ ); \ Func(tRes.ref(), tf1(), f2); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } \ \ @@ -198,8 +192,8 @@ tmp> Func \ New(tf1, tf2) \ ); \ Func(tRes.ref(), tf1(), tf2()); \ - reuseTmpTmpFieldField:: \ - clear(tf1, tf2); \ + tf1.clear(); \ + tf2.clear(); \ return tRes; \ } @@ -249,7 +243,7 @@ tmp> Func \ reuseTmpFieldField::New(tf1) \ ); \ Func(tRes.ref(), tf1(), s); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } @@ -297,7 +291,7 @@ tmp> Func \ reuseTmpFieldField::New(tf2) \ ); \ Func(tRes.ref(), s, tf2()); \ - reuseTmpFieldField::clear(tf2); \ + tf2.clear(); \ return tRes; \ } @@ -352,7 +346,7 @@ tmp> operator Op \ reuseTmpFieldField::New(tf2) \ ); \ OpFunc(tRes.ref(), f1, tf2()); \ - reuseTmpFieldField::clear(tf2); \ + tf2.clear(); \ return tRes; \ } \ \ @@ -368,7 +362,7 @@ tmp> operator Op \ reuseTmpFieldField::New(tf1) \ ); \ OpFunc(tRes.ref(), tf1(), f2); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } \ \ @@ -385,8 +379,8 @@ tmp> operator Op \ New(tf1, tf2) \ ); \ OpFunc(tRes.ref(), tf1(), tf2()); \ - reuseTmpTmpFieldField:: \ - clear(tf1, tf2); \ + tf1.clear(); \ + tf2.clear(); \ return tRes; \ } @@ -436,7 +430,7 @@ tmp> operator Op \ reuseTmpFieldField::New(tf2) \ ); \ OpFunc(tRes.ref(), s, tf2()); \ - reuseTmpFieldField::clear(tf2); \ + tf2.clear(); \ return tRes; \ } @@ -484,7 +478,7 @@ tmp> operator Op \ reuseTmpFieldField::New(tf1) \ ); \ OpFunc(tRes.ref(), tf1(), s); \ - reuseTmpFieldField::clear(tf1); \ + tf1.clear(); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H index 672006b452..0006d9aa01 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldReuseFunctions.H @@ -33,6 +33,34 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template class Field, class TypeR> +tmp> New +( + const tmp>& tf1, + const bool initRet = false +) +{ + if (tf1.isTmp()) + { + return tf1; + } + else + { + tmp> rtf + ( + FieldField::NewCalculatedType(tf1()) + ); + + if (initRet) + { + rtf.ref() = tf1(); + } + + return rtf; + } +} + + template class Field, class TypeR, class Type1> class reuseTmpFieldField { @@ -48,11 +76,6 @@ public: FieldField::NewCalculatedType(tf1()) ); } - - static void clear(const tmp>& tf1) - { - tf1.clear(); - } }; @@ -63,8 +86,7 @@ public: static tmp> New ( - const tmp>& tf1, - const bool initRet = false + const tmp>& tf1 ) { if (tf1.isTmp()) @@ -73,24 +95,12 @@ public: } else { - tmp> rtf + return tmp> ( FieldField::NewCalculatedType(tf1()) ); - - if (initRet) - { - rtf.ref() = tf1(); - } - - return rtf; } } - - static void clear(const tmp>& tf1) - { - tf1.clear(); - } }; @@ -117,16 +127,6 @@ public: FieldField::NewCalculatedType(tf1()) ); } - - static void clear - ( - const tmp>& tf1, - const tmp>& tf2 - ) - { - tf1.clear(); - tf2.clear(); - } }; @@ -153,16 +153,6 @@ public: ); } } - - static void clear - ( - const tmp>& tf1, - const tmp>& tf2 - ) - { - tf1.clear(); - tf2.clear(); - } }; @@ -189,16 +179,6 @@ public: ); } } - - static void clear - ( - const tmp>& tf1, - const tmp>& tf2 - ) - { - tf1.clear(); - tf2.clear(); - } }; @@ -229,16 +209,6 @@ public: ); } } - - static void clear - ( - const tmp>& tf1, - const tmp>& tf2 - ) - { - tf1.clear(); - tf2.clear(); - } }; diff --git a/src/OpenFOAM/fields/FieldFields/scalarFieldField/scalarFieldField.C b/src/OpenFOAM/fields/FieldFields/scalarFieldField/scalarFieldField.C index ab97ba0020..3774f66c59 100644 --- a/src/OpenFOAM/fields/FieldFields/scalarFieldField/scalarFieldField.C +++ b/src/OpenFOAM/fields/FieldFields/scalarFieldField/scalarFieldField.C @@ -173,12 +173,9 @@ tmp> func \ const tmp>& tsf \ ) \ { \ - tmp> tRes \ - ( \ - reuseTmpFieldField::New(tsf) \ - ); \ + tmp> tRes(New(tsf)); \ func(tRes(), n, tsf()); \ - reuseTmpFieldField::clear(tsf); \ + tsf.clear(); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index 59b356e6f2..cb723b0aed 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C @@ -624,7 +624,7 @@ template \ class PatchField, class GeoMesh> \ tmp \ < \ - GeometricField::type, PatchField, GeoMesh> \ + GeometricField::type, PatchField, GeoMesh> \ > \ operator op \ ( \ @@ -646,8 +646,7 @@ operator op \ \ Foam::opFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf2); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -656,7 +655,7 @@ template \ class PatchField, class GeoMesh> \ tmp \ < \ - GeometricField::type, PatchField, GeoMesh> \ + GeometricField::type, PatchField, GeoMesh> \ > \ operator op \ ( \ @@ -678,8 +677,7 @@ operator op \ \ Foam::opFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -688,7 +686,7 @@ template \ class PatchField, class GeoMesh> \ tmp \ < \ - GeometricField::type, PatchField, GeoMesh> \ + GeometricField::type, PatchField, GeoMesh> \ > \ operator op \ ( \ @@ -713,9 +711,8 @@ operator op \ \ Foam::opFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpTmpGeometricField \ - \ - ::clear(tgf1, tgf2); \ + tgf1.clear(); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -736,7 +733,7 @@ void opFunc \ \ template \ class PatchField, class GeoMesh> \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const GeometricField& gf1, \ @@ -775,7 +772,7 @@ template \ class Type, template class PatchField, \ class GeoMesh \ > \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const GeometricField& gf1, \ @@ -788,7 +785,7 @@ operator op \ \ template \ class PatchField, class GeoMesh> \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const tmp>& tgf1, \ @@ -809,8 +806,7 @@ operator op \ \ Foam::opFunc(tRes.ref(), gf1, dvs); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -823,7 +819,7 @@ template \ class Type, template class PatchField, \ class GeoMesh \ > \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const tmp>& tgf1, \ @@ -850,7 +846,7 @@ void opFunc \ \ template \ class PatchField, class GeoMesh> \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const dimensioned
& dvs, \ @@ -888,7 +884,7 @@ template \ class Type, template class PatchField, \ class GeoMesh \ > \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const VectorSpace& vs, \ @@ -900,7 +896,7 @@ operator op \ \ template \ class PatchField, class GeoMesh> \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const dimensioned& dvs, \ @@ -921,8 +917,7 @@ operator op \ \ Foam::opFunc(tRes.ref(), dvs, gf1); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -935,7 +930,7 @@ template \ class Type, template class PatchField, \ class GeoMesh \ > \ -tmp::type, PatchField, GeoMesh>> \ +tmp::type, PatchField, GeoMesh>> \ operator op \ ( \ const VectorSpace& vs, \ diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C index 344e79e8e6..2d0b007c27 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctionsM.C @@ -93,8 +93,7 @@ tmp> Func \ \ Foam::Func(tRes.ref(), gf1); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } @@ -163,8 +162,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), gf1); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } @@ -236,8 +234,7 @@ tmp> Func \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf2); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -263,8 +260,7 @@ tmp> Func \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -294,9 +290,8 @@ tmp> Func \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ - reuseTmpTmpGeometricField \ - \ - ::clear(tgf1, tgf2); \ + tgf1.clear(); \ + tgf2.clear(); \ \ return tRes; \ } @@ -378,8 +373,7 @@ tmp> Func \ \ Foam::Func(tRes.ref(), dt1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf2); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -470,8 +464,7 @@ tmp> Func \ \ Foam::Func(tRes.ref(), gf1, dt2); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -560,8 +553,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf2); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -587,8 +579,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ @@ -617,9 +608,8 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ - reuseTmpTmpGeometricField \ - \ - ::clear(tgf1, tgf2); \ + tgf1.clear(); \ + tgf2.clear(); \ \ return tRes; \ } @@ -702,8 +692,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), dt1, gf2); \ \ - reuseTmpGeometricField \ - ::clear(tgf2); \ + tgf2.clear(); \ \ return tRes; \ } \ @@ -794,8 +783,7 @@ tmp> operator Op \ \ Foam::OpFunc(tRes.ref(), gf1, dt2); \ \ - reuseTmpGeometricField \ - ::clear(tgf1); \ + tgf1.clear(); \ \ return tRes; \ } \ diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H index 5429c4f44f..3cb442163d 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldReuseFunctions.H @@ -75,6 +75,51 @@ bool reusable(const tmp>& tgf) } +template class PatchField, class GeoMesh> +tmp> New +( + const tmp>& tgf1, + const word& name, + const dimensionSet& dimensions, + const bool initRet = false +) +{ + GeometricField& gf1 = + const_cast& >(tgf1()); + + if (reusable(tgf1)) + { + gf1.rename(name); + gf1.dimensions().reset(dimensions); + return tgf1; + } + else + { + tmp> rtgf + ( + new GeometricField + ( + IOobject + ( + name, + gf1.instance(), + gf1.db() + ), + gf1.mesh(), + dimensions + ) + ); + + if (initRet) + { + rtgf.ref() == tgf1(); + } + + return rtgf; + } +} + + template < class TypeR, @@ -110,14 +155,6 @@ public: ) ); } - - static void clear - ( - const tmp>& tgf1 - ) - { - tgf1.clear(); - } }; @@ -130,8 +167,7 @@ public: ( const tmp>& tgf1, const word& name, - const dimensionSet& dimensions, - const bool initRet = false + const dimensionSet& dimensions ) { GeometricField& gf1 = @@ -145,7 +181,7 @@ public: } else { - tmp> rtgf + return tmp> ( new GeometricField ( @@ -159,23 +195,8 @@ public: dimensions ) ); - - if (initRet) - { - rtgf.ref() == tgf1(); - } - - return rtgf; } } - - static void clear - ( - const tmp>& tgf1 - ) - { - tgf1.clear(); - } }; @@ -217,16 +238,6 @@ public: ) ); } - - static void clear - ( - const tmp>& tgf1, - const tmp>& tgf2 - ) - { - tgf1.clear(); - tgf2.clear(); - } }; @@ -279,16 +290,6 @@ public: ); } } - - static void clear - ( - const tmp>& tgf1, - const tmp>& tgf2 - ) - { - tgf1.clear(); - tgf2.clear(); - } }; @@ -338,16 +339,6 @@ public: ); } } - - static void clear - ( - const tmp>& tgf1, - const tmp>& tgf2 - ) - { - tgf1.clear(); - tgf2.clear(); - } }; @@ -399,16 +390,6 @@ public: ); } } - - static void clear - ( - const tmp>& tgf1, - const tmp>& tgf2 - ) - { - tgf1.clear(); - tgf2.clear(); - } }; diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C index add1ed8dfb..41bbe8178f 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricScalarField/GeometricScalarField.C @@ -89,7 +89,7 @@ tmp> stabilise tmp> tRes ( - reuseTmpGeometricField::New + New ( tgsf, "stabilise(" + gsf.name() + ',' + ds.name() + ')', @@ -99,7 +99,7 @@ tmp> stabilise stabilise(tRes.ref(), gsf, ds); - reuseTmpGeometricField::clear(tgsf); + tgsf.clear(); return tRes; } @@ -176,7 +176,7 @@ tmp> pow tmp> tPow ( - reuseTmpGeometricField::New + New ( tgsf1, "pow(" + gsf1.name() + ',' + gsf2.name() + ')', @@ -190,7 +190,7 @@ tmp> pow pow(tPow.ref(), gsf1, gsf2); - reuseTmpGeometricField::clear(tgsf1); + tgsf1.clear(); return tPow; } @@ -207,7 +207,7 @@ tmp> pow tmp> tPow ( - reuseTmpGeometricField::New + New ( tgsf2, "pow(" + gsf1.name() + ',' + gsf2.name() + ')', @@ -221,7 +221,7 @@ tmp> pow pow(tPow.ref(), gsf1, gsf2); - reuseTmpGeometricField::clear(tgsf2); + tgsf2.clear(); return tPow; } @@ -254,9 +254,8 @@ tmp> pow pow(tPow.ref(), gsf1, gsf2); - reuseTmpTmpGeometricField - - ::clear(tgsf1, tgsf2); + tgsf1.clear(); + tgsf2.clear(); return tPow; } @@ -315,7 +314,7 @@ tmp> pow tmp> tPow ( - reuseTmpGeometricField::New + New ( tgsf, "pow(" + gsf.name() + ',' + ds.name() + ')', @@ -325,7 +324,7 @@ tmp> pow pow(tPow.ref(), gsf, ds); - reuseTmpGeometricField::clear(tgsf); + tgsf.clear(); return tPow; } @@ -405,7 +404,7 @@ tmp> pow tmp> tPow ( - reuseTmpGeometricField::New + New ( tgsf, "pow(" + ds.name() + ',' + gsf.name() + ')', @@ -415,7 +414,7 @@ tmp> pow pow(tPow.ref(), ds, gsf); - reuseTmpGeometricField::clear(tgsf); + tgsf.clear(); return tPow; } @@ -497,7 +496,7 @@ tmp> atan2 tmp> tAtan2 ( - reuseTmpGeometricField::New + New ( tgsf1, "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', @@ -507,7 +506,7 @@ tmp> atan2 atan2(tAtan2.ref(), gsf1, gsf2); - reuseTmpGeometricField::clear(tgsf1); + tgsf1.clear(); return tAtan2; } @@ -524,7 +523,7 @@ tmp> atan2 tmp> tAtan2 ( - reuseTmpGeometricField::New + New ( tgsf2, "atan2(" + gsf1.name() + ',' + gsf2.name() + ')', @@ -534,7 +533,7 @@ tmp> atan2 atan2(tAtan2.ref(), gsf1, gsf2); - reuseTmpGeometricField::clear(tgsf2); + tgsf2.clear(); return tAtan2; } @@ -563,9 +562,8 @@ tmp> atan2 atan2(tAtan2.ref(), gsf1, gsf2); - reuseTmpTmpGeometricField - - ::clear(tgsf1, tgsf2); + tgsf1.clear(); + tgsf2.clear(); return tAtan2; } @@ -624,7 +622,7 @@ tmp> atan2 tmp> tAtan2 ( - reuseTmpGeometricField::New + New ( tgsf, "atan2(" + gsf.name() + ',' + ds.name() + ')', @@ -634,7 +632,7 @@ tmp> atan2 atan2(tAtan2.ref(), gsf, ds); - reuseTmpGeometricField::clear(tgsf); + tgsf.clear(); return tAtan2; } @@ -714,7 +712,7 @@ tmp> atan2 tmp> tAtan2 ( - reuseTmpGeometricField::New + New ( tgsf, "atan2(" + ds.name() + ',' + gsf.name() + ')', @@ -724,7 +722,7 @@ tmp> atan2 atan2(tAtan2.ref(), ds, gsf); - reuseTmpGeometricField::clear(tgsf); + tgsf.clear(); return tAtan2; } @@ -859,7 +857,7 @@ tmp> func \ \ tmp> tFunc \ ( \ - reuseTmpGeometricField::New \ + New \ ( \ tgsf, \ #func "(" + gsf.name() + ')', \ @@ -869,8 +867,7 @@ tmp> func \ \ func(tFunc.ref(), n, gsf); \ \ - reuseTmpGeometricField \ - ::clear(tgsf); \ + tgsf.clear(); \ \ return tFunc; \ } diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index a6a2824d79..5c96220048 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -82,23 +82,23 @@ inline Foam::tmp::tmp(const tmp& t, bool allowTransfer) { if (isTmp()) { - if (allowTransfer) + if (ptr_) { - const_cast&>(t).ptr_ = 0; - } - else - { - if (ptr_) + if (allowTransfer) { - ptr_->operator++(); + t.ptr_ = 0; } else { - FatalErrorInFunction - << "Attempted copy of a deallocated " << typeName() - << abort(FatalError); + ptr_->operator++(); } } + else + { + FatalErrorInFunction + << "Attempted copy of a deallocated " << typeName() + << abort(FatalError); + } } } diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C index 5e31ac1269..6b9cc1ca6f 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C @@ -228,8 +228,7 @@ Foam::tmp Foam::MRFZoneList::relative { tmp rphi ( - reuseTmpGeometricField - ::New + New ( tphi, "relative(" + tphi().name() + ')', @@ -240,8 +239,7 @@ Foam::tmp Foam::MRFZoneList::relative makeRelative(rphi.ref()); - reuseTmpGeometricField - ::clear(tphi); + tphi.clear(); return rphi; } @@ -260,17 +258,14 @@ Foam::MRFZoneList::relative { if (size()) { - tmp> rphi - ( - reuseTmpFieldField::New(tphi, true) - ); + tmp> rphi(New(tphi, true)); forAll(*this, i) { operator[](i).makeRelative(rphi.ref()); } - reuseTmpFieldField::clear(tphi); + tphi.clear(); return rphi; } @@ -348,8 +343,7 @@ Foam::tmp Foam::MRFZoneList::absolute { tmp rphi ( - reuseTmpGeometricField - ::New + New ( tphi, "absolute(" + tphi().name() + ')', @@ -360,8 +354,7 @@ Foam::tmp Foam::MRFZoneList::absolute makeAbsolute(rphi.ref()); - reuseTmpGeometricField - ::clear(tphi); + tphi.clear(); return rphi; }