Mercurial > repos > public > sbplib
comparison +rv/+time/RungekuttaExteriorRv.m @ 1154:3108963cc42c feature/rv
Improve efficiency of diffOps in Burgers2d, the artificial diffusion operator in rv.constructDiffOps and the RungekuttaExteriorRv time-steppers
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 06 Mar 2019 09:45:52 +0100 |
parents | 010bb2677230 |
children |
comparison
equal
deleted
inserted
replaced
1153:635386c073b9 | 1154:3108963cc42c |
---|---|
3 F % RHS of the ODE | 3 F % RHS of the ODE |
4 k % Time step | 4 k % Time step |
5 t % Time point | 5 t % Time point |
6 v % Solution vector | 6 v % Solution vector |
7 n % Time level | 7 n % Time level |
8 coeffs % The coefficents used for the RK time integration | 8 rkScheme % The particular RK scheme used for time integration |
9 RV % Residual Viscosity operator | 9 RV % Residual Viscosity operator |
10 DvDt % Function for computing the time deriative used for the RV evaluation | 10 DvDt % Function for computing the time deriative used for the RV evaluation |
11 end | 11 end |
12 methods | 12 methods |
13 | 13 |
15 obj.F = F; | 15 obj.F = F; |
16 obj.k = k; | 16 obj.k = k; |
17 obj.t = t0; | 17 obj.t = t0; |
18 obj.v = v0; | 18 obj.v = v0; |
19 obj.n = 0; | 19 obj.n = 0; |
20 % Extract the coefficients for the specified order | 20 |
21 % used for the RK updates from the Butcher tableua. | 21 if (order == 4) % Use specialized RK4 scheme |
22 [s,a,b,c] = time.rk.butcherTableau(order); | 22 obj.rkScheme = @time.rk.rungekutta_4; |
23 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); | 23 else |
24 % Extract the coefficients for the specified order | |
25 % used for the RK updates from the Butcher tableua. | |
26 [s,a,b,c] = time.rk.butcherTableau(order); | |
27 coeffs = struct('s',s,'a',a,'b',b,'c',c); | |
28 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); | |
29 end | |
24 | 30 |
25 obj.RV = RV; | 31 obj.RV = RV; |
26 obj.DvDt = DvDt; | 32 obj.DvDt = DvDt; |
27 end | 33 end |
28 | 34 |
39 | 45 |
40 % Advances the solution vector one time step using the Runge-Kutta method given by | 46 % Advances the solution vector one time step using the Runge-Kutta method given by |
41 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps | 47 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps |
42 function obj = step(obj) | 48 function obj = step(obj) |
43 % Fix the viscosity of the RHS function F | 49 % Fix the viscosity of the RHS function F |
44 F_visc = @(v,t) obj.F(v,t,obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v))); | 50 viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v)); |
45 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs); | 51 m = length(viscosity); |
52 F_visc = @(v,t) obj.F(v,t,spdiags(viscosity,0,m,m)); | |
53 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_visc); | |
46 obj.t = obj.t + obj.k; | 54 obj.t = obj.t + obj.k; |
47 obj.n = obj.n + 1; | 55 obj.n = obj.n + 1; |
48 end | 56 end |
49 end | 57 end |
50 end | 58 end |