data.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2023 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::data
29 
30 Description
31  Database for solution data, solver performance and other reduced data.
32 
33  Both faMesh and fvMesh are derived from this class so that every
34  GeometricField has access to this data via their mesh reference.
35 
36 SourceFiles
37  data.C
38  dataTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_data_H
43 #define Foam_data_H
44 
45 #include "IOdictionary.H"
46 #include "solverPerformance.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class data Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class data
58 :
59  public IOdictionary
60 {
61  // Private Data
62 
63  //- Previously used time-index, used for reset between iterations
64  mutable label prevTimeIndex_;
65 
66 
67  // Private Member Functions
68 
69  //- True if boolean entry exists and is set
70  bool getBoolEntry(const word& keyword) const
71  {
72  bool value = false;
73  return readIfPresent(keyword, value) && value;
74  }
75 
76  //- Add/remove boolean entry
77  void setBoolEntry(const word& keyword, bool on)
78  {
79  if (on)
80  {
81  add(keyword, true);
82  }
83  else
84  {
85  remove(keyword);
86  }
87  }
88 
89  //- No copy construct
90  data(const data&) = delete;
91 
92  //- No copy assignment
93  void operator=(const data&) = delete;
94 
95 public:
96 
97  // Constructors
98 
99  //- Construct for objectRegistry (registered with specified name)
100  //- optionally with initial content
101  data
102  (
103  const word& name,
104  const objectRegistry& obr,
105  const dictionary* content = nullptr
106  );
107 
108  //- Construct for objectRegistry (registered as "data")
109  explicit data(const objectRegistry& obr)
110  :
111  data("data", obr)
112  {}
113 
114  //- Construct for objectRegistry (registered with specified name)
115  //- copying initial content
116  data
117  (
118  const word& name,
119  const objectRegistry& obr,
120  const dictionary& dict
121  )
122  :
123  data(name, obr, &dict)
124  {}
125 
126  //- Construct for objectRegistry (registered as "data")
127  //- copying initial content
128  data(const objectRegistry& obr, const dictionary& dict)
129  :
130  data("data", obr, &dict)
131  {}
132 
133 
134  // Member Functions
135 
136  //- Return the dictionary of solver performance data which
137  //- includes initial and final residuals for convergence checking
138  const dictionary& solverPerformanceDict() const;
139 
140  //- True if "firstIteration" entry exists and is set
141  bool isFirstIteration() const
142  {
143  return getBoolEntry("firstIteration");
144  }
145 
146  //- True if "finalIteration" entry exists and is set
147  bool isFinalIteration() const
148  {
149  return getBoolEntry("finalIteration");
150  }
151 
152  //- Add/remove "firstIteration" entry
153  void isFirstIteration(bool on)
154  {
155  return setBoolEntry("firstIteration", on);
156  }
157 
158  //- Add/remove "finalIteration" entry
159  void isFinalIteration(bool on)
160  {
161  return setBoolEntry("finalIteration", on);
162  }
163 
164 
165  //- Add/set the solverPerformance entry for the named field
166  template<class Type>
168  (
169  const word& name,
170  const SolverPerformance<Type>& sp
171  ) const;
172 
173  //- Add/set the solverPerformance entry, using its fieldName
174  template<class Type>
176  (
177  const SolverPerformance<Type>& sp
178  ) const;
179 };
180 
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 } // End namespace Foam
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #ifdef NoRepository
189  #include "dataTemplates.C"
190 #endif
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
195 
196 // ************************************************************************* //
void setSolverPerformance(const word &name, const SolverPerformance< Type > &sp) const
Add/set the solverPerformance entry for the named field.
Definition: dataTemplates.C:29
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const dictionary & solverPerformanceDict() const
Return the dictionary of solver performance data which includes initial and final residuals for conve...
Definition: data.C:58
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:637
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
bool isFinalIteration() const
True if "finalIteration" entry exists and is set.
Definition: data.H:166
A class for handling words, derived from Foam::string.
Definition: word.H:63
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
bool isFirstIteration() const
True if "firstIteration" entry exists and is set.
Definition: data.H:158
Registry of regIOobjects.
Namespace for OpenFOAM.