Loading...
Searching...
No Matches
foamReport.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::functionObjects::foamReport
28
29Group
30 grpUtilitiesFunctionObjects
31
32Description
33 Replaces user-supplied keywords by run-time computed values in a text file.
34
35 Operands:
36 \table
37 Operand | Type | Location
38 input | - | -
39 output file | TBA | postProcessing/<FO>/<time>/<file>(s)
40 \endtable
41
42Usage
43 Example using \c system/controlDict.functions:
44 \verbatim
45 foamReportFO
46 {
47 // Mandatory entries
48 type foamReport;
49 libs (utilityFunctionObjects);
50
51 template "<system>/myTemplate.md";
52
53 substitutions
54 {
55 divSchemes1
56 {
57 type dictionaryValue;
58 object fvSchemes;
59
60 entries
61 {
62 divSchemes "divSchemes";
63 }
64 }
65 fvSolution1
66 {
67 type dictionaryValue;
68 path "<system>/fvSolution";
69
70 entries
71 {
72 solver_p "solvers/p/solver";
73 solver_p_tol "solvers/p/tolerance";
74 solver_p_reltol "solvers/p/relTol";
75 solver_U "solvers/U/solver";
76 solver_U_tol "solvers/U/tolerance";
77 solver_U_reltol "solvers/U/relTol";
78 }
79 }
80 controlDict1
81 {
82 type dictionaryValue;
83 path "<system>/controlDict";
84
85 entries
86 {
87 initial_deltaT "deltaT";
88 }
89 }
90 continuityErrors
91 {
92 type functionObjectValue;
93 functionObject continuityError1;
94
95 entries
96 {
97 cont_error_local local;
98 cont_error_global global;
99 cont_error_cumulative cumulative;
100 }
101 }
102 }
103
104 // Optional entries
105 debugKeys <bool>;
106
107 // Inherited entries
108 ...
109 }
110 \endverbatim
111
112 where the entries mean:
113 \table
114 Property | Description | Type | Reqd | Deflt
115 type | Type name: foamReport | word | yes | -
116 libs | Library name: utilityFunctionObjects | word | yes | -
117 template | Path to user-supplied text template | string | yes | -
118 substitutions | Dictionary of substitution models | dictionary | yes | -
119 debugKeys | Flag to write all known keys | bool | no | false
120 \endtable
121
122 The \c entries sections typically define a dictionary of keys (to use in
123 your template) and method to set the key value, e.g. for a dictionaryValue
124 model used to set values from the \c fvSolution file:
125
126 \verbatim
127 type dictionaryValue;
128 path "<system>/fvSolution";
129
130 entries
131 {
132 solver_p "solvers/p/solver";
133 solver_p_tol "solvers/p/tolerance";
134 }
135 \endverbatim
136
137 The inherited entries are elaborated in:
138 - \link substitutionModel.H \endlink
139 - \link stateFunctionObject.H \endlink
140 - \link writeFile.H \endlink
141
142See also
143 - Foam::functionObject
144 - Foam::functionObjects::stateFunctionObject
145 - Foam::functionObjects::writeFile
146 - Foam::substitutionModel
147
148SourceFiles
149 foamReport.C
150 foamReportTemplates.C
151
152\*---------------------------------------------------------------------------*/
153
154#ifndef Foam_functionObjects_foamReport_H
155#define Foam_functionObjects_foamReport_H
156
157#include "stateFunctionObject.H"
158#include "writeFile.H"
159#include "Tuple2.H"
160
161// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162
163namespace Foam
164{
165
167
168namespace functionObjects
169{
170
171/*---------------------------------------------------------------------------*\
172 Class foamReport Declaration
173\*---------------------------------------------------------------------------*/
174
175class foamReport
176:
177 public stateFunctionObject,
178 public writeFile
179{
180
181protected:
182
183 // Protected Data
184
185 //- Path to user-supplied template
186 fileName templateFile_;
187
188 //- Mapping from keyword to substitution model index and line
189 //- numbers of template file where keyword is used
190 HashTable<Tuple2<label, DynamicList<label>>> modelKeys_;
191
192 //- Template file contents split into lines
193 List<string> templateContents_;
194
195 //- List of substitution models
196 PtrList<substitutionModel> substitutions_;
197
198 //- Debug flag to write all known keys
199 // Helps when assembling template file...
200 bool debugKeys_;
201
202
203 // Protected Member Functions
204
205 //- Parse the template and collect keyword information
206 bool parseTemplate(const fileName& fName);
207
208 //- Set static builtin entries
209 void setStaticBuiltins();
210
211 //- Set dynamic (potentially changing per execution step) builtin
212 //- entries
213 void setDynamicBuiltins();
214
215 //- Apply the substitution models to the template
216 bool apply(Ostream& os) const;
217
219 // Generated Methods
220
221 //- No copy construct
222 foamReport(const foamReport&) = delete;
223
224 //- No copy assignment
225 void operator=(const foamReport&) = delete;
226
227
228public:
229
230 //- Runtime type information
231 TypeName("foamReport");
232
233
234 // Constructors
235
236 //- Construct from name, Time and dictionary
238 (
239 const word& name,
240 const Time& runTime,
241 const dictionary& dict
242 );
243
244
245 //- Destructor
246 virtual ~foamReport() = default;
248
249 // Member Functions
250
251 //- Read the function-object dictionary
252 virtual bool read(const dictionary&);
253
254 //- Execute the function-object operations
255 virtual bool execute();
256
257 //- Write the function-object results
258 virtual bool write();
259};
260
261
262// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263
264} // End namespace functionObjects
265} // End namespace Foam
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269#endif
270
271// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class for handling file names.
Definition fileName.H:75
const word & name() const noexcept
Return the name of this functionObject.
Replaces user-supplied keywords by run-time computed values in a text file.
Definition foamReport.H:222
void setStaticBuiltins()
Set static builtin entries.
Definition foamReport.C:47
void operator=(const foamReport &)=delete
No copy assignment.
HashTable< Tuple2< label, DynamicList< label > > > modelKeys_
Mapping from keyword to substitution model index and line numbers of template file where keyword is u...
Definition foamReport.H:237
PtrList< substitutionModel > substitutions_
List of substitution models.
Definition foamReport.H:247
void setDynamicBuiltins()
Set dynamic (potentially changing per execution step) builtin entries.
Definition foamReport.C:128
bool debugKeys_
Debug flag to write all known keys.
Definition foamReport.H:254
foamReport(const foamReport &)=delete
No copy construct.
List< string > templateContents_
Template file contents split into lines.
Definition foamReport.H:242
bool parseTemplate(const fileName &fName)
Parse the template and collect keyword information.
Definition foamReport.C:144
fileName templateFile_
Path to user-supplied template.
Definition foamReport.H:231
virtual ~foamReport()=default
Destructor.
bool apply(Ostream &os) const
Apply the substitution models to the template.
Definition foamReport.C:206
virtual bool execute()
Execute the function-object operations.
Definition foamReport.C:321
TypeName("foamReport")
Runtime type information.
virtual bool write()
Write the function-object results.
Definition foamReport.C:332
virtual bool read(const dictionary &)
Read the function-object dictionary.
Definition foamReport.C:269
Base class for function objects, adding functionality to read/write state information (data required ...
stateFunctionObject(const stateFunctionObject &)=delete
No copy construct.
Base class for writing single files from the function objects.
Definition writeFile.H:113
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
Base class for substitution models.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68