autogenu-jupyter
An automatic code generator and the continuation/GMRES (C/GMRES) based numerical solvers for nonlinear MPC
Loading...
Searching...
No Matches
control_input_bounds_shooting.hpp
Go to the documentation of this file.
1#ifndef CGMRES__CONTROL_INPUT_BOUNDS_SHOOTING_HPP_
2#define CGMRES__CONTROL_INPUT_BOUNDS_SHOOTING_HPP_
3
4#include <array>
5
6#include "cgmres/types.hpp"
7
10
11namespace cgmres {
12namespace detail {
13namespace ubounds {
14
15template <typename OCP, int N>
16void eval_fonc_hu(const OCP& ocp, const Vector<OCP::nuc*N>& solution,
17 const std::array<Vector<OCP::nub>, N>& dummy,
18 const std::array<Vector<OCP::nub>, N>& mu,
19 Vector<OCP::nuc*N>& fonc_hu) {
20 if constexpr (OCP::nub > 0) {
21 constexpr int nuc = OCP::nuc;
22 for (size_t i=0; i<N; ++i) {
23 eval_hu(ocp, solution.template segment<nuc>(nuc*i), dummy[i], mu[i],
24 fonc_hu.template segment<nuc>(nuc*i));
25 }
26 }
27}
28
29template <typename OCP, int N>
30void eval_fonc_hdummy(const OCP& ocp, const Vector<OCP::nuc*N>& solution,
31 const std::array<Vector<OCP::nub>, N>& dummy,
32 const std::array<Vector<OCP::nub>, N>& mu,
33 std::array<Vector<OCP::nub>, N>& fonc_hdummy) {
34 if constexpr (OCP::nub > 0) {
35 constexpr int nuc = OCP::nuc;
36 for (size_t i=0; i<N; ++i) {
37 eval_hdummy(ocp, solution.template segment<nuc>(nuc*i), dummy[i], mu[i],
38 fonc_hdummy[i]);
39 }
40 }
41}
42
43template <typename OCP, int N>
44void eval_fonc_hmu(const OCP& ocp, const Vector<OCP::nuc*N>& solution,
45 const std::array<Vector<OCP::nub>, N>& dummy,
46 const std::array<Vector<OCP::nub>, N>& mu,
47 std::array<Vector<OCP::nub>, N>& fonc_hmu) {
48 if constexpr (OCP::nub > 0) {
49 constexpr int nuc = OCP::nuc;
50 for (size_t i=0; i<N; ++i) {
51 eval_hmu(ocp, solution.template segment<nuc>(nuc*i), dummy[i], mu[i],
52 fonc_hmu[i]);
53 }
54 }
55}
56
57template <typename OCP, int N>
58void multiply_hdummy_inv(const std::array<Vector<OCP::nub>, N>& dummy,
59 const std::array<Vector<OCP::nub>, N>& mu,
60 const std::array<Vector<OCP::nub>, N>& fonc_hdummy,
61 const std::array<Vector<OCP::nub>, N>& fonc_hmu,
62 std::array<Vector<OCP::nub>, N>& fonc_hdummy_inv) {
63 if constexpr (OCP::nub > 0) {
64 for (size_t i=0; i<N; ++i) {
65 multiply_hdummy_inv(dummy[i], mu[i], fonc_hdummy[i], fonc_hmu[i],
66 fonc_hdummy_inv[i]);
67 }
68 }
69}
70
71template <typename OCP, int N>
72void multiply_hmu_inv(const std::array<Vector<OCP::nub>, N>& dummy,
73 const std::array<Vector<OCP::nub>, N>& mu,
74 const std::array<Vector<OCP::nub>, N>& fonc_hdummy,
75 const std::array<Vector<OCP::nub>, N>& fonc_hmu,
76 const std::array<Vector<OCP::nub>, N>& fonc_hdummy_inv,
77 std::array<Vector<OCP::nub>, N>& fonc_hmu_inv) {
78 if constexpr (OCP::nub > 0) {
79 for (size_t i=0; i<N; ++i) {
80 multiply_hmu_inv(dummy[i], mu[i], fonc_hdummy[i], fonc_hmu[i],
81 fonc_hdummy_inv[i], fonc_hmu_inv[i]);
82 }
83 }
84}
85
86template <typename OCP, int N>
87void retrive_dummy_update(const OCP& ocp,
88 const Vector<OCP::nuc*N>& solution,
89 const std::array<Vector<OCP::nub>, N>& dummy,
90 const std::array<Vector<OCP::nub>, N>& mu,
91 const Vector<OCP::nuc*N>& solution_update,
92 std::array<Vector<OCP::nub>, N>& dummy_update) {
93 if constexpr (OCP::nub > 0) {
94 constexpr int nuc = OCP::nuc;
95 for (size_t i=0; i<N; ++i) {
96 retrive_dummy_update(ocp, solution.template segment<nuc>(nuc*i), dummy[i], mu[i],
97 solution_update.template segment<nuc>(nuc*i), dummy_update[i]);
98 }
99 }
100}
101
102template <typename OCP, int N>
103void retrive_mu_update(const OCP& ocp,
104 const Vector<OCP::nuc*N>& solution,
105 const std::array<Vector<OCP::nub>, N>& dummy,
106 const std::array<Vector<OCP::nub>, N>& mu,
107 const Vector<OCP::nuc*N>& solution_update,
108 std::array<Vector<OCP::nub>, N>& mu_update) {
109 if constexpr (OCP::nub > 0) {
110 constexpr int nuc = OCP::nuc;
111 for (size_t i=0; i<N; ++i) {
112 retrive_mu_update(ocp, solution.template segment<nuc>(nuc*i), dummy[i], mu[i],
113 solution_update.template segment<nuc>(nuc*i), mu_update[i]);
114 }
115 }
116}
117
118template <typename OCP, int N>
119void clip_dummy(std::array<Vector<OCP::nub>, N>& dummy, const Scalar min) {
120 if constexpr (OCP::nub > 0) {
121 for (size_t i=0; i<N; ++i) {
122 clip_dummy(dummy[i], min);
123 }
124 }
125}
126
127} // namespace ubounds
128} // namespace detail
129} // namespace cgmres
130
131#endif // CGMRES__CONTROL_INPUT_BOUNDS_SHOOTING_HPP_
void retrive_mu_update(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &u_update, const MatrixBase< VectorType5 > &mu_udpate)
Definition: control_input_bounds.hpp:107
void retrive_dummy_update(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &u_update, const MatrixBase< VectorType5 > &dummy_update)
Definition: control_input_bounds.hpp:88
void clip_dummy(const MatrixBase< VectorType > &dummy, const Scalar min)
Definition: control_input_bounds.hpp:127
void eval_hmu(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hmu)
Definition: control_input_bounds.hpp:47
void multiply_hmu_inv(const MatrixBase< VectorType1 > &dummy, const MatrixBase< VectorType2 > &mu, const MatrixBase< VectorType3 > &hdummy, const MatrixBase< VectorType4 > &hmu, const MatrixBase< VectorType5 > &hdummy_multiplied, const MatrixBase< VectorType6 > &hmu_multiplied)
Definition: control_input_bounds.hpp:77
void eval_fonc_hmu(const OCP &ocp, const Vector< OCP::nuc *N > &solution, const std::array< Vector< OCP::nub >, N > &dummy, const std::array< Vector< OCP::nub >, N > &mu, std::array< Vector< OCP::nub >, N > &fonc_hmu)
Definition: control_input_bounds_shooting.hpp:44
void multiply_hdummy_inv(const MatrixBase< VectorType1 > &dummy, const MatrixBase< VectorType2 > &mu, const MatrixBase< VectorType3 > &hdummy, const MatrixBase< VectorType4 > &hmu, const MatrixBase< VectorType5 > &hdummy_multiplied)
Definition: control_input_bounds.hpp:67
void eval_fonc_hdummy(const OCP &ocp, const Vector< OCP::nuc *N > &solution, const std::array< Vector< OCP::nub >, N > &dummy, const std::array< Vector< OCP::nub >, N > &mu, std::array< Vector< OCP::nub >, N > &fonc_hdummy)
Definition: control_input_bounds_shooting.hpp:30
void eval_fonc_hu(const OCP &ocp, const Vector< OCP::nuc *N > &solution, const std::array< Vector< OCP::nub >, N > &dummy, const std::array< Vector< OCP::nub >, N > &mu, Vector< OCP::nuc *N > &fonc_hu)
Definition: control_input_bounds_shooting.hpp:16
void eval_hdummy(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hdummy)
Definition: control_input_bounds.hpp:32
void eval_hu(const OCP &ocp, const MatrixBase< VectorType1 > &u, const MatrixBase< VectorType2 > &dummy, const MatrixBase< VectorType3 > &mu, const MatrixBase< VectorType4 > &hu)
Definition: control_input_bounds.hpp:15
Definition: continuation_gmres.hpp:11
Eigen::Matrix< Scalar, size, 1 > Vector
Alias of Eigen::Vector.
Definition: types.hpp:23
double Scalar
Alias of double.
Definition: types.hpp:11