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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::functionObjects::foamReport
28 
29 Group
30  grpUtilitiesFunctionObjects
31 
32 Description
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 <!--
40  --> | postProcessing/<FO>/<time>/<file>(s)
41  \endtable
42 
43 Usage
44  Example using \c system/controlDict.functions:
45 
46  \verbatim
47  foamReport1
48  {
49  // Mandatory entries
50  type foamReport;
51  libs (utilityFunctionObjects);
52 
53  template "<system>/myTemplate.md";
54 
55  substitutions
56  {
57  divSchemes1
58  {
59  type dictionaryValue;
60  object fvSchemes;
61 
62  entries
63  {
64  divSchemes "divSchemes";
65  }
66  }
67  fvSolution1
68  {
69  type dictionaryValue;
70  path "<system>/fvSolution";
71 
72  entries
73  {
74  solver_p "solvers/p/solver";
75  solver_p_tol "solvers/p/tolerance";
76  solver_p_reltol "solvers/p/relTol";
77  solver_U "solvers/U/solver";
78  solver_U_tol "solvers/U/tolerance";
79  solver_U_reltol "solvers/U/relTol";
80  }
81  }
82  controlDict1
83  {
84  type dictionaryValue;
85  path "<system>/controlDict";
86 
87  entries
88  {
89  initial_deltaT "deltaT";
90  }
91  }
92  continuityErrors
93  {
94  type functionObjectValue;
95  functionObject continuityError1;
96 
97  entries
98  {
99  cont_error_local local;
100  cont_error_global global;
101  cont_error_cumulative cumulative;
102  }
103  }
104  }
105 
106  // Optional entries
107  debugKeys <bool>;
108 
109  // Inherited entries
110  ...
111  }
112  \endverbatim
113 
114  where the entries mean:
115  \table
116  Property | Description | Type | Reqd | Deflt
117  type | Type name: foamReport | word | yes | -
118  libs | Library name: utilityFunctionObjects | word | yes | -
119  template | Path to user-supplied text template | string | yes | -
120  substitutions | Dictionary of substitution models | dictionary | yes | -
121  debugKeys | Flag to write all known keys | bool | no | false
122  \endtable
123 
124  The \c entries sections typically define a dictionary of keys (to use in
125  your template) and method to set the key value, e.g. for a dictionaryValue
126  model used to set values from the \c fvSolution file:
127 
128  \verbatim
129  type dictionaryValue;
130  path "<system>/fvSolution";
131 
132  entries
133  {
134  solver_p "solvers/p/solver";
135  solver_p_tol "solvers/p/tolerance";
136  }
137  \endverbatim
138 
139  The inherited entries are elaborated in:
140  - \link substitutionModel.H \endlink
141  - \link stateFunctionObject.H \endlink
142  - \link writeFile.H \endlink
143 
144 See also
145  - Foam::functionObject
146  - Foam::functionObjects::stateFunctionObject
147  - Foam::functionObjects::writeFile
148  - Foam::substitutionModel
149 
150 SourceFiles
151  foamReport.C
152  foamReportTemplates.C
153 
154 \*---------------------------------------------------------------------------*/
155 
156 #ifndef functionObjects_foamReport_H
157 #define functionObjects_foamReport_H
158 
159 #include "stateFunctionObject.H"
160 #include "writeFile.H"
161 #include "Tuple2.H"
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 namespace Foam
166 {
167 
168 class substitutionModel;
169 
170 namespace functionObjects
171 {
172 
173 /*---------------------------------------------------------------------------*\
174  Class foamReport Declaration
175 \*---------------------------------------------------------------------------*/
176 
177 class foamReport
178 :
179  public stateFunctionObject,
180  public writeFile
181 {
182 
183 protected:
184 
185  // Protected Data
186 
187  //- Path to user-supplied template
188  fileName templateFile_;
189 
190  //- Mapping from keyword to substitution model index and line
191  //- numbers of template file where keyword is used
192  HashTable<Tuple2<label, DynamicList<label>>> modelKeys_;
193 
194  //- Template file contents split into lines
195  List<string> templateContents_;
196 
197  //- List of substitution models
198  PtrList<substitutionModel> substitutions_;
199 
200  //- Debug flag to write all known keys
201  // Helps when assembling template file...
202  bool debugKeys_;
203 
204 
205  // Protected Member Functions
206 
207  //- Parse the template and collect keyword information
208  bool parseTemplate(const fileName& fName);
209 
210  //- Set static builtin entries
211  void setStaticBuiltins();
212 
213  //- Set dynamic (potentially changing per execution step) builtin
214  //- entries
215  void setDynamicBuiltins();
216 
217  //- Apply the substitution models to the template
218  bool apply(Ostream& os) const;
219 
220 
221  // Generated Methods
223  //- No copy construct
224  foamReport(const foamReport&) = delete;
225 
226  //- No copy assignment
227  void operator=(const foamReport&) = delete;
228 
229 
230 public:
231 
232  //- Runtime type information
233  TypeName("foamReport");
234 
236  // Constructors
237 
238  //- Construct from Time and dictionary
239  foamReport
240  (
241  const word& name,
242  const Time& runTime,
243  const dictionary& dict
244  );
245 
247  //- Destructor
248  virtual ~foamReport() = default;
249 
250 
251  // Member Functions
252 
253  //- Read foamReport settings
254  virtual bool read(const dictionary&);
255 
256  //- Execute foamReport
257  virtual bool execute();
259  //- Write foamReport results
260  virtual bool write();
261 };
262 
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 } // End namespace functionObjects
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #endif
272 
273 // ************************************************************************* //
bool parseTemplate(const fileName &fName)
Parse the template and collect keyword information.
Definition: foamReport.C:124
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool debugKeys_
Debug flag to write all known keys.
Definition: foamReport.H:258
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool read(const dictionary &)
Read foamReport settings.
Definition: foamReport.C:249
const word & name() const noexcept
Return the name of this functionObject.
virtual bool execute()
Execute foamReport.
Definition: foamReport.C:301
void setStaticBuiltins()
Set static builtin entries.
Definition: foamReport.C:46
TypeName("foamReport")
Runtime type information.
virtual ~foamReport()=default
Destructor.
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:241
A class for handling words, derived from Foam::string.
Definition: word.H:63
PtrList< substitutionModel > substitutions_
List of substitution models.
Definition: foamReport.H:251
bool apply(Ostream &os) const
Apply the substitution models to the template.
Definition: foamReport.C:186
void setDynamicBuiltins()
Set dynamic (potentially changing per execution step) builtin entries.
Definition: foamReport.C:108
OBJstream os(runTime.globalPath()/outputName)
virtual bool write()
Write foamReport results.
Definition: foamReport.C:312
void operator=(const foamReport &)=delete
No copy assignment.
Replaces user-supplied keywords by run-time computed values in a text file.
Definition: foamReport.H:222
List< string > templateContents_
Template file contents split into lines.
Definition: foamReport.H:246
foamReport(const foamReport &)=delete
No copy construct.
fileName templateFile_
Path to user-supplied template.
Definition: foamReport.H:235
Namespace for OpenFOAM.