3 #include "Epetra_BLAS.h"
4 #include "Epetra_Export.h"
5 #include "Epetra_Import.h"
6 #include "Epetra_Time.h"
8 #include "AnasaziEpetraAdapter.hpp"
9 #include "AnasaziSpecializedEpetraAdapter.hpp"
10 #include "AnasaziBasicEigenproblem.hpp"
11 #include "AnasaziBlockKrylovSchurSolMgr.hpp"
14 #include "Epetra_MpiComm.h"
16 #include "Epetra_SerialComm.h"
22 isInitialized_( false ),
37 if ( rbmethod_params.
get(
"Basis Size", 16) < ss->NumVectors() ) {
38 basis_size_ = rbmethod_params.
get(
"Basis Size", 16);
41 basis_size_ = ss->NumVectors();
44 isInner_ = ( rbmethod_params.
get(
"Anasazi POD Operator Form",
"Inner")==
"Inner"?
true : false );
47 if (rbmethod_params.
isParameter(
"POD Operator Weighting Matrix" )) {
48 std::string matFile = Teuchos::getParameter<std::string>( rbmethod_params,
"POD Operator Weighting Matrix" );
49 std::vector<std::string> filename(1,matFile);
50 op_ = fileio->Read( filename );
54 if (rbmethod_params.
isParameter(
"Inner Product Matrix" )) {
55 std::string matFile = Teuchos::getParameter<std::string>( rbmethod_params,
"Inner Product Matrix" );
56 std::vector<std::string> filename(1,matFile);
57 inner_prod_op_ = fileio->Read( filename );
61 sv_.resize( basis_size_ );
75 int MyPID = comm.
MyPID();
80 int num_vecs = ss_->NumVectors();
81 int vec_length = ss_->GlobalLength();
86 if (basis_size_ > num_vecs) {
88 basis_size_ = num_vecs;
93 int nev = basis_size_;
94 int maxBlocks = 3*basis_size_;
95 int maxRestarts = 300;
96 int verbosity = Anasazi::Warnings + Anasazi::Errors;
98 std::string which=
"LM";
104 if ( maxBlocks > num_vecs )
105 maxBlocks = num_vecs-1;
108 if ( maxBlocks > vec_length )
109 maxBlocks = vec_length-1;
115 MyPL.
set(
"Verbosity", verbosity );
116 MyPL.
set(
"Block Size", blockSize );
117 MyPL.
set(
"Num Blocks", maxBlocks );
118 MyPL.
set(
"Maximum Restarts", maxRestarts );
119 MyPL.
set(
"Which", which );
120 MyPL.
set(
"Step Size", step );
121 MyPL.
set(
"Convergence Tolerance", tol );
125 typedef Anasazi::MultiVec<double> MV;
126 typedef Anasazi::Operator<double> OP;
131 if (op_ != Teuchos::null) {
133 Amat =
Teuchos::rcp(
new Anasazi::EpetraWSymMVOp( ss_, op_ ) );
138 Amat =
Teuchos::rcp(
new Anasazi::EpetraSymMVOp( ss_, !isInner_ ) );
149 if (inner_prod_op_ != Teuchos::null)
150 ivec=
Teuchos::rcp(
new Anasazi::EpetraOpMultiVec( inner_prod_op_, localMap, blockSize ) );
152 ivec =
Teuchos::rcp(
new Anasazi::EpetraMultiVec( localMap, blockSize ) );
155 if (inner_prod_op_ != Teuchos::null)
156 ivec =
Teuchos::rcp(
new Anasazi::EpetraOpMultiVec( inner_prod_op_, ss_->Map(), blockSize ) );
158 ivec =
Teuchos::rcp(
new Anasazi::EpetraMultiVec( ss_->Map(), blockSize ) );
165 Teuchos::rcp(
new Anasazi::BasicEigenproblem<double,MV,OP>(Amat, ivec) );
168 MyProblem->setHermitian(
true );
171 MyProblem->setNEV( nev );
174 bool boolret = MyProblem->setProblem();
175 if (boolret !=
true) {
177 std::cout <<
"Anasazi::BasicEigenproblem::setProblem() returned with error." << std::endl;
182 Anasazi::BlockKrylovSchurSolMgr<double,MV,OP> MySolverMgr(MyProblem, MyPL);
187 Anasazi::ReturnType returnCode = MySolverMgr.solve();
188 if (returnCode != Anasazi::Converged && MyPID==0) {
189 std::cout <<
"Anasazi::EigensolverMgr::solve() returned unconverged." << std::endl;
195 Anasazi::Eigensolution<double,MV> sol = MyProblem->getSolution();
196 std::vector<Anasazi::Value<double> > evals = sol.Evals;
197 int numev = sol.numVecs;
199 if (numev < nev && MyPID==0) {
200 std::cout <<
"RBGen::AnasaziPOD will return " << numev <<
" singular vectors." << std::endl;
208 std::vector<int> index(numev);
209 for (i=0; i<numev; i++) { index[i] = i; }
211 Anasazi::MultiVecTraits<double,MV>::CloneView(*sol.Evecs, index) );
216 for (i=0; i<numev; i++) {
225 std::vector<double> tempnrm( numev );
231 info = AV.Multiply(
'N',
'N', 1.0, *ss_, *evecs, 0.0 );
232 AV.Norm2( &tempnrm[0] );
237 for( i=0; i<numev; i++ ) { S[i][i] = 1.0/tempnrm[i]; }
238 info = basis_->Multiply(
'N',
'N', 1.0, AV, S, 0.0 );
259 info = ATU.Multiply(
'T',
'N', 1.0, *ss_, *evecs, 0.0 );
260 ATU.Norm2( &tempnrm[0] );
265 for( i=0; i<numev; i++ ) { S[i][i] = 1.0/tempnrm[i]; }
266 info = V.Multiply(
'N',
'N', 1.0, ATU, S, 0.0 );
void Initialize(const Teuchos::RCP< Teuchos::ParameterList > ¶ms, const Teuchos::RCP< const Epetra_MultiVector > &ss, const Teuchos::RCP< RBGen::FileIOHandler< Epetra_Operator > > &fileio=Teuchos::null)
Initialize the method with the given parameter list and snapshot set.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
double ElapsedTime(void) const
AnasaziPOD()
Default constructor.
Provides POD method using Anasazi eigensolvers.
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void ResetStartTime(void)
void computeBasis()
Compute a basis for the provided snapshots.