Mercurial > repos > public > sbplib
view +time/Rungekutta.m @ 846:c6fcee3fcf1b feature/burgers1d
Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 20 Sep 2018 17:51:19 +0200 |
parents | |
children | 1c6f1595bb94 |
line wrap: on
line source
classdef Rungekutta < time.Timestepper properties F % RHS of the ODE k % Time step t % Time point v % Solution vector n % Time level coeffs % The coefficents used for the RK time integration end methods % Timesteps v_t = F(v,t), using RK with specfied order from t = t0 with % timestep k and initial conditions v = v0 function obj = Rungekutta(F, k, t0, v0, order) default_arg('order','4'); obj.F = F; obj.k = k; obj.t = t0; obj.v = v0; obj.n = 0; % Extract the coefficients for the specified order % used for the RK updates from the Butcher tableua. [s,a,b,c] = butcherTableau(order); obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); end function [v,t] = getV(obj) v = obj.v; t = obj.t; end function obj = step(obj) obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, obj.F, obj.coeffs); obj.t = obj.t + obj.k; obj.n = obj.n + 1; end end end