STYLE: more explicit use of REGISTER when storing fields

ENH: add phaseScopedName convenience method

- unites IOobject::scopedName + phasePropertyName
This commit is contained in:
Mark Olesen
2023-05-09 13:34:24 +02:00
parent 16591012e9
commit 8e32db2b5f
41 changed files with 211 additions and 177 deletions

View File

@ -899,7 +899,8 @@ int main(int argc, char *argv[])
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
args.getOrDefault<fileName>("decomposeParDict", "") args.getOrDefault<fileName>("decomposeParDict", "")
) )

View File

@ -171,7 +171,8 @@ int main(int argc, char *argv[])
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
args.getOrDefault<fileName>("decomposeParDict", "") args.getOrDefault<fileName>("decomposeParDict", "")
) )

View File

@ -537,7 +537,9 @@ Foam::expressions::fvExprDriver::regionMesh
regionName, regionName,
mesh.time().constant(), mesh.time().constant(),
mesh.time(), mesh.time(),
IOobject::MUST_READ IOobject::MUST_READ,
IOobject::NO_WRITE,
IOobject::REGISTER
) )
); );

View File

@ -151,30 +151,28 @@ Foam::LimitedScheme<Type, Limiter, LimitFunc>::limiter
if (this->mesh().cache("limiter")) if (this->mesh().cache("limiter"))
{ {
if (!mesh.foundObject<surfaceScalarField>(limiterFieldName)) auto* fldptr = mesh.getObjectPtr<surfaceScalarField>(limiterFieldName);
if (!fldptr)
{ {
surfaceScalarField* limiterField fldptr = new surfaceScalarField
( (
new surfaceScalarField IOobject
( (
IOobject limiterFieldName,
( mesh.time().timeName(),
limiterFieldName,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh, mesh,
dimless IOobject::NO_READ,
) IOobject::NO_WRITE,
IOobject::REGISTER
),
mesh,
dimless
); );
mesh.objectRegistry::store(limiterField); mesh.objectRegistry::store(fldptr);
} }
auto& limiterField = *fldptr;
surfaceScalarField& limiterField =
mesh.lookupObjectRef<surfaceScalarField>(limiterFieldName);
calcLimiter(phi, limiterField); calcLimiter(phi, limiterField);

View File

@ -78,17 +78,11 @@ bool Foam::functionObjects::CourantNo::calc()
) )
); );
if (foundObject<volScalarField>(resultName_, false)) auto* resultPtr = getObjectPtr<volScalarField>(resultName_);
{
volScalarField& Co =
lookupObjectRef<volScalarField>(resultName_);
Co.ref() = Coi(); if (!resultPtr)
Co.correctBoundaryConditions();
}
else
{ {
auto tCo = tmp<volScalarField>::New resultPtr = new volScalarField
( (
IOobject IOobject
( (
@ -96,16 +90,19 @@ bool Foam::functionObjects::CourantNo::calc()
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero), dimensionedScalar(dimless, Zero),
fvPatchFieldBase::zeroGradientType() fvPatchFieldBase::zeroGradientType()
); );
tCo.ref().ref() = Coi(); mesh_.objectRegistry::store(resultPtr);
tCo.ref().correctBoundaryConditions();
mesh_.objectRegistry::store(tCo.ptr());
} }
auto& Co = *resultPtr;
Co.internalFieldRef() = Coi;
Co.correctBoundaryConditions();
return true; return true;
} }

View File

@ -80,7 +80,8 @@ Foam::functionObjects::DESModelRegions::DESModelRegions
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero) dimensionedScalar(dimless, Zero)

View File

@ -92,7 +92,8 @@ Foam::functionObjects::blendingFactor::blendingFactor
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero), dimensionedScalar(dimless, Zero),

View File

@ -66,7 +66,8 @@ int Foam::functionObjects::ddt2::apply(const word& inputName, int& state)
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dims, Zero) dimensionedScalar(dims, Zero)

View File

@ -143,7 +143,8 @@ void Foam::functionObjects::fieldAverage::restoreWindowFieldsType
obr().time().timeName(obr().time().startTime().value()), obr().time().timeName(obr().time().startTime().value()),
obr(), obr(),
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
); );
if (io.typeHeaderOk<Type>(true)) if (io.typeHeaderOk<Type>(true))

View File

@ -82,7 +82,8 @@ Foam::functionObjects::heatTransferCoeff::heatTransferCoeff
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimPower/dimArea/dimTemperature, Zero) dimensionedScalar(dimPower/dimArea/dimTemperature, Zero)

View File

@ -138,7 +138,8 @@ Foam::functionObjects::multiphaseInterHtcModel::multiphaseInterHtcModel
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimPower/dimArea/dimTemperature, Zero) dimensionedScalar(dimPower/dimArea/dimTemperature, Zero)

View File

@ -147,7 +147,8 @@ Foam::functionObjects::reactingEulerHtcModel::reactingEulerHtcModel
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimPower/dimArea/dimTemperature, Zero) dimensionedScalar(dimPower/dimArea/dimTemperature, Zero)

View File

@ -173,7 +173,8 @@ Foam::functionObjects::momentumError::momentumError
subMesh.time().timeName(), subMesh.time().timeName(),
subMesh, subMesh,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
subMesh, subMesh,
dimensionedVector(momDims) dimensionedVector(momDims)
@ -192,7 +193,8 @@ Foam::functionObjects::momentumError::momentumError
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedVector(momDims) dimensionedVector(momDims)

View File

@ -332,7 +332,8 @@ bool Foam::functionObjects::pressure::calc()
p.mesh().time().timeName(), p.mesh().time().timeName(),
p.mesh(), p.mesh(),
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
coeff(calcPressure(p, rhoScale(p))) coeff(calcPressure(p, rhoScale(p)))
); );

View File

@ -65,10 +65,11 @@ Foam::functionObjects::processorField::processorField
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Pstream::myProcNo()) dimensionedScalar(dimless, UPstream::myProcNo())
) )
); );
@ -92,7 +93,7 @@ bool Foam::functionObjects::processorField::execute()
mesh_.lookupObjectRef<volScalarField>("processorID"); mesh_.lookupObjectRef<volScalarField>("processorID");
procField == procField ==
dimensionedScalar("proci", dimless, Pstream::myProcNo()); dimensionedScalar("proci", dimless, UPstream::myProcNo());
return true; return true;
} }
@ -123,10 +124,11 @@ void Foam::functionObjects::processorField::updateMesh(const mapPolyMesh& mpm)
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Pstream::myProcNo()) dimensionedScalar(dimless, UPstream::myProcNo())
) )
); );

View File

@ -541,7 +541,8 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero) dimensionedScalar(dimless, Zero)
@ -565,7 +566,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false)) if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
{ {
volScalarField* vfPtr = new volScalarField(fieldHeader, mesh_); auto* vfPtr = new volScalarField(fieldHeader, mesh_);
mesh_.objectRegistry::store(vfPtr); mesh_.objectRegistry::store(vfPtr);
} }
else else
@ -595,7 +596,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false)) if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
{ {
volScalarField* vfPtr = new volScalarField(fieldHeader, mesh_); auto* vfPtr = new volScalarField(fieldHeader, mesh_);
mesh_.objectRegistry::store(vfPtr); mesh_.objectRegistry::store(vfPtr);
} }
else else
@ -623,7 +624,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false)) if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
{ {
volScalarField* vfPtr(new volScalarField(fieldHeader, mesh_)); auto* vfPtr = new volScalarField(fieldHeader, mesh_);
mesh_.objectRegistry::store(vfPtr); mesh_.objectRegistry::store(vfPtr);
} }
else else

View File

@ -404,10 +404,11 @@ Foam::tmp<Foam::pointScalarField> Foam::functionObjects::streamFunction::calc
bool Foam::functionObjects::streamFunction::calc() bool Foam::functionObjects::streamFunction::calc()
{ {
if (foundObject<surfaceScalarField>(fieldName_)) const auto* phiPtr = findObject<surfaceScalarField>(fieldName_);
if (phiPtr)
{ {
const surfaceScalarField& phi = const surfaceScalarField& phi = *phiPtr;
mesh_.lookupObject<surfaceScalarField>(fieldName_);
return store(resultName_, calc(phi)); return store(resultName_, calc(phi));
} }

View File

@ -53,7 +53,7 @@ Foam::functionObjects::surfaceDistance::surfaceDistance
{ {
read(dict); read(dict);
volScalarField* procFieldPtr volScalarField* distPtr
( (
new volScalarField new volScalarField
( (
@ -63,14 +63,15 @@ Foam::functionObjects::surfaceDistance::surfaceDistance
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimLength, Zero) dimensionedScalar(dimLength, Zero)
) )
); );
mesh_.objectRegistry::store(procFieldPtr); mesh_.objectRegistry::store(distPtr);
} }

View File

@ -119,7 +119,8 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimMass/pow3(dimTime), Zero) dimensionedScalar(dimMass/pow3(dimTime), Zero)

View File

@ -106,7 +106,8 @@ Foam::functionObjects::wallShearStress::wallShearStress
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedVector(sqr(dimLength)/sqr(dimTime), Zero) dimensionedVector(sqr(dimLength)/sqr(dimTime), Zero)

View File

@ -87,7 +87,8 @@ Foam::functionObjects::yPlus::yPlus
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero) dimensionedScalar(dimless, Zero)

View File

@ -92,7 +92,8 @@ int Foam::functionObjects::zeroGradient::apply
time_.timeName(), time_.timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensioned<Type>(input.dimensions(), Zero), dimensioned<Type>(input.dimensions(), Zero),

View File

@ -191,7 +191,8 @@ Foam::functionObjects::hydrostaticPressure::hydrostaticPressure
runTime.timeName(), runTime.timeName(),
mesh_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::AUTO_WRITE // To enable restart IOobject::AUTO_WRITE, // To enable restart
IOobject::REGISTER
), ),
mesh_ mesh_
); );

View File

@ -57,7 +57,8 @@ Foam::functionObjects::electricPotential::operandField()
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_ mesh_
); );

View File

@ -67,7 +67,8 @@ Foam::volScalarField& Foam::functionObjects::energyTransport::transportedField()
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE,
IOobject::REGISTER
), ),
mesh_ mesh_
); );

View File

@ -69,7 +69,8 @@ Foam::volScalarField& Foam::functionObjects::scalarTransport::transportedField()
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_ mesh_
); );

View File

@ -91,7 +91,9 @@ void Foam::functionObjects::solverInfo::createResidualField
IOobject::scopedName("initialResidual", fieldName) IOobject::scopedName("initialResidual", fieldName)
); );
if (!mesh_.foundObject<IOField<scalar>>(residualName)) auto* fieldPtr = mesh_.getObjectPtr<IOField<scalar>>(residualName);
if (!fieldPtr)
{ {
auto* fieldPtr = auto* fieldPtr =
new IOField<scalar> new IOField<scalar>

View File

@ -64,11 +64,11 @@ void Foam::HeatTransferCoeff<CloudType>::postEvolve
const auto& tc = const auto& tc =
static_cast<const ThermoCloud<KinematicCloud<Cloud<parcelType>>>&>(c); static_cast<const ThermoCloud<KinematicCloud<Cloud<parcelType>>>&>(c);
auto* htcPtr = c.template getObjectPtr<IOField<scalar>>("htc"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("htc");
if (!htcPtr) if (!resultPtr)
{ {
htcPtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -81,9 +81,9 @@ void Foam::HeatTransferCoeff<CloudType>::postEvolve
) )
); );
htcPtr->store(); resultPtr->store();
} }
auto& htc = *htcPtr; auto& htc = *resultPtr;
htc.resize(c.size()); htc.resize(c.size());

View File

@ -61,11 +61,11 @@ void Foam::KinematicReynoldsNumber<CloudType>::postEvolve
{ {
auto& c = this->owner(); auto& c = this->owner();
auto* RePtr = c.template getObjectPtr<IOField<scalar>>("Re"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("Re");
if (!RePtr) if (!resultPtr)
{ {
RePtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -78,9 +78,9 @@ void Foam::KinematicReynoldsNumber<CloudType>::postEvolve
) )
); );
RePtr->store(); resultPtr->store();
} }
auto& Re = *RePtr; auto& Re = *resultPtr;
Re.resize(c.size()); Re.resize(c.size());

View File

@ -64,11 +64,11 @@ void Foam::NusseltNumber<CloudType>::postEvolve
const auto& tc = const auto& tc =
static_cast<const ThermoCloud<KinematicCloud<Cloud<parcelType>>>&>(c); static_cast<const ThermoCloud<KinematicCloud<Cloud<parcelType>>>&>(c);
auto* NuPtr = c.template getObjectPtr<IOField<scalar>>("Nu"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("Nu");
if (!NuPtr) if (!resultPtr)
{ {
NuPtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -81,9 +81,9 @@ void Foam::NusseltNumber<CloudType>::postEvolve
) )
); );
NuPtr->store(); resultPtr->store();
} }
auto& Nu = *NuPtr; auto& Nu = *resultPtr;
Nu.resize(c.size()); Nu.resize(c.size());

View File

@ -64,11 +64,11 @@ void Foam::ParticleDose<CloudType>::postEvolve
{ {
auto& c = this->owner(); auto& c = this->owner();
auto* DPtr = c.template getObjectPtr<IOField<scalar>>("D"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("D");
if (!DPtr) if (!resultPtr)
{ {
DPtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -81,9 +81,9 @@ void Foam::ParticleDose<CloudType>::postEvolve
) )
); );
DPtr->store(); resultPtr->store();
} }
auto& D = *DPtr; auto& D = *resultPtr;
D.resize(c.size(), Zero); D.resize(c.size(), Zero);

View File

@ -62,11 +62,11 @@ void Foam::ThermoReynoldsNumber<CloudType>::postEvolve
{ {
auto& c = this->owner(); auto& c = this->owner();
auto* RePtr = c.template getObjectPtr<IOField<scalar>>("Re"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("Re");
if (!RePtr) if (!resultPtr)
{ {
RePtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -79,9 +79,9 @@ void Foam::ThermoReynoldsNumber<CloudType>::postEvolve
) )
); );
RePtr->store(); resultPtr->store();
} }
auto& Re = *RePtr; auto& Re = *resultPtr;
Re.resize(c.size()); Re.resize(c.size());

View File

@ -62,11 +62,11 @@ void Foam::WeberNumberReacting<CloudType>::postEvolve
{ {
const auto& c = this->owner(); const auto& c = this->owner();
auto* WePtr = c.template getObjectPtr<IOField<scalar>>("We"); auto* resultPtr = c.template getObjectPtr<IOField<scalar>>("We");
if (!WePtr) if (!resultPtr)
{ {
WePtr = new IOField<scalar> resultPtr = new IOField<scalar>
( (
IOobject IOobject
( (
@ -79,9 +79,9 @@ void Foam::WeberNumberReacting<CloudType>::postEvolve
) )
); );
WePtr->store(); resultPtr->store();
} }
auto& We = *WePtr; auto& We = *resultPtr;
We.resize(c.size()); We.resize(c.size());

View File

@ -67,26 +67,28 @@ Foam::InterfaceForce<CloudType>::~InterfaceForce()
template<class CloudType> template<class CloudType>
void Foam::InterfaceForce<CloudType>::cacheFields(const bool store) void Foam::InterfaceForce<CloudType>::cacheFields(const bool store)
{ {
static word fName("gradAlpha"); static word resultName("gradAlpha");
bool fieldExists = volVectorField* resultPtr =
this->mesh().template foundObject<volVectorField>(fName); this->mesh().template getObjectPtr<volVectorField>(resultName);
if (store) if (store)
{ {
if (!fieldExists) if (!resultPtr)
{ {
const volScalarField& alpha = this->mesh().template const volScalarField& alpha = this->mesh().template
lookupObject<volScalarField>(alphaName_); lookupObject<volScalarField>(alphaName_);
volVectorField* gradInterForcePtr = resultPtr = new volVectorField
new volVectorField(fName, fvc::grad(alpha*(1-alpha))); (
resultName,
fvc::grad(alpha*(1-alpha))
);
gradInterForcePtr->store(); resultPtr->store();
} }
const volVectorField& gradInterForce = this->mesh().template const volVectorField& gradInterForce = *resultPtr;
lookupObject<volVectorField>(fName);
gradInterForceInterpPtr_.reset gradInterForceInterpPtr_.reset
( (
@ -101,12 +103,9 @@ void Foam::InterfaceForce<CloudType>::cacheFields(const bool store)
{ {
gradInterForceInterpPtr_.clear(); gradInterForceInterpPtr_.clear();
if (fieldExists) if (resultPtr)
{ {
volVectorField& gradInterForce = resultPtr->checkOut();
this->mesh().template lookupObjectRef<volVectorField>(fName);
gradInterForce.checkOut();
} }
} }
} }

View File

@ -84,25 +84,24 @@ Foam::LiftForce<CloudType>::~LiftForce()
template<class CloudType> template<class CloudType>
void Foam::LiftForce<CloudType>::cacheFields(const bool store) void Foam::LiftForce<CloudType>::cacheFields(const bool store)
{ {
static word fName("curlUcDt"); static word resultName("curlUcDt");
bool fieldExists = this->mesh().template foundObject<volVectorField>(fName); volVectorField* resultPtr =
this->mesh().template getObjectPtr<volVectorField>(resultName);
if (store) if (store)
{ {
if (!fieldExists) if (!resultPtr)
{ {
const volVectorField& Uc = this->mesh().template const volVectorField& Uc = this->mesh().template
lookupObject<volVectorField>(UName_); lookupObject<volVectorField>(UName_);
volVectorField* curlUcPtr = resultPtr = new volVectorField(resultName, fvc::curl(Uc));
new volVectorField(fName, fvc::curl(Uc));
curlUcPtr->store(); resultPtr->store();
} }
const volVectorField& curlUc = this->mesh().template const volVectorField& curlUc = *resultPtr;
lookupObject<volVectorField>(fName);
curlUcInterpPtr_.reset curlUcInterpPtr_.reset
( (
@ -117,12 +116,9 @@ void Foam::LiftForce<CloudType>::cacheFields(const bool store)
{ {
curlUcInterpPtr_.clear(); curlUcInterpPtr_.clear();
if (fieldExists) if (resultPtr)
{ {
volVectorField& curlUc = resultPtr->checkOut();
this->mesh().template lookupObjectRef<volVectorField>(fName);
curlUc.checkOut();
} }
} }
} }

View File

@ -71,28 +71,27 @@ Foam::PressureGradientForce<CloudType>::~PressureGradientForce()
template<class CloudType> template<class CloudType>
void Foam::PressureGradientForce<CloudType>::cacheFields(const bool store) void Foam::PressureGradientForce<CloudType>::cacheFields(const bool store)
{ {
static word fName("DUcDt"); static word resultName("DUcDt");
bool fieldExists = this->mesh().template foundObject<volVectorField>(fName); volVectorField* resultPtr =
this->mesh().template getObjectPtr<volVectorField>(resultName);
if (store) if (store)
{ {
if (!fieldExists) if (!resultPtr)
{ {
const volVectorField& Uc = this->mesh().template const volVectorField& Uc = this->mesh().template
lookupObject<volVectorField>(UName_); lookupObject<volVectorField>(UName_);
volVectorField* DUcDtPtr = new volVectorField resultPtr = new volVectorField
( (
fName, resultName,
fvc::ddt(Uc) + (Uc & fvc::grad(Uc)) fvc::ddt(Uc) + (Uc & fvc::grad(Uc))
); );
DUcDtPtr->store(); resultPtr->store();
} }
const volVectorField& DUcDt = *resultPtr;
const volVectorField& DUcDt = this->mesh().template
lookupObject<volVectorField>(fName);
DUcDtInterpPtr_.reset DUcDtInterpPtr_.reset
( (
@ -107,12 +106,9 @@ void Foam::PressureGradientForce<CloudType>::cacheFields(const bool store)
{ {
DUcDtInterpPtr_.clear(); DUcDtInterpPtr_.clear();
if (fieldExists) if (resultPtr)
{ {
volVectorField& DUcDt = resultPtr->checkOut();
this->mesh().template lookupObjectRef<volVectorField>(fName);
DUcDt.checkOut();
} }
} }
} }

View File

@ -186,15 +186,15 @@ Foam::lumpedPointDisplacementPointPatchVectorField::movement() const
lumpedPointIOMovement* ptr = lumpedPointIOMovement* ptr =
lumpedPointIOMovement::getMovementObject(obr); lumpedPointIOMovement::getMovementObject(obr);
if (ptr) if (!ptr)
{ {
return *ptr; // Already exists // Create and register with this patch as the owner
ptr = lumpedPointIOMovement::New(obr, this->patch().index()).ptr();
objectRegistry::store(ptr);
} }
// Create and register with this patch as the owner return *ptr;
ptr = lumpedPointIOMovement::New(obr, this->patch().index()).ptr();
return objectRegistry::store(ptr);
} }

View File

@ -292,7 +292,7 @@ bool Foam::mappedPatchBase::constructIOField
if (tok.isCompound() && tok.compoundToken().type() == tag) if (tok.isCompound() && tok.compoundToken().type() == tag)
{ {
IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(name); IOField<Type>* fldPtr = obr.getObjectPtr<IOField<Type>>(name);
if (fldPtr) if (fldPtr)
{ {
fldPtr->transfer fldPtr->transfer
@ -305,14 +305,15 @@ bool Foam::mappedPatchBase::constructIOField
} }
else else
{ {
IOField<Type>* fldPtr = new IOField<Type> fldPtr = new IOField<Type>
( (
IOobject IOobject
( (
name, name,
obr, obr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
label(0) label(0)
); );
@ -342,7 +343,7 @@ void Foam::mappedPatchBase::storeField
const Field<Type>& values const Field<Type>& values
) )
{ {
IOField<Type>* fldPtr = obr.findObject<IOField<Type>>(fieldName); IOField<Type>* fldPtr = obr.getObjectPtr<IOField<Type>>(fieldName);
if (fldPtr) if (fldPtr)
{ {
*fldPtr = values; *fldPtr = values;
@ -356,7 +357,8 @@ void Foam::mappedPatchBase::storeField
fieldName, fieldName,
obr, obr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
values values
); );

View File

@ -47,19 +47,22 @@ namespace regionModels
void Foam::regionModels::regionModel::constructMeshObjects() void Foam::regionModels::regionModel::constructMeshObjects()
{ {
if (!time_.foundObject<fvMesh>(regionName_)) fvMesh* regionMeshPtr = time_.getObjectPtr<fvMesh>(regionName_);
if (!regionMeshPtr)
{ {
fvMesh* regionMeshPtr = regionMeshPtr = new fvMesh
new fvMesh (
IOobject
( (
IOobject regionName_,
( time_.timeName(),
regionName_, time_,
time_.timeName(), IOobject::MUST_READ,
time_, IOobject::NO_WRITE,
IOobject::MUST_READ IOobject::REGISTER
) )
); );
regionMeshPtr->objectRegistry::store(); regionMeshPtr->objectRegistry::store();
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef basicThermo_H #ifndef Foam_basicThermo_H
#define basicThermo_H #define Foam_basicThermo_H
#include "volFields.H" #include "volFields.H"
#include "typeInfo.H" #include "typeInfo.H"
@ -219,7 +219,7 @@ public:
static autoPtr<Thermo> New static autoPtr<Thermo> New
( (
const fvMesh&, const fvMesh&,
const word& phaseName=word::null const word& phaseName = word::null
); );
//- Generic New for each of the related thermodynamics packages //- Generic New for each of the related thermodynamics packages
@ -228,7 +228,7 @@ public:
( (
const fvMesh&, const fvMesh&,
const dictionary&, const dictionary&,
const word& phaseName=word::null const word& phaseName = word::null
); );
//- Generic New for each of the related thermodynamics packages //- Generic New for each of the related thermodynamics packages
@ -244,7 +244,7 @@ public:
static autoPtr<basicThermo> New static autoPtr<basicThermo> New
( (
const fvMesh&, const fvMesh&,
const word& phaseName=word::null const word& phaseName = word::null
); );
@ -254,22 +254,34 @@ public:
// Member Functions // Member Functions
//- The dictionary name ("thermophysicalProperties")
static const word dictName; static const word dictName;
static word phasePropertyName //- The phase property name as property.phase
( //- \sa IOobject::groupName
const word& name, static word phasePropertyName(const word& name, const word& phaseName)
const word& phaseName
)
{ {
return IOobject::groupName(name, phaseName); return IOobject::groupName(name, phaseName);
} }
//- The phase property name as property.phase (using phaseName_)
//- \sa IOobject::groupName
word phasePropertyName(const word& name) const word phasePropertyName(const word& name) const
{ {
return IOobject::groupName(name, phaseName_); return IOobject::groupName(name, phaseName_);
} }
//- The phase property name scoped as scope:property.phase
//- \sa IOobject::groupName and \sa IOobject::scopedName
word phaseScopedName(const std::string& scope, const word& name) const
{
return IOobject::groupName
(
IOobject::scopedName(scope, name),
phaseName_
);
}
static const basicThermo& lookupThermo(const fvPatchScalarField& pf); static const basicThermo& lookupThermo(const fvPatchScalarField& pf);
//- Print (filtered) table of thermo names, splits on \c " ,<>" //- Print (filtered) table of thermo names, splits on \c " ,<>"

View File

@ -58,9 +58,11 @@ namespace functionObjects
void Foam::functionObjects::BilgerMixtureFraction::calcBilgerMixtureFraction() void Foam::functionObjects::BilgerMixtureFraction::calcBilgerMixtureFraction()
{ {
if (!mesh_.foundObject<volScalarField>(resultName_, false)) auto* resultPtr = mesh_.getObjectPtr<volScalarField>(resultName_);
if (!resultPtr)
{ {
auto tCo = tmp<volScalarField>::New resultPtr = new volScalarField
( (
IOobject IOobject
( (
@ -68,15 +70,15 @@ void Foam::functionObjects::BilgerMixtureFraction::calcBilgerMixtureFraction()
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::REGISTER
), ),
mesh_, mesh_,
dimensionedScalar(dimless, Zero) dimensionedScalar(dimless, Zero)
); );
mesh_.objectRegistry::store(tCo.ptr()); mesh_.objectRegistry::store(resultPtr);
} }
auto& f_Bilger = *resultPtr;
auto& f_Bilger = mesh_.lookupObjectRef<volScalarField>(resultName_);
auto& Y = thermo_.Y(); auto& Y = thermo_.Y();