Mercurial > repos > public > sbplib
annotate +scheme/AdvectionRV2D.m @ 1023:defc9d0cc1f2 feature/advectionRV
Remove incorrect assertion of the number of BC:s
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 07 Jan 2019 12:06:49 +0100 |
parents | 87809b4762c9 |
children |
rev | line source |
---|---|
1009
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
1 classdef AdvectionRV2D < scheme.Scheme |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
2 properties |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
3 grid % Physical grid |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
4 order % Order accuracy for the approximation |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
5 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
6 D % Non-stabilized scheme operator |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
7 H % Discrete norm |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
8 H_inv % Norm inverse |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
9 halfnorm_inv % Cell array of inverse halfnorm operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
10 e_l % Cell array of left boundary operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
11 e_r % Cell array of right boundary operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
12 d_l % Cell array of left boundary derivative operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
13 d_r % Cell array of right boundary derivative operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
14 waveSpeed |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
15 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
16 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
17 methods |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
18 function obj = AdvectionRV2D(g, operator_type, order, dissipation, waveSpeed) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
19 if ~isa(g, 'grid.Cartesian') || g.D() ~= 2 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
20 error('Grid must be 2d cartesian'); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
21 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
22 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
23 obj.grid = g; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
24 obj.order = order; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
25 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
26 % Create cell array of 1D operators. For example D1_1d{1} = D1_x, D1_1d{2} = D1_y. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
27 [Dp_1d, Dm_1d, H_1d, H_inv_1d, d_l_1d, d_r_1d, e_l_1d, e_r_1d, I, DissipationOp_1d] = ... |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
28 obj.assemble1DOperators(g, operator_type, order, dissipation); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
29 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
30 %% 2D-operators |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
31 % D1 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
32 D1_1d{1} = (Dp_1d{1} + Dp_1d{1})/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
33 D1_1d{2} = (Dp_1d{2} + Dp_1d{2})/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
34 D1_2d = obj.extendOperatorTo2D(D1_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
35 D1 = D1_2d{1} + D1_2d{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
36 % D2 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
37 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
38 Dp_2d = obj.extendOperatorTo2D(Dp_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
39 Dm_2d = obj.extendOperatorTo2D(Dm_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
40 D2 = @(viscosity) Dm_2d{1}*spdiag(viscosity)*Dp_2d{1} + Dm_2d{2}*spdiag(viscosity)*Dp_2d{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
41 % m = g.size(); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
42 % ind = grid.funcToMatrix(g, 1:g.N()); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
43 % for i = 1:g.D() |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
44 % D2_2d{i} = sparse(zeros(g.N())); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
45 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
46 % % x-direction |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
47 % for i = 1:m(2) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
48 % p = ind(:,i); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
49 % D2_2d{1}(p,p) = @(viscosity) D2_1d{1}(viscosity(p)); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
50 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
51 % % y-direction |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
52 % for i = 1:m(1) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
53 % p = ind(i,:); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
54 % D2_2d{2}(p,p) = @(viscosity) D2_1d{2}(viscosity(p)); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
55 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
56 % D2 = D2_2d{1} + D2_2d{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
57 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
58 obj.d_l = obj.extendOperatorTo2D(d_l_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
59 obj.d_r = obj.extendOperatorTo2D(d_r_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
60 obj.e_l = obj.extendOperatorTo2D(e_l_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
61 obj.e_r = obj.extendOperatorTo2D(e_r_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
62 obj.H = kron(H_1d{1},H_1d{2}); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
63 obj.H_inv = kron(H_inv_1d{1},H_inv_1d{2}); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
64 obj.halfnorm_inv = obj.extendOperatorTo2D(H_inv_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
65 obj.waveSpeed = waveSpeed; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
66 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
67 % Dissipation operator |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
68 switch dissipation |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
69 case 'on' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
70 DissOp_2d = obj.extendOperatorTo2D(DissipationOp_1d, I); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
71 DissOp = DissOp_2d{1} + DissOp_2d{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
72 % max(abs()) or just abs()? |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
73 obj.D = @(v, viscosity) (-waveSpeed.*D1 + D2(viscosity) + abs(waveSpeed).*DissOp)*v; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
74 case 'off' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
75 obj.D = @(v, viscosity) (-waveSpeed.*D1 + D2(viscosity))*v; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
76 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
77 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
78 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
79 % Closure functions return the operators applied to the own doamin to close the boundary |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
80 % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other domain. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
81 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
82 % type is a string specifying the type of boundary condition if there are several. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
83 % data is a function returning the data that should be applied at the boundary. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
84 function [closure, penalty] = boundary_condition(obj,boundary,type,data) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
85 default_arg('type','robin'); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
86 default_arg('data',0); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
87 [e, d, halfnorm_inv, i_b, s] = obj.get_boundary_ops(boundary); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
88 switch type |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
89 case {'D', 'dirichlet'} |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
90 p = s*halfnorm_inv*e; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
91 closure = @(v,viscosity) p*(v(i_b)); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
92 case {'N', 'nuemann'} |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
93 p = s*halfnorm_inv*e; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
94 closure = @(v,viscosity) p*(viscosity(i_b).*d*v); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
95 case {'R', 'robin'} |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
96 p = s*halfnorm_inv*e; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
97 closure = @(v, viscosity) p*(obj.waveSpeed(i_b).*v(i_b) - 2*viscosity(i_b).*d*v); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
98 otherwise |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
99 error('No such boundary condition: type = %s',type); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
100 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
101 switch class(data) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
102 case 'double' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
103 penalty = s*p*data; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
104 case 'function_handle' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
105 penalty = @(t) s*p*data(t); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
106 otherwise |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
107 error('Wierd data argument!') |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
108 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
109 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
110 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
111 % Ruturns the boundary ops, half-norm, boundary indices and sign for the boundary specified by the string boundary. |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
112 % The right boundary for each coordinate direction is considered the positive boundary |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
113 function [e, d, halfnorm_inv, ind_boundary, s] = get_boundary_ops(obj,boundary) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
114 ind = grid.funcToMatrix(obj.grid, 1:obj.grid.N()); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
115 switch boundary |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
116 case 'w' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
117 e = obj.e_l{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
118 d = obj.d_l{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
119 halfnorm_inv = obj.halfnorm_inv{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
120 ind_boundary = ind(1,:); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
121 s = -1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
122 case 'e' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
123 e = obj.e_r{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
124 d = obj.d_r{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
125 halfnorm_inv = obj.halfnorm_inv{1}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
126 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
127 ind_boundary = ind(end,:); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
128 s = 1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
129 case 's' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
130 e = obj.e_l{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
131 d = obj.d_l{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
132 halfnorm_inv = obj.halfnorm_inv{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
133 ind_boundary = ind(:,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
134 s = -1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
135 case 'n' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
136 e = obj.e_r{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
137 d = obj.d_r{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
138 halfnorm_inv = obj.halfnorm_inv{2}; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
139 ind_boundary = ind(:,end); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
140 s = 1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
141 otherwise |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
142 error('No such boundary: boundary = %s',boundary); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
143 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
144 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
145 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
146 function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
147 error('An interface function does not exist yet'); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
148 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
149 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
150 function N = size(obj) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
151 N = obj.grid.m; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
152 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
153 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
154 |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
155 methods(Static) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
156 function [Dp, Dm, H, Hi, d_l, d_r, e_l, e_r, I, DissipationOp] = assemble1DOperators(g, operator_type, order, dissipation) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
157 dim = g.D(); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
158 I = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
159 D1 = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
160 D2 = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
161 H = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
162 Hi = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
163 e_l = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
164 e_r = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
165 d1_l = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
166 d1_r = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
167 DissipationOp = cell(dim,1); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
168 for i = 1:dim |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
169 switch operator_type |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
170 % case 'narrow' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
171 % ops = sbp.D4Variable(g.m(i), g.lim{i}, order); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
172 % D1{i} = ops.D1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
173 % D2{i} = ops.D2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
174 % d_l{i} = ops.d1_l'; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
175 % d_r{i} = ops.d1_r'; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
176 % if (strcmp(dissipation,'on')) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
177 % DissipationOp{i} = -1*sbp.dissipationOperator(g.m(i), order, ops.HI); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
178 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
179 % case 'upwind-' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
180 % ops = sbp.D1Upwind(g.m(i), g.lim{i}, order); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
181 % D1{i} = (ops.Dp + ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
182 % D2{i} = @(viscosity) ops.Dp*spdiag(viscosity)*ops.Dm; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
183 % d_l{i} = ops.e_l'*ops.Dm; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
184 % d_r{i} = ops.e_r'*ops.Dm; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
185 % if (strcmp(dissipation,'on')) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
186 % DissipationOp{i} = (ops.Dp-ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
187 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
188 case 'upwind+' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
189 ops = sbp.D1Upwind(g.m(i), g.lim{i}, order); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
190 Dp{i} = ops.Dp; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
191 Dm{i} = ops.Dm; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
192 % D1{i} = (ops.Dp + ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
193 % D2{i} = @(viscosity) ops.Dm*spdiag(viscosity)*ops.Dp; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
194 d_l{i} = ops.e_l'*ops.Dp; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
195 d_r{i} = ops.e_r'*ops.Dp; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
196 if (strcmp(dissipation,'on')) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
197 DissipationOp{i} = (ops.Dp-ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
198 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
199 % case 'upwind+-' |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
200 % ops = sbp.D1Upwind(g.m(i), g.lim{i}, order); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
201 % D1{i} = (ops.Dp + ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
202 % D2{i} = @(viscosity) (ops.Dp*spdiag(viscosity)*ops.Dm + ops.Dm*spdiag(viscosity)*ops.Dp)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
203 % d_l{i} = ops.e_l'*D1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
204 % d_r{i} = ops.e_r'*D1; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
205 % if (strcmp(dissipation,'on')) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
206 % DissipationOp{i} = (ops.Dp-ops.Dm)/2; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
207 % end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
208 otherwise |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
209 error('Other operator types not yet supported', operator_type); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
210 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
211 H{i} = ops.H; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
212 Hi{i} = ops.HI; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
213 e_l{i} = ops.e_l; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
214 e_r{i} = ops.e_r; |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
215 I{i} = speye(g.m(i)); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
216 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
217 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
218 function op_2d = extendOperatorTo2D(op, I) |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
219 op_2d{1} = kr(op{1}, I{2}); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
220 op_2d{2} = kr(I{1}, op{2}); |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
221 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
222 end |
87809b4762c9
Draft implementation of scheme for advection with RV
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
223 end |