Belos Version of the Day
Loading...
Searching...
No Matches
BelosStatusTestLogResNorm.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_LOGRESNORM_HPP
12#define BELOS_STATUS_TEST_LOGRESNORM_HPP
13
19#include "BelosStatusTest.hpp"
20#include "Teuchos_ScalarTraits.hpp"
21#include "Teuchos_RCP.hpp"
22
32namespace Belos {
33
34template <class ScalarType, class MV, class OP>
35class StatusTestLogResNorm: public StatusTest<ScalarType,MV,OP> {
36
37public:
39 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
40
41private:
43
46
47 public:
48
50
51
54
58
60
61
63
67
69 StatusType getStatus() const {return(Undefined);}
70
72
74
75
77 void reset();
78
80 void setMaxIters(int maxIters) { maxIters_ = maxIters; logResNorm_.reserve( maxIters_ ); }
81
83
85
86
88 int getMaxIters() const { return(maxIters_); }
89
91 int getNumIters() const { return(nIters_); }
92
94 const std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>&
95 getLogResNorm() const { return(logResNorm_); }
96
98
100
101
103 void print(std::ostream& os, int indent = 0) const;
104
106 void printStatus(std::ostream& os, StatusType type) const;
107
109
112
114 std::string description() const
115 {
116 std::ostringstream oss;
117 oss << "Belos::StatusTestLogResNorm<>: [ " << getNumIters() << " / " << getMaxIters() << " ]";
118 return oss.str();
119 }
121
122private:
123
125
126
127 int maxIters_;
128
130 int nIters_;
131
133 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> logResNorm_;
134
136
137};
138
139 template <class ScalarType, class MV, class OP>
141 {
142 if (maxIters < 1)
143 maxIters_ = 1;
144 else
145 maxIters_ = maxIters;
146
147 logResNorm_.reserve( maxIters_ );
148
149 nIters_ = 0;
150 }
151
152 template <class ScalarType, class MV, class OP>
154 {
155 // Check that this solve is a single-vector, single-block.
156 const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem ();
157 int blkSize = lp.getLSIndex().size();
158 int numRHS = MVT::GetNumberVecs( *(lp.getRHS()) );
159
160 int currIters = iSolver->getNumIters();
161
162 if ( (numRHS==1) && (blkSize==1) && (currIters!=nIters_) )
163 {
164 std::vector<MagnitudeType> tmp_resvector( 1 );
165 Teuchos::RCP<const MV> residMV = iSolver->getNativeResiduals (&tmp_resvector);
166 if (! residMV.is_null ())
167 {
168 // We got a multivector back. Compute the norms explicitly.
169 MVT::MvNorm (*residMV, tmp_resvector, TwoNorm);
170 }
171
172 logResNorm_.push_back( tmp_resvector[0] );
173 nIters_ = currIters;
174 }
175
176 return Undefined;
177 }
178
179 template <class ScalarType, class MV, class OP>
181 {
182 nIters_ = 0;
183 logResNorm_.clear();
184 logResNorm_.reserve( maxIters_ );
185 }
186
187 template <class ScalarType, class MV, class OP>
189 {
190 for (int j = 0; j < indent; j ++)
191 os << ' ';
192 printStatus(os, Undefined);
193 os << "Logging Absolute Residual 2-Norm" << std::endl;
194 }
195
196 template <class ScalarType, class MV, class OP>
198 {
199 os << std::left << std::setw(13) << std::setfill('.');
200 os << "**";
201 os << std::left << std::setfill(' ');
202 return;
203 }
204
205} // end Belos namespace
206
207#endif /* BELOS_STATUS_TEST_LOGRESNORM_HPP */
Pure virtual base class for defining the status testing capabilities of Belos.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
A Belos::StatusTest debugging class for storing the absolute residual norms generated during a solve.
void reset()
Resets the status test to the initial internal state.
StatusTestLogResNorm(int maxIters)
Constructor.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed.
int getNumIters() const
Returns the current number of iterations from the most recent StatusTest call.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
void setMaxIters(int maxIters)
Sets the maximum number of iterations allowed so internal storage can be resized.
const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > & getLogResNorm() const
Returns the log of the absolute residual norm from the iteration.
std::string description() const
Method to return description of the debugging status test
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
int getMaxIters() const
Returns the maximum number of iterations set in the constructor.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
The type of the magnitude (absolute value) of a ScalarType.
A pure virtual class for defining the status tests for the Belos iterative solvers.
StatusType
Whether the StatusTest wants iteration to stop.

Generated for Belos by doxygen 1.9.8