ROL
ROL_DynamicObjective_CheckInterface.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_DYNAMICOBJECTIVE_CHECKINTERFACE_HPP
12 #define ROL_DYNAMICOBJECTIVE_CHECKINTERFACE_HPP
13 
14 #include <functional>
15 
16 #include "ROL_DynamicObjective.hpp"
17 #include "ROL_FunctionBindings.hpp"
18 
19 
20 namespace ROL {
21 namespace details {
22 
23 namespace ph = std::placeholders;
24 
25 template<typename Real>
27 private:
28 
29  using V = Vector<Real>;
31 
33  Real tol_;
35 
36 public:
37 
39  ts_.t.resize(2);
40  ts_.t.at(0) = 0.0;
41  ts_.t.at(1) = 1.0;
42  ts_.k = 0;
43  }
44 
46  obj_(obj), ts_(ts) { }
47 
48 
49  f_update_t<Real> update_uo( const V& un, const V& z ) {
50  return std::bind( &Obj::update, &obj_, ph::_1, std::cref(un), std::cref(z), ts_ );
51  }
52 
53  f_update_t<Real> update_un( const V& uo, const V& z ) {
54  return std::bind( &Obj::update, &obj_, std::cref(uo), ph::_1, std::cref(z), ts_ );
55  }
56 
57  f_update_t<Real> update_z( const V& uo, const V& un ) {
58  return std::bind( &Obj::update, &obj_, std::cref(uo), std::cref(un), ph::_1, ts_ );
59  }
60 
61  //----------------------------------------------------------------------------
62 
63  f_scalar_t<Real> value_uo( const V& un, const V& z ) {
64  return std::bind( &Obj::value, &obj_, ph::_1, std::cref(un), std::cref(z), ts_ );
65  }
66 
67  f_scalar_t<Real> value_un( const V& uo, const V& z ) {
68  return std::bind( &Obj::value, &obj_, std::cref(uo), ph::_1, std::cref(z), ts_ );
69  }
70 
71  f_scalar_t<Real> value_z( const V& uo, const V& un ) {
72  return std::bind( &Obj::value, &obj_, std::cref(uo), std::cref(un), ph::_1, ts_ );
73  }
74 
75  //----------------------------------------------------------------------------
76 
77  f_vector_t<Real> gradient_uo( const V& un, const V& z ) {
78  return std::bind( &Obj::gradient_uo, &obj_, ph::_1, ph::_2, std::cref(un), std::cref(z), ts_ );
79  }
80 
81  f_vector_t<Real> gradient_un( const V& uo, const V& z ) {
82  return std::bind( &Obj::gradient_un, &obj_, ph::_1, std::cref(uo), ph::_2, std::cref(z), ts_ );
83  }
84 
85  f_vector_t<Real> gradient_z( const V& uo, const V& un ) {
86  return std::bind( &Obj::gradient_z, &obj_, ph::_1, std::cref(uo), std::cref(un), ph::_2, ts_ );
87  }
88 
89  // For hessian checks
90  f_vector_t<Real> gradient_uo_uo( const V& un, const V& z ) {
91  return std::bind( &Obj::gradient_uo, &obj_, ph::_1, ph::_2, std::cref(un), std::cref(z), ts_ );
92  }
93 
94  f_vector_t<Real> gradient_uo_un( const V& uo, const V& z ) {
95  return std::bind( &Obj::gradient_uo, &obj_, ph::_1, std::cref(uo), ph::_2, std::cref(z), ts_ );
96  }
97 
98  f_vector_t<Real> gradient_uo_z( const V& uo, const V& un ) {
99  return std::bind( &Obj::gradient_uo, &obj_, ph::_1, std::cref(uo), std::cref(un), ph::_2, ts_ );
100  }
101 
102  f_vector_t<Real> gradient_un_uo( const V& un, const V& z ) {
103  return std::bind( &Obj::gradient_un, &obj_, ph::_1, ph::_2, std::cref(un), std::cref(z), ts_ );
104  }
105 
106  f_vector_t<Real> gradient_un_un( const V& uo, const V& z ) {
107  return std::bind( &Obj::gradient_un, &obj_, ph::_1, std::cref(uo), ph::_2, std::cref(z), ts_ );
108  }
109 
110  f_vector_t<Real> gradient_un_z( const V& uo, const V& un ) {
111  return std::bind( &Obj::gradient_un, &obj_, ph::_1, std::cref(uo), std::cref(un), ph::_2, ts_ );
112  }
113 
114  f_vector_t<Real> gradient_z_uo( const V& un, const V& z ) {
115  return std::bind( &Obj::gradient_z, &obj_, ph::_1, ph::_2, std::cref(un), std::cref(z), ts_ );
116  }
117 
118  f_vector_t<Real> gradient_z_un( const V& uo, const V& z ) {
119  return std::bind( &Obj::gradient_z, &obj_, ph::_1, std::cref(uo), ph::_2, std::cref(z), ts_ );
120  }
121 
122  f_vector_t<Real> gradient_z_z( const V& uo, const V& un ) {
123  return std::bind( &Obj::gradient_z, &obj_, ph::_1, std::cref(uo), std::cref(un), ph::_2, ts_ );
124  }
125 
126  //----------------------------------------------------------------------------
127 
128  f_dderiv_t<Real> hessVec_uo_uo( const V& un, const V& z ) {
129  return std::bind( &Obj::hessVec_uo_uo, &obj_, ph::_1, ph::_2, ph::_3, std::cref(un), std::cref(z), ts_ );
130  }
131 
132  f_dderiv_t<Real> hessVec_uo_un( const V& uo, const V& z ) {
133  return std::bind( &Obj::hessVec_uo_un, &obj_, ph::_1, ph::_2, std::cref(uo), ph::_3, std::cref(z), ts_ );
134  }
135 
136  f_dderiv_t<Real> hessVec_uo_z( const V& uo, const V& un ) {
137  return std::bind( &Obj::hessVec_uo_z, &obj_, ph::_1, ph::_2, std::cref(uo), std::cref(un), ph::_3, ts_ );
138  }
139 
140  //----------------------------------------------------------------------------
141 
142  f_dderiv_t<Real> hessVec_un_uo( const V& un, const V& z ) {
143  return std::bind( &Obj::hessVec_un_uo, &obj_, ph::_1, ph::_2, ph::_3, std::cref(un), std::cref(z), ts_ );
144  }
145 
146  f_dderiv_t<Real> hessVec_un_un( const V& uo, const V& z ) {
147  return std::bind( &Obj::hessVec_un_un, &obj_, ph::_1, ph::_2, std::cref(uo), ph::_3, std::cref(z), ts_ );
148  }
149 
150  f_dderiv_t<Real> hessVec_un_z( const V& uo, const V& un ) {
151  return std::bind( &Obj::hessVec_un_z, &obj_, ph::_1, ph::_2, std::cref(uo), std::cref(un), ph::_3, ts_ );
152  }
153 
154  //----------------------------------------------------------------------------
155 
156  f_dderiv_t<Real> hessVec_z_uo( const V& un, const V& z ) {
157  return std::bind( &Obj::hessVec_z_uo, &obj_, ph::_1, ph::_2, ph::_3, std::cref(un), std::cref(z), ts_ );
158  }
159 
160  f_dderiv_t<Real> hessVec_z_un( const V& uo, const V& z ) {
161  return std::bind( &Obj::hessVec_z_un, &obj_, ph::_1, ph::_2, std::cref(uo), ph::_3, std::cref(z), ts_ );
162  }
163 
164  f_dderiv_t<Real> hessVec_z_z( const V& uo, const V& un ) {
165  return std::bind( &Obj::hessVec_z_z, &obj_, ph::_1, ph::_2, std::cref(uo), std::cref(un), ph::_3, ts_ );
166  }
167 
168 
169 }; // DynamicObjective_CheckInterface
170 
171 
172 } // namespace details
173 
174 using details::DynamicObjective_CheckInterface;
175 
176 template<typename Real>
177 DynamicObjective_CheckInterface<Real> make_check( DynamicObjective<Real>& obj ) {
178  return DynamicObjective_CheckInterface<Real>( obj );
179 }
180 
181 template<typename Real>
182 DynamicObjective_CheckInterface<Real> make_check( DynamicObjective<Real>& obj,
183  TimeStamp<Real>& ts ) {
184  return DynamicObjective_CheckInterface<Real>( obj, ts );
185 }
186 
187 
188 } // namespace ROL
189 
190 
191 #endif // ROL_DYNAMICOBJECTIVE_CHECKINTERFACE_HPP
192 
f_vector_t< Real > gradient_uo_uo(const V &un, const V &z)
f_dderiv_t< Real > hessVec_un_un(const V &uo, const V &z)
f_vector_t< Real > gradient_z(const V &uo, const V &un)
virtual void hessVec_z_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
f_dderiv_t< Real > hessVec_uo_un(const V &uo, const V &z)
f_dderiv_t< Real > hessVec_z_un(const V &uo, const V &z)
f_vector_t< Real > gradient_uo_z(const V &uo, const V &un)
f_vector_t< Real > gradient_un_un(const V &uo, const V &z)
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.
f_dderiv_t< Real > hessVec_z_z(const V &uo, const V &un)
f_vector_t< Real > gradient_z_uo(const V &un, const V &z)
f_vector_t< Real > gradient_z_un(const V &uo, const V &z)
virtual void hessVec_un_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_dderiv_t< Real > hessVec_un_z(const V &uo, const V &un)
virtual void hessVec_z_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_vector_t< Real > gradient_un_uo(const V &un, const V &z)
f_update_t< Real > update_z(const V &uo, const V &un)
virtual void hessVec_uo_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_vector_t< Real > gradient_uo_un(const V &uo, const V &z)
virtual void gradient_z(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_vector_t< Real > gradient_un(const V &uo, const V &z)
f_vector_t< Real > gradient_uo(const V &un, const V &z)
virtual void hessVec_uo_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
virtual void hessVec_un_un(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
std::vector< Real > t
virtual void gradient_un(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_dderiv_t< Real > hessVec_z_uo(const V &un, const V &z)
f_dderiv_t< Real > hessVec_uo_uo(const V &un, const V &z)
f_vector_t< Real > gradient_z_z(const V &uo, const V &un)
f_scalar_t< Real > value_z(const V &uo, const V &un)
f_dderiv_t< Real > hessVec_uo_z(const V &uo, const V &un)
virtual void hessVec_un_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_vector_t< Real > gradient_un_z(const V &uo, const V &un)
virtual void hessVec_z_uo(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
virtual void hessVec_uo_z(V &hv, const V &v, const V &uo, const V &un, const V &z, const TS &timeStamp) const
virtual void gradient_uo(V &g, const V &uo, const V &un, const V &z, const TS &timeStamp) const
f_dderiv_t< Real > hessVec_un_uo(const V &un, const V &z)
virtual Real value(const V &uo, const V &un, const V &z, const TS &timeStamp) const =0
DynamicConstraint_CheckInterface< Real > make_check(DynamicConstraint< Real > &con)