ROL
step/trustregion/ROL_SemismoothNewtonDualModel.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #pragma once
11 #ifndef ROL_SEMISMOOTHNEWTONDUALMODEL_HPP
12 #define ROL_SEMISMOOTHNEWTONDUALMODEL_HPP
13 
14 #include "ROL_TrustRegionModel.hpp"
16 #include "ROL_BoundConstraint.hpp"
17 #include "ROL_VectorWorkspace.hpp"
18 
32 namespace ROL {
33 
34 
35 template<class Real>
36 class SemismoothNewtonDualModel : public TrustRegionModel<Real> {
37 
38  using V = Vector<Real>;
39  using VPrim = InactiveSet_PrimalVector<Real>;
40  using VDual = InactiveSet_DualVector<Real>;
41 
42  using Obj = Objective<Real>;
43  using Sec = Secant<Real>;
44  using Bnd = BoundConstraint<Real>;
45 
46 private:
47 
48  class ProjectedObjective : public Objective<Real> {
49  private:
50  Obj& objPrimal_;
51  Bnd& bnd_;
52  Ptr<V> primalVec_;
53 
54  public:
55  ProjectedObjective( Obj& objPrimal, Bnd& bnd, const Ptr<V>& primalVec ) :
56  objPrimal_(objPrimal), bnd_(bnd), primalVec_( primalVec ) {}
57 
58  Real value( const V& p, Real& tol ) override {
59  primalVec_->set(p);
60  bnd_.project(*primalVec_);
61  return objPrimal_->value(*primalVec_, tol);
62  }
63 
64  void gradient( V& g, const V& p, Real& tol ) override {
65  primalVec_->set(p);
66  bnd_.project(*primalVec_);
67  objPrimal_->gradient(g,*primalVec_, tol);
68  }
69 
70  void hessVec( V& hv, const V& v, const V& p, Real& tol ) override {
71  primalVec_->set(p);
72  bnd_.project(*primalVec_);
73  objPrimal_->hessVec(hv,v,*primalVec_, tol);
74  }
75 
76  }; // ProjectedObjective
77 
78  ProjectedObjective projObj_;
79  Bnd bnd_;
80  Sec secant_;
81  Ptr<V> p_, g_, x_;
82  Ptr<V> ones_;
83  Ptr<VPrim> s_;
84  Real alpha_;
85 
86  VectorWorkspace<Real> workspace_;
87 
88 
89 public:
90 
91  SemismoothNewtonDualModel( Obj& obj, Bnd& bnd, const V& p, const V& g, const Real alpha ) :
92  TrustRegionModel( obj, p, g, false ), bnd_( bnd ),
93  p_( p.clone() ), g_( p.dual().clone() ), x_( p.clone() ), ones_( p.clone() ),
94  s_( p.clone(), ones_, p_, bnd_ ), projObj_( obj, bnd, p_ ), alpha_(alpha) {
95 
96  ones_->setScalar( Real(1.0) );
97  }
98 
99 
100  Real value( const V& s, Real& tol ) {
101 
102  auto hs = workspace_.clone(*g_);
103 
104  gradient(*g_,s,tol);
105  hessVec(*hs,s,s,tol);
106  hs->scale( 0.5 );
107  hs->plus(*g_);
108  s_->set(s);
109  return s_->dot(*hs);
110  }
111 
112  void gradient( V& g, const V& s, Real& tol ) {
113  projObj_->gradient(g,*p_,tol);
114  g.axpy(alpha_,*p_);
115  }
116 
117  void hessVec( V& hv, const V& v, const V& s, Real& tol ) {
118  auto vprune_ = workspace_.copy(v);
119  bnd_->pruneActive( *vprune_, *p_ );
120  projObj_->hessVec( hv, *vprune_, *p_, tol );
121  hv.axpy(alpha_,v);
122  }
123 
124  void update( const V& p, bool flag = true, int iter = -1 ) {
125  p_->set(p);
126  auto x = this->getIterate();
127  }
128 
129 } // namespace ROL
130 
VectorWorkspace< Real > workspace_
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
ROL::Objective_SimOpt value
Objective_TimeSimOpt< Real > Obj
Vector< Real > V
virtual Real value(const Vector< Real > &u, const Vector< Real > &z, Real &tol)=0
Compute value.