11#ifndef ANASAZI_STATUS_TEST_COMBO_HPP
12#define ANASAZI_STATUS_TEST_COMBO_HPP
22#include "Teuchos_Array.hpp"
42template <
class ScalarType,
class MV,
class OP>
46 typedef Teuchos::Array< Teuchos::RCP< StatusTest<ScalarType,MV,OP> > > STPArray;
60#ifndef DOXYGEN_SHOULD_SKIP_THIS
62 typedef Teuchos::Array< Teuchos::RCP< StatusTest<ScalarType,MV,OP> > > t_arr;
63 typedef std::vector< Teuchos::RCP< StatusTest<ScalarType,MV,OP> > > st_vector;
64 typedef typename st_vector::iterator iterator;
65 typedef typename st_vector::const_iterator const_iterator;
146 Teuchos::Array<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > >
getTests()
const {
return tests_;}
153 tests_.push_back(test);
187 std::ostream&
print(std::ostream& os,
int indent = 0)
const;
200 std::vector<int> ind_;
205template <
class ScalarType,
class MV,
class OP>
208 typename STPArray::iterator iter1;
209 iter1 = std::find(tests_.begin(),tests_.end(),test);
210 if (iter1 != tests_.end()) {
217template <
class ScalarType,
class MV,
class OP>
222 state_ = evalOR(solver);
225 state_ = evalAND(solver);
228 state_ = evalSEQOR(solver);
231 state_ = evalSEQAND(solver);
238template <
class ScalarType,
class MV,
class OP>
242 typedef typename STPArray::iterator iter;
243 for (iter i=tests_.begin(); i != tests_.end(); i++) {
248template <
class ScalarType,
class MV,
class OP>
252 typedef typename STPArray::iterator iter;
253 for (iter i=tests_.begin(); i != tests_.end(); i++) {
258template <
class ScalarType,
class MV,
class OP>
260 std::string ind(indent,
' ');
261 os << ind <<
"- StatusTestCombo: ";
264 os <<
"Passed" << std::endl;
267 os <<
"Failed" << std::endl;
270 os <<
"Undefined" << std::endl;
274 typedef typename STPArray::const_iterator const_iter;
275 for (const_iter i=tests_.begin(); i != tests_.end(); i++) {
276 (*i)->print(os,indent+2);
281template <
class ScalarType,
class MV,
class OP>
284 typedef typename STPArray::iterator iter;
285 for (iter i=tests_.begin(); i != tests_.end(); i++) {
287 if (i == tests_.begin()) {
288 ind_ = (*i)->whichVecs();
290 std::sort(ind_.begin(),ind_.end());
296 std::vector<int> iwv = (*i)->whichVecs();
297 std::sort(iwv.begin(),iwv.end());
298 std::vector<int> tmp(ind_.size() + iwv.size());
299 std::vector<int>::iterator end;
300 end = std::set_union(ind_.begin(),ind_.end(),iwv.begin(),iwv.end(),tmp.begin());
301 tmp.resize(end - tmp.begin());
309 TEUCHOS_TEST_FOR_EXCEPTION(r !=
Failed,StatusTestError,
310 "Anasazi::StatusTestCombo::evalOR(): child test gave invalid return");
316template <
class ScalarType,
class MV,
class OP>
317TestStatus StatusTestCombo<ScalarType,MV,OP>::evalSEQOR( Eigensolver<ScalarType,MV,OP>* solver ) {
319 typedef typename STPArray::iterator iter;
320 for (iter i=tests_.begin(); i != tests_.end(); i++) {
322 if (i == tests_.begin()) {
323 ind_ = (*i)->whichVecs();
325 std::sort(ind_.begin(),ind_.end());
331 std::vector<int> iwv = (*i)->whichVecs();
332 std::sort(iwv.begin(),iwv.end());
333 std::vector<int> tmp(ind_.size() + iwv.size());
334 std::vector<int>::iterator end;
335 end = std::set_union(ind_.begin(),ind_.end(),iwv.begin(),iwv.end(),tmp.begin());
336 tmp.resize(end - tmp.begin());
345 TEUCHOS_TEST_FOR_EXCEPTION(r !=
Failed,StatusTestError,
346 "Anasazi::StatusTestCombo::evalSEQOR(): child test gave invalid return");
352template <
class ScalarType,
class MV,
class OP>
353TestStatus StatusTestCombo<ScalarType,MV,OP>::evalAND( Eigensolver<ScalarType,MV,OP>* solver ) {
355 typedef typename STPArray::iterator iter;
356 for (iter i=tests_.begin(); i != tests_.end(); i++) {
358 if (i == tests_.begin()) {
359 ind_ = (*i)->whichVecs();
361 std::sort(ind_.begin(),ind_.end());
367 std::vector<int> iwv = (*i)->whichVecs();
368 std::sort(iwv.begin(),iwv.end());
369 std::vector<int> tmp(ind_.size() + iwv.size());
370 std::vector<int>::iterator end;
371 end = std::set_intersection(ind_.begin(),ind_.end(),iwv.begin(),iwv.end(),tmp.begin());
372 tmp.resize(end - tmp.begin());
380 TEUCHOS_TEST_FOR_EXCEPTION(r !=
Passed,StatusTestError,
381 "Anasazi::StatusTestCombo::evalAND(): child test gave invalid return");
387template <
class ScalarType,
class MV,
class OP>
388TestStatus StatusTestCombo<ScalarType,MV,OP>::evalSEQAND( Eigensolver<ScalarType,MV,OP>* solver ) {
390 typedef typename STPArray::iterator iter;
391 for (iter i=tests_.begin(); i != tests_.end(); i++) {
393 if (i == tests_.begin()) {
394 ind_ = (*i)->whichVecs();
396 std::sort(ind_.begin(),ind_.end());
402 std::vector<int> iwv = (*i)->whichVecs();
403 std::sort(iwv.begin(),iwv.end());
404 std::vector<int> tmp(ind_.size() + iwv.size());
405 std::vector<int>::iterator end;
406 end = std::set_intersection(ind_.begin(),ind_.end(),iwv.begin(),iwv.end(),tmp.begin());
407 tmp.resize(end - tmp.begin());
416 TEUCHOS_TEST_FOR_EXCEPTION(r !=
Passed,StatusTestError,
417 "Anasazi::StatusTestCombo::evalAND(): child test gave invalid return");
Declaration and definition of Anasazi::StatusTest.
Types and exceptions used within Anasazi solvers and interfaces.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
Status test for forming logical combinations of other status tests.
void setComboType(ComboType type)
Set the maximum number of iterations. This also resets the test status to Undefined.
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.
void addTest(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Add a test to the combination.
Teuchos::Array< Teuchos::RCP< StatusTest< ScalarType, MV, OP > > > getTests() const
Get the tests.
void setTests(Teuchos::Array< Teuchos::RCP< StatusTest< ScalarType, MV, OP > > > tests)
Set the tests This also resets the test status to Undefined.
ComboType
Enumerated type to list the types of StatusTestCombo combo types.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
int howMany() const
Get the number of vectors that passed the test.
virtual ~StatusTestCombo()
Destructor.
void removeTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &test)
Removes a test from the combination, if it exists in the tester.
ComboType getComboType() const
Get the maximum number of iterations.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state.
void clearStatus()
Clears the results of the last status test.
StatusTestCombo(ComboType type, Teuchos::Array< Teuchos::RCP< StatusTest< ScalarType, MV, OP > > > tests)
Constructor specifying the StatusTestCombo::ComboType and the tests.
StatusTestCombo()
Default constructor has no tests and initializes to StatusTestCombo::ComboType StatusTestCombo::OR.
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
TestStatus getStatus() const
Return the result of the most recent checkStatus call.
Common interface of stopping criteria for Anasazi's solvers.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
TestStatus
Enumerated type used to pass back information from a StatusTest.