ROL
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
20
31namespace ROL {
32template<typename Real>
34public:
35
36 using V = Vector<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
73protected:
74
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
86private:
87
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
112
113#endif // ROL_DYNAMICFUNCTION_HPP
114
Vector< Real > V
PartitionedVector< Real > PV
Provides update interface, casting and vector management to DynamicConstraint and DynamicObjective.
VectorWorkspace< Real > & getVectorWorkspace() const
virtual void update_uo(const V &x, const TS &ts)
void add_terms(const First &first)
bool is_zero_derivative(const std::string &key)
VectorWorkspace< Real > workspace_
void add_terms(const First &first, const Rest &... rest)
std::vector< std::string > zero_deriv_terms_
virtual void update_z(const V &x, const TS &ts)
DynamicFunction(std::initializer_list< std::string > zero_deriv_terms={})
virtual void update_un(const V &x, const TS &ts)
Defines the linear algebra of vector space on a generic partitioned vector.
Defines the linear algebra or vector space interface.
Contains local time step information.