ROL
ROL_DynamicTrackingFEMObjective.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_DYNAMICTRACKINGFEMOBJECTIVE_HPP
12 #define ROL_DYNAMICTRACKINGFEMOBJECTIVE_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  DynamicTrackingFEMObjective( 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 
60  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
61  Real w = 2.0*dt/3.0;
62 
63  size_type k = timeStamp.k;
64 
65  auto res_n = workspace_.copy(un);
66  auto res_o = workspace_.copy(uo);
67 
68  Real result = 0.5*dt*alpha_*z.dot(z);
69 
70  res_n->set(un);
71  res_n->axpy( -1.0, *(target_->get(k)) );
72  result += w*res_n->dot(*res_n);
73 
74  if( k>0 ) {
75  res_o->set(uo);
76  res_o->axpy( -1, *(target_->get(k-1) ) );
77  result += w*res_n->dot(*res_o);
78  result += w*res_o->dot(*res_o);
79  }
80 
81  return result;
82  }
83 
84  //----------------------------------------------------------------------------
85  // Gradient Terms
86  virtual void gradient_uo( V& g, const V& uo, const V& un,
87  const V& z, const TS& timeStamp ) const override {
88  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
89  Real w = dt/3.0;
90 
91  size_type k = timeStamp.k;
92 
93  auto res_n = workspace_.copy(un);
94  auto res_o = workspace_.copy(uo);
95 
96 
97 
98 
99  else g.zero();
100  }
101 
102  virtual void gradient_un( V& g, const V& uo, const V& un,
103  const V& z, const TS& timeStamp ) const override {
104  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
105  g.set(un);
106  g.axpy(-1.0, *(target_->get(timeStamp.k)) );
107  g.scale(0.5*dt);
108  }
109 
110  virtual void gradient_z( V& g, const V& uo, const V& un,
111  const V& z, const TS& timeStamp ) const override {
112  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
113  g.set(z);
114  g.scale(dt*alpha_);
115  }
116 
117  //----------------------------------------------------------------------------
118  // Hessian-Vector product terms
119  virtual void hessVec_uo_uo( V& hv, const V& v, const V& uo, const V& un,
120  const V& z, const TS& timeStamp ) const override {
121  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
122  if( timeStamp.k>0 ) {
123  hv.set(v);
124  hv.axpy(-1.0, *(target_->get(timeStamp.k-1)) );
125  hv.scale(0.5*dt);
126  }
127  else hv.zero();
128  }
129 
130  virtual void hessVec_uo_un( V& hv, const V& v, const V& uo, const V& un,
131  const V& z, const TS& timeStamp ) const override {
132  hv.zero();
133  }
134 
135  virtual void hessVec_uo_z( V& hv, const V& v, const V& uo, const V& un,
136  const V& z, const TS& timeStamp ) const override {
137  hv.zero();
138  }
139 
140  virtual void hessVec_un_uo( V& hv, const V& v, const V& uo, const V& un,
141  const V& z, const TS& timeStamp ) const override {
142  hv.zero();
143  }
144 
145  virtual void hessVec_un_un( V& hv, const V& v, const V& uo, const V& un,
146  const V& z, const TS& timeStamp ) const override {
147  hv.set(v);
148  hv.scale(0.5*(timeStamp.t.at(1)-timeStamp.t.at(0)));
149  }
150 
151  virtual void hessVec_un_z( 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_uo( V& hv, const V& v, const V& uo, const V& un,
157  const V& z, const TS& timeStamp ) const override {
158  hv.zero();
159  }
160 
161  virtual void hessVec_z_un( V& hv, const V& v, const V& uo, const V& un,
162  const V& z, const TS& timeStamp ) const override {
163  hv.zero();
164  }
165 
166  virtual void hessVec_z_z( V& hv, const V& v, const V& uo, const V& un,
167  const V& z, const TS& timeStamp ) const override {
168  hv.set(v);
169  hv.scale(alpha_*(timeStamp.t.at(1)-timeStamp.t.at(0)));
170  }
171 
172 }; // DynamicTrackingFEMObjective
173 
174 
175 template<typename Real>
176 inline Ptr<DynamicObjective<Real>>
177 make_DynamicTrackingFEMObjective( const Ptr<PartitionedVector<Real>>& target, Real alpha=0.0 ) {
178  Ptr<DynamicObjective<Real>> obj = makePtr<DynamicTrackingFEMObjective<Real>>(target,alpha);
179  return obj;
180 }
181 
182 } // namespace ROL
183 
184 #endif // ROL_DYNAMICTRACKINGFEMOBJECTIVE_HPP
185 
186 
virtual void gradient_z(V &g, 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 axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
DynamicTrackingFEMObjective(const Ptr< PartitionedVector< Real >> &target, Real alpha=0.0)
Defines the linear algebra of vector space on a generic partitioned vector.
virtual void hessVec_z_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
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 gradient_uo(V &g, 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 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.
virtual Real dot(const Vector &x) const =0
Compute where .
virtual void hessVec_un_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
virtual void hessVec_un_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
Ptr< DynamicObjective< Real > > make_DynamicTrackingFEMObjective(const Ptr< PartitionedVector< Real >> &target, Real alpha=0.0)
virtual Real value(const V &uo, const V &un, const V &z, const TS &timeStamp) const override
typename PartitionedVector< Real >::size_type size_type
std::vector< Real > t
std::vector< PV >::size_type size_type
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
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 hessVec_uo_un(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 gradient_un(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const override
Defines the time-local contribution to a quadratic tracking objective.
virtual void hessVec_un_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const override