Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Application
28 postProcess
29
30Description
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
48using namespace Foam;
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52void 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);
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
153int 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"
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 }
235 {
236 // No additional work
237 break;
238 }
239 default:
240 {
241 FatalErrorIn(args.executable())
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// ************************************************************************* //
Field reading functions for post-processing utilities.
Required Classes.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
DimensionedField< scalar, volMesh > Internal
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition HashSet.H:96
Report an I/O error.
Definition error.H:370
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
bool contains(const T &val) const
True if the value is contained in the list.
Definition UListI.H:302
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
List of function objects with start(), execute() and end() functions that is called for each object.
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< wordRe > &requiredFields)
Construct and return a functionObjectList for an application.
static void list()
Print a list of functionObject configuration files in the directories located using Foam::findEtcDirs...
bool execute(bool writeProperties=true)
Called at each ++ or += of the time-loop.
bool end()
Called when Time::run() determines that the time-loop exits.
static bool postProcess
Global post-processing mode switch.
Helper class to manage file-based field selections.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Mesh representing a set of points created from polyMesh.
Definition pointMesh.H:49
static bool print(Ostream &os)
Print profiling information to specified output.
Definition profiling.C:119
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
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...
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
Required Classes.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition error.H:592
auto & name
Namespace for OpenFOAM.
UniformDimensionedField< sphericalTensor > uniformDimensionedSphericalTensorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
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< word > wordList
List of word.
Definition fileName.H:60
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
UniformDimensionedField< symmTensor > uniformDimensionedSymmTensorField
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
UniformDimensionedField< scalar > uniformDimensionedScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
List< instant > instantList
List of instants.
Definition instantList.H:41
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
UniformDimensionedField< tensor > uniformDimensionedTensorField
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
GeometricField< tensor, fvPatchField, volMesh > volTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
UniformDimensionedField< vector > uniformDimensionedVectorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
errorManip< error > abort(error &err)
Definition errorManip.H:139
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Foam::surfaceFields.
Various UniformDimensionedField types.