ROL
ROL_Objective_SerialSimOpt.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_SERIALSIMOPT_HPP
12 #define ROL_OBJECTIVE_SERIALSIMOPT_HPP
13 
15 
16 namespace ROL {
17 
18 template<typename Real>
20 
21  using V = Vector<Real>;
24 
25  using size_type = typename PV<Real>::size_type;
26 
27 private:
28 
29  const Ptr<Obj> obj_;
30  const Ptr<V> ui_; // Initial condition
31 
32  VectorWorkspace<Real> workspace_; // Memory management
33 
34 
35 protected:
36 
37  PV& partition( V& x ) const { return static_cast<PV&>(x); }
38 
39  const PV& partition( const V& x ) const { return static_cast<const PV&>(x); }
40 
41 public:
42 
43  Objective_SerialSimOpt( const Ptr<Obj>& obj, const V& ui ) :
44  obj_(obj),
45  ui_( workspace_.copy( ui ) ),
46  u0_->zero(); z0_->zero();
47  }
48 
49 
50  virtual Real value( const V& u, const V& z, Real& tol ) override {
51 
52  auto& up = partition(u);
53  auto& zp = partition(z);
54 
55  // First step
56  Real result = obj_->value( *ui_, *(up.get(0)), *(zp.get(0)), tol );
57 
58  for( size_type k=1; k<up.numVector(); ++k ) {
59  result += obj_->value( *(up.get(k-1), *(up.get(k)), *(zp.get(k)), tol );
60  }
61  return result;
62  }
63 
64  virtual void gradient_1( V& g, const V &u, const V& z, Real& tol ) override {
65 
66  auto& up = partition(u);
67  auto& zp = partition(z);
68  auto& gp = partition(g);
69 
70  // First step
71  obj_->gradient_1( *(gp.get(0)), *ui_, *ui_, *(up.get(0)), *(zp.get(0)), tol );
72 
73  for( size_type k=1; k<up.numVector(); ++k ) {
74  obj_->gradient_1( *(gp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
75  }
76  }
77 
78  virtual void gradient_2( V& g, const V& u, const V& z, Real& tol ) override {
79 
80  auto& up = partition(u);
81  auto& zp = partition(z);
82  auto& gp = partition(g);
83 
84  // First step
85  obj_->gradient_2( *(gp.get(0)), *ui_, *ui_, *(up.get(0)), *(zp.get(0)), tol );
86 
87  for( size_type k=1; k<up.numVector(); ++k ) {
88  obj_->gradient_2( *(gp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
89  }
90  }
91 
92  virtual void hessVec_11( V& hv, const V& v,
93  const V& u, const V& z, Real& tol ) override {
94 
95  auto& hvp = partition(hv);
96  auto& vp = partition(v);
97  auto& up = partition(u);
98  auto& zp = partition(z);
99  auto& gp = partition(g);
100 
101  // First step
102  obj_->hessVec_11( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
103 
104  for( size_type k=1; k<up.numVector(); ++k ) {
105  obj_->hessVec_11( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
106  }
107  }
108 
109  virtual void hessVec_12( V& hv, const V& v, const V&u, const V&z, Real &tol ) override {
110 
111  auto& hvp = partition(hv);
112  auto& vp = partition(v);
113  auto& up = partition(u);
114  auto& zp = partition(z);
115  auto& gp = partition(g);
116 
117  // First step
118  obj_->hessVec_12( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
119 
120  for( size_type k=1; k<up.numVector(); ++k ) {
121  obj_->hessVec_12( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
122  }
123  }
124 
125  virtual void hessVec_21( V&hv, const V&v, const V&u, const V&z, Real &tol ) override {
126 
127  auto& hvp = partition(hv);
128  auto& vp = partition(v);
129  auto& up = partition(u);
130  auto& zp = partition(z);
131  auto& gp = partition(g);
132 
133  // First step
134  obj_->hessVec_21( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
135 
136  for( size_type k=1; k<up.numVector(); ++k ) {
137  obj_->hessVec_21( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
138  }
139  }
140 
141  virtual void hessVec_22( V&hv, const V&v, const V&u, const V&z, Real &tol ) override {
142 
143  auto& hvp = partition(hv);
144  auto& vp = partition(v);
145  auto& up = partition(u);
146  auto& zp = partition(z);
147  auto& gp = partition(g);
148 
149  // First step
150  obj_->hessVec_22( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
151 
152  for( size_type k=1; k<up.numVector(); ++k ) {
153  obj_->hessVec_22( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
154  }
155  }
156 
157 }; // class Objective_SerialSimOpt
158 
159 } // namespace ROL
160 
161 
162 #endif // ROL_OBJECTIVE_SERIALSIMOPT_HPP
163 
PartitionedVector< Real > & partition(Vector< Real > &x)
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.
typename PV< Real >::size_type size_type
virtual void gradient_1(V &g, const V &u, const V &z, Real &tol) override
const PV & partition(const V &x) const
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.
ROL::Objective_SimOpt value
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
Vector< Real > V
virtual void hessVec_22(V &hv, const V &v, const V &u, const V &z, Real &tol) override
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
const Ptr< V > ui_
virtual void hessVec_11(V &hv, const V &v, const V &u, const V &z, Real &tol) override
std::vector< PV >::size_type size_type
const Ptr< Obj > obj_
typename PV< Real >::size_type size_type