30 #ifndef ANASAZI_STATUS_TEST_RESNORM_HPP 31 #define ANASAZI_STATUS_TEST_RESNORM_HPP 40 #include "Teuchos_ScalarTraits.hpp" 77 template <
class ScalarType,
class MV,
class OP>
80 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
88 StatusTestResNorm(
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol,
int quorum = -1,
ResType whichNorm = RES_ORTH,
bool scaled =
true,
bool throwExceptionOnNaN =
true);
139 void setTolerance(
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol) {
145 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
getTolerance() {
return tol_;}
153 whichNorm_ = whichNorm;
201 std::ostream&
print(std::ostream& os,
int indent = 0)
const;
207 std::vector<int> ind_;
211 bool throwExceptionOnNaN_;
215 template <
class ScalarType,
class MV,
class OP>
217 : state_(
Undefined), tol_(tol), quorum_(quorum), scaled_(scaled), whichNorm_(whichNorm), throwExceptionOnNaN_(throwExceptionOnNaN)
220 template <
class ScalarType,
class MV,
class OP>
223 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
225 std::vector<MagnitudeType> res;
229 std::vector<Value<ScalarType> > vals = solver->
getRitzValues();
230 switch (whichNorm_) {
234 vals.resize(res.size());
239 vals.resize(res.size());
248 Teuchos::LAPACK<int,MagnitudeType> lapack;
250 for (
unsigned int i=0; i<res.size(); i++) {
251 MagnitudeType tmp = lapack.LAPY2(vals[i].realpart,vals[i].imagpart);
253 if ( tmp != MT::zero() ) {
261 ind_.resize(res.size());
262 for (
unsigned int i=0; i<res.size(); i++) {
264 "StatusTestResNorm::checkStatus(): residual norm is nan or inf" );
271 int need = (quorum_ == -1) ? res.size() : quorum_;
277 template <
class ScalarType,
class MV,
class OP>
280 std::string ind(indent,
' ');
281 os << ind <<
"- StatusTestResNorm: ";
284 os <<
"Passed" << std::endl;
287 os <<
"Failed" << std::endl;
290 os <<
"Undefined" << std::endl;
293 os << ind <<
" (Tolerance,WhichNorm,Scaled,Quorum): " 295 switch (whichNorm_) {
303 os <<
",RITZRES_2NORM";
306 os <<
"," << (scaled_ ?
"true" :
"false")
311 os << ind <<
" Which vectors: ";
312 if (ind_.size() > 0) {
313 for (
unsigned int i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
317 os <<
"[empty]" << std::endl;
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getResNorms()=0
Get the current residual norms.
bool getScale()
Returns true if the test scales the norms by the eigenvalue estimates (relative scale).
ResType
Enumerated type used to specify which residual norm used by residual norm status tests.
virtual std::vector< Value< ScalarType > > getRitzValues()=0
Get the Ritz values from the previous iteration.
void setTolerance(typename Teuchos::ScalarTraits< ScalarType >::magnitudeType tol)
Set tolerance. This also resets the test status to Undefined.
An exception class parent to all Anasazi exceptions.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state...
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
TestStatus
Enumerated type used to pass back information from a StatusTest.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
ResType getWhichNorm()
Return the residual norm used by the status test.
virtual ~StatusTestResNorm()
Destructor.
int getQuorum() const
Get quorum.
TestStatus getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run...
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRitzRes2Norms()=0
ResNormNaNError is thrown from StatusTestResNorm::checkStatus() when a NaN ("not a number") is detect...
Teuchos::ScalarTraits< ScalarType >::magnitudeType getTolerance()
Get tolerance.
virtual std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getRes2Norms()=0
int howMany() const
Get the number of vectors that passed the test.
Types and exceptions used within Anasazi solvers and interfaces.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
void setQuorum(int quorum)
Set quorum.
Common interface of stopping criteria for Anasazi's solvers.
A status test for testing the norm of the eigenvectors residuals.
void setScale(bool relscale)
Instruct test to scale norms by eigenvalue estimates (relative scale). This also resets the test stat...
StatusTestResNorm(typename Teuchos::ScalarTraits< ScalarType >::magnitudeType tol, int quorum=-1, ResType whichNorm=RES_ORTH, bool scaled=true, bool throwExceptionOnNaN=true)
Constructor.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
void setWhichNorm(ResType whichNorm)
Set the residual norm to be used by the status test.
void clearStatus()
Clears the results of the last status test.
Declaration and definition of Anasazi::StatusTest.
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.