view +time/+rk4/rungekutta_4RV.m @ 845:1e057b0f2fed feature/burgers1d

Add RK6 with residual viscosity update and reduce computational effort of spatial scheme - Add RK6 with residual updates - Change the D2 operator for upwind schemes to one less computationally expensive.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 19 Sep 2018 16:32:05 +0200
parents f63b99f0729d
children
line wrap: on
line source

% Takes one time step of size k using the rungekutta method
% starting from v_0 and where the function F(v,t) gives the
% time derivatives.
function v = rungekutta_4RV(v, t , k, F, RV)
    
    v1 = v + k/2*F(v,t, RV.getViscosity());
    
    RV.update(v1, v, k/2);
    v2 = v + k/2*F(v1,t+k/2, RV.getViscosity());
    
    RV.update(v2, v, k/2);
    v3 = v + k*F(v2,t+k/2, RV.getViscosity());
    
    RV.update(v3,v,k);
    v4 = v + k*F(v3,t+k, RV.getViscosity());
    
    v_next = 1/6*(-3*v + 2*v1 + 4*v2 + 2*v3 + v4);
    RV.update(v_next,v,k);
    v = v_next;
    
    % k1 = F(v, t, RV.getViscosity());
    
    % RV.update(v+0.5*k*k1, v, 0.5*k);
    % k2 = F(v+0.5*k*k1, t+0.5*k, RV.getViscosity());
    
    % RV.update(v+0.5*k*k2, v, 0.5*k);
    % k3 = F(v+0.5*k*k2, t+0.5*k, RV.getViscosity());
    
    % RV.update(v+k*k3, v, k);
    % k4 = F(v+k*k3,t+k, RV.getViscosity());
    
    % RV.update(v + (1/6)*(k1+2*(k2+k3)+k4)*k, v, k);
    % v = v + (1/6)*(k1+2*(k2+k3)+k4)*k;
end