Commit ac7a8803 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: modernize code for concrete Fields (#1160)

- use forwarding tmp factory methods, auto types
parent 7e48f2c6
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -42,9 +42,8 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
const dimensioned<scalar>& ds
)
{
tmp<DimensionedField<scalar, GeoMesh>> tRes
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -54,12 +53,11 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
),
dsf.mesh(),
dsf.dimensions() + ds.dimensions()
)
);
);
stabilise(tRes.ref().field(), dsf.field(), ds.value());
stabilise(tres.ref().field(), dsf.field(), ds.value());
return tRes;
return tres;
}
......@@ -72,18 +70,18 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tRes = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf,
"stabilise(" + dsf.name() + ',' + ds.name() + ')',
dsf.dimensions() + ds.dimensions()
);
stabilise(tRes.ref().field(), dsf.field(), ds.value());
stabilise(tres.ref().field(), dsf.field(), ds.value());
tdsf.clear();
return tRes;
return tres;
}
......@@ -120,9 +118,8 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -132,12 +129,11 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
),
dsf1.mesh(),
dimless
)
);
);
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
pow(tres.ref().field(), dsf1.field(), dsf2.field());
return tPow;
return tres;
}
......@@ -164,18 +160,18 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf1,
"pow(" + dsf1.name() + ',' + dsf2.name() + ')',
dimless
);
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
pow(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf1.clear();
return tPow;
return tres;
}
......@@ -202,18 +198,18 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf2,
"pow(" + dsf1.name() + ',' + dsf2.name() + ')',
dimless
);
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
pow(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf2.clear();
return tPow;
return tres;
}
......@@ -241,7 +237,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow =
auto tres =
reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::
New
(
......@@ -251,12 +247,12 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
dimless
);
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
pow(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf1.clear();
tdsf2.clear();
return tPow;
return tres;
}
......@@ -274,9 +270,8 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -286,12 +281,11 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
),
dsf.mesh(),
pow(dsf.dimensions(), ds)
)
);
);
pow(tPow.ref().field(), dsf.field(), ds.value());
pow(tres.ref().field(), dsf.field(), ds.value());
return tPow;
return tres;
}
......@@ -311,18 +305,18 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf,
"pow(" + dsf.name() + ',' + ds.name() + ')',
pow(dsf.dimensions(), ds)
);
pow(tPow.ref().field(), dsf.field(), ds.value());
pow(tres.ref().field(), dsf.field(), ds.value());
tdsf.clear();
return tPow;
return tres;
}
......@@ -369,9 +363,8 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -381,12 +374,11 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
),
dsf.mesh(),
dimless
)
);
);
pow(tPow.ref().field(), ds.value(), dsf.field());
pow(tres.ref().field(), ds.value(), dsf.field());
return tPow;
return tres;
}
......@@ -413,18 +405,18 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
<< exit(FatalError);
}
tmp<DimensionedField<scalar, GeoMesh>> tPow = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf,
"pow(" + ds.name() + ',' + dsf.name() + ')',
dimless
);
pow(tPow.ref().field(), ds.value(), dsf.field());
pow(tres.ref().field(), ds.value(), dsf.field());
tdsf.clear();
return tPow;
return tres;
}
template<class GeoMesh>
......@@ -457,9 +449,8 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
const DimensionedField<scalar, GeoMesh>& dsf2
)
{
tmp<DimensionedField<scalar, GeoMesh>> tAtan2
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -469,12 +460,11 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
),
dsf1.mesh(),
atan2(dsf1.dimensions(), dsf2.dimensions())
)
);
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
atan2(tres.ref().field(), dsf1.field(), dsf2.field());
return tAtan2;
return tres;
}
......@@ -487,18 +477,18 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf1,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
atan2(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf1.clear();
return tAtan2;
return tres;
}
......@@ -511,18 +501,18 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf2,
"atan2(" + dsf1.name() + ',' + dsf2.name() + ')',
atan2(dsf1.dimensions(), dsf2.dimensions())
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
atan2(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf2.clear();
return tAtan2;
return tres;
}
template<class GeoMesh>
......@@ -535,7 +525,7 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
const DimensionedField<scalar, GeoMesh>& dsf1 = tdsf1();
const DimensionedField<scalar, GeoMesh>& dsf2 = tdsf2();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 =
auto tres =
reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::
New
(
......@@ -545,12 +535,12 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
atan2(dsf1.dimensions(), dsf2.dimensions())
);
atan2(tAtan2.ref().field(), dsf1.field(), dsf2.field());
atan2(tres.ref().field(), dsf1.field(), dsf2.field());
tdsf1.clear();
tdsf2.clear();
return tAtan2;
return tres;
}
......@@ -561,9 +551,8 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
const dimensionedScalar& ds
)
{
tmp<DimensionedField<scalar, GeoMesh>> tAtan2
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -573,12 +562,11 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
),
dsf.mesh(),
atan2(dsf.dimensions(), ds)
)
);
);
atan2(tAtan2.ref().field(), dsf.field(), ds.value());
atan2(tres.ref().field(), dsf.field(), ds.value());
return tAtan2;
return tres;
}
template<class GeoMesh>
......@@ -590,18 +578,18 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf,
"atan2(" + dsf.name() + ',' + ds.name() + ')',
atan2(dsf.dimensions(), ds)
);
atan2(tAtan2.ref().field(), dsf.field(), ds.value());
atan2(tres.ref().field(), dsf.field(), ds.value());
tdsf.clear();
return tAtan2;
return tres;
}
template<class GeoMesh>
......@@ -632,9 +620,8 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
const DimensionedField<scalar, GeoMesh>& dsf
)
{
tmp<DimensionedField<scalar, GeoMesh>> tAtan2
(
new DimensionedField<scalar, GeoMesh>
auto tres =
tmp<DimensionedField<scalar, GeoMesh>>::New
(
IOobject
(
......@@ -644,12 +631,11 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
),
dsf.mesh(),
atan2(ds, dsf.dimensions())
)
);
);
atan2(tAtan2.ref().field(), ds.value(), dsf.field());
atan2(tres.ref().field(), ds.value(), dsf.field());
return tAtan2;
return tres;
}
......@@ -662,18 +648,18 @@ tmp<DimensionedField<scalar, GeoMesh>> atan2
{
const DimensionedField<scalar, GeoMesh>& dsf = tdsf();
tmp<DimensionedField<scalar, GeoMesh>> tAtan2 = New
tmp<DimensionedField<scalar, GeoMesh>> tres = New
(
tdsf,
"atan2(" + ds.name() + ',' + dsf.name() + ')',
atan2(ds, dsf.dimensions())
);
atan2(tAtan2.ref().field(), ds.value(), dsf.field());
atan2(tres.ref().field(), ds.value(), dsf.field());
tdsf.clear();
return tAtan2;
return tres;
}
template<class GeoMesh>
......@@ -756,9 +742,8 @@ tmp<DimensionedField<scalar, GeoMesh>> func \
<< abort(FatalError); \
} \
\
tmp<DimensionedField<scalar, GeoMesh>> tFunc \
( \
new DimensionedField<scalar, GeoMesh> \
auto tres = \
tmp<DimensionedField<scalar, GeoMesh>>::New \
( \
IOobject \
( \
......@@ -768,14 +753,14 @@ tmp<DimensionedField<scalar, GeoMesh>> func \
), \
dsf.mesh(), \
dimless \
) \
); \
); \
\
func(tFunc.ref().field(), n, dsf.field()); \
func(tres.ref().field(), n, dsf.field()); \
\
return tFunc; \
return tres; \
} \
\
\
template<class GeoMesh> \
tmp<DimensionedField<scalar, GeoMesh>> func \
( \
......@@ -792,7 +777,7 @@ tmp<DimensionedField<scalar, GeoMesh>> func \
<< abort(FatalError); \
} \
\
tmp<DimensionedField<scalar, GeoMesh>> tFunc \
tmp<DimensionedField<scalar, GeoMesh>> tres \
( \
New \
( \
......@@ -802,11 +787,11 @@ tmp<DimensionedField<scalar, GeoMesh>> func \
) \
); \
\
func(tFunc.ref().field(), n, dsf.field()); \
func(tres.ref().field(), n, dsf.field()); \
\
tdsf.clear(); \
\
return tFunc; \
return tres; \
}
BesselFunc(jn)
......
......@@ -73,17 +73,17 @@ void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
tmp<scalarField> stabilise(const UList<scalar>& sf, const scalar s)
{
tmp<scalarField> tRes(new scalarField(sf.size()));
stabilise(tRes.ref(), sf, s);
return tRes;
auto tresult = tmp<scalarField>::New(sf.size());
stabilise(tresult.ref(), sf, s);
return tresult;
}
tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
{
tmp<scalarField> tRes = New(tsf);
stabilise(tRes.ref(), tsf(), s);
tmp<scalarField> tresult = New(tsf);
stabilise(tresult.ref(), tsf(), s);
tsf.clear();
return tRes;
return tresult;
}
......@@ -92,16 +92,12 @@ tmp<scalarField> stabilise(const tmp<scalarField>& tsf, const scalar s)
template<>
scalar sumProd(const UList<scalar>& f1, const UList<scalar>& f2)
{
scalar SumProd = 0.0;
if (f1.size() && (f1.size() == f2.size()))
{
scalar SumProd = 0.0;
TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, scalar, f1, *, scalar, f2)
return SumProd;
}
else
{
return 0.0;
}
return SumProd;
}
......@@ -174,17 +170,17 @@ void func(scalarField& res, const int n, const UList<scalar>& sf) \
\
tmp<scalarField> func(const int n, const UList<scalar>& sf) \
{ \
tmp<scalarField> tRes(new scalarField(sf.size())); \
func(tRes.ref(), n, sf); \
return tRes; \
auto tresult = tmp<scalarField>::New(sf.size()); \
func(tresult.ref(), n, sf); \
return tresult; \
} \
\
tmp<scalarField> func(const int n, const tmp<scalarField>& tsf) \
{ \
tmp<scalarField> tRes = New(tsf); \
func(tRes.ref(), n, tsf()); \
tmp<scalarField> tresult = New(tsf); \
func(tresult.ref(), n, tsf()); \
tsf.clear(); \
return tRes; \
return tresult; \
}
BesselFunc(jn)
......
......@@ -107,17 +107,17 @@ void inv(Field<symmTensor>& tf, const UList<symmTensor>& tf1)
tmp<symmTensorField> inv(const UList<symmTensor>& tf)
{
tmp<symmTensorField> result(new symmTensorField(tf.size()));
inv(result.ref(), tf);
return result;
auto tresult = tmp<symmTensorField>::New(tf.size());
inv(tresult.ref(), tf);
return tresult;
}
tmp<symmTensorField> inv(const tmp<symmTensorField>& tf)
{
tmp<symmTensorField> tRes = New(tf);
inv(tRes.ref(), tf());
tmp<symmTensorField> tresult = New(tf);
inv(tresult.ref(), tf());
tf.clear();
return tRes;
return tresult;
}
......
......@@ -31,7 +31,7 @@ License
namespace Foam
{
// * * * * * * * * * * * * * * * global functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type>