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 | 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 Application
25  postProcess
26 
27 Description
28  Execute the set of functionObjects specified in the selected dictionary
29  (which defaults to system/controlDict) or on the command-line for the
30  selected set of times on the selected set of fields.
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #include "argList.H"
35 #include "timeSelector.H"
36 #include "ReadFields.H"
37 #include "volFields.H"
38 #include "surfaceFields.H"
39 #include "pointFields.H"
41 
42 using namespace Foam;
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 #define ReadFields(GeoFieldType) \
47  readFields<GeoFieldType>(mesh, objects, selectedFields, storedObjects);
48 
49 #define ReadPointFields(GeoFieldType) \
50  readFields<GeoFieldType>(pMesh, objects, selectedFields, storedObjects);
51 
52 #define ReadUniformFields(FieldType) \
53  readUniformFields<FieldType> \
54  (constantObjects, selectedFields, storedObjects);
55 
56 void executeFunctionObjects
57 (
58  const argList& args,
59  const Time& runTime,
60  fvMesh& mesh,
61  const HashSet<word>& selectedFields,
62  functionObjectList& functions,
63  bool lastTime
64 )
65 {
66  Info<< nl << "Reading fields:" << endl;
67 
68  // Maintain a stack of the stored objects to clear after executing
69  // the functionObjects
70  LIFOStack<regIOobject*> storedObjects;
71 
72  // Read objects in time directory
73  IOobjectList objects(mesh, runTime.timeName());
74 
75  // Read volFields
81 
82  // Read internal fields
88 
89  // Read surface fields
95 
96  // Read point fields.
97  const pointMesh& pMesh = pointMesh::New(mesh);
98 
99  ReadPointFields(pointScalarField)
100  ReadPointFields(pointVectorField);
101  ReadPointFields(pointSphericalTensorField);
102  ReadPointFields(pointSymmTensorField);
103  ReadPointFields(pointTensorField);
104 
105  // Read uniform dimensioned fields
106  IOobjectList constantObjects(mesh, runTime.constant());
107 
108  ReadUniformFields(uniformDimensionedScalarField);
109  ReadUniformFields(uniformDimensionedVectorField);
110  ReadUniformFields(uniformDimensionedSphericalTensorField);
111  ReadUniformFields(uniformDimensionedSymmTensorField);
112  ReadUniformFields(uniformDimensionedTensorField);
113 
114  Info<< nl << "Executing functionObjects" << endl;
115 
116  // Execute the functionObjects in post-processing mode
117  functions.execute();
118 
119  // Execute the functionObject 'end()' function for the last time
120  if (lastTime)
121  {
122  functions.end();
123  }
124 
125  while (!storedObjects.empty())
126  {
127  storedObjects.pop()->checkOut();
128  }
129 }
130 
131 
132 int main(int argc, char *argv[])
133 {
135  #include "addRegionOption.H"
136  #include "addFunctionObjectOptions.H"
137 
138  // Set functionObject post-processing mode
140 
141  #include "setRootCase.H"
142 
143  if (args.optionFound("list"))
144  {
146  return 0;
147  }
148 
149  #include "createTime.H"
150  Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
151  #include "createNamedMesh.H"
152 
153  // Initialize the set of selected fields from the command-line options
154  HashSet<word> selectedFields;
155  if (args.optionFound("fields"))
156  {
157  args.optionLookup("fields")() >> selectedFields;
158  }
159  if (args.optionFound("field"))
160  {
161  selectedFields.insert(args.optionLookup("field")());
162  }
163 
164  // Externally stored dictionary for functionObjectList
165  // if not constructed from runTime
166  dictionary functionsDict;
167 
168  // Construct functionObjectList
169  autoPtr<functionObjectList> functionsPtr
170  (
171  functionObjectList::New(args, runTime, functionsDict, selectedFields)
172  );
173 
174  forAll(timeDirs, timei)
175  {
176  runTime.setTime(timeDirs[timei], timei);
177 
178  Info<< "Time = " << runTime.timeName() << endl;
179 
180  if (mesh.readUpdate() != polyMesh::UNCHANGED)
181  {
182  // Update functionObjectList if mesh changes
183  functionsPtr = functionObjectList::New
184  (
185  args,
186  runTime,
187  functionsDict,
188  selectedFields
189  );
190  }
191 
193 
194  try
195  {
196  executeFunctionObjects
197  (
198  args,
199  runTime,
200  mesh,
201  selectedFields,
202  functionsPtr(),
203  timei == timeDirs.size()-1
204  );
205  }
206  catch (IOerror& err)
207  {
208  Warning<< err << endl;
209  }
210 
211  Info<< endl;
212  }
213 
214  Info<< "End\n" << endl;
215 
216  return 0;
217 }
218 
219 
220 // ************************************************************************* //
A LIFO stack based on a singly-linked list.
Definition: LIFOStack.H:51
Foam::surfaceFields.
A HashTable with keys but without contents.
Definition: HashSet.H:59
bool empty() const
Return true if the list is empty.
Definition: SLListBaseI.H:73
wordList ReadFields(const Mesh &mesh, const IOobjectList &objects, PtrList< GeoField > &fields, const bool syncPar=true)
Read all fields of the specified type.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
static bool postProcess
Global post-processing mode switch.
static void list()
Print a list of functionObject configuration files in.
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
Field reading functions for post-processing utilities.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:715
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static const pointMesh & New(const polyMesh &mesh)
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
if(args.optionReadIfPresent("region", regionName))
T pop()
Pop the top element off the stack.
Definition: LIFOStack.H:103
void throwExceptions()
Definition: error.H:122
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:924
List of function objects with start(), execute() and end() functions that is called for each object...
Report an I/O error.
Definition: error.H:196
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:302
static const char nl
Definition: Ostream.H:262
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
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...
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:114
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
static autoPtr< functionObjectList > New(const argList &args, const Time &runTime, dictionary &controlDict, HashSet< word > &requiredFields)
Construct and return a functionObjectList for an application.
bool end()
Called when Time::run() determines that the time-loop exits.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.
IOerror FatalIOError