libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_rk_4.cc
Go to the documentation of this file.
1
2
3#include "ode_rk_4.h"
4
5namespace ode {
6
7OdeRK4::OdeRK4 (unsigned long neq) :
8 OdeAdaptive (neq, false),
9 OdeRK (neq, 4),
10 OdeERK (neq) {
11
12 method_ = "RK4";
13 //tableau of coefficients
14 c2 = 1.0/2; a21 = c2;
15 c3 = 1.0/2; a32 = 1.0/2;
16 c4 = 1.0; a43 = 1.0;
17 b1 = 1.0/6; b2 = 1.0/3; b3 = 1.0/3; b4 = 1.0/6;
18}
19
20void OdeRK4::step_ (double dt) {
21
22 unsigned long i;
23
24 //------------------------------------------------------------------
25 ode_fun_(sol_, k_[0]);
26
27 //------------------------------------------------------------------
28 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*a21*k_[0][i];
29 ode_fun_(soltemp_, k_[1]);
30
31 //------------------------------------------------------------------
32 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*a32*k_[1][i];
33 ode_fun_(soltemp_, k_[2]);
34
35 //------------------------------------------------------------------
36 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + dt*a43*k_[2][i];
37 ode_fun_(soltemp_, k_[3]);
38
39 //------------------------------------------------------------------
40 for (i=0; i<neq_; i++) sol_[i] += dt*(b1*k_[0][i]
41 + b2*k_[1][i]
42 + b3*k_[2][i]
43 + b4*k_[3][i]);
44}
45
46} // namespace ode
Base class implementing solver functions with adaptive time steps.
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
OdeRK4(unsigned long neq)
constructs
Definition ode_rk_4.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