ROL
ROL_Objective_TimeSimOpt.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_OBJECTIVE_TIMESIMOPT_HPP
46#define ROL_OBJECTIVE_TIMESIMOPT_HPP
47
50
77namespace ROL {
78
79template<typename Real>
81private:
82
83 // Get the end point of the time intervals vector
84 template<int I>
86 return *(static_cast<PartitionedVector<Real>&>(x).get(I));
87 }
88
89 template<int I>
90 const Vector<Real> & getVector(const Vector<Real> & x) const {
91 return *(static_cast<const PartitionedVector<Real>&>(x).get(I));
92 }
93
95
96protected:
97
99
100public:
101
102 using Objective_SimOpt<Real>::Objective_SimOpt;
103
104 // Interface functions (to be overloaded)
105
113 virtual void update( const Vector<Real>& u_old,
114 const Vector<Real>& u_new,
115 const Vector<Real>& z,
116 bool flag = true, int iter = -1 ) {
117 update_1_old( u_old, flag, iter );
118 update_1_new( u_new, flag, iter );
119 update_2( z, flag, iter );
120 }
121};
122
128 virtual void update_1_old( const Vector<Real>& u_old, bool flag = true, int iter = -1 ) {}
129
135 virtual void update_1_new( const Vector<Real>& u_new, bool flag = true, int iter = -1 ) {}
136
142 virtual void update_2( const Vector<Real> &z, bool flag = true, int iter = -1 ) override {}
143
144
146 virtual Real value( const Vector<Real>& u_old, const Vector<Real>& u_new,
147 const Vector<Real>& z, Real& tol ) { return 0; }
148
149
151 virtual void gradient_1_old( Vector<Real>& g, const Vector<Real>& u_old,
152 Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) {}
153
155 virtual void gradient_1_new( Vector<Real>& g, const Vector<Real>& u_old,
156 Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) {}
157
158
160 virtual void gradient_2( Vector<Real>& g, const Vector<Real>& u_old,
161 Vector<Real>& u_new, const Vector<Real>& z, Real& tol ) override {}
162
163 virtual void hessVec_11_old( Vector<Real> &hv, const Vector<Real> &v_old,
164 const Vector<Real> &u_old, const Vector<Real>& u_new,
165 const Vector<Real> &z, Real &tol ) {}
166
167 virtual void hessVec_11_new( Vector<Real> &hv, const Vector<Real> &v_new,
168 const Vector<Real> &u_old, const Vector<Real>& u_new,
169 const Vector<Real> &z, Real &tol ) {}
170
171 // Functions from SimOpt that are overriden
173
174 virtual void update( const Vector<Real>& u, const Vector<Real>& z,
175 bool flag = true, int iter = -1 ) override {
176 update(getVector<0>(u), getVector<1>(u), z, flag,iter);
177 }
178
179 virtual Real value( const Vector<Real>& u, const Vector<Real>& z,
180 Real& tol ) override {
181 return value( getVector<0>(u), getVector<1>(u), z, tol );
182 }
183
184 virtual void solve( Vector<Real>& c, Vector<Real>& u, const Vector<Real>& z ) override {
185 solve( c, getVector<0>(u), getVector<1>(u), z, tol );
186 }
187
188 virtual void gradient_1( Vector<Real>& g, const Vector<Real>& u,
189 const Vector<Real>& z, Real& tol ) override {
190
191 auto& u_old = getVector<0>(u);
192 auto& u_new = getVector<1>(u);
193
194 gradient_1_old( g, u_old, u_new, z, tol );
195
196 auto g_new = workspace_.clone(g);
197
198 gradient_1_new( *g_new, u_old, u_new, z, tol );
199
200 g.plus(*g_new);
201 }
202
203 virtual void gradient_2( Vector<Real>& g, const Vector<Real>& u,
204 const Vector<Real>& z, Real& tol ) override {
205 auto& u_old = getVector<0>(u);
206 auto& u_new = getVector<1>(u);
207
208 gradient_2( g, u_old, u_new, z, tol );
209 }
210
211 virtual void hessVec_11( Vector<Real>& hv, const Vector<Real>& v,
212 const Vector<Real>& u, const Vector<Real>& z,
213 Real& tol ) override {
214
215 auto& hv_old = getVector<0>(hv);
216 auto& hv_new = getVector<1>(hv);
217 auto& v_old = getVector<0>(v);
218 auto& v_new = getVector<1>(v):
219 auto& u_old = getVector<0>(u);
220 auto& u_new = getVector<1>(u);
221
222 hessVec_11( hv_old, v_old, u_old, u_new, z, tol );
223 hessVec_11( hv_new, v_new, u_old, u_new, z, tol );
224
225 }
226
227 virtual void hessVec_12( Vector<Real>& hv, const Vector<Real>& v,
228 const Vector<Real>& u, const Vector<Real>& z,
229 Real& tol ) override { hv.zero(); }
230
231 virtual void hessVec_21( Vector<Real>& hv, const Vector<Real>& v,
232 const Vector<Real>& u, const Vector<Real>& z,
233 Real& tol ) override { hv.zero(); }
234
235 virtual void hessVec_22( Vector<Real>& hv, const Vector<Real>& v,
236 const Vector<Real>& u, const Vector<Real>& z,
237 Real& tol ) override { hv.zero(); }
238
239} // namespace ROL
240
241
242#endif // ROL_OBJECTIVE_TIMESIMOPT_HPP
243
VectorWorkspace< Real > workspace_
Provides the interface to evaluate simulation-based objective functions.
Defines the time-dependent objective function interface for simulation-based optimization....
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....
Vector< Real > & getVector(Vector< Real > &x) const
VectorWorkspace< Real > & getVectorWorkspace() const
const Vector< Real > & getVector(const Vector< Real > &x) const
Defines the linear algebra of vector space on a generic partitioned vector.
Defines the linear algebra or vector space interface.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void zero()
Set to zero vector.
ROL::Objective_SerialSimOpt Objective_SimOpt value(const V &u, const V &z, Real &tol) override
virtual void hessVec_12(V &hv, const V &v, const V &u, const V &z, Real &tol) override
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,...
virtual void gradient_2(V &g, const V &u, const V &z, Real &tol) override
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
virtual void hessVec_21(V &hv, const V &v, const V &u, const V &z, Real &tol) override
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 i...
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(V &hv, const V &v, 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
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
virtual void gradient_1(V &g, const V &u, const V &z, Real &tol) override
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_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)
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 i...
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.