1 #include "RBGen_IncSVDPOD.h"
2 #include "AnasaziSVQBOrthoManager.hpp"
3 #include "AnasaziBasicOrthoManager.hpp"
5 #include "Epetra_SerialDenseMatrix.h"
6 #include "Epetra_LAPACK.h"
7 #include "Epetra_LocalMap.h"
8 #include "Epetra_Comm.h"
13 isInitialized_(false),
14 filter_(Teuchos::null),
25 timerComp_(
"Total Elapsed Time"),
33 if (curRank_ == 0 || isInitialized_ ==
false) {
40 if (curRank_ == 0 || isInitialized_ ==
false) {
47 std::vector<double> ret(sigma_.begin(),sigma_.begin()+curRank_);
61 maxBasisSize_ = rbmethod_params.
get<
int>(
"Max Basis Size");
66 if (filter_ == Teuchos::null) {
67 int k = rbmethod_params.
get(
"Rank",(
int)5);
72 tol_ = rbmethod_params.
get<
double>(
"Convergence Tolerance",tol_);
75 debug_ = rbmethod_params.
get<
bool>(
"IncSVD Debug",debug_);
78 verbLevel_ = rbmethod_params.
get<
int>(
"IncSVD Verbosity Level",verbLevel_);
81 if (rbmethod_params.
isType<
82 Teuchos::RCP< Anasazi::OrthoManager<double,Epetra_MultiVector> >
86 ortho_ = rbmethod_params.
get<
89 TEUCHOS_TEST_FOR_EXCEPTION(ortho_ == Teuchos::null,std::invalid_argument,
"User specified null ortho manager.");
92 std::string omstr = rbmethod_params.
get(
"Ortho Manager",
"DGKS");
93 if (omstr ==
"SVQB") {
94 ortho_ =
rcp(
new Anasazi::SVQBOrthoManager<double,Epetra_MultiVector,Epetra_Operator>() );
97 ortho_ =
rcp(
new Anasazi::BasicOrthoManager<double,Epetra_MultiVector,Epetra_Operator>() );
102 lmin_ = rbmethod_params.
get(
"Min Update Size",1);
103 TEUCHOS_TEST_FOR_EXCEPTION(lmin_ < 1 || lmin_ >= maxBasisSize_,std::invalid_argument,
104 "Method requires 1 <= min update size < max basis size.");
105 lmax_ = rbmethod_params.
get(
"Max Update Size",maxBasisSize_);
106 TEUCHOS_TEST_FOR_EXCEPTION(lmin_ > lmax_,std::invalid_argument,
"Max update size must be >= min update size.");
108 startRank_ = rbmethod_params.
get(
"Start Rank",lmin_);
109 TEUCHOS_TEST_FOR_EXCEPTION(startRank_ < 1 || startRank_ > maxBasisSize_,std::invalid_argument,
110 "Starting rank must be in [1,maxBasisSize_)");
112 maxNumPasses_ = rbmethod_params.
get(
"Maximum Number Passes",maxNumPasses_);
113 TEUCHOS_TEST_FOR_EXCEPTION(maxNumPasses_ != -1 && maxNumPasses_ <= 0, std::invalid_argument,
114 "Maximum number passes must be -1 or > 0.");
116 TEUCHOS_TEST_FOR_EXCEPTION(ss == Teuchos::null,std::invalid_argument,
"Input snapshot matrix cannot be null.");
120 maxNumCols_ = A_->NumVectors();
121 maxNumCols_ = rbmethod_params.
get(
"Maximum Number Columns",maxNumCols_);
122 TEUCHOS_TEST_FOR_EXCEPTION(maxNumCols_ < A_->NumVectors(), std::invalid_argument,
123 "Maximum number of columns must be at least as many as in the initializing data set.");
130 sigma_.reserve( maxBasisSize_ );
143 resNorms_.reserve(maxBasisSize_);
150 isInitialized_ =
true;
158 isInitialized_ =
false;
170 "computeBasis() requires non-null snapshot set.");
174 "RBGen::IncSVDPOD::computeBasis(): Solver must be initialized.");
183 while (curNumPasses_ < maxNumPasses_ || maxNumPasses_ == -1) {
189 std::vector<double> resnorms = this->
getResNorms();
192 int numConverged = 0;
193 for (
int i=0; i<curRank_; i++) {
194 if (resnorms[i] <= tol_) {
198 if (comm->
MyPID() == 0 && verbLevel_ >= 1) {
199 std::cout <<
"| Num converged: " << numConverged << std::endl
200 <<
"| Resid norms: " << std::endl;
201 for (
int i=0; i<curRank_; i++) {
202 std::cout <<
"| " << resnorms[i] << std::endl;
205 if (numConverged == curRank_)
break;
210 void IncSVDPOD::incStep(
int lup) {
219 const int lwork = 5*curRank_;
222 std::vector<double> Shat(curRank_), work(lwork);
225 lapack.
GESVD(
'O',
'A',curRank_,curRank_,Uhat.A(),Uhat.LDA(),&Shat[0],Uhat.A(),Uhat.LDA(),Vhat.A(),Vhat.LDA(),&work[0],&lwork,&info);
229 std::vector<int> keepind = filter_->filter(Shat);
230 std::vector<int> truncind(curRank_-keepind.size());
232 std::vector<int> allind(curRank_);
233 for (
int i=0; i<curRank_; i++) {
236 set_difference(allind.begin(),allind.end(),keepind.begin(),keepind.end(),truncind.begin());
240 std::vector<double> Scopy(Shat);
241 for (
int j=0; j<curRank_; j++) {
242 for (
int i=0; i<curRank_; i++) {
243 Vcopy(i,j) = Vhat(j,i);
247 for (
unsigned int j=0; j<keepind.size(); j++) {
248 std::copy(&Ucopy(0,keepind[j]),&Ucopy(curRank_,keepind[j]),&Uhat(0,j));
249 std::copy(&Vcopy(0,keepind[j]),&Vcopy(curRank_,keepind[j]),&Vhat(0,j));
250 Shat[j] = Scopy[keepind[j]];
252 for (
unsigned int j=0; j<truncind.size(); j++) {
253 std::copy(&Ucopy(0,truncind[j]),&Ucopy(curRank_,truncind[j]),&Uhat(0,keepind.size()+j));
254 std::copy(&Vcopy(0,truncind[j]),&Vcopy(curRank_,truncind[j]),&Vhat(0,keepind.size()+j));
255 Shat[keepind.size()+j] = Scopy[truncind[j]];
261 this->shrink(truncind.size(),Shat,Uhat,Vhat);
265 if (comm->MyPID() == 0 && verbLevel_ >= 2) {
267 <<
"------------- IncSVDPOD::incStep() --------------" << std::endl
268 <<
"| Cols Processed: " << numProc_ << std::endl
269 <<
"| Current lup: " << lup << std::endl
270 <<
"| Current ldown: " << truncind.size() << std::endl
271 <<
"| Current rank: " << curRank_ << std::endl
272 <<
"| Current sigmas: " << std::endl;
273 for (
int i=0; i<curRank_; i++) {
274 std::cout <<
"| " << sigma_[i] << std::endl;
void Reset(const Teuchos::RCP< Epetra_MultiVector > &new_ss)
Reset the snapshot set used to compute the reduced basis.
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::vector< double > getSingularValues() const
Return the singular values.
void GESVD(const char JOBU, const char JOBVT, const int M, const int N, float *A, const int LDA, float *S, float *U, const int LDU, float *VT, const int LDVT, float *WORK, const int *LWORK, int *INFO) const
Teuchos::RCP< const Epetra_MultiVector > getRightBasis() const
Return a basis for the right singular subspace.
Teuchos::RCP< const Epetra_MultiVector > getBasis() const
Return a basis for the left singular subspace.
virtual int MyPID() const =0
void computeBasis()
Computes bases for the left and (optionally) right singular subspaces, along with singular vaues...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void Initialize(const Teuchos::RCP< Teuchos::ParameterList > ¶ms, const Teuchos::RCP< const Epetra_MultiVector > &init, const Teuchos::RCP< RBGen::FileIOHandler< Epetra_Operator > > &fileio=Teuchos::null)
Initialize the method with the given parameter list and snapshot set.
const std::vector< double > & getResNorms()
Return the scaled residual norms.
IncSVDPOD()
Default constructor.
bool isType(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")