annotate +rv/+time/RungekuttaInteriorRv.m @ 1031:2ef20d00b386 feature/advectionRV

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
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:25:06 +0100
parents 78c75c95b7dd
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: 1017
diff changeset
1 classdef RungekuttaInteriorRv < time.Timestepper
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 F % RHS of the ODE
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 k % Time step
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 t % Time point
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 v % Solution vector
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 n % Time level
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
8 coeffs % The coefficents used for the RK time integration
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 RV % Residual Viscosity
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
10 DvDt % Function for computing the time deriative used for the RV evaluation
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: 1012
diff changeset
11
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
12 % Convenience properties. Only for plotting
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
13 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
14 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
15 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
16 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
17 Df % Evaluated flux in residual
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 methods
1030
78c75c95b7dd Rename Rungekutta-Rv classes according to naming convention
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1017
diff changeset
21 function obj = RungekuttaInteriorRv(F, k, t0, v0, RV, DvDt, order)
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
22 obj.F = F;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 obj.k = k;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24 obj.t = t0;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 obj.v = v0;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 obj.n = 0;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 % Extract the coefficients for the specified order
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 % used for the RK updates from the Butcher tableua.
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 [s,a,b,c] = time.rk.butcherTableau(order);
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
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: 1012
diff changeset
31 obj.RV = RV;
2d7c1333bd6c Add support for using the ODE to approximate the time derivative in the residual
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1012
diff changeset
32 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: 1012
diff changeset
33 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
34 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37 function [v, t] = getV(obj)
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38 v = obj.v;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 t = obj.t;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
42 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
43 state = struct('v', obj.v, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 'residualViscosity', obj.residualViscosity, 'firstOrderViscosity', obj.firstOrderViscosity, 't', obj.t);
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46 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: 1012
diff changeset
47 obj.v = rv.time.rungekuttaRV(obj.v, obj.t, obj.k, obj.F, obj.RV, obj.DvDt, obj.coeffs);
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48 obj.t = obj.t + obj.k;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49 obj.n = obj.n + 1;
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: 1012
diff changeset
50 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
51 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
53 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
54 end