mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
postProcessing: Replaced 'foamCalc' and the 'postCalc' utilities
with the more general and flexible 'postProcess' utility and '-postProcess' solver option
Rationale
---------
Both the 'postProcess' utility and '-postProcess' solver option use the
same extensive set of functionObjects available for data-processing
during the run avoiding the substantial code duplication necessary for
the 'foamCalc' and 'postCalc' utilities and simplifying maintenance.
Additionally consistency is guaranteed between solver data processing
and post-processing.
The functionObjects have been substantially re-written and generalized
to simplify development and encourage contribution.
Configuration
-------------
An extensive set of simple functionObject configuration files are
provided in
OpenFOAM-dev/etc/caseDicts/postProcessing
and more will be added in the future. These can either be copied into
'<case>/system' directory and included into the 'controlDict.functions'
sub-dictionary or included directly from 'etc/caseDicts/postProcessing'
using the '#includeEtc' directive or the new and more convenient
'#includeFunc' directive which searches the
'<etc>/caseDicts/postProcessing' directories for the selected
functionObject, e.g.
functions
{
#includeFunc Q
#includeFunc Lambda2
}
'#includeFunc' first searches the '<case>/system' directory in case
there is a local configuration.
Description of #includeFunc
---------------------------
Specify a functionObject dictionary file to include, expects the
functionObject name to follow (without quotes).
Search for functionObject dictionary file in
user/group/shipped directories.
The search scheme allows for version-specific and
version-independent files using the following hierarchy:
- \b user settings:
- ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing
- ~/.OpenFOAM/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is set):
- $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_SITE/caseDicts/postProcessing
- \b group (site) settings (when $WM_PROJECT_SITE is not set):
- $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing
- $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing
- \b other (shipped) settings:
- $WM_PROJECT_DIR/etc/caseDicts/postProcessing
An example of the \c \#includeFunc directive:
\verbatim
#includeFunc <funcName>
\endverbatim
postProcess
-----------
The 'postProcess' utility and '-postProcess' solver option provide the
same set of controls to execute functionObjects after the run either by
reading a specified set of fields to process in the case of
'postProcess' or by reading all fields and models required to start the
run in the case of '-postProcess' for each selected time:
postProcess -help
Usage: postProcess [OPTIONS]
options:
-case <dir> specify alternate case directory, default is the cwd
-constant include the 'constant/' dir in the times list
-dict <file> read control dictionary from specified location
-field <name> specify the name of the field to be processed, e.g. U
-fields <list> specify a list of fields to be processed, e.g. '(U T p)' -
regular expressions not currently supported
-func <name> specify the name of the functionObject to execute, e.g. Q
-funcs <list> specify the names of the functionObjects to execute, e.g.
'(Q div(U))'
-latestTime select the latest time
-newTimes select the new times
-noFunctionObjects
do not execute functionObjects
-noZero exclude the '0/' dir from the times list, has precedence
over the -withZero option
-parallel run in parallel
-region <name> specify alternative mesh region
-roots <(dir1 .. dirN)>
slave root directories for distributed running
-time <ranges> comma-separated time ranges - eg, ':10,20,40:70,1000:'
-srcDoc display source code in browser
-doc display application documentation in browser
-help print the usage
pimpleFoam -postProcess -help
Usage: pimpleFoam [OPTIONS]
options:
-case <dir> specify alternate case directory, default is the cwd
-constant include the 'constant/' dir in the times list
-dict <file> read control dictionary from specified location
-field <name> specify the name of the field to be processed, e.g. U
-fields <list> specify a list of fields to be processed, e.g. '(U T p)' -
regular expressions not currently supported
-func <name> specify the name of the functionObject to execute, e.g. Q
-funcs <list> specify the names of the functionObjects to execute, e.g.
'(Q div(U))'
-latestTime select the latest time
-newTimes select the new times
-noFunctionObjects
do not execute functionObjects
-noZero exclude the '0/' dir from the times list, has precedence
over the -withZero option
-parallel run in parallel
-postProcess Execute functionObjects only
-region <name> specify alternative mesh region
-roots <(dir1 .. dirN)>
slave root directories for distributed running
-time <ranges> comma-separated time ranges - eg, ':10,20,40:70,1000:'
-srcDoc display source code in browser
-doc display application documentation in browser
-help print the usage
The functionObjects to execute may be specified on the command-line
using the '-func' option for a single functionObject or '-funcs' for a
list, e.g.
postProcess -func Q
postProcess -funcs '(div(U) div(phi))'
In the case of 'Q' the default field to process is 'U' which is
specified in and read from the configuration file but this may be
overridden thus:
postProcess -func 'Q(Ua)'
as is done in the example above to calculate the two forms of the divergence of
the velocity field. Additional fields which the functionObjects may depend on
can be specified using the '-field' or '-fields' options.
The 'postProcess' utility can only be used to execute functionObjects which
process fields present in the time directories. However, functionObjects which
depend on fields obtained from models, e.g. properties derived from turbulence
models can be executed using the '-postProcess' of the appropriate solver, e.g.
pisoFoam -postProcess -func PecletNo
or
sonicFoam -postProcess -func MachNo
In this case all required fields will have already been read so the '-field' or
'-fields' options are not be needed.
Henry G. Weller
CFD Direct Ltd.
This commit is contained in:
314
src/functionObjects/solvers/scalarTransport/scalarTransport.C
Normal file
314
src/functionObjects/solvers/scalarTransport/scalarTransport.C
Normal file
@ -0,0 +1,314 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
\\/ 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 "scalarTransport.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "dictionary.H"
|
||||
#include "fixedValueFvPatchFields.H"
|
||||
#include "zeroGradientFvPatchFields.H"
|
||||
#include "fvScalarMatrix.H"
|
||||
#include "fvmDdt.H"
|
||||
#include "fvmDiv.H"
|
||||
#include "fvcDiv.H"
|
||||
#include "fvmLaplacian.H"
|
||||
#include "fvmSup.H"
|
||||
#include "turbulentTransportModel.H"
|
||||
#include "turbulentFluidThermoModel.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(scalarTransport, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
scalarTransport,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::wordList Foam::functionObjects::scalarTransport::boundaryTypes() const
|
||||
{
|
||||
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
|
||||
|
||||
wordList bTypes(U.boundaryField().size());
|
||||
|
||||
forAll(bTypes, patchi)
|
||||
{
|
||||
const fvPatchField<vector>& pf = U.boundaryField()[patchi];
|
||||
if (isA<fixedValueFvPatchVectorField>(pf))
|
||||
{
|
||||
bTypes[patchi] = fixedValueFvPatchScalarField::typeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
bTypes[patchi] = zeroGradientFvPatchScalarField::typeName;
|
||||
}
|
||||
}
|
||||
|
||||
return bTypes;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::DT
|
||||
(
|
||||
const surfaceScalarField& phi
|
||||
) const
|
||||
{
|
||||
typedef incompressible::turbulenceModel icoModel;
|
||||
typedef compressible::turbulenceModel cmpModel;
|
||||
|
||||
if (userDT_)
|
||||
{
|
||||
return tmp<volScalarField>
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"DT",
|
||||
mesh_.time().timeName(),
|
||||
mesh_.time(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("DT", phi.dimensions()/dimLength, DT_)
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (mesh_.foundObject<icoModel>(turbulenceModel::propertiesName))
|
||||
{
|
||||
const icoModel& model = mesh_.lookupObject<icoModel>
|
||||
(
|
||||
turbulenceModel::propertiesName
|
||||
);
|
||||
|
||||
return model.nuEff();
|
||||
}
|
||||
else if (mesh_.foundObject<cmpModel>(turbulenceModel::propertiesName))
|
||||
{
|
||||
const cmpModel& model = mesh_.lookupObject<cmpModel>
|
||||
(
|
||||
turbulenceModel::propertiesName
|
||||
);
|
||||
|
||||
return model.muEff();
|
||||
}
|
||||
else
|
||||
{
|
||||
return tmp<volScalarField>
|
||||
(
|
||||
new volScalarField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"DT",
|
||||
mesh_.time().timeName(),
|
||||
mesh_.time(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("DT", phi.dimensions()/dimLength, 0.0)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::scalarTransport::scalarTransport
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
DT_(0.0),
|
||||
nCorr_(0),
|
||||
fvOptions_(mesh_),
|
||||
T_
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
name,
|
||||
mesh_.time().timeName(),
|
||||
mesh_,
|
||||
IOobject::READ_IF_PRESENT,
|
||||
IOobject::AUTO_WRITE
|
||||
),
|
||||
mesh_,
|
||||
dimensionedScalar("zero", dimless, 0.0),
|
||||
boundaryTypes()
|
||||
)
|
||||
{
|
||||
read(dict);
|
||||
|
||||
if (resetOnStartUp_)
|
||||
{
|
||||
T_ == dimensionedScalar("zero", dimless, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::scalarTransport::~scalarTransport()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
|
||||
UName_ = dict.lookupOrDefault<word>("U", "U");
|
||||
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
|
||||
|
||||
userDT_ = false;
|
||||
if (dict.readIfPresent("DT", DT_))
|
||||
{
|
||||
userDT_ = true;
|
||||
}
|
||||
|
||||
dict.lookup("resetOnStartUp") >> resetOnStartUp_;
|
||||
|
||||
dict.readIfPresent("nCorr", nCorr_);
|
||||
|
||||
dict.lookup("autoSchemes") >> autoSchemes_;
|
||||
|
||||
fvOptions_.reset(dict.subDict("fvOptions"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::scalarTransport::execute(const bool postProcess)
|
||||
{
|
||||
Info<< type() << " output:" << endl;
|
||||
|
||||
const surfaceScalarField& phi =
|
||||
mesh_.lookupObject<surfaceScalarField>(phiName_);
|
||||
|
||||
// calculate the diffusivity
|
||||
volScalarField DT(this->DT(phi));
|
||||
|
||||
// set schemes
|
||||
word schemeVar = T_.name();
|
||||
if (autoSchemes_)
|
||||
{
|
||||
schemeVar = UName_;
|
||||
}
|
||||
|
||||
word divScheme("div(phi," + schemeVar + ")");
|
||||
word laplacianScheme("laplacian(" + DT.name() + "," + schemeVar + ")");
|
||||
|
||||
// set under-relaxation coeff
|
||||
scalar relaxCoeff = 0.0;
|
||||
if (mesh_.relaxEquation(schemeVar))
|
||||
{
|
||||
relaxCoeff = mesh_.equationRelaxationFactor(schemeVar);
|
||||
}
|
||||
|
||||
if (phi.dimensions() == dimMass/dimTime)
|
||||
{
|
||||
const volScalarField& rho =
|
||||
mesh_.lookupObject<volScalarField>(rhoName_);
|
||||
|
||||
// solve
|
||||
for (label i = 0; i <= nCorr_; i++)
|
||||
{
|
||||
fvScalarMatrix TEqn
|
||||
(
|
||||
fvm::ddt(rho, T_)
|
||||
+ fvm::div(phi, T_, divScheme)
|
||||
- fvm::laplacian(DT, T_, laplacianScheme)
|
||||
==
|
||||
fvOptions_(rho, T_)
|
||||
);
|
||||
|
||||
TEqn.relax(relaxCoeff);
|
||||
|
||||
fvOptions_.constrain(TEqn);
|
||||
|
||||
TEqn.solve(mesh_.solverDict(schemeVar));
|
||||
}
|
||||
}
|
||||
else if (phi.dimensions() == dimVolume/dimTime)
|
||||
{
|
||||
// solve
|
||||
for (label i = 0; i <= nCorr_; i++)
|
||||
{
|
||||
fvScalarMatrix TEqn
|
||||
(
|
||||
fvm::ddt(T_)
|
||||
+ fvm::div(phi, T_, divScheme)
|
||||
- fvm::laplacian(DT, T_, laplacianScheme)
|
||||
==
|
||||
fvOptions_(T_)
|
||||
);
|
||||
|
||||
TEqn.relax(relaxCoeff);
|
||||
|
||||
fvOptions_.constrain(TEqn);
|
||||
|
||||
TEqn.solve(mesh_.solverDict(schemeVar));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Incompatible dimensions for phi: " << phi.dimensions() << nl
|
||||
<< "Dimensions should be " << dimMass/dimTime << " or "
|
||||
<< dimVolume/dimTime << endl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::scalarTransport::write(const bool postProcess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
165
src/functionObjects/solvers/scalarTransport/scalarTransport.H
Normal file
165
src/functionObjects/solvers/scalarTransport/scalarTransport.H
Normal file
@ -0,0 +1,165 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
\\/ 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::scalarTransport
|
||||
|
||||
Group
|
||||
grpSolversFunctionObjects
|
||||
|
||||
Description
|
||||
This function object evolves a passive scalar transport equation. The
|
||||
field in ininitially zero, to which sources are added. The field name
|
||||
is assigned the name of the function object. Boundary conditions are
|
||||
automatically applied, based on the velocity boundary conditions.
|
||||
|
||||
- the field can be zeroed on start-up using the resetOnStartUp flag
|
||||
- to employ the same numerical schemes as the flow velocity, use the
|
||||
autoSchemes flag
|
||||
- the diffusivity can be set manually using the DT entry, or retrieved
|
||||
from the turbulence model (if applicable)
|
||||
|
||||
SeeAlso
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
|
||||
SourceFiles
|
||||
scalarTransport.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_scalarTransport_H
|
||||
#define functionObjects_scalarTransport_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "volFields.H"
|
||||
#include "surfaceFieldsFwd.H"
|
||||
#include "fvOptionList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class scalarTransport Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class scalarTransport
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of flux field (optional)
|
||||
word phiName_;
|
||||
|
||||
//- Name of velocity field (optional)
|
||||
word UName_;
|
||||
|
||||
//- Name of density field (optional)
|
||||
word rhoName_;
|
||||
|
||||
//- Diffusion coefficient (optional)
|
||||
scalar DT_;
|
||||
|
||||
//- Flag to indicate whether user DT_ is used
|
||||
bool userDT_;
|
||||
|
||||
//- Flag to reset scalar field on start-up
|
||||
bool resetOnStartUp_;
|
||||
|
||||
//- Number of corrector iterations (optional)
|
||||
label nCorr_;
|
||||
|
||||
//- Flag to employ schemes for velocity for scalar transport
|
||||
bool autoSchemes_;
|
||||
|
||||
//- Run-time selectable finite volume options, e.g. sources, constraints
|
||||
fv::optionList fvOptions_;
|
||||
|
||||
//- The scalar field
|
||||
volScalarField T_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the boundary types for the scalar field
|
||||
wordList boundaryTypes() const;
|
||||
|
||||
//- Return the diffusivity field
|
||||
tmp<volScalarField> DT(const surfaceScalarField& phi) const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
scalarTransport(const scalarTransport&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const scalarTransport&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("scalarTransport");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
scalarTransport
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~scalarTransport();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the scalarTransport data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Calculate the scalarTransport
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Do nothing.
|
||||
// The volScalarField is registered and written automatically
|
||||
virtual bool write(const bool postProcess = false);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user