Mercurial > repos > public > sbplib
comparison +rv/+time/RungekuttaExteriorRvMg.m @ 1160:76e3bb7836cf feature/rv
First attempt at multi-grid calculation of the residual
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 25 Jun 2019 16:52:54 +0200 |
parents | |
children | 0ec06ca3fc36 |
comparison
equal
deleted
inserted
replaced
1159:1ad7da049b50 | 1160:76e3bb7836cf |
---|---|
1 classdef RungekuttaExteriorRvMg < 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 rkScheme % The particular RK scheme used for time integration | |
9 RV % Residual Viscosity operator | |
10 DvDt % Function for computing the time deriative used for the RV evaluation | |
11 v_unstable | |
12 viscosity | |
13 end | |
14 methods | |
15 | |
16 function obj = RungekuttaExteriorRvMg(F, k, t0, v0, RV, DvDt, order) | |
17 obj.F = F; | |
18 obj.k = k; | |
19 obj.t = t0; | |
20 obj.v = v0; | |
21 obj.n = 0; | |
22 | |
23 if (order == 4) % Use specialized RK4 scheme | |
24 obj.rkScheme = @time.rk.rungekutta_4; | |
25 else | |
26 % Extract the coefficients for the specified order | |
27 % used for the RK updates from the Butcher tableua. | |
28 [s,a,b,c] = time.rk.butcherTableau(order); | |
29 coeffs = struct('s',s,'a',a,'b',b,'c',c); | |
30 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); | |
31 end | |
32 | |
33 obj.RV = RV; | |
34 obj.DvDt = DvDt; | |
35 obj.v_unstable = 0*v0 | |
36 obj.viscosity = 0*v0 | |
37 end | |
38 | |
39 function [v, t] = getV(obj) | |
40 v = obj.v; | |
41 t = obj.t; | |
42 end | |
43 | |
44 function state = getState(obj) | |
45 dvdt = obj.DvDt(obj.v_unstable); | |
46 [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); | |
48 end | |
49 | |
50 % 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 | |
52 function obj = step(obj) | |
53 % Fix the viscosity of the RHS function F | |
54 m = length(obj.viscosity); | |
55 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); | |
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.n = obj.n + 1; | |
62 end | |
63 end | |
64 end |