42 #ifndef ANASAZI_STATUS_TEST_SPECTRANS_HPP 43 #define ANASAZI_STATUS_TEST_SPECTRANS_HPP 54 template<
class ScalarType,
class MV,
class OP>
55 class StatusTestSpecTrans :
public StatusTest<ScalarType,MV,OP> {
57 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
58 typedef MultiVecTraits<ScalarType,MV> MVT;
59 typedef OperatorTraits<ScalarType,MV,OP> OPT;
64 StatusTestSpecTrans(MagnitudeType tol,
int quorum = -1,
ResType whichNorm = RES_2NORM,
bool scaled =
true,
bool throwExceptionOnNan =
true,
const RCP<const OP> Mop = Teuchos::null);
67 virtual ~StatusTestSpecTrans() {};
70 TestStatus checkStatus(Eigensolver<ScalarType,MV,OP> *solver);
73 TestStatus getStatus()
const {
return state_; }
76 std::vector<int> whichVecs()
const {
return ind_; }
79 int howMany()
const {
return ind_.size(); }
81 void setQuorum (
int quorum) {
86 int getQuorum()
const {
return quorum_; }
88 void setTolerance(MagnitudeType tol)
94 MagnitudeType getTolerance()
const {
return tol_; }
96 void setWhichNorm(
ResType whichNorm)
99 whichNorm_ = whichNorm;
102 ResType getWhichNorm()
const {
return whichNorm_; }
104 void setScale(
bool relscale)
110 bool getScale()
const {
return scaled_; }
120 void clearStatus() { reset(); };
123 std::ostream & print(std::ostream &os,
int indent=0)
const;
128 std::vector<int> ind_;
132 bool throwExceptionOnNaN_;
135 const MagnitudeType ONE;
140 template <
class ScalarType,
class MV,
class OP>
141 StatusTestSpecTrans<ScalarType,MV,OP>::StatusTestSpecTrans(MagnitudeType tol,
int quorum,
ResType whichNorm,
bool scaled,
bool throwExceptionOnNaN,
const RCP<const OP> Mop)
146 whichNorm_(whichNorm),
147 throwExceptionOnNaN_(throwExceptionOnNaN),
149 ONE(Teuchos::ScalarTraits<MagnitudeType>::one())
154 template <
class ScalarType,
class MV,
class OP>
155 TestStatus StatusTestSpecTrans<ScalarType,MV,OP>::checkStatus( Eigensolver<ScalarType,MV,OP>* solver )
157 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
158 typedef TraceMinBase<ScalarType,MV,OP> TS;
162 TS* tm_solver =
dynamic_cast<TS*
>(solver);
163 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!");
167 TraceMinBaseState<ScalarType,MV> state = tm_solver->getState();
169 size_t nvecs = state.ritzShifts->size();
170 std::vector<int> curind(nvecs);
171 for(
size_t i=0; i<nvecs; i++)
174 RCP<const MV> locKX, locMX, locX;
176 locX = MVT::CloneView(*state.X,curind);
177 if(state.KX != Teuchos::null)
178 locKX = MVT::CloneView(*state.KX,curind);
181 if(state.MX != Teuchos::null)
182 locMX = MVT::CloneView(*state.MX,curind);
185 R = MVT::CloneCopy(*locKX,curind);
187 std::vector<MagnitudeType> evals(nvecs);
188 for(
size_t i=0; i<nvecs; i++)
189 evals[i] = ONE/(*state.T)[i];
190 MVT::MvScale(*R,evals);
191 MVT::MvAddMv(-ONE,*R,ONE,*locMX,*R);
194 std::vector<MagnitudeType> res(nvecs);
195 switch (whichNorm_) {
203 RCP<MV> MR = MVT::Clone(*R,nvecs);
204 OPT::Apply(*M_,*R,*MR);
205 MVT::MvDot(*R,*MR,res);
206 for(
size_t i=0; i<nvecs; i++)
207 res[i] = MT::squareroot(res[i]);
212 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"The trace minimization solvers do not define a Ritz residual. Please choose a different residual type");
220 for(
size_t i=0; i<nvecs; i++)
221 res[i] /= std::abs(evals[i]);
226 for(
size_t i=0; i<nvecs; i++)
228 TEUCHOS_TEST_FOR_EXCEPTION( MT::isnaninf(res[i]), ResNormNaNError,
229 "StatusTestSpecTrans::checkStatus(): residual norm is nan or inf" );
233 int have = ind_.size();
234 int need = (quorum_ == -1) ? nvecs : quorum_;
241 template <
class ScalarType,
class MV,
class OP>
242 std::ostream& StatusTestSpecTrans<ScalarType,MV,OP>::print(std::ostream& os,
int indent)
const 244 std::string ind(indent,
' ');
245 os << ind <<
"- StatusTestSpecTrans: ";
257 os << ind <<
" (Tolerance, WhichNorm,Scaled,Quorum): " 259 switch (whichNorm_) {
267 os <<
",RITZRES_2NORM";
270 os <<
"," << (scaled_ ?
"true" :
"false")
275 os << ind <<
" Which vectors: ";
276 if (ind_.size() > 0) {
277 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.