10#ifndef ANASAZI_GENERALIZED_DAVIDSON_HPP
11#define ANASAZI_GENERALIZED_DAVIDSON_HPP
19#include "Teuchos_RCPDecl.hpp"
20#include "Teuchos_ParameterList.hpp"
21#include "Teuchos_SerialDenseMatrix.hpp"
22#include "Teuchos_SerialDenseVector.hpp"
23#include "Teuchos_Array.hpp"
24#include "Teuchos_BLAS.hpp"
25#include "Teuchos_LAPACK.hpp"
26#include "Teuchos_FancyOStream.hpp"
44template <
class ScalarType,
class MV>
77 std::vector< Value<ScalarType> >
eVals;
108template <
class ScalarType,
class MV,
class OP>
115 typedef Teuchos::ScalarTraits<ScalarType> ST;
116 typedef typename ST::magnitudeType MagnitudeType;
117 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
146 Teuchos::ParameterList &
pl);
184 if( !d_ritzVectorsValid )
185 computeRitzVectors();
199 if( !d_ritzIndexValid )
211 return d_expansionIndices;
280 Teuchos::Array< RCP<const MV> >
getAuxVecs()
const {
return d_auxVecs; }
314 void expandSearchSpace();
317 void applyOperators();
320 void updateProjections();
323 void solveProjectedEigenproblem();
326 void computeProjectedEigenvectors( Teuchos::SerialDenseMatrix<int,ScalarType> &X );
329 void scaleEigenvectors(
const Teuchos::SerialDenseMatrix<int,ScalarType> &X,
330 Teuchos::SerialDenseMatrix<int,ScalarType> &
X_alpha,
331 Teuchos::SerialDenseMatrix<int,ScalarType> &
X_beta );
334 void sortValues( std::vector<MagnitudeType> &
realParts,
340 void computeResidual();
343 void computeRitzIndex();
346 void computeRitzVectors();
350 Teuchos::ParameterList d_pl;
359 int d_maxSubspaceDim;
362 std::string d_initType;
364 bool d_relativeConvergence;
373 std::vector< Value<ScalarType> > d_eigenvalues;
377 std::vector<MagnitudeType> d_resNorms;
385 Teuchos::Array< RCP<const MV> > d_auxVecs;
396 std::vector<MagnitudeType> d_alphar;
397 std::vector<MagnitudeType> d_alphai;
398 std::vector<MagnitudeType> d_betar;
399 std::vector<int> d_ritzIndex;
400 std::vector<int> d_convergedIndices;
401 std::vector<int> d_expansionIndices;
414 std::string d_testSpace;
422 bool d_ritzIndexValid;
423 bool d_ritzVectorsValid;
430template <
class MagnitudeType,
class MV,
class OP>
431class GeneralizedDavidson<std::complex<MagnitudeType>,MV,OP>
435 typedef std::complex<MagnitudeType> ScalarType;
437 const RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
438 const RCP<SortManager<MagnitudeType> > &sortman,
439 const RCP<OutputManager<ScalarType> > &outputman,
440 const RCP<StatusTest<ScalarType,MV,OP> > &tester,
441 const RCP<OrthoManager<ScalarType,MV> > &orthoman,
442 Teuchos::ParameterList &pl)
445 MagnitudeType::this_class_is_missing_a_specialization();
456template <
class ScalarType,
class MV,
class OP>
463 Teuchos::ParameterList &
pl )
475 std::invalid_argument,
"Either A or Operator must be non-null on Eigenproblem");
485 d_NEV = d_problem->getNEV();
486 d_initType = d_pl.get<std::string>(
"Initial Guess",
"Random");
487 d_numToPrint = d_pl.get<
int>(
"Print Number of Ritz Values",-1);
488 d_useLeading = d_pl.get<
bool>(
"Use Leading Vectors",
false);
490 if( d_B != Teuchos::null )
495 if( d_P != Teuchos::null )
500 d_testSpace = d_pl.get<std::string>(
"Test Space",
"V");
502 "Anasazi::GeneralizedDavidson: Test Space must be V, AV, or BV" );
504 "Anasazi::GeneralizedDavidson: Test Space must be V for standard eigenvalue problem" );
507 int blockSize = d_pl.get<
int>(
"Block Size",1);
510 d_maxSubspaceDim = -1;
512 d_relativeConvergence = d_pl.get<
bool>(
"Relative Convergence Tolerance",
false);
518 std::invalid_argument,
"Maximum Subspace Dimension must be strictly greater than NEV");
520 std::invalid_argument,
"Maximum Subspace Dimension cannot exceed problem size");
526 d_ritzIndexValid =
false;
527 d_ritzVectorsValid =
false;
534template <
class ScalarType,
class MV,
class OP>
540 d_outputMan->stream(
Warnings) <<
"WARNING: GeneralizedDavidson::iterate called without first calling initialize" << std::endl;
541 d_outputMan->stream(
Warnings) <<
" Default initialization will be performed" << std::endl;
546 if( d_outputMan->isVerbosity(
Debug) )
548 currentStatus( d_outputMan->stream(
Debug) );
555 while( d_tester->getStatus() !=
Passed && d_curDim+d_expansionSize <= d_maxSubspaceDim )
565 solveProjectedEigenproblem();
570 int numToSort = std::max(d_blockSize,d_NEV);
577 if( d_outputMan->isVerbosity(
Debug) )
579 currentStatus( d_outputMan->stream(
Debug) );
591template <
class ScalarType,
class MV,
class OP>
595 state.curDim = d_curDim;
605 state.eVals = getRitzValues();
612template <
class ScalarType,
class MV,
class OP>
621template <
class ScalarType,
class MV,
class OP>
628 d_initialized =
false;
630 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidson: Allocating eigenproblem"
631 <<
" state with block size of " << d_blockSize
632 <<
" and maximum subspace dimension of " << d_maxSubspaceDim << std::endl;
635 d_alphar.resize(d_maxSubspaceDim);
636 d_alphai.resize(d_maxSubspaceDim);
637 d_betar.resize(d_maxSubspaceDim);
640 int msd = d_maxSubspaceDim;
650 d_VAV = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
651 d_S = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
652 d_Q = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
653 d_Z = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
659 d_VBV = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
660 d_T = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
msd,
msd) );
671 d_R = MVT::Clone(*
initVec,std::max(d_blockSize,d_NEV)+1);
672 d_ritzVecSpace = MVT::Clone(*
initVec,std::max(d_blockSize,d_NEV)+1);
687template <
class ScalarType,
class MV,
class OP>
692 d_curDim = (
state.curDim > 0 ?
state.curDim : d_blockSize );
694 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidson: Initializing state"
695 <<
" with subspace dimension " << d_curDim << std::endl;
698 std::vector<int>
initInds(d_curDim);
699 for(
int i=0;
i<d_curDim; ++
i )
707 if(
state.curDim > 0 &&
state.V != Teuchos::null && MVT::GetNumberVecs(*
state.V) >= d_curDim )
714 else if( MVT::GetNumberVecs(*d_problem->getInitVec()) < d_blockSize || d_initType ==
"Random" )
730 int rank = d_orthoMan->projectAndNormalize( *
V1, d_auxVecs );
732 "Anasazi::GeneralizedDavidson::initialize(): Error generating initial orthonormal basis" );
735 if( d_outputMan->isVerbosity(
Debug) )
737 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidson: Error in V^T V == I: "
738 << d_orthoMan->orthonormError( *
V1 ) << std::endl;
746 if( !
reset_V &&
state.AV != Teuchos::null && MVT::GetNumberVecs(*
state.AV) >= d_curDim )
748 if(
state.AV != d_AV )
754 OPT::Apply( *d_A, *
V1, *
AV1 );
755 d_opApplies += MVT::GetNumberVecs( *
V1 );
759 Teuchos::SerialDenseMatrix<int,ScalarType>
VAV1( Teuchos::View, *d_VAV, d_curDim, d_curDim );
762 if( !
reset_V &&
state.VAV != Teuchos::null &&
state.VAV->numRows() >= d_curDim &&
state.VAV->numCols() >= d_curDim )
764 if(
state.VAV != d_VAV )
766 Teuchos::SerialDenseMatrix<int,ScalarType>
state_VAV( Teuchos::View, *
state.VAV, d_curDim, d_curDim );
773 if( d_testSpace ==
"V" )
775 MVT::MvTransMv( ST::one(), *
V1, *
AV1,
VAV1 );
777 else if( d_testSpace ==
"AV" )
779 MVT::MvTransMv( ST::one(), *
AV1, *
AV1,
VAV1 );
781 else if( d_testSpace ==
"BV" )
784 MVT::MvTransMv( ST::one(), *
BV1, *
AV1,
VAV1 );
795 if( !
reset_V &&
state.BV != Teuchos::null && MVT::GetNumberVecs(*
state.BV) >= d_curDim )
797 if(
state.BV != d_BV )
803 OPT::Apply( *d_B, *
V1, *
BV1 );
807 Teuchos::SerialDenseMatrix<int,ScalarType>
VBV1( Teuchos::View, *d_VBV, d_curDim, d_curDim );
810 if( !
reset_V &&
state.VBV != Teuchos::null &&
state.VBV->numRows() >= d_curDim &&
state.VBV->numCols() >= d_curDim )
812 if(
state.VBV != d_VBV )
814 Teuchos::SerialDenseMatrix<int,ScalarType>
state_VBV( Teuchos::View, *
state.VBV, d_curDim, d_curDim );
821 if( d_testSpace ==
"V" )
823 MVT::MvTransMv( ST::one(), *
V1, *
BV1,
VBV1 );
825 else if( d_testSpace ==
"AV" )
827 MVT::MvTransMv( ST::one(), *
AV1, *
BV1,
VBV1 );
829 else if( d_testSpace ==
"BV" )
831 MVT::MvTransMv( ST::one(), *
BV1, *
BV1,
VBV1 );
837 solveProjectedEigenproblem();
840 int numToSort = std::max(d_blockSize,d_NEV);
848 d_initialized =
true;
854template <
class ScalarType,
class MV,
class OP>
864template <
class ScalarType,
class MV,
class OP>
865std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
868 return getResNorms(d_residualSize);
874template <
class ScalarType,
class MV,
class OP>
875std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>
884 std::vector<MagnitudeType>
resNorms;
893template <
class ScalarType,
class MV,
class OP>
901 if( d_betar[
ival] != MT::zero() )
921template <
class ScalarType,
class MV,
class OP>
935 d_initialized =
false;
941template <
class ScalarType,
class MV,
class OP>
946 std::vector< Value<ScalarType> >
ritzVals = getRitzValues();
947 for(
int i=0;
i<d_curDim; ++
i )
956 std::vector<int>
sel(d_curDim,0);
972 Teuchos::LAPACK<int,ScalarType>
lapack;
973 lapack.TGSEN(
ijob,
wantq,
wantz, &
sel[0], d_curDim, d_S->values(), d_S->stride(), d_T->values(), d_T->stride(),
974 &d_alphar[0], &d_alphai[0], &d_betar[0], d_Q->values(), d_Q->stride(), d_Z->values(), d_Z->stride(),
977 d_ritzIndexValid =
false;
978 d_ritzVectorsValid =
false;
980 std::stringstream
ss;
981 ss <<
"Anasazi::GeneralizedDavidson: TGSEN returned error code " <<
info << std::endl;
988 d_outputMan->stream(
Warnings) <<
"WARNING: " <<
ss.str() << std::endl;
989 d_outputMan->stream(
Warnings) <<
" Problem may not be correctly sorted" << std::endl;
1002 Teuchos::LAPACK<int,ScalarType>
lapack;
1004 d_S->stride (), d_Z->values (), d_Z->stride (),
1005 &d_alphar[0], &d_alphai[0], &
subDim, 0, 0, &
work[0],
1008 std::fill( d_betar.begin(), d_betar.end(), ST::one() );
1010 d_ritzIndexValid =
false;
1011 d_ritzVectorsValid =
false;
1014 info < 0, std::runtime_error,
"Anasazi::GeneralizedDavidson::"
1015 "sortProblem: LAPACK routine TRSEN returned error code INFO = "
1016 <<
info <<
" < 0. This indicates that argument " << -
info
1017 <<
" (counting starts with one) of TRSEN had an illegal value.");
1024 info == 1, std::runtime_error,
"Anasazi::GeneralizedDavidson::"
1025 "sortProblem: LAPACK routine TRSEN returned error code INFO = 1. "
1026 "This indicates that the reordering failed because some eigenvalues "
1027 "are too close to separate (the problem is very ill-conditioned).");
1030 info > 1, std::logic_error,
"Anasazi::GeneralizedDavidson::"
1031 "sortProblem: LAPACK routine TRSEN returned error code INFO = "
1032 <<
info <<
" > 1. This should not be possible. It may indicate an "
1033 "error either in LAPACK itself, or in Teuchos' LAPACK wrapper.");
1045template <
class ScalarType,
class MV,
class OP>
1050 std::vector<int>
newIndices(d_expansionSize);
1051 for(
int i=0;
i<d_expansionSize; ++
i )
1058 for(
int i=0;
i<d_curDim; ++
i )
1064 RCP<const MV>
R_active = MVT::CloneView( *d_R, d_expansionIndices);
1078 Teuchos::Array< RCP<const MV> >
against = d_auxVecs;
1082 if( d_outputMan->isVerbosity(
Debug) )
1084 std::vector<int>
allIndices(d_curDim+d_expansionSize);
1085 for(
int i=0;
i<d_curDim+d_expansionSize; ++
i )
1090 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidson: Error in V^T V == I: "
1091 << d_orthoMan->orthonormError( *
V_all ) << std::endl;
1095 "Anasazi::GeneralizedDavidson::ExpandSearchSpace(): Orthonormalization of new vectors failed" );
1102template <
class ScalarType,
class MV,
class OP>
1103void GeneralizedDavidson<ScalarType,MV,OP>::applyOperators()
1106 std::vector<int>
newIndices(d_expansionSize);
1107 for(
int i=0;
i<d_expansionSize; ++
i )
1116 d_opApplies += MVT::GetNumberVecs( *
V_new );
1129template <
class ScalarType,
class MV,
class OP>
1130void GeneralizedDavidson<ScalarType,MV,OP>::updateProjections()
1133 std::vector<int>
newIndices(d_expansionSize);
1134 for(
int i=0;
i<d_expansionSize; ++
i )
1138 for(
int i=0;
i<d_curDim; ++
i )
1141 std::vector<int>
allIndices(d_curDim+d_expansionSize);
1142 for(
int i=0;
i<d_curDim+d_expansionSize; ++
i )
1147 if( d_testSpace ==
"V" )
1152 else if( d_testSpace ==
"AV" )
1157 else if( d_testSpace ==
"BV" )
1168 Teuchos::SerialDenseMatrix<int,ScalarType>
VAV_lastrow( Teuchos::View, *d_VAV, d_expansionSize, d_curDim, d_curDim, 0 );
1172 Teuchos::SerialDenseMatrix<int,ScalarType>
VAV_lastcol( Teuchos::View, *d_VAV, d_curDim+d_expansionSize, d_expansionSize, 0, d_curDim );
1182 Teuchos::SerialDenseMatrix<int,ScalarType>
VBV_lastrow( Teuchos::View, *d_VBV, d_expansionSize, d_curDim, d_curDim, 0 );
1186 Teuchos::SerialDenseMatrix<int,ScalarType>
VBV_lastcol( Teuchos::View, *d_VBV, d_curDim+d_expansionSize, d_expansionSize, 0, d_curDim );
1191 d_curDim += d_expansionSize;
1193 d_ritzIndexValid =
false;
1194 d_ritzVectorsValid =
false;
1200template <
class ScalarType,
class MV,
class OP>
1201void GeneralizedDavidson<ScalarType,MV,OP>::solveProjectedEigenproblem()
1208 d_S->assign(*d_VAV);
1209 d_T->assign(*d_VBV);
1217 Teuchos::LAPACK<int,ScalarType>
lapack;
1221 std::vector<ScalarType>
work(1);
1223 d_T->values(), d_T->stride(), &
sdim, &d_alphar[0], &d_alphai[0], &d_betar[0],
1224 d_Q->values(), d_Q->stride(), d_Z->values(), d_Z->stride(), &
work[0],
work_size, 0, &
info );
1229 d_T->values(), d_T->stride(), &
sdim, &d_alphar[0], &d_alphai[0], &d_betar[0],
1230 d_Q->values(), d_Q->stride(), d_Z->values(), d_Z->stride(), &
work[0],
work_size, 0, &
info );
1232 d_ritzIndexValid =
false;
1233 d_ritzVectorsValid =
false;
1235 std::stringstream
ss;
1236 ss <<
"Anasazi::GeneralizedDavidson: GGES returned error code " <<
info << std::endl;
1243 d_S->assign(*d_VAV);
1252 Teuchos::LAPACK<int,ScalarType>
lapack;
1253 lapack.GEES(
vecs, d_curDim, d_S->values(), d_S->stride(), &
sdim, &d_alphar[0], &d_alphai[0],
1256 std::fill( d_betar.begin(), d_betar.end(), ST::one() );
1258 d_ritzIndexValid =
false;
1259 d_ritzVectorsValid =
false;
1261 std::stringstream
ss;
1262 ss <<
"Anasazi::GeneralizedDavidson: GEES returned error code " <<
info << std::endl;
1275template <
class ScalarType,
class MV,
class OP>
1276void GeneralizedDavidson<ScalarType,MV,OP>::computeRitzIndex()
1278 if( d_ritzIndexValid )
1281 d_ritzIndex.resize( d_curDim );
1283 while(
i < d_curDim )
1285 if( d_alphai[
i] == ST::zero() )
1293 d_ritzIndex[
i+1] = -1;
1297 d_ritzIndexValid =
true;
1308template <
class ScalarType,
class MV,
class OP>
1309void GeneralizedDavidson<ScalarType,MV,OP>::computeRitzVectors()
1311 if( d_ritzVectorsValid )
1319 for(
int ii=0;
ii<d_residualSize; ++
ii )
1323 Teuchos::SerialDenseMatrix<int,ScalarType> X(Teuchos::Copy,*d_Z,d_curDim,d_curDim);
1324 computeProjectedEigenvectors( X );
1327 Teuchos::SerialDenseMatrix<int,ScalarType>
X_wanted(Teuchos::View,X,d_curDim,d_residualSize);
1330 d_ritzVecs = MVT::CloneViewNonConst( *d_ritzVecSpace,
checkedIndices );
1333 for(
int i=0;
i<d_curDim; ++
i )
1342 std::vector<MagnitudeType>
scale(d_residualSize);
1343 MVT::MvNorm( *d_ritzVecs,
scale );
1344 Teuchos::LAPACK<int,ScalarType>
lapack;
1345 for(
int i=0;
i<d_residualSize; ++
i )
1347 if( d_ritzIndex[
i] == 0 )
1351 else if( d_ritzIndex[
i] == 1 )
1358 MVT::MvScale( *d_ritzVecs,
scale );
1360 d_ritzVectorsValid =
true;
1367template <
class ScalarType,
class MV,
class OP>
1368void GeneralizedDavidson<ScalarType,MV,OP>::sortValues( std::vector<MagnitudeType> &realParts,
1369 std::vector<MagnitudeType> &imagParts,
1370 std::vector<int> &permVec,
1376 "Anasazi::GeneralizedDavidson::SortValues: Number of requested sorted values greater than vector length." );
1378 "Anasazi::GeneralizedDavidson::SortValues: Number of requested sorted values greater than vector length." );
1384 d_ritzIndexValid =
false;
1385 d_ritzVectorsValid =
false;
1399template <
class ScalarType,
class MV,
class OP>
1400void GeneralizedDavidson<ScalarType,MV,OP>::computeProjectedEigenvectors(
1401 Teuchos::SerialDenseMatrix<int,ScalarType> &X )
1403 int N = X.numRows();
1406 Teuchos::SerialDenseMatrix<int,ScalarType> S(Teuchos::Copy, *d_S,
N,
N);
1407 Teuchos::SerialDenseMatrix<int,ScalarType> T(Teuchos::Copy, *d_T,
N,
N);
1408 Teuchos::SerialDenseMatrix<int,ScalarType>
VL(Teuchos::Copy, *d_Q,
N,
N);
1410 char whichVecs =
'R';
1417 Teuchos::LAPACK<int,ScalarType>
lapack;
1418 lapack.TGEVC( whichVecs, howMany, 0,
N, S.values(), S.stride(), T.values(), T.stride(),
1419 VL.values(),
VL.stride(), X.values(), X.stride(),
N, &
M, &
work[0], &
info );
1421 std::stringstream
ss;
1422 ss <<
"Anasazi::GeneralizedDavidson: TGEVC returned error code " <<
info << std::endl;
1427 Teuchos::SerialDenseMatrix<int,ScalarType> S(Teuchos::Copy, *d_S,
N,
N);
1428 Teuchos::SerialDenseMatrix<int,ScalarType>
VL(Teuchos::Copy, *d_Z,
N,
N);
1430 char whichVecs =
'R';
1433 std::vector<ScalarType>
work(3*
N);
1437 Teuchos::LAPACK<int,ScalarType>
lapack;
1439 lapack.TREVC( whichVecs, howMany, &
sel,
N, S.values(), S.stride(),
VL.values(),
VL.stride(),
1440 X.values(), X.stride(),
N, &
m, &
work[0], &
info );
1442 std::stringstream
ss;
1443 ss <<
"Anasazi::GeneralizedDavidson: TREVC returned error code " <<
info << std::endl;
1451template <
class ScalarType,
class MV,
class OP>
1452void GeneralizedDavidson<ScalarType,MV,OP>::scaleEigenvectors(
1453 const Teuchos::SerialDenseMatrix<int,ScalarType> &X,
1454 Teuchos::SerialDenseMatrix<int,ScalarType> &X_alpha,
1455 Teuchos::SerialDenseMatrix<int,ScalarType> &X_beta )
1457 int Nr = X.numRows();
1458 int Nc = X.numCols();
1461 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: Matrix size exceeds current dimension");
1463 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: Matrix size exceeds current dimension");
1465 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: number of rows in Xalpha does not match X");
1467 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: number of cols in Xalpha does not match X");
1469 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: number of rows in Xbeta does not match X");
1471 "Anasazi::GeneralizedDavidson::ScaleEigenvectors: number of cols in Xbeta does not match X");
1475 Teuchos::SerialDenseMatrix<int,ScalarType>
Alpha(
Nc,
Nc,
true);
1476 Teuchos::SerialDenseMatrix<int,ScalarType>
Beta(
Nc,
Nc,
true);
1480 for(
int i=0;
i<
Nc; ++
i )
1482 if( d_ritzIndex[
i] == 0 )
1487 else if( d_ritzIndex[
i] == 1 )
1504 err =
X_alpha.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, ST::one(), X,
Alpha, ST::zero() );
1506 astream <<
"GeneralizedDavidson::ScaleEigenvectors: multiply returned error code " <<
err;
1510 err =
X_beta.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, ST::one(), X,
Beta, ST::zero() );
1512 bstream <<
"GeneralizedDavidson::ScaleEigenvectors: multiply returned error code " <<
err;
1519template <
class ScalarType,
class MV,
class OP>
1520void GeneralizedDavidson<ScalarType,MV,OP>::computeResidual()
1525 d_residualSize = std::max( d_blockSize, d_NEV );
1526 if( d_curDim < d_residualSize )
1528 d_residualSize = d_curDim;
1530 else if( d_ritzIndex[d_residualSize-1] == 1 )
1537 for(
int i=0;
i<d_residualSize; ++
i )
1541 Teuchos::SerialDenseMatrix<int,ScalarType> X(Teuchos::Copy,*d_Z,d_curDim,d_curDim);
1544 computeProjectedEigenvectors( X );
1547 Teuchos::SerialDenseMatrix<int,ScalarType>
X_alpha(d_curDim,d_residualSize);
1548 Teuchos::SerialDenseMatrix<int,ScalarType>
X_beta(d_curDim,d_residualSize);
1551 Teuchos::SerialDenseMatrix<int,ScalarType>
X_wanted(Teuchos::View, X, d_curDim, d_residualSize);
1561 for(
int i=0;
i<d_curDim; ++
i )
1591 Teuchos::LAPACK<int,ScalarType>
lapack;
1592 Teuchos::BLAS<int,ScalarType>
blas;
1593 std::vector<MagnitudeType>
resScaling(d_residualSize);
1596 if( d_ritzIndex[
icol] == 0 )
1599 MagnitudeType
ABscaling = d_relativeConvergence ? d_alphar[
icol] : d_betar[
icol];
1602 else if( d_ritzIndex[
icol] == 1 )
1616 d_resNorms.resize(d_residualSize);
1624 for(
int i=0;
i<d_residualSize; ++
i )
1626 if( d_ritzIndex[
i] == 1 )
1628 MagnitudeType
nrm =
lapack.LAPY2(d_resNorms[
i],d_resNorms[
i+1]);
1629 d_resNorms[
i] =
nrm;
1630 d_resNorms[
i+1] =
nrm;
1635 d_tester->checkStatus(
this);
1638 if( d_useLeading || d_blockSize >= d_NEV )
1640 d_expansionSize=d_blockSize;
1641 if( d_ritzIndex[d_blockSize-1]==1 )
1644 d_expansionIndices.resize(d_expansionSize);
1645 for(
int i=0;
i<d_expansionSize; ++
i )
1646 d_expansionIndices[
i] =
i;
1663 if(
endVec > (d_residualSize-1) )
1665 endVec = d_residualSize-1;
1666 startVec = d_residualSize-d_blockSize;
1676 if( d_ritzIndex[
endVec]==1 )
1680 d_expansionIndices.resize(d_expansionSize);
1681 for(
int i=0;
i<d_expansionSize; ++
i )
1689template <
class ScalarType,
class MV,
class OP>
1694 myout.setf(std::ios::scientific, std::ios::floatfield);
1697 myout <<
"================================================================================" <<
endl;
1699 myout <<
" GeneralizedDavidson Solver Solver Status" <<
endl;
1701 myout <<
"The solver is "<<(d_initialized ?
"initialized." :
"not initialized.") <<
endl;
1702 myout <<
"The number of iterations performed is " << d_iteration <<
endl;
1703 myout <<
"The number of operator applies performed is " << d_opApplies <<
endl;
1704 myout <<
"The block size is " << d_expansionSize <<
endl;
1705 myout <<
"The current basis size is " << d_curDim <<
endl;
1706 myout <<
"The number of requested eigenvalues is " << d_NEV <<
endl;
1707 myout <<
"The number of converged values is " << d_tester->howMany() <<
endl;
1710 myout.setf(std::ios_base::right, std::ios_base::adjustfield);
1716 myout << std::setw(24) <<
"Ritz Value"
1717 << std::setw(30) <<
"Residual Norm" <<
endl;
1718 myout <<
"--------------------------------------------------------------------------------" <<
endl;
1719 if( d_residualSize > 0 )
1722 std::vector< Value<ScalarType> >
ritzVals = getRitzValues();
1723 for(
int i=0;
i<d_curDim; ++
i )
1731 int numToPrint = std::max( d_numToPrint, d_NEV );
1748 myout <<
" + i" << std::setw(15) << ST::magnitude(
imagRitz[
i] );
1749 if(
i < d_residualSize )
1760 myout <<
" + i" << std::setw(15) << ST::magnitude(
imagRitz[
i] );
1761 if(
i < d_residualSize )
1768 myout <<
" - i" << std::setw(15) << ST::magnitude(
imagRitz[
i] );
1769 if(
i < d_residualSize )
1780 myout << std::setw(20) <<
"[ NONE COMPUTED ]" <<
endl;
1784 myout <<
"================================================================================" <<
endl;
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Abstract base class which defines the interface required by an eigensolver and status test class to c...
Pure virtual base class which describes the basic interface to the iterative eigensolver.
Templated virtual class for providing orthogonalization/orthonormalization methods.
Abstract class definition for Anasazi Output Managers.
Virtual base class which defines the interface between an eigensolver and a class whose job is the so...
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...
Solves eigenvalue problem using generalized Davidson method.
void sortProblem(int numWanted)
int getCurSubspaceDim() const
Get current subspace dimension.
RCP< StatusTest< ScalarType, MV, OP > > getStatusTest() const
Get status test.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Get eigenproblem.
void setStatusTest(RCP< StatusTest< ScalarType, MV, OP > > tester)
Set status test.
void currentStatus(std::ostream &myout)
Print current status of solver.
int getMaxSubspaceDim() const
Get maximum subspace dimension.
std::vector< MagnitudeType > getResNorms()
Get the current residual norms (w.r.t. norm defined by OrthoManager)
std::vector< int > getBlockIndex() const
Get indices of current block.
std::vector< int > getRitzIndex()
Get the current Ritz index vector.
GeneralizedDavidson(const RCP< Eigenproblem< ScalarType, MV, OP > > &problem, const RCP< SortManager< MagnitudeType > > &sortman, const RCP< OutputManager< ScalarType > > &outputman, const RCP< StatusTest< ScalarType, MV, OP > > &tester, const RCP< OrthoManager< ScalarType, MV > > &orthoman, Teuchos::ParameterList &pl)
Constructor.
void initialize()
Initialize the eigenvalue problem.
GeneralizedDavidsonState< ScalarType, MV > getState()
Get the current state of the eigensolver.
bool isInitialized() const
Query if the solver is in an initialized state.
void setAuxVecs(const Teuchos::Array< RCP< const MV > > &auxVecs)
Set auxilliary vectors.
std::vector< Value< ScalarType > > getRitzValues()
Get the current Ritz values.
int getNumIters() const
Get number of iterations.
std::vector< MagnitudeType > getRes2Norms()
Get the current residual norms (2-norm)
void resetNumIters()
Reset the number of iterations.
RCP< const MV > getRitzVectors()
Get the current Ritz vectors.
int getBlockSize() const
Get block size.
Teuchos::Array< RCP< const MV > > getAuxVecs() const
Get the auxilliary vectors.
void iterate()
Solves the eigenvalue problem.
std::vector< MagnitudeType > getRitzRes2Norms()
Get the current Ritz residual norms (2-norm)
void setSize(int blockSize, int maxSubDim)
Set problem size.
void setBlockSize(int blockSize)
Set block size.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Operator()
Default constructor.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
Structure to contain pointers to GeneralizedDavidson state variables.
RCP< MV > AV
Image of V under A.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > T
Right quasi upper triangular matrix from QZ decomposition of (VAV,VBV)
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > VAV
Projection of A onto V.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Q
Left generalized Schur vectors from QZ decomposition of (VAV,VBV)
int curDim
The current subspace dimension.
std::vector< Value< ScalarType > > eVals
Vector of generalized eigenvalues.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > VBV
Projection of B onto V.
RCP< MV > BV
Image of V under B.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Z
Right generalized Schur vectors from QZ decomposition of (VAV,VBV)
RCP< MV > V
Orthonormal basis for search subspace.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > S
Left quasi upper triangular matrix from QZ decomposition of (VAV,VBV)