Mercurial > repos > public > sbplib
annotate +rv/ResidualViscosity.m @ 1223:9fddc8749445 rv_diffOp_test
Closing branch
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 05 Aug 2019 10:48:37 +0200 |
parents | 010bb2677230 |
children | 2ba63553ccfc |
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. |
1151
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
10 boundaryIndices % indices of the boundary of the domain |
1012
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
11 end |
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
12 |
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
13 methods |
1016
4b42999874c0
Add lower level for boot-strapping to RungeKuttaExteriorRV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1015
diff
changeset
|
14 % 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
|
15 % wrapping it in a function. |
1151
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
16 function obj = ResidualViscosity(g, Df, waveSpeed, Cmax, Cres, h, normalization) |
1150
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
17 default_arg('normalization',@(v)abs(obj.minmaxDiffNeighborhood1d(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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 obj.normalization = normalization; |
1151
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
24 obj.boundaryIndices = obj.getBoundaryIndices(g); |
1012
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
25 end |
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
26 |
1152
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
27 function viscosity = evaluateViscosity(obj, v, dvdt) |
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
28 viscosity = min(obj.Cmax*obj.h*abs(obj.waveSpeed(v)), obj.Cres*obj.h^2*abs(dvdt + obj.Df(v))./obj.normalization(v)); |
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
29 % TODO: If the boundary conditions are implemented correctly, this might not be needed. |
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
30 viscosity(obj.boundaryIndices) = 0; |
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
31 end |
010bb2677230
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1151
diff
changeset
|
32 |
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
|
33 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
|
34 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
|
35 firstOrderViscosity = obj.Cmax*obj.h*abs(obj.waveSpeed(v)); |
1039
a8ee5eca0e6c
Allow for the residual normalization function to return a vector. Also change the default normalization from normalizing on norm(u-mean(u),inf) to norm(u/2), since this proved to be better for 1d burgers
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1031
diff
changeset
|
36 residualViscosity = obj.Cres*obj.h^2*abs(dvdt + Df)./obj.normalization(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
|
37 viscosity = min(firstOrderViscosity, residualViscosity); |
1151
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
38 % TODO: If the boundary conditions are implemented correctly, this might not be needed. |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
39 viscosity(obj.boundaryIndices) = 0; |
1012
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 end |
1150
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
42 methods (Static) |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
43 |
1151
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
44 function boundaryind = getBoundaryIndices(g) |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
45 ind = grid.funcToMatrix(g, 1:g.N()); |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
46 switch g.D() |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
47 case 1 |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
48 boundaryind = [ind(1) ind(end)]; |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
49 case 2 |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
50 boundaryind = [ind(1,:) ind(end,:), ind(:,1)' ind(:,end)']; |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
51 case 3 |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
52 error; |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
53 end |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
54 end |
03ecf18d035f
Set RV artificial viscosity to zero around borders of the domain
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1150
diff
changeset
|
55 |
1150
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
56 function minmaxDiff = minmaxDiffNeighborhood1d(u) |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
57 umax = movmax(u,3); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
58 umin = movmin(u,3); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
59 minmaxDiff = umax - umin; |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
60 end |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
61 function minmaxDiff = minmaxDiffNeighborhood2d(g, u) |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
62 m = g.m(); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
63 uMatrix = grid.funcToMatrix(g,u); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
64 umax = max(movmax(uMatrix,3,1),movmax(uMatrix,3,2)); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
65 umin = min(movmin(uMatrix,3,1),movmin(uMatrix,3,2)); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
66 minmaxDiff = umax - umin; |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
67 minmaxDiff = reshape(minmaxDiff',m(1)*m(2),1); |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
68 end |
922996695952
Implement local residual normalization functions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1039
diff
changeset
|
69 end |
1012
1e437c9e5132
Create residual viscosity package +rv and generalize the ResidualViscosity class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
70 end |