SolverPerformance.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 | Copyright (C) 2012-2016 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  // Private data
82 
83  word solverName_;
84  word fieldName_;
85  Type initialResidual_;
86  Type finalResidual_;
87  label noIterations_;
88  bool converged_;
90 
91 
92 public:
93 
94  // Static data
95 
96  // Declare name of the class and its debug switch
97  ClassName("SolverPerformance");
98 
99  //- Large Type for the use in solvers
100  static const scalar great_;
101 
102  //- Small Type for the use in solvers
103  static const scalar small_;
104 
105  //- Very small Type for the use in solvers
106  static const scalar vsmall_;
107 
108 
109  // Constructors
112  :
113  initialResidual_(Zero),
114  finalResidual_(Zero),
115  noIterations_(0),
116  converged_(false),
117  singular_(false)
118  {}
119 
120 
122  (
123  const word& solverName,
124  const word& fieldName,
125  const Type& iRes = pTraits<Type>::zero,
126  const Type& fRes = pTraits<Type>::zero,
127  const label nIter = 0,
128  const bool converged = false,
129  const bool singular = false
130  )
131  :
132  solverName_(solverName),
133  fieldName_(fieldName),
134  initialResidual_(iRes),
135  finalResidual_(fRes),
136  noIterations_(nIter),
137  converged_(converged),
138  singular_(singular)
139  {}
140 
141 
142  // Member functions
143 
144  //- Return solver name
145  const word& solverName() const
146  {
147  return solverName_;
148  }
149 
150  //- Return solver name
151  word& solverName()
152  {
153  return solverName_;
154  }
155 
156 
157  //- Return field name
158  const word& fieldName() const
159  {
160  return fieldName_;
161  }
162 
163 
164  //- Return initial residual
165  const Type& initialResidual() const
166  {
167  return initialResidual_;
168  }
169 
170  //- Return initial residual
171  Type& initialResidual()
172  {
173  return initialResidual_;
174  }
175 
176 
177  //- Return final residual
178  const Type& finalResidual() const
179  {
180  return finalResidual_;
181  }
182 
183  //- Return final residual
184  Type& finalResidual()
185  {
186  return finalResidual_;
187  }
188 
189 
190  //- Return number of iterations
191  label nIterations() const
192  {
193  return noIterations_;
194  }
195 
196  //- Return number of iterations
197  label& nIterations()
198  {
199  return noIterations_;
200  }
201 
202 
203  //- Has the solver converged?
204  bool converged() const
205  {
206  return converged_;
207  }
208 
209  //- Is the matrix singular?
210  bool singular() const;
211 
212  //- Check, store and return convergence
213  bool checkConvergence
214  (
215  const Type& tolerance,
216  const Type& relTolerance
217  );
218 
219  //- Singularity test
220  bool checkSingularity(const Type& residual);
221 
222  //- Print summary of solver performance to the given stream
223  void print(Ostream& os) const;
224 
225  //- Replace component based on the minimal SolverPerformance
226  void replace
227  (
228  const label cmpt,
229  const SolverPerformance<typename pTraits<Type>::cmptType>& sp
230  );
231 
232  //- Return the summary maximum of SolverPerformance<Type>
233  // Effectively it will mostly return solverPerformanceScalar
235 
236 
237  // Member Operators
238 
239  bool operator!=(const SolverPerformance<Type>&) const;
240 
241 
242  // Friend functions
243 
244  //- Return the element-wise maximum of two SolverPerformance<Type>s
245  friend SolverPerformance<Type> Foam::max <Type>
246  (
248  const SolverPerformance<Type>&
249  );
250 
251 
252  // Ostream Operator
253 
254  friend Istream& operator>> <Type>
255  (
256  Istream&,
257  SolverPerformance<Type>&
258  );
259 
260  friend Ostream& operator<< <Type>
261  (
262  Ostream&,
263  const SolverPerformance<Type>&
264  );
265 };
266 
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 } // End namespace Foam
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 #define makeSolverPerformance(Type) \
275  \
276 typedef Foam::SolverPerformance<Type> \
277  solverPerformance##Type; \
278  \
279 defineNamedTemplateTypeNameAndDebug(solverPerformance##Type, 0); \
280  \
281 template<> \
282 const scalar solverPerformance##Type::great_(1e20); \
283  \
284 template<> \
285 const scalar solverPerformance##Type::small_(1e-20); \
286  \
287 template<> \
288 const scalar solverPerformance##Type::vsmall_(VSMALL); \
289 
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 #ifdef NoRepository
294  #include "SolverPerformance.C"
295 #endif
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************************************************************* //
bool converged() const
Has the solver converged?
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
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static const scalar small_
Small Type for the use in solvers.
const Type & finalResidual() const
Return final residual.
Traits class for primitives.
Definition: pTraits.H:50
bool checkSingularity(const Type &residual)
Singularity test.
static const scalar great_
Large Type for the use in solvers.
void print(Ostream &os) const
Print summary of solver performance to the given stream.
bool checkConvergence(const Type &tolerance, const Type &relTolerance)
Check, store and return convergence.
A class for handling words, derived from string.
Definition: word.H:59
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics...
label nIterations() const
Return number of iterations.
static const zero Zero
Definition: zero.H:91
ClassName("SolverPerformance")
bool operator!=(const SolverPerformance< Type > &) const
const word & solverName() const
Return solver name.
static const scalar vsmall_
Very small Type for the use in solvers.
const Type & initialResidual() const
Return initial residual.
const word & fieldName() const
Return field name.
SolverPerformance< typename pTraits< Type >::cmptType > max()
Return the summary maximum of SolverPerformance<Type>
void replace(const label cmpt, const SolverPerformance< typename pTraits< Type >::cmptType > &sp)
Replace component based on the minimal SolverPerformance.
bool singular() const
Is the matrix singular?
Namespace for OpenFOAM.