ENH: electricPotential: replace operandField with getOrReadField

This commit is contained in:
Kutalmis Bercin
2023-01-11 11:48:39 +00:00
committed by Kutalmış Berçin
parent d92583f4b6
commit 7269cc1d3b
2 changed files with 20 additions and 14 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -44,16 +44,20 @@ namespace functionObjects
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::volScalarField& Foam::volScalarField& Foam::functionObjects::electricPotential::getOrReadField
Foam::functionObjects::electricPotential::operandField() (
const word& fieldName
) const
{ {
if (!foundObject<volScalarField>(fieldName_)) auto* ptr = mesh_.getObjectPtr<volScalarField>(fieldName);
if (!ptr)
{ {
auto tfldPtr = tmp<volScalarField>::New ptr = new volScalarField
( (
IOobject IOobject
( (
fieldName_, fieldName,
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
@ -62,10 +66,10 @@ Foam::functionObjects::electricPotential::operandField()
), ),
mesh_ mesh_
); );
store(fieldName_, tfldPtr); mesh_.objectRegistry::store(ptr);
} }
return lookupObjectRef<volScalarField>(fieldName_); return *ptr;
} }
@ -212,7 +216,7 @@ Foam::functionObjects::electricPotential::electricPotential
// Force creation of transported field so any BCs using it can // Force creation of transported field so any BCs using it can
// look it up // look it up
volScalarField& eV = operandField(); volScalarField& eV = getOrReadField(fieldName_);
eV.correctBoundaryConditions(); eV.correctBoundaryConditions();
} }
@ -316,7 +320,7 @@ bool Foam::functionObjects::electricPotential::execute()
tmp<volScalarField> tsigma = this->sigma(); tmp<volScalarField> tsigma = this->sigma();
const volScalarField& sigma = tsigma(); const volScalarField& sigma = tsigma();
volScalarField& eV = operandField(); volScalarField& eV = getOrReadField(fieldName_);
for (label i = 1; i <= nCorr_; ++i) for (label i = 1; i <= nCorr_; ++i)
{ {
@ -342,7 +346,7 @@ bool Foam::functionObjects::electricPotential::write()
<< tab << fieldName_ << tab << fieldName_
<< endl; << endl;
volScalarField& eV = operandField(); volScalarField& eV = getOrReadField(fieldName_);
if (writeDerivedFields_) if (writeDerivedFields_)
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -212,8 +212,10 @@ class electricPotential
// Private Member Functions // Private Member Functions
//- Return reference to the registered operand field //- Return requested field from the object registry
volScalarField& operandField(); //- or read+register the field to the object registry
volScalarField& getOrReadField(const word& fieldName) const;
//- Return the isotropic electrical conductivity field of the mixture //- Return the isotropic electrical conductivity field of the mixture
tmp<volScalarField> sigma() const; tmp<volScalarField> sigma() const;