comparison +rv/+time/RungekuttaExteriorRv.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
comparison
equal deleted inserted replaced
1030:78c75c95b7dd 1031:2ef20d00b386
7 n % Time level 7 n % Time level
8 coeffs % The coefficents used for the RK time integration 8 coeffs % The coefficents used for the RK time integration
9 9
10 % Properties related to the residual viscositys 10 % Properties related to the residual viscositys
11 RV % Residual Viscosity operator 11 RV % Residual Viscosity operator
12 viscosity % Viscosity vector
13 v_prev % Solution vector at previous time levels, used for the RV evaluation 12 v_prev % Solution vector at previous time levels, used for the RV evaluation
14 DvDt % Function for computing the time deriative used for the RV evaluation 13 DvDt % Function for computing the time deriative used for the RV evaluation
15 lowerBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation. 14 lowerBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
16 % dictates which accuracy the boot-strapping should start from. 15 % dictates which accuracy the boot-strapping should start from.
17 upperBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation. 16 upperBdfOrder % Orders of the approximation of the time deriative, used for the RV evaluation.
18 % Dictates the order of accuracy used once the boot-strapping is complete. 17 % Dictates the order of accuracy used once the boot-strapping is complete.
19 18
20 % Convenience properties. Only for plotting 19 % Convenience properties. Only for plotting
21 residual 20 viscosity % Total viscosity
22 dvdt 21 residualViscosity % Residual viscosity
23 Df 22 firstOrderViscosity % first order viscosity
23 dvdt % Evaluated time derivative in residual
24 Df % Evaluated flux in residual
24 end 25 end
25 methods 26 methods
26 27
27 function obj = RungekuttaExteriorRv(F, k, t0, v0, RV, DvDt, order) 28 function obj = RungekuttaExteriorRv(F, k, t0, v0, RV, DvDt, order)
28 obj.F = F; 29 obj.F = F;
36 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); 37 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
37 38
38 obj.RV = RV; 39 obj.RV = RV;
39 obj.DvDt = DvDt; 40 obj.DvDt = DvDt;
40 obj.dvdt = obj.DvDt(obj.v); 41 obj.dvdt = obj.DvDt(obj.v);
41 [obj.viscosity, obj.Df] = RV.evaluate(obj.v,obj.dvdt); 42 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = RV.evaluate(obj.v,obj.dvdt);
42 obj.residual = obj.dvdt + obj.Df;
43 end 43 end
44 44
45 function [v, t] = getV(obj) 45 function [v, t] = getV(obj)
46 v = obj.v; 46 v = obj.v;
47 t = obj.t; 47 t = obj.t;
48 end 48 end
49 49
50 function state = getState(obj) 50 function state = getState(obj)
51 state = struct('v', obj.v, 'residual', obj.residual, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 't', obj.t); 51 state = struct('v', obj.v, 'dvdt', obj.dvdt, 'Df', obj.Df, 'viscosity', obj.viscosity, 'residualViscosity', obj.residualViscosity, 'firstOrderViscosity', obj.firstOrderViscosity, 't', obj.t);
52 end 52 end
53 53
54 function obj = step(obj) 54 function obj = step(obj)
55 obj.dvdt = obj.DvDt(obj.v); 55 obj.dvdt = obj.DvDt(obj.v);
56 [obj.viscosity, obj.Df] = obj.RV.evaluate(obj.v,obj.dvdt); 56 [obj.viscosity, obj.Df, obj.firstOrderViscosity, obj.residualViscosity] = obj.RV.evaluate(obj.v,obj.dvdt);
57 obj.residual = obj.dvdt + obj.Df;
58 57
59 % Fix the viscosity of the RHS function F 58 % Fix the viscosity of the RHS function F
60 F_visc = @(v,t) obj.F(v,t,obj.viscosity); 59 F_visc = @(v,t) obj.F(v,t,obj.viscosity);
61 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs); 60 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, F_visc, obj.coeffs);
62 obj.t = obj.t + obj.k; 61 obj.t = obj.t + obj.k;