view +time/Ode45.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents 48b6fb693025
children b5e5b195da1e
line wrap: on
line source

classdef Ode45 < time.Timestepper
    properties
        F
        k
        t
        w
        m
        D
        E
        S
        M
        C
        n
    end


    methods
        function obj = Ode45(D, E, S, k, t0, v0, v0t)
            obj.D = D;
            obj.E = E;
            obj.S = S;
            obj.m = length(v0);

            I = speye(obj.m);
            O = sparse(obj.m,obj.m);
            obj.M = [O, I; D, E*I]; % Multiply with I to allow 0 as input.

            if S == 0
                obj.C = zeros(2*obj.m,1);
            else
                obj.C = [zeros(obj.m,1), S];
            end

            obj.k = k;
            obj.t = t0;
            obj.w = [v0; v0t];

            obj.F = @(w,t)(obj.M*w + obj.C);
        end

        function [v,t] = getV(obj)
            v = obj.w(1:end/2);
            t = obj.t;
        end

        function [vt,t] = getVt(obj)
            vt = obj.w(end/2+1:end);
            t = obj.t;
        end

        function obj = step(obj)
            [t,w] = ode45(@(t,w)(obj.F(w,t)),[obj.t obj.t+obj.k],obj.w);

            obj.t = t(end);
            obj.w = w(end,:)';
            obj.n = obj.n + 1;
        end
    end


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

end