2#ifndef HDNUM_RUNGEKUTTA_HH
3#define HDNUM_RUNGEKUTTA_HH
58 for (
int i = 0;
i < s;
i++)
61 for(
int k = 0;
k < n;
k++)
67 for (
int i = 0;
i < s;
i++)
70 model.f(t + c[
i] * dt, u +
xx[
i], f[
i]);
73 for (
int i = 0;
i < s;
i++)
77 for (
int i = 0;
i < s;
i++)
80 for (
int j = 0;
j < s;
j++)
87 for (
int i = 0;
i < s;
i++)
89 for (
int j = 0;
j < n;
j++)
100 for (
int i = 0;
i < s;
i++)
103 for(
int k = 0;
k < n;
k++)
109 for (
int i = 0;
i < n;
i++)
113 for (
int i = 0;
i < s;
i++)
115 for (
int j = 0;
j < s;
j++)
119 model.f_x(t+c[
j]*dt, u +
xx[
j],
H);
125 for (
int k = 0;
k < n;
k++)
127 for (
int l = 0;
l < n;
l++)
156 template<
class M,
class S = Newton>
174 : model(
model_), u(model.size()), w(model.size()), K(
A_.rowsize ())
181 model.initialize(t,u);
183 for (
int i = 0;
i < s;
i++)
191 HDNUM_ERROR(
"need square and nonempty matrix");
193 HDNUM_ERROR(
"vector incompatible with matrix");
195 HDNUM_ERROR(
"vector incompatible with matrix");
204 : model(
model_), u(model.size()), w(model.size()), K(
A_.rowsize ())
211 model.initialize(t,u);
213 for (
int i = 0;
i < s;
i++)
220 HDNUM_ERROR(
"need square and nonempty matrix");
222 HDNUM_ERROR(
"vector incompatible with matrix");
224 HDNUM_ERROR(
"vector incompatible with matrix");
237 for (
int i = 0;
i < s;
i++)
239 for (
int j =
i;
j < s;
j++)
258 for (
int i = 0;
i < s;
i++)
263 for (
int j = 0;
j <
i+1;
j++)
268 model.f(t + c[
i]*dt,
wert, K[
i]);
278 for (
int i = 0;
i<s;
i++)
280 if (A[s-1][
i] != b[
i])
288 solver.set_maxit(2000);
289 solver.set_verbosity(verbosity);
290 solver.set_reduction(1
e-10);
291 solver.set_abslimit(1
e-10);
292 solver.set_linesearchsteps(10);
293 solver.set_sigma(0.01);
313 for (
int i=0;
i<s;
i++)
322 for (
int j = 0;
j < s;
j++)
330 for(
int i=0;
i<s;
i++)
334 for (
int j = 0;
j < n;
j++)
347 for (
int i = 0;
i < s;
i++)
350 for (
int j=0;
j < s;
j++)
422 template<
class M,
class S>
425 typename M::number_type
T,
426 typename M::number_type
h_0,
430 typedef typename M::time_type time_type;
431 typedef typename M::number_type number_type;
439 for (
int i=0;
i<
l;
i++)
448 time_type dt =
h_0/pow(2,
i) ;
452 while (solver.get_time()<
T-2*solver.get_dt())
458 if (solver.get_time()<
T-solver.get_dt())
460 solver.set_dt((
T-solver.get_time())/2.0);
461 for(
int i=0;
i<2;
i++)
468 solver.set_dt(
T-solver.get_time());
479 << std::scientific << std::showpoint << std::setprecision(8)
489 << std::scientific << std::showpoint << std::setprecision(8)
496 <<
rate << std::endl;
Class with mathematical matrix operations.
Definition densematrix.hh:33
void update(const REAL s, const DenseMatrix &B)
Scaled update of a Matrix.
Definition densematrix.hh:489
size_t rowsize() const
get number of rows of the matrix
Definition densematrix.hh:136
size_t colsize() const
get number of columns of the matrix
Definition densematrix.hh:153
Nonlinear problem we need to solve to do one step of an implicit Runge Kutta method.
Definition rungekutta.hh:17
M::number_type number_type
export number_type
Definition rungekutta.hh:26
void F_x(const Vector< number_type > &x, DenseMatrix< number_type > &result) const
jacobian evaluation needed for newton in implicite solvers
Definition rungekutta.hh:97
std::size_t size() const
return number of componentes for the model
Definition rungekutta.hh:49
M::size_type size_type
export size_type
Definition rungekutta.hh:20
M::time_type time_type
export time_type
Definition rungekutta.hh:23
ImplicitRungeKuttaStepProblem(const M &model_, DenseMatrix< number_type > A_, Vector< number_type > b_, Vector< number_type > c_, time_type t_, Vector< number_type > u_, time_type dt_)
constructor stores parameter lambda
Definition rungekutta.hh:29
void F(const Vector< number_type > &x, Vector< number_type > &result) const
model evaluation
Definition rungekutta.hh:55
classical Runge-Kutta method (order n with n stages)
Definition rungekutta.hh:158
M::number_type number_type
export number_type
Definition rungekutta.hh:167
M::size_type size_type
export size_type
Definition rungekutta.hh:161
time_type get_dt() const
get dt used in last step (i.e. to compute current state)
Definition rungekutta.hh:384
time_type get_time() const
get current time
Definition rungekutta.hh:378
void set_verbosity(int verbosity_)
how much should the ODE solver talk
Definition rungekutta.hh:390
RungeKutta(const M &model_, DenseMatrix< number_type > A_, Vector< number_type > b_, Vector< number_type > c_)
constructor stores reference to the model
Definition rungekutta.hh:170
void set_state(time_type t_, const Vector< number_type > &u_)
set current state
Definition rungekutta.hh:365
void step()
do one step
Definition rungekutta.hh:251
M::time_type time_type
export time_type
Definition rungekutta.hh:164
void set_dt(time_type dt_)
set time step for subsequent steps
Definition rungekutta.hh:228
const Vector< number_type > & get_state() const
get current state
Definition rungekutta.hh:372
RungeKutta(const M &model_, DenseMatrix< number_type > A_, Vector< number_type > b_, Vector< number_type > c_, number_type sigma_)
constructor stores reference to the model
Definition rungekutta.hh:199
bool check_explicit()
test if method is explicit
Definition rungekutta.hh:234
Vector & update(const REAL alpha, const Vector &y)
Update vector by addition of a scaled vector (x += a y )
Definition vector.hh:201
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition lr.hh:160
void lr_fullpivot(DenseMatrix< T > &A, Vector< std::size_t > &p, Vector< std::size_t > &q)
lr decomposition of A with full pivoting
Definition lr.hh:107
void permute_backward(const Vector< std::size_t > &q, Vector< T > &z)
apply permutations to a solution vector
Definition lr.hh:171
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition lr.hh:203
void solveR(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume R = upper triangle of A and solve R x = b.
Definition lr.hh:233
void solveL(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume L = lower triangle of A with l_ii=1, solve L x = b.
Definition lr.hh:215
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition lr.hh:182
Newton's method with line search.
void ordertest(const M &model, S solver, typename M::number_type T, typename M::number_type h_0, int l)
Test convergence order of an ODE solver applied to a model problem.
Definition rungekutta.hh:423