35 #ifndef ANASAZI_SVQB_ORTHOMANAGER_HPP 36 #define ANASAZI_SVQB_ORTHOMANAGER_HPP 55 template<
class ScalarType,
class MV,
class OP>
284 bool normalize_in )
const;
290 template<
class ScalarType,
class MV,
class OP>
292 :
MatOrthoManager<ScalarType,MV,OP>(Op), dbgstr(
" *** "), debug_(debug) {
295 eps_ = lapack.
LAMCH(
'E');
297 std::cout <<
"eps_ == " << eps_ << std::endl;
304 template<
class ScalarType,
class MV,
class OP>
311 for (
int i=0; i<rank; i++) {
319 template<
class ScalarType,
class MV,
class OP>
337 template<
class ScalarType,
class MV,
class OP>
345 findBasis(X,MX,C,Teuchos::null,Q,
false);
352 template<
class ScalarType,
class MV,
class OP>
359 return findBasis(X,MX,C,B,Q,
true);
366 template<
class ScalarType,
class MV,
class OP>
375 return findBasis(X,MX,C,B,Q,
true);
407 template<
class ScalarType,
class MV,
class OP>
413 bool normalize_in)
const {
431 std::vector<int> qcs(nq);
432 for (
int i=0; i<nq; i++) {
437 if (normalize_in ==
true && qsize + xc > xr) {
440 "Anasazi::SVQBOrthoManager::findBasis(): Orthogonalization constraints not feasible" );
444 if (normalize_in ==
false && (qsize == 0 || xc == 0)) {
448 else if (normalize_in ==
true && (xc == 0 || xr == 0)) {
451 "Anasazi::SVQBOrthoManager::findBasis(): X must be non-empty" );
456 "Anasazi::SVQBOrthoManager::findBasis(): Size of X not consistant with size of Q" );
465 for (
int i=0; i<nq; i++) {
468 "Anasazi::SVQBOrthoManager::findBasis(): Size of Q not mutually consistant" );
470 "Anasazi::SVQBOrthoManager::findBasis(): Q has less rows than columns" );
472 if ( C[i] == Teuchos::null ) {
477 "Anasazi::SVQBOrthoManager::findBasis(): Size of Q not consistant with C" );
480 C[i]->putScalar(ZERO);
490 if (normalize_in ==
true) {
491 if ( B == Teuchos::null ) {
495 "Anasazi::SVQBOrthoManager::findBasis(): Size of B not consistant with X" );
498 for (
int i=0; i<xc; i++) {
515 if (MX == Teuchos::null) {
523 MX = Teuchos::rcpFromRef(X);
525 std::vector<ScalarType> normX(xc), invnormX(xc);
532 std::vector<ScalarType> work;
533 std::vector<MagnitudeType> lambda, lambdahi, rwork;
536 int lwork = lapack.
ILAENV(1,
"hetrd",
"VU",xc,-1,-1,-1);
540 "Anasazi::SVQBOrthoManager::findBasis(): Error code from ILAENV" );
542 lwork = (lwork+2)*xc;
545 lwork = (3*xc-2 > 1) ? 3*xc - 2 : 1;
557 "Anasazi::SVQBOrthoManager::findBasis(): Size of X not consistant with MX" );
560 bool doGramSchmidt =
true;
565 while (doGramSchmidt) {
575 std::vector<MagnitudeType> normX_mag(xc);
577 for (
int i=0; i<xc; ++i) {
578 normX[i] = normX_mag[i];
579 invnormX[i] = (normX_mag[i] == ZERO) ? ZERO : MONE/normX_mag[i];
589 std::vector<MagnitudeType> nrm2(xc);
590 std::cout << dbgstr <<
"max post-scale norm: (with/without MX) : ";
591 MagnitudeType maxpsnw = ZERO, maxpsnwo = ZERO;
593 for (
int i=0; i<xc; i++) {
594 maxpsnw = (nrm2[i] > maxpsnw ? nrm2[i] : maxpsnw);
597 for (
int i=0; i<xc; i++) {
598 maxpsnwo = (nrm2[i] > maxpsnwo ? nrm2[i] : maxpsnwo);
600 std::cout <<
"(" << maxpsnw <<
"," << maxpsnwo <<
")" << std::endl;
603 for (
int i=0; i<nq; i++) {
607 for (
int i=0; i<nq; i++) {
623 MagnitudeType maxNorm = ZERO;
624 for (
int j=0; j<xc; j++) {
625 MagnitudeType sum = ZERO;
626 for (
int k=0; k<nq; k++) {
627 for (
int i=0; i<qcs[k]; i++) {
631 maxNorm = (sum > maxNorm) ? sum : maxNorm;
635 if (maxNorm < 0.36) {
636 doGramSchmidt =
false;
640 for (
int k=0; k<nq; k++) {
641 for (
int j=0; j<xc; j++) {
642 for (
int i=0; i<qcs[k]; i++) {
643 (*newC[k])(i,j) *= normX[j];
651 for (
int i=0; i<nq; i++) {
653 TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
"Anasazi::SVQBOrthoManager::findBasis(): Input error to SerialDenseMatrix::multiply.");
658 for (
int i=0; i<nq; i++) {
665 doGramSchmidt =
false;
673 MagnitudeType condT = tolerance;
675 while (condT >= tolerance) {
683 std::vector<MagnitudeType> Dh(xc), Dhi(xc);
684 for (
int i=0; i<xc; i++) {
686 Dhi[i] = (Dh[i] == ZERO ? ZERO : MONE/Dh[i]);
689 for (
int i=0; i<xc; i++) {
690 for (
int j=0; j<xc; j++) {
691 XtMX(i,j) *= Dhi[i]*Dhi[j];
697 lapack.
HEEV(
'V',
'U', xc, XtMX.values(), XtMX.stride(), &lambda[0], &work[0], work.size(), &rwork[0], &info);
698 std::stringstream os;
699 os <<
"Anasazi::SVQBOrthoManager::findBasis(): Error code " << info <<
" from HEEV";
703 std::cout << dbgstr <<
"eigenvalues of XtMX: (";
704 for (
int i=0; i<xc-1; i++) {
705 std::cout << lambda[i] <<
",";
707 std::cout << lambda[xc-1] <<
")" << std::endl;
712 MagnitudeType maxLambda = lambda[xc-1],
713 minLambda = lambda[0];
715 for (
int i=0; i<xc; i++) {
716 if (lambda[i] <= 10*eps_*maxLambda) {
729 lambdahi[i] = MONE/lambda[i];
736 std::vector<int> ind(xc);
737 for (
int i=0; i<xc; i++) {ind[i] = i;}
742 for (
int j=0; j<xc; j++) {
743 for (
int i=0; i<xc; i++) {
744 workU(i,j) *= Dhi[i]*lambdahi[j];
754 if (maxLambda >= tolerance * minLambda) {
771 for (
int j=0; j<xc; j++) {
772 for (
int i=0; i<xc; i++) {
773 workU(i,j) = Dh[i] * (*B)(i,j);
777 TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
"Anasazi::SVQBOrthoManager::findBasis(): Input error to SerialDenseMatrix::multiply.");
778 for (
int j=0; j<xc ;j++) {
779 for (
int i=0; i<xc; i++) {
780 (*B)(i,j) *= lambda[i];
787 std::cout << dbgstr <<
"augmenting multivec with " << iZeroMax+1 <<
" random directions" << std::endl;
792 std::vector<int> ind2(iZeroMax+1);
793 for (
int i=0; i<iZeroMax+1; i++) {
803 MXnull = Teuchos::null;
805 Xnull = Teuchos::null;
807 doGramSchmidt =
true;
813 std::cout << dbgstr <<
"condT: " << condT <<
", tolerance = " << tolerance << std::endl;
818 doGramSchmidt =
true;
828 std::cout << dbgstr <<
"(numGS,numSVQB,numRand) : " 840 #endif // ANASAZI_SVQB_ORTHOMANAGER_HPP static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
static ptrdiff_t GetGlobalLength(const MV &mv)
void norm(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Implements the interface OrthoManager::norm().
Declaration of basic traits for the multivector type.
int normalizeMat(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null, Teuchos::RCP< MV > MX=Teuchos::null) const
This method takes a multivector X and attempts to compute an orthonormal basis for ...
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
OrdinalType ILAENV(const OrdinalType ispec, const std::string &NAME, const std::string &OPTS, const OrdinalType N1=-1, const OrdinalType N2=-1, const OrdinalType N3=-1, const OrdinalType N4=-1) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Virtual base class which defines basic traits for the operator type.
void innerProdMat(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z, Teuchos::RCP< const MV > MX=Teuchos::null, Teuchos::RCP< const MV > MY=Teuchos::null) const
Provides a matrix-based inner product.
ScalarType LAMCH(const char CMACH) const
static void Apply(const OP &Op, const MV &x, MV &y)
Application method which performs operation y = Op*x. An OperatorError exception is thrown if there i...
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using the SVQB iter...
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
int projectAndNormalizeMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null, Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::RCP< const MV >(Teuchos::null))) const
Given a set of bases Q[i] and a multivector X, this method computes an orthonormal basis for ...
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogErrorMat(const MV &X, const MV &Y, Teuchos::RCP< const MV > MX=Teuchos::null, Teuchos::RCP< const MV > MY=Teuchos::null) const
This method computes the error in orthogonality of two multivectors, measured as the Frobenius norm o...
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
Exception thrown to signal error in an orthogonalization manager method.
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
static magnitudeType magnitude(ScalarType a)
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormErrorMat(const MV &X, Teuchos::RCP< const MV > MX=Teuchos::null) const
This method computes the error in orthonormality of a multivector, measured as the Frobenius norm of ...
void HEEV(const char JOBZ, const char UPLO, const OrdinalType n, ScalarType *A, const OrdinalType lda, MagnitudeType *W, ScalarType *WORK, const OrdinalType lwork, MagnitudeType *RWORK, OrdinalType *info) const
~SVQBOrthoManager()
Destructor.
int reshape(OrdinalType numRows, OrdinalType numCols)
void projectMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::RCP< const MV >(Teuchos::null))) const
Given a list of mutually orthogonal and internally orthonormal bases Q, this method projects a multiv...
SVQBOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null, bool debug=false)
Constructor specifying re-orthogonalization tolerance.
void normMat(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, Teuchos::RCP< const MV > MX=Teuchos::null) const
Provides the norm induced by the matrix-based inner product.
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.