ROL
ROL_Objective_TimeSimOpt.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_OBJECTIVE_TIMESIMOPT_HPP
12 #define ROL_OBJECTIVE_TIMESIMOPT_HPP
13 
14 #include "ROL_Objective_SimOpt.hpp"
15 #include "ROL_VectorWorkspace.hpp"
16 
43 namespace ROL {
44 
45 template<typename Real>
46 class Objective_TimeSimOpt : public Objective_SimOpt<Real> {
47 private:
48 
49  // Get the end point of the time intervals vector
50  template<int I>
52  return *(static_cast<PartitionedVector<Real>&>(x).get(I));
53  }
54 
55  template<int I>
56  const Vector<Real> & getVector(const Vector<Real> & x) const {
57  return *(static_cast<const PartitionedVector<Real>&>(x).get(I));
58  }
59 
61 
62 protected:
63 
65 
66 public:
67 
69 
70  // Interface functions (to be overloaded)
71 
79  virtual void update( const Vector<Real>& u_old,
80  const Vector<Real>& u_new,
81  const Vector<Real>& z,
82  bool flag = true, int iter = -1 ) {
83  update_1_old( u_old, flag, iter );
84  update_1_new( u_new, flag, iter );
85  update_2( z, flag, iter );
86  }
87 };
88 
94  virtual void update_1_old( const Vector<Real>& u_old, bool flag = true, int iter = -1 ) {}
95 
101  virtual void update_1_new( const Vector<Real>& u_new, bool flag = true, int iter = -1 ) {}
102 
108  virtual void update_2( const Vector<Real> &z, bool flag = true, int iter = -1 ) override {}
109 
110 
112  virtual Real value( const Vector<Real>& u_old, const Vector<Real>& u_new,
113  const Vector<Real>& z, Real& tol ) { return 0; }
114 
115 
117  virtual void gradient_1_old( Vector<Real>& g, const Vector<Real>& u_old,
118  Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) {}
119 
121  virtual void gradient_1_new( Vector<Real>& g, const Vector<Real>& u_old,
122  Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) {}
123 
124 
126  virtual void gradient_2( Vector<Real>& g, const Vector<Real>& u_old,
127  Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) override {}
128 
129  virtual void hessVec_11_old( Vector<Real> &hv, const Vector<Real> &v_old,
130  const Vector<Real> &u_old, const Vector<Real>& u_new,
131  const Vector<Real> &z, Real &tol ) {}
132 
133  virtual void hessVec_11_new( Vector<Real> &hv, const Vector<Real> &v_new,
134  const Vector<Real> &u_old, const Vector<Real>& u_new,
135  const Vector<Real> &z, Real &tol ) {}
136 
137  // Functions from SimOpt that are overriden
139 
140  virtual void update( const Vector<Real>& u, const Vector<Real>& z,
141  bool flag = true, int iter = -1 ) override {
142  update(getVector<0>(u), getVector<1>(u), z, flag,iter);
143  }
144 
145  virtual Real value( const Vector<Real>& u, const Vector<Real>& z,
146  Real& tol ) override {
147  return value( getVector<0>(u), getVector<1>(u), z, tol );
148  }
149 
150  virtual void solve( Vector<Real>& c, Vector<Real>& u, const Vector<Real>& z ) override {
151  solve( c, getVector<0>(u), getVector<1>(u), z, tol );
152  }
153 
154  virtual void gradient_1( Vector<Real>& g, const Vector<Real>& u,
155  const Vector<Real>& z, Real& tol ) override {
156 
157  auto& u_old = getVector<0>(u);
158  auto& u_new = getVector<1>(u);
159 
160  gradient_1_old( g, u_old, u_new, z, tol );
161 
162  auto g_new = workspace_.clone(g);
163 
164  gradient_1_new( *g_new, u_old, u_new, z, tol );
165 
166  g.plus(*g_new);
167  }
168 
169  virtual void gradient_2( Vector<Real>& g, const Vector<Real>& u,
170  const Vector<Real>& z, Real& tol ) override {
171  auto& u_old = getVector<0>(u);
172  auto& u_new = getVector<1>(u);
173 
174  gradient_2( g, u_old, u_new, z, tol );
175  }
176 
177  virtual void hessVec_11( Vector<Real>& hv, const Vector<Real>& v,
178  const Vector<Real>& u, const Vector<Real>& z,
179  Real& tol ) override {
180 
181  auto& hv_old = getVector<0>(hv);
182  auto& hv_new = getVector<1>(hv);
183  auto& v_old = getVector<0>(v);
184  auto& v_new = getVector<1>(v):
185  auto& u_old = getVector<0>(u);
186  auto& u_new = getVector<1>(u);
187 
188  hessVec_11( hv_old, v_old, u_old, u_new, z, tol );
189  hessVec_11( hv_new, v_new, u_old, u_new, z, tol );
190 
191  }
192 
193  virtual void hessVec_12( Vector<Real>& hv, const Vector<Real>& v,
194  const Vector<Real>& u, const Vector<Real>& z,
195  Real& tol ) override { hv.zero(); }
196 
197  virtual void hessVec_21( Vector<Real>& hv, const Vector<Real>& v,
198  const Vector<Real>& u, const Vector<Real>& z,
199  Real& tol ) override { hv.zero(); }
200 
201  virtual void hessVec_22( Vector<Real>& hv, const Vector<Real>& v,
202  const Vector<Real>& u, const Vector<Real>& z,
203  Real& tol ) override { hv.zero(); }
204 
205 } // namespace ROL
206 
207 
208 #endif // ROL_OBJECTIVE_TIMESIMOPT_HPP
209 
virtual void gradient_1_old(Vector< Real > &g, const Vector< Real > &u_old, Vector< Real > &u_new, const Vector< Real > &z, Real &tol)
Compute contribution to simulation term gradient from this time step.
virtual void hessVec_21(V &hv, const V &v, const V &u, const V &z, Real &tol) override
Provides the interface to evaluate simulation-based objective functions.
virtual void gradient_1(V &g, const V &u, const V &z, Real &tol) override
VectorWorkspace< Real > workspace_
virtual void plus(const Vector &x)=0
Compute , where .
virtual void gradient_1_new(Vector< Real > &g, const Vector< Real > &u_old, Vector< Real > &u_new, const Vector< Real > &z, Real &tol)
Compute contribution to simulation term gradient from this time step.
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.
Defines the linear algebra of vector space on a generic partitioned vector.
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
ROL::Objective_SimOpt value
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
virtual void hessVec_12(V &hv, const V &v, const V &u, const V &z, Real &tol) override
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void gradient_2(V &g, const V &u, const V &z, Real &tol) override
virtual void hessVec_22(V &hv, const V &v, const V &u, const V &z, Real &tol) override
VectorWorkspace< Real > & getVectorWorkspace() const
virtual void update_1_new(const Vector< Real > &u_new, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. u_new is the state variable flag = true if ...
virtual void hessVec_11_new(Vector< Real > &hv, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)
virtual void hessVec_11_old(Vector< Real > &hv, const Vector< Real > &v_old, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)
VectorWorkspace< Real > workspace_
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
virtual void hessVec_11(V &hv, const V &v, const V &u, const V &z, Real &tol) override
const Vector< Real > & getVector(const Vector< Real > &x) const
virtual void update_2(const Vector< Real > &z, bool flag=true, int iter=-1) override
Update constraint functions with respect to Opt variable. z is the control variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
Vector< Real > & getVector(Vector< Real > &x) const
virtual void update_1_old(const Vector< Real > &u_old, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. u_old is the state variable flag = true if ...
virtual void update(const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions. u_old Is the state from the end of the previous time step...