10#ifndef ANASAZI_STATUS_TEST_SPECTRANS_HPP
11#define ANASAZI_STATUS_TEST_SPECTRANS_HPP
22 template<
class ScalarType,
class MV,
class OP>
23 class StatusTestSpecTrans :
public StatusTest<ScalarType,MV,OP> {
25 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
26 typedef MultiVecTraits<ScalarType,MV> MVT;
27 typedef OperatorTraits<ScalarType,MV,OP> OPT;
32 StatusTestSpecTrans(MagnitudeType tol,
int quorum = -1,
ResType whichNorm = RES_2NORM,
bool scaled =
true,
bool throwExceptionOnNan =
true,
const RCP<const OP> Mop = Teuchos::null);
35 virtual ~StatusTestSpecTrans() {};
38 TestStatus checkStatus(Eigensolver<ScalarType,MV,OP> *solver);
41 TestStatus getStatus()
const {
return state_; }
44 std::vector<int> whichVecs()
const {
return ind_; }
47 int howMany()
const {
return ind_.size(); }
49 void setQuorum (
int quorum) {
54 int getQuorum()
const {
return quorum_; }
56 void setTolerance(MagnitudeType tol)
62 MagnitudeType getTolerance()
const {
return tol_; }
64 void setWhichNorm(
ResType whichNorm)
67 whichNorm_ = whichNorm;
70 ResType getWhichNorm()
const {
return whichNorm_; }
72 void setScale(
bool relscale)
78 bool getScale()
const {
return scaled_; }
88 void clearStatus() { reset(); };
91 std::ostream & print(std::ostream &os,
int indent=0)
const;
96 std::vector<int> ind_;
100 bool throwExceptionOnNaN_;
103 const MagnitudeType ONE;
108 template <
class ScalarType,
class MV,
class OP>
109 StatusTestSpecTrans<ScalarType,MV,OP>::StatusTestSpecTrans(MagnitudeType tol,
int quorum,
ResType whichNorm,
bool scaled,
bool throwExceptionOnNaN,
const RCP<const OP> Mop)
114 whichNorm_(whichNorm),
115 throwExceptionOnNaN_(throwExceptionOnNaN),
117 ONE(Teuchos::ScalarTraits<MagnitudeType>::one())
122 template <
class ScalarType,
class MV,
class OP>
123 TestStatus StatusTestSpecTrans<ScalarType,MV,OP>::checkStatus( Eigensolver<ScalarType,MV,OP>* solver )
125 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
126 typedef TraceMinBase<ScalarType,MV,OP> TS;
130 TS* tm_solver =
dynamic_cast<TS*
>(solver);
131 TEUCHOS_TEST_FOR_EXCEPTION(tm_solver == 0, std::invalid_argument,
"The status test for spectral transformations currently only works for the trace minimization eigensolvers. Sorry!");
135 TraceMinBaseState<ScalarType,MV> state = tm_solver->getState();
137 size_t nvecs = state.ritzShifts->size();
138 std::vector<int> curind(nvecs);
139 for(
size_t i=0; i<nvecs; i++)
142 RCP<const MV> locKX, locMX, locX;
144 locX = MVT::CloneView(*state.X,curind);
145 if(state.KX != Teuchos::null)
146 locKX = MVT::CloneView(*state.KX,curind);
149 if(state.MX != Teuchos::null)
150 locMX = MVT::CloneView(*state.MX,curind);
153 R = MVT::CloneCopy(*locKX,curind);
155 std::vector<MagnitudeType> evals(nvecs);
156 for(
size_t i=0; i<nvecs; i++)
157 evals[i] = ONE/(*state.T)[i];
158 MVT::MvScale(*R,evals);
159 MVT::MvAddMv(-ONE,*R,ONE,*locMX,*R);
162 std::vector<MagnitudeType> res(nvecs);
163 switch (whichNorm_) {
171 RCP<MV> MR = MVT::Clone(*R,nvecs);
172 OPT::Apply(*M_,*R,*MR);
173 MVT::MvDot(*R,*MR,res);
174 for(
size_t i=0; i<nvecs; i++)
175 res[i] = MT::squareroot(res[i]);
180 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"The trace minimization solvers do not define a Ritz residual. Please choose a different residual type");
188 for(
size_t i=0; i<nvecs; i++)
189 res[i] /= std::abs(evals[i]);
194 for(
size_t i=0; i<nvecs; i++)
196 TEUCHOS_TEST_FOR_EXCEPTION( MT::isnaninf(res[i]), ResNormNaNError,
197 "StatusTestSpecTrans::checkStatus(): residual norm is nan or inf" );
201 int have = ind_.size();
202 int need = (quorum_ == -1) ? nvecs : quorum_;
203 state_ = (have >= need) ? Passed :
Failed;
209 template <
class ScalarType,
class MV,
class OP>
210 std::ostream& StatusTestSpecTrans<ScalarType,MV,OP>::print(std::ostream& os,
int indent)
const
212 std::string ind(indent,
' ');
213 os << ind <<
"- StatusTestSpecTrans: ";
225 os << ind <<
" (Tolerance, WhichNorm,Scaled,Quorum): "
227 switch (whichNorm_) {
235 os <<
",RITZRES_2NORM";
238 os <<
"," << (scaled_ ?
"true" :
"false")
242 if (state_ != Undefined) {
243 os << ind <<
" Which vectors: ";
244 if (ind_.size() > 0) {
245 for(
size_t i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
A status test for testing the norm of the eigenvectors residuals.
Abstract base class for trace minimization eigensolvers.
Types and exceptions used within Anasazi solvers and interfaces.
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.