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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,7 +53,7 @@ Foam::functionObjects::surfaceDistance::surfaceDistance
{
read(dict);
volScalarField* procFieldPtr
volScalarField* distPtr
(
new volScalarField
(
@ -63,14 +63,15 @@ Foam::functionObjects::surfaceDistance::surfaceDistance
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
IOobject::NO_WRITE,
IOobject::REGISTER
),
mesh_,
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_,
IOobject::NO_READ,
IOobject::NO_WRITE
IOobject::NO_WRITE,
IOobject::REGISTER
),
mesh_,
dimensionedScalar(dimMass/pow3(dimTime), Zero)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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