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-------------------------------------------------------------------------------
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
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
62void 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);
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
138int main(int argc, char *argv[])
139{
140 argList::addNote
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
147 timeSelector::addOptions();
148 #include "addProfilingOption.H"
149 #include "addRegionOption.H"
151
152 // Set functionObject post-processing mode
153 functionObject::postProcess = true;
154
155 #include "setRootCase.H"
156
157 if (args.found("list"))
158 {
159 functionObjectList::list();
160 return 0;
161 }
162
163 #include "createTime.H"
164 instantList timeDirs = timeSelector::select0(runTime, args);
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 (
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 (
190 functionObjectList::New
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 {
207 case polyMesh::POINTS_MOVED:
208 {
209 functionsPtr->movePoints(mesh);
210 break;
211 }
212 case polyMesh::TOPO_CHANGE:
213 case polyMesh::TOPO_PATCH_CHANGE:
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)
251 profiling::print(Info);
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// ************************************************************************* //
Field reading functions for post-processing utilities.
Report an I/O error.
Definition: error.H:282
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:54
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:90
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
List< T > getList(const label index) const
Get a List of values from the argument at index.
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:51
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:169
List of function objects with start(), execute() and end() functions that is called for each object.
bool execute()
Called at each ++ or += of the time-loop.
bool end()
Called when Time::run() determines that the time-loop exits.
Helper class to manage file-based field selections.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:55
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:448
Namespace for OpenFOAM.
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.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
IOerror FatalIOError
messageStream Warning
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Foam::surfaceFields.