1 #include "RBGen_ISVDMultiCD.h"
3 #include "Epetra_LAPACK.h"
4 #include "Epetra_BLAS.h"
5 #include "Epetra_Comm.h"
13 "RBGen::ISVDMultiCD::updateBasis(): this routine not supported.");
16 void ISVDMultiCD::makePass() {
20 bool firstPass = (curRank_ == 0);
21 const int numCols = A_->NumVectors();
23 "RBGen::ISVDMultiCD::makePass(): after first pass, numProc should be numCols");
41 int info, lwork = curRank_;
42 std::vector<double> tau(curRank_), work(lwork);
43 info = lclZ->ExtractView(&Z_A,&Z_LDA);
45 "RBGen::ISVDMultiCD::makePass(): error calling ExtractView on Epetra_MultiVector Z.");
46 lapack.
GEQRF(numCols,curRank_,Z_A,Z_LDA,&tau[0],&work[0],lwork,&info);
48 "RBGen::ISVDMultiCD::makePass(): error calling GEQRF on current right basis while constructing next pass coefficients.");
54 for (
int j=0; j<curRank_; j++) {
55 for (
int i=0; i<j; i++) {
56 Rerr += abs(Z_A[j*Z_LDA+i]);
58 Rerr += abs(abs(Z_A[j*Z_LDA+j]) - 1.0);
63 lapack.
LARFT(
'F',
'C',numCols,curRank_,Z_A,Z_LDA,&tau[0],workT_->
A(),workT_->
LDA());
76 for (
int j=0; j<curRank_; j++) {
78 for (
int i=0; i<j; i++) {
85 info = lclAZT->Multiply(
'N',
'N',1.0,*A_,*lclZ,0.0);
87 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for A*Z");
89 info = lclAZT->ExtractView(&AZT_A,&AZT_LDA);
91 "RBGen::ISVDMultiCD::makePass(): error calling ExtractView on Epetra_MultiVector AZ.");
92 blas.
TRMM(
'R',
'U',
'N',
'N',numCols,curRank_,1.0,workT_->
A(),workT_->
LDA(),AZT_A,AZT_LDA);
104 while (numProc_ < numCols) {
123 lup = (lup < lmin_ ? lmin_ : lup);
124 lup = (lup > lmax_ ? lmax_ : lup);
131 lup = (lup > numCols - numProc_ ? numCols - numProc_ : lup);
133 lup = (lup > maxBasisSize_ - curRank_ ? maxBasisSize_ - curRank_ : lup);
150 int info = Unew.Multiply(
'N',
'T',-1.0,*lclAZT,Zi,1.0);
152 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for A*Wi");
175 info = TZTV.Multiply(
'T',
'N',1.0,*lclZ,*lclV,0.0);
177 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for Z^T V.");
179 info = TZTV.ExtractView(&TZTV_A,&TZTV_LDA);
181 "RBGen::ISVDMultiCD::makePass(): error calling ExtractView on Epetra_MultiVector TZTV.");
183 blas.
TRMM(
'L',
'U',
'N',
'N',oldRank,curRank_,1.0,workT_->
A(),workT_->
LDA(),TZTV_A,TZTV_LDA);
185 info = lclV->Multiply(
'N',
'N',-1.0,*lclZ,TZTV,1.0);
187 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for W V.");
208 int info = ATUlcl.Multiply(
'T',
'N',1.0,*A_,Ulcl,0.0);
210 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply for A^T U.");
213 for (
int i=0; i<curRank_; i++) {
217 info = ATUlcl.Multiply(
'N',
'N',-1.0,Vlcl,S,1.0);
219 "RBGen::ISVDMultiCD::computeBasis(): Error calling Epetra_MultiVector::Multiply for V S.");
220 resNorms_.resize(curRank_);
221 ATUlcl.Norm2(&resNorms_[0]);
223 for (
int i=0; i<curRank_; i++) {
224 if (sigma_[i] != 0.0) {
225 resNorms_[i] /= sigma_[i];
231 std::vector<double> errnorms(curRank_);
237 curU(::View,*U_,0,curRank_),
238 curV(::View,*V_,0,curRank_);
242 for (
int i=0; i<curRank_; i++) {
243 curS[i][i] = sigma_[i];
245 info = work.Multiply(
'N',
'N',1.0,curU,curS,0.0);
247 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for debugging U S.");
248 info = work.Multiply(
'N',
'N',-1.0,*A_,curV,1.0);
250 "RBGen::ISVDMultiCD::makePass(): Error calling Epetra_MultiVector::Multiply() for debugging U S - A V.");
251 work.Norm2(&errnorms[0]);
252 for (
int i=0; i<curRank_; i++) {
253 if (sigma_[i] != 0.0) {
254 errnorms[i] /= sigma_[i];
264 if (comm->
MyPID() == 0 && verbLevel_ >= 1) {
266 <<
"------------- ISVDMultiCD::makePass() -----------" << std::endl
267 <<
"| Number of passes: " << curNumPasses_ << std::endl
268 <<
"| Current rank: " << curRank_ << std::endl
269 <<
"| Current sigmas: " << std::endl;
270 for (
int i=0; i<curRank_; i++) {
271 std::cout <<
"| " << sigma_[i] << std::endl;
274 std::cout <<
"|DBG US-AV norms: " << std::endl;
275 for (
int i=0; i<curRank_; i++) {
276 std::cout <<
"|DBG " << errnorms[i] << std::endl;
279 std::cout <<
"|DBG R-I norm: " << Rerr << std::endl;
void TRMM(const char SIDE, const char UPLO, const char TRANSA, const char DIAG, const int M, const int N, const float ALPHA, const float *A, const int LDA, float *B, const int LDB) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void GEQRF(const int M, const int N, float *A, const int LDA, float *TAU, float *WORK, const int lwork, int *INFO) const
virtual int MyPID() const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void updateBasis(const Teuchos::RCP< Epetra_MultiVector > &update_ss)
Update the current basis by appending new snapshots.
ISVDMultiCD()
Default constructor.
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.
void LARFT(const char DIRECT, const char STOREV, const int N, const int K, double *V, const int LDV, double *TAU, double *T, const int LDT) const