changeset 1242:ff613067dec6 feature/dirac_discr

Merge heads
author Martin Almquist <malmquist@stanford.edu>
date Tue, 19 Nov 2019 17:04:32 -0800
parents d1b201fe328e (diff) a0940c1db455 (current diff)
children 4e0b88f3def1
files diracDiscr.m
diffstat 2 files changed, 28 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/diracDiscr.m	Tue Nov 19 16:21:26 2019 -0800
+++ b/diracDiscr.m	Tue Nov 19 17:04:32 2019 -0800
@@ -2,7 +2,7 @@
 function d = diracDiscr(g, x_s, m_order, s_order, H)
     % n-dimensional delta function
     % g: cartesian grid
-    % x_s: source point coordinate vector, e.g. [x, y] or [x, y, z].
+    % x_s: source point coordinate vector, e.g. [x; y] or [x; y; z].
     % m_order: Number of moment conditions
     % s_order: Number of smoothness conditions
     % H: cell array of 1D norm matrices
@@ -30,7 +30,7 @@
 
 
 % Helper function for 1D delta functions
-function ret = diracDiscr1D(x_s , x , m_order, s_order, H)
+function ret = diracDiscr1D(x_s, x, m_order, s_order, H)
 
     % Return zeros if x0 is outside grid
     if x_s < x(1) || x_s > x(end)
@@ -49,7 +49,7 @@
 
         polynomial = (x(index)-x(index(1)))/(x(index(end))-x(index(1)));
         x_0 = (x_s-x(index(1)))/(x(index(end))-x(index(1)));
-        
+
         quadrature = diag(H);
         quadrature_weights = quadrature(index)/h;
 
--- a/diracDiscrCurve.m	Tue Nov 19 16:21:26 2019 -0800
+++ b/diracDiscrCurve.m	Tue Nov 19 17:04:32 2019 -0800
@@ -1,6 +1,6 @@
 function d = diracDiscrCurve(x_s, g, m_order, s_order, order, opSet)
     % 2-dimensional delta function for single-block curvilinear grid
-    % x_s:      source point coordinate vector, e.g. [x, y] or [x, y, z].
+    % x_s:      source point coordinate vector, e.g. [x; y] or [x; y; z].
     % g:        single-block grid containing the source
     % m_order:  Number of moment conditions
     % s_order:  Number of smoothness conditions
@@ -14,6 +14,30 @@
     assert(dim == 2, 'diracDiscrCurve: Only implemented for 2d.');
     assert(isa(g, 'grid.Curvilinear'));
 
+    % Compute Jacobian
+    J = jacobian(g, opSet, order);
+
+    % Find approximate logical coordinates of point source
+    X = g.points();
+    U = g.logic.points();
+    U_interp = scatteredInterpolant(X, U(:,1));
+    V_interp = scatteredInterpolant(X, U(:,2));
+    uS = U_interp(x_s);
+    vS = V_interp(x_s);
+
+    % Get quadrature matrices for moment conditions
+    m = g.size();
+    ops_u = opSet{1}(m(1), {0, 1}, order);
+    ops_v = opSet{2}(m(2), {0, 1}, order);
+    H_u =  ops_u.H;
+    H_v =  ops_v.H;
+
+    % Get delta function for logical grid and scale by Jacobian
+    d = (1./J).*diracDiscr(g, [uS; vS], m_order, s_order, {H_u, H_v});
+
+end
+
+function J = jacobian(g, opSet, order)
     m = g.size();
     m_u = m(1);
     m_v = m(2);
@@ -23,18 +47,11 @@
     I_v = speye(m_v);
 
     D1_u = ops_u.D1;
-    H_u =  ops_u.H;
-
     D1_v = ops_v.D1;
-    H_v =  ops_v.H;
 
     Du = kr(D1_u,I_v);
     Dv = kr(I_u,D1_v);
 
-    u = ops_u.x;
-    v = ops_v.x;
-
-    % Compute Jacobian
     coords = g.points();
     x = coords(:,1);
     y = coords(:,2);
@@ -45,14 +62,4 @@
     y_v = Dv*y;
 
     J = x_u.*y_v - x_v.*y_u;
-
-    % Find approximate logical coordinates of point source
-    [U, V] = meshgrid(u, v);
-    U_interp = scatteredInterpolant(coords, U(:));
-    V_interp = scatteredInterpolant(coords, V(:));
-    uS = U_interp(x_s);
-    vS = V_interp(x_s);
-
-    d = (1./J).*diracDiscr([uS, vS], {u, v}, m_order, s_order, {H_u, H_v});
-
 end
\ No newline at end of file