RBGen  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RBGen_ISVDUDV.cpp
1 #include "RBGen_ISVDUDV.h"
2 
3 namespace RBGen {
4 
6 
7  void ISVDUDV::expand(const int lup)
8  {
9  //
10  // build B and perform gram-schmidt expansion
11  //
12  // k l
13  // B = [S C] k
14  // [ Z] l
15  //
18  U2 = Teuchos::rcp( new Epetra_MultiVector(View,*U_,curRank_,lup) );
19  int info = (*B_).Scale(0.0);
20  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,std::logic_error,
21  "RBGen::ISVDUDV::expand(): error calling Epetra_SerialDenseMatrix::scale()");
22  for (int i=0; i<curRank_; ++i) {
23  (*B_)(i,i) = sigma_[i];
24  }
25  // get pointer for C,B inside of B, as Teuchos::SerialDenseMatrix objects
28  if (curRank_ > 0) {
29  U1 = Teuchos::rcp( new Epetra_MultiVector(View,*U_,0,curRank_) );
30  C = Teuchos::rcp( new Epetra_SerialDenseMatrix(View, &((*B_)(0,curRank_)), B_->LDA(), curRank_, lup) );
31  Cteuchos = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,double>(Teuchos::View,C->A(),C->LDA(),curRank_,lup) );
32  }
33  Z = Teuchos::rcp( new Epetra_SerialDenseMatrix(View, &((*B_)(curRank_,curRank_)), B_->LDA(), lup, lup) );
34  Zteuchos = Teuchos::rcp( new Teuchos::SerialDenseMatrix<int,double>(Teuchos::View, Z->A(), Z->LDA(), lup, lup ) );
35  // perform Grams-Schmidt expansion
36  int newRank;
37  if (curRank_ > 0) {
38  newRank = ortho_->projectAndNormalize(*U2,Teuchos::tuple(U1),Teuchos::tuple(Cteuchos),Zteuchos);
39  }
40  else {
41  newRank = ortho_->normalize(*U2,Zteuchos);
42  }
43  TEUCHOS_TEST_FOR_EXCEPTION(newRank != lup,std::logic_error,
44  "RBGen::ISVDUDV::incStep(): Couldn't recover full rank basis.");
45  Cteuchos = Teuchos::null;
46  Zteuchos = Teuchos::null;
47  C = Teuchos::null;
48  Z = Teuchos::null;
49  U2 = Teuchos::null;
50  U1 = Teuchos::null;
51  // augment V with I:
52  // Vnew = [V 0]
53  // [0 I]
54  //
55  // Set V(0:numProc+lup-1,curRank:curRank+lup-1) = 0
56  //
57  // Vnew = [* 0]
58  // [* 0]
59  for (int j=curRank_; j<curRank_+lup; j++) {
60  for (int i=0; i<numProc_+lup; i++) {
61  (*V_)[j][i] = 0.0;
62  // V_->ReplaceGlobalValue(i,j,0.0);
63  }
64  }
65  //
66  // Set V(numProc:numProc+lup-1,0:curRank-1) = 0
67  //
68  // Vnew = [* *]
69  // [0 *]
70  for (int j=0; j<curRank_; j++) {
71  for (int i=numProc_; i<numProc_+lup; i++) {
72  (*V_)[j][i] = 0.0;
73  // V_->ReplaceGlobalValue(i,j,0.0);
74  }
75  }
76  //
77  // Set V(numProc:numProc+lup-1,curRank:curRank+lup-1) = I
78  //
79  // Vnew = [* * ]
80  // [* diag(I)]
81  for (int j=0; j<lup; j++) {
82  (*V_)[curRank_+j][numProc_+j] = 1.0;
83  // V_->ReplaceGlobalValue(numProc_+j,curRank_+j,1.0);
84  }
85 
86  numProc_ += lup;
87  curRank_ += lup;
88  }
89 
90 
91  void ISVDUDV::shrink(const int down, std::vector<double> &S, Epetra_SerialDenseMatrix &U, Epetra_SerialDenseMatrix &V)
92  {
93  //
94  // put RU1 into an Epetra MultiVector
95  Epetra_LocalMap LocalMap(curRank_, 0, U_->Map().Comm());
96  Epetra_MultiVector Uh1(::View, LocalMap, U.A(), U.LDA(), curRank_-down);
97  Epetra_MultiVector Vh1(::View, LocalMap, V.A(), V.LDA(), curRank_-down);
98 
99  //
100  // update bases
101  Teuchos::RCP<Epetra_MultiVector> newwU, fullU, newU, newwV, fullV, newV;
102  fullU = Teuchos::rcp( new Epetra_MultiVector(::View,*U_,0,curRank_) );
103  newwU = Teuchos::rcp( new Epetra_MultiVector(::View,*workU_,0,curRank_-down) );
104  // multiply by Uh1
105  int info = newwU->Multiply('N','N',1.0,*fullU,Uh1,0.0);
106  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,std::logic_error,"ISVDUDV::shrink(): Error calling EMV::Multiply(U).");
107  fullU = Teuchos::null;
108  newU = Teuchos::rcp( new Epetra_MultiVector(::View,*U_,0,curRank_-down) );
109  *newU = *newwU;
110  newU = Teuchos::null;
111  newwU = Teuchos::null;
112 
113  // multiply by Vh1
114  // get multivector views of V(1:numProc,1:curRank) and workV(1:numProc,1:curRank-down)
115  double *V_A, *workV_A;
116  int V_LDA, workV_LDA;
117  info = V_->ExtractView(&V_A,&V_LDA);
118  TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
119  "RBGen::ISVDUDV::shrink(): Error calling Epetra_MultiVector::ExtractView() on V_.");
120  info = workV_->ExtractView(&workV_A,&workV_LDA);
121  TEUCHOS_TEST_FOR_EXCEPTION(info != 0, std::logic_error,
122  "RBGen::ISVDUDV::shrink(): Error calling Epetra_MultiVector::ExtractView() on workV_.");
123  Epetra_LocalMap lclmap(numProc_,0,A_->Comm());
124  fullV = Teuchos::rcp( new Epetra_MultiVector(::View,lclmap, V_A, V_LDA,curRank_ ) );
125  newwV = Teuchos::rcp( new Epetra_MultiVector(::View,lclmap,workV_A,workV_LDA,curRank_-down) );
126  // multiply workV = fullV * Vh1
127  info = newwV->Multiply('N','N',1.0,*fullV,Vh1,0.0);
128  TEUCHOS_TEST_FOR_EXCEPTION(info != 0,std::logic_error,"ISVDUDV::shrink(): Error calling EMV::Multiply(V).");
129  fullV = Teuchos::null;
130  // now set newV = workV
131  newV = Teuchos::rcp( new Epetra_MultiVector(::View,lclmap, V_A, V_LDA, curRank_-down) );
132  *newV = *newwV;
133  newV = Teuchos::null;
134  newwV = Teuchos::null;
135 
136  // save new singular values
137  for (int i=0; i<curRank_-down; i++) {
138  sigma_[i] = S[i];
139  }
140 
141  curRank_ = curRank_-down;
142  }
143 
144 
148  {
149  workU_ = Teuchos::rcp( new Epetra_MultiVector(ss->Map(),maxBasisSize_,false) );
150  Epetra_LocalMap lclmap(ss->NumVectors(),0,ss->Comm());
151  workV_ = Teuchos::rcp( new Epetra_MultiVector(lclmap,maxBasisSize_,false) );
152  }
153 
154 } // end of RBGen namespace
155 
ISVDUDV()
Default constructor.
void Initialize(const Teuchos::RCP< Teuchos::ParameterList > &params, 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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
double * A() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)