Mercurial > repos > public > sbplib
annotate +scheme/Laplace1dVariable.m @ 1324:56439c1a49b4 feature/laplace1d_variable
Bugifx penalty sign.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Sun, 27 Jun 2021 16:19:28 +0200 |
parents | 3f4e011193f0 |
children |
rev | line source |
---|---|
1323
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 classdef Laplace1dVariable < scheme.Scheme |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 properties |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 grid |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 order % Order accuracy for the approximation |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
5 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
6 D % scheme operator |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
7 H % Discrete norm |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
8 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 % Variable coefficients a(b u_x)_x |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 a |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 b |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 Hi |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
14 e_l |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 e_r |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 d_l |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 d_r |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 gamm |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
19 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
20 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
21 methods |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
22 function obj = Laplace1dVariable(g, order, a, b) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 default_arg('a', @(x) 0*x + 1); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 default_arg('b', @(x) 0*x + 1); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 assertType(g, 'grid.Cartesian'); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 ops = sbp.D2Variable(g.size(), g.lim{1}, order); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 obj.H = sparse(ops.H); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 obj.Hi = sparse(ops.HI); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
32 obj.e_l = sparse(ops.e_l); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 obj.e_r = sparse(ops.e_r); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 obj.d_l = -sparse(ops.d1_l); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 obj.d_r = sparse(ops.d1_r); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 obj.grid = g; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 obj.order = order; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 a = grid.evalOn(g, a); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 b = grid.evalOn(g, b); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 A = spdiag(a); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
45 B = spdiag(b); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 obj.a = A; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 obj.b = B; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
50 obj.D = A*ops.D2(b); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
51 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
52 obj.gamm = g.h*ops.borrowing.M.d1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
53 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 % Closure functions return the opertors applied to the own doamin to close the boundary |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 % Penalty functions return the opertors to force the solution. In the case of an interface it returns the operator applied to the other doamin. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 % boundary is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 % type is a string specifying the type of boundary condition if there are several. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 % data is a function returning the data that should be applied at the boundary. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 % neighbour_scheme is an instance of Scheme that should be interfaced to. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 % neighbour_boundary is a string specifying which boundary to interface to. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
63 function [closure, penalty] = boundary_condition(obj,boundary,type,data) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 default_arg('type','neumann'); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 default_arg('data',0); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 e = obj.getBoundaryOperator('e', boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 d = obj.getBoundaryOperator('d', boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 s = obj.getBoundarySign(boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 b = e'*obj.b*e; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
72 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
73 switch type |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
74 % Dirichlet boundary condition |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
75 case {'D','d','dirichlet'} |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
76 tuning = 1.1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
77 tau1 = -tuning/obj.gamm; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
78 tau2 = 1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
79 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
80 tau = tau1*e + tau2*d; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
81 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
82 closure = obj.a*obj.Hi*tau*b*e'; |
1324
56439c1a49b4
Bugifx penalty sign.
Martin Almquist <malmquist@stanford.edu>
parents:
1323
diff
changeset
|
83 penalty = -obj.a*obj.Hi*tau*b; |
1323
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
84 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
85 % Neumann boundary condition |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
86 case {'N','n','neumann'} |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
87 tau = -e; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
88 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
89 closure = obj.a*obj.Hi*tau*b*d'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
90 penalty = -obj.a*obj.Hi*tau*b; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
91 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
92 % Unknown, boundary condition |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
93 otherwise |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
94 error('No such boundary condition: type = %s',type); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
95 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
96 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
97 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
98 function [closure, penalty] = interface(obj, boundary, neighbour_scheme, neighbour_boundary, type) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
99 % u denotes the solution in the own domain |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
100 % v denotes the solution in the neighbour domain |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
101 e_u = obj.getBoundaryOperator('e', boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
102 d_u = obj.getBoundaryOperator('d', boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
103 s_u = obj.getBoundarySign(boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
104 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
105 e_v = neighbour_scheme.getBoundaryOperator('e', neighbour_boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
106 d_v = neighbour_scheme.getBoundaryOperator('d', neighbour_boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
107 s_v = neighbour_scheme.getBoundarySign(neighbour_boundary); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
108 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
109 b_u = e_u'*obj.b*e_u; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
110 b_v = e_v'*neighbour_scheme.b*e_v; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
111 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
112 gamm_u = obj.gamm; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
113 gamm_v = neighbour_scheme.gamm; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
114 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
115 tuning = 1.1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
116 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
117 closure = zeros(size(obj.D)); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
118 penalty = zeros(length(obj.D), length(b_v)); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
119 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
120 % Continuity of bu_x |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
121 closure = closure - 1/2*e_u*b_u*d_u'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
122 penalty = penalty - 1/2*e_u*b_v*d_v'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
123 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
124 % Continuity of u (symmetrizing term) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
125 closure = closure + 1/2*d_u*b_u*e_u'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
126 penalty = penalty - 1/2*d_u*b_u*e_v'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
127 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
128 % Continuity of u (symmetric term) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
129 tau = 1/4*(b_u/gamm_u + b_v/gamm_v)*tuning; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
130 closure = closure - e_u*tau*e_u'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
131 penalty = penalty + e_u*tau*e_v'; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
132 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
133 % Multiply by Hi and a. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
134 closure = obj.Hi*obj.a*closure; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
135 penalty = obj.Hi*obj.a*penalty; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
136 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
137 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
138 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
139 % Returns the boundary operator op for the boundary specified by the string boundary. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
140 % op -- string |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
141 % boundary -- string |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
142 function o = getBoundaryOperator(obj, op, boundary) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
143 assertIsMember(op, {'e', 'd'}) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
144 assertIsMember(boundary, {'l', 'r'}) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
145 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
146 o = obj.([op, '_', boundary]); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
147 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
148 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
149 % Returns square boundary quadrature matrix, of dimension |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
150 % corresponding to the number of boundary points |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
151 % |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
152 % boundary -- string |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
153 % Note: for 1d diffOps, the boundary quadrature is the scalar 1. |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
154 function H_b = getBoundaryQuadrature(obj, boundary) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
155 assertIsMember(boundary, {'l', 'r'}) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
156 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
157 H_b = 1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
158 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
159 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
160 % Returns the boundary sign. The right boundary is considered the positive boundary |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
161 % boundary -- string |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
162 function s = getBoundarySign(obj, boundary) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
163 assertIsMember(boundary, {'l', 'r'}) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
164 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
165 switch boundary |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
166 case {'r'} |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
167 s = 1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
168 case {'l'} |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
169 s = -1; |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
170 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
171 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
172 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
173 function N = size(obj) |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
174 N = obj.grid.size(); |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
175 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
176 |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
177 end |
3f4e011193f0
First implementation of Laplace1dVariable. Passes symmetry and definiteness tests.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
178 end |