11#ifndef ANASAZI_STATUS_TEST_RESNORM_HPP
12#define ANASAZI_STATUS_TEST_RESNORM_HPP
21#include "Teuchos_ScalarTraits.hpp"
22#include "Teuchos_LAPACK.hpp"
59 template <
class ScalarType,
class MV,
class OP>
62 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
70 StatusTestResNorm(
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol,
int quorum = -1,
ResType whichNorm = RES_ORTH,
bool scaled =
true,
bool throwExceptionOnNaN =
true);
121 void setTolerance(
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol) {
127 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
getTolerance() {
return tol_;}
135 whichNorm_ = whichNorm;
183 std::ostream&
print(std::ostream& os,
int indent = 0)
const;
189 std::vector<int> ind_;
193 bool throwExceptionOnNaN_;
197 template <
class ScalarType,
class MV,
class OP>
199 : state_(
Undefined), tol_(tol), quorum_(quorum), scaled_(scaled), whichNorm_(whichNorm), throwExceptionOnNaN_(throwExceptionOnNaN)
202 template <
class ScalarType,
class MV,
class OP>
205 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
207 std::vector<MagnitudeType> res;
211 std::vector<Value<ScalarType> > vals = solver->
getRitzValues();
212 switch (whichNorm_) {
216 vals.resize(res.size());
221 vals.resize(res.size());
230 Teuchos::LAPACK<int,MagnitudeType> lapack;
232 for (
unsigned int i=0; i<res.size(); i++) {
233 MagnitudeType tmp = lapack.LAPY2(vals[i].realpart,vals[i].imagpart);
235 if ( tmp != MT::zero() ) {
243 ind_.resize(res.size());
244 for (
unsigned int i=0; i<res.size(); i++) {
246 "StatusTestResNorm::checkStatus(): residual norm is nan or inf" );
253 int need = (quorum_ == -1) ? res.size() : quorum_;
259 template <
class ScalarType,
class MV,
class OP>
262 std::string ind(indent,
' ');
263 os << ind <<
"- StatusTestResNorm: ";
266 os <<
"Passed" << std::endl;
269 os <<
"Failed" << std::endl;
272 os <<
"Undefined" << std::endl;
275 os << ind <<
" (Tolerance,WhichNorm,Scaled,Quorum): "
277 switch (whichNorm_) {
285 os <<
",RITZRES_2NORM";
288 os <<
"," << (scaled_ ?
"true" :
"false")
293 os << ind <<
" Which vectors: ";
294 if (ind_.size() > 0) {
295 for (
unsigned int i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
299 os <<
"[empty]" << std::endl;
Declaration and definition of Anasazi::StatusTest.
Types and exceptions used within Anasazi solvers and interfaces.
An exception class parent to all Anasazi exceptions.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRes2Norms()=0
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()=0
Get the current residual norms.
virtual std::vector< Value< ScalarType > > getRitzValues()=0
Get the Ritz values from the previous iteration.
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()=0
ResNormNaNError is thrown from StatusTestResNorm::checkStatus() when a NaN ("not a number") is detect...
A status test for testing the norm of the eigenvectors residuals.
virtual ~StatusTestResNorm()
Destructor.
int getQuorum() const
Get quorum.
Teuchos::ScalarTraits< ScalarType >::magnitudeType getTolerance()
Get tolerance.
void clearStatus()
Clears the results of the last status test.
ResType getWhichNorm()
Return the residual norm used by the status test.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
void setTolerance(typename Teuchos::ScalarTraits< ScalarType >::magnitudeType tol)
Set tolerance. This also resets the test status to Undefined.
TestStatus getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run.
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.
int howMany() const
Get the number of vectors that passed the test.
StatusTestResNorm(typename Teuchos::ScalarTraits< ScalarType >::magnitudeType tol, int quorum=-1, ResType whichNorm=RES_ORTH, bool scaled=true, bool throwExceptionOnNaN=true)
Constructor.
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
void setScale(bool relscale)
Instruct test to scale norms by eigenvalue estimates (relative scale). This also resets the test stat...
bool getScale()
Returns true if the test scales the norms by the eigenvalue estimates (relative scale).
void setQuorum(int quorum)
Set quorum.
void setWhichNorm(ResType whichNorm)
Set the residual norm to be used by the status test.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state.
Common interface of stopping criteria for Anasazi's solvers.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ResType
Enumerated type used to specify which residual norm used by residual norm status tests.
TestStatus
Enumerated type used to pass back information from a StatusTest.