4 #include"Teuchos_LAPACK.hpp"
6 #ifndef __INNER_PRODUCT_MATRIX__
7 #define __INNER_PRODUCT_MATRIX__
14 const std::vector<Real> &
V,
15 const std::vector<Real> &w,
19 const std::vector<Real> &V,
20 const std::vector<Real> &w,
21 const std::vector<Real> &a);
25 void update(
const std::vector<Real> &a);
29 void apply(ROL::Ptr<
const std::vector<Real> > xp,
30 ROL::Ptr<std::vector<Real> > bp);
32 void applyadd(ROL::Ptr<
const std::vector<Real> > xp,
33 ROL::Ptr<std::vector<Real> > bp);
36 ROL::Ptr<std::vector<Real> > bp, Real factor);
39 Real
inner(ROL::Ptr<
const std::vector<Real> > up,
40 ROL::Ptr<
const std::vector<Real> > vp);
43 virtual void solve(ROL::Ptr<
const std::vector<Real> > bp,
44 ROL::Ptr<std::vector<Real> > xp){};
47 virtual Real
inv_inner(ROL::Ptr<
const std::vector<Real> > up,
48 ROL::Ptr<
const std::vector<Real> > vp){
54 const std::vector<Real>
U_;
55 const std::vector<Real>
V_;
56 const std::vector<Real>
w_;
67 const std::vector<Real> &
V,
68 const std::vector<Real> &w,
70 nq_(w.size()), ni_(U.size()/nq_),
71 U_(U),V_(V),w_(w),M_(ni_*ni_,0) {
72 for(
int i=0;i<
ni_;++i) {
73 for(
int j=0;j<
ni_;++j) {
74 for(
int k=0;k<
nq_;++k) {
83 const std::vector<Real> &
V,
84 const std::vector<Real> &w,
85 const std::vector<Real> &a ) :
86 nq_(w.size()), ni_(U.size()/nq_),
87 U_(U),V_(V),w_(w),M_(ni_*ni_,0) {
88 for(
int i=0;i<
ni_;++i) {
89 for(
int j=0;j<
ni_;++j) {
90 for(
int k=0;k<
nq_;++k) {
103 ROL::Ptr<std::vector<Real> > bp ) {
104 for(
int i=0;i<ni_;++i) {
106 for(
int j=0;j<ni_;++j ) {
107 (*bp)[i] += M_[i+ni_*j]*(*xp)[j];
114 ROL::Ptr<std::vector<Real> > bp ) {
115 for(
int i=0;i<ni_;++i) {
116 for(
int j=0;j<ni_;++j ) {
117 (*bp)[i] += M_[i+ni_*j]*(*xp)[j];
124 ROL::Ptr<std::vector<Real> > bp, Real factor ) {
125 for(
int i=0;i<ni_;++i) {
126 for(
int j=0;j<ni_;++j ) {
127 (*bp)[i] += factor*M_[i+ni_*j]*(*xp)[j];
135 std::fill(M_.begin(),M_.end(),0);
136 for(
int i=0;i<ni_;++i) {
137 for(
int j=0;j<ni_;++j) {
138 for(
int k=0;k<nq_;++k) {
139 M_[i+j*ni_] += a[k]*w_[k]*U_[k+i*nq_]*V_[k+j*nq_];
152 ROL::Ptr<
const std::vector<Real> > vp ) {
154 ROL::Ptr<std::vector<Real> > Mvp = ROL::makePtr<std::vector<Real>>(ni_,0);
156 for(
int i=0;i<ni_;++i) {
157 J += (*up)[i]*(*Mvp)[i];
174 std::vector<Real>
M_;
184 const std::vector<Real> &U=std::vector<Real>(),
185 const std::vector<Real> &
V=std::vector<Real>(),
186 const std::vector<Real> &w=std::vector<Real>(),
190 const std::vector<Real> &U=std::vector<Real>(),
191 const std::vector<Real> &
V=std::vector<Real>(),
192 const std::vector<Real> &w=std::vector<Real>(),
193 const std::vector<Real> &a=std::vector<Real>());
195 void solve(ROL::Ptr<
const std::vector<Real> > bp,
196 ROL::Ptr<std::vector<Real> > xp);
198 Real
inv_inner(ROL::Ptr<
const std::vector<Real> > up,
199 ROL::Ptr<
const std::vector<Real> > vp);
205 const std::vector<Real> &U,
206 const std::vector<Real> &
V,
207 const std::vector<Real> &w,
214 TRANS_(
'N'), ipiv_(ni_,0), PLU_(ni_*ni_,0),
225 const std::vector<Real> &U,
226 const std::vector<Real> &
V,
227 const std::vector<Real> &w,
228 const std::vector<Real> &a):
234 TRANS_(
'N'), ipiv_(ni_,0), PLU_(ni_*ni_,0),
246 ROL::Ptr<std::vector<Real> > xp){
248 int nrhs = bp->size()/ni_;
253 lapack_->GETRS(TRANS_,ni_,nrhs,&PLU_[0],ni_,&ipiv_[0],&(*xp)[0],ni_,&info_);
260 ROL::Ptr<
const std::vector<Real> > vp ) {
262 ROL::Ptr<std::vector<Real> > Mivp = ROL::makePtr<std::vector<Real>>(ni_,0);
263 this->
solve(vp,Mivp);
264 for(
int i=0;i<ni_;++i) {
266 J += (*up)[i]*(*Mivp)[i];
ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack_
virtual Real inv_inner(ROL::Ptr< const std::vector< Real > > up, ROL::Ptr< const std::vector< Real > > vp)
void solve(ROL::Ptr< const std::vector< Real > > bp, ROL::Ptr< std::vector< Real > > xp)
solve for
const std::vector< Real > U_
Real inner(ROL::Ptr< const std::vector< Real > > up, ROL::Ptr< const std::vector< Real > > vp)
Compute the inner product .
InnerProductMatrixSolver(ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack, const std::vector< Real > &U=std::vector< Real >(), const std::vector< Real > &V=std::vector< Real >(), const std::vector< Real > &w=std::vector< Real >(), const int a=1)
Defines the linear algebra or vector space interface.
void apply(ROL::Ptr< const std::vector< Real > > xp, ROL::Ptr< std::vector< Real > > bp)
const std::vector< Real > w_
void applyadd(ROL::Ptr< const std::vector< Real > > xp, ROL::Ptr< std::vector< Real > > bp)
InnerProductMatrix(const std::vector< Real > &U, const std::vector< Real > &V, const std::vector< Real > &w, const int a=1)
Real inv_inner(ROL::Ptr< const std::vector< Real > > up, ROL::Ptr< const std::vector< Real > > vp)
Compute the inner product .
const std::vector< Real > V_
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
This class adds a solve method.
void applyaddtimes(ROL::Ptr< const std::vector< Real > > xp, ROL::Ptr< std::vector< Real > > bp, Real factor)
virtual ~InnerProductMatrix()
ROL::DiagonalOperator apply
void update(const std::vector< Real > &a)
virtual void solve(ROL::Ptr< const std::vector< Real > > bp, ROL::Ptr< std::vector< Real > > xp)