AnasaziStatusTestCombo.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
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   // print children, with extra indention
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 } // end of Anasazi namespace
00343 
00344 #endif /* ANASAZI_STATUS_TEST_COMBO_HPP */

Generated on Thu Sep 18 12:31:38 2008 for Anasazi by doxygen 1.3.9.1