43#ifndef ANASAZI_STATUS_TEST_ORDEREDRESNORM_HPP
44#define ANASAZI_STATUS_TEST_ORDEREDRESNORM_HPP
54#include "Teuchos_ScalarTraits.hpp"
82template <
class ScalarType,
class MV,
class OP>
86 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
87 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
173 test_->clearStatus();
180 void setAuxVals(
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &vals) {
182 ivals_.resize(rvals_.size(),MT::zero());
190 void setAuxVals(
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &rvals,
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &ivals) {
200 void getAuxVals(std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &rvals, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &ivals)
const {
211 std::ostream&
print(std::ostream& os,
int indent = 0)
const;
216 std::vector<int> ind_;
218 std::vector<MagnitudeType> rvals_, ivals_;
219 Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > sorter_;
220 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
224template <
class ScalarType,
class MV,
class OP>
226 : state_(
Undefined), ind_(0), quorum_(quorum), rvals_(0), ivals_(0), sorter_(sorter), test_(test)
228 TEUCHOS_TEST_FOR_EXCEPTION(sorter_ == Teuchos::null,
StatusTestError,
"StatusTestWithOrdering::constructor() was passed null pointer for constituent SortManager.");
229 TEUCHOS_TEST_FOR_EXCEPTION(test_ == Teuchos::null,
StatusTestError,
"StatusTestWithOrdering::constructor() was passed null pointer for constituent StatusTest.");
232template <
class ScalarType,
class MV,
class OP>
259 test_->checkStatus(solver);
260 std::vector<int> cwhch( test_->whichVecs() );
263 std::vector<Value<ScalarType> > solval = solver->
getRitzValues();
264 int numsolval = solval.size();
265 int numauxval = rvals_.size();
266 int numallval = numsolval + numauxval;
268 if (numallval == 0) {
274 std::vector<MagnitudeType> allvalr(numallval), allvali(numallval);
276 for (
int i=0; i<numsolval; ++i) {
277 allvalr[i] = solval[i].realpart;
278 allvali[i] = solval[i].imagpart;
281 std::copy(rvals_.begin(),rvals_.end(),allvalr.begin()+numsolval);
282 std::copy(ivals_.begin(),ivals_.end(),allvali.begin()+numsolval);
285 std::vector<int> perm(numallval);
286 sorter_->sort(allvalr,allvali,Teuchos::rcpFromRef(perm),numallval);
289 std::vector<int> allpass(cwhch.size() + numauxval);
290 std::copy(cwhch.begin(),cwhch.end(),allpass.begin());
291 for (
int i=0; i<numauxval; i++) {
292 allpass[cwhch.size()+i] = -(i+1);
296 int numsig = quorum_ < numallval ? quorum_ : numallval;
298 std::vector<int> mostsig(numsig);
299 for (
int i=0; i<numsig; ++i) {
300 mostsig[i] = perm[i];
303 if (mostsig[i] >= numsolval) {
304 mostsig[i] = mostsig[i]-numsolval-numauxval;
313 std::vector<int>::iterator end;
314 std::sort(mostsig.begin(),mostsig.end());
315 std::sort(allpass.begin(),allpass.end());
316 end = std::set_intersection(mostsig.begin(),mostsig.end(),allpass.begin(),allpass.end(),ind_.begin());
317 ind_.resize(end - ind_.begin());
320 if (ind_.size() >= (
unsigned int)quorum_) {
330template <
class ScalarType,
class MV,
class OP>
333 std::string ind(indent,
' ');
335 os << ind <<
"- StatusTestWithOrdering: ";
338 os <<
"Passed" << std::endl;
341 os <<
"Failed" << std::endl;
344 os <<
"Undefined" << std::endl;
348 os << ind <<
" Quorum: " << quorum_ << std::endl;
350 os << ind <<
" Auxiliary values: ";
351 if (rvals_.size() > 0) {
352 for (
unsigned int i=0; i<rvals_.size(); i++) {
353 os <<
"(" << rvals_[i] <<
", " << ivals_[i] <<
") ";
358 os <<
"[empty]" << std::endl;
362 os << ind <<
" Which vectors: ";
363 if (ind_.size() > 0) {
364 for (
unsigned int i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
368 os <<
"[empty]" << std::endl;
372 test_->print(os,indent+2);
Declaration and definition of Anasazi::StatusTest.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
virtual std::vector< Value< ScalarType > > getRitzValues()=0
Get the Ritz values from the previous iteration.
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Exception thrown to signal error in a status test during Anasazi::StatusTest::checkStatus().
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
void clearStatus()
Clears the results of the last status test.
int getQuorum() const
Get quorum.
void getAuxVals(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rvals, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &ivals) const
Get the auxiliary eigenvalues.
int howMany() const
Get the number of vectors that passed the test.
void setAuxVals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rvals, const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &ivals)
Set the auxiliary eigenvalues.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
virtual ~StatusTestWithOrdering()
Destructor.
TestStatus getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run.
void setAuxVals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &vals)
Set the auxiliary eigenvalues.
void setQuorum(int quorum)
Set quorum.
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.
StatusTestWithOrdering(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, Teuchos::RCP< SortManager< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > sorter, int quorum=-1)
Constructor.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state.
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.