objectRegistry: Improvements to caching of temporary objects

Cached temporary objects are now registered from the moment of
construction. This means it is possible to use them before they go out
of scope. Non-cached temporaries are not registered, as before.

The check for the existence of requested cached objects is now done
after function object evaluation. This means that caching can be done on
fields generated by the function objects themselves without generating
warning messages.

The above, however, means that if an object isn't successfully cached
and it's lookup in a function fails, then the warning will not be
generated before the lookup raises an error. This could make diagnosing
the reason for such a failure more difficult. To remedy this the content
of the warning (i.e., the list of objects that are available for
caching) has been added to the lookup error message if the looked up
name is on the caching list. The same level of logged information is
therefore retained in the event of caching and lookup failures.
This commit is contained in:
Will Bainbridge
2019-09-30 11:20:16 +01:00
parent 54f379f668
commit 1bbac95448
7 changed files with 59 additions and 31 deletions

View File

@ -808,13 +808,13 @@ bool Foam::Time::run() const
{ {
if (!running && timeIndex_ != startTimeIndex_) if (!running && timeIndex_ != startTimeIndex_)
{ {
functionObjects_.execute();
functionObjects_.end();
if (cacheTemporaryObjects_) if (cacheTemporaryObjects_)
{ {
cacheTemporaryObjects_ = checkCacheTemporaryObjects(); cacheTemporaryObjects_ = checkCacheTemporaryObjects();
} }
functionObjects_.execute();
functionObjects_.end();
} }
} }
@ -830,12 +830,12 @@ bool Foam::Time::run() const
} }
else else
{ {
functionObjects_.execute();
if (cacheTemporaryObjects_) if (cacheTemporaryObjects_)
{ {
cacheTemporaryObjects_ = checkCacheTemporaryObjects(); cacheTemporaryObjects_ = checkCacheTemporaryObjects();
} }
functionObjects_.execute();
} }
} }

View File

@ -196,7 +196,19 @@ const Type& Foam::objectRegistry::lookupObject(const word& name) const
<< " " << name << " from objectRegistry " << this->name() << " " << name << " from objectRegistry " << this->name()
<< " failed\n available objects of type " << Type::typeName << " failed\n available objects of type " << Type::typeName
<< " are" << nl << " are" << nl
<< names<Type>() << names<Type>();
if (cacheTemporaryObject(name))
{
FatalErrorInFunction
<< nl
<< " request for " << name << " from objectRegistry "
<< this->name() << " to be cached failed" << nl
<< " available temporary objects are" << nl
<< temporaryObjects_;
}
FatalErrorInFunction
<< abort(FatalError); << abort(FatalError);
} }

View File

@ -283,7 +283,7 @@ DimensionedField<Type, GeoMesh>::New
mesh, mesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false mesh.cacheTemporaryObject(name)
), ),
mesh, mesh,
ds, ds,
@ -313,7 +313,7 @@ DimensionedField<Type, GeoMesh>::New
mesh, mesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false mesh.cacheTemporaryObject(name)
), ),
mesh, mesh,
dt, dt,
@ -343,7 +343,7 @@ DimensionedField<Type, GeoMesh>::New
df.db(), df.db(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false df.db().cacheTemporaryObject(newName)
), ),
df df
) )
@ -371,7 +371,7 @@ DimensionedField<Type, GeoMesh>::New
tdf().db(), tdf().db(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false tdf().db().cacheTemporaryObject(newName)
), ),
tdf tdf
) )

View File

@ -763,7 +763,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
diField.mesh().thisDb(), diField.mesh().thisDb(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false diField.mesh().thisDb().cacheTemporaryObject(name)
), ),
diField, diField,
ptfl ptfl
@ -793,7 +793,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
mesh.thisDb(), mesh.thisDb(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false mesh.thisDb().cacheTemporaryObject(name)
), ),
mesh, mesh,
ds, ds,
@ -824,7 +824,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
mesh.thisDb(), mesh.thisDb(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false mesh.thisDb().cacheTemporaryObject(name)
), ),
mesh, mesh,
dt, dt,
@ -857,7 +857,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
mesh.thisDb(), mesh.thisDb(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false mesh.thisDb().cacheTemporaryObject(name)
), ),
mesh, mesh,
dt, dt,
@ -888,7 +888,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
tgf().db(), tgf().db(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false tgf().db().cacheTemporaryObject(newName)
), ),
tgf tgf
) )
@ -918,7 +918,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
tgf().db(), tgf().db(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false tgf().db().cacheTemporaryObject(newName)
), ),
tgf, tgf,
patchFieldTypes, patchFieldTypes,

View File

@ -142,7 +142,11 @@ public:
// of mixture [W/m/K] // of mixture [W/m/K]
virtual tmp<volScalarField> kappaEff() const virtual tmp<volScalarField> kappaEff() const
{ {
return kappa(); return volScalarField::New
(
"kappaEff",
this->transport_.kappa()
);
} }
//- Effective thermal turbulent diffusivity for temperature //- Effective thermal turbulent diffusivity for temperature
@ -155,7 +159,11 @@ public:
//- Effective thermal turbulent diffusivity of mixture [kg/m/s] //- Effective thermal turbulent diffusivity of mixture [kg/m/s]
virtual tmp<volScalarField> alphaEff() const virtual tmp<volScalarField> alphaEff() const
{ {
return this->transport_.alphahe(); return volScalarField::New
(
"alphaEff",
this->transport_.alphahe()
);
} }
//- Effective thermal turbulent diffusivity of mixture //- Effective thermal turbulent diffusivity of mixture

View File

@ -172,7 +172,7 @@ bool Foam::functionObjects::scalarTransport::execute()
mesh_.lookupObject<surfaceScalarField>(phiName_); mesh_.lookupObject<surfaceScalarField>(phiName_);
// Calculate the diffusivity // Calculate the diffusivity
volScalarField D(this->D(phi)); volScalarField D("D" + s_.name(), this->D(phi));
word divScheme("div(phi," + schemesField_ + ")"); word divScheme("div(phi," + schemesField_ + ")");
word laplacianScheme("laplacian(" + D.name() + "," + schemesField_ + ")"); word laplacianScheme("laplacian(" + D.name() + "," + schemesField_ + ")");

View File

@ -633,9 +633,11 @@ template<class BasicThermo, class MixtureType>
Foam::tmp<Foam::volScalarField> Foam::tmp<Foam::volScalarField>
Foam::heThermo<BasicThermo, MixtureType>::kappa() const Foam::heThermo<BasicThermo, MixtureType>::kappa() const
{ {
tmp<Foam::volScalarField> kappa(Cp()*this->alpha_); return volScalarField::New
kappa.ref().rename("kappa"); (
return kappa; "kappa",
Cp()*this->alpha_
);
} }
@ -659,9 +661,11 @@ template<class BasicThermo, class MixtureType>
Foam::tmp<Foam::volScalarField> Foam::tmp<Foam::volScalarField>
Foam::heThermo<BasicThermo, MixtureType>::alphahe() const Foam::heThermo<BasicThermo, MixtureType>::alphahe() const
{ {
tmp<Foam::volScalarField> alphaEff(this->CpByCpv()*this->alpha_); return volScalarField::New
alphaEff.ref().rename("alphahe"); (
return alphaEff; "alphahe",
this->CpByCpv()*this->alpha_
);
} }
@ -687,9 +691,11 @@ Foam::heThermo<BasicThermo, MixtureType>::kappaEff
const volScalarField& alphat const volScalarField& alphat
) const ) const
{ {
tmp<Foam::volScalarField> kappaEff(Cp()*(this->alpha_ + alphat)); return volScalarField::New
kappaEff.ref().rename("kappaEff"); (
return kappaEff; "kappaEff",
Cp()*(this->alpha_ + alphat)
);
} }
@ -719,9 +725,11 @@ Foam::heThermo<BasicThermo, MixtureType>::alphaEff
const volScalarField& alphat const volScalarField& alphat
) const ) const
{ {
tmp<Foam::volScalarField> alphaEff(this->CpByCpv()*(this->alpha_ + alphat)); return volScalarField::New
alphaEff.ref().rename("alphaEff"); (
return alphaEff; "alphaEff",
this->CpByCpv()*(this->alpha_ + alphat)
);
} }