functionObjects: Generating and storing fields on demand rather than on construction

Resolves bug report https://bugs.openfoam.org/view.php?id=3019
This commit is contained in:
Will Bainbridge
2018-08-03 15:51:41 +01:00
parent f7100178e4
commit 8c152cbc38
11 changed files with 166 additions and 229 deletions

View File

@ -62,12 +62,28 @@ void Foam::functionObjects::yPlus::writeFileHeader(const label i)
}
void Foam::functionObjects::yPlus::calcYPlus
Foam::tmp<Foam::volScalarField> Foam::functionObjects::yPlus::calcYPlus
(
const turbulenceModel& turbModel,
volScalarField& yPlus
const turbulenceModel& turbModel
)
{
tmp<volScalarField> tyPlus
(
new volScalarField
(
IOobject
(
type(),
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar("0", dimless, 0.0)
)
);
volScalarField::Boundary& yPlusBf = tyPlus.ref().boundaryFieldRef();
volScalarField::Boundary d = nearWallDist(mesh_).y();
const volScalarField::Boundary nutBf =
@ -81,8 +97,6 @@ void Foam::functionObjects::yPlus::calcYPlus
const fvPatchList& patches = mesh_.boundary();
volScalarField::Boundary& yPlusBf = yPlus.boundaryFieldRef();
forAll(patches, patchi)
{
const fvPatch& patch = patches[patchi];
@ -108,6 +122,8 @@ void Foam::functionObjects::yPlus::calcYPlus
)/nuBf[patchi];
}
}
return tyPlus;
}
@ -124,25 +140,6 @@ Foam::functionObjects::yPlus::yPlus
logFiles(obr_, name),
writeLocalObjects(obr_, log)
{
volScalarField* yPlusPtr
(
new volScalarField
(
IOobject
(
type(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0)
)
);
mesh_.objectRegistry::store(yPlusPtr);
read(dict);
resetName(typeName);
resetLocalObjectName(typeName);
@ -168,9 +165,6 @@ bool Foam::functionObjects::yPlus::read(const dictionary& dict)
bool Foam::functionObjects::yPlus::execute()
{
volScalarField& yPlus =
mesh_.lookupObjectRef<volScalarField>(type());
if (mesh_.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
{
const turbulenceModel& model = mesh_.lookupObject<turbulenceModel>
@ -178,7 +172,9 @@ bool Foam::functionObjects::yPlus::execute()
turbulenceModel::propertiesName
);
calcYPlus(model, yPlus);
word name(type());
return store(name, calcYPlus(model));
}
else
{

View File

@ -95,10 +95,9 @@ class yPlus
virtual void writeFileHeader(const label i);
//- Calculate y+
void calcYPlus
tmp<volScalarField> calcYPlus
(
const turbulenceModel& turbModel,
volScalarField& yPlus
const turbulenceModel& turbModel
);
//- Disallow default bitwise copy construct