comparison +rv/+time/RungekuttaExteriorRv.m @ 1033:037f203b9bf5 feature/burgers1d

Merge with branch feature/advectioRV to utilize the +rv package
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:44:12 +0100
parents 2ef20d00b386
children 010bb2677230
comparison
equal deleted inserted replaced
854:18162a0a5bb5 1033:037f203b9bf5
1 classdef RungekuttaExteriorRv < time.Timestepper
2 properties
3 F % RHS of the ODE
4 k % Time step
5 t % Time point
6 v % Solution vector
7 n % Time level
8 coeffs % The coefficents used for the RK time integration
9
10 % Properties related to the residual viscositys
11 RV % Residual Viscosity operator
12 v_prev % Solution vector at previous time levels, used for the RV evaluation
13 DvDt % Function for computing the time deriative used for the RV evaluation
14 lowerBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
15 % dictates which accuracy the boot-strapping should start from.
16 upperBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
17 % Dictates the order of accuracy used once the boot-strapping is complete.
18
19 % Convenience properties. Only for plotting
20 viscosity % Total viscosity
21 residualViscosity % Residual viscosity
22 firstOrderViscosity % first order viscosity
23 dvdt % Evaluated time derivative in residual
24 Df % Evaluated flux in residual
25 end
26 methods
27
28 function obj = RungekuttaExteriorRv(F, k, t0, v0, RV, DvDt, order)
29 obj.F = F;
30 obj.k = k;
31 obj.t = t0;
32 obj.v = v0;
33 obj.n = 0;
34 % Extract the coefficients for the specified order
35 % used for the RK updates from the Butcher tableua.
36 [s,a,b,c] = time.rk.butcherTableau(order);
37 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
38
39 obj.RV = RV;
40 obj.DvDt = DvDt;
41 obj.dvdt = obj.DvDt(obj.v);
42 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = RV.evaluate(obj.v,obj.dvdt);
43 end
44
45 function [v, t] = getV(obj)
46 v = obj.v;
47 t = obj.t;
48 end
49
50 function state = getState(obj)
51 state = struct('v', obj.v, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 'residualViscosity', obj.residualViscosity, 'firstOrderViscosity', obj.firstOrderViscosity, 't', obj.t);
52 end
53
54 function obj = step(obj)
55 obj.dvdt = obj.DvDt(obj.v);
56 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);
57
58 % Fix the viscosity of the RHS function F
59 F_visc = @(v,t) obj.F(v,t,obj.viscosity);
60 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs);
61 obj.t = obj.t + obj.k;
62 obj.n = obj.n + 1;
63 end
64 end
65 end