annotate +rv/+time/RungekuttaExteriorRv.m @ 1142:cff49fba3cc8 rv-interpolation

Closing branch
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 05 Aug 2019 10:49:21 +0200
parents 2ef20d00b386
children 010bb2677230
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1030
78c75c95b7dd Rename Rungekutta-Rv classes according to naming convention
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1029
diff changeset
1 classdef RungekuttaExteriorRv < time.Timestepper
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 F % RHS of the ODE
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 k % Time step
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 t % Time point
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 v % Solution vector
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 n % Time level
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 coeffs % The coefficents used for the RK time integration
1017
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
9
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
10 % Properties related to the residual viscositys
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
11 RV % Residual Viscosity operator
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
12 v_prev % Solution vector at previous time levels, used for the RV evaluation
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
13 DvDt % Function for computing the time deriative used for the RV evaluation
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
14 lowerBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
15 % dictates which accuracy the boot-strapping should start from.
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
16 upperBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
17 % Dictates the order of accuracy used once the boot-strapping is complete.
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
18
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
19 % Convenience properties. Only for plotting
1031
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
20 viscosity % Total viscosity
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
21 residualViscosity % Residual viscosity
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
22 firstOrderViscosity % first order viscosity
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
23 dvdt % Evaluated time derivative in residual
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
24 Df % Evaluated flux in residual
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 methods
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27
1030
78c75c95b7dd Rename Rungekutta-Rv classes according to naming convention
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1029
diff changeset
28 function obj = RungekuttaExteriorRv(F, k, t0, v0, RV, DvDt, order)
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 obj.F = F;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 obj.k = k;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 obj.t = t0;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 obj.v = v0;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 obj.n = 0;
1030
78c75c95b7dd Rename Rungekutta-Rv classes according to naming convention
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1029
diff changeset
34 % Extract the coefficients for the specified order
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 % used for the RK updates from the Butcher tableua.
1030
78c75c95b7dd Rename Rungekutta-Rv classes according to naming convention
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1029
diff changeset
36 [s,a,b,c] = time.rk.butcherTableau(order);
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 obj.RV = RV;
1017
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
40 obj.DvDt = DvDt;
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
41 obj.dvdt = obj.DvDt(obj.v);
1031
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
42 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = RV.evaluate(obj.v,obj.dvdt);
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45 function [v, t] = getV(obj)
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46 v = obj.v;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
47 t = obj.t;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50 function state = getState(obj)
1031
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
51 state = struct('v', obj.v, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 'residualViscosity', obj.residualViscosity, 'firstOrderViscosity', obj.firstOrderViscosity, 't', obj.t);
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53
1029
dce08a74e0ad Create a separate class of RungekuttaExteriorRV which uses BDFs for computing the time derivative. Remove BDFs from RungekuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1020
diff changeset
54 function obj = step(obj)
1017
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
55 obj.dvdt = obj.DvDt(obj.v);
1031
2ef20d00b386 For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1030
diff changeset
56 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);
1017
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
57
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
58 % Fix the viscosity of the RHS function F
1017
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1016
diff changeset
59 F_visc = @(v,t) obj.F(v,t,obj.viscosity);
1014
e547794a9407 Add boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1013
diff changeset
60 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs);
1013
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
61 obj.t = obj.t + obj.k;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
62 obj.n = obj.n + 1;
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
63 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
64 end
eb441fbdf379 Draft implementation of RungeKutta with exterior RV updates
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
65 end