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;
164 
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
176 
177  //- Construct from Time and dictionary
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
191 
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
writeFile.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::solverInfo::read
virtual bool read(const dictionary &)
Read solverInfo settings.
Definition: solverInfo.C:139
solverInfoTemplates.C
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
fvMeshFunctionObject.H
Foam::functionObjects::solverInfo::initialiseResidualField
void initialiseResidualField(const word &fieldName)
Initialise a residual field.
Definition: solverInfoTemplates.C:74
solverFieldSelection.H
Foam::functionObjects::solverFieldSelection
Definition: solverFieldSelection.H:52
Foam::functionObjects::solverInfo::updateSolverInfo
void updateSolverInfo(const word &fieldName)
Calculate the solver information.
Definition: solverInfoTemplates.C:109
Foam::HashSet< word, Hash< word > >
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::solverInfo
Writes solver information for a list of user-specified fields.
Definition: solverInfo.H:168
Foam::functionObjects::solverInfo::execute
virtual bool execute()
Execute solverInfo.
Definition: solverInfo.C:158
Foam::functionObjects::solverInfo::writeResidualFields_
bool writeResidualFields_
Flag to write the initial-residual as a vol field.
Definition: solverInfo.H:184
Foam::functionObjects::solverInfo::TypeName
TypeName("solverInfo")
Runtime type information.
Foam::functionObjects::solverInfo::residualFieldNames_
wordHashSet residualFieldNames_
Names of (result) residual fields.
Definition: solverInfo.H:181
Foam::functionObjects::solverInfo::solverInfo
solverInfo(const solverInfo &)=delete
No copy construct.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::solverInfo::writeFileHeader
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:46
Foam::functionObjects::solverInfo::initialised_
bool initialised_
Initialisation flag.
Definition: solverInfo.H:187
Foam::functionObjects::solverInfo::write
virtual bool write()
Write solverInfo results.
Definition: solverInfo.C:198
Foam::functionObjects::solverInfo::~solverInfo
virtual ~solverInfo()=default
Destructor.
Foam::functionObjects::solverInfo::fieldSet_
solverFieldSelection fieldSet_
Names of operand fields.
Definition: solverInfo.H:178
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::solverInfo::operator=
void operator=(const solverInfo &)=delete
No copy assignment.
Foam::functionObjects::solverInfo::createResidualField
void createResidualField(const word &fieldName)
Create and store a residual field on the mesh database.
Definition: solverInfo.C:80