postProcess.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2016 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 functionsDict;
98 
99  HashSet<word> selectedFields;
100 
101  // Construct functionObjectList
102  autoPtr<functionObjectList> functionsPtr
103  (
104  functionObjectList::New(args, runTime, functionsDict, selectedFields)
105  );
106 
107  forAll(timeDirs, timei)
108  {
109  runTime.setTime(timeDirs[timei], timei);
110 
111  Info<< "Time = " << runTime.timeName() << endl;
112 
113  if (mesh.readUpdate() != polyMesh::UNCHANGED)
114  {
115  // Update functionObjects if mesh changes
116  functionsPtr = functionObjectList::New
117  (
118  args,
119  runTime,
120  functionsDict,
121  selectedFields
122  );
123  }
124 
126 
127  try
128  {
129  #include INCLUDE_FILE(CREATE_FIELDS)
130 
131  #ifdef CREATE_FIELDS_2
132  #include INCLUDE_FILE(CREATE_FIELDS_2)
133  #endif
134 
135  #ifdef CREATE_FIELDS_3
136  #include INCLUDE_FILE(CREATE_FIELDS_3)
137  #endif
138 
139  functionsPtr->execute();
140 
141  // Execute the functionObject 'end()' function for the last time
142  if (timei == timeDirs.size()-1)
143  {
144  functionsPtr->end();
145  }
146  }
147  catch (IOerror& err)
148  {
149  Warning<< err << endl;
150  }
151 
152  Info<< endl;
153  }
154 
155  Info<< "End\n" << endl;
156 
157  return 0;
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #undef INCLUDE_FILE
164 #undef INCLUDE_FILE2
165 
166 #undef CREATE_MESH
167 #undef CREATE_FIELDS
168 #undef CREATE_CONTROL
169 
170 // ************************************************************************* //
#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:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
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:83
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