ROL
ROL_ReducedDynamicStationaryControlsObjective.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 #ifndef ROL_REDUCEDDYNAMICSTATIONARYCONTROLSOBJECTIVE_HPP
11 #define ROL_REDUCEDDYNAMICSTATIONARYCONTROLSOBJECTIVE_HPP
12 
13 #include "ROL_Ptr.hpp"
16 
17 namespace ROL
18 {
19 
20 template <typename Real>
22 {
23 public:
26  virtual void
27  preValue(const Vector<Real> &x) const = 0;
28  virtual void
29  postValue(Real val) const = 0;
30  virtual void
31  preGradient(const Vector<Real> &x) const = 0;
32  virtual void
33  postGradient(const Vector<Real> &g) const = 0;
34 };
35 
42 template <typename Real>
44 {
45 public:
47 
49  const Ptr<ReducedDynamicObjective<Real>> &red_dyn_obj,
50  const Ptr<Vector<Real>> &x,
51  const size_type Nt,
52  const Ptr<ReducedDynamicStationaryControlsObjectiveHook<Real>> &hook = nullPtr)
53  : red_dyn_obj_(red_dyn_obj), Nt_(Nt), hook_(hook)
54  {
58  }
59 
61 
62  void
63  update( const Vector<Real> &x, UpdateType type, int iter = -1 ) override
64  {
65  for (size_type i = 0; i < Nt_; ++i)
66  (*x_dyn_)[i].set(x);
67  red_dyn_obj_->update(*x_dyn_, true, iter);
68  }
69 
70  void
71  update(const Vector<Real> &x, bool flag = true, int iter = -1) override
72  {
73  for (size_type i = 0; i < Nt_; ++i)
74  (*x_dyn_)[i].set(x);
75  red_dyn_obj_->update(*x_dyn_, flag, iter);
76  }
77 
78  Real
79  value(const Vector<Real> &x, Real &tol) override
80  {
81  if (hook_ != nullPtr)
82  hook_->preValue(x);
83  for (size_type i = 0; i < Nt_; ++i)
84  (*x_dyn_)[i].set(x);
85  Real val = red_dyn_obj_->value(*x_dyn_, tol);
86  if (hook_ != nullPtr)
87  hook_->postValue(val);
88  return val;
89  }
90 
91  void
92  gradient(Vector<Real> &g, const Vector<Real> &x, Real &tol) override
93  {
94  if (hook_ != nullPtr)
95  hook_->preGradient(x);
96  for (size_type i = 0; i < Nt_; ++i)
97  (*x_dyn_)[i].set(x);
98  red_dyn_obj_->gradient(*g_dyn_, *x_dyn_, tol);
99  g.zero();
100  for (size_type i = 0; i < Nt_; ++i)
101  g.axpy(1.0, (*g_dyn_)[i]);
102  if (hook_ != nullPtr)
103  hook_->postGradient(g);
104  }
105 
106  void
107  hessVec(Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol) override
108  {
109  for (size_type i = 0; i < Nt_; ++i)
110  {
111  (*x_dyn_)[i].set(x);
112  (*v_dyn_)[i].set(v);
113  }
114  red_dyn_obj_->hessVec(*g_dyn_, *v_dyn_, *x_dyn_, tol);
115  hv.zero();
116  for (size_type i = 0; i < Nt_; ++i)
117  hv.axpy(1.0, (*g_dyn_)[i]);
118  }
119 
120 private:
121  Ptr<ReducedDynamicObjective<Real>> red_dyn_obj_;
123  Ptr<ReducedDynamicStationaryControlsObjectiveHook<Real>> hook_;
124  Ptr<PartitionedVector<Real>> x_dyn_;
125  Ptr<PartitionedVector<Real>> v_dyn_;
126  Ptr<PartitionedVector<Real>> g_dyn_;
127 };
128 } // namespace ROL
129 
130 #endif
Provides the interface to evaluate objective functions.
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
typename PV< Real >::size_type size_type
virtual void preGradient(const Vector< Real > &x) const =0
Defines the reduced time-dependent objective function interface for simulation-based optimization...
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void postGradient(const Vector< Real > &g) const =0
Ptr< ReducedDynamicStationaryControlsObjectiveHook< Real > > hook_
virtual void preValue(const Vector< Real > &x) const =0
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
virtual void postValue(Real val) const =0
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
Defines the reduced time-dependent objective function interface for simulation-based optimization whe...
void update(const Vector< Real > &x, bool flag=true, int iter=-1) override
Update objective function.
ReducedDynamicStationaryControlsObjective(const Ptr< ReducedDynamicObjective< Real >> &red_dyn_obj, const Ptr< Vector< Real >> &x, const size_type Nt, const Ptr< ReducedDynamicStationaryControlsObjectiveHook< Real >> &hook=nullPtr)
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.