Commit 159ee1d9 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: solverInfo - separated execute and write functionality

parent a6acce45
......@@ -110,41 +110,8 @@ void Foam::functionObjects::solverInfo::createResidualField
);
fieldPtr->store();
}
}
void Foam::functionObjects::solverInfo::writeResidualField
(
const word& fieldName
) const
{
const word residualName("initialResidual:" + fieldName);
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName);
if (residualPtr)
{
volScalarField residual
(
IOobject
(
residualName,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
dimensionedScalar(dimless, Zero),
zeroGradientFvPatchField<scalar>::typeName
);
residual.primitiveFieldRef() = *residualPtr;
residual.correctBoundaryConditions();
residual.write();
residualFieldNames_.insert(residualName);
}
}
......@@ -162,6 +129,7 @@ Foam::functionObjects::solverInfo::solverInfo
writeFile(obr_, name, typeName, dict),
fieldSet_(mesh_),
writeResidualFields_(false),
residualFieldNames_(),
initialised_(false)
{
read(dict);
......@@ -174,11 +142,15 @@ bool Foam::functionObjects::solverInfo::read(const dictionary& dict)
{
if (fvMeshFunctionObject::read(dict))
{
initialised_ = false;
fieldSet_.read(dict);
writeResidualFields_ =
dict.lookupOrDefault("writeResidualFields", false);
residualFieldNames_.clear();
return true;
}
......@@ -209,24 +181,54 @@ bool Foam::functionObjects::solverInfo::execute()
initialised_ = true;
}
writeTime(file());
for (const word& fieldName : fieldSet_.selectionNames())
{
updateSolverInfo<scalar>(fieldName);
updateSolverInfo<vector>(fieldName);
updateSolverInfo<sphericalTensor>(fieldName);
updateSolverInfo<symmTensor>(fieldName);
updateSolverInfo<tensor>(fieldName);
}
file() << endl;
return true;
}
bool Foam::functionObjects::solverInfo::write()
{
writeTime(file());
for (const word& fieldName : fieldSet_.selectionNames())
for (const word& residualName : residualFieldNames_)
{
writeSolverInfo<scalar>(fieldName);
writeSolverInfo<vector>(fieldName);
writeSolverInfo<sphericalTensor>(fieldName);
writeSolverInfo<symmTensor>(fieldName);
writeSolverInfo<tensor>(fieldName);
}
const auto* residualPtr =
mesh_.findObject<IOField<scalar>>(residualName);
file() << endl;
if (residualPtr)
{
volScalarField residual
(
IOobject
(
residualName,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
dimensionedScalar(dimless, Zero),
zeroGradientFvPatchField<scalar>::typeName
);
residual.primitiveFieldRef() = *residualPtr;
residual.correctBoundaryConditions();
residual.write();
}
}
return true;
}
......
......@@ -107,6 +107,9 @@ protected:
//- Flag to write the residual as a vol field
bool writeResidualFields_;
//- Names of (result) residual fields
wordHashSet residualFieldNames_;
//- Initialisation flag
bool initialised_;
......@@ -119,9 +122,6 @@ protected:
//- Create and store a residual field on the mesh database
void createResidualField(const word& fieldName);
//- Write a residual field
void writeResidualField(const word& fieldName) const;
//- Output file header information per primitive type value
template<class Type>
void writeFileHeader(Ostream& os, const word& fileName) const;
......@@ -132,7 +132,7 @@ protected:
//- Calculate the solver information
template<class Type>
void writeSolverInfo(const word& fieldName);
void updateSolverInfo(const word& fieldName);
private:
......
......@@ -105,7 +105,7 @@ void Foam::functionObjects::solverInfo::initialiseResidualField
template<class Type>
void Foam::functionObjects::solverInfo::writeSolverInfo(const word& fieldName)
void Foam::functionObjects::solverInfo::updateSolverInfo(const word& fieldName)
{
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
typedef typename pTraits<Type>::labelType labelType;
......@@ -150,8 +150,6 @@ void Foam::functionObjects::solverInfo::writeSolverInfo(const word& fieldName)
setResult(resultName + "_initial", ri);
setResult(resultName + "_final", rf);
setResult(resultName + "_iters", n);
writeResidualField(resultName);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment