Mercurial > repos > public > sbplib
annotate +scheme/Laplace1d.m @ 1198:2924b3a9b921 feature/d2_compatible
Add OpSet for fully compatible D2Variable, created from regular D2Variable by replacing d1 by first row of D1. Formal reduction by one order of accuracy at the boundary point.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Fri, 16 Aug 2019 14:30:28 -0700 |
parents | 33c378e508d2 |
children |
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 | |
1082
a20fc67e9ac0
Add d and n as acceptable boundary condition identifiers, which is consistent with eg LaplaceCurvilinear.
Martin Almquist <malmquist@stanford.edu>
parents:
1079
diff
changeset
|
65 case {'D','d','dirichlet'} |
0 | 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'; |
1116
33c378e508d2
Bugfix minus sign in Laplace1d Dirichlet penalty.
Martin Almquist <malmquist@stanford.edu>
parents:
1083
diff
changeset
|
73 penalty = -obj.a*obj.Hi*tau; |
0 | 74 |
75 % Neumann boundary condition | |
1082
a20fc67e9ac0
Add d and n as acceptable boundary condition identifiers, which is consistent with eg LaplaceCurvilinear.
Martin Almquist <malmquist@stanford.edu>
parents:
1079
diff
changeset
|
76 case {'N','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 | |
1047
6bc55a773e7c
Fix some mistakes from dc1bcbef2a86
Jonatan Werpers <jonatan@werpers.com>
parents:
1046
diff
changeset
|
91 e_u = obj.getBoundaryOperator('e', boundary); |
6bc55a773e7c
Fix some mistakes from dc1bcbef2a86
Jonatan Werpers <jonatan@werpers.com>
parents:
1046
diff
changeset
|
92 d_u = 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
|
93 s_u = obj.getBoundarySign(boundary); |
898 | 94 |
1047
6bc55a773e7c
Fix some mistakes from dc1bcbef2a86
Jonatan Werpers <jonatan@werpers.com>
parents:
1046
diff
changeset
|
95 e_v = neighbour_scheme.getBoundaryOperator('e', neighbour_boundary); |
6bc55a773e7c
Fix some mistakes from dc1bcbef2a86
Jonatan Werpers <jonatan@werpers.com>
parents:
1046
diff
changeset
|
96 d_v = neighbour_scheme.getBoundaryOperator('d', neighbour_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
|
97 s_v = neighbour_scheme.getBoundarySign(neighbour_boundary); |
0 | 98 |
898 | 99 a_u = obj.a; |
100 a_v = neighbour_scheme.a; | |
0 | 101 |
102 gamm_u = obj.gamm; | |
103 gamm_v = neighbour_scheme.gamm; | |
104 | |
898 | 105 tuning = 1.1; |
946
706d1c2b4199
Raname opts to type in a bunch of interface methods
Jonatan Werpers <jonatan@werpers.com>
parents:
943
diff
changeset
|
106 |
1083
a22b23098021
Divide interface penalty strength by 4, to make it sharp. Stability verified by eigenvalue computations.
Martin Almquist <malmquist@stanford.edu>
parents:
1082
diff
changeset
|
107 tau1 = -1/4*(a_u/gamm_u + a_v/gamm_v) * tuning; |
898 | 108 tau2 = 1/2*a_u; |
109 sig1 = -1/2; | |
0 | 110 sig2 = 0; |
111 | |
112 tau = tau1*e_u + tau2*d_u; | |
113 sig = sig1*e_u + sig2*d_u; | |
114 | |
898 | 115 closure = obj.Hi*( tau*e_u' + sig*a_u*d_u'); |
116 penalty = obj.Hi*(-tau*e_v' + sig*a_v*d_v'); | |
0 | 117 end |
118 | |
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 % 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
|
120 % 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
|
121 % 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
|
122 function o = getBoundaryOperator(obj, op, boundary) |
1046
19ed046aec52
Clean up getBoundaryOps for a few schemes
Jonatan Werpers <jonatan@werpers.com>
parents:
1045
diff
changeset
|
123 assertIsMember(op, {'e', 'd'}) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
124 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
|
125 |
1079
ae4b090b5299
Bugfix missing semi-colon in Laplace1d.
Martin Almquist <malmquist@stanford.edu>
parents:
1049
diff
changeset
|
126 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
|
127 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
|
128 |
1049
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
129 % Returns square boundary quadrature matrix, of dimension |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
130 % corresponding to the number of boundary points |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
131 % |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
132 % boundary -- string |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
133 % Note: for 1d diffOps, the boundary quadrature is the scalar 1. |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
134 function H_b = getBoundaryQuadrature(obj, boundary) |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
135 assertIsMember(boundary, {'l', 'r'}) |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
136 |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
137 H_b = 1; |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
138 end |
0c504a21432d
Add getBoundaryQuadrature to all 1d diffOps
Martin Almquist <malmquist@stanford.edu>
parents:
1047
diff
changeset
|
139 |
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
|
140 % 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
|
141 % 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
|
142 function s = getBoundarySign(obj, boundary) |
1042
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
143 assertIsMember(boundary, {'l', 'r'}) |
8d73fcdb07a5
Add asserts to boundary identifier inputs
Jonatan Werpers <jonatan@werpers.com>
parents:
998
diff
changeset
|
144 |
0 | 145 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
|
146 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
|
147 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
|
148 case {'l'} |
0 | 149 s = -1; |
150 end | |
151 end | |
152 | |
153 function N = size(obj) | |
898 | 154 N = obj.grid.size(); |
0 | 155 end |
156 | |
157 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
|
158 end |