postProcess.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Global
25  postProcess
26 
27 Description
28  Execute application functionObjects to post-process existing results.
29 
30  If the "dict" argument is specified the functionObjectList is constructed
31  from that dictionary otherwise the functionObjectList is constructed from
32  the "functions" sub-dictionary of "system/controlDict"
33 
34  Multiple time-steps may be processed and the standard utility time
35  controls are provided.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 #ifndef CREATE_TIME
42  #define CREATE_TIME createTime.H
43 #endif
44 
45 #ifndef CREATE_MESH
46  #define CREATE_MESH createMesh.H
47 #endif
48 
49 #ifndef CREATE_FIELDS
50  #define CREATE_FIELDS createFields.H
51 #endif
52 
53 #ifndef CREATE_CONTROL
54  #define CREATE_CONTROL createControl.H
55 #endif
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 #define INCLUDE_FILE(X) INCLUDE_FILE2(X)
60 #define INCLUDE_FILE2(X) #X
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
65 (
66  argList::postProcessOptionName,
67  "Execute functionObjects only"
68 );
69 
70 if (argList::postProcess(argc, argv))
71 {
73  #include "addRegionOption.H"
75 
76  // Set functionObject post-processing mode
77  functionObject::postProcess = true;
78 
79  #include "setRootCase.H"
80 
81  if (args.optionFound("list"))
82  {
83  functionObjectList::list();
84  return 0;
85  }
86 
87  #include INCLUDE_FILE(CREATE_TIME)
89  #include INCLUDE_FILE(CREATE_MESH)
90 
91  #ifndef NO_CONTROL
92  #include INCLUDE_FILE(CREATE_CONTROL)
93  #endif
94 
95  // Externally stored dictionary for functionObjectList
96  // if not constructed from runTime
97  dictionary functionsControlDict("controlDict");
98 
99  HashSet<word> selectedFields;
100 
101  // Construct functionObjectList
102  autoPtr<functionObjectList> functionsPtr
103  (
105  (
106  args,
107  runTime,
108  functionsControlDict,
109  selectedFields
110  )
111  );
112 
113  forAll(timeDirs, timei)
114  {
115  runTime.setTime(timeDirs[timei], timei);
116 
117  Info<< "Time = " << runTime.timeName() << endl;
118 
119  if (mesh.readUpdate() != polyMesh::UNCHANGED)
120  {
121  // Update functionObjects if mesh changes
122  functionsPtr = functionObjectList::New
123  (
124  args,
125  runTime,
126  functionsControlDict,
127  selectedFields
128  );
129  }
130 
132 
133  try
134  {
135  #include INCLUDE_FILE(CREATE_FIELDS)
136 
137  #ifdef CREATE_FIELDS_2
138  #include INCLUDE_FILE(CREATE_FIELDS_2)
139  #endif
140 
141  #ifdef CREATE_FIELDS_3
142  #include INCLUDE_FILE(CREATE_FIELDS_3)
143  #endif
144 
145  functionsPtr->execute();
146 
147  // Execute the functionObject 'end()' function for the last time
148  if (timei == timeDirs.size()-1)
149  {
150  functionsPtr->end();
151  }
152  }
153  catch (IOerror& err)
154  {
155  Warning<< err << endl;
156  }
157 
158  // Clear the objects owned by the mesh
159  mesh.objectRegistry::clear();
160 
161  Info<< endl;
162  }
163 
164  Info<< "End\n" << endl;
165 
166  return 0;
167 }
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #undef INCLUDE_FILE
173 #undef INCLUDE_FILE2
174 
175 #undef CREATE_MESH
176 #undef CREATE_FIELDS
177 #undef CREATE_CONTROL
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
dynamicFvMesh & mesh
static instantList timeDirs
Definition: globalFoam.H:44
void throwExceptions()
Definition: error.H:122
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:257
messageStream Warning
messageStream Info
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:110
Foam::argList args(argc, argv)
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
IOerror FatalIOError