libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_rkck.cc
Go to the documentation of this file.
1
2
3#include "ode_rkck.h"
4
5namespace ode {
6
7OdeRKCK::OdeRKCK (unsigned long neq) :
8 OdeEmbedded (neq, false, 4),
9 OdeRK (neq, 6),
10 OdeERK (neq) {
11
12 method_ = "RKCK";
13 //coefficents of tableau
14 c2 = 1.0/5; a21 = 1.0/5;
15 c3 = 3.0/10; a31 = 3.0/40; a32 = 9.0/40;
16 c4 = 3.0/5; a41 = 3.0/10; a42 = -9.0/10; a43 = 6.0/5;
17 c5 = 1.0; a51 = -11.0/54; a52 = 5.0/2; a53 = -70.0/27; a54 = 35.0/27;
18 c6 = 7.0/8; a61 = 1631.0/55296; a62 = 175.0/512; a63 = 575.0/13824; a64 = 44275.0/110592; a65 = 253.0/4096;
19 b1 = 37.0/378; b3 = 250.0/621; b4 = 125.0/594; b6 = 512.0/1771;
20 d1 = 2825.0/27648; d3 = 18575.0/48384; d4 = 13525.0/55296; d5 = 277.0/14336; d6 = 1.0/4;
21 e1 = 19.0/54; e3 = -10.0/27; e4 = 55.0/54;
22 f1 = -3.0/2; f2 = 5.0/2;
23 g1 = 1.0;
24}
25
26void OdeRKCK::step_ (double dt) {
27
28 unsigned long i;
29
30 //------------------------------------------------------------------
31 ode_fun_(sol_, k_[0]);
32
33 //------------------------------------------------------------------
34 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*a21*k_[0][i];
35 ode_fun_(soltemp_, k_[1]);
36
37 //------------------------------------------------------------------
38 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*(a31*k_[0][i]
39 + a32*k_[1][i]);
40 ode_fun_(soltemp_, k_[2]);
41
42 //------------------------------------------------------------------
43 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*(a41*k_[0][i]
44 + a42*k_[1][i]
45 + a43*k_[2][i]);
46 ode_fun_(soltemp_, k_[3]);
47
48 //------------------------------------------------------------------
49 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*(a51*k_[0][i]
50 + a52*k_[1][i]
51 + a53*k_[2][i]
52 + a54*k_[3][i]);
53 ode_fun_(soltemp_, k_[4]);
54
55 //------------------------------------------------------------------
56 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*(a61*k_[0][i]
57 + a62*k_[1][i]
58 + a63*k_[2][i]
59 + a64*k_[3][i]
60 + a65*k_[4][i]);
61 ode_fun_(soltemp_, k_[5]);
62
63 //------------------------------------------------------------------
64 for (i=0; i<neq_; i++) {
65 solemb_[i] = sol_[i] + dt*(d1*k_[0][i]
66 + d3*k_[2][i]
67 + d4*k_[3][i]
68 + d5*k_[4][i]
69 + d6*k_[5][i]);
70 sol_[i] = sol_[i] + dt*(b1*k_[0][i]
71 + b3*k_[2][i]
72 + b4*k_[3][i]
73 + b6*k_[5][i]);
74 }
75}
76
77} // namespace ode
unsigned long neq_
number of equations in the system of ODEs
Definition ode_base.h:327
std::string method_
the "name" of the solver/method, as in "Euler" or "RK4"
Definition ode_base.h:319
double * sol_
array for the solution, changing over time
Definition ode_base.h:333
void ode_fun_(double *solin, double *fout)
wrapper, calls ode_fun() and increases the neval counter by one
Definition ode_base.cc:87
Base class providing space for temporary solutions moving through RK stages.
Definition ode_erk.h:9
double * soltemp_
temporary solution vector
Definition ode_erk.h:22
Base clase implementing methods for embedded Runge-Kutta error estimation.
double * solemb_
embedded solution array
OdeRKCK(unsigned long neq)
constructs
Definition ode_rkck.cc:7
Provides space for stage slope values, an array of arrays for k values.
Definition ode_rk.h:9
double ** k_
stage evaluations
Definition ode_rk.h:23