Belos
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
BelosStatusTestMaxIters.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Belos: Block Linear Solvers Package
4
//
5
// Copyright 2004-2016 NTESS and the Belos contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
//
10
11
#ifndef BELOS_STATUS_TEST_MAXITERS_HPP
12
#define BELOS_STATUS_TEST_MAXITERS_HPP
13
18
19
#include "
BelosStatusTest.hpp
"
20
27
28
namespace
Belos
{
29
30
template
<
class
ScalarType,
class
MV,
class
OP>
31
class
StatusTestMaxIters
:
public
StatusTest
<ScalarType,MV,OP> {
32
33
public
:
34
36
37
39
StatusTestMaxIters
(
int
maxIters);
40
42
virtual
~StatusTestMaxIters
() {};
44
46
47
49
52
StatusType
checkStatus
(
Iteration<ScalarType,MV,OP>
*iSolver );
53
55
StatusType
getStatus
()
const
{
return
(status_);}
56
58
60
61
63
void
reset
();
64
66
void
setMaxIters
(
int
maxIters) { maxIters_ = maxIters; }
67
69
71
72
74
int
getMaxIters
()
const
{
return
(maxIters_); }
75
77
int
getNumIters
()
const
{
return
(nIters_); }
78
80
82
83
85
void
print
(std::ostream& os,
int
indent = 0)
const
;
86
88
void
printStatus
(std::ostream& os,
StatusType
type)
const
;
89
91
94
96
std::string
description
()
const
97
{
98
std::ostringstream oss;
99
oss <<
"Belos::StatusTestMaxIters<>: [ "
<<
getNumIters
() <<
" / "
<<
getMaxIters
() <<
" ]"
;
100
return
oss.str();
101
}
102
103
104
private
:
105
107
108
109
int
maxIters_;
110
112
int
nIters_;
113
115
StatusType
status_;
117
118
};
119
120
template
<
class
ScalarType,
class
MV,
class
OP>
121
StatusTestMaxIters<ScalarType,MV,OP>::StatusTestMaxIters
(
int
maxIters)
122
{
123
if
(maxIters < 1)
124
maxIters_ = 1;
125
else
126
maxIters_ = maxIters;
127
128
nIters_ = 0;
129
status_ =
Undefined
;
130
}
131
132
template
<
class
ScalarType,
class
MV,
class
OP>
133
StatusType
StatusTestMaxIters<ScalarType,MV,OP>::checkStatus
(
Iteration<ScalarType,MV,OP>
*iSolver )
134
{
135
status_ =
Failed
;
136
nIters_ = iSolver->
getNumIters
();
137
if
(nIters_ >= maxIters_)
138
status_ =
Passed
;
139
return
status_;
140
}
141
142
template
<
class
ScalarType,
class
MV,
class
OP>
143
void
StatusTestMaxIters<ScalarType,MV,OP>::reset
()
144
{
145
nIters_ = 0;
146
status_ =
Undefined
;
147
}
148
149
template
<
class
ScalarType,
class
MV,
class
OP>
150
void
StatusTestMaxIters<ScalarType,MV,OP>::print
(std::ostream& os,
int
indent)
const
151
{
152
for
(
int
j = 0; j < indent; j ++)
153
os <<
' '
;
154
printStatus
(os, status_);
155
os <<
"Number of Iterations = "
;
156
os << nIters_;
157
os << ((nIters_ < maxIters_) ?
" < "
: ((nIters_ == maxIters_) ?
" == "
:
" > "
));
158
os << maxIters_;
159
os << std::endl;
160
}
161
162
template
<
class
ScalarType,
class
MV,
class
OP>
163
void
StatusTestMaxIters<ScalarType,MV,OP>::printStatus
(std::ostream& os,
StatusType
type)
const
164
{
165
os << std::left << std::setw(13) << std::setfill(
'.'
);
166
switch
(type) {
167
case
Passed
:
168
os <<
"Failed"
;
169
break
;
170
case
Failed
:
171
os <<
"OK"
;
172
break
;
173
case
Undefined
:
174
default
:
175
os <<
"**"
;
176
break
;
177
}
178
os << std::left << std::setfill(
' '
);
179
return
;
180
}
181
182
}
// end Belos namespace
183
184
#endif
/* BELOS_STATUS_TEST_MAXITERS_HPP */
BelosStatusTest.hpp
Pure virtual base class for defining the status testing capabilities of Belos.
Belos::Iteration
Definition
BelosIteration.hpp:41
Belos::Iteration::getNumIters
virtual int getNumIters() const =0
Get the current iteration count.
Belos::StatusTest::StatusTest
StatusTest()
Constructor.
Definition
BelosStatusTest.hpp:57
Belos::StatusTestMaxIters::print
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
Definition
BelosStatusTestMaxIters.hpp:150
Belos::StatusTestMaxIters::checkStatus
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed.
Definition
BelosStatusTestMaxIters.hpp:133
Belos::StatusTestMaxIters::reset
void reset()
Resets the status test to the initial internal state.
Definition
BelosStatusTestMaxIters.hpp:143
Belos::StatusTestMaxIters::StatusTestMaxIters
StatusTestMaxIters(int maxIters)
Constructor.
Definition
BelosStatusTestMaxIters.hpp:121
Belos::StatusTestMaxIters::description
std::string description() const
Method to return description of the maximum iteration status test.
Definition
BelosStatusTestMaxIters.hpp:96
Belos::StatusTestMaxIters::~StatusTestMaxIters
virtual ~StatusTestMaxIters()
Destructor.
Definition
BelosStatusTestMaxIters.hpp:42
Belos::StatusTestMaxIters::getStatus
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
Definition
BelosStatusTestMaxIters.hpp:55
Belos::StatusTestMaxIters::setMaxIters
void setMaxIters(int maxIters)
Sets the maximum number of iterations allowed.
Definition
BelosStatusTestMaxIters.hpp:66
Belos::StatusTestMaxIters::getMaxIters
int getMaxIters() const
Returns the maximum number of iterations set in the constructor.
Definition
BelosStatusTestMaxIters.hpp:74
Belos::StatusTestMaxIters::getNumIters
int getNumIters() const
Returns the current number of iterations from the most recent StatusTest call.
Definition
BelosStatusTestMaxIters.hpp:77
Belos::StatusTestMaxIters::printStatus
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
Definition
BelosStatusTestMaxIters.hpp:163
Belos
Definition
Belos_Details_EBelosSolverType.cpp:13
Belos::StatusType
StatusType
Whether the StatusTest wants iteration to stop.
Definition
BelosTypes.hpp:157
Belos::Failed
@ Failed
Definition
BelosTypes.hpp:158
Belos::Undefined
@ Undefined
Definition
BelosTypes.hpp:159
Belos::Passed
@ Passed
Definition
BelosTypes.hpp:157
Generated for Belos by
1.17.0