comparison +rv/+time/RungekuttaRvMultiGrid.m @ 1169:d02e5b8a0b24 feature/rv

Rename RungekuttaRV time steppers. Add RungekuttaRVMultiStage time stepper
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 28 Jun 2019 13:13:17 +0200
parents +rv/+time/RungekuttaExteriorRvMg.m@745ae0d134c9
children b96b1245a77d
comparison
equal deleted inserted replaced
1168:af3c4eb0cbbd 1169:d02e5b8a0b24
1 classdef RungekuttaRvMultiGrid < time.Timestepper
2 properties
3 F % RHS of the ODE
4 F_coarse % RHS of the unstabalized ODE
5 k % Time step
6 t % Time point
7 v % Solution vector
8 n % Time level
9 rkScheme % The particular RK scheme used for time integration
10 RV % Residual Viscosity operator
11 DvDt % Function for computing the time deriative used for the RV evaluation
12 v_unstable
13 viscosity
14 end
15 methods
16
17 function obj = RungekuttaRvMultiGrid(F, F_coarse, k, t0, v0, RV, DvDt, order)
18 obj.F = F;
19 obj.F_coarse = F_coarse;
20 obj.k = k;
21 obj.t = t0;
22 obj.v = v0;
23 obj.n = 0;
24
25 if (order == 4) % Use specialized RK4 scheme
26 obj.rkScheme = @time.rk.rungekutta_4;
27 else
28 % Extract the coefficients for the specified order
29 % used for the RK updates from the Butcher tableua.
30 [s,a,b,c] = time.rk.butcherTableau(order);
31 coeffs = struct('s',s,'a',a,'b',b,'c',c);
32 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs);
33 end
34
35 obj.RV = RV;
36 obj.DvDt = DvDt;
37 obj.v_unstable = 0*v0;
38 obj.viscosity = 0*v0;
39 end
40
41 function [v, t] = getV(obj)
42 v = obj.v;
43 t = obj.t;
44 end
45
46 function state = getState(obj)
47 dvdt = obj.DvDt(obj.v_unstable);
48 [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt);
49 state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t);
50 end
51
52 % Advances the solution vector one time step using the Runge-Kutta method given by
53 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps
54 function obj = step(obj)
55 m = length(obj.viscosity);
56 obj.v_unstable = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_coarse);
57 obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_unstable));
58 % Fix the viscosity of the stabilized RHS
59 F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m));
60 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable);
61 obj.t = obj.t + obj.k;
62 obj.n = obj.n + 1;
63 end
64 end
65 end