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 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::SolverPerformance
29
30Description
31 SolverPerformance is the class returned by the LduMatrix solver
32 containing performance statistics.
33
34SourceFiles
35 SolverPerformance.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef SolverPerformance_H
40#define SolverPerformance_H
41
42#include "word.H"
43#include "FixedList.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50// Forward Declarations
51
52template<class Type>
53class SolverPerformance;
54
55template<class Type>
57(
60);
61
62template<class Type>
63Istream& operator>>
64(
65 Istream&,
67);
68
69template<class Type>
70Ostream& operator<<
71(
72 Ostream&,
74);
75
76
77/*---------------------------------------------------------------------------*\
78 Class SolverPerformance Declaration
79\*---------------------------------------------------------------------------*/
80
81template<class Type>
83{
84 // Label type corresponding to Type
85 typedef typename pTraits<Type>::labelType labelType;
86
87 // Private Data
88
89 word solverName_;
90 word fieldName_;
91 Type initialResidual_;
92 Type finalResidual_;
93 labelType nIterations_;
94 bool converged_;
96
97
98public:
99
100 // Static Data
101
102 // Declare name of the class and its debug switch
103 ClassName("SolverPerformance");
104
105 //- Large Type for the use in solvers
106 static const scalar great_;
107
108 //- Small Type for the use in solvers
109 static const scalar small_;
110
111 //- Very small Type for the use in solvers
112 static const scalar vsmall_;
113
114
115 // Constructors
118 :
119 initialResidual_(Zero),
120 finalResidual_(Zero),
121 nIterations_(Zero),
122 converged_(false),
123 singular_(false)
124 {}
125
128 (
129 const word& solverName,
130 const word& fieldName,
131 const Type& iRes = pTraits<Type>::zero,
132 const Type& fRes = pTraits<Type>::zero,
133 const labelType& nIter = pTraits<labelType>::zero,
134 const bool converged = false,
135 const bool singular = false
136 )
137 :
138 solverName_(solverName),
139 fieldName_(fieldName),
140 initialResidual_(iRes),
141 finalResidual_(fRes),
142 nIterations_(nIter),
143 converged_(converged),
144 singular_(singular)
145 {}
146
147
148 // Member Functions
149
150 //- Return solver name
151 const word& solverName() const noexcept
152 {
153 return solverName_;
154 }
155
156 //- Return solver name
158 {
159 return solverName_;
160 }
161
162
163 //- Return field name
164 const word& fieldName() const noexcept
165 {
166 return fieldName_;
167 }
168
169
170 //- Return initial residual
171 const Type& initialResidual() const noexcept
172 {
173 return initialResidual_;
174 }
175
176 //- Return initial residual
178 {
179 return initialResidual_;
180 }
181
182
183 //- Return final residual
184 const Type& finalResidual() const noexcept
185 {
186 return finalResidual_;
187 }
188
189 //- Return final residual
190 Type& finalResidual() noexcept
191 {
192 return finalResidual_;
193 }
194
195
196 //- Return number of iterations
197 const labelType& nIterations() const noexcept
198 {
199 return nIterations_;
200 }
201
202 //- Return number of iterations
203 labelType& nIterations() noexcept
204 {
205 return nIterations_;
206 }
207
208
209 //- Has the solver converged?
210 bool converged() const noexcept
211 {
212 return converged_;
213 }
214
215 //- Is the matrix singular?
216 bool singular() const;
217
218 //- Check, store and return convergence
220 (
221 const Type& tolerance,
222 const Type& relTolerance,
223 const int logLevel = 0
224 );
225
226 //- Singularity test
227 bool checkSingularity(const Type& residual);
228
229 //- Print summary of solver performance to the given stream
230 void print(Ostream& os) const;
231
232 //- Replace component based on the minimal SolverPerformance
233 void replace
234 (
235 const label cmpt,
237 );
238
239 //- Return the summary maximum of SolverPerformance<Type>
240 // Effectively it will mostly return solverPerformanceScalar
242
243
244 // Member Operators
245
246 bool operator!=(const SolverPerformance<Type>&) const;
247
248
249 // Friend functions
250
251 //- Return the element-wise maximum of two SolverPerformance<Type>s
252 friend SolverPerformance<Type> Foam::max <Type>
253 (
256 );
257
258
259 // Ostream Operator
261 friend Istream& operator>> <Type>
262 (
263 Istream&,
265 );
267 friend Ostream& operator<< <Type>
268 (
269 Ostream&,
271 );
272};
273
274
275// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276
277} // End namespace Foam
278
279// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281#define makeSolverPerformance(Type) \
282 \
283typedef Foam::SolverPerformance<Type> \
284 solverPerformance##Type; \
285 \
286defineNamedTemplateTypeNameAndDebug(solverPerformance##Type, 0); \
287 \
288template<> \
289const scalar solverPerformance##Type::great_(1e20); \
290 \
291template<> \
292const scalar solverPerformance##Type::small_(1e-20); \
293 \
294template<> \
295const scalar solverPerformance##Type::vsmall_(VSMALL); \
296
297
298// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299
300#ifdef NoRepository
301 #include "SolverPerformance.C"
302#endif
303
304// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305
306#endif
307
308// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
const Type & finalResidual() const noexcept
Return final residual.
Type & initialResidual() noexcept
Return initial residual.
const labelType & nIterations() const noexcept
Return number of iterations.
Type & finalResidual() noexcept
Return final residual.
bool operator!=(const SolverPerformance< Type > &) const
word & solverName() noexcept
Return solver name.
void replace(const label cmpt, const SolverPerformance< typename pTraits< Type >::cmptType > &sp)
Replace component based on the minimal SolverPerformance.
ClassName("SolverPerformance")
void print(Ostream &os) const
Print summary of solver performance to the given stream.
bool singular() const
Is the matrix singular?
bool converged() const noexcept
Has the solver converged?
static const scalar small_
Small Type for the use in solvers.
SolverPerformance(const word &solverName, const word &fieldName, const Type &iRes=pTraits< Type >::zero, const Type &fRes=pTraits< Type >::zero, const labelType &nIter=pTraits< labelType >::zero, const bool converged=false, const bool singular=false)
bool checkSingularity(const Type &residual)
Singularity test.
static const scalar vsmall_
Very small Type for the use in solvers.
static const scalar great_
Large Type for the use in solvers.
const word & solverName() const noexcept
Return solver name.
labelType & nIterations() noexcept
Return number of iterations.
const Type & initialResidual() const noexcept
Return initial residual.
SolverPerformance< typename pTraits< Type >::cmptType > max()
Return the summary maximum of SolverPerformance<Type>
const word & fieldName() const noexcept
Return field name.
bool checkConvergence(const Type &tolerance, const Type &relTolerance, const int logLevel=0)
Check, store and return convergence.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
const direction noexcept
Definition: Scalar.H:223
A non-counting (dummy) refCount.
Definition: refCount.H:59