ROL
ROL_DynamicTrackingObjective.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_DYNAMICTRACKINGOBJECTIVE_HPP
12 #define ROL_DYNAMICTRACKINGOBJECTIVE_HPP
13 
14 #include "ROL_DynamicObjective.hpp"
15 #include "ROL_VectorWorkspace.hpp"
16 
17 
31 namespace ROL {
32 
33 template<typename Real>
35 public:
36 
37  using V = Vector<Real>;
40 
41 private:
42 
43  Ptr<PartitionedVector<Real>> target_;
44 
45  size_type Nt_; // Number of time steps
46  Real alpha_; // Regularization parameter
47 
49 
50 public:
51 
52  DynamicTrackingObjective( const Ptr<PartitionedVector<Real>>& target, Real alpha=0.0 ) :
53  target_(target), Nt_(target_->numVectors()), alpha_(alpha) {}
54 
56 
57  virtual Real value( const V& uo, const V& un,
58  const V& z, const TS& timeStamp ) const override {
59  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
60 
61  size_type k = timeStamp.k;
62 
63  auto udiff = workspace_.copy(un);
64  auto utarg = target_->get(k);
65 
66  udiff->axpy(-1.0, *utarg);
67 
68  Real result = 0.5*dt*( 0.5*udiff->dot(*udiff) + alpha_*z.dot(z) );
69 
70  if( k>0 ) {
71  utarg = target_->get(k-1);
72  udiff->set(uo);
73  udiff->axpy(-1.0,*utarg);
74  result += 0.25*dt*(udiff->dot(*udiff));
75  }
76  return result;
77  }
78 
79  //----------------------------------------------------------------------------
80  // Gradient Terms
81  virtual void gradient_uo( V& g, const V& uo, const V& un,
82  const V& z, const TS& timeStamp ) const override {
83  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
84  if( timeStamp.k>0 ) {
85  g.set(uo);
86  g.axpy(-1.0, *(target_->get(timeStamp.k-1)) );
87  g.scale(0.5*dt);
88  }
89  else g.zero();
90  }
91 
92  virtual void gradient_un( V& g, const V& uo, const V& un,
93  const V& z, const TS& timeStamp ) const override {
94  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
95  g.set(un);
96  g.axpy(-1.0, *(target_->get(timeStamp.k)) );
97  g.scale(0.5*dt);
98  }
99 
100  virtual void gradient_z( V& g, const V& uo, const V& un,
101  const V& z, const TS& timeStamp ) const override {
102  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
103  g.set(z);
104  g.scale(dt*alpha_);
105  }
106 
107  //----------------------------------------------------------------------------
108  // Hessian-Vector product terms
109  virtual void hessVec_uo_uo( V& hv, const V& v, const V& uo, const V& un,
110  const V& z, const TS& timeStamp ) const override {
111  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
112  if( timeStamp.k>0 ) {
113  hv.set(v);
114  hv.scale(dt/2.0);
115  }
116  else hv.zero();
117  }
118 
119  virtual void hessVec_uo_un( V& hv, const V& v, const V& uo, const V& un,
120  const V& z, const TS& timeStamp ) const override {
121  hv.zero();
122  }
123 
124  virtual void hessVec_uo_z( V& hv, const V& v, const V& uo, const V& un,
125  const V& z, const TS& timeStamp ) const override {
126  hv.zero();
127  }
128 
129  virtual void hessVec_un_uo( V& hv, const V& v, const V& uo, const V& un,
130  const V& z, const TS& timeStamp ) const override {
131  hv.zero();
132  }
133 
134  virtual void hessVec_un_un( V& hv, const V& v, const V& uo, const V& un,
135  const V& z, const TS& timeStamp ) const override {
136  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
137  hv.set(v);
138  hv.scale(dt/2.0);
139  }
140 
141  virtual void hessVec_un_z( V& hv, const V& v, const V& uo, const V& un,
142  const V& z, const TS& timeStamp ) const override {
143  hv.zero();
144  }
145 
146  virtual void hessVec_z_uo( V& hv, const V& v, const V& uo, const V& un,
147  const V& z, const TS& timeStamp ) const override {
148  hv.zero();
149  }
150 
151  virtual void hessVec_z_un( V& hv, const V& v, const V& uo, const V& un,
152  const V& z, const TS& timeStamp ) const override {
153  hv.zero();
154  }
155 
156  virtual void hessVec_z_z( V& hv, const V& v, const V& uo, const V& un,
157  const V& z, const TS& timeStamp ) const override {
158  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
159  hv.set(v);
160  hv.scale(alpha_*dt);
161  }
162 
163 }; // DynamicTrackingObjective
164 
165 
166 template<typename Real>
167 inline Ptr<DynamicObjective<Real>>
168 make_DynamicTrackingObjective( const Ptr<PartitionedVector<Real>>& target, Real alpha=0.0 ) {
169  Ptr<DynamicObjective<Real>> obj = makePtr<DynamicTrackingObjective<Real>>(target,alpha);
170  return obj;
171 }
172 
173 } // namespace ROL
174 
175 #endif // ROL_DYNAMICTRACKINGOBJECTIVE_HPP
176 
177 
virtual void hessVec_un_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void hessVec_z_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void scale(const Real alpha)=0
Compute where .
virtual void gradient_uo(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
Defines the linear algebra of vector space on a generic partitioned vector.
virtual void hessVec_uo_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void gradient_z(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Defines the time-dependent objective function interface for simulation-based optimization. Computes time-local contributions of value, gradient, Hessian-vector product etc to a larger composite objective defined over the simulation time. In contrast to other objective classes Objective_TimeSimOpt has a default implementation of value which returns zero, as time-dependent simulation based optimization problems may have an objective value which depends only on the final state of the system.
DynamicTrackingObjective(const Ptr< PartitionedVector< Real >> &target, Real alpha=0.0)
virtual Real dot(const Vector &x) const =0
Compute where .
Ptr< DynamicObjective< Real > > make_DynamicTrackingObjective(const Ptr< PartitionedVector< Real >> &target, Real alpha=0.0)
virtual void hessVec_z_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
typename PartitionedVector< Real >::size_type size_type
virtual void gradient_un(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual Real value(const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void hessVec_uo_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void hessVec_uo_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
Ptr< PartitionedVector< Real > > target_
std::vector< Real > t
std::vector< PV >::size_type size_type
virtual void hessVec_z_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
Defines the time-local contribution to a quadratic tracking objective.
virtual void hessVec_un_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void hessVec_un_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override