postProcess.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  postProcess
29 
30 Description
31  Execute the set of functionObjects specified in the selected dictionary
32  (which defaults to system/controlDict) or on the command-line for the
33  selected set of times on the selected set of fields.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #include "argList.H"
38 #include "profiling.H"
39 #include "timeSelector.H"
40 #include "ReadFields.H"
41 #include "volFields.H"
42 #include "surfaceFields.H"
43 #include "pointFields.H"
45 #include "fileFieldSelection.H"
46 #include "mapPolyMesh.H"
47 
48 using namespace Foam;
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 #define ReadFields(GeoFieldType) \
53  readFields<GeoFieldType>(mesh, objects, selectedFields, storedObjects);
54 
55 #define ReadPointFields(GeoFieldType) \
56  readFields<GeoFieldType>(pMesh, objects, selectedFields, storedObjects);
57 
58 #define ReadUniformFields(FieldType) \
59  readUniformFields<FieldType> \
60  (constantObjects, selectedFields, storedObjects);
61 
62 void executeFunctionObjects
63 (
64  const argList& args,
65  const Time& runTime,
66  fvMesh& mesh,
67  const wordHashSet& selectedFields,
68  functionObjectList& functions,
69  bool lastTime
70 )
71 {
72  Info<< nl << "Reading fields:" << endl;
73 
74  // Maintain a stack of the stored objects to clear after executing
75  // the functionObjects
76  LIFOStack<regIOobject*> storedObjects;
77 
78  // Read objects in time directory
79  IOobjectList objects(mesh, runTime.timeName());
80 
81  // Read volFields
87 
88  // Read internal fields
94 
95  // Read surface fields
101 
102  // Read point fields.
103  const pointMesh& pMesh = pointMesh::New(mesh);
104 
105  ReadPointFields(pointScalarField)
106  ReadPointFields(pointVectorField);
107  ReadPointFields(pointSphericalTensorField);
108  ReadPointFields(pointSymmTensorField);
109  ReadPointFields(pointTensorField);
110 
111  // Read uniform dimensioned fields
112  IOobjectList constantObjects(mesh, runTime.constant());
113 
114  ReadUniformFields(uniformDimensionedScalarField);
115  ReadUniformFields(uniformDimensionedVectorField);
116  ReadUniformFields(uniformDimensionedSphericalTensorField);
117  ReadUniformFields(uniformDimensionedSymmTensorField);
118  ReadUniformFields(uniformDimensionedTensorField);
119 
120  Info<< nl << "Executing functionObjects" << endl;
121 
122  // Execute the functionObjects in post-processing mode
123  functions.execute();
124 
125  // Execute the functionObject 'end()' function for the last time
126  if (lastTime)
127  {
128  functions.end();
129  }
130 
131  while (!storedObjects.empty())
132  {
133  storedObjects.pop()->checkOut();
134  }
135 }
136 
137 
138 int main(int argc, char *argv[])
139 {
141  (
142  "Execute the set of functionObjects specified in the selected"
143  " dictionary or on the command-line for the"
144  " selected set of times on the selected set of fields"
145  );
146 
148  #include "addProfilingOption.H"
149  #include "addRegionOption.H"
150  #include "addFunctionObjectOptions.H"
151 
152  // Set functionObject post-processing mode
154 
155  #include "setRootCase.H"
156 
157  if (args.found("list"))
158  {
160  return 0;
161  }
162 
163  #include "createTime.H"
165  #include "createNamedMesh.H"
166 
167  // Initialize the set of selected fields from the command-line options
169  if (args.found("fields"))
170  {
171  fields.resetFieldFilters
172  (
173  HashSet<wordRe>(args.getList<wordRe>("fields"))
174  );
175  }
176  if (args.found("field"))
177  {
178  fields.resetFieldFilters(args.get<wordRe>("field"));
179  }
180 
181  // Externally stored dictionary for functionObjectList
182  // if not constructed from runTime
183  dictionary functionsDict;
184 
185  HashSet<wordRe> fieldFilters(fields.filters());
186 
187  // Construct functionObjectList
188  autoPtr<functionObjectList> functionsPtr
189  (
191  (
192  args,
193  runTime,
194  functionsDict,
195  fieldFilters // include any additional command-line fields
196  )
197  );
198 
199  forAll(timeDirs, timei)
200  {
201  runTime.setTime(timeDirs[timei], timei);
202 
203  Info<< "Time = " << runTime.timeName() << endl;
204 
205  switch (mesh.readUpdate())
206  {
208  {
209  functionsPtr->movePoints(mesh);
210  break;
211  }
214  {
215  mapPolyMesh mpm(mesh);
216  functionsPtr->updateMesh(mpm);
217  break;
218  }
219  case polyMesh::UNCHANGED:
220  {
221  // No additional work
222  break;
223  }
224  default:
225  {
227  << "Unhandled enumeration"
228  << abort(FatalError);
229  }
230  }
231 
232  fields.resetFieldFilters(fieldFilters);
233 
234  fields.updateSelection();
235 
236  const bool oldThrowingIOErr = FatalIOError.throwing(true);
237 
238  try
239  {
240  executeFunctionObjects
241  (
242  args,
243  runTime,
244  mesh,
245  fields.selectionNames(),
246  functionsPtr(),
247  timei == timeDirs.size()-1
248  );
249 
250  // Report to output (avoid overwriting values from simulation)
252  }
253  catch (const Foam::IOerror& err)
254  {
255  Warning << err << endl;
256  }
257 
258  Info<< endl;
259 
260  // Restore previous exception throwing state
261  FatalIOError.throwing(oldThrowingIOErr);
262  }
263 
264  Info<< "End\n" << endl;
265 
266  return 0;
267 }
268 
269 
270 // ************************************************************************* //
volFields.H
profiling.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjectList::list
static void list()
Definition: functionObjectList.C:192
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::polyMesh::POINTS_MOVED
Definition: polyMesh.H:93
Foam::ReadFields
wordList ReadFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh >> &fields, const bool syncPar=true, const bool readOldTime=false)
Read Geometric fields of templated type.
mapPolyMesh.H
Foam::Warning
messageStream Warning
addFunctionObjectOptions.H
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::error::throwing
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:169
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::LIFOStack::pop
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:90
Foam::functionObjectList::execute
bool execute()
Called at each ++ or += of the time-loop.
Definition: functionObjectList.C:624
Foam::HashSet< word, Hash< word > >
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
Foam::functionObjectList
List of function objects with start(), execute() and end() functions that is called for each object.
Definition: functionObjectList.H:130
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:648
Foam::polyMesh::TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
fileFieldSelection.H
Foam::UniformDimensionedField< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
addProfilingOption.H
Foam::functionObjects::fileFieldSelection
Helper class to manage file-based field selections.
Definition: fileFieldSelection.H:55
argList.H
Foam::functionObject::postProcess
static bool postProcess
Global post-processing mode switch.
Definition: functionObject.H:370
addRegionOption.H
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:92
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:94
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
createNamedMesh.H
Required Variables.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::functionObjectList::New
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
Definition: functionObjectList.C:424
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
uniformDimensionedFields.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
setRootCase.H
ReadFields.H
Field reading functions for post-processing utilities.
Foam::regIOobject::checkOut
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:224
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::argList::executable
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:51
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:102
Foam::List< instant >
Foam::Time::setTime
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:1003
Foam::profiling::print
static bool print(Ostream &os)
Print profiling information to specified output.
Definition: profiling.C:123
timeSelector.H
createTime.H
Foam::argList::getList
List< T > getList(const label index) const
Get a List of values from the argument at index.
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::IOerror
Report an I/O error.
Definition: error.H:279
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:448
Foam::LIFOStack
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:51
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:235
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::GeometricField< scalar, fvPatchField, volMesh >
args
Foam::argList args(argc, argv)
Foam::functionObjectList::end
bool end()
Called when Time::run() determines that the time-loop exits.
Definition: functionObjectList.C:835
pointFields.H
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178