annotate diracDiscr1D.m @ 1136:eee71789f13b feature/laplace_curvilinear_test

Add LaplaceCurvilinear schemes where the minimum check will be implemented. The Virta scheme will be used for comparison only.
author Martin Almquist <malmquist@stanford.edu>
date Mon, 10 Jun 2019 10:43:12 +0200
parents b29892853daf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1129
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
1 % Generates discrete 1D delta function
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
2 function ret = diracDiscr1D(x_0in , x , m_order, s_order, H)
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
3
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
4 m = length(x);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
5
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
6 % Return zeros if x0 is outside grid
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
7 if(x_0in < x(1) || x_0in > x(end) )
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
8
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
9 ret = zeros(size(x));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
10
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
11 else
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
12
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
13 fnorm = diag(H);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
14 eta = abs(x-x_0in);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
15 tot = m_order+s_order;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
16 S = [];
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
17 M = [];
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
18
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
19 % Get interior grid spacing
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
20 middle = floor(m/2);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
21 h = x(middle+1) - x(middle);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
22
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
23 poss = find(tot*h/2 >= eta);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
24
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
25 % Ensure that poss is not too long
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
26 if length(poss) == (tot + 2)
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
27 poss = poss(2:end-1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
28 elseif length(poss) == (tot + 1)
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
29 poss = poss(1:end-1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
30 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
31
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
32 % Use first tot grid points
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
33 if length(poss)<tot && x_0in < x(1) + ceil(tot/2)*h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
34 index=1:tot;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
35 pol=(x(1:tot)-x(1))/(x(tot)-x(1));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
36 x_0=(x_0in-x(1))/(x(tot)-x(1));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
37 norm=fnorm(1:tot)/h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
38
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
39 % Use last tot grid points
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
40 elseif length(poss)<tot && x_0in > x(end) - ceil(tot/2)*h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
41 index = length(x)-tot+1:length(x);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
42 pol = (x(end-tot+1:end)-x(end-tot+1))/(x(end)-x(end-tot+1));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
43 norm = fnorm(end-tot+1:end)/h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
44 x_0 = (x_0in-x(end-tot+1))/(x(end)-x(end-tot+1));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
45
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
46 % Interior, compensate for round-off errors.
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
47 elseif length(poss) < tot
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
48 if poss(end)<m
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
49 poss = [poss; poss(end)+1];
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
50 else
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
51 poss = [poss(1)-1; poss];
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
52 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
53 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1)));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
54 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1)));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
55 norm = fnorm(poss)/h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
56 index = poss;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
57
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
58 % Interior
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
59 else
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
60 pol = (x(poss)-x(poss(1)))/(x(poss(end))-x(poss(1)));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
61 x_0 = (x_0in-x(poss(1)))/(x(poss(end))-x(poss(1)));
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
62 norm = fnorm(poss)/h;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
63 index = poss;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
64 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
65
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
66 h_pol = pol(2)-pol(1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
67 b = zeros(m_order+s_order,1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
68
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
69 for i = 1:m_order
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
70 b(i,1) = x_0^(i-1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
71 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
72
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
73 for i = 1:(m_order+s_order)
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
74 for j = 1:m_order
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
75 M(j,i) = pol(i)^(j-1)*h_pol*norm(i);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
76 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
77 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
78
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
79 for i = 1:(m_order+s_order)
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
80 for j = 1:s_order
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
81 S(j,i) = (-1)^(i-1)*pol(i)^(j-1);
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
82 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
83 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
84
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
85 A = [M;S];
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
86
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
87 d = A\b;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
88 ret = x*0;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
89 ret(index) = d/h*h_pol;
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
90 end
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
91
b29892853daf Refactor diracDiscr.m by moving the helper function diracDiscr1D to a separate file.
Martin Almquist <malmquist@stanford.edu>
parents:
diff changeset
92 end