Belos Version of the Day
Loading...
Searching...
No Matches
BelosStatusTestLogResNorm.hpp
Go to the documentation of this file.
1//@HEADER
2// ************************************************************************
3//
4// Belos: Block Linear Solvers Package
5// Copyright 2004 Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40//@HEADER
41//
42
43#ifndef BELOS_STATUS_TEST_LOGRESNORM_HPP
44#define BELOS_STATUS_TEST_LOGRESNORM_HPP
45
51#include "BelosStatusTest.hpp"
52#include "Teuchos_ScalarTraits.hpp"
53#include "Teuchos_RCP.hpp"
54
64namespace Belos {
65
66template <class ScalarType, class MV, class OP>
67class StatusTestLogResNorm: public StatusTest<ScalarType,MV,OP> {
68
69public:
71 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
72
73private:
75
78
79 public:
80
82
83
85 StatusTestLogResNorm(int maxIters);
86
90
92
93
95
99
101 StatusType getStatus() const {return(Undefined);}
102
104
106
107
109 void reset();
110
112 void setMaxIters(int maxIters) { maxIters_ = maxIters; logResNorm_.reserve( maxIters_ ); }
113
115
117
118
120 int getMaxIters() const { return(maxIters_); }
121
123 int getNumIters() const { return(nIters_); }
124
126 const std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>&
127 getLogResNorm() const { return(logResNorm_); }
128
130
132
133
135 void print(std::ostream& os, int indent = 0) const;
136
138 void printStatus(std::ostream& os, StatusType type) const;
139
141
144
146 std::string description() const
147 {
148 std::ostringstream oss;
149 oss << "Belos::StatusTestLogResNorm<>: [ " << getNumIters() << " / " << getMaxIters() << " ]";
150 return oss.str();
151 }
153
154private:
155
157
158
159 int maxIters_;
160
162 int nIters_;
163
165 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> logResNorm_;
166
168
169};
170
171 template <class ScalarType, class MV, class OP>
173 {
174 if (maxIters < 1)
175 maxIters_ = 1;
176 else
177 maxIters_ = maxIters;
178
179 logResNorm_.reserve( maxIters_ );
180
181 nIters_ = 0;
182 }
183
184 template <class ScalarType, class MV, class OP>
186 {
187 // Check that this solve is a single-vector, single-block.
188 const LinearProblem<ScalarType,MV,OP>& lp = iSolver->getProblem ();
189 int blkSize = lp.getLSIndex().size();
190 int numRHS = MVT::GetNumberVecs( *(lp.getRHS()) );
191
192 int currIters = iSolver->getNumIters();
193
194 if ( (numRHS==1) && (blkSize==1) && (currIters!=nIters_) )
195 {
196 std::vector<MagnitudeType> tmp_resvector( 1 );
197 Teuchos::RCP<const MV> residMV = iSolver->getNativeResiduals (&tmp_resvector);
198 if (! residMV.is_null ())
199 {
200 // We got a multivector back. Compute the norms explicitly.
201 MVT::MvNorm (*residMV, tmp_resvector, TwoNorm);
202 }
203
204 logResNorm_.push_back( tmp_resvector[0] );
205 nIters_ = currIters;
206 }
207
208 return Undefined;
209 }
210
211 template <class ScalarType, class MV, class OP>
213 {
214 nIters_ = 0;
215 logResNorm_.clear();
216 logResNorm_.reserve( maxIters_ );
217 }
218
219 template <class ScalarType, class MV, class OP>
220 void StatusTestLogResNorm<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
221 {
222 for (int j = 0; j < indent; j ++)
223 os << ' ';
224 printStatus(os, Undefined);
225 os << "Logging Absolute Residual 2-Norm" << std::endl;
226 }
227
228 template <class ScalarType, class MV, class OP>
230 {
231 os << std::left << std::setw(13) << std::setfill('.');
232 os << "**";
233 os << std::left << std::setfill(' ');
234 return;
235 }
236
237} // end Belos namespace
238
239#endif /* BELOS_STATUS_TEST_LOGRESNORM_HPP */
Pure virtual base class for defining the status testing capabilities of Belos.
virtual int getNumIters() const =0
Get the current iteration count.
virtual Teuchos::RCP< const MV > getNativeResiduals(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *norms) const =0
Get the residuals native to the solver.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
Get a constant reference to the linear problem.
A linear system to solve, and its associated information.
const std::vector< int > & getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
Traits class which defines basic operations on multivectors.
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.10.0