libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_row6a.cc
Go to the documentation of this file.
1
2
3#include "ode_row6a.h"
4
5namespace ode {
6
7OdeROW6A::OdeROW6A (unsigned long neq) :
8 OdeAdaptive (neq, true),
9 OdeRosenbrock (neq, 6) {
10
11 method_ = "ROW6A";
12 //main diagonal, gam_ii
13 gam = 0.33414236706805043;
14
15 a21 = 0.66828473413610087;
16 a31 = 0.5852480389573658; a32 = -0.048594008221492802;
17 a41 = -0.61719233202999775; a42 = -0.83995264476522158; a43 = 0.62641917900148600;
18 a51 = 3.5406887484552165; a52 = 0.65991497772646308; a53 = -0.63661180895697222; a54 = -1.1945984675295562;
19 a61 = 0.80783664328582613; a62 = 0.10194631616818569; a63 = -0.078396778850607012; a64 = -0.044341977375427388; a65 = 0.013074732797453325;
20
21 c21 = -5.8308828523185086;
22 c31 = -4.0175939515896193; c32 = 0.43970131925236112;
23 c41 = 7.7228006257490299; c42 = 4.3368108251435758; c43 = -2.8219574578033366;
24 c51 = -1.0516225114542007; c52 = -0.58853585181331353; c53 = 2.0433794587212771; c54 = 5.0098631723809151;
25 c61 = -6.7357785372199458; c62 = -0.53593889506199845; c63 = 0.38622517020810987; c64 = 0.21066472713931598; c65 = -0.053546655670373728;
26
27 m1 = 11.358660043232931; m2 = -6.9896898855829058; m3 = -4.5967580421042947; m4 = -3.7220984696531517; m5 = 0.96012685868421520; m6 = 12.953396234292936;
28}
29
30void OdeROW6A::step_ (double dt) {
31
32 unsigned long i;
33
34 //------------------------------------------------------------------
35 //first evaluate the Jacobian, do arithmetic, and LU factorize it
36
38 prep_jac(Jac_, neq_, dt, p_);
39
40 //------------------------------------------------------------------
41 //stage 1
42
43 ode_fun_(sol_, k_[0]);
44 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[0][i];
46
47 //------------------------------------------------------------------
48 //stage 2
49
50 //temporary solution vector for evaluating ode_fun
51 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + a21*k_[0][i];
52 //put new slope values into k vector temporarily
53 ode_fun_(soltemp_, k_[1]);
54 //compute right hand side of matrix equation
55 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[1][i] + c21*k_[0][i];
56 //solve the matrix equation
58
59 //------------------------------------------------------------------
60 //stage 3
61
62 //temporary solution vector for evaluating ode_fun
63 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + a31*k_[0][i]
64 + a32*k_[1][i];
65 //put new slope values into k vector temporarily
66 ode_fun_(soltemp_, k_[2]);
67 //compute right hand side of matrix equation
68 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[2][i] + c31*k_[0][i]
69 + c32*k_[1][i];
70 //solve the matrix equation
72
73 //------------------------------------------------------------------
74 //stage 4
75
76 //temporary solution vector for evaluating ode_fun
77 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + a41*k_[0][i]
78 + a42*k_[1][i]
79 + a43*k_[2][i];
80 //put new slope values into k vector temporarily
81 ode_fun_(soltemp_, k_[3]);
82 //compute right hand side of matrix equation
83 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[3][i] + c41*k_[0][i]
84 + c42*k_[1][i]
85 + c43*k_[2][i];
86 //solve the matrix equation
88
89 //------------------------------------------------------------------
90 //stage 5
91
92 //temporary solution vector for evaluating ode_fun
93 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + a51*k_[0][i]
94 + a52*k_[1][i]
95 + a53*k_[2][i]
96 + a54*k_[3][i];
97 //put new slope values into k vector temporarily
98 ode_fun_(soltemp_, k_[4]);
99 //compute right hand side of matrix equation
100 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[4][i] + c51*k_[0][i]
101 + c52*k_[1][i]
102 + c53*k_[2][i]
103 + c54*k_[3][i];
104 //solve the matrix equation
105 ode_solve_LU(Jac_, p_, rhs_, neq_, k_[4]);
106
107 //------------------------------------------------------------------
108 //stage 6
109
110 //temporary solution vector for evaluating ode_fun
111 for (i=0; i<neq_; i++) soltemp_[i] = sol_[i] + a61*k_[0][i]
112 + a62*k_[1][i]
113 + a63*k_[2][i]
114 + a64*k_[3][i]
115 + a65*k_[4][i];
116 //put new slope values into k vector temporarily
117 ode_fun_(soltemp_, k_[5]);
118 //compute right hand side of matrix equation
119 for (i=0; i<neq_; i++) rhs_[i] = dt*k_[5][i] + c61*k_[0][i]
120 + c62*k_[1][i]
121 + c63*k_[2][i]
122 + c64*k_[3][i]
123 + c65*k_[4][i];
124 //solve the matrix equation
125 ode_solve_LU(Jac_, p_, rhs_, neq_, k_[5]);
126
127 //------------------------------------------------------------------
128 //solution and embedded solution
129
130 for (i=0; i<neq_; i++)
131 sol_[i] = sol_[i] + (m1*k_[0][i]
132 + m2*k_[1][i]
133 + m3*k_[2][i]
134 + m4*k_[3][i]
135 + m5*k_[4][i]
136 + m6*k_[5][i]);
137}
138
139} // namespace ode
Base class implementing solver functions with adaptive time steps.
void ode_jac_(double *solin, double **Jout)
wrapper, calls ode_jac() and increments nJac;
Definition ode_base.cc:95
unsigned long neq_
number of equations in the system of ODEs
Definition ode_base.h:327
double ** Jac_
storage for the ODE system's Jacobian matrix, only allocated for the methods that need it
Definition ode_base.h:341
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
OdeROW6A(unsigned long neq)
constructs
Definition ode_row6a.cc:7
Base class for Rosenbrock methods.
void prep_jac(double **Jac, unsigned long n, double dt, int *p)
do necessary arithmetic with the Jacobian then lu factor it
int * p_
permutation array for LU factorization
double ** k_
stage derivatives
double * soltemp_
temporary sol vector
double * rhs_
right hand side of matrix equations
double gam
parameter multipying Jacobian or single diagonal gamma
void ode_solve_LU(double **LU, int *p, double *b, int n, double *out)
Solves a matrix equation where the matrix has already be crout LU decomposed.
Definition ode_linalg.cc:76