annotate +time/RungekuttaRV.m @ 851:ab2e5a24ddde feature/burgers1d

- Fix bug when constructing closure for narrow stencils - Update the residual outside of the RK time steps. At least for the inner convergence rate, updating the residual inside does not seem to be required.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 21 Sep 2018 15:33:15 +0200
parents c6fcee3fcf1b
children cda996e64925
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 classdef RungekuttaRV < time.Timestepper
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 F % RHS of the ODE
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 k % Time step
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 t % Time point
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 v % Solution vector
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 n % Time level
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 RV % Residual Viscosity
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 coeffs % The coefficents used for the RK time integration
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
12 methods
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 function obj = RungekuttaRV(F, k, t0, v0, RV, order)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
14 obj.F = F;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 obj.k = k;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16 obj.t = t0;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17 obj.v = v0;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 obj.n = 0;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19 obj.RV = RV;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 % Extract the coefficients for the specified order
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 % used for the RK updates from the Butcher tableua.
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 [s,a,b,c] = time.rk.butcherTableau(order);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 function [v, t] = getV(obj)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 v = obj.v;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 t = obj.t;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 function state = getState(obj)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 [residual, u_t, f_x] = obj.RV.getResidual();
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 state = struct('v', obj.v, 'residual', residual, 'u_t', u_t, 'f_x', f_x, 'viscosity', obj.RV.getViscosity(), 't', obj.t);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
34 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 function obj = step(obj)
851
ab2e5a24ddde - Fix bug when constructing closure for narrow stencils
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 846
diff changeset
37 F = @(v,t) obj.F(v,t,obj.RV.getViscosity());
ab2e5a24ddde - Fix bug when constructing closure for narrow stencils
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 846
diff changeset
38 v_p = obj.v;
ab2e5a24ddde - Fix bug when constructing closure for narrow stencils
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 846
diff changeset
39 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F, obj.coeffs);
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 obj.t = obj.t + obj.k;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41 obj.n = obj.n + 1;
851
ab2e5a24ddde - Fix bug when constructing closure for narrow stencils
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 846
diff changeset
42 obj.RV.update(obj.v,v_p,obj.k);
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
47 methods (Static)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48 function k = getTimeStep(lambda)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49 k = rk4.get_rk4_time_step(lambda);
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
51 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53 end