annotate +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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1169
d02e5b8a0b24 Rename RungekuttaRV time steppers. Add RungekuttaRVMultiStage time stepper
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1165
diff changeset
1 classdef RungekuttaRvMultiGrid < time.Timestepper
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
1165
745ae0d134c9 Pass RHS of unstabilized ode to RKExterirorRvMg
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1162
diff changeset
3 F % RHS of the ODE
1169
d02e5b8a0b24 Rename RungekuttaRV time steppers. Add RungekuttaRVMultiStage time stepper
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1165
diff changeset
4 F_coarse % RHS of the unstabalized ODE
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 k % Time step
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 t % Time point
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 v % Solution vector
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 n % Time level
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 rkScheme % The particular RK scheme used for time integration
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 RV % Residual Viscosity operator
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11 DvDt % Function for computing the time deriative used for the RV evaluation
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
12 v_coarse
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 viscosity
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
14 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 methods
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16
1169
d02e5b8a0b24 Rename RungekuttaRV time steppers. Add RungekuttaRVMultiStage time stepper
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1165
diff changeset
17 function obj = RungekuttaRvMultiGrid(F, F_coarse, k, t0, v0, RV, DvDt, order)
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 obj.F = F;
1169
d02e5b8a0b24 Rename RungekuttaRV time steppers. Add RungekuttaRVMultiStage time stepper
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1165
diff changeset
19 obj.F_coarse = F_coarse;
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 obj.k = k;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 obj.t = t0;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 obj.v = v0;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 obj.n = 0;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 if (order == 4) % Use specialized RK4 scheme
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 obj.rkScheme = @time.rk.rungekutta_4;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 else
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 % Extract the coefficients for the specified order
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 % used for the RK updates from the Butcher tableua.
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 [s,a,b,c] = time.rk.butcherTableau(order);
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 coeffs = struct('s',s,'a',a,'b',b,'c',c);
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs);
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
34
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 obj.RV = RV;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 obj.DvDt = DvDt;
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
37 obj.v_coarse = 0*v0;
1162
0ec06ca3fc36 Add missing semicolons
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1160
diff changeset
38 obj.viscosity = 0*v0;
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41 function [v, t] = getV(obj)
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
42 v = obj.v;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 t = obj.t;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46 function state = getState(obj)
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
47 dvdt = obj.DvDt(obj.v_coarse);
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48 [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt);
1165
745ae0d134c9 Pass RHS of unstabilized ode to RKExterirorRvMg
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1162
diff changeset
49 state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t);
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
51
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52 % Advances the solution vector one time step using the Runge-Kutta method given by
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53 % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
54 function obj = step(obj)
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
55 % Fix the viscosity of the stabilized RHS
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
56 m = length(obj.viscosity);
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
57 F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m));
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
58 % Advance solution on unstabilized coarse mesh based on current solution
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
59 obj.v_coarse = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_coarse);
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
60 % Advance solution on on stabilized mesh based on current viscosity
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
61 obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable);
1174
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
62 % Compute viscosity for the next time time level using the advanced solution
b96b1245a77d Update variable names and comments in RungekuttaRvMultiGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1169
diff changeset
63 obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_coarse));
1160
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
64 obj.t = obj.t + obj.k;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
65 obj.n = obj.n + 1;
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
66 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
67 end
76e3bb7836cf First attempt at multi-grid calculation of the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
68 end