view +rv/+time/RungekuttaExteriorRv.m @ 1031:2ef20d00b386 feature/advectionRV

For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:25:06 +0100
parents 78c75c95b7dd
children 010bb2677230
line wrap: on
line source

classdef RungekuttaExteriorRv < 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
        
        % Properties related to the residual viscositys
        RV              % Residual Viscosity operator
        v_prev          % Solution vector at previous time levels, used for the RV evaluation
        DvDt            % Function for computing the time deriative used for the RV evaluation
        lowerBdfOrder   % Orders of the approximation of the time deriative, used for the RV evaluation.
                        % dictates which accuracy the boot-strapping should start from.
        upperBdfOrder   % Orders of the approximation of the time deriative, used for the RV evaluation.
                        % Dictates the order of accuracy used once the boot-strapping is complete.
        
        % Convenience properties. Only for plotting
        viscosity % Total viscosity
        residualViscosity % Residual viscosity
        firstOrderViscosity % first order viscosity
        dvdt % Evaluated time derivative in residual
        Df % Evaluated flux in residual
    end
    methods

        function obj = RungekuttaExteriorRv(F, k, t0, v0, RV, DvDt, order)
            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] = time.rk.butcherTableau(order);
            obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
        
            obj.RV = RV;
            obj.DvDt = DvDt;
            obj.dvdt = obj.DvDt(obj.v);
            [obj.viscosity,  obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = RV.evaluate(obj.v,obj.dvdt);
        end

        function [v, t] = getV(obj)
            v = obj.v;
            t = obj.t;
        end

        function state = getState(obj)
            state = struct('v', obj.v, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 'residualViscosity', obj.residualViscosity, 'firstOrderViscosity', obj.firstOrderViscosity, 't', obj.t);
        end

        function obj = step(obj)            
            obj.dvdt = obj.DvDt(obj.v);
            [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);

            % Fix the viscosity of the RHS function F
            F_visc = @(v,t) obj.F(v,t,obj.viscosity);
            obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs);
            obj.t = obj.t + obj.k;
            obj.n = obj.n + 1;
        end
    end
end