2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
33 template <
typename T,
unsigned int N>
36 RK4Integrator(
Rates<T, N>& rate_calculator);
43 void step(T start_time, T end_time,
const std::array<T, N> &start_state, std::array<T, N> &out_state);
54 void configureForStep(T start_time, T end_time,
const std::array<T, N> &start_state);
61 void calculateK2(
const std::array<T, N> &state_in_k2, std::array<T, N> &state_for_k3);
65 void calculateK3(
const std::array<T, N> &state_in_k2, std::array<T, N> &state_for_k4);
68 void calculateK4(
const std::array<T, N> &state_in_k4);
81 std::array<T, N> _start_state;
90 template <
typename T,
unsigned int N>
95 _half_step_size = 0.0;
101 for(
unsigned int i = 0; i < N; i++) {
102 _start_state[i] = 0.0;
110 template <
typename T,
unsigned int N>
112 const std::array<T, N> &start_state) {
118 _end_time = end_time;
119 for(
unsigned int i = 0; i < N; i++) {
120 _start_state[i] = start_state[i];
124 template <
typename T,
unsigned int N>
130 for(
unsigned int i = 0; i < N; i++) {
131 state_for_k2[i] = _start_state[i] + _half_step_size*
_k1[i];
135 template <
typename T,
unsigned int N>
137 std::array<T, N> &state_for_k3) {
142 for(
unsigned int i = 0; i < N; i++) {
143 state_for_k3[i] = _start_state[i] + _half_step_size*_k2[i];
147 template <
typename T,
unsigned int N>
149 std::array<T, N> &state_for_k4) {
154 for(
unsigned int i = 0; i < N; i++) {
159 template <
typename T,
unsigned int N>
165 template <
typename T,
unsigned int N>
167 for(
unsigned int i = 0; i < N; i++) {
168 end_state[i] = _start_state[i] + _step_average*(
_k1[i] + 2.0*_k2[i] + 2.0*_k3[i] + _k4[i]);
172 template <
typename T,
unsigned int N>
174 const std::array<T, N> &start_state,
175 std::array<T, N> &out_state) {
This class is a base implementation of the integrator. It defines the basic functions and components ...
Definition Integrator.hpp:37
Definition RK4Integrator.hpp:34
void configureForStep(T start_time, T end_time, const std::array< T, N > &start_state)
Function to configure a full integration step.
Definition RK4Integrator.hpp:111
void getValueEndStep(std::array< T, N > &end_state)
Calculation of final integrated step at the end of state.
Definition RK4Integrator.hpp:166
void calculateK3(const std::array< T, N > &state_in_k2, std::array< T, N > &state_for_k4)
Function to calculate k3.
Definition RK4Integrator.hpp:148
T _start_time
Initial state tracking.
Definition RK4Integrator.hpp:79
void step(T start_time, T end_time, const std::array< T, N > &start_state, std::array< T, N > &out_state)
Function to take a full integrator step forward from time start to time end.
Definition RK4Integrator.hpp:173
void calculateK1(std::array< T, N > &state_for_k2)
Function to calculate k1.
Definition RK4Integrator.hpp:125
void calculateK4(const std::array< T, N > &state_in_k4)
Function to calculate k4.
Definition RK4Integrator.hpp:160
std::array< T, N > _k1
RK4 step rate values k1, k2, k3, k4 and var to calc average rate.
Definition RK4Integrator.hpp:84
T _full_step_size
Step size for integrator.
Definition RK4Integrator.hpp:74
void calculateK2(const std::array< T, N > &state_in_k2, std::array< T, N > &state_for_k3)
Function to calculate k2.
Definition RK4Integrator.hpp:136