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:
Henry Weller
2016-05-28 18:58:48 +01:00
parent 6f9573bb12
commit e4dc50dcb0
394 changed files with 1450 additions and 5384 deletions

View File

@ -28,6 +28,18 @@ License
#include "mapPolyMesh.H"
#include "argList.H"
#include "timeControlFunctionObject.H"
#include "IFstream.H"
#include "dictionaryEntry.H"
#include "stringOps.H"
#include "etcFiles.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
Foam::fileName Foam::functionObjectList::functionObjectDictPath
(
"caseDicts/postProcessing"
);
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
@ -59,6 +71,125 @@ Foam::functionObject* Foam::functionObjectList::remove
}
Foam::fileName Foam::functionObjectList::findDict(const word& funcName)
{
// First check if there is a functionObject dictionary file in the
// case system directory
fileName dictFile = stringOps::expand("$FOAM_CASE")/"system"/funcName;
if (isFile(dictFile))
{
return dictFile;
}
else
{
fileNameList etcDirs(findEtcDirs(functionObjectDictPath));
forAll(etcDirs, i)
{
dictFile = search(funcName, etcDirs[i]);
if (!dictFile.empty())
{
return dictFile;
}
}
}
return fileName::null;
}
void Foam::functionObjectList::readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& selectedFields
)
{
// Parse the optional functionObject arguments
// e.g. 'Q(U)' -> funcName = Q; args = (U);
word funcNameArgs(funcNameArgs0);
string::stripInvalid<word>(funcNameArgs);
word funcName(funcNameArgs);
wordList args;
word::size_type start = 0;
word::size_type i = 0;
for
(
word::const_iterator iter = funcNameArgs.begin();
iter != funcNameArgs.end();
++iter
)
{
char c = *iter;
if (c == '(')
{
funcName.resize(i);
start = i+1;
}
else if (c == ',')
{
args.append(funcNameArgs(start, i - start));
start = i+1;
}
else if (c == ')')
{
args.append(funcNameArgs(start, i - start));
break;
}
++i;
}
// Search for the functionObject dictionary
fileName path = findDict(funcName);
if (path == fileName::null)
{
WarningInFunction
<< "Cannot find functionObject file " << funcName << endl;
return;
}
// Read the functionObject dictionary
IFstream fileStream(path);
dictionary funcsDict(fileStream);
dictionary& funcDict = funcsDict.subDict(funcName);
// Insert the 'field' or 'fields' entry corresponding to the optional
// arguments or read the 'field' or 'fields' entry and add the required
// fields to selectedFields
if (args.size() == 1)
{
funcDict.set("field", args[0]);
selectedFields.insert(args[0]);
}
else if (args.size() > 1)
{
funcDict.set("fields", args);
selectedFields.insert(args);
}
else if (funcDict.found("field"))
{
selectedFields.insert(word(funcDict.lookup("field")));
}
else if (funcDict.found("fields"))
{
selectedFields.insert(wordList(funcDict.lookup("fields")));
}
// Merge this functionObject dictionary into functionsDict
dictionary funcArgsDict;
funcArgsDict.add(funcNameArgs, funcDict);
functionsDict.subDict("functions").merge(funcArgsDict);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjectList::functionObjectList
@ -98,35 +229,65 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
(
const argList& args,
const Time& runTime,
dictionary& functionObjectsDict
dictionary& functionsDict,
HashSet<word>& selectedFields
)
{
autoPtr<functionObjectList> functionObjectsPtr;
autoPtr<functionObjectList> functionsPtr;
if (args.optionFound("dict"))
functionsDict.add
(
dictionaryEntry("functions", functionsDict, dictionary::null)
);
if
(
args.optionFound("dict")
|| args.optionFound("func")
|| args.optionFound("funcs")
)
{
functionObjectsDict = IOdictionary
(
IOobject
if (args.optionFound("dict"))
{
functionsDict.merge
(
args["dict"],
runTime,
IOobject::MUST_READ_IF_MODIFIED
)
);
IOdictionary
(
IOobject
(
args["dict"],
runTime,
IOobject::MUST_READ_IF_MODIFIED
)
)
);
}
functionObjectsPtr.reset
(
new functionObjectList(runTime, functionObjectsDict)
);
if (args.optionFound("func"))
{
readFunctionObject(args["func"], functionsDict, selectedFields);
}
if (args.optionFound("funcs"))
{
wordList funcs(args.optionLookup("funcs")());
forAll(funcs, i)
{
readFunctionObject(funcs[i], functionsDict, selectedFields);
}
}
functionsPtr.reset(new functionObjectList(runTime, functionsDict));
}
else
{
functionObjectsPtr.reset(new functionObjectList(runTime));
functionsPtr.reset(new functionObjectList(runTime));
}
functionObjectsPtr->start();
return functionObjectsPtr;
functionsPtr->start();
return functionsPtr;
}

View File

@ -44,6 +44,7 @@ SourceFiles
#include "functionObject.H"
#include "SHA1Digest.H"
#include "HashTable.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -90,6 +91,13 @@ class functionObjectList
// Returns a NULL pointer (and index -1) if it didn't exist.
functionObject* remove(const word&, label& oldIndex);
static void readFunctionObject
(
const word& funcNameArgs0,
dictionary& functionsDict,
HashSet<word>& selectedFields
);
//- Disallow default bitwise copy construct
functionObjectList(const functionObjectList&);
@ -99,13 +107,20 @@ class functionObjectList
public:
// Static data members
//- Default relative path to the directory structure
// containing the functionObject dictionary files
static fileName functionObjectDictPath;
// Constructors
//- Construct from Time and the execution setting
//- Construct from Time and the execution setting.
// The functionObject specifications are read from the controlDict
functionObjectList
(
const Time&,
const Time& runTime,
const bool execution=true
);
@ -119,13 +134,12 @@ public:
// or not. Default: true.
functionObjectList
(
const Time& t,
const Time& runTime,
const dictionary& parentDict,
const bool execution=true
);
//- Construct and return a functionObjectList for an application.
//
// If the "dict" argument is specified the functionObjectList is
// constructed from that dictionary which is returned as
// functionObjectsDict otherwise the functionObjectList is constructed
@ -134,7 +148,8 @@ public:
(
const argList& args,
const Time& runTime,
dictionary& functionObjectsDict
dictionary& functionObjectsDict,
HashSet<word>& selectedFields
);
@ -159,6 +174,26 @@ public:
//- Find the ID of a given function object by name
label findObjectID(const word& name) const;
//- 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
//
// \return The path of the functionObject dictionary file if found
// otherwise null
static fileName findDict(const word& funcName);
//- Read and set the function objects if their data have changed
bool read();

View File

@ -71,7 +71,7 @@ if (argList::postProcess(argc, argv))
{
Foam::timeSelector::addOptions();
#include "addRegionOption.H"
#include "addDictOption.H"
#include "addFunctionObjectOptions.H"
#include "setRootCase.H"
#include INCLUDE_FILE(CREATE_TIME)
@ -84,12 +84,14 @@ if (argList::postProcess(argc, argv))
// Externally stored dictionary for functionObjectList
// if not constructed from runTime
dictionary functionObjectsDict;
dictionary functionsDict;
HashSet<word> selectedFields;
// Construct functionObjectList
autoPtr<functionObjectList> functionObjectsPtr
autoPtr<functionObjectList> functionsPtr
(
functionObjectList::New(args, runTime, functionObjectsDict)
functionObjectList::New(args, runTime, functionsDict, selectedFields)
);
forAll(timeDirs, timeI)
@ -101,8 +103,13 @@ if (argList::postProcess(argc, argv))
if (mesh.readUpdate() != polyMesh::UNCHANGED)
{
// Update functionObjects if mesh changes
functionObjectsPtr =
functionObjectList::New(args, runTime, functionObjectsDict);
functionsPtr = functionObjectList::New
(
args,
runTime,
functionsDict,
selectedFields
);
}
FatalIOError.throwExceptions();
@ -119,7 +126,7 @@ if (argList::postProcess(argc, argv))
#include INCLUDE_FILE(CREATE_FIELDS_3)
#endif
functionObjectsPtr->execute(true);
functionsPtr->execute(true);
}
catch (IOerror& err)
{