Mercurial > repos > public > sbplib
annotate +scheme/Utux.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 | d6ab5ceba496 |
children | 8a9393084b30 |
rev | line source |
---|---|
270 | 1 classdef Utux < scheme.Scheme |
2 properties | |
3 m % Number of points in each direction, possibly a vector | |
4 h % Grid spacing | |
571
38c3da9675a5
Bug fixes in scheme.Utux
Martin Almquist <martin.almquist@it.uu.se>
parents:
367
diff
changeset
|
5 grid % Grid |
270 | 6 order % Order accuracy for the approximation |
7 | |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
8 a % Wave speed |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
9 % Can either be a constant or function handle. |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
10 |
270 | 11 H % Discrete norm |
12 D | |
13 | |
14 D1 | |
15 Hi | |
16 e_l | |
17 e_r | |
18 end | |
19 | |
20 | |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
21 methods |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
22 function obj = Utux(g, order, opSet, a, fluxSplitting) |
949
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
23 default_arg('opSet',@sbp.D2Standard); |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
24 default_arg('a',1); |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
25 default_arg('fluxSplitting',[]); |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
26 |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
27 assertType(g, 'grid.Cartesian'); |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
28 if isa(a, 'function_handle') |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
29 obj.a = spdiag(grid.evalOn(g, a)); |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
30 else |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
31 obj.a = a; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
32 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
33 |
949
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
34 m = g.size(); |
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
35 xl = g.getBoundary('l'); |
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
36 xr = g.getBoundary('r'); |
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
37 xlim = {xl, xr}; |
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
38 |
6d2167719557
Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents:
946
diff
changeset
|
39 ops = opSet(m, xlim, order); |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
40 |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
41 if (isequal(opSet, @sbp.D1Upwind)) |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
42 obj.D1 = (ops.Dp + ops.Dm)/2; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
43 DissOp = (ops.Dm - ops.Dp)/2; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
44 obj.D = -(obj.a*obj.D1 + fluxSplitting*DissOp); |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
45 else |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
46 obj.D1 = ops.D1; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
47 obj.D = -obj.a*obj.D1; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
48 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
49 |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
50 obj.grid = g; |
270 | 51 |
290
d32f674bcbe5
A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents:
270
diff
changeset
|
52 obj.H = ops.H; |
d32f674bcbe5
A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents:
270
diff
changeset
|
53 obj.Hi = ops.HI; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
54 |
290
d32f674bcbe5
A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents:
270
diff
changeset
|
55 obj.e_l = ops.e_l; |
d32f674bcbe5
A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents:
270
diff
changeset
|
56 obj.e_r = ops.e_r; |
270 | 57 |
58 obj.m = m; | |
290
d32f674bcbe5
A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents:
270
diff
changeset
|
59 obj.h = ops.h; |
270 | 60 obj.order = order; |
61 end | |
62 % Closure functions return the opertors applied to the own doamin to close the boundary | |
63 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. | |
64 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. | |
65 % type is a string specifying the type of boundary condition if there are several. | |
66 % data is a function returning the data that should be applied at the boundary. | |
67 % neighbour_scheme is an instance of Scheme that should be interfaced to. | |
68 % neighbour_boundary is a string specifying which boundary to interface to. | |
573
efe2dbf9796e
Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents:
572
diff
changeset
|
69 function [closure, penalty] = boundary_condition(obj,boundary,type) |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
70 default_arg('type','dirichlet'); |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
71 sigma_left = -1; % Scalar penalty parameter for left boundary |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
72 sigma_right = 1; % Scalar penalty parameter for right boundary |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
73 switch boundary |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
74 % Can only specify boundary condition where there is inflow |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
75 % Extract the postivie resp. negative part of a, for the left |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
76 % resp. right boundary, and set other values of a to zero. |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
77 % Then the closure will effectively only contribute to inflow boundaries |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
78 case {'l','L','left','Left'} |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
79 a_inflow = obj.a; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
80 a_inflow(a_inflow < 0) = 0; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
81 tau = sigma_left*a_inflow*obj.e_l; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
82 closure = obj.Hi*tau*obj.e_l'; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
83 case {'r','R','right','Right'} |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
84 a_inflow = obj.a; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
85 a_inflow(a_inflow > 0) = 0; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
86 tau = sigma_right*a_inflow*obj.e_r; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
87 closure = obj.Hi*tau*obj.e_r'; |
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
88 end |
573
efe2dbf9796e
Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents:
572
diff
changeset
|
89 penalty = -obj.Hi*tau; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
90 |
270 | 91 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
92 |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
910
diff
changeset
|
93 function [closure, penalty] = interface(obj, boundary, neighbour_scheme, neighbour_boundary, type) |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
94 switch boundary |
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
95 % Upwind coupling |
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
96 case {'l','left'} |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
97 tau = -1*obj.a*obj.e_l; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
98 closure = obj.Hi*tau*obj.e_l'; |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
99 penalty = -obj.Hi*tau*neighbour_scheme.e_r'; |
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
100 case {'r','right'} |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
101 tau = 0*obj.a*obj.e_r; |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
102 closure = obj.Hi*tau*obj.e_r'; |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
103 penalty = -obj.Hi*tau*neighbour_scheme.e_l'; |
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
104 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
105 |
270 | 106 end |
905
459eeb99130f
Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents:
573
diff
changeset
|
107 |
270 | 108 function N = size(obj) |
109 N = obj.m; | |
110 end | |
111 | |
112 end | |
113 | |
114 methods(Static) | |
573
efe2dbf9796e
Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents:
572
diff
changeset
|
115 % Calculates the matrices needed for the inteface coupling between boundary bound_u of scheme schm_u |
270 | 116 % and bound_v of scheme schm_v. |
572
4a73b2aab91f
Edit scheme.Utux: Add interface function. Compatible with new grids. Works with Utux_1D_interface.
Martin Almquist <martin.almquist@it.uu.se>
parents:
571
diff
changeset
|
117 % [uu, uv, vv, vu] = inteface_coupling(A,'r',B,'l') |
270 | 118 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v) |
119 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v); | |
120 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u); | |
121 end | |
122 end | |
123 end |