annotate +scheme/Utux.m @ 998:2b1b944deae1 feature/getBoundaryOp

Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
author Martin Almquist <malmquist@stanford.edu>
date Sat, 12 Jan 2019 13:35:19 -0800
parents 6d2167719557
children 8d73fcdb07a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
1 classdef Utux < scheme.Scheme
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
2 properties
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
3 m % Number of points in each direction, possibly a vector
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
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
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
6 order % Order accuracy for the approximation
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
7
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
8 H % Discrete norm
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
9 D
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
10
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
11 D1
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
12 Hi
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
13 e_l
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
14 e_r
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
15 v0
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
16 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
17
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
18
905
459eeb99130f Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents: 573
diff changeset
19 methods
949
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
20 function obj = Utux(g, order, opSet)
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
21 default_arg('opSet',@sbp.D2Standard);
905
459eeb99130f Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents: 573
diff changeset
22
949
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
23 m = g.size();
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
24 xl = g.getBoundary('l');
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
25 xr = g.getBoundary('r');
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
26 xlim = {xl, xr};
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
27
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
28 ops = opSet(m, xlim, order);
6d2167719557 Remove half-commented switch in Utux.
Martin Almquist <malmquist@stanford.edu>
parents: 946
diff changeset
29 obj.D1 = ops.D1;
905
459eeb99130f Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents: 573
diff changeset
30
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
31 obj.grid = g;
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
32
290
d32f674bcbe5 A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents: 270
diff changeset
33 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
34 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
35
290
d32f674bcbe5 A first attempt to make a general scheme fo hyperbolic systems
Ylva Rydin <ylva.rydin@telia.com>
parents: 270
diff changeset
36 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
37 obj.e_r = ops.e_r;
571
38c3da9675a5 Bug fixes in scheme.Utux
Martin Almquist <martin.almquist@it.uu.se>
parents: 367
diff changeset
38 obj.D = -obj.D1;
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
39
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
40 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
41 obj.h = ops.h;
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
42 obj.order = order;
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
43
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
44 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
45 % Closure functions return the opertors applied to the own doamin to close the boundary
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
46 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin.
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
47 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'.
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
48 % type is a string specifying the type of boundary condition if there are several.
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
49 % data is a function returning the data that should be applied at the boundary.
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
50 % neighbour_scheme is an instance of Scheme that should be interfaced to.
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
51 % 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
52 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
53 default_arg('type','dirichlet');
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 tau =-1*obj.e_l;
459eeb99130f Include type as (optional) input parameter in the interface method of all schemes.
Martin Almquist <malmquist@stanford.edu>
parents: 573
diff changeset
55 closure = obj.Hi*tau*obj.e_l';
573
efe2dbf9796e Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents: 572
diff changeset
56 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
57
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
58 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
59
946
706d1c2b4199 Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents: 910
diff changeset
60 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
61 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
62 % 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
63 case {'l','left'}
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
64 tau = -1*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
65 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
66 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
67 case {'r','right'}
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
68 tau = 0*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
69 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
70 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
71 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
72
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
73 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
74
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
75 % Returns the boundary operator op for the boundary specified by the string boundary.
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
76 % op -- string or a cell array of strings
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
77 % boundary -- string
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
78 function varargout = getBoundaryOperator(obj, op, boundary)
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
79
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
80 if ~iscell(op)
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
81 op = {op};
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
82 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
83
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
84 for i = 1:numel(op)
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
85 switch op{i}
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
86 case 'e'
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
87 switch boundary
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
88 case 'l'
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
89 e = obj.e_l;
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
90 case 'r'
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
91 e = obj.e_r;
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
92 otherwise
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
93 error('No such boundary: boundary = %s',boundary);
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
94 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
95 varargout{i} = e;
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
96 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
97 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
98 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
99
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
100 function N = size(obj)
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
101 N = obj.m;
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
102 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
103
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
104 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
105
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
106 methods(Static)
573
efe2dbf9796e Remove data input from boundary condition function
Martin Almquist <martin.almquist@it.uu.se>
parents: 572
diff changeset
107 % Calculates the matrices needed for the inteface coupling between boundary bound_u of scheme schm_u
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
108 % 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
109 % [uu, uv, vv, vu] = inteface_coupling(A,'r',B,'l')
270
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
110 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v)
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
111 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v);
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
112 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u);
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
113 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
114 end
d755816aa0fa added a u_t+u_x=0 scheme
Ylva Rydin <ylva.rydin@telia.com>
parents:
diff changeset
115 end