mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: solverInfo - separated execute and write functionality
This commit is contained in:
@ -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,21 +181,15 @@ bool Foam::functionObjects::solverInfo::execute()
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::solverInfo::write()
|
||||
{
|
||||
writeTime(file());
|
||||
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeSolverInfo<scalar>(fieldName);
|
||||
writeSolverInfo<vector>(fieldName);
|
||||
writeSolverInfo<sphericalTensor>(fieldName);
|
||||
writeSolverInfo<symmTensor>(fieldName);
|
||||
writeSolverInfo<tensor>(fieldName);
|
||||
updateSolverInfo<scalar>(fieldName);
|
||||
updateSolverInfo<vector>(fieldName);
|
||||
updateSolverInfo<sphericalTensor>(fieldName);
|
||||
updateSolverInfo<symmTensor>(fieldName);
|
||||
updateSolverInfo<tensor>(fieldName);
|
||||
}
|
||||
|
||||
file() << endl;
|
||||
@ -232,4 +198,40 @@ bool Foam::functionObjects::solverInfo::write()
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::solverInfo::write()
|
||||
{
|
||||
for (const word& residualName : residualFieldNames_)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user