ROL
ROL_DynamicTrackingObjective.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #pragma once
45 #ifndef ROL_DYNAMICTRACKINGOBJECTIVE_HPP
46 #define ROL_DYNAMICTRACKINGOBJECTIVE_HPP
47 
48 #include "ROL_DynamicObjective.hpp"
49 #include "ROL_VectorWorkspace.hpp"
50 
51 
65 namespace ROL {
66 
67 template<typename Real>
69 public:
70 
71  using V = Vector<Real>;
74 
75 private:
76 
77  Ptr<PartitionedVector<Real>> target_;
78 
79  size_type Nt_; // Number of time steps
80  Real alpha_; // Regularization parameter
81 
83 
84 public:
85 
86  DynamicTrackingObjective( const Ptr<PartitionedVector<Real>>& target, Real alpha=0.0 ) :
87  target_(target), Nt_(target_->numVectors()), alpha_(alpha) {}
88 
90 
91  virtual Real value( const V& uo, const V& un,
92  const V& z, const TS& timeStamp ) const override {
93  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
94 
95  size_type k = timeStamp.k;
96 
97  auto udiff = workspace_.copy(un);
98  auto utarg = target_->get(k);
99 
100  udiff->axpy(-1.0, *utarg);
101 
102  Real result = 0.5*dt*( 0.5*udiff->dot(*udiff) + alpha_*z.dot(z) );
103 
104  if( k>0 ) {
105  utarg = target_->get(k-1);
106  udiff->set(uo);
107  udiff->axpy(-1.0,*utarg);
108  result += 0.25*dt*(udiff->dot(*udiff));
109  }
110  return result;
111  }
112 
113  //----------------------------------------------------------------------------
114  // Gradient Terms
115  virtual void gradient_uo( V& g, const V& uo, const V& un,
116  const V& z, const TS& timeStamp ) const override {
117  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
118  if( timeStamp.k>0 ) {
119  g.set(uo);
120  g.axpy(-1.0, *(target_->get(timeStamp.k-1)) );
121  g.scale(0.5*dt);
122  }
123  else g.zero();
124  }
125 
126  virtual void gradient_un( V& g, const V& uo, const V& un,
127  const V& z, const TS& timeStamp ) const override {
128  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
129  g.set(un);
130  g.axpy(-1.0, *(target_->get(timeStamp.k)) );
131  g.scale(0.5*dt);
132  }
133 
134  virtual void gradient_z( V& g, 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  g.set(z);
138  g.scale(dt*alpha_);
139  }
140 
141  //----------------------------------------------------------------------------
142  // Hessian-Vector product terms
143  virtual void hessVec_uo_uo( V& hv, const V& v, const V& uo, const V& un,
144  const V& z, const TS& timeStamp ) const override {
145  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
146  if( timeStamp.k>0 ) {
147  hv.set(v);
148  hv.scale(dt/2.0);
149  }
150  else hv.zero();
151  }
152 
153  virtual void hessVec_uo_un( V& hv, const V& v, const V& uo, const V& un,
154  const V& z, const TS& timeStamp ) const override {
155  hv.zero();
156  }
157 
158  virtual void hessVec_uo_z( V& hv, const V& v, const V& uo, const V& un,
159  const V& z, const TS& timeStamp ) const override {
160  hv.zero();
161  }
162 
163  virtual void hessVec_un_uo( V& hv, const V& v, const V& uo, const V& un,
164  const V& z, const TS& timeStamp ) const override {
165  hv.zero();
166  }
167 
168  virtual void hessVec_un_un( V& hv, const V& v, const V& uo, const V& un,
169  const V& z, const TS& timeStamp ) const override {
170  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
171  hv.set(v);
172  hv.scale(dt/2.0);
173  }
174 
175  virtual void hessVec_un_z( V& hv, const V& v, const V& uo, const V& un,
176  const V& z, const TS& timeStamp ) const override {
177  hv.zero();
178  }
179 
180  virtual void hessVec_z_uo( V& hv, const V& v, const V& uo, const V& un,
181  const V& z, const TS& timeStamp ) const override {
182  hv.zero();
183  }
184 
185  virtual void hessVec_z_un( V& hv, const V& v, const V& uo, const V& un,
186  const V& z, const TS& timeStamp ) const override {
187  hv.zero();
188  }
189 
190  virtual void hessVec_z_z( V& hv, const V& v, const V& uo, const V& un,
191  const V& z, const TS& timeStamp ) const override {
192  Real dt = timeStamp.t.at(1)-timeStamp.t.at(0);
193  hv.set(v);
194  hv.scale(alpha_*dt);
195  }
196 
197 }; // DynamicTrackingObjective
198 
199 
200 template<typename Real>
201 inline Ptr<DynamicObjective<Real>>
202 make_DynamicTrackingObjective( const Ptr<PartitionedVector<Real>>& target, Real alpha=0.0 ) {
203  Ptr<DynamicObjective<Real>> obj = makePtr<DynamicTrackingObjective<Real>>(target,alpha);
204  return obj;
205 }
206 
207 } // namespace ROL
208 
209 #endif // ROL_DYNAMICTRACKINGOBJECTIVE_HPP
210 
211 
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:153
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:167
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
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:209
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