discretization_runge_kutta_alias.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef DISCRETIZATION_RUNGE_KUTTA_ALIAS_HPP
34 #define DISCRETIZATION_RUNGE_KUTTA_ALIAS_HPP
35 
36 #include <float.h>
37 #include <memory>
38 #include <functional>
39 #include <tuw_control/utils.h>
40 
41 namespace tuw
42 {
43 class StateSim;
44 using StateSimPtr = std::shared_ptr<StateSim>;
45 
46 namespace RungeKutta
47 {
48 template <std::size_t StateNmSize, std::size_t RKOrder, typename... RKCoeff>
49 void discretize(StateSim& _stateSim, const double& _arc);
50 template <>
51 void discretize<0, 0>(StateSim& _stateSim, const double& _arc);
52 
53 using DiscretizationFuncPtr = void (*)(StateSim&, const double&);
54 
57 {
58  USER_DEF,
59  EULER,
60  HEUN,
61  RK4,
62  RK4_38
63 };
64 
67 template <std::size_t StateNmSize>
69 {
70  using Dtp = DiscretizationType;
71  switch (_discrType)
72  {
73  case (Dtp::USER_DEF):
74  return discretize<0, 0>;
75  break;
76 
77  case (Dtp::EULER):
78  return discretize<StateNmSize, 1, RatioEval<1, 1> >;
79  break;
80 
81  case (Dtp::HEUN):
82  return discretize<StateNmSize, 2, RatioEval<1, 2>, // ci values
83  RatioEval<0, 1>, RatioEval<1, 1>, // bj values
84  RatioEval<1, 2> // aij values
85  >;
86  break;
87 
88  case (Dtp::RK4):
89  return discretize<StateNmSize, 4, RatioEval<1, 2>, RatioEval<1, 2>, RatioEval<1, 1>, // ci
90  RatioEval<1, 6>, RatioEval<1, 3>, RatioEval<1, 3>, RatioEval<1, 6>, // bj
91  RatioEval<1, 2>, RatioEval<0, 1>, RatioEval<1, 2>, RatioEval<0, 1>, RatioEval<0, 1>,
92  RatioEval<1, 1> // aij
93  >;
94  break;
95 
96  case (Dtp::RK4_38):
97  return discretize<StateNmSize, 4, RatioEval<1, 3>, RatioEval<2, 3>, RatioEval<1, 1>, // ci
98  RatioEval<1, 8>, RatioEval<3, 8>, RatioEval<3, 8>, RatioEval<1, 8>, // bj
99  RatioEval<1, 3>, RatioEval<-1, 3>, RatioEval<1, 1>, RatioEval<1, 1>, RatioEval<-1, 1>,
100  RatioEval<1, 1> // aij
101  >;
102  break;
103  }
104  return nullptr;
105 }
106 }
107 }
108 
109 #endif // DISCRETIZATION_RUNGE_KUTTA_ALIAS_HPP
void discretize(StateSim &_stateSim, const double &_arc)
Templetized generic discretization function.
void discretize< 0, 0 >(StateSim &_stateSim, const double &_arc)
Specialization for using a user-defined discretization function.
DiscretizationType
Several discretization modes.
DiscretizationFuncPtr getDiscrFunc(DiscretizationType _discrType)
Returns a discretization function pointer for pre-defined Runge-Kutta specializations defined in Disc...
std::shared_ptr< StateSim > StateSimPtr
Interface for a state simulator structure that performs numerical integration of not-closed-form stat...
Definition: state_sim.h:58
void(*)(StateSim &, const double &) DiscretizationFuncPtr


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:21