Commit 9042bc2b authored by Andrew Heather's avatar Andrew Heather

Merge branch 'feature-solver-info' into 'develop'

Function object updates

See merge request !231
parents 39aa3dc1 fec3d59f
...@@ -2,6 +2,8 @@ AMIWeights/AMIWeights.C ...@@ -2,6 +2,8 @@ AMIWeights/AMIWeights.C
columnAverage/columnAverage.C columnAverage/columnAverage.C
continuityError/continuityError.C
fieldAverage/fieldAverage.C fieldAverage/fieldAverage.C
fieldAverage/fieldAverageItem/fieldAverageItem.C fieldAverage/fieldAverageItem/fieldAverageItem.C
fieldAverage/fieldAverageItem/fieldAverageItemIO.C fieldAverage/fieldAverageItem/fieldAverageItemIO.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "continuityError.H"
#include "volFields.H"
#include "fvcDiv.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(continuityError, 0);
addToRunTimeSelectionTable(functionObject, continuityError, dictionary);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::continuityError::writeFileHeader(Ostream& os)
{
writeHeader(os, "Continuity error");
writeCommented(os, "Time");
writeCommented(os, "Local");
writeCommented(os, "Global");
writeCommented(os, "Cumulative");
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::continuityError::continuityError
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(mesh_, name, typeName, dict),
phiName_("phi"),
cumulative_(getProperty<scalar>("cumulative"))
{
if (read(dict))
{
writeFileHeader(file());
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::continuityError::read(const dictionary& dict)
{
if (fvMeshFunctionObject::read(dict) && writeFile::read(dict))
{
dict.readIfPresent("phi", phiName_);
return true;
}
return false;
}
bool Foam::functionObjects::continuityError::execute()
{
return true;
}
bool Foam::functionObjects::continuityError::write()
{
const auto phiPtr = mesh_.lookupObjectPtr<surfaceScalarField>(phiName_);
if (!phiPtr)
{
WarningInFunction
<< "Unable to find flux field " << phiName_
<< endl;
return false;
}
const volScalarField error(fvc::div(*phiPtr));
const scalar deltaT = mesh_.time().deltaTValue();
scalar local = deltaT*mag(error)().weightedAverage(mesh_.V()).value();
scalar global = deltaT*error.weightedAverage(mesh_.V()).value();
cumulative_ += global;
Ostream& os = file();
writeTime(os);
os << local << tab
<< global << tab
<< cumulative_ << endl;
Log << type() << " " << name() << " write:" << nl
<< " local = " << local << nl
<< " global = " << global << nl
<< " cumulative = " << cumulative_ << nl
<< endl;
setResult("local", local);
setResult("global", global);
setResult("cumulative", cumulative_);
setProperty<scalar>("cumulative", cumulative_);
return true;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::continuityError
Group
grpFieldFunctionObjects
Description
Calculates the continuity error for a flux field
Usage
Example of function object specification:
\verbatim
continuityError1
{
type continuityError;
libs ("libfieldFunctionObjects.so");
...
writeToFile yes;
log yes;
phi phi;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: continuityError | yes |
writeToFile | write min/max data to file | no | yes
log | write min/max data to standard output | no | yes
phi | name of flux field | no | phi
\endtable
Output data is written to the file \<timeDir\>/continuityError.dat
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
continuityError.C
continuityErrorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_continuityError_H
#define functionObjects_continuityError_H
#include "Switch.H"
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class continuityError Declaration
\*---------------------------------------------------------------------------*/
class continuityError
:
public fvMeshFunctionObject,
public writeFile
{
private:
// Private Member Functions
//- No copy construct
continuityError(const continuityError&) = delete;
//- No copy assignment
void operator=(const continuityError&) = delete;
protected:
// Protected data
//- Name of the flux field; default = "phi
word phiName_;
//- Cumulative error
scalar cumulative_;
// Protected Member Functions
//- Output file header information
virtual void writeFileHeader(Ostream& os);
public:
//- Runtime type information
TypeName("continuityError");
// Constructors
//- Construct from Time and dictionary
continuityError
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~continuityError() = default;
// Member Functions
//- Read the field min/max data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual bool execute();
//- Write the continuityError
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
...@@ -10,7 +10,7 @@ vtkWrite/vtkWriteUpdate.C ...@@ -10,7 +10,7 @@ vtkWrite/vtkWriteUpdate.C
removeRegisteredObject/removeRegisteredObject.C removeRegisteredObject/removeRegisteredObject.C
residuals/residuals.C solverInfo/solverInfo.C
runTimeControl/runTimeControl.C runTimeControl/runTimeControl.C
runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -23,7 +23,7 @@ License ...@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "residuals.H" #include "solverInfo.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
...@@ -32,12 +32,12 @@ namespace Foam ...@@ -32,12 +32,12 @@ namespace Foam
{ {
namespace functionObjects namespace functionObjects
{ {
defineTypeNameAndDebug(residuals, 0); defineTypeNameAndDebug(solverInfo, 0);
addToRunTimeSelectionTable addToRunTimeSelectionTable
( (
functionObject, functionObject,
residuals, solverInfo,
dictionary dictionary
); );
} }
...@@ -46,7 +46,7 @@ namespace functionObjects ...@@ -46,7 +46,7 @@ namespace functionObjects
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) void Foam::functionObjects::solverInfo::writeFileHeader(Ostream& os)
{ {
if (!fieldSet_.updateSelection()) if (!fieldSet_.updateSelection())
{ {
...@@ -59,7 +59,7 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) ...@@ -59,7 +59,7 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os)
} }
else else
{ {
writeHeader(os, "Residuals"); writeHeader(os, "Solver information");
} }
writeCommented(os, "Time"); writeCommented(os, "Time");
...@@ -79,9 +79,12 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) ...@@ -79,9 +79,12 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os)
} }
void Foam::functionObjects::residuals::createField(const word& fieldName) void Foam::functionObjects::solverInfo::createResidualField
(
const word& fieldName
)
{ {
if (!writeFields_) if (!writeResidualFields_)
{ {
return; return;
} }
...@@ -109,7 +112,10 @@ void Foam::functionObjects::residuals::createField(const word& fieldName) ...@@ -109,7 +112,10 @@ void Foam::functionObjects::residuals::createField(const word& fieldName)
} }
void Foam::functionObjects::residuals::writeField(const word& fieldName) const void Foam::functionObjects::solverInfo::writeResidualField
(
const word& fieldName
) const
{ {
const word residualName("initialResidual:" + fieldName); const word residualName("initialResidual:" + fieldName);
...@@ -143,7 +149,7 @@ void Foam::functionObjects::residuals::writeField(const word& fieldName) const ...@@ -143,7 +149,7 @@ void Foam::functionObjects::residuals::writeField(const word& fieldName) const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::residuals::residuals Foam::functionObjects::solverInfo::solverInfo
( (
const word& name, const word& name,
const Time& runTime, const Time& runTime,
...@@ -153,28 +159,23 @@ Foam::functionObjects::residuals::residuals ...@@ -153,28 +159,23 @@ Foam::functionObjects::residuals::residuals
fvMeshFunctionObject(name, runTime, dict), fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict), writeFile(obr_, name, typeName, dict),
fieldSet_(mesh_), fieldSet_(mesh_),
writeFields_(false), writeResidualFields_(false),
initialised_(false) initialised_(false)
{ {
read(dict); read(dict);
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::residuals::~residuals()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::residuals::read(const dictionary& dict) bool Foam::functionObjects::solverInfo::read(const dictionary& dict)
{ {
if (fvMeshFunctionObject::read(dict)) if (fvMeshFunctionObject::read(dict))
{ {
fieldSet_.read(dict); fieldSet_.read(dict);
writeFields_ = dict.lookupOrDefault("writeFields", false); writeResidualFields_ =
dict.lookupOrDefault("writeResidualFields", false);
return true; return true;
} }
...@@ -183,7 +184,7 @@ bool Foam::functionObjects::residuals::read(const dictionary& dict) ...@@ -183,7 +184,7 @@ bool Foam::functionObjects::residuals::read(const dictionary& dict)
} }
bool Foam::functionObjects::residuals::execute() bool Foam::functionObjects::solverInfo::execute()
{ {
// Note: delaying initialisation until after first iteration so that // Note: delaying initialisation until after first iteration so that
// we can find wildcard fields // we can find wildcard fields
...@@ -191,15 +192,15 @@ bool Foam::functionObjects::residuals::execute() ...@@ -191,15 +192,15 @@ bool Foam::functionObjects::residuals::execute()
{ {
writeFileHeader(file()); writeFileHeader(file());
if (writeFields_) if (writeResidualFields_)
{ {
for (const word& fieldName : fieldSet_.selectionNames()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
initialiseField<scalar>(fieldName); initialiseResidualField<scalar>(fieldName);
initialiseField<vector>(fieldName); initialiseResidualField<vector>(fieldName);
initialiseField<sphericalTensor>(fieldName); initialiseResidualField<sphericalTensor>(fieldName);
initialiseField<symmTensor>(fieldName); initialiseResidualField<symmTensor>(fieldName);
initialiseField<tensor>(fieldName); initialiseResidualField<tensor>(fieldName);
} }
} }
...@@ -210,17 +211,17 @@ bool Foam::functionObjects::residuals::execute() ...@@ -210,17 +211,17 @@ bool Foam::functionObjects::residuals::execute()
} }
bool Foam::functionObjects::residuals::write() bool Foam::functionObjects::solverInfo::write()
{ {
writeTime(file()); writeTime(file());
for (const word& fieldName : fieldSet_.selectionNames()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
writeResidual<scalar>(fieldName); writeSolverInfo<scalar>(fieldName);
writeResidual<vector>(fieldName); writeSolverInfo<vector>(fieldName);
writeResidual<sphericalTensor>(fieldName); writeSolverInfo<sphericalTensor>(fieldName);
writeResidual<symmTensor>(fieldName); writeSolverInfo<symmTensor>(fieldName);
writeResidual<tensor>(fieldName); writeSolverInfo<tensor>(fieldName);
} }
file() << endl; file() << endl;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -22,37 +22,44 @@ License ...@@ -22,37 +22,44 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::functionObjects::residuals Foam::functionObjects::solverInfo
Group Group
grpUtilitiesFunctionObjects grpUtilitiesFunctionObjects
Description Description
Writes out the initial residual for specified fields. Writes solver information for a list of user-specified fields
Information written to file includes:
- residual fields
- solver type
- initial residual
- final residual