ROL
ROL_Objective_SerialSimOpt.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 
45 #pragma once
46 #ifndef ROL_OBJECTIVE_SERIALSIMOPT_HPP
47 #define ROL_OBJECTIVE_SERIALSIMOPT_HPP
48 
50 
51 namespace ROL {
52 
53 template<typename Real>
55 
56  using V = Vector<Real>;
59 
60  using size_type = typename PV<Real>::size_type;
61 
62 private:
63 
64  const Ptr<Obj> obj_;
65  const Ptr<V> ui_; // Initial condition
66 
67  VectorWorkspace<Real> workspace_; // Memory management
68 
69 
70 protected:
71 
72  PV& partition( V& x ) const { return static_cast<PV&>(x); }
73 
74  const PV& partition( const V& x ) const { return static_cast<const PV&>(x); }
75 
76 public:
77 
78  Objective_SerialSimOpt( const Ptr<Obj>& obj, const V& ui ) :
79  obj_(obj),
80  ui_( workspace_.copy( ui ) ),
81  u0_->zero(); z0_->zero();
82  }
83 
84 
85  virtual Real value( const V& u, const V& z, Real& tol ) override {
86 
87  auto& up = partition(u);
88  auto& zp = partition(z);
89 
90  // First step
91  Real result = obj_->value( *ui_, *(up.get(0)), *(zp.get(0)), tol );
92 
93  for( size_type k=1; k<up.numVector(); ++k ) {
94  result += obj_->value( *(up.get(k-1), *(up.get(k)), *(zp.get(k)), tol );
95  }
96  return result;
97  }
98 
99  virtual void gradient_1( V& g, const V &u, const V& z, Real& tol ) override {
100 
101  auto& up = partition(u);
102  auto& zp = partition(z);
103  auto& gp = partition(g);
104 
105  // First step
106  obj_->gradient_1( *(gp.get(0)), *ui_, *ui_, *(up.get(0)), *(zp.get(0)), tol );
107 
108  for( size_type k=1; k<up.numVector(); ++k ) {
109  obj_->gradient_1( *(gp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
110  }
111  }
112 
113  virtual void gradient_2( V& g, const V& u, const V& z, Real& tol ) override {
114 
115  auto& up = partition(u);
116  auto& zp = partition(z);
117  auto& gp = partition(g);
118 
119  // First step
120  obj_->gradient_2( *(gp.get(0)), *ui_, *ui_, *(up.get(0)), *(zp.get(0)), tol );
121 
122  for( size_type k=1; k<up.numVector(); ++k ) {
123  obj_->gradient_2( *(gp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
124  }
125  }
126 
127  virtual void hessVec_11( V& hv, const V& v,
128  const V& u, const V& z, Real& tol ) override {
129 
130  auto& hvp = partition(hv);
131  auto& vp = partition(v);
132  auto& up = partition(u);
133  auto& zp = partition(z);
134  auto& gp = partition(g);
135 
136  // First step
137  obj_->hessVec_11( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
139  for( size_type k=1; k<up.numVector(); ++k ) {
140  obj_->hessVec_11( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
141  }
142  }
143 
144  virtual void hessVec_12( V& hv, const V& v, const V&u, const V&z, Real &tol ) override {
145 
146  auto& hvp = partition(hv);
147  auto& vp = partition(v);
148  auto& up = partition(u);
149  auto& zp = partition(z);
150  auto& gp = partition(g);
151 
152  // First step
153  obj_->hessVec_12( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
155  for( size_type k=1; k<up.numVector(); ++k ) {
156  obj_->hessVec_12( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
157  }
158  }
159 
160  virtual void hessVec_21( V&hv, const V&v, const V&u, const V&z, Real &tol ) override {
161 
162  auto& hvp = partition(hv);
163  auto& vp = partition(v);
164  auto& up = partition(u);
165  auto& zp = partition(z);
166  auto& gp = partition(g);
167 
168  // First step
169  obj_->hessVec_21( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
170 
171  for( size_type k=1; k<up.numVector(); ++k ) {
172  obj_->hessVec_21( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
173  }
174  }
175 
176  virtual void hessVec_22( V&hv, const V&v, const V&u, const V&z, Real &tol ) override {
177 
178  auto& hvp = partition(hv);
179  auto& vp = partition(v);
180  auto& up = partition(u);
181  auto& zp = partition(z);
182  auto& gp = partition(g);
183 
184  // First step
185  obj_->hessVec_22( *(hvp.get(0)), *(vp.get(0)), *ui_, *(up.get(0)), *(zp.get(0)), tol );
186 
187  for( size_type k=1; k<up.numVector(); ++k ) {
188  obj_->hessVec_22( *(hvp.get(k)), *(vp.get(k)), *(up.get(k-1)), *(up.get(k)), *(zp.get(k)), tol );
189  }
190  }
191 
192 }; // class Objective_SerialSimOpt
193 
194 } // namespace ROL
195 
196 
197 #endif // ROL_OBJECTIVE_SERIALSIMOPT_HPP
198 
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:80
virtual void gradient_2(V &g, const V &u, const V &z, Real &tol) override
Vector< Real > V
PV & partition(V &x) const
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