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 // ************************************************************************* //
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:45
Foam::surfaceFields.
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
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.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
static bool postProcess
Global post-processing mode switch.
static void list()
Print a list of functionObject configuration files in the directories located using Foam::findEtcDirs...
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:198
Various UniformDimensionedField types.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
List< T > getList(const label index) const
Get a List of values from the argument at index.
Required Variables.
Field reading functions for post-processing utilities.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
bool execute()
Called at each ++ or += of the time-loop.
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:96
dynamicFvMesh & mesh
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:671
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:44
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:997
List of function objects with start(), execute() and end() functions that is called for each object...
errorManip< error > abort(error &err)
Definition: errorManip.H:139
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
Report an I/O error.
Definition: error.H:350
Helper class to manage file-based field selections.
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:223
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:770
static bool print(Ostream &os)
Print profiling information to specified output.
Definition: profiling.C:118
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:89
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
Definition: timeSelector.C:234
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional &#39;FOAM Warning&#39; header text...
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Foam::argList args(argc, argv)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:570
bool end()
Called when Time::run() determines that the time-loop exits.
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:101
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...