13 #include"Teuchos_LAPACK.hpp"
15 #ifndef __INNER_PRODUCT_MATRIX__
16 #define __INNER_PRODUCT_MATRIX__
23 const std::vector<Real> &
V,
24 const std::vector<Real> &w,
28 const std::vector<Real> &V,
29 const std::vector<Real> &w,
30 const std::vector<Real> &a);
34 void update(
const std::vector<Real> &a);
38 void apply(ROL::Ptr<
const std::vector<Real> > xp,
39 ROL::Ptr<std::vector<Real> > bp);
41 void applyadd(ROL::Ptr<
const std::vector<Real> > xp,
42 ROL::Ptr<std::vector<Real> > bp);
45 ROL::Ptr<std::vector<Real> > bp, Real factor);
48 Real
inner(ROL::Ptr<
const std::vector<Real> > up,
49 ROL::Ptr<
const std::vector<Real> > vp);
52 virtual void solve(ROL::Ptr<
const std::vector<Real> > bp,
53 ROL::Ptr<std::vector<Real> > xp){};
56 virtual Real
inv_inner(ROL::Ptr<
const std::vector<Real> > up,
57 ROL::Ptr<
const std::vector<Real> > vp){
63 const std::vector<Real>
U_;
64 const std::vector<Real>
V_;
65 const std::vector<Real>
w_;
76 const std::vector<Real> &
V,
77 const std::vector<Real> &w,
79 nq_(w.size()), ni_(U.size()/nq_),
80 U_(U),V_(V),w_(w),M_(ni_*ni_,0) {
81 for(
int i=0;i<
ni_;++i) {
82 for(
int j=0;j<
ni_;++j) {
83 for(
int k=0;k<
nq_;++k) {
92 const std::vector<Real> &
V,
93 const std::vector<Real> &w,
94 const std::vector<Real> &a ) :
95 nq_(w.size()), ni_(U.size()/nq_),
96 U_(U),V_(V),w_(w),M_(ni_*ni_,0) {
97 for(
int i=0;i<
ni_;++i) {
98 for(
int j=0;j<
ni_;++j) {
99 for(
int k=0;k<
nq_;++k) {
112 ROL::Ptr<std::vector<Real> > bp ) {
113 for(
int i=0;i<ni_;++i) {
115 for(
int j=0;j<ni_;++j ) {
116 (*bp)[i] += M_[i+ni_*j]*(*xp)[j];
123 ROL::Ptr<std::vector<Real> > bp ) {
124 for(
int i=0;i<ni_;++i) {
125 for(
int j=0;j<ni_;++j ) {
126 (*bp)[i] += M_[i+ni_*j]*(*xp)[j];
133 ROL::Ptr<std::vector<Real> > bp, Real factor ) {
134 for(
int i=0;i<ni_;++i) {
135 for(
int j=0;j<ni_;++j ) {
136 (*bp)[i] += factor*M_[i+ni_*j]*(*xp)[j];
144 std::fill(M_.begin(),M_.end(),0);
145 for(
int i=0;i<ni_;++i) {
146 for(
int j=0;j<ni_;++j) {
147 for(
int k=0;k<nq_;++k) {
148 M_[i+j*ni_] += a[k]*w_[k]*U_[k+i*nq_]*V_[k+j*nq_];
161 ROL::Ptr<
const std::vector<Real> > vp ) {
163 ROL::Ptr<std::vector<Real> > Mvp = ROL::makePtr<std::vector<Real>>(ni_,0);
165 for(
int i=0;i<ni_;++i) {
166 J += (*up)[i]*(*Mvp)[i];
183 std::vector<Real>
M_;
193 const std::vector<Real> &U=std::vector<Real>(),
194 const std::vector<Real> &
V=std::vector<Real>(),
195 const std::vector<Real> &w=std::vector<Real>(),
199 const std::vector<Real> &U=std::vector<Real>(),
200 const std::vector<Real> &
V=std::vector<Real>(),
201 const std::vector<Real> &w=std::vector<Real>(),
202 const std::vector<Real> &a=std::vector<Real>());
204 void solve(ROL::Ptr<
const std::vector<Real> > bp,
205 ROL::Ptr<std::vector<Real> > xp);
207 Real
inv_inner(ROL::Ptr<
const std::vector<Real> > up,
208 ROL::Ptr<
const std::vector<Real> > vp);
214 const std::vector<Real> &U,
215 const std::vector<Real> &
V,
216 const std::vector<Real> &w,
223 TRANS_(
'N'), ipiv_(ni_,0), PLU_(ni_*ni_,0),
234 const std::vector<Real> &U,
235 const std::vector<Real> &
V,
236 const std::vector<Real> &w,
237 const std::vector<Real> &a):
243 TRANS_(
'N'), ipiv_(ni_,0), PLU_(ni_*ni_,0),
255 ROL::Ptr<std::vector<Real> > xp){
257 int nrhs = bp->size()/ni_;
262 lapack_->GETRS(TRANS_,ni_,nrhs,&PLU_[0],ni_,&ipiv_[0],&(*xp)[0],ni_,&info_);
269 ROL::Ptr<
const std::vector<Real> > vp ) {
271 ROL::Ptr<std::vector<Real> > Mivp = ROL::makePtr<std::vector<Real>>(ni_,0);
272 this->
solve(vp,Mivp);
273 for(
int i=0;i<ni_;++i) {
275 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)