29 #ifndef ANASAZI_STATUS_TEST_SPECTRANS_HPP 30 #define ANASAZI_STATUS_TEST_SPECTRANS_HPP 41 template<
class ScalarType,
class MV,
class OP>
42 class StatusTestSpecTrans :
public StatusTest<ScalarType,MV,OP> {
44 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
45 typedef MultiVecTraits<ScalarType,MV> MVT;
46 typedef OperatorTraits<ScalarType,MV,OP> OPT;
51 StatusTestSpecTrans(MagnitudeType tol,
int quorum = -1,
ResType whichNorm = RES_2NORM,
bool scaled =
true,
bool throwExceptionOnNan =
true,
const RCP<const OP> Mop = Teuchos::null);
54 virtual ~StatusTestSpecTrans() {};
57 TestStatus checkStatus(Eigensolver<ScalarType,MV,OP> *solver);
60 TestStatus getStatus()
const {
return state_; }
63 std::vector<int> whichVecs()
const {
return ind_; }
66 int howMany()
const {
return ind_.size(); }
68 void setQuorum (
int quorum) {
73 int getQuorum()
const {
return quorum_; }
75 void setTolerance(MagnitudeType tol)
81 MagnitudeType getTolerance()
const {
return tol_; }
83 void setWhichNorm(
ResType whichNorm)
86 whichNorm_ = whichNorm;
89 ResType getWhichNorm()
const {
return whichNorm_; }
91 void setScale(
bool relscale)
97 bool getScale()
const {
return scaled_; }
107 void clearStatus() { reset(); };
110 std::ostream & print(std::ostream &os,
int indent=0)
const;
115 std::vector<int> ind_;
119 bool throwExceptionOnNaN_;
122 const MagnitudeType ONE;
127 template <
class ScalarType,
class MV,
class OP>
128 StatusTestSpecTrans<ScalarType,MV,OP>::StatusTestSpecTrans(MagnitudeType tol,
int quorum,
ResType whichNorm,
bool scaled,
bool throwExceptionOnNaN,
const RCP<const OP> Mop)
133 whichNorm_(whichNorm),
134 throwExceptionOnNaN_(throwExceptionOnNaN),
136 ONE(Teuchos::ScalarTraits<MagnitudeType>::one())
141 template <
class ScalarType,
class MV,
class OP>
142 TestStatus StatusTestSpecTrans<ScalarType,MV,OP>::checkStatus( Eigensolver<ScalarType,MV,OP>* solver )
144 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
145 typedef TraceMinBase<ScalarType,MV,OP> TS;
149 TS* tm_solver =
dynamic_cast<TS*
>(solver);
150 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!");
154 TraceMinBaseState<ScalarType,MV> state = tm_solver->getState();
156 size_t nvecs = state.ritzShifts->size();
157 std::vector<int> curind(nvecs);
158 for(
size_t i=0; i<nvecs; i++)
161 RCP<const MV> locKX, locMX, locX;
163 locX = MVT::CloneView(*state.X,curind);
164 if(state.KX != Teuchos::null)
165 locKX = MVT::CloneView(*state.KX,curind);
168 if(state.MX != Teuchos::null)
169 locMX = MVT::CloneView(*state.MX,curind);
172 R = MVT::CloneCopy(*locKX,curind);
174 std::vector<MagnitudeType> evals(nvecs);
175 for(
size_t i=0; i<nvecs; i++)
176 evals[i] = ONE/(*state.T)[i];
177 MVT::MvScale(*R,evals);
178 MVT::MvAddMv(-ONE,*R,ONE,*locMX,*R);
181 std::vector<MagnitudeType> res(nvecs);
182 switch (whichNorm_) {
190 RCP<MV> MR = MVT::Clone(*R,nvecs);
191 OPT::Apply(*M_,*R,*MR);
192 MVT::MvDot(*R,*MR,res);
193 for(
size_t i=0; i<nvecs; i++)
194 res[i] = MT::squareroot(res[i]);
199 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"The trace minimization solvers do not define a Ritz residual. Please choose a different residual type");
207 for(
size_t i=0; i<nvecs; i++)
208 res[i] /= std::abs(evals[i]);
213 for(
size_t i=0; i<nvecs; i++)
215 TEUCHOS_TEST_FOR_EXCEPTION( MT::isnaninf(res[i]), ResNormNaNError,
216 "StatusTestSpecTrans::checkStatus(): residual norm is nan or inf" );
220 int have = ind_.size();
221 int need = (quorum_ == -1) ? nvecs : quorum_;
228 template <
class ScalarType,
class MV,
class OP>
229 std::ostream& StatusTestSpecTrans<ScalarType,MV,OP>::print(std::ostream& os,
int indent)
const 231 std::string ind(indent,
' ');
232 os << ind <<
"- StatusTestSpecTrans: ";
244 os << ind <<
" (Tolerance, WhichNorm,Scaled,Quorum): " 246 switch (whichNorm_) {
254 os <<
",RITZRES_2NORM";
257 os <<
"," << (scaled_ ?
"true" :
"false")
262 os << ind <<
" Which vectors: ";
263 if (ind_.size() > 0) {
264 for(
size_t i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
Abstract base class for trace minimization eigensolvers.
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.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
A status test for testing the norm of the eigenvectors residuals.
Types and exceptions used within Anasazi solvers and interfaces.