All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SolverPerformance.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::SolverPerformance
26 
27 Description
28  SolverPerformance is the class returned by the LduMatrix solver
29  containing performance statistics.
30 
31 SourceFiles
32  SolverPerformance.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef SolverPerformance_H
37 #define SolverPerformance_H
38 
39 #include "word.H"
40 #include "FixedList.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of friend functions and operators
48 
49 template<class Type>
50 class SolverPerformance;
51 
52 template<class Type>
54 (
57 );
58 
59 template<class Type>
60 Istream& operator>>
61 (
62  Istream&,
64 );
65 
66 template<class Type>
67 Ostream& operator<<
68 (
69  Ostream&,
71 );
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class SolverPerformance Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type>
80 {
81  // Label type corresponding to Type
82  typedef typename pTraits<Type>::labelType labelType;
83 
84  // Private Data
85 
86  word solverName_;
87  word fieldName_;
88  Type initialResidual_;
89  Type finalResidual_;
90  labelType nIterations_;
91  bool converged_;
93 
94 
95 public:
96 
97  // Static data
98 
99  // Declare name of the class and its debug switch
100  ClassName("SolverPerformance");
101 
102  //- Large Type for the use in solvers
103  static const scalar great_;
104 
105  //- Small Type for the use in solvers
106  static const scalar small_;
107 
108  //- Very small Type for the use in solvers
109  static const scalar vsmall_;
110 
111 
112  // Constructors
115  :
116  initialResidual_(Zero),
117  finalResidual_(Zero),
118  nIterations_(Zero),
119  converged_(false),
120  singular_(false)
121  {}
122 
123 
125  (
126  const word& solverName,
127  const word& fieldName,
128  const Type& iRes = pTraits<Type>::zero,
129  const Type& fRes = pTraits<Type>::zero,
130  const labelType& nIter = pTraits<labelType>::zero,
131  const bool converged = false,
132  const bool singular = false
133  )
134  :
135  solverName_(solverName),
136  fieldName_(fieldName),
137  initialResidual_(iRes),
138  finalResidual_(fRes),
139  nIterations_(nIter),
140  converged_(converged),
141  singular_(singular)
142  {}
143 
144 
145  // Member Functions
146 
147  //- Return solver name
148  const word& solverName() const
149  {
150  return solverName_;
151  }
152 
153  //- Return solver name
154  word& solverName()
155  {
156  return solverName_;
157  }
158 
159 
160  //- Return field name
161  const word& fieldName() const
162  {
163  return fieldName_;
164  }
165 
166 
167  //- Return initial residual
168  const Type& initialResidual() const
169  {
170  return initialResidual_;
171  }
172 
173  //- Return initial residual
174  Type& initialResidual()
175  {
176  return initialResidual_;
177  }
178 
179 
180  //- Return final residual
181  const Type& finalResidual() const
182  {
183  return finalResidual_;
184  }
185 
186  //- Return final residual
187  Type& finalResidual()
188  {
189  return finalResidual_;
190  }
191 
192 
193  //- Return number of iterations
194  const labelType& nIterations() const
195  {
196  return nIterations_;
197  }
198 
199  //- Return number of iterations
200  labelType& nIterations()
201  {
202  return nIterations_;
203  }
204 
205 
206  //- Has the solver converged?
207  bool converged() const
208  {
209  return converged_;
210  }
211 
212  //- Is the matrix singular?
213  bool singular() const;
214 
215  //- Check, store and return convergence
216  bool checkConvergence
217  (
218  const Type& tolerance,
219  const Type& relTolerance
220  );
221 
222  //- Singularity test
223  bool checkSingularity(const Type& residual);
224 
225  //- Print summary of solver performance to the given stream
226  void print(Ostream& os) const;
227 
228  //- Replace component based on the minimal SolverPerformance
229  void replace
230  (
231  const label cmpt,
232  const SolverPerformance<typename pTraits<Type>::cmptType>& sp
233  );
234 
235  //- Return the summary maximum of SolverPerformance<Type>
236  // Effectively it will mostly return solverPerformanceScalar
238 
239 
240  // Member Operators
241 
242  bool operator!=(const SolverPerformance<Type>&) const;
243 
244 
245  // Friend Functions
246 
247  //- Return the element-wise maximum of two SolverPerformance<Type>s
248  friend SolverPerformance<Type> Foam::max <Type>
249  (
251  const SolverPerformance<Type>&
252  );
253 
254 
255  // Ostream Operator
256 
257  friend Istream& operator>> <Type>
258  (
259  Istream&,
260  SolverPerformance<Type>&
261  );
262 
263  friend Ostream& operator<< <Type>
264  (
265  Ostream&,
266  const SolverPerformance<Type>&
267  );
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 #define makeSolverPerformance(Type) \
278  \
279 typedef Foam::SolverPerformance<Type> \
280  solverPerformance##Type; \
281  \
282 defineNamedTemplateTypeNameAndDebug(solverPerformance##Type, 0); \
283  \
284 template<> \
285 const scalar solverPerformance##Type::great_(1e20); \
286  \
287 template<> \
288 const scalar solverPerformance##Type::small_(1e-20); \
289  \
290 template<> \
291 const scalar solverPerformance##Type::vsmall_(vSmall); \
292 
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #ifdef NoRepository
297  #include "SolverPerformance.C"
298 #endif
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const labelType & nIterations() const
Return number of iterations.
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static const scalar small_
Small Type for the use in solvers.
const word & fieldName() const
Return field name.
const word & solverName() const
Return solver name.
Traits class for primitives.
Definition: pTraits.H:50
bool converged() const
Has the solver converged?
bool checkSingularity(const Type &residual)
Singularity test.
const Type & finalResidual() const
Return final residual.
static const scalar great_
Large Type for the use in solvers.
bool checkConvergence(const Type &tolerance, const Type &relTolerance)
Check, store and return convergence.
const Type & initialResidual() const
Return initial residual.
A class for handling words, derived from string.
Definition: word.H:59
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
static const zero Zero
Definition: zero.H:97
bool operator!=(const SolverPerformance< Type > &) const
void print(Ostream &os) const
Print summary of solver performance to the given stream.
ClassName("SolverPerformance")
static const scalar vsmall_
Very small Type for the use in solvers.
SolverPerformance< typename pTraits< Type >::cmptType > max()
Return the summary maximum of SolverPerformance<Type>
bool singular() const
Is the matrix singular?
void replace(const label cmpt, const SolverPerformance< typename pTraits< Type >::cmptType > &sp)
Replace component based on the minimal SolverPerformance.
Namespace for OpenFOAM.