Mercurial > repos > public > sbplib
annotate +scheme/Utux.m @ 1225:68ee061639a1 feature/rv
Make sure matrices are sparse.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 06 Nov 2019 14:52:07 +0100 |
parents | 433c89bf19e0 |
children |
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 |
1036
8a9393084b30
Change argument order to the "correct" order, i.e providing diffOp specific parameters before the opSet.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1027
diff
changeset
|
22 function obj = Utux(g, order, a, fluxSplitting, opSet) |
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'); |
1197 | 71 s = obj.getBoundarySign(boundary); |
72 e = obj.getBoundaryOperator('e', boundary); | |
1027
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 |
1197 | 78 case {'l'} |
1027
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; |
1197 | 81 case {'r'} |
1027
d6ab5ceba496
Support variable wave speed and upwind operators in Utux
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
949
diff
changeset
|
82 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
|
83 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
|
84 end |
1197 | 85 tau = s*a_inflow*e; |
86 closure = obj.Hi*tau*e'; | |
573
efe2dbf9796e
Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents:
572
diff
changeset
|
87 penalty = -obj.Hi*tau; |
270 | 88 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
|
89 |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
910
diff
changeset
|
90 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
|
91 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
|
92 % 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 |
270 | 103 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
|
104 |
1197 | 105 % Returns the boundary sign. The right boundary is considered the positive boundary |
106 % boundary -- string | |
107 function s = getBoundarySign(obj, boundary) | |
108 assertIsMember(boundary, {'l', 'r'}) | |
109 | |
110 switch boundary | |
111 case {'r'} | |
112 s = 1; | |
113 case {'l'} | |
114 s = -1; | |
115 end | |
116 end | |
117 | |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
949
diff
changeset
|
118 % Returns the boundary operator op for the boundary specified by the string boundary. |
1048
adbb80e60b10
Clean up Elastic2dVariable (partially), Utux, and Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
1044
diff
changeset
|
119 % op -- string |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
949
diff
changeset
|
120 % boundary -- string |
1048
adbb80e60b10
Clean up Elastic2dVariable (partially), Utux, and Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
1044
diff
changeset
|
121 function o = getBoundaryOperator(obj, op, boundary) |
adbb80e60b10
Clean up Elastic2dVariable (partially), Utux, and Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
1044
diff
changeset
|
122 assertIsMember(op, {'e'}) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
123 assertIsMember(boundary, {'l', 'r'}) |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
949
diff
changeset
|
124 |
1048
adbb80e60b10
Clean up Elastic2dVariable (partially), Utux, and Utux2d.
Martin Almquist <malmquist@stanford.edu>
parents:
1044
diff
changeset
|
125 o = obj.([op, '_', boundary]); |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
949
diff
changeset
|
126 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
949
diff
changeset
|
127 |
1049
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
128 % Returns square boundary quadrature matrix, of dimension |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
129 % corresponding to the number of boundary points |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
130 % |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
131 % boundary -- string |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
132 % Note: for 1d diffOps, the boundary quadrature is the scalar 1. |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
133 function H_b = getBoundaryQuadrature(obj, boundary) |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
134 assertIsMember(boundary, {'l', 'r'}) |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
135 |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
136 H_b = 1; |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
137 end |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1048
diff
changeset
|
138 |
270 | 139 function N = size(obj) |
140 N = obj.m; | |
141 end | |
142 | |
143 end | |
1043
c12b84fe9b00
Remove static method `interface_coupling` that shouldn't have existed in the first place
Jonatan Werpers <jonatan@werpers.com>
parents:
949
diff
changeset
|
144 end |