Mercurial > repos > public > sbplib
comparison +rv/+time/RungekuttaExteriorRvMg.m @ 1165:745ae0d134c9 feature/rv
Pass RHS of unstabilized ode to RKExterirorRvMg
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 27 Jun 2019 17:14:30 +0200 |
parents | 0ec06ca3fc36 |
children |
comparison
equal
deleted
inserted
replaced
1164:fc2631ba4da5 | 1165:745ae0d134c9 |
---|---|
1 classdef RungekuttaExteriorRvMg < time.Timestepper | 1 classdef RungekuttaExteriorRvMg < time.Timestepper |
2 properties | 2 properties |
3 F % RHS of the ODE | 3 F % RHS of the ODE |
4 F_unstable % RHS of the unstabalized ODE | |
4 k % Time step | 5 k % Time step |
5 t % Time point | 6 t % Time point |
6 v % Solution vector | 7 v % Solution vector |
7 n % Time level | 8 n % Time level |
8 rkScheme % The particular RK scheme used for time integration | 9 rkScheme % The particular RK scheme used for time integration |
11 v_unstable | 12 v_unstable |
12 viscosity | 13 viscosity |
13 end | 14 end |
14 methods | 15 methods |
15 | 16 |
16 function obj = RungekuttaExteriorRvMg(F, k, t0, v0, RV, DvDt, order) | 17 function obj = RungekuttaExteriorRvMg(F, F_unstable, k, t0, v0, RV, DvDt, order) |
17 obj.F = F; | 18 obj.F = F; |
19 obj.F_unstable = F_unstable; | |
18 obj.k = k; | 20 obj.k = k; |
19 obj.t = t0; | 21 obj.t = t0; |
20 obj.v = v0; | 22 obj.v = v0; |
21 obj.n = 0; | 23 obj.n = 0; |
22 | 24 |
42 end | 44 end |
43 | 45 |
44 function state = getState(obj) | 46 function state = getState(obj) |
45 dvdt = obj.DvDt(obj.v_unstable); | 47 dvdt = obj.DvDt(obj.v_unstable); |
46 [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt); | 48 [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt); |
47 state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t); | 49 state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t); |
48 end | 50 end |
49 | 51 |
50 % Advances the solution vector one time step using the Runge-Kutta method given by | 52 % Advances the solution vector one time step using the Runge-Kutta method given by |
51 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps | 53 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps |
52 function obj = step(obj) | 54 function obj = step(obj) |
53 % Fix the viscosity of the RHS function F | |
54 m = length(obj.viscosity); | 55 m = length(obj.viscosity); |
56 obj.v_unstable = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_unstable); | |
57 obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_unstable)); | |
58 % Fix the viscosity of the stabilized RHS | |
55 F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m)); | 59 F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m)); |
56 F_unstable = @(v,t) obj.F(v,t,spdiags(0*obj.viscosity,0,m,m)); | |
57 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); | 60 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); |
58 obj.v_unstable = obj.rkScheme(obj.v, obj.t, obj.k, F_unstable); | |
59 obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_unstable)); | |
60 obj.t = obj.t + obj.k; | 61 obj.t = obj.t + obj.k; |
61 obj.n = obj.n + 1; | 62 obj.n = obj.n + 1; |
62 end | 63 end |
63 end | 64 end |
64 end | 65 end |