libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_geng_5.cc
Go to the documentation of this file.
1
2
3#include "ode_geng_5.h"
4
5namespace ode {
6
7void NewtonGeng5::f_Newton (double *x, double *y) {
8
9 (void)x; //supress unused variable warning
10 unsigned long i;
11 int j,n;
12 double dt = *dt_; //get time step from solver object
13
14 for (n=0; n<nk_; n++) {
15 //evaluate temporary solution based on current k values
16 for (i=0; i<neq_; i++) {
17 soltemp_[i] = sol_[i];
18 for (j=0; j<nk_; j++) soltemp_[i] += dt*a[n][j]*k_[j][i];
19 }
20 //compute k1 values
22 //evaluate the Newton function's k1 component
23 for (i=0; i<neq_; i++) y[i+n*neq_] = k_[n][i] - ftemp_[i];
24 }
25}
26
27void NewtonGeng5::J_Newton (double *x, double **J) {
28
29 (void)x; //supress unused variable warning
30 unsigned long i,j;
31 int m,n;
32 double dt = *dt_; //get time step from solver object
33
34 if ( get_modified() ) jac(sol_, Jac_);
35
36 for (n=0; n<nk_; n++) {
37 if ( !get_modified() ) {
38 //evaluate temporary solution based on current k values for k1
39 for (i=0; i<neq_; i++) {
40 soltemp_[i] = sol_[i];
41 for (m=0; m<nk_; m++) soltemp_[i] += dt*a[n][m]*k_[m][i];
42 }
43 //evaluate J at soltemp
45 }
46 //evaluate the Newton jacobian
47 for (i=0; i<neq_; i++) {
48 for (j=0; j<neq_; j++) {
49 for (m=0; m<nk_; m++) {
50 J[i+n*neq_][j+m*neq_] = -dt*a[n][m]*Jac_[i][j];
51 }
52 }
53 J[i+n*neq_][i+n*neq_] += 1.0; //subtract from the identity matrix
54 }
55 }
56}
57
58//------------------------------------------------------------------------------
59
60OdeGeng5::OdeGeng5 (unsigned long neq) :
61 OdeAdaptive (neq, true),
62 OdeIRK (neq, 3) {
63
64 method_ = "Geng5";
65
66 int nk = 3;
67 a = new double*[nk];
68 for (int i=0; i<nk; i++) a[i] = new double[nk];
69 b = new double[nk];
70
71 double r = sqrt(6.0);
72
73 a[0][0] = (16 - r)/72; a[0][1] = (328 - 167*r)/1800; a[0][2] = (-2 + 3*r)/450;
74 a[1][0] = (328 + 167*r)/1800; a[1][1] = (16 + r)/72; a[1][2] = (-2 - 3*r)/450;
75 a[2][0] = (85 - 10*r)/180; a[2][1] = (85 + 10*r)/180; a[2][2] = 1.0/18;
76 b[0] = (16 - r)/36; b[1] = (16 + r)/36; b[2] = 1.0/9;
77
78 newton_ = new NewtonGeng5(neq, nk, this);
79 newton_->set_modified(true);
80}
81
83 for (int i=0; i<nk_; i++) delete [] a[i];
84 delete [] a;
85 delete [] b;
86}
87
88void OdeGeng5::step_ (double dt) {
89
90 unsigned long i;
91 //set k values to zero
92 for (i=0; i<neq_*nk_; i++) kall_[i] = 0.0;
93 //solve for slopes
94 newton_->solve_Newton(kall_);
95 //compute new solution
96 for (i=0; i<neq_; i++) sol_[i] += dt*(b[0]*k_[0][i]
97 + b[1]*k_[1][i]
98 + b[2]*k_[2][i]);
99}
100
101} // namespace ode
Nonlinear system solver for OdeGeng5.
Definition ode_geng_5.h:17
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
~OdeGeng5()
destructs
Definition ode_geng_5.cc:82
OdeGeng5(unsigned long neq)
constructs
Definition ode_geng_5.cc:60
Provides a large vector containing the slope values of all stages with pointers to each of the indivi...
Definition ode_irk.h:9
double ** k_
individual k arrays for each stage
Definition ode_irk.h:25
int nk_
number of RK stages
Definition ode_irk.h:21
double * kall_
pointer to single array storing all stage k values
Definition ode_irk.h:23
double ** Jac_
pointer to the solver's Jacobian matrix
void fun(double *solin, double *fout)
wrapper around system evaluation function
unsigned long neq_
ODE system size.
double * dt_
pointer to time step member
void jac(double *solin, double **Jout)
wrapper around Jacobian evaluation function
double * ftemp_
temporary values for evaluation of Newton function
double * sol_
pointer to the solver's solution vector
double * soltemp_
temporary solution values
void set_modified(bool modified)
sets whether modified Newtion's is being used
Definition ode_newton.h:56
int solve_Newton(double *x)
Solve the system of equations.
Definition ode_newton.cc:84
bool get_modified()
gets whether modified Newtion's is being used
Definition ode_newton.h:45
int nk_
number of stages or k vectors
double ** a
pointer to tableau coefficients
double ** k_
pointer to the stage slopes of RK methods