30 #ifndef ANASAZI_STATUS_TEST_ORDEREDRESNORM_HPP 31 #define ANASAZI_STATUS_TEST_ORDEREDRESNORM_HPP 41 #include "Teuchos_ScalarTraits.hpp" 42 #include "Teuchos_LAPACK.hpp" 70 template <
class ScalarType,
class MV,
class OP>
74 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
75 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
161 test_->clearStatus();
168 void setAuxVals(
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &vals) {
170 ivals_.resize(rvals_.size(),MT::zero());
178 void setAuxVals(
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &rvals,
const std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &ivals) {
188 void getAuxVals(std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &rvals, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &ivals)
const {
199 std::ostream&
print(std::ostream& os,
int indent = 0)
const;
204 std::vector<int> ind_;
206 std::vector<MagnitudeType> rvals_, ivals_;
207 Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > sorter_;
208 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
212 template <
class ScalarType,
class MV,
class OP>
214 : state_(
Undefined), ind_(0), quorum_(quorum), rvals_(0), ivals_(0), sorter_(sorter), test_(test)
216 TEUCHOS_TEST_FOR_EXCEPTION(sorter_ == Teuchos::null,
StatusTestError,
"StatusTestWithOrdering::constructor() was passed null pointer for constituent SortManager.");
217 TEUCHOS_TEST_FOR_EXCEPTION(test_ == Teuchos::null,
StatusTestError,
"StatusTestWithOrdering::constructor() was passed null pointer for constituent StatusTest.");
220 template <
class ScalarType,
class MV,
class OP>
247 test_->checkStatus(solver);
248 std::vector<int> cwhch( test_->whichVecs() );
251 std::vector<Value<ScalarType> > solval = solver->
getRitzValues();
252 int numsolval = solval.size();
253 int numauxval = rvals_.size();
254 int numallval = numsolval + numauxval;
256 if (numallval == 0) {
262 std::vector<MagnitudeType> allvalr(numallval), allvali(numallval);
264 for (
int i=0; i<numsolval; ++i) {
265 allvalr[i] = solval[i].realpart;
266 allvali[i] = solval[i].imagpart;
269 std::copy(rvals_.begin(),rvals_.end(),allvalr.begin()+numsolval);
270 std::copy(ivals_.begin(),ivals_.end(),allvali.begin()+numsolval);
273 std::vector<int> perm(numallval);
274 sorter_->sort(allvalr,allvali,Teuchos::rcpFromRef(perm),numallval);
277 std::vector<int> allpass(cwhch.size() + numauxval);
278 std::copy(cwhch.begin(),cwhch.end(),allpass.begin());
279 for (
int i=0; i<numauxval; i++) {
280 allpass[cwhch.size()+i] = -(i+1);
284 int numsig = quorum_ < numallval ? quorum_ : numallval;
286 std::vector<int> mostsig(numsig);
287 for (
int i=0; i<numsig; ++i) {
288 mostsig[i] = perm[i];
291 if (mostsig[i] >= numsolval) {
292 mostsig[i] = mostsig[i]-numsolval-numauxval;
301 std::vector<int>::iterator end;
302 std::sort(mostsig.begin(),mostsig.end());
303 std::sort(allpass.begin(),allpass.end());
304 end = std::set_intersection(mostsig.begin(),mostsig.end(),allpass.begin(),allpass.end(),ind_.begin());
305 ind_.resize(end - ind_.begin());
308 if (ind_.size() >= (
unsigned int)quorum_) {
318 template <
class ScalarType,
class MV,
class OP>
321 std::string ind(indent,
' ');
323 os << ind <<
"- StatusTestWithOrdering: ";
326 os <<
"Passed" << std::endl;
329 os <<
"Failed" << std::endl;
332 os <<
"Undefined" << std::endl;
336 os << ind <<
" Quorum: " << quorum_ << std::endl;
338 os << ind <<
" Auxiliary values: ";
339 if (rvals_.size() > 0) {
340 for (
unsigned int i=0; i<rvals_.size(); i++) {
341 os <<
"(" << rvals_[i] <<
", " << ivals_[i] <<
") ";
346 os <<
"[empty]" << std::endl;
350 os << ind <<
" Which vectors: ";
351 if (ind_.size() > 0) {
352 for (
unsigned int i=0; i<ind_.size(); i++) os << ind_[i] <<
" ";
356 os <<
"[empty]" << std::endl;
360 test_->print(os,indent+2);
virtual std::vector< Value< ScalarType > > getRitzValues()=0
Get the Ritz values from the previous iteration.
Exception thrown to signal error in a status test during Anasazi::StatusTest::checkStatus().
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...
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
void getAuxVals(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rvals, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &ivals) const
Get the auxiliary eigenvalues.
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 setAuxVals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rvals, const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &ivals)
Set the auxiliary eigenvalues.
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
TestStatus getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run...
void setQuorum(int quorum)
Set quorum.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state...
void setAuxVals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &vals)
Set the auxiliary eigenvalues.
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
int getQuorum() const
Get quorum.
virtual ~StatusTestWithOrdering()
Destructor.
void clearStatus()
Clears the results of the last status test.
Common interface of stopping criteria for Anasazi's solvers.
int howMany() const
Get the number of vectors that passed the test.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
Declaration and definition of Anasazi::StatusTest.