Commit c02bf70e authored by Henry Weller's avatar Henry Weller

tmp: Improved reference count checks to provide better error diagnostics

in case of tmp misuse.

Simplified tmp reuse pattern in field algebra to use tmp copy and
assignment rather than the complex delayed call to 'ptr()'.

Removed support for unused non-const 'REF' storage of non-tmp objects due to C++
limitation in constructor overloading: if both tmp(T&) and tmp(const T&)
constructors are provided resolution is ambiguous.

The turbulence libraries have been upgraded and '-DCONST_TMP' option
specified in the 'options' file to switch to the new 'tmp' behavior.
parent 5a74397f
EXE_INC = \
EXE_INC = -DCONST_TMP \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/transportModels \
......
......@@ -201,7 +201,7 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Kd
{
if (phase1 == &phase)
{
tKd() += K;
tKd.ref() += K;
}
Swap(phase1, phase2);
......
EXE_INC = \
EXE_INC = -DCONST_TMP \
-I../multiphaseSystem/lnInclude \
-I../../phaseSystems/lnInclude \
-I../../interfacialModels/lnInclude\
......
EXE_INC = \
EXE_INC = -DCONST_TMP \
-I../twoPhaseSystem/lnInclude \
-I../../phaseSystems/lnInclude \
-I../../interfacialModels/lnInclude\
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -83,7 +83,7 @@ alphatPhaseChangeJayatillekeWallFunctionFvPatchScalarField::yPlusTherm
) const
{
tmp<scalarField> typsf(new scalarField(this->size()));
scalarField& ypsf = typsf();
scalarField& ypsf = typsf.ref();
forAll(ypsf, faceI)
{
......@@ -197,7 +197,7 @@ alphatPhaseChangeJayatillekeWallFunctionFvPatchScalarField::calcAlphat
scalarField yPlusTherm(this->yPlusTherm(P, Prat));
tmp<scalarField> talphatConv(new scalarField(this->size()));
scalarField& alphatConv = talphatConv();
scalarField& alphatConv = talphatConv.ref();
// Populate boundary values
forAll(alphatConv, faceI)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -132,7 +132,7 @@ Foam::kineticTheoryModels::frictionalStressModels::Schaeffer::nu
)
);
volScalarField& nuf = tnu();
volScalarField& nuf = tnu.ref();
forAll(D, celli)
{
......
......@@ -273,7 +273,8 @@ Foam::RASModels::kineticTheoryModel::pPrime() const
)
);
volScalarField::GeometricBoundaryField& bpPrime = tpPrime().boundaryField();
volScalarField::GeometricBoundaryField& bpPrime =
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......
......@@ -164,7 +164,8 @@ Foam::RASModels::phasePressureModel::pPrime() const
)
);
volScalarField::GeometricBoundaryField& bpPrime = tpPrime().boundaryField();
volScalarField::GeometricBoundaryField& bpPrime =
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......@@ -192,7 +193,7 @@ Foam::RASModels::phasePressureModel::pPrimef() const
);
surfaceScalarField::GeometricBoundaryField& bpPrime =
tpPrime().boundaryField();
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......
EXE_INC = \
EXE_INC = -DCONST_TMP \
-I../twoPhaseSystem/lnInclude \
-I../interfacialModels/lnInclude\
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -132,7 +132,7 @@ Foam::kineticTheoryModels::frictionalStressModels::Schaeffer::nu
)
);
volScalarField& nuf = tnu();
volScalarField& nuf = tnu.ref();
forAll(D, celli)
{
......
......@@ -278,7 +278,8 @@ Foam::RASModels::kineticTheoryModel::pPrime() const
)
);
volScalarField::GeometricBoundaryField& bpPrime = tpPrime().boundaryField();
volScalarField::GeometricBoundaryField& bpPrime =
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......
......@@ -170,7 +170,8 @@ Foam::RASModels::phasePressureModel::pPrime() const
)
);
volScalarField::GeometricBoundaryField& bpPrime = tpPrime().boundaryField();
volScalarField::GeometricBoundaryField& bpPrime =
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......@@ -198,7 +199,7 @@ Foam::RASModels::phasePressureModel::pPrimef() const
);
surfaceScalarField::GeometricBoundaryField& bpPrime =
tpPrime().boundaryField();
tpPrime.ref().boundaryField();
forAll(bpPrime, patchi)
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -45,7 +45,7 @@ inline void token::clear()
}
else if (type_ == COMPOUND)
{
if (compoundTokenPtr_->okToDelete())
if (compoundTokenPtr_->unique())
{
delete compoundTokenPtr_;
}
......
......@@ -390,7 +390,7 @@ operator op \
) \
); \
\
Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
return tRes; \
} \
......@@ -415,7 +415,7 @@ operator op \
df1.dimensions() op df2.dimensions() \
); \
\
Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<productType, Type2, GeoMesh>::clear(tdf2); \
\
......@@ -442,7 +442,7 @@ operator op \
df1.dimensions() op df2.dimensions() \
); \
\
Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<productType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -472,7 +472,7 @@ operator op \
df1.dimensions() op df2.dimensions() \
); \
\
Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField \
<productType, Type1, Type1, Type2, GeoMesh>::clear(tdf1, tdf2); \
......@@ -505,7 +505,7 @@ operator op \
) \
); \
\
Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
\
return tRes; \
} \
......@@ -542,7 +542,7 @@ operator op \
df1.dimensions() op dvs.dimensions() \
); \
\
Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
\
reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
\
......@@ -585,7 +585,7 @@ operator op \
) \
); \
\
Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
\
return tRes; \
} \
......@@ -621,7 +621,7 @@ operator op \
dvs.dimensions() op df1.dimensions() \
); \
\
Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
\
reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
\
......
......@@ -50,7 +50,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field()); \
Func(tRes.ref().field(), df1.field()); \
\
return tRes; \
} \
......@@ -73,7 +73,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field()); \
Func(tRes.ref().field(), df1.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -106,7 +106,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field()); \
\
return tRes; \
} \
......@@ -129,7 +129,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -163,7 +163,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), df2.field()); \
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
return tRes; \
} \
......@@ -187,7 +187,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), df2.field()); \
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
\
......@@ -213,7 +213,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), df2.field()); \
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -242,7 +242,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), df2.field()); \
Func(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField<ReturnType, Type1, Type1, Type2, GeoMesh> \
::clear(tdf1, tdf2); \
......@@ -277,7 +277,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), dt1.value(), df2.field()); \
Func(tRes.ref().field(), dt1.value(), df2.field()); \
\
return tRes; \
} \
......@@ -312,7 +312,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), dt1.value(), df2.field()); \
Func(tRes.ref().field(), dt1.value(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
\
......@@ -354,7 +354,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), dt2.value()); \
Func(tRes.ref().field(), df1.field(), dt2.value()); \
\
return tRes; \
} \
......@@ -389,7 +389,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> Func \
) \
); \
\
Func(tRes().field(), df1.field(), dt2.value()); \
Func(tRes.ref().field(), df1.field(), dt2.value()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -438,7 +438,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field(), df2.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
return tRes; \
} \
......@@ -462,7 +462,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field(), df2.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
\
......@@ -488,7 +488,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field(), df2.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......@@ -517,7 +517,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field(), df2.field()); \
Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
\
reuseTmpTmpDimensionedField<ReturnType, Type1, Type1, Type2, GeoMesh>:: \
clear(tdf1, tdf2); \
......@@ -552,7 +552,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), dt1.value(), df2.field()); \
Foam::OpFunc(tRes.ref().field(), dt1.value(), df2.field()); \
\
return tRes; \
} \
......@@ -587,7 +587,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), dt1.value(), tdf2().field()); \
Foam::OpFunc(tRes.ref().field(), dt1.value(), tdf2().field()); \
\
reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::clear(tdf2); \
\
......@@ -629,7 +629,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), df1.field(), dt2.value()); \
Foam::OpFunc(tRes.ref().field(), df1.field(), dt2.value()); \
\
return tRes; \
} \
......@@ -664,7 +664,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
) \
); \
\
Foam::OpFunc(tRes().field(), tdf1().field(), dt2.value()); \
Foam::OpFunc(tRes.ref().field(), tdf1().field(), dt2.value()); \
\
reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::clear(tdf1); \
\
......
......@@ -112,10 +112,7 @@ public:
static void clear(const tmp<DimensionedField<TypeR, GeoMesh>>& tdf1)
{
if (tdf1.isTmp())
{
tdf1.ptr();
}
tdf1.clear();
}
};
......@@ -212,10 +209,7 @@ public:
)
{
tdf1.clear();
if (tdf2.isTmp())
{
tdf2.ptr();
}
tdf2.clear();
}
};
......@@ -267,10 +261,7 @@ public:
const tmp<DimensionedField<Type2, GeoMesh>>& tdf2
)
{
if (tdf1.isTmp())
{
tdf1.ptr();
}
tdf1.clear();
tdf2.clear();
}
};
......@@ -331,16 +322,8 @@ public:
const tmp<DimensionedField<TypeR, GeoMesh>>& tdf2
)
{
if (tdf1.isTmp())
{
tdf1.ptr();
tdf2.clear();
}
else if (tdf2.isTmp())
{
tdf1.clear();
tdf2.ptr();
}
tdf1.clear();
tdf2.clear();
}
};
......
......@@ -57,7 +57,7 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
)
);
stabilise(tRes().field(), dsf.field(), ds.value());
stabilise(tRes.ref().field(), dsf.field(), ds.value());
return tRes;
}
......@@ -80,7 +80,7 @@ tmp<DimensionedField<scalar, GeoMesh>> stabilise
dsf.dimensions() + ds.dimensions()
);
stabilise(tRes().field(), dsf.field(), ds.value());
stabilise(tRes.ref().field(), dsf.field(), ds.value());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf);
......@@ -126,7 +126,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
)
);
pow(tPow().field(), dsf1.field(), dsf2.field());
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
return tPow;
}
......@@ -153,7 +153,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
)
);
pow(tPow().field(), dsf1.field(), dsf2.field());
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf1);
......@@ -182,7 +182,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
)
);
pow(tPow().field(), dsf1.field(), dsf2.field());
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
reuseTmpDimensionedField<scalar, scalar, GeoMesh>::clear(tdsf2);
......@@ -213,7 +213,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
)
);
pow(tPow().field(), dsf1.field(), dsf2.field());
pow(tPow.ref().field(), dsf1.field(), dsf2.field());
reuseTmpTmpDimensionedField<scalar, scalar, scalar, scalar, GeoMesh>::clear
(
......@@ -247,7 +247,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
)
);
pow(tPow().field(), dsf.field(), ds.value());
pow(tPow.ref().field(), dsf.field(), ds.value());
return tPow;
}
......@@ -269,7 +269,7 @@ tmp<DimensionedField<scalar, GeoMesh>> pow
pow(dsf.dimensions(), ds)
);
pow(tPow().field(), dsf.field(), ds.value());