34 #ifndef ANASAZI_BASIC_ORTHOMANAGER_HPP
35 #define ANASAZI_BASIC_ORTHOMANAGER_HPP
48 #include "Teuchos_TimeMonitor.hpp"
49 #include "Teuchos_LAPACK.hpp"
50 #include "Teuchos_BLAS.hpp"
51 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
52 # include <Teuchos_FancyOStream.hpp>
57 template<
class ScalarType,
class MV,
class OP>
61 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
62 typedef Teuchos::ScalarTraits<ScalarType> SCT;
73 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType kappa = 1.41421356 ,
74 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType eps = 0.0,
75 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol = 0.20 );
127 Teuchos::Array<Teuchos::RCP<const MV> > Q,
128 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
129 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
130 Teuchos::RCP<MV> MX = Teuchos::null,
131 Teuchos::Array<Teuchos::RCP<const MV> > MQ = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
175 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
176 Teuchos::RCP<MV> MX = Teuchos::null
241 Teuchos::Array<Teuchos::RCP<const MV> > Q,
242 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
243 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
244 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
245 Teuchos::RCP<MV> MX = Teuchos::null,
246 Teuchos::Array<Teuchos::RCP<const MV> > MQ = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
258 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
265 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
266 orthogErrorMat(
const MV &X1,
const MV &X2, Teuchos::RCP<const MV> MX1, Teuchos::RCP<const MV> MX2)
const;
274 void setKappa(
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType kappa ) { kappa_ = kappa; }
277 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
getKappa()
const {
return kappa_; }
283 MagnitudeType kappa_;
288 int findBasis(MV &X, Teuchos::RCP<MV> MX,
289 Teuchos::SerialDenseMatrix<int,ScalarType> &B,
290 bool completeBasis,
int howMany = -1 )
const;
295 Teuchos::RCP<Teuchos::Time> timerReortho_;
302 template<
class ScalarType,
class MV,
class OP>
304 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType kappa,
305 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType eps,
306 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType tol ) :
307 MatOrthoManager<ScalarType,MV,OP>(Op), kappa_(kappa), eps_(eps), tol_(tol)
308 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
309 , timerReortho_(Teuchos::TimeMonitor::getNewTimer(
"Anasazi::BasicOrthoManager::Re-orthogonalization"))
312 TEUCHOS_TEST_FOR_EXCEPTION(eps_ < SCT::magnitude(SCT::zero()),std::invalid_argument,
313 "Anasazi::BasicOrthoManager::BasicOrthoManager(): argument \"eps\" must be non-negative.");
315 Teuchos::LAPACK<int,MagnitudeType> lapack;
316 eps_ = lapack.LAMCH(
'E');
317 eps_ = Teuchos::ScalarTraits<MagnitudeType>::pow(eps_,.75);
319 TEUCHOS_TEST_FOR_EXCEPTION(
320 tol_ < SCT::magnitude(SCT::zero()) || tol_ > SCT::magnitude(SCT::one()),
321 std::invalid_argument,
322 "Anasazi::BasicOrthoManager::BasicOrthoManager(): argument \"tol\" must be in [0,1].");
329 template<
class ScalarType,
class MV,
class OP>
330 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
332 const ScalarType ONE = SCT::one();
333 int rank = MVT::GetNumberVecs(X);
334 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(rank,rank);
336 for (
int i=0; i<rank; i++) {
339 return xTx.normFrobenius();
346 template<
class ScalarType,
class MV,
class OP>
347 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
349 int r1 = MVT::GetNumberVecs(X1);
350 int r2 = MVT::GetNumberVecs(X2);
351 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(r1,r2);
353 return xTx.normFrobenius();
359 template<
class ScalarType,
class MV,
class OP>
362 Teuchos::Array<Teuchos::RCP<const MV> > Q,
363 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
365 Teuchos::Array<Teuchos::RCP<const MV> > MQ
382 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
384 Teuchos::RCP<Teuchos::FancyOStream>
385 out = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
386 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
387 *out <<
"Entering Anasazi::BasicOrthoManager::projectMat(...)\n";
390 ScalarType ONE = SCT::one();
392 int xc = MVT::GetNumberVecs( X );
393 ptrdiff_t xr = MVText::GetGlobalLength( X );
395 std::vector<int> qcs(nq);
397 if (nq == 0 || xc == 0 || xr == 0) {
398 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
399 *out <<
"Leaving Anasazi::BasicOrthoManager::projectMat(...)\n";
403 ptrdiff_t qr = MVText::GetGlobalLength ( *Q[0] );
412 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
413 *out <<
"Allocating MX...\n";
415 if (MX == Teuchos::null) {
417 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
418 OPT::Apply(*(this->_Op),X,*MX);
419 this->_OpCounter += MVT::GetNumberVecs(X);
424 MX = Teuchos::rcpFromRef(X);
426 int mxc = MVT::GetNumberVecs( *MX );
427 ptrdiff_t mxr = MVText::GetGlobalLength( *MX );
430 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
431 "Anasazi::BasicOrthoManager::projectMat(): MVT returned negative dimensions for X,MX" );
433 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr || xr!=qr, std::invalid_argument,
434 "Anasazi::BasicOrthoManager::projectMat(): Size of X not consistent with MX,Q" );
438 for (
int i=0; i<nq; i++) {
439 TEUCHOS_TEST_FOR_EXCEPTION( MVText::GetGlobalLength( *Q[i] ) != qr, std::invalid_argument,
440 "Anasazi::BasicOrthoManager::projectMat(): Q lengths not mutually consistent" );
441 qcs[i] = MVT::GetNumberVecs( *Q[i] );
442 TEUCHOS_TEST_FOR_EXCEPTION( qr < static_cast<ptrdiff_t>(qcs[i]), std::invalid_argument,
443 "Anasazi::BasicOrthoManager::projectMat(): Q has less rows than columns" );
447 if ( C[i] == Teuchos::null ) {
448 C[i] = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(qcs[i],xc) );
451 TEUCHOS_TEST_FOR_EXCEPTION( C[i]->numRows() != qcs[i] || C[i]->numCols() != xc , std::invalid_argument,
452 "Anasazi::BasicOrthoManager::projectMat(): Size of Q not consistent with size of C" );
459 std::vector<ScalarType> oldDot( xc );
460 MVT::MvDot( X, *MX, oldDot );
461 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
462 *out <<
"oldDot = { ";
463 std::copy(oldDot.begin(), oldDot.end(), std::ostream_iterator<ScalarType>(*out,
" "));
469 for (
int i=0; i<nq; i++) {
473 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
474 *out <<
"Applying projector P_Q[" << i <<
"]...\n";
476 MVT::MvTimesMatAddMv( -ONE, *Q[i], *C[i], ONE, X );
481 if (MQ[i] == Teuchos::null) {
482 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
483 *out <<
"Updating MX via M*X...\n";
485 OPT::Apply( *(this->_Op), X, *MX);
486 this->_OpCounter += MVT::GetNumberVecs(X);
489 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
490 *out <<
"Updating MX via M*Q...\n";
492 MVT::MvTimesMatAddMv( -ONE, *MQ[i], *C[i], ONE, *MX );
498 std::vector<ScalarType> newDot(xc);
499 MVT::MvDot( X, *MX, newDot );
500 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
501 *out <<
"newDot = { ";
502 std::copy(newDot.begin(), newDot.end(), std::ostream_iterator<ScalarType>(*out,
" "));
507 for (
int j = 0; j < xc; ++j) {
509 if ( SCT::magnitude(kappa_*newDot[j]) < SCT::magnitude(oldDot[j]) ) {
510 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
511 *out <<
"kappa_*newDot[" <<j<<
"] == " << kappa_*newDot[j] <<
"... another step of Gram-Schmidt.\n";
513 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
514 Teuchos::TimeMonitor lcltimer( *timerReortho_ );
516 for (
int i=0; i<nq; i++) {
517 Teuchos::SerialDenseMatrix<int,ScalarType> C2(*C[i]);
522 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
523 *out <<
"Applying projector P_Q[" << i <<
"]...\n";
525 MVT::MvTimesMatAddMv( -ONE, *Q[i], C2, ONE, X );
529 if (MQ[i] == Teuchos::null) {
530 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
531 *out <<
"Updating MX via M*X...\n";
533 OPT::Apply( *(this->_Op), X, *MX);
534 this->_OpCounter += MVT::GetNumberVecs(X);
537 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
538 *out <<
"Updating MX via M*Q...\n";
540 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MX );
548 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
549 *out <<
"Leaving Anasazi::BasicOrthoManager::projectMat(...)\n";
557 template<
class ScalarType,
class MV,
class OP>
560 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
561 Teuchos::RCP<MV> MX)
const {
565 int xc = MVT::GetNumberVecs(X);
566 ptrdiff_t xr = MVText::GetGlobalLength(X);
571 if (MX == Teuchos::null) {
573 MX = MVT::Clone(X,xc);
574 OPT::Apply(*(this->_Op),X,*MX);
575 this->_OpCounter += MVT::GetNumberVecs(X);
581 if ( B == Teuchos::null ) {
582 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
585 int mxc = (this->_hasOp) ? MVT::GetNumberVecs( *MX ) : xc;
586 ptrdiff_t mxr = (this->_hasOp) ? MVText::GetGlobalLength( *MX ) : xr;
589 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
590 "Anasazi::BasicOrthoManager::normalizeMat(): X must be non-empty" );
591 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
592 "Anasazi::BasicOrthoManager::normalizeMat(): Size of X not consistent with size of B" );
593 TEUCHOS_TEST_FOR_EXCEPTION( xc != mxc || xr != mxr, std::invalid_argument,
594 "Anasazi::BasicOrthoManager::normalizeMat(): Size of X not consistent with size of MX" );
595 TEUCHOS_TEST_FOR_EXCEPTION( static_cast<ptrdiff_t>(xc) > xr, std::invalid_argument,
596 "Anasazi::BasicOrthoManager::normalizeMat(): Size of X not feasible for normalization" );
598 return findBasis(X, MX, *B,
true );
605 template<
class ScalarType,
class MV,
class OP>
608 Teuchos::Array<Teuchos::RCP<const MV> > Q,
609 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
610 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
612 Teuchos::Array<Teuchos::RCP<const MV> > MQ
615 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
617 Teuchos::RCP<Teuchos::FancyOStream>
618 out = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
619 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
620 *out <<
"Entering Anasazi::BasicOrthoManager::projectAndNormalizeMat(...)\n";
624 int xc = MVT::GetNumberVecs( X );
625 ptrdiff_t xr = MVText::GetGlobalLength( X );
631 if ( B == Teuchos::null ) {
632 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
637 if (MX == Teuchos::null) {
639 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
640 *out <<
"Allocating MX...\n";
642 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
643 OPT::Apply(*(this->_Op),X,*MX);
644 this->_OpCounter += MVT::GetNumberVecs(X);
649 MX = Teuchos::rcpFromRef(X);
652 int mxc = MVT::GetNumberVecs( *MX );
653 ptrdiff_t mxr = MVText::GetGlobalLength( *MX );
655 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
"Anasazi::BasicOrthoManager::projectAndNormalizeMat(): X must be non-empty" );
657 ptrdiff_t numbas = 0;
658 for (
int i=0; i<nq; i++) {
659 numbas += MVT::GetNumberVecs( *Q[i] );
663 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
664 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): Size of X must be consistent with size of B" );
666 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
667 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): MVT returned negative dimensions for X,MX" );
669 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr, std::invalid_argument,
670 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): Size of X must be consistent with size of MX" );
672 TEUCHOS_TEST_FOR_EXCEPTION( numbas+xc > xr, std::invalid_argument,
673 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): Orthogonality constraints not feasible" );
676 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
677 *out <<
"Orthogonalizing X against Q...\n";
679 projectMat(X,Q,C,MX,MQ);
681 Teuchos::SerialDenseMatrix<int,ScalarType> oldCoeff(xc,1);
687 int curxsize = xc - rank;
692 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
693 *out <<
"Attempting to find orthonormal basis for X...\n";
695 rank = findBasis(X,MX,*B,
false,curxsize);
697 if (oldrank != -1 && rank != oldrank) {
703 for (
int i=0; i<xc; i++) {
704 (*B)(i,oldrank) = oldCoeff(i,0);
709 if (rank != oldrank) {
717 for (
int i=0; i<xc; i++) {
718 oldCoeff(i,0) = (*B)(i,rank);
725 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
726 *out <<
"Finished computing basis.\n";
731 TEUCHOS_TEST_FOR_EXCEPTION( rank < oldrank,
OrthoError,
732 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): basis lost rank; this shouldn't happen");
734 if (rank != oldrank) {
750 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
751 *out <<
"Randomizing X[" << rank <<
"]...\n";
753 Teuchos::RCP<MV> curX, curMX;
754 std::vector<int> ind(1);
756 curX = MVT::CloneViewNonConst(X,ind);
757 MVT::MvRandom(*curX);
759 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
760 *out <<
"Applying operator to random vector.\n";
762 curMX = MVT::CloneViewNonConst(*MX,ind);
763 OPT::Apply( *(this->_Op), *curX, *curMX );
764 this->_OpCounter += MVT::GetNumberVecs(*curX);
772 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > dummyC(0);
773 projectMat(*curX,Q,dummyC,curMX,MQ);
779 TEUCHOS_TEST_FOR_EXCEPTION( rank > xc || rank < 0, std::logic_error,
780 "Anasazi::BasicOrthoManager::projectAndNormalizeMat(): Debug error in rank variable." );
782 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
783 *out <<
"Leaving Anasazi::BasicOrthoManager::projectAndNormalizeMat(...)\n";
794 template<
class ScalarType,
class MV,
class OP>
796 MV &X, Teuchos::RCP<MV> MX,
797 Teuchos::SerialDenseMatrix<int,ScalarType> &B,
798 bool completeBasis,
int howMany )
const {
815 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
817 Teuchos::RCP<Teuchos::FancyOStream>
818 out = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
819 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
820 *out <<
"Entering Anasazi::BasicOrthoManager::findBasis(...)\n";
823 const ScalarType ONE = SCT::one();
824 const MagnitudeType ZERO = SCT::magnitude(SCT::zero());
826 int xc = MVT::GetNumberVecs( X );
835 TEUCHOS_TEST_FOR_EXCEPTION(this->_hasOp ==
true && MX == Teuchos::null, std::logic_error,
836 "Anasazi::BasicOrthoManager::findBasis(): calling routine did not specify MS.");
837 TEUCHOS_TEST_FOR_EXCEPTION( howMany < 0 || howMany > xc, std::logic_error,
838 "Anasazi::BasicOrthoManager::findBasis(): Invalid howMany parameter" );
843 int xstart = xc - howMany;
845 for (
int j = xstart; j < xc; j++) {
854 for (
int i=j+1; i<xc; ++i) {
859 std::vector<int> index(1);
861 Teuchos::RCP<MV> Xj = MVT::CloneViewNonConst( X, index );
862 Teuchos::RCP<MV> MXj;
863 if ((this->_hasOp)) {
865 MXj = MVT::CloneViewNonConst( *MX, index );
873 std::vector<int> prev_idx( numX );
874 Teuchos::RCP<const MV> prevX, prevMX;
877 for (
int i=0; i<numX; ++i) prev_idx[i] = i;
878 prevX = MVT::CloneViewNonConst( X, prev_idx );
880 prevMX = MVT::CloneViewNonConst( *MX, prev_idx );
889 for (
int numTrials = 0; numTrials < 10; numTrials++) {
890 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
891 *out <<
"Trial " << numTrials <<
" for vector " << j <<
"\n";
895 Teuchos::SerialDenseMatrix<int,ScalarType> product(numX, 1);
896 std::vector<MagnitudeType> origNorm(1), newNorm(1), newNorm2(1);
901 Teuchos::RCP<MV> oldMXj = MVT::CloneCopy( *MXj );
903 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
904 *out <<
"origNorm = " << origNorm[0] <<
"\n";
915 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
916 *out <<
"Orthogonalizing X[" << j <<
"]...\n";
918 MVT::MvTimesMatAddMv( -ONE, *prevX, product, ONE, *Xj );
925 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
926 *out <<
"Updating MX[" << j <<
"]...\n";
928 MVT::MvTimesMatAddMv( -ONE, *prevMX, product, ONE, *MXj );
933 MagnitudeType product_norm = product.normOne();
935 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
936 *out <<
"newNorm = " << newNorm[0] <<
"\n";
937 *out <<
"prodoct_norm = " << product_norm <<
"\n";
941 if ( product_norm/newNorm[0] >= tol_ || newNorm[0] < eps_*origNorm[0]) {
942 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
943 if (product_norm/newNorm[0] >= tol_) {
944 *out <<
"product_norm/newNorm == " << product_norm/newNorm[0] <<
"... another step of Gram-Schmidt.\n";
947 *out <<
"eps*origNorm == " << eps_*origNorm[0] <<
"... another step of Gram-Schmidt.\n";
952 Teuchos::SerialDenseMatrix<int,ScalarType> P2(numX,1);
955 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
956 *out <<
"Orthogonalizing X[" << j <<
"]...\n";
958 MVT::MvTimesMatAddMv( -ONE, *prevX, P2, ONE, *Xj );
959 if ((this->_hasOp)) {
960 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
961 *out <<
"Updating MX[" << j <<
"]...\n";
963 MVT::MvTimesMatAddMv( -ONE, *prevMX, P2, ONE, *MXj );
967 product_norm = P2.normOne();
968 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
969 *out <<
"newNorm2 = " << newNorm2[0] <<
"\n";
970 *out <<
"product_norm = " << product_norm <<
"\n";
972 if ( product_norm/newNorm2[0] >= tol_ || newNorm2[0] < eps_*origNorm[0] ) {
974 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
975 if (product_norm/newNorm2[0] >= tol_) {
976 *out <<
"product_norm/newNorm2 == " << product_norm/newNorm2[0] <<
"... setting vector to zero.\n";
978 else if (newNorm[0] < newNorm2[0]) {
979 *out <<
"newNorm2 > newNorm... setting vector to zero.\n";
982 *out <<
"eps*origNorm == " << eps_*origNorm[0] <<
"... setting vector to zero.\n";
985 MVT::MvInit(*Xj,ZERO);
986 if ((this->_hasOp)) {
987 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
988 *out <<
"Setting MX[" << j <<
"] to zero as well.\n";
990 MVT::MvInit(*MXj,ZERO);
997 if (numTrials == 0) {
998 for (
int i=0; i<numX; i++) {
999 B(i,j) = product(i,0);
1005 if ( newNorm[0] != ZERO && newNorm[0] > SCT::sfmin() ) {
1006 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1007 *out <<
"Normalizing X[" << j <<
"], norm(X[" << j <<
"]) = " << newNorm[0] <<
"\n";
1011 MVT::MvScale( *Xj, ONE/newNorm[0]);
1013 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1014 *out <<
"Normalizing M*X[" << j <<
"]...\n";
1017 MVT::MvScale( *MXj, ONE/newNorm[0]);
1021 if (numTrials == 0) {
1022 B(j,j) = newNorm[0];
1030 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1031 *out <<
"Not normalizing M*X[" << j <<
"]...\n";
1038 if (completeBasis) {
1040 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1041 *out <<
"Inserting random vector in X[" << j <<
"]...\n";
1043 MVT::MvRandom( *Xj );
1045 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1046 *out <<
"Updating M*X[" << j <<
"]...\n";
1048 OPT::Apply( *(this->_Op), *Xj, *MXj );
1049 this->_OpCounter += MVT::GetNumberVecs(*Xj);
1060 if (rankDef ==
true) {
1061 TEUCHOS_TEST_FOR_EXCEPTION( rankDef && completeBasis, OrthoError,
1062 "Anasazi::BasicOrthoManager::findBasis(): Unable to complete basis" );
1063 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1064 *out <<
"Returning early, rank " << j <<
" from Anasazi::BasicOrthoManager::findBasis(...)\n";
1071 #ifdef ANASAZI_BASIC_ORTHO_DEBUG
1072 *out <<
"Returning " << xc <<
" from Anasazi::BasicOrthoManager::findBasis(...)\n";
1079 #endif // ANASAZI_BASIC_ORTHOMANAGER_HPP
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 ...
Teuchos::ScalarTraits< ScalarType >::magnitudeType getKappa() const
Return parameter for re-orthogonalization threshold.
~BasicOrthoManager()
Destructor.
Declaration of basic traits for the multivector type.
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.
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...
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogErrorMat(const MV &X1, const MV &X2, Teuchos::RCP< const MV > MX1, Teuchos::RCP< const MV > MX2) const
This method computes the error in orthogonality of two multivectors, measured as the Frobenius norm o...
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
void setKappa(typename Teuchos::ScalarTraits< ScalarType >::magnitudeType kappa)
Set parameter for re-orthogonalization threshold.
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
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 ...
Exception thrown to signal error in an orthogonalization manager method.
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 ...
BasicOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType kappa=1.41421356, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType eps=0.0, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType tol=0.20)
Constructor specifying re-orthogonalization tolerance.
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using (potentially)...
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 ...
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.