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:
@ -73,48 +73,33 @@ bool Foam::functionObjects::CourantNo::calc()
|
||||
const surfaceScalarField& phi =
|
||||
lookupObject<surfaceScalarField>(fieldName_);
|
||||
|
||||
tmp<volScalarField::Internal> Coi
|
||||
tmp<volScalarField> tCo
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
resultName_,
|
||||
mesh_.time().timeName(),
|
||||
mesh_
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimless, 0.0),
|
||||
zeroGradientFvPatchScalarField::typeName
|
||||
)
|
||||
);
|
||||
|
||||
tCo->ref() =
|
||||
byRho
|
||||
(
|
||||
(0.5*mesh_.time().deltaT())
|
||||
*fvc::surfaceSum(mag(phi))()()
|
||||
/mesh_.V()
|
||||
)
|
||||
);
|
||||
|
||||
if (foundObject<volScalarField>(resultName_))
|
||||
{
|
||||
volScalarField& Co = lookupObjectRef<volScalarField>(resultName_);
|
||||
|
||||
Co.ref() = Coi();
|
||||
Co.correctBoundaryConditions();
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp<volScalarField> tCo
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
resultName_,
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimless, 0.0),
|
||||
zeroGradientFvPatchScalarField::typeName
|
||||
)
|
||||
);
|
||||
tCo.ref().ref() = Coi();
|
||||
tCo.ref().correctBoundaryConditions();
|
||||
mesh_.objectRegistry::store(tCo.ptr());
|
||||
}
|
||||
|
||||
return true;
|
||||
tCo->correctBoundaryConditions();
|
||||
|
||||
return store(resultName_, tCo);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -51,25 +51,6 @@ Foam::functionObjects::processorField::processorField
|
||||
fvMeshFunctionObject(name, runTime, dict)
|
||||
{
|
||||
read(dict);
|
||||
|
||||
volScalarField* procFieldPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"processorID",
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimless, 0.0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(procFieldPtr);
|
||||
}
|
||||
|
||||
|
||||
@ -91,10 +72,24 @@ bool Foam::functionObjects::processorField::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::processorField::execute()
|
||||
{
|
||||
mesh_.lookupObjectRef<volScalarField>("processorID") ==
|
||||
dimensionedScalar("proci", dimless, Pstream::myProcNo());
|
||||
word name("processorID");
|
||||
|
||||
return true;
|
||||
tmp<volScalarField> tprocField
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
name,
|
||||
mesh_.time().timeName(),
|
||||
mesh_
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar(name, dimless, Pstream::myProcNo())
|
||||
)
|
||||
);
|
||||
|
||||
return store(name, tprocField);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -71,25 +71,6 @@ Foam::functionObjects::turbulenceIntensity::turbulenceIntensity
|
||||
logFiles(obr_, name),
|
||||
writeLocalObjects(obr_, log)
|
||||
{
|
||||
volScalarField* turbulenceIntensityPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"I",
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimless, 0.0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(turbulenceIntensityPtr);
|
||||
|
||||
read(dict);
|
||||
resetName(typeName);
|
||||
resetLocalObjectName("I");
|
||||
@ -115,9 +96,6 @@ bool Foam::functionObjects::turbulenceIntensity::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::turbulenceIntensity::execute()
|
||||
{
|
||||
volScalarField& turbulenceIntensity =
|
||||
mesh_.lookupObjectRef<volScalarField>("I");
|
||||
|
||||
if (mesh_.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
|
||||
{
|
||||
const turbulenceModel& turbModel = mesh_.lookupObject<turbulenceModel>
|
||||
@ -126,12 +104,19 @@ bool Foam::functionObjects::turbulenceIntensity::execute()
|
||||
);
|
||||
|
||||
volScalarField uPrime(sqrt((2.0/3.0)*turbModel.k()));
|
||||
turbulenceIntensity =
|
||||
uPrime
|
||||
/max
|
||||
|
||||
word name("I");
|
||||
|
||||
return
|
||||
store
|
||||
(
|
||||
max(uPrime, mag(turbModel.U())),
|
||||
dimensionedScalar("small", dimVelocity, small)
|
||||
name,
|
||||
uPrime
|
||||
/max
|
||||
(
|
||||
max(uPrime, mag(turbModel.U())),
|
||||
dimensionedScalar("small", dimVelocity, small)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -139,9 +124,9 @@ bool Foam::functionObjects::turbulenceIntensity::execute()
|
||||
FatalErrorInFunction
|
||||
<< "Unable to find turbulence model in the "
|
||||
<< "database" << exit(FatalError);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -58,15 +58,30 @@ void Foam::functionObjects::wallHeatFlux::writeFileHeader(const label i)
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::wallHeatFlux::calcHeatFlux
|
||||
Foam::tmp<Foam::volScalarField>
|
||||
Foam::functionObjects::wallHeatFlux::calcWallHeatFlux
|
||||
(
|
||||
const volScalarField& alpha,
|
||||
const volScalarField& he,
|
||||
volScalarField& wallHeatFlux
|
||||
const volScalarField& he
|
||||
)
|
||||
{
|
||||
tmp<volScalarField> twallHeatFlux
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimMass/pow3(dimTime), 0)
|
||||
)
|
||||
);
|
||||
|
||||
volScalarField::Boundary& wallHeatFluxBf =
|
||||
wallHeatFlux.boundaryFieldRef();
|
||||
twallHeatFlux.ref().boundaryFieldRef();
|
||||
|
||||
const volScalarField::Boundary& heBf =
|
||||
he.boundaryField();
|
||||
@ -97,6 +112,8 @@ void Foam::functionObjects::wallHeatFlux::calcHeatFlux
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return twallHeatFlux;
|
||||
}
|
||||
|
||||
|
||||
@ -114,25 +131,6 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux
|
||||
writeLocalObjects(obr_, log),
|
||||
patchSet_()
|
||||
{
|
||||
volScalarField* wallHeatFluxPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("0", dimMass/pow3(dimTime), 0)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(wallHeatFluxPtr);
|
||||
|
||||
read(dict);
|
||||
resetName(typeName);
|
||||
resetLocalObjectName(typeName);
|
||||
@ -205,7 +203,7 @@ bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::wallHeatFlux::execute()
|
||||
{
|
||||
volScalarField& wallHeatFlux = lookupObjectRef<volScalarField>(type());
|
||||
word name(type());
|
||||
|
||||
if
|
||||
(
|
||||
@ -220,20 +218,17 @@ bool Foam::functionObjects::wallHeatFlux::execute()
|
||||
(
|
||||
turbulenceModel::propertiesName
|
||||
);
|
||||
const volScalarField& alpha = turbModel.alphaEff();
|
||||
const volScalarField& he = turbModel.transport().he();
|
||||
|
||||
calcHeatFlux
|
||||
(
|
||||
turbModel.alphaEff(),
|
||||
turbModel.transport().he(),
|
||||
wallHeatFlux
|
||||
);
|
||||
return store(name, calcWallHeatFlux(alpha, he));
|
||||
}
|
||||
else if (foundObject<solidThermo>(solidThermo::dictName))
|
||||
{
|
||||
const solidThermo& thermo =
|
||||
lookupObject<solidThermo>(solidThermo::dictName);
|
||||
|
||||
calcHeatFlux(thermo.alpha(), thermo.he(), wallHeatFlux);
|
||||
return store(name, calcWallHeatFlux(thermo.alpha(), thermo.he()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -108,11 +108,10 @@ protected:
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
//- Calculate the heat-flux
|
||||
void calcHeatFlux
|
||||
tmp<volScalarField> calcWallHeatFlux
|
||||
(
|
||||
const volScalarField& alpha,
|
||||
const volScalarField& he,
|
||||
volScalarField& wallHeatFlux
|
||||
const volScalarField& he
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -63,15 +63,35 @@ void Foam::functionObjects::wallHeatTransferCoeff::writeFileHeader
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::wallHeatTransferCoeff::calcHeatTransferCoeff
|
||||
Foam::tmp<Foam::volScalarField>
|
||||
Foam::functionObjects::wallHeatTransferCoeff::calcHeatTransferCoeff
|
||||
(
|
||||
const volScalarField& nu,
|
||||
const volScalarField& nut,
|
||||
volScalarField& wallHeatTransferCoeff
|
||||
const volScalarField& nut
|
||||
)
|
||||
{
|
||||
tmp<volScalarField> twallHeatTransferCoeff
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar
|
||||
(
|
||||
"0",
|
||||
dimMass/pow3(dimTime)/(dimTemperature/dimLength),
|
||||
0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
volScalarField::Boundary& wallHeatTransferCoeffBf =
|
||||
wallHeatTransferCoeff.boundaryFieldRef();
|
||||
twallHeatTransferCoeff.ref().boundaryFieldRef();
|
||||
|
||||
const volScalarField::Boundary& nuBf = nu.boundaryField();
|
||||
const volScalarField::Boundary& nutBf = nut.boundaryField();
|
||||
@ -84,6 +104,8 @@ void Foam::functionObjects::wallHeatTransferCoeff::calcHeatTransferCoeff
|
||||
rho_*Cp_*(nuBf[patchi]/Prl_ + nutBf[patchi]/Prt_);
|
||||
}
|
||||
}
|
||||
|
||||
return twallHeatTransferCoeff;
|
||||
}
|
||||
|
||||
|
||||
@ -101,30 +123,6 @@ Foam::functionObjects::wallHeatTransferCoeff::wallHeatTransferCoeff
|
||||
writeLocalObjects(obr_, log),
|
||||
patchSet_()
|
||||
{
|
||||
volScalarField* wallHeatTransferCoeffPtr
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar
|
||||
(
|
||||
"0",
|
||||
dimMass/pow3(dimTime)/(dimTemperature/dimLength),
|
||||
0
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(wallHeatTransferCoeffPtr);
|
||||
|
||||
read(dict);
|
||||
resetName(typeName);
|
||||
resetLocalObjectName(typeName);
|
||||
@ -202,8 +200,7 @@ bool Foam::functionObjects::wallHeatTransferCoeff::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::wallHeatTransferCoeff::execute()
|
||||
{
|
||||
volScalarField& wallHeatTransferCoeff =
|
||||
lookupObjectRef<volScalarField>(type());
|
||||
word name(type());
|
||||
|
||||
if
|
||||
(
|
||||
@ -219,21 +216,19 @@ bool Foam::functionObjects::wallHeatTransferCoeff::execute()
|
||||
turbulenceModel::propertiesName
|
||||
);
|
||||
|
||||
calcHeatTransferCoeff
|
||||
(
|
||||
turbModel.nu(),
|
||||
turbModel.nut(),
|
||||
wallHeatTransferCoeff
|
||||
);
|
||||
const volScalarField& nu = turbModel.nu();
|
||||
const volScalarField& nut = turbModel.nut();
|
||||
|
||||
return store(name, calcHeatTransferCoeff(nu, nut));
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unable to find incompressible turbulence model in the "
|
||||
<< "database" << exit(FatalError);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -130,11 +130,10 @@ protected:
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
//- Calculate the heat transfer coefficient
|
||||
void calcHeatTransferCoeff
|
||||
tmp<volScalarField> calcHeatTransferCoeff
|
||||
(
|
||||
const volScalarField& nu,
|
||||
const volScalarField& nut,
|
||||
volScalarField& wallHeatTransferCoeff
|
||||
const volScalarField& nut
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -57,25 +57,42 @@ void Foam::functionObjects::wallShearStress::writeFileHeader(const label i)
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::wallShearStress::calcShearStress
|
||||
Foam::tmp<Foam::volVectorField>
|
||||
Foam::functionObjects::wallShearStress::calcShearStress
|
||||
(
|
||||
const volSymmTensorField& Reff,
|
||||
volVectorField& shearStress
|
||||
const volSymmTensorField& Reff
|
||||
)
|
||||
{
|
||||
shearStress.dimensions().reset(Reff.dimensions());
|
||||
tmp<volVectorField> twallShearStress
|
||||
(
|
||||
new volVectorField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_
|
||||
),
|
||||
mesh_,
|
||||
dimensionedVector("0", Reff.dimensions(), Zero)
|
||||
)
|
||||
);
|
||||
|
||||
volVectorField::Boundary& wallShearStressBf =
|
||||
twallShearStress.ref().boundaryFieldRef();
|
||||
|
||||
forAllConstIter(labelHashSet, patchSet_, iter)
|
||||
{
|
||||
label patchi = iter.key();
|
||||
|
||||
vectorField& ssp = shearStress.boundaryFieldRef()[patchi];
|
||||
const vectorField& Sfp = mesh_.Sf().boundaryField()[patchi];
|
||||
const scalarField& magSfp = mesh_.magSf().boundaryField()[patchi];
|
||||
const symmTensorField& Reffp = Reff.boundaryField()[patchi];
|
||||
|
||||
ssp = (-Sfp/magSfp) & Reffp;
|
||||
wallShearStressBf[patchi] = (-Sfp/magSfp) & Reffp;
|
||||
}
|
||||
|
||||
return twallShearStress;
|
||||
}
|
||||
|
||||
|
||||
@ -93,30 +110,6 @@ Foam::functionObjects::wallShearStress::wallShearStress
|
||||
writeLocalObjects(obr_, log),
|
||||
patchSet_()
|
||||
{
|
||||
volVectorField* wallShearStressPtr
|
||||
(
|
||||
new volVectorField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
type(),
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedVector
|
||||
(
|
||||
"0",
|
||||
sqr(dimLength)/sqr(dimTime),
|
||||
Zero
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
mesh_.objectRegistry::store(wallShearStressPtr);
|
||||
|
||||
read(dict);
|
||||
resetName(typeName);
|
||||
resetLocalObjectName(typeName);
|
||||
@ -192,9 +185,6 @@ bool Foam::functionObjects::wallShearStress::execute()
|
||||
typedef compressible::turbulenceModel cmpModel;
|
||||
typedef incompressible::turbulenceModel icoModel;
|
||||
|
||||
volVectorField& wallShearStress =
|
||||
mesh_.lookupObjectRef<volVectorField>(type());
|
||||
|
||||
tmp<volSymmTensorField> Reff;
|
||||
if (mesh_.foundObject<cmpModel>(turbulenceModel::propertiesName))
|
||||
{
|
||||
@ -217,9 +207,9 @@ bool Foam::functionObjects::wallShearStress::execute()
|
||||
<< "database" << exit(FatalError);
|
||||
}
|
||||
|
||||
calcShearStress(Reff(), wallShearStress);
|
||||
word name(type());
|
||||
|
||||
return true;
|
||||
return store(name, calcShearStress(Reff));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -117,10 +117,9 @@ protected:
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
//- Calculate the shear-stress
|
||||
void calcShearStress
|
||||
tmp<volVectorField> calcShearStress
|
||||
(
|
||||
const volSymmTensorField& Reff,
|
||||
volVectorField& shearStress
|
||||
const volSymmTensorField& Reff
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user