00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ANASAZI_STATUS_TEST_COMBO_HPP
00031 #define ANASAZI_STATUS_TEST_COMBO_HPP
00032
00039 #include "AnasaziTypes.hpp"
00040 #include "AnasaziStatusTest.hpp"
00041 #include "Teuchos_Array.hpp"
00042
00058 namespace Anasazi {
00059
00060
00061 template <class ScalarType, class MV, class OP>
00062 class StatusTestCombo : public StatusTest<ScalarType,MV,OP> {
00063
00064 private:
00065 typedef Teuchos::Array< Teuchos::RefCountPtr< StatusTest<ScalarType,MV,OP> > > STPArray;
00066
00067 public:
00068
00070 enum ComboType
00071 {
00072 OR,
00073 AND,
00074 SEQOR,
00075 SEQAND
00076 };
00077
00078
00079 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00080
00081 typedef Teuchos::Array< Teuchos::RefCountPtr< StatusTest<ScalarType,MV,OP> > > t_arr;
00082 typedef std::vector< Teuchos::RefCountPtr< StatusTest<ScalarType,MV,OP> > > st_vector;
00083 typedef typename st_vector::iterator iterator;
00084 typedef typename st_vector::const_iterator const_iterator;
00085
00086 #endif // DOXYGEN_SHOULD_SKIP_THIS
00087
00089
00090
00093 StatusTestCombo() : state_(Undefined) {}
00094
00097 StatusTestCombo(ComboType type, Teuchos::Array< Teuchos::RefCountPtr< StatusTest<ScalarType,MV,OP> > > tests) :
00098 state_(Undefined),
00099 type_(type)
00100 {
00101 setTests(tests);
00102 };
00103
00105 virtual ~StatusTestCombo() {};
00107
00109
00110
00114 TestStatus checkStatus( Eigensolver<ScalarType,MV,OP>* solver );
00115
00117 TestStatus getStatus() const {
00118 return state_;
00119 }
00121
00123
00124
00128 void setComboType(ComboType type) {
00129 type_ = type;
00130 state_ = Undefined;
00131 }
00132
00134 ComboType getComboType() const {return type_;}
00135
00139 void setTests(Teuchos::Array<Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > > tests) {
00140 tests_ = tests;
00141 state_ = Undefined;
00142 }
00143
00145 Teuchos::Array<Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > > getTests() const {return tests_;}
00146
00151 void addTest(Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > test) {
00152 tests_.push_back(test);
00153 state_ = Undefined;
00154 }
00155
00160 void removeTest(const Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > &test);
00161
00163
00165
00166
00167
00170 void reset();
00171
00173
00178 void clearStatus();
00179
00181
00183
00184
00186 ostream& print(ostream& os, int indent = 0) const;
00187
00189 private:
00190
00191 TestStatus evalOR(Eigensolver<ScalarType,MV,OP>* solver);
00192 TestStatus evalAND(Eigensolver<ScalarType,MV,OP>* solver);
00193 TestStatus evalSEQOR(Eigensolver<ScalarType,MV,OP>* solver);
00194 TestStatus evalSEQAND(Eigensolver<ScalarType,MV,OP>* solver);
00195
00196 TestStatus state_;
00197 ComboType type_;
00198 STPArray tests_;
00199
00200 };
00201
00202
00203 template <class ScalarType, class MV, class OP>
00204 void StatusTestCombo<ScalarType,MV,OP>::removeTest(const Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > &test)
00205 {
00206 typename STPArray::iterator iter1;
00207 iter1 = find(tests_.begin(),tests_.end(),test);
00208 if (iter1 != tests_.end()) {
00209 tests_.erase(iter1);
00210 state_ = Undefined;
00211 }
00212 }
00213
00214
00215 template <class ScalarType, class MV, class OP>
00216 TestStatus StatusTestCombo<ScalarType,MV,OP>::checkStatus( Eigensolver<ScalarType,MV,OP>* solver ) {
00217 clearStatus();
00218 switch (type_) {
00219 case OR:
00220 state_ = evalOR(solver);
00221 break;
00222 case AND:
00223 state_ = evalAND(solver);
00224 break;
00225 case SEQOR:
00226 state_ = evalSEQOR(solver);
00227 break;
00228 case SEQAND:
00229 state_ = evalSEQAND(solver);
00230 break;
00231 }
00232 return state_;
00233 }
00234
00235
00236 template <class ScalarType, class MV, class OP>
00237 void StatusTestCombo<ScalarType,MV,OP>::reset() {
00238 state_ = Undefined;
00239 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00240 (*i)->reset();
00241 }
00242 }
00243
00244 template <class ScalarType, class MV, class OP>
00245 void StatusTestCombo<ScalarType,MV,OP>::clearStatus() {
00246 state_ = Undefined;
00247 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00248 (*i)->clearStatus();
00249 }
00250 }
00251
00252 template <class ScalarType, class MV, class OP>
00253 ostream& StatusTestCombo<ScalarType,MV,OP>::print(ostream& os, int indent) const {
00254 string ind(indent,' ');
00255 os << ind << "- StatusTestCombo: ";
00256 switch (state_) {
00257 case Passed:
00258 os << "Passed" << endl;
00259 break;
00260 case Failed:
00261 os << "Failed" << endl;
00262 break;
00263 case Undefined:
00264 os << "Undefined" << endl;
00265 break;
00266 }
00267
00268 for (const_iterator i=tests_.begin(); i != tests_.end(); i++) {
00269 (*i)->print(os,indent+2);
00270 }
00271 return os;
00272 }
00273
00274 template <class ScalarType, class MV, class OP>
00275 TestStatus StatusTestCombo<ScalarType,MV,OP>::evalOR( Eigensolver<ScalarType,MV,OP>* solver ) {
00276 state_ = Failed;
00277 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00278 TestStatus r = (*i)->checkStatus(solver);
00279 if (r == Passed) {
00280 state_ = Passed;
00281 }
00282 else {
00283 TEST_FOR_EXCEPTION(r != Failed,StatusTestError,
00284 "Anasazi::StatusTestCombo::evalOR(): child test gave invalid return");
00285 }
00286 }
00287 return state_;
00288 }
00289
00290 template <class ScalarType, class MV, class OP>
00291 TestStatus StatusTestCombo<ScalarType,MV,OP>::evalSEQOR( Eigensolver<ScalarType,MV,OP>* solver ) {
00292 state_ = Failed;
00293 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00294 TestStatus r = (*i)->checkStatus(solver);
00295 if (r == Passed) {
00296 state_ = Passed;
00297 break;
00298 }
00299 else {
00300 TEST_FOR_EXCEPTION(r != Failed,StatusTestError,
00301 "Anasazi::StatusTestCombo::evalSEQOR(): child test gave invalid return");
00302 }
00303 }
00304 return state_;
00305 }
00306
00307 template <class ScalarType, class MV, class OP>
00308 TestStatus StatusTestCombo<ScalarType,MV,OP>::evalAND( Eigensolver<ScalarType,MV,OP>* solver ) {
00309 state_ = Passed;
00310 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00311 TestStatus r = (*i)->checkStatus(solver);
00312 if (r == Failed) {
00313 state_ = Failed;
00314 }
00315 else {
00316 TEST_FOR_EXCEPTION(r != Passed,StatusTestError,
00317 "Anasazi::StatusTestCombo::evalAND(): child test gave invalid return");
00318 }
00319 }
00320 return state_;
00321 }
00322
00323 template <class ScalarType, class MV, class OP>
00324 TestStatus StatusTestCombo<ScalarType,MV,OP>::evalSEQAND( Eigensolver<ScalarType,MV,OP>* solver ) {
00325 state_ = Passed;
00326 for (iterator i=tests_.begin(); i != tests_.end(); i++) {
00327 TestStatus r = (*i)->checkStatus(solver);
00328 if (r == Failed) {
00329 state_ = Failed;
00330 break;
00331 }
00332 else {
00333 TEST_FOR_EXCEPTION(r != Passed,StatusTestError,
00334 "Anasazi::StatusTestCombo::evalAND(): child test gave invalid return");
00335 }
00336 }
00337 return state_;
00338 }
00339
00340
00341
00342 }
00343
00344 #endif