Mercurial > repos > public > sbplib
annotate +scheme/Laplace1d.m @ 1046:19ed046aec52 feature/getBoundaryOp
Clean up getBoundaryOps for a few schemes
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 22 Jan 2019 17:37:07 +0100 |
parents | dc1bcbef2a86 |
children | 6bc55a773e7c |
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 | |
1045
dc1bcbef2a86
Remove ability to get several boundary ops at the same time from a few of the schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1044
diff
changeset
|
59 e = obj.getBoundaryOperator('e', boundary); |
dc1bcbef2a86
Remove ability to get several boundary ops at the same time from a few of the schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1044
diff
changeset
|
60 d = obj.getBoundaryOperator('d', 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
|
61 s = obj.getBoundarySign(boundary); |
0 | 62 |
63 switch type | |
64 % Dirichlet boundary condition | |
65 case {'D','dirichlet'} | |
66 tuning = 1.1; | |
898 | 67 tau1 = -tuning/obj.gamm; |
68 tau2 = 1; | |
0 | 69 |
898 | 70 tau = tau1*e + tau2*d; |
0 | 71 |
898 | 72 closure = obj.a*obj.Hi*tau*e'; |
73 penalty = obj.a*obj.Hi*tau; | |
0 | 74 |
75 % Neumann boundary condition | |
76 case {'N','neumann'} | |
898 | 77 tau = -e; |
0 | 78 |
898 | 79 closure = obj.a*obj.Hi*tau*d'; |
80 penalty = -obj.a*obj.Hi*tau; | |
0 | 81 |
82 % Unknown, boundary condition | |
83 otherwise | |
84 error('No such boundary condition: type = %s',type); | |
85 end | |
86 end | |
87 | |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
943
diff
changeset
|
88 function [closure, penalty] = interface(obj, boundary, neighbour_scheme, neighbour_boundary, type) |
0 | 89 % u denotes the solution in the own domain |
90 % 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
|
91 [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
|
92 s_u = obj.getBoundarySign(boundary); |
898 | 93 |
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
|
94 [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
|
95 s_v = neighbour_scheme.getBoundarySign(neighbour_boundary); |
0 | 96 |
898 | 97 a_u = obj.a; |
98 a_v = neighbour_scheme.a; | |
0 | 99 |
100 gamm_u = obj.gamm; | |
101 gamm_v = neighbour_scheme.gamm; | |
102 | |
898 | 103 tuning = 1.1; |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
943
diff
changeset
|
104 |
898 | 105 tau1 = -(a_u/gamm_u + a_v/gamm_v) * tuning; |
106 tau2 = 1/2*a_u; | |
107 sig1 = -1/2; | |
0 | 108 sig2 = 0; |
109 | |
110 tau = tau1*e_u + tau2*d_u; | |
111 sig = sig1*e_u + sig2*d_u; | |
112 | |
898 | 113 closure = obj.Hi*( tau*e_u' + sig*a_u*d_u'); |
114 penalty = obj.Hi*(-tau*e_v' + sig*a_v*d_v'); | |
0 | 115 end |
116 | |
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
|
117 % Returns the boundary operator op for the boundary specified by the string boundary. |
1045
dc1bcbef2a86
Remove ability to get several boundary ops at the same time from a few of the schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1044
diff
changeset
|
118 % op -- string |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
119 % boundary -- string |
1045
dc1bcbef2a86
Remove ability to get several boundary ops at the same time from a few of the schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1044
diff
changeset
|
120 function o = getBoundaryOperator(obj, op, boundary) |
1046
19ed046aec52
Clean up getBoundaryOps for a few schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1045
diff
changeset
|
121 assertIsMember(op, {'e', 'd'}) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
122 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
|
123 |
1046
19ed046aec52
Clean up getBoundaryOps for a few schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1045
diff
changeset
|
124 o = obj.([op, '_', boundary]) |
998
2b1b944deae1
Add getBoundaryOperator to all 1d schemes. Did not add getBoundaryQuadrature because it doesnt make sense in 1d (?)
Martin Almquist <malmquist@stanford.edu>
parents:
950
diff
changeset
|
125 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
|
126 |
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 % 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
|
128 % 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
|
129 function s = getBoundarySign(obj, boundary) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
130 assertIsMember(boundary, {'l', 'r'}) |
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
131 |
0 | 132 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
|
133 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
|
134 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
|
135 case {'l'} |
0 | 136 s = -1; |
137 end | |
138 end | |
139 | |
140 function N = size(obj) | |
898 | 141 N = obj.grid.size(); |
0 | 142 end |
143 | |
144 end | |
1043
c12b84fe9b00
Remove static method `interface_coupling` that shouldn't have existed in the first place
Jonatan Werpers <jonatan@werpers.com>
parents:
950
diff
changeset
|
145 end |