Mercurial > repos > public > sbplib
changeset 1170:d3bde8a23e08 feature/rv
Fix incorrect filename
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 28 Jun 2019 13:14:59 +0200 |
parents | d02e5b8a0b24 |
children | 393ed30866a1 |
files | +rv/+time/RungekuttaExteriorRvMultiStage.m +rv/+time/RungekuttaRvMultiStage.m |
diffstat | 2 files changed, 65 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/+rv/+time/RungekuttaExteriorRvMultiStage.m Fri Jun 28 13:13:17 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -classdef RungekuttaRvMultiStage < time.Timestepper - properties - F % RHS of the ODE - F_unstable % RHS of the unstabalized ODE - k % Time step - t % Time point - v % Solution vector - n % Time level - rkScheme % The particular RK scheme used for time integration - RV % Residual Viscosity operator - DvDt % Function for computing the time deriative used for the RV evaluation - v_unstable - viscosity - end - methods - - function obj = RungekuttaRvMultiStage(F, F_unstable, k, t0, v0, RV, DvDt, order) - obj.F = F; - obj.F_unstable = F_unstable; - obj.k = k; - obj.t = t0; - obj.v = v0; - obj.n = 0; - - if (order == 4) % Use specialized RK4 scheme - obj.rkScheme = @time.rk.rungekutta_4; - else - % Extract the coefficients for the specified order - % used for the RK updates from the Butcher tableua. - [s,a,b,c] = time.rk.butcherTableau(order); - coeffs = struct('s',s,'a',a,'b',b,'c',c); - obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); - end - - obj.RV = RV; - obj.DvDt = DvDt; - obj.v_unstable = 0*v0; - obj.viscosity = 0*v0; - end - - function [v, t] = getV(obj) - v = obj.v; - t = obj.t; - end - - function state = getState(obj) - dvdt = obj.DvDt(obj.v_unstable); - [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt); - state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t); - end - - % Advances the solution vector one time step using the Runge-Kutta method given by - % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps - function obj = step(obj) - m = length(obj.viscosity); - obj.v_unstable = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_unstable); - obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_unstable)); - % Fix the viscosity of the stabilized RHS - F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m)); - obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); - obj.t = obj.t + obj.k; - obj.n = obj.n + 1; - end - end -end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+rv/+time/RungekuttaRvMultiStage.m Fri Jun 28 13:14:59 2019 +0200 @@ -0,0 +1,65 @@ +classdef RungekuttaRvMultiStage < time.Timestepper + properties + F % RHS of the ODE + F_unstable % RHS of the unstabalized ODE + k % Time step + t % Time point + v % Solution vector + n % Time level + rkScheme % The particular RK scheme used for time integration + RV % Residual Viscosity operator + DvDt % Function for computing the time deriative used for the RV evaluation + v_unstable + viscosity + end + methods + + function obj = RungekuttaRvMultiStage(F, F_unstable, k, t0, v0, RV, DvDt, order) + obj.F = F; + obj.F_unstable = F_unstable; + obj.k = k; + obj.t = t0; + obj.v = v0; + obj.n = 0; + + if (order == 4) % Use specialized RK4 scheme + obj.rkScheme = @time.rk.rungekutta_4; + else + % Extract the coefficients for the specified order + % used for the RK updates from the Butcher tableua. + [s,a,b,c] = time.rk.butcherTableau(order); + coeffs = struct('s',s,'a',a,'b',b,'c',c); + obj.rkScheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs); + end + + obj.RV = RV; + obj.DvDt = DvDt; + obj.v_unstable = 0*v0; + obj.viscosity = 0*v0; + end + + function [v, t] = getV(obj) + v = obj.v; + t = obj.t; + end + + function state = getState(obj) + dvdt = obj.DvDt(obj.v_unstable); + [viscosity, Df, firstOrderViscosity, residualViscosity] = obj.RV.evaluate(obj.v, dvdt); + state = struct('v', obj.v, 'dvdt', dvdt, 'Df', Df, 'viscosity', obj.viscosity, 'residualViscosity', residualViscosity, 'firstOrderViscosity', firstOrderViscosity, 't', obj.t); + end + + % Advances the solution vector one time step using the Runge-Kutta method given by + % obj.coeffs, using a fixed residual viscosity for the Runge-Kutta substeps + function obj = step(obj) + m = length(obj.viscosity); + obj.v_unstable = obj.rkScheme(obj.v, obj.t, obj.k, obj.F_unstable); + obj.viscosity = obj.RV.evaluateViscosity(obj.v, obj.DvDt(obj.v_unstable)); + % Fix the viscosity of the stabilized RHS + F_stable = @(v,t) obj.F(v,t,spdiags(obj.viscosity,0,m,m)); + obj.v = obj.rkScheme(obj.v, obj.t, obj.k, F_stable); + obj.t = obj.t + obj.k; + obj.n = obj.n + 1; + end + end +end \ No newline at end of file