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();
|
fieldPtr->store();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
residualFieldNames_.insert(residualName);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +129,7 @@ Foam::functionObjects::solverInfo::solverInfo
|
|||||||
writeFile(obr_, name, typeName, dict),
|
writeFile(obr_, name, typeName, dict),
|
||||||
fieldSet_(mesh_),
|
fieldSet_(mesh_),
|
||||||
writeResidualFields_(false),
|
writeResidualFields_(false),
|
||||||
|
residualFieldNames_(),
|
||||||
initialised_(false)
|
initialised_(false)
|
||||||
{
|
{
|
||||||
read(dict);
|
read(dict);
|
||||||
@ -174,11 +142,15 @@ bool Foam::functionObjects::solverInfo::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
if (fvMeshFunctionObject::read(dict))
|
if (fvMeshFunctionObject::read(dict))
|
||||||
{
|
{
|
||||||
|
initialised_ = false;
|
||||||
|
|
||||||
fieldSet_.read(dict);
|
fieldSet_.read(dict);
|
||||||
|
|
||||||
writeResidualFields_ =
|
writeResidualFields_ =
|
||||||
dict.lookupOrDefault("writeResidualFields", false);
|
dict.lookupOrDefault("writeResidualFields", false);
|
||||||
|
|
||||||
|
residualFieldNames_.clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,21 +181,15 @@ bool Foam::functionObjects::solverInfo::execute()
|
|||||||
initialised_ = true;
|
initialised_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::solverInfo::write()
|
|
||||||
{
|
|
||||||
writeTime(file());
|
writeTime(file());
|
||||||
|
|
||||||
for (const word& fieldName : fieldSet_.selectionNames())
|
for (const word& fieldName : fieldSet_.selectionNames())
|
||||||
{
|
{
|
||||||
writeSolverInfo<scalar>(fieldName);
|
updateSolverInfo<scalar>(fieldName);
|
||||||
writeSolverInfo<vector>(fieldName);
|
updateSolverInfo<vector>(fieldName);
|
||||||
writeSolverInfo<sphericalTensor>(fieldName);
|
updateSolverInfo<sphericalTensor>(fieldName);
|
||||||
writeSolverInfo<symmTensor>(fieldName);
|
updateSolverInfo<symmTensor>(fieldName);
|
||||||
writeSolverInfo<tensor>(fieldName);
|
updateSolverInfo<tensor>(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
file() << endl;
|
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
|
//- Flag to write the residual as a vol field
|
||||||
bool writeResidualFields_;
|
bool writeResidualFields_;
|
||||||
|
|
||||||
|
//- Names of (result) residual fields
|
||||||
|
wordHashSet residualFieldNames_;
|
||||||
|
|
||||||
//- Initialisation flag
|
//- Initialisation flag
|
||||||
bool initialised_;
|
bool initialised_;
|
||||||
|
|
||||||
@ -119,9 +122,6 @@ protected:
|
|||||||
//- Create and store a residual field on the mesh database
|
//- Create and store a residual field on the mesh database
|
||||||
void createResidualField(const word& fieldName);
|
void createResidualField(const word& fieldName);
|
||||||
|
|
||||||
//- Write a residual field
|
|
||||||
void writeResidualField(const word& fieldName) const;
|
|
||||||
|
|
||||||
//- Output file header information per primitive type value
|
//- Output file header information per primitive type value
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void writeFileHeader(Ostream& os, const word& fileName) const;
|
void writeFileHeader(Ostream& os, const word& fileName) const;
|
||||||
@ -132,7 +132,7 @@ protected:
|
|||||||
|
|
||||||
//- Calculate the solver information
|
//- Calculate the solver information
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void writeSolverInfo(const word& fieldName);
|
void updateSolverInfo(const word& fieldName);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -105,7 +105,7 @@ void Foam::functionObjects::solverInfo::initialiseResidualField
|
|||||||
|
|
||||||
|
|
||||||
template<class Type>
|
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 GeometricField<Type, fvPatchField, volMesh> volFieldType;
|
||||||
typedef typename pTraits<Type>::labelType labelType;
|
typedef typename pTraits<Type>::labelType labelType;
|
||||||
@ -150,8 +150,6 @@ void Foam::functionObjects::solverInfo::writeSolverInfo(const word& fieldName)
|
|||||||
setResult(resultName + "_initial", ri);
|
setResult(resultName + "_initial", ri);
|
||||||
setResult(resultName + "_final", rf);
|
setResult(resultName + "_final", rf);
|
||||||
setResult(resultName + "_iters", n);
|
setResult(resultName + "_iters", n);
|
||||||
|
|
||||||
writeResidualField(resultName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user