Mercurial > repos > public > sbplib
annotate diracDiscrCurve.m @ 1244:745dc1f1a069 feature/dirac_discr
Use assertType instead of assert(isa(...))
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 20 Nov 2019 20:22:53 +0100 |
parents | 1fbd93f24bed |
children | 25efceb0c392 |
rev | line source |
---|---|
1230 | 1 function d = diracDiscrCurve(x_s, g, m_order, s_order, order, opSet) |
2 % 2-dimensional delta function for single-block curvilinear grid | |
1240
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
3 % x_s: source point coordinate vector, e.g. [x; y] or [x; y; z]. |
1230 | 4 % g: single-block grid containing the source |
5 % m_order: Number of moment conditions | |
6 % s_order: Number of smoothness conditions | |
7 % order: Order of SBP derivative approximations | |
8 % opSet: Cell array of function handle to opSet generator | |
9 | |
10 default_arg('order', m_order); | |
11 default_arg('opSet', {@sbp.D2Variable, @sbp.D2Variable}); | |
12 | |
13 dim = length(x_s); | |
14 assert(dim == 2, 'diracDiscrCurve: Only implemented for 2d.'); | |
1244
745dc1f1a069
Use assertType instead of assert(isa(...))
Jonatan Werpers <jonatan@werpers.com>
parents:
1240
diff
changeset
|
15 assertType(g, 'grid.Curvilinear'); |
1230 | 16 |
1240
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
17 % Compute Jacobian |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
18 J = jacobian(g, opSet, order); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
19 |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
20 % Find approximate logical coordinates of point source |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
21 X = g.points(); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
22 U = g.logic.points(); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
23 U_interp = scatteredInterpolant(X, U(:,1)); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
24 V_interp = scatteredInterpolant(X, U(:,2)); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
25 uS = U_interp(x_s); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
26 vS = V_interp(x_s); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
27 |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
28 % Get quadrature matrices for moment conditions |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
29 m = g.size(); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
30 ops_u = opSet{1}(m(1), {0, 1}, order); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
31 ops_v = opSet{2}(m(2), {0, 1}, order); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
32 H_u = ops_u.H; |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
33 H_v = ops_v.H; |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
34 |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
35 % Get delta function for logical grid and scale by Jacobian |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
36 d = (1./J).*diracDiscr(g, [uS; vS], m_order, s_order, {H_u, H_v}); |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
37 |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
38 end |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
39 |
1fbd93f24bed
Factor out Jacobian computation in diracDiscrCurve.m
Martin Almquist <malmquist@stanford.edu>
parents:
1230
diff
changeset
|
40 function J = jacobian(g, opSet, order) |
1230 | 41 m = g.size(); |
42 m_u = m(1); | |
43 m_v = m(2); | |
44 ops_u = opSet{1}(m_u, {0, 1}, order); | |
45 ops_v = opSet{2}(m_v, {0, 1}, order); | |
46 I_u = speye(m_u); | |
47 I_v = speye(m_v); | |
48 | |
49 D1_u = ops_u.D1; | |
50 D1_v = ops_v.D1; | |
51 | |
52 Du = kr(D1_u,I_v); | |
53 Dv = kr(I_u,D1_v); | |
54 | |
55 coords = g.points(); | |
56 x = coords(:,1); | |
57 y = coords(:,2); | |
58 | |
59 x_u = Du*x; | |
60 x_v = Dv*x; | |
61 y_u = Du*y; | |
62 y_v = Dv*y; | |
63 | |
64 J = x_u.*y_v - x_v.*y_u; | |
65 end |