view +time/RungekuttaRV.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 ab2e5a24ddde
line wrap: on
line source

classdef RungekuttaRV < time.Timestepper
    properties
        F       % RHS of the ODE
        k       % Time step
        t       % Time point
        v       % Solution vector
        n       % Time level
        RV      % Residual Viscosity
        coeffs  % The coefficents used for the RK time integration
    end

    methods
        function obj = RungekuttaRV(F, k, t0, v0, RV, order)
            obj.F = F;
            obj.k = k;
            obj.t = t0;
            obj.v = v0;
            obj.n = 0;
            obj.RV = RV;
            % Extract the coefficients for the specified order
            % used for the RK updates from the Butcher tableua.
            [s,a,b,c] = time.rk.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 state = getState(obj)
            [residual, u_t, f_x] = obj.RV.getResidual();
            state = struct('v', obj.v, 'residual', residual, 'u_t', u_t, 'f_x', f_x, 'viscosity', obj.RV.getViscosity(), 't', obj.t);
        end

        function obj = step(obj)
            obj.v = time.rk.rungekuttaRV(obj.v, obj.t, obj.k, obj.F, obj.RV, obj.coeffs);
            obj.t = obj.t + obj.k;
            obj.n = obj.n + 1;
        end
    end


    methods (Static)
        function k = getTimeStep(lambda)
            k = rk4.get_rk4_time_step(lambda);
        end
    end

end