solverInfo.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) 2015-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::functionObjects::solverInfo
29 
30 Group
31  grpUtilitiesFunctionObjects
32 
33 Description
34  Writes solver information for a list of user-specified fields.
35 
36  Information written to file includes:
37  - residual fields
38  - solver type
39  - initial residual
40  - final residual
41  - number of solver iterations
42  - convergence flag
43 
44  Operands:
45  \table
46  Operand | Type | Location
47  input | - | -
48  output file | dat <!--
49  --> | postProcessing/<FO>/<time>/<file>(s)
50  output field | volScalarField(s) <!--
51  --> | <time>/initialResiduals:<outField>(s)
52  \endtable
53 
54 Usage
55  Minimal example by using \c system/controlDict.functions:
56  \verbatim
57  solverInfo1
58  {
59  // Mandatory entries (unmodifiable)
60  type solverInfo;
61  libs (utilityFunctionObjects);
62 
63  // Mandatory entries (runtime modifiable)
64  fields (<field1> <field2> ... <fieldN>);
65 
66  // Optional entries (runtime modifiable)
67  writeResidualFields true;
68 
69  // Inherited entries
70  ...
71  }
72  \endverbatim
73 
74  where the entries mean:
75  \table
76  Property | Description | Type | Reqd | Deflt
77  type | Type name: solverInfo | word | yes | -
78  libs | Library name: utilityFunctionObjects | word | yes | -
79  fields | Names of operand fields | wordList | yes | -
80  writeResidualFields | Flag to write the initial-residual fields <!--
81  --> | bool | no | false
82  \endtable
83 
84  The inherited entries are elaborated in:
85  - \link functionObject.H \endlink
86  - \link writeFile.H \endlink
87 
88 See also
89  - Foam::functionObject
90  - Foam::functionObjects::fvMeshFunctionObject
91  - Foam::functionObjects::writeFile
92 
93 SourceFiles
94  solverInfo.C
95  solverInfoTemplates.C
96 
97 \*---------------------------------------------------------------------------*/
98 
99 #ifndef functionObjects_solverInfo_H
100 #define functionObjects_solverInfo_H
101 
102 #include "fvMeshFunctionObject.H"
103 #include "writeFile.H"
104 #include "solverFieldSelection.H"
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
108 namespace Foam
109 {
110 namespace functionObjects
111 {
112 
113 /*---------------------------------------------------------------------------*\
114  Class solverInfo Declaration
115 \*---------------------------------------------------------------------------*/
116 
117 class solverInfo
118 :
119  public fvMeshFunctionObject,
120  public writeFile
121 {
122 protected:
123 
124  // Protected Data
125 
126  //- Names of operand fields
127  solverFieldSelection fieldSet_;
128 
129  //- Names of (result) residual fields
131 
132  //- Flag to write the initial-residual as a vol field
134 
135  //- Initialisation flag
136  bool initialised_;
137 
138 
139  // Protected Member Functions
140 
141  //- Output file header information
142  void writeFileHeader(Ostream& os);
143 
144  //- Create and store a residual field on the mesh database
145  void createResidualField(const word& fieldName);
146 
147  //- Output file header information per primitive type value
148  template<class Type>
149  void writeFileHeader(Ostream& os, const word& fileName) const;
150 
151  //- Initialise a residual field
152  template<class Type>
153  void initialiseResidualField(const word& fieldName);
154 
155  //- Calculate the solver information
156  template<class Type>
157  void updateSolverInfo(const word& fieldName);
158 
159 
160  // Generated Methods
161 
162  //- No copy construct
163  solverInfo(const solverInfo&) = delete;
165  //- No copy assignment
166  void operator=(const solverInfo&) = delete;
167 
168 
169 public:
170 
171  //- Runtime type information
172  TypeName("solverInfo");
173 
174 
175  // Constructors
177  //- Construct from Time and dictionary
178  solverInfo
179  (
180  const word& name,
181  const Time& runTime,
182  const dictionary& dict
183  );
184 
185 
186  //- Destructor
187  virtual ~solverInfo() = default;
188 
189 
190  // Member Functions
192  //- Read solverInfo settings
193  virtual bool read(const dictionary&);
194 
195  //- Execute solverInfo
196  virtual bool execute();
197 
198  //- Write solverInfo results
199  virtual bool write();
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace functionObjects
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #ifdef NoRepository
211  #include "solverInfoTemplates.C"
212 #endif
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
bool initialised_
Initialisation flag.
Definition: solverInfo.H:191
dictionary dict
virtual ~solverInfo()=default
Destructor.
Writes solver information for a list of user-specified fields.
Definition: solverInfo.H:164
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool execute()
Execute solverInfo.
Definition: solverInfo.C:154
const word & name() const noexcept
Return the name of this functionObject.
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:39
A class for handling words, derived from Foam::string.
Definition: word.H:63
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
bool writeResidualFields_
Flag to write the initial-residual as a vol field.
Definition: solverInfo.H:186
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:73
wordHashSet residualFieldNames_
Names of (result) residual fields.
Definition: solverInfo.H:181
OBJstream os(runTime.globalPath()/outputName)
void operator=(const solverInfo &)=delete
No copy assignment.
solverFieldSelection fieldSet_
Names of operand fields.
Definition: solverInfo.H:176
TypeName("solverInfo")
Runtime type information.
void createResidualField(const word &fieldName)
Create and store a residual field on the mesh database.
Definition: solverInfo.C:73
solverInfo(const solverInfo &)=delete
No copy construct.
virtual bool write()
Write solverInfo results.
Definition: solverInfo.C:194
Namespace for OpenFOAM.
virtual bool read(const dictionary &)
Read solverInfo settings.
Definition: solverInfo.C:135