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-2015 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 
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
110 
112  :
113  initialResidual_(pTraits<Type>::zero),
114  finalResidual_(pTraits<Type>::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  :
134  initialResidual_(iRes),
135  finalResidual_(fRes),
136  noIterations_(nIter),
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  (
249  );
250 
251 
252  // Ostream Operator
253 
254  friend Istream& operator>> <Type>
255  (
256  Istream&,
258  );
259 
260  friend Ostream& operator<< <Type>
261  (
262  Ostream&,
264  );
265 };
266 
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 } // End namespace Foam
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
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 // ************************************************************************* //
Foam::SolverPerformance::SolverPerformance
SolverPerformance()
Definition: SolverPerformance.H:110
Foam::SolverPerformance::max
SolverPerformance< typename pTraits< Type >::cmptType > max()
Return the summary maximum of SolverPerformance<Type>
Definition: SolverPerformance.C:144
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::SolverPerformance::fieldName_
word fieldName_
Definition: SolverPerformance.H:83
Foam::SolverPerformance::solverName
word & solverName()
Return solver name.
Definition: SolverPerformance.H:150
Foam::SolverPerformance::great_
static const scalar great_
Large Type for the use in solvers.
Definition: SolverPerformance.H:99
Foam::SolverPerformance::finalResidual
const Type & finalResidual() const
Return final residual.
Definition: SolverPerformance.H:177
Foam::SolverPerformance::vsmall_
static const scalar vsmall_
Very small Type for the use in solvers.
Definition: SolverPerformance.H:105
Foam::SolverPerformance::converged
bool converged() const
Has the solver converged?
Definition: SolverPerformance.H:203
Foam::SolverPerformance::solverName
const word & solverName() const
Return solver name.
Definition: SolverPerformance.H:144
Foam::SolverPerformance::print
void print(Ostream &os) const
Print summary of solver performance to the given stream.
Definition: SolverPerformance.C:97
Foam::SolverPerformance::noIterations_
label noIterations_
Definition: SolverPerformance.H:86
Foam::SolverPerformance::checkConvergence
bool checkConvergence(const Type &tolerance, const Type &relTolerance)
Check, store and return convergence.
Definition: SolverPerformance.C:61
Foam::SolverPerformance::operator!=
bool operator!=(const SolverPerformance< Type > &) const
Definition: SolverPerformance.C:161
Foam::SolverPerformance::singular_
FixedList< bool, pTraits< Type >::nComponents > singular_
Definition: SolverPerformance.H:88
Foam::label
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
Foam::SolverPerformance::fieldName
const word & fieldName() const
Return field name.
Definition: SolverPerformance.H:157
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::SolverPerformance::replace
void replace(const label cmpt, const SolverPerformance< typename pTraits< Type >::cmptType > &sp)
Replace component based on the minimal SolverPerformance.
Definition: SolverPerformance.C:131
Foam::SolverPerformance::initialResidual
const Type & initialResidual() const
Return initial residual.
Definition: SolverPerformance.H:164
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::SolverPerformance::finalResidual_
Type finalResidual_
Definition: SolverPerformance.H:85
Foam::SolverPerformance::small_
static const scalar small_
Small Type for the use in solvers.
Definition: SolverPerformance.H:102
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::SolverPerformance::singular
bool singular() const
Is the matrix singular?
Definition: SolverPerformance.C:48
Foam::SolverPerformance::solverName_
word solverName_
Definition: SolverPerformance.H:82
Foam::SolverPerformance::finalResidual
Type & finalResidual()
Return final residual.
Definition: SolverPerformance.H:183
Foam::SolverPerformance::checkSingularity
bool checkSingularity(const Type &residual)
Singularity test.
Definition: SolverPerformance.C:33
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::SolverPerformance::nIterations
label & nIterations()
Return number of iterations.
Definition: SolverPerformance.H:196
Foam::SolverPerformance::ClassName
ClassName("SolverPerformance")
SolverPerformance.C
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
FixedList.H
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:49
Foam::SolverPerformance::initialResidual_
Type initialResidual_
Definition: SolverPerformance.H:84
Foam::SolverPerformance::initialResidual
Type & initialResidual()
Return initial residual.
Definition: SolverPerformance.H:170
Foam::SolverPerformance::nIterations
label nIterations() const
Return number of iterations.
Definition: SolverPerformance.H:190
Foam::zero
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
Foam::SolverPerformance::converged_
bool converged_
Definition: SolverPerformance.H:87