Skip to content

Commit

Permalink
functionObjects: Generating and storing fields on demand rather than …
Browse files Browse the repository at this point in the history
…on construction

Resolves bug report https://bugs.openfoam.org/view.php?id=3019
  • Loading branch information
Will Bainbridge committed Aug 6, 2018
1 parent 1a0c91b commit 0f14683
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 229 deletions.
53 changes: 19 additions & 34 deletions src/functionObjects/field/CourantNo/CourantNo.C
Expand Up @@ -73,48 +73,33 @@ bool Foam::functionObjects::CourantNo::calc()
const surfaceScalarField& phi =
lookupObject<surfaceScalarField>(fieldName_);

tmp<volScalarField::Internal> Coi
tmp<volScalarField> tCo
(
byRho
new volScalarField
(
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
IOobject
(
resultName_,
mesh_.time().timeName(),
mesh_
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);

if (foundObject<volScalarField>(resultName_))
{
volScalarField& Co = lookupObjectRef<volScalarField>(resultName_);

Co.ref() = Coi();
Co.correctBoundaryConditions();
}
else
{
tmp<volScalarField> tCo
tCo->ref() =
byRho
(
new volScalarField
(
IOobject
(
resultName_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
);
tCo.ref().ref() = Coi();
tCo.ref().correctBoundaryConditions();
mesh_.objectRegistry::store(tCo.ptr());
}

return true;
tCo->correctBoundaryConditions();

return store(resultName_, tCo);
}
else
{
Expand Down
39 changes: 17 additions & 22 deletions src/functionObjects/field/processorField/processorField.C
Expand Up @@ -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);
}


Expand All @@ -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);
}


Expand Down
43 changes: 14 additions & 29 deletions src/functionObjects/field/turbulenceIntensity/turbulenceIntensity.C
Expand Up @@ -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");
Expand All @@ -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>
Expand All @@ -126,22 +104,29 @@ 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
{
FatalErrorInFunction
<< "Unable to find turbulence model in the "
<< "database" << exit(FatalError);
}

return true;
return false;
}
}


Expand Down
57 changes: 26 additions & 31 deletions src/functionObjects/field/wallHeatFlux/wallHeatFlux.C
Expand Up @@ -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();
Expand Down Expand Up @@ -97,6 +112,8 @@ void Foam::functionObjects::wallHeatFlux::calcHeatFlux
}
}
}

return twallHeatFlux;
}


Expand All @@ -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);
Expand Down Expand Up @@ -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
(
Expand All @@ -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
{
Expand Down
5 changes: 2 additions & 3 deletions src/functionObjects/field/wallHeatFlux/wallHeatFlux.H
Expand Up @@ -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
);


Expand Down

0 comments on commit 0f14683

Please sign in to comment.