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-2023 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 void executeFunctionObjects
53 (
54  const argList& args,
55  const Time& runTime,
56  fvMesh& mesh,
57  const wordList& selectedFields,
58  functionObjectList& functions,
59  bool lastTime
60 )
61 {
62  Info<< nl << "Reading fields:" << endl;
63 
64  // Read objects in constant directory
65  IOobjectList constObjects(mesh, runTime.constant());
66 
67  // Read objects in time directory
68  IOobjectList objects(mesh, runTime.timeName());
69 
70  // List of stored objects to clear after executing functionObjects
71  DynamicList<regIOobject*> storedObjects
72  (
73  objects.size() + constObjects.size()
74  );
75 
76  const auto nameMatcher = [&](const word& name) -> bool
77  {
78  return selectedFields.contains(name);
79  };
80 
81  // Read GeometricFields
82 
83  #undef ReadFields
84  #define ReadFields(FieldType) \
85  readFields<FieldType>(mesh, objects, nameMatcher, storedObjects);
86 
87  // Read volFields
93 
94  // Read internal fields
100 
101  // Read surface fields
107 
108 
109  // Read point fields.
110  const pointMesh& pMesh = pointMesh::New(mesh);
111  #undef ReadPointFields
112  #define ReadPointFields(FieldType) \
113  readFields<FieldType>(pMesh, objects, nameMatcher, storedObjects);
114 
115  ReadPointFields(pointScalarField)
116  ReadPointFields(pointVectorField);
117  ReadPointFields(pointSphericalTensorField);
118  ReadPointFields(pointSymmTensorField);
119  ReadPointFields(pointTensorField);
120 
121 
122  // Read uniform dimensioned fields
123 
124  #undef ReadUniformFields
125  #define ReadUniformFields(FieldType) \
126  readUniformFields<FieldType>(constObjects, nameMatcher, storedObjects);
127 
128  ReadUniformFields(uniformDimensionedScalarField);
129  ReadUniformFields(uniformDimensionedVectorField);
130  ReadUniformFields(uniformDimensionedSphericalTensorField);
131  ReadUniformFields(uniformDimensionedSymmTensorField);
132  ReadUniformFields(uniformDimensionedTensorField);
133 
134  Info<< nl << "Executing functionObjects" << endl;
135 
136  // Execute the functionObjects in post-processing mode
137  functions.execute();
138 
139  // Execute the functionObject 'end()' function for the last time
140  if (lastTime)
141  {
142  functions.end();
143  }
144 
145  while (!storedObjects.empty())
146  {
147  storedObjects.back()->checkOut();
148  storedObjects.pop_back();
149  }
150 }
151 
152 
153 int main(int argc, char *argv[])
154 {
156  (
157  "Execute the set of functionObjects specified in the selected"
158  " dictionary or on the command-line for the"
159  " selected set of times on the selected set of fields"
160  );
161 
163  #include "addProfilingOption.H"
164  #include "addRegionOption.H"
165  #include "addFunctionObjectOptions.H"
166 
167  // Set functionObject post-processing mode
169 
170  #include "setRootCase.H"
171 
172  if (args.found("list"))
173  {
175  return 0;
176  }
177 
178  #include "createTime.H"
180  #include "createNamedMesh.H"
181 
182  // Initialize the set of selected fields from the command-line options
184  if (args.found("fields"))
185  {
186  fields.resetFieldFilters
187  (
188  HashSet<wordRe>(args.getList<wordRe>("fields"))
189  );
190  }
191  if (args.found("field"))
192  {
193  fields.resetFieldFilters(args.get<wordRe>("field"));
194  }
195 
196  // Externally stored dictionary for functionObjectList
197  // if not constructed from runTime
198  dictionary functionsDict;
199 
200  HashSet<wordRe> fieldFilters(fields.filters());
201 
202  // Construct functionObjectList
203  autoPtr<functionObjectList> functionsPtr
204  (
206  (
207  args,
208  runTime,
209  functionsDict,
210  fieldFilters // include any additional command-line fields
211  )
212  );
213 
214  forAll(timeDirs, timei)
215  {
216  runTime.setTime(timeDirs[timei], timei);
217 
218  Info<< "Time = " << runTime.timeName() << endl;
219 
220  switch (mesh.readUpdate())
221  {
223  {
224  functionsPtr->movePoints(mesh);
225  break;
226  }
229  {
230  mapPolyMesh mpm(mesh);
231  functionsPtr->updateMesh(mpm);
232  break;
233  }
234  case polyMesh::UNCHANGED:
235  {
236  // No additional work
237  break;
238  }
239  default:
240  {
242  << "Unhandled enumeration"
243  << abort(FatalError);
244  }
245  }
246 
247  fields.resetFieldFilters(fieldFilters);
248 
249  fields.updateSelection();
250 
251  const bool oldThrowingIOErr = FatalIOError.throwing(true);
252 
253  try
254  {
255  executeFunctionObjects
256  (
257  args,
258  runTime,
259  mesh,
260  fields.selectionNames(),
261  functionsPtr(),
262  timei == timeDirs.size()-1
263  );
264 
265  // Report to output (avoid overwriting values from simulation)
267  }
268  catch (const Foam::IOerror& err)
269  {
270  Warning << err << endl;
271  }
272 
273  Info<< endl;
274 
275  // Restore previous exception throwing state
276  FatalIOError.throwing(oldThrowingIOErr);
277  }
278 
279  Info<< "End\n" << endl;
280 
281  return 0;
282 }
283 
284 
285 // ************************************************************************* //
Foam::surfaceFields.
A HashTable with keys but without contents that is similar to std::unordered_set. ...
Definition: HashSet.H:73
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:129
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:50
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:218
Various UniformDimensionedField types.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< T > getList(const label index) const
Get a List of values from the argument at index.
Required Classes.
Field reading functions for post-processing utilities.
bool contains(const T &val) const
True if the value is contained in the list.
Definition: UListI.H:300
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:421
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
Required Classes.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:704
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
A class for handling words, derived from Foam::string.
Definition: word.H:63
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:935
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:370
Helper class to manage file-based field selections.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
static bool print(Ostream &os)
Print profiling information to specified output.
Definition: profiling.C:119
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
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:78
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
bool execute(bool writeProperties=true)
Called at each ++ or += of the time-loop.
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:590
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 ...