ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
function
dynamic
ROL_DynamicFunction.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_DYNAMICFUNCTION_HPP
12
#define ROL_DYNAMICFUNCTION_HPP
13
14
#include <initializer_list>
15
16
#include "
ROL_TimeStamp.hpp
"
17
18
#include "
ROL_PartitionedVector.hpp
"
19
#include "
ROL_VectorWorkspace.hpp
"
20
31
namespace
ROL
{
32
template
<
typename
Real>
33
class
DynamicFunction
{
34
public
:
35
36
using
V
=
Vector<Real>
;
37
using
PV
=
PartitionedVector<Real>
;
38
using
TS
=
TimeStamp<Real>
;
39
40
DynamicFunction
( std::initializer_list<std::string> zero_deriv_terms={} ) :
41
zero_deriv_terms_
(zero_deriv_terms) {
42
43
if
(
is_zero_derivative
(
"uo"
) )
add_terms
(
"uo_uo"
,
"uo_un"
,
"uo_z"
);
44
if
(
is_zero_derivative
(
"un"
) )
add_terms
(
"un_uo"
,
"un_un"
,
"un_z"
);
45
if
(
is_zero_derivative
(
"z"
) )
add_terms
(
"z_uo"
,
"z_un"
,
"z_z"
);
46
if
(
is_zero_derivative
(
"uo_un"
) )
add_terms
(
"un_uo"
);
47
if
(
is_zero_derivative
(
"uo_z"
) )
add_terms
(
"z_uo"
);
48
if
(
is_zero_derivative
(
"un_z"
) )
add_terms
(
"z_un"
);
49
if
(
is_zero_derivative
(
"un_uo"
) )
add_terms
(
"uo_un"
);
50
if
(
is_zero_derivative
(
"z_uo"
) )
add_terms
(
"uo_z"
);
51
if
(
is_zero_derivative
(
"z_un"
) )
add_terms
(
"un_z"
);
52
53
}
54
55
virtual
~DynamicFunction
() {}
56
57
// Update old state
58
virtual
void
update_uo
(
const
V
& x,
const
TS
& ts ) {}
59
60
// Update new state
61
virtual
void
update_un
(
const
V
& x,
const
TS
& ts ) {}
62
63
// Update control
64
virtual
void
update_z
(
const
V
& x,
const
TS
& ts ) {}
65
66
bool
is_zero_derivative
(
const
std::string& key ) {
67
return
std::find( std::begin(
zero_deriv_terms_
),
68
std::end(
zero_deriv_terms_
),
69
key ) != std::end(
zero_deriv_terms_
);
70
}
71
72
73
protected
:
74
75
VectorWorkspace<Real>
&
getVectorWorkspace
()
const
;
76
77
PV
&
partition
(
V
& x )
const
;
78
const
PV
&
partition
(
const
V
& x )
const
;
79
80
V
&
getNew
(
V
& x )
const
;
81
const
V
&
getNew
(
const
V
& x )
const
;
82
83
V
&
getOld
(
V
& x )
const
;
84
const
V
&
getOld
(
const
V
& x )
const
;
85
86
private
:
87
88
mutable
VectorWorkspace<Real>
workspace_
;
89
std::vector<std::string>
zero_deriv_terms_
;
90
91
template
<
typename
First>
92
void
add_terms
(
const
First& first ) {
93
if
( !
is_zero_derivative
(first) )
94
zero_deriv_terms_
.push_back(first);
95
}
96
97
template
<
typename
First,
typename
...Rest>
98
void
add_terms
(
const
First& first,
const
Rest&... rest ) {
99
if
( !
is_zero_derivative
(first) )
100
zero_deriv_terms_
.push_back(first);
101
add_terms
(rest...);
102
}
103
104
};
105
106
107
}
// namespace ROL
108
109
110
111
#include "
ROL_DynamicFunctionDef.hpp
"
112
113
#endif
// ROL_DYNAMICFUNCTION_HPP
114
V
Vector< Real > V
Definition
ROL_BlockOperator2Diagonal.hpp:46
PV
PartitionedVector< Real > PV
Definition
ROL_BlockOperator2Diagonal.hpp:47
ROL_DynamicFunctionDef.hpp
ROL_PartitionedVector.hpp
ROL_TimeStamp.hpp
ROL_VectorWorkspace.hpp
ROL::DynamicFunction::getOld
V & getOld(V &x) const
Definition
ROL_DynamicFunctionDef.hpp:47
ROL::DynamicFunction::getVectorWorkspace
VectorWorkspace< Real > & getVectorWorkspace() const
Definition
ROL_DynamicFunctionDef.hpp:19
ROL::DynamicFunction::update_uo
virtual void update_uo(const V &x, const TS &ts)
Definition
ROL_DynamicFunction.hpp:58
ROL::DynamicFunction::~DynamicFunction
virtual ~DynamicFunction()
Definition
ROL_DynamicFunction.hpp:55
ROL::DynamicFunction::PV
PartitionedVector< Real > PV
Definition
ROL_DynamicFunction.hpp:37
ROL::DynamicFunction::add_terms
void add_terms(const First &first)
Definition
ROL_DynamicFunction.hpp:92
ROL::DynamicFunction::is_zero_derivative
bool is_zero_derivative(const std::string &key)
Definition
ROL_DynamicFunction.hpp:66
ROL::DynamicFunction::TS
TimeStamp< Real > TS
Definition
ROL_DynamicFunction.hpp:38
ROL::DynamicFunction::workspace_
VectorWorkspace< Real > workspace_
Definition
ROL_DynamicFunction.hpp:88
ROL::DynamicFunction::partition
PV & partition(V &x) const
Definition
ROL_DynamicFunctionDef.hpp:23
ROL::DynamicFunction::add_terms
void add_terms(const First &first, const Rest &... rest)
Definition
ROL_DynamicFunction.hpp:98
ROL::DynamicFunction::zero_deriv_terms_
std::vector< std::string > zero_deriv_terms_
Definition
ROL_DynamicFunction.hpp:89
ROL::DynamicFunction::update_z
virtual void update_z(const V &x, const TS &ts)
Definition
ROL_DynamicFunction.hpp:64
ROL::DynamicFunction::V
Vector< Real > V
Definition
ROL_DynamicFunction.hpp:36
ROL::DynamicFunction::getNew
V & getNew(V &x) const
Definition
ROL_DynamicFunctionDef.hpp:35
ROL::DynamicFunction::DynamicFunction
DynamicFunction(std::initializer_list< std::string > zero_deriv_terms={})
Definition
ROL_DynamicFunction.hpp:40
ROL::DynamicFunction::update_un
virtual void update_un(const V &x, const TS &ts)
Definition
ROL_DynamicFunction.hpp:61
ROL::PartitionedVector
Defines the linear algebra of vector space on a generic partitioned vector.
Definition
ROL_PartitionedVector.hpp:26
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::details::VectorWorkspace
Definition
ROL_VectorWorkspace.hpp:64
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::TimeStamp
Contains local time step information.
Definition
ROL_TimeStamp.hpp:35
Generated by
1.17.0