Mercurial > repos > public > sbplib
annotate +scheme/Laplace1d.m @ 1042:8d73fcdb07a5 feature/getBoundaryOp
Add asserts to boundary identifier inputs
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 22 Jan 2019 16:47:34 +0100 |
parents | 2b1b944deae1 |
children | 5afc774fb7c4 |
rev | line source |
---|---|
950
cab047de7f5d
Rename *2D schemes to *2d
Jonatan Werpers <jonatan@werpers.com>
parents:
946
diff
changeset
|
1 classdef Laplace1d < scheme.Scheme |
0 | 2 properties |
898 | 3 grid |
0 | 4 order % Order accuracy for the approximation |
5 | |
6 D % non-stabalized scheme operator | |
7 H % Discrete norm | |
8 M % Derivative norm | |
896
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
9 a |
0 | 10 |
11 D2 | |
12 Hi | |
13 e_l | |
14 e_r | |
896
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
15 d_l |
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
16 d_r |
0 | 17 gamm |
18 end | |
19 | |
20 methods | |
950
cab047de7f5d
Rename *2D schemes to *2d
Jonatan Werpers <jonatan@werpers.com>
parents:
946
diff
changeset
|
21 function obj = Laplace1d(grid, order, a) |
896
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
22 default_arg('a', 1); |
0 | 23 |
898 | 24 assertType(grid, 'grid.Cartesian'); |
896
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
25 |
898 | 26 ops = sbp.D2Standard(grid.size(), grid.lim{1}, order); |
0 | 27 |
898 | 28 obj.D2 = sparse(ops.D2); |
29 obj.H = sparse(ops.H); | |
30 obj.Hi = sparse(ops.HI); | |
31 obj.M = sparse(ops.M); | |
32 obj.e_l = sparse(ops.e_l); | |
33 obj.e_r = sparse(ops.e_r); | |
34 obj.d_l = -sparse(ops.d1_l); | |
35 obj.d_r = sparse(ops.d1_r); | |
0 | 36 |
37 | |
898 | 38 obj.grid = grid; |
0 | 39 obj.order = order; |
40 | |
896
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
41 obj.a = a; |
09c5fbc783d3
Rename and mordernize scheme.Wave to scheme.Laplace1d. Not fully converted
Jonatan Werpers <jonatan@werpers.com>
parents:
141
diff
changeset
|
42 obj.D = a*obj.D2; |
0 | 43 |
898 | 44 obj.gamm = grid.h*ops.borrowing.M.S; |
0 | 45 end |
46 | |
47 | |
48 % Closure functions return the opertors applied to the own doamin to close the boundary | |
49 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. | |
50 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. | |
51 % type is a string specifying the type of boundary condition if there are several. | |
52 % data is a function returning the data that should be applied at the boundary. | |
53 % neighbour_scheme is an instance of Scheme that should be interfaced to. | |
54 % neighbour_boundary is a string specifying which boundary to interface to. | |
55 function [closure, penalty] = boundary_condition(obj,boundary,type,data) | |
56 default_arg('type','neumann'); | |
57 default_arg('data',0); | |
58 | |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
59 [e, d] = obj.getBoundaryOperator({'e', 'd'}, boundary); |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
60 s = obj.getBoundarySign(boundary); |
0 | 61 |
62 switch type | |
63 % Dirichlet boundary condition | |
64 case {'D','dirichlet'} | |
65 tuning = 1.1; | |
898 | 66 tau1 = -tuning/obj.gamm; |
67 tau2 = 1; | |
0 | 68 |
898 | 69 tau = tau1*e + tau2*d; |
0 | 70 |
898 | 71 closure = obj.a*obj.Hi*tau*e'; |
72 penalty = obj.a*obj.Hi*tau; | |
0 | 73 |
74 % Neumann boundary condition | |
75 case {'N','neumann'} | |
898 | 76 tau = -e; |
0 | 77 |
898 | 78 closure = obj.a*obj.Hi*tau*d'; |
79 penalty = -obj.a*obj.Hi*tau; | |
0 | 80 |
81 % Unknown, boundary condition | |
82 otherwise | |
83 error('No such boundary condition: type = %s',type); | |
84 end | |
85 end | |
86 | |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
943
diff
changeset
|
87 function [closure, penalty] = interface(obj, boundary, neighbour_scheme, neighbour_boundary, type) |
0 | 88 % u denotes the solution in the own domain |
89 % v denotes the solution in the neighbour domain | |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
90 [e_u, d_u] = obj.getBoundaryOperator({'e', 'd'}, boundary); |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
91 s_u = obj.getBoundarySign(boundary); |
898 | 92 |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
93 [e_v, d_v] = neighbour_scheme.getBoundaryOperator({'e', 'd'}, neighbour_boundary); |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
94 s_v = neighbour_scheme.getBoundarySign(neighbour_boundary); |
0 | 95 |
898 | 96 a_u = obj.a; |
97 a_v = neighbour_scheme.a; | |
0 | 98 |
99 gamm_u = obj.gamm; | |
100 gamm_v = neighbour_scheme.gamm; | |
101 | |
898 | 102 tuning = 1.1; |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
943
diff
changeset
|
103 |
898 | 104 tau1 = -(a_u/gamm_u + a_v/gamm_v) * tuning; |
105 tau2 = 1/2*a_u; | |
106 sig1 = -1/2; | |
0 | 107 sig2 = 0; |
108 | |
109 tau = tau1*e_u + tau2*d_u; | |
110 sig = sig1*e_u + sig2*d_u; | |
111 | |
898 | 112 closure = obj.Hi*( tau*e_u' + sig*a_u*d_u'); |
113 penalty = obj.Hi*(-tau*e_v' + sig*a_v*d_v'); | |
0 | 114 end |
115 | |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
116 % Returns the boundary operator op for the boundary specified by the string boundary. |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
117 % op -- string or a cell array of strings |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
118 % boundary -- string |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
119 function varargout = getBoundaryOperator(obj, op, boundary) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
120 assertIsMember(boundary, {'l', 'r'}) |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
121 |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
122 if ~iscell(op) |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
123 op = {op}; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
124 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
125 |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
126 for i = 1:numel(op) |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
127 switch op{i} |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
128 case 'e' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
129 switch boundary |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
130 case 'l' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
131 e = obj.e_l; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
132 case 'r' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
133 e = obj.e_r; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
134 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
135 varargout{i} = e; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
136 |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
137 case 'd' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
138 switch boundary |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
139 case 'l' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
140 d = obj.d_l; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
141 case 'r' |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
142 d = obj.d_r; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
143 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
144 varargout{i} = d; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
145 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
146 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
147 end |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
148 |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
149 % Returns the boundary sign. The right boundary is considered the positive boundary |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
150 % boundary -- string |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
151 function s = getBoundarySign(obj, boundary) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
152 assertIsMember(boundary, {'l', 'r'}) |
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
153 |
0 | 154 switch boundary |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
155 case {'r'} |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
156 s = 1; |
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
157 case {'l'} |
0 | 158 s = -1; |
159 end | |
160 end | |
161 | |
162 function N = size(obj) | |
898 | 163 N = obj.grid.size(); |
0 | 164 end |
165 | |
166 end | |
167 | |
168 methods(Static) | |
169 % Calculates the matrcis need for the inteface coupling between boundary bound_u of scheme schm_u | |
170 % and bound_v of scheme schm_v. | |
171 % [uu, uv, vv, vu] = inteface_couplong(A,'r',B,'l') | |
172 function [uu, uv, vv, vu] = interface_coupling(schm_u,bound_u,schm_v,bound_v) | |
173 [uu,uv] = schm_u.interface(bound_u,schm_v,bound_v); | |
174 [vv,vu] = schm_v.interface(bound_v,schm_u,bound_u); | |
175 end | |
176 end | |
177 end |