Commit e1405f22 authored by Henry Weller's avatar Henry Weller
Browse files

FieldField, DimensionedField, GeometricField: Simplified tmp reuse and cleanup

parent 85fa6c26
......@@ -88,7 +88,7 @@ pow
pow<Type, r, GeoMesh>(tPow().field(), df.field());
reuseTmpDimensionedField<powProductType, Type, GeoMesh>::clear(tdf);
tdf.clear();
return tPow;
}
......@@ -137,7 +137,7 @@ sqr(const tmp<DimensionedField<Type, GeoMesh>>& tdf)
sqr(tSqr().field(), df.field());
reuseTmpDimensionedField<outerProductType, Type, GeoMesh>::clear(tdf);
tdf.clear();
return tSqr;
}
......@@ -187,7 +187,7 @@ tmp<DimensionedField<scalar, GeoMesh>> magSqr
magSqr(tMagSqr().field(), df.field());
reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
tdf.clear();
return tMagSqr;
}
......@@ -237,7 +237,7 @@ tmp<DimensionedField<scalar, GeoMesh>> mag
mag(tMag().field(), df.field());
reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
tdf.clear();
return tMag;
}
......@@ -296,7 +296,7 @@ cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tdf)
cmptAv(CmptAv().field(), df.field());
reuseTmpDimensionedField<cmptType, Type, GeoMesh>::clear(tdf);
tdf.clear();
return CmptAv;
}
......@@ -417,7 +417,7 @@ operator op \
\
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<productType, Type2, GeoMesh>::clear(tdf2); \
tdf2.clear(); \
\
return tRes; \
} \
......@@ -444,7 +444,7 @@ operator op \
\
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<productType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......@@ -474,8 +474,8 @@ operator op \
\
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField \
<productType, Type1, Type1, Type2, GeoMesh>::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<productType, Type, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......@@ -623,7 +623,7 @@ operator op \
\
Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
\
reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......
......@@ -75,7 +75,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), df1.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
}
......@@ -131,7 +131,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), df1.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
}
......@@ -189,7 +189,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
tdf2.clear(); \
\
return tRes; \
} \
......@@ -215,7 +215,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......@@ -244,8 +244,8 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField<ReturnType, Type1, Type1, Type2, GeoMesh> \
::clear(tdf1, tdf2); \
tdf1.clear(); \
tdf2.clear(); \
\
return tRes; \
}
......@@ -314,7 +314,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), dt1.value(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
tdf2.clear(); \
\
return tRes; \
} \
......@@ -391,7 +391,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
\
Func(tRes.ref().field(), df1.field(), dt2.value()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......@@ -464,7 +464,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
tdf2.clear(); \
\
return tRes; \
} \
......@@ -490,7 +490,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......@@ -519,8 +519,8 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField<ReturnType, Type1, Type1, Type2, GeoMesh>:: \
clear(tdf1, tdf2); \
tdf1.clear(); \
tdf2.clear(); \
\
return tRes; \
}
......@@ -589,7 +589,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), dt1.value(), tdf2().field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
tdf2.clear(); \
\
return tRes; \
} \
......@@ -666,7 +666,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
\
Foam::OpFunc(tRes.ref().field(), tdf1().field(), dt2.value()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
tdf1.clear(); \
\
return tRes; \
} \
......
......@@ -33,6 +33,43 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class TypeR, class GeoMesh>
tmp<DimensionedField<TypeR, GeoMesh>> New
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
const word& name,
const dimensionSet& dimensions
)
{
DimensionedField<TypeR, GeoMesh>& df1 =
const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
if (tdf1.isTmp())
{
df1.rename(name);
df1.dimensions().reset(dimensions);
return tdf1;
}
else
{
return tmp<DimensionedField<TypeR, GeoMesh>>
(
new DimensionedField<TypeR, GeoMesh>
(
IOobject
(
name,
df1.instance(),
df1.db()
),
df1.mesh(),
dimensions
)
);
}
}
template<class TypeR, class Type1, class GeoMesh>
class reuseTmpDimensionedField
{
......@@ -62,11 +99,6 @@ public:
)
);
}
static void clear(const tmp<DimensionedField<Type1, GeoMesh>>& tdf1)
{
tdf1.clear();
}
};
......@@ -109,11 +141,6 @@ public:
);
}
}
static void clear(const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1)
{
tdf1.clear();
}
};
......@@ -147,16 +174,6 @@ public:
)
);
}
static void clear
(
const tmp<DimensionedField<Type1, GeoMesh>>& tdf1,
const tmp<DimensionedField<Type2, GeoMesh>>& tdf2
)
{
tdf1.clear();
tdf2.clear();
}
};
......@@ -201,16 +218,6 @@ public:
);
}
}
static void clear
(
const tmp<DimensionedField<Type1, GeoMesh>>& tdf1,
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf2
)
{
tdf1.clear();
tdf2.clear();
}
};
......@@ -254,16 +261,6 @@ public:
);
}
}
static void clear
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
const tmp<DimensionedField<Type2, GeoMesh>>& tdf2
)
{
tdf1.clear();
tdf2.clear();
}
};
......@@ -315,16 +312,6 @@ public:
);
}
}
static void clear
(
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1,
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf2
)
{
tdf1.clear();
tdf2.clear();
}
};
......
......@@ -72,17 +72,16 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tRes =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf,
"stabilise(" + dsf.name() + ',' + ds.name() + ')',
dsf.dimensions() + ds.dimensions()
);
tmp<DimensionedField<scalar, GeoMesh>> tRes = New
(
tdsf,
"stabilise(" + dsf.name() + ',' + ds.name() + ')',
dsf.dimensions() + ds.dimensions()
);
stabilise(tRes.ref().field(), dsf.field(), ds.value());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
tdsf.clear();
return tRes;
}
......@@ -141,21 +140,20 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
{
const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
tmp<DimensionedField<scalar, GeoMesh>> tPow =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
tmp<DimensionedField<scalar, GeoMesh>> 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<scalar, scalar, GeoMesh>::clear(tdsf1);
tdsf1.clear();
return tPow;
}
......@@ -170,21 +168,20 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
{
const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
tmp<DimensionedField<scalar, GeoMesh>> tPow =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
tmp<DimensionedField<scalar, GeoMesh>> 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<scalar, scalar, GeoMesh>::clear(tdsf2);
tdsf2.clear();
return tPow;
}
......@@ -215,11 +212,8 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::clear
(
tdsf1,
tdsf2
);
tdsf1.clear();
tdsf2.clear();
return tPow;
}
......@@ -261,17 +255,16 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tPow =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf,
"pow(" + dsf.name() + ',' + ds.name() + ')',
pow(dsf.dimensions(), ds)
);
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
(
tdsf,
"pow(" + dsf.name() + ',' + ds.name() + ')',
pow(dsf.dimensions(), ds)
);
pow(tPow.ref().field(), dsf.field(), ds.value());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
tdsf.clear();
return tPow;
}
......@@ -334,17 +327,16 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tPow =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf,
"pow(" + ds.name() + ',' + dsf.name() + ')',
pow(ds, dsf.dimensions())
);
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
(
tdsf,
"pow(" + ds.name() + ',' + dsf.name() + ')',
pow(ds, dsf.dimensions())
);
pow(tPow.ref().field(), ds.value(), dsf.field());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
tdsf.clear();
return tPow;
}
......@@ -409,17 +401,16 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf1,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
(
tdsf1,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf1);
tdsf1.clear();
return tAtan2;
}
......@@ -434,17 +425,16 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf2,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
(
tdsf2,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf2);
tdsf2.clear();
return tAtan2;
}
......@@ -471,11 +461,8 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::clear
(
tdsf1,
tdsf2
);
tdsf1.clear();
tdsf2.clear();
return tAtan2;
}
......@@ -517,17 +504,16 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf,
"atan2(" + dsf.name() + ',' + ds.name() + ')',
atan2(dsf.dimensions(), ds)
);
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
(
tdsf,
"atan2(" + dsf.name() + ',' + ds.name() + ')',
atan2(dsf.dimensions(), ds)
);
atan2(tAtan2.ref().field(), dsf.field(), ds.value());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
tdsf.clear();
return tAtan2;
}
......@@ -590,17 +576,16 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 =
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::New
(
tdsf,
"atan2(" + ds.name() + ',' + dsf.name() + ')',
atan2(ds, dsf.dimensions())