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