ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
function
dynamic
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"
14
#include "
ROL_ReducedDynamicObjective.hpp
"
15
#include "
ROL_PartitionedVector.hpp
"
16
17
namespace
ROL
18
{
19
20
template
<
typename
Real>
21
class
ReducedDynamicStationaryControlsObjectiveHook
22
{
23
public
:
24
ReducedDynamicStationaryControlsObjectiveHook
() {}
25
virtual
~ReducedDynamicStationaryControlsObjectiveHook
() {}
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>
43
class
ReducedDynamicStationaryControlsObjective
:
public
Objective
<Real>
44
{
45
public
:
46
using
size_type
=
typename
std::vector<Real>::size_type;
47
48
ReducedDynamicStationaryControlsObjective
(
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
{
55
x_dyn_
=
PartitionedVector<Real>::create
(*x,
Nt_
);
56
v_dyn_
=
PartitionedVector<Real>::create
(*x,
Nt_
);
57
g_dyn_
=
PartitionedVector<Real>::create
(x->dual(),
Nt_
);
58
}
59
60
virtual
~ReducedDynamicStationaryControlsObjective
() {}
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_
;
122
size_type
Nt_
;
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
ROL_PartitionedVector.hpp
ROL_ReducedDynamicObjective.hpp
ROL::PartitionedVector::create
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
Definition
ROL_PartitionedVector.hpp:244
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::ReducedDynamicObjective
Defines the reduced time-dependent objective function interface for simulation-based optimization.
Definition
ROL_ReducedDynamicObjective.hpp:46
ROL::ReducedDynamicStationaryControlsObjectiveHook
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:22
ROL::ReducedDynamicStationaryControlsObjectiveHook::preValue
virtual void preValue(const Vector< Real > &x) const =0
ROL::ReducedDynamicStationaryControlsObjectiveHook::postValue
virtual void postValue(Real val) const =0
ROL::ReducedDynamicStationaryControlsObjectiveHook::preGradient
virtual void preGradient(const Vector< Real > &x) const =0
ROL::ReducedDynamicStationaryControlsObjectiveHook::ReducedDynamicStationaryControlsObjectiveHook
ReducedDynamicStationaryControlsObjectiveHook()
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:24
ROL::ReducedDynamicStationaryControlsObjectiveHook::postGradient
virtual void postGradient(const Vector< Real > &g) const =0
ROL::ReducedDynamicStationaryControlsObjectiveHook::~ReducedDynamicStationaryControlsObjectiveHook
virtual ~ReducedDynamicStationaryControlsObjectiveHook()
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:25
ROL::ReducedDynamicStationaryControlsObjective::value
Real value(const Vector< Real > &x, Real &tol) override
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:79
ROL::ReducedDynamicStationaryControlsObjective::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:92
ROL::ReducedDynamicStationaryControlsObjective::x_dyn_
Ptr< PartitionedVector< Real > > x_dyn_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:124
ROL::ReducedDynamicStationaryControlsObjective::g_dyn_
Ptr< PartitionedVector< Real > > g_dyn_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:126
ROL::ReducedDynamicStationaryControlsObjective::ReducedDynamicStationaryControlsObjective
ReducedDynamicStationaryControlsObjective(const Ptr< ReducedDynamicObjective< Real > > &red_dyn_obj, const Ptr< Vector< Real > > &x, const size_type Nt, const Ptr< ReducedDynamicStationaryControlsObjectiveHook< Real > > &hook=nullPtr)
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:48
ROL::ReducedDynamicStationaryControlsObjective::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1) override
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:71
ROL::ReducedDynamicStationaryControlsObjective::hessVec
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:107
ROL::ReducedDynamicStationaryControlsObjective::v_dyn_
Ptr< PartitionedVector< Real > > v_dyn_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:125
ROL::ReducedDynamicStationaryControlsObjective::update
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:63
ROL::ReducedDynamicStationaryControlsObjective::size_type
typename std::vector< Real >::size_type size_type
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:46
ROL::ReducedDynamicStationaryControlsObjective::~ReducedDynamicStationaryControlsObjective
virtual ~ReducedDynamicStationaryControlsObjective()
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:60
ROL::ReducedDynamicStationaryControlsObjective::hook_
Ptr< ReducedDynamicStationaryControlsObjectiveHook< Real > > hook_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:123
ROL::ReducedDynamicStationaryControlsObjective::Nt_
size_type Nt_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:122
ROL::ReducedDynamicStationaryControlsObjective::red_dyn_obj_
Ptr< ReducedDynamicObjective< Real > > red_dyn_obj_
Definition
ROL_ReducedDynamicStationaryControlsObjective.hpp:121
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
ROL::Vector::axpy
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition
ROL_Vector.hpp:120
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
Generated by
1.17.0