annotate +scheme/Staggered1DAcousticsVariable.m @ 761:8ed102db8e9c feature/d1_staggered

Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
author Martin Almquist <malmquist@stanford.edu>
date Mon, 18 Jun 2018 16:36:24 -0700
parents ec0ac76006e2
children 18e10217dca9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
1 classdef Staggered1DAcousticsVariable < scheme.Scheme
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
2 properties
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
3 m % Number of points of primal grid in each direction, possibly a vector
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
4 h % Grid spacing
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
5
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
6 % Grids
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
7 grid % Total grid object
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
8 grid_primal
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
9 grid_dual
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
10
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
11 order % Order accuracy for the approximation
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
12
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
13 H % Combined norm
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
14 Hi % Inverse
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
15 D % Semi-discrete approximation matrix
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
16
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
17 D1_primal
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
18 D1_dual
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
19
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
20 % Pick out left or right boundary
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
21 e_l
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
22 e_r
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
23
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
24 % Initial data
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
25 v0
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
26
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
27 % Pick out primal or dual component
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
28 e_primal
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
29 e_dual
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
30
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
31 % System matrices, cell matrices of function handles
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
32 A
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
33 B
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
34
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
35 % Variable coefficient matrices evaluated at boundaries.
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
36 A_l, A_r
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
37 B_l, B_r
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
38 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
39
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
40
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
41 methods
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
42 % Scheme for A*u_t + B u_x = 0,
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
43 % u = [p, v];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
44 % A: Diagonal and A > 0,
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
45 % A = [a1, 0;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
46 % 0, a2]
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
47 %
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
48 % B = B^T and with diagonal entries = 0.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
49 % B = [0 b
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
50 % b 0]
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
51 % Here we store p on the primal grid and v on the dual
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
52 % A and B are cell matrices of function handles
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
53 function obj = Staggered1DAcousticsVariable(g, order, A, B)
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
54 default_arg('B',{@(x)0*x, @(x)0*x+1; @(x)0*x+1, @(x)0*x});
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
55 default_arg('A',{@(x)0*x+1, @(x)0*x; @(x)0*x, @(x)0*x+1});
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
56
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
57 obj.order = order;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
58 obj.A = A;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
59 obj.B = B;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
60
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
61 % Grids
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
62 obj.m = g.size();
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
63 xl = g.getBoundary('l');
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
64 xr = g.getBoundary('r');
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
65 xlim = {xl, xr};
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
66 obj.grid = g;
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
67 obj.grid_primal = g.grids{1};
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
68 obj.grid_dual = g.grids{2};
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
69 x_primal = obj.grid_primal.points();
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
70 x_dual = obj.grid_dual.points();
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
71
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
72 % Boundary matrices
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
73 obj.A_l = [A{1,1}(xl), A{1,2}(xl);....
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
74 A{2,1}(xl), A{2,2}(xl)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
75 obj.A_r = [A{1,1}(xr), A{1,2}(xr);....
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
76 A{2,1}(xr), A{2,2}(xr)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
77 obj.B_l = [B{1,1}(xl), B{1,2}(xl);....
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
78 B{2,1}(xl), B{2,2}(xl)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
79 obj.B_r = [B{1,1}(xr), B{1,2}(xr);....
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
80 B{2,1}(xr), B{2,2}(xr)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
81
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
82 % Get operators
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
83 ops = sbp.D1StaggeredUpwind(obj.m, xlim, order);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
84 obj.h = ops.h;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
85
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
86 % Build combined operators
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
87 H_primal = ops.H_primal;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
88 H_dual = ops.H_dual;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
89 obj.H = blockmatrix.toMatrix( {H_primal, []; [], H_dual } );
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
90 obj.Hi = inv(obj.H);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
91
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
92 D1_primal = ops.D1_primal;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
93 D1_dual = ops.D1_dual;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
94 A11_B12 = spdiag(-1./A{1,1}(x_primal).*B{1,2}(x_primal), 0);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
95 A22_B21 = spdiag(-1./A{2,2}(x_dual).*B{2,1}(x_dual), 0);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
96 D = {[], A11_B12*D1_primal;...
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
97 A22_B21*D1_dual, []};
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
98 obj.D = blockmatrix.toMatrix(D);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
99 obj.D1_primal = D1_primal;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
100 obj.D1_dual = D1_dual;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
101
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
102 % Combined boundary operators
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
103 e_primal_l = ops.e_primal_l;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
104 e_primal_r = ops.e_primal_r;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
105 e_dual_l = ops.e_dual_l;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
106 e_dual_r = ops.e_dual_r;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
107 e_l = {e_primal_l, [];...
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
108 [] , e_dual_l};
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
109 e_r = {e_primal_r, [];...
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
110 [] , e_dual_r};
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
111 obj.e_l = blockmatrix.toMatrix(e_l);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
112 obj.e_r = blockmatrix.toMatrix(e_r);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
113
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
114 % Pick out first or second component of solution
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
115 N_primal = obj.grid_primal.N();
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
116 N_dual = obj.grid_dual.N();
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
117 obj.e_primal = [speye(N_primal, N_primal); sparse(N_dual, N_primal)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
118 obj.e_dual = [sparse(N_primal, N_dual); speye(N_dual, N_dual)];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
119
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
120
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
121 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
122 % Closure functions return the operators applied to the own domain to close the boundary
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
123 % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other domain.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
124 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
125 % type is a string specifying the type of boundary condition if there are several.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
126 % neighbour_scheme is an instance of Scheme that should be interfaced to.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
127 % neighbour_boundary is a string specifying which boundary to interface to.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
128 function [closure, penalty] = boundary_condition(obj, boundary, type)
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
129
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
130 default_arg('type','p');
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
131
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
132 % type = 'p' => boundary condition for p
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
133 % type = 'v' => boundary condition for v
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
134 % No other types implemented yet
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
135
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
136 % BC on the form Lu - g = 0;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
137
682
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
138 % Need a transformation T such that w = T^{−1}*u is a
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
139 % meaningful change of variables and T^T*B*T is block-diagonal,
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
140 % For linear acoustics, T = T_C meets these criteria.
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
141
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
142 % Get boundary matrices
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
143 switch boundary
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
144 case 'l'
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
145 A = obj.A_l;
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
146 B = obj.B_l;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
147 case 'r'
653
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
148 A = obj.A_r;
2351a7690e8a Clean up and improve comments in StaggeredVariable
Martin Almquist <malmquist@stanford.edu>
parents: 652
diff changeset
149 B = obj.B_r;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
150 end
672
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
151 C = inv(A)*B;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
152
682
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
153 % Diagonalize C and use T_C to diagonalize B
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
154 [T, ~] = eig(C);
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
155 Lambda = T'*B*T;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
156 lambda = diag(Lambda);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
157
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
158 % Identify in- and outgoing characteristic variables
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
159 Iplus = lambda > 0;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
160 Iminus = lambda < 0;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
161
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
162 switch boundary
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
163 case 'l'
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
164 Iin = Iplus;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
165 case 'r'
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
166 Iin = Iminus;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
167 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
168 Tin = T(:,Iin);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
169
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
170 switch type
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
171 case 'p'
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
172 L = [1, 0];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
173 case 'v'
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
174 L = [0, 1];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
175 case 'characteristic'
672
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
176 % Diagonalize C
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
177 [T_C, Lambda_C] = eig(C);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
178 lambda_C = diag(Lambda_C);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
179 % Identify in- and outgoing characteristic variables
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
180 Iplus = lambda_C > 0;
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
181 Iminus = lambda_C < 0;
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
182
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
183 switch boundary
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
184 case 'l'
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
185 Iin_C = Iplus;
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
186 case 'r'
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
187 Iin_C = Iminus;
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
188 end
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
189 T_C_inv = inv(T_C);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
190 L = T_C_inv(Iin_C,:);
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
191 otherwise
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
192 error('Boundary condition not implemented.');
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
193 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
194
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
195 % Penalty parameters
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
196 sigma = [0; 0];
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
197 sigma(Iin) = lambda(Iin);
672
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
198
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
199 % Sparsify
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
200 A = sparse(A);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
201 T = sparse(T);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
202 sigma = sparse(sigma);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
203 L = sparse(L);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
204 Tin = sparse(Tin);
82024d32e333 Correct char BC in staggered acoustics 1D variable coeff.
Martin Almquist <malmquist@stanford.edu>
parents: 653
diff changeset
205
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
206 switch boundary
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
207 case 'l'
682
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
208 tau = -1*obj.e_l * inv(A) * inv(T)' * sigma * inv(L*Tin);
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
209 closure = obj.Hi*tau*L*obj.e_l';
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
210
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
211 case 'r'
682
ec0ac76006e2 Modify BC in Staggered 1D acoustics to ensure that only physically meaningful changes of variables are used. See hypsyst varcoeff sec 3.
Martin Almquist <malmquist@stanford.edu>
parents: 672
diff changeset
212 tau = 1*obj.e_r * inv(A) * inv(T)' * sigma * inv(L*Tin);
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
213 closure = obj.Hi*tau*L*obj.e_r';
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
214
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
215 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
216
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
217 penalty = -obj.Hi*tau;
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
218
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
219 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
220
761
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
221 % Uses the hat variable method for the interface coupling,
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
222 % see hypsyst_varcoeff.pdf in the hypsyst repository.
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
223 % Notation: u for left side of interface, v for right side.
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
224 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary)
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
225
761
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
226 % Get boundary matrices
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
227 switch boundary
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
228 case 'l'
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
229 A_v = obj.A_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
230 B_v = obj.B_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
231 Hi_v = obj.Hi;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
232 e_v = obj.e_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
233
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
234 A_u = neighbour_scheme.A_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
235 B_u = neighbour_scheme.B_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
236 Hi_u = neighbour_scheme.Hi;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
237 e_u = neighbour_scheme.e_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
238 case 'r'
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
239 A_u = obj.A_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
240 B_u = obj.B_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
241 Hi_u = obj.Hi;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
242 e_u = obj.e_r;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
243
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
244 A_v = neighbour_scheme.A_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
245 B_v = neighbour_scheme.B_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
246 Hi_v = neighbour_scheme.Hi;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
247 e_v = neighbour_scheme.e_l;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
248 end
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
249 C_u = inv(A_u)*B_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
250 C_v = inv(A_v)*B_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
251
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
252 % Diagonalize C
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
253 [T_u, ~] = eig(C_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
254 Lambda_u = inv(T_u)*C_u*T_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
255 lambda_u = diag(Lambda_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
256 S_u = inv(T_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
257
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
258 [T_v, ~] = eig(C_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
259 Lambda_v = inv(T_v)*C_v*T_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
260 lambda_v = diag(Lambda_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
261 S_v = inv(T_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
262
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
263 % Identify in- and outgoing characteristic variables
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
264 Im_u = lambda_u < 0;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
265 Ip_u = lambda_u > 0;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
266 Im_v = lambda_v < 0;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
267 Ip_v = lambda_v > 0;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
268
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
269 Tp_u = T_u(:,Ip_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
270 Tm_u = T_u(:,Im_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
271 Sp_u = S_u(Ip_u,:);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
272 Sm_u = S_u(Im_u,:);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
273
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
274 Tp_v = T_v(:,Ip_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
275 Tm_v = T_v(:,Im_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
276 Sp_v = S_v(Ip_v,:);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
277 Sm_v = S_v(Im_v,:);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
278
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
279 % Create S_tilde and T_tilde
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
280 Stilde = [Sp_u; Sm_v];
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
281 Ttilde = inv(Stilde);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
282 Ttilde_p = Ttilde(:,1);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
283 Ttilde_m = Ttilde(:,2);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
284
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
285 % Solve for penalty parameters theta_1,2
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
286 LHS = Ttilde_m*Sm_v*Tm_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
287 RHS = B_u*Tm_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
288 th_u = RHS./LHS;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
289 TH_u = diag(th_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
290
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
291 LHS = Ttilde_p*Sp_u*Tp_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
292 RHS = -B_v*Tp_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
293 th_v = RHS./LHS;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
294 TH_v = diag(th_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
295
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
296 % Construct penalty matrices
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
297 Z_u = TH_u*Ttilde_m*Sm_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
298 Z_u = sparse(Z_u);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
299
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
300 Z_v = TH_v*Ttilde_p*Sp_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
301 Z_v = sparse(Z_v);
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
302
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
303 closure_u = Hi_u*e_u*Z_u*e_u';
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
304 penalty_u = -Hi_u*e_u*Z_u*e_v';
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
305 closure_v = Hi_v*e_v*Z_v*e_v';
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
306 penalty_v = -Hi_v*e_v*Z_v*e_u';
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
307
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
308 switch boundary
761
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
309 case 'l'
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
310 closure = closure_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
311 penalty = penalty_v;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
312 case 'r'
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
313 closure = closure_u;
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
314 penalty = penalty_u;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
315 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
316
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
317 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
318
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
319 function N = size(obj)
761
8ed102db8e9c Add discont interface in 1D acoustics staggered, using the hat variable interface coupling.
Martin Almquist <malmquist@stanford.edu>
parents: 682
diff changeset
320 N = 2*obj.m+1;
652
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
321 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
322
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
323 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
324
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
325 methods(Static)
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
326 % Calculates the matrices needed for the inteface coupling between boundary bound_u of scheme schm_u
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
327 % and bound_v of scheme schm_v.
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
328 % [uu, uv, vv, vu] = inteface_coupling(A,'r',B,'l')
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
329 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v)
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
330 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
331 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u);
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
332 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
333 end
be941bb0a11a Add staggered 1D variable coefficient. Convergence study working.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
334 end