annotate +rv/ResidualViscosity.m @ 1033:037f203b9bf5 feature/burgers1d

Merge with branch feature/advectioRV to utilize the +rv package
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:44:12 +0100
parents 2ef20d00b386
children a8ee5eca0e6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 classdef ResidualViscosity < handle
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
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
3 Df % Diff op approximating the gradient of the flux f(u)
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 waveSpeed % Wave speed at each grid point, e.g f'(u). %TBD: Better naming?
1016
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
5 Cmax % Constant controlling relative amount of upwind dissipation
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
6 Cres % Constant controling relative amount of upwind dissipation
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
7 h % Length scale used for scaling the viscosity. Typically grid spacing.
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
8 normalization % Function used to normalize the residual such that it is amplified in the
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
9 % shocks.
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
12 methods
1016
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
13 % TBD: Decide on how to treat waveSpeed. It would be nice to just pass a constant value without
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
14 % wrapping it in a function.
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
15 function obj = ResidualViscosity(Df, waveSpeed, Cmax, Cres, h, normalization)
1016
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
16 default_arg('normalization',@(v)norm(v-mean(v),inf));
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
17 obj.Df = Df;
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 obj.waveSpeed = waveSpeed;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19 obj.h = h;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 obj.Cmax = Cmax;
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 obj.Cres = Cres;
1016
4b42999874c0 Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1015
diff changeset
22 obj.normalization = normalization;
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24
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: 1017
diff changeset
25 function [viscosity, Df, firstOrderViscosity, residualViscosity] = evaluate(obj, v, 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
26 Df = obj.Df(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: 1017
diff changeset
27 firstOrderViscosity = obj.Cmax*obj.h*abs(obj.waveSpeed(v));
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: 1017
diff changeset
28 residualViscosity = obj.Cres*obj.h^2*abs(dvdt + Df)/obj.normalization(v);
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: 1017
diff changeset
29 viscosity = min(firstOrderViscosity, residualViscosity);
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: 1017
diff changeset
30 %viscosity = obj.Cmax*obj.h*abs(obj.waveSpeed(v));
1012
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 end
1e437c9e5132 Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 end