Mercurial > repos > public > sbplib
view +rv/+time/RungekuttaExteriorRV.m @ 1013:eb441fbdf379 feature/advectionRV
Draft implementation of RungeKutta with exterior RV updates
- Draft class RungeKuttaExteriorRV which updates the residual using a BDF approximation of the derivtive outside of the RK stages.
- Draft class for BDF derivative
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 05 Dec 2018 15:04:44 +0100 |
parents | |
children | e547794a9407 |
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 RV % Residual Viscosity v_prev % Solution vector at previous time levels, used for the RV update DvDt % Function for computing the time deriative used for the RV update end methods function obj = RungekuttaExteriorRV(F, k, t0, v0, RV, rkOrder, bdfOrder) obj.F = F; obj.k = k; obj.t = t0; obj.v = v0; obj.n = 0; % Extract the coefficients for the specified rkOrder % used for the RK updates from the Butcher tableua. [s,a,b,c] = time.rk.butcherTableau(rkOrder); obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); obj.RV = RV; % TODO: Initialize v_prev. obj.v_prev = zeros(length(obj.v),bdfOrder); % TBD: For cases where h~k we could probably use rkOrder-2 here. obj.DvDt = rv.time.BDFDerivative(bdfOrder,k); end function [v, t] = getV(obj) v = obj.v; t = obj.t; end function state = getState(obj) [residual, u_t, grad_f] = obj.RV.getResidual(); state = struct('v', obj.v, 'residual', residual, 'u_t', u_t, 'grad_f', grad_f, 'viscosity', obj.RV.getViscosity(), 't', obj.t); end function obj = step(obj) % Store current time level obj.v_prev(:,2:end) = obj.v_prev(:,1:end-1); obj.v_prev(:,1) = obj.v; % Fix the viscosity of the RHS function F F_visc = @(v,t)F(v,t,obj.RV.getViscosity()); %Remove state in RV? obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.RV, obj.coeffs); % Calculate dvdt and update RV dvdt = obj.DvDt.evaluate(v, v_prev, lenght(v_prev)); RV.update(v,dvdt); obj.t = obj.t + obj.k; obj.n = obj.n + 1; end end end