Mercurial > repos > public > sbplib
changeset 1233:57df0bf741dc feature/dirac_discr
Merge in curvilinear discr of dirac delta
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 19 Nov 2019 13:55:43 -0800 |
parents | 52d774e69b1f (current diff) 8a456f6e54cc (diff) |
children | f1806475498b 48c9a83260c8 |
files | |
diffstat | 1 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 52d774e69b1f -r 57df0bf741dc diracDiscrCurve.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/diracDiscrCurve.m Tue Nov 19 13:55:43 2019 -0800 @@ -0,0 +1,58 @@ +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]. + % g: single-block grid containing the source + % m_order: Number of moment conditions + % s_order: Number of smoothness conditions + % order: Order of SBP derivative approximations + % opSet: Cell array of function handle to opSet generator + + default_arg('order', m_order); + default_arg('opSet', {@sbp.D2Variable, @sbp.D2Variable}); + + dim = length(x_s); + assert(dim == 2, 'diracDiscrCurve: Only implemented for 2d.'); + assert(isa(g, 'grid.Curvilinear')); + + m = g.size(); + m_u = m(1); + m_v = m(2); + ops_u = opSet{1}(m_u, {0, 1}, order); + ops_v = opSet{2}(m_v, {0, 1}, order); + I_u = speye(m_u); + 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); + + x_u = Du*x; + x_v = Dv*x; + y_u = Du*y; + 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