Mercurial > repos > public > sbplib
comparison +rv/+time/RungekuttaRvMultiGrid.m @ 1174:b96b1245a77d feature/rv
Update variable names and comments in RungekuttaRvMultiGrid
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 28 Jun 2019 13:33:49 +0200 |
parents | d02e5b8a0b24 |
children | ebec2b86f539 |
comparison
equal
deleted
inserted
replaced
1173:dde29b865244 | 1174:b96b1245a77d |
---|---|
7 v % Solution vector | 7 v % Solution vector |
8 n % Time level | 8 n % Time level |
9 rkScheme % The particular RK scheme used for time integration | 9 rkScheme % The particular RK scheme used for time integration |
10 RV % Residual Viscosity operator | 10 RV % Residual Viscosity operator |
11 DvDt % Function for computing the time deriative used for the RV evaluation | 11 DvDt % Function for computing the time deriative used for the RV evaluation |
12 v_unstable | 12 v_coarse |
13 viscosity | 13 viscosity |
14 end | 14 end |
15 methods | 15 methods |
16 | 16 |
17 function obj = RungekuttaRvMultiGrid(F, F_coarse, k, t0, v0, RV, DvDt, order) | 17 function obj = RungekuttaRvMultiGrid(F, F_coarse, k, t0, v0, RV, DvDt, order) |
32 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); | 32 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); |
33 end | 33 end |
34 | 34 |
35 obj.RV = RV; | 35 obj.RV = RV; |
36 obj.DvDt = DvDt; | 36 obj.DvDt = DvDt; |
37 obj.v_unstable = 0*v0; | 37 obj.v_coarse = 0*v0; |
38 obj.viscosity = 0*v0; | 38 obj.viscosity = 0*v0; |
39 end | 39 end |
40 | 40 |
41 function [v, t] = getV(obj) | 41 function [v, t] = getV(obj) |
42 v = obj.v; | 42 v = obj.v; |
43 t = obj.t; | 43 t = obj.t; |
44 end | 44 end |
45 | 45 |
46 function state = getState(obj) | 46 function state = getState(obj) |
47 dvdt = obj.DvDt(obj.v_unstable); | 47 dvdt = obj.DvDt(obj.v_coarse); |
48 [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt); | 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); | 49 state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t); |
50 end | 50 end |
51 | 51 |
52 % 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 |
53 % 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 |
54 function obj = step(obj) | 54 function obj = step(obj) |
55 % Fix the viscosity of the stabilized RHS | |
55 m = length(obj.viscosity); | 56 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)); | 57 F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m)); |
58 % Advance solution on unstabilized coarse mesh based on current solution | |
59 obj.v_coarse = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_coarse); | |
60 % Advance solution on on stabilized mesh based on current viscosity | |
60 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); | 61 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); |
62 % Compute viscosity for the next time time level using the advanced solution | |
63 obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_coarse)); | |
61 obj.t = obj.t + obj.k; | 64 obj.t = obj.t + obj.k; |
62 obj.n = obj.n + 1; | 65 obj.n = obj.n + 1; |
63 end | 66 end |
64 end | 67 end |
65 end | 68 end |