libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_gauss_6.cc
Go to the documentation of this file.
1
2
3#include "ode_gauss_6.h"
4
5namespace ode {
6
7void NewtonGauss6::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 NewtonGauss6::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
60OdeGauss6::OdeGauss6 (unsigned long neq) :
61 OdeAdaptive (neq, true),
62 OdeIRK (neq, 3) {
63
64 method_ = "Gauss6";
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(15.0);
72
73 a[0][0] = 5.0/36; a[0][1] = 2.0/9 - r/15; a[0][2] = 5.0/36 - r/30;
74 a[1][0] = 5.0/36 + r/24; a[1][1] = 2.0/9; a[1][2] = 5.0/36 - r/24;
75 a[2][0] = 5.0/36 + r/30; a[2][1] = 2.0/9 + r/15; a[2][2] = 5.0/36;
76
77 b[0] = 5.0/18; b[1] = 4.0/9; b[2] = 5.0/18;
78
79 newton_ = new NewtonGauss6(neq, nk, this);
80 newton_->set_modified(true);
81}
82
84 for (int i=0; i<nk_; i++) delete [] a[i];
85 delete [] a;
86 delete [] b;
87}
88
89void OdeGauss6::step_ (double dt) {
90
91 unsigned long i;
92 //set k values to zero
93 for (i=0; i<neq_*nk_; i++) kall_[i] = 0.0;
94 //solve for slopes
95 newton_->solve_Newton(kall_);
96 //compute new solution
97 for (i=0; i<neq_; i++) sol_[i] += dt*(b[0]*k_[0][i]
98 + b[1]*k_[1][i]
99 + b[2]*k_[2][i]);
100}
101
102} // namspace ode
Nonlinear system solver for OdeGauss6.
Definition ode_gauss_6.h:16
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
OdeGauss6(unsigned long neq)
constructs
~OdeGauss6()
destructs
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