From fff252e68953c6ed61c3151e49b78f3d724a1602 Mon Sep 17 00:00:00 2001
From: Florian Atteneder <florian.atteneder@uni-jena.de>
Date: Thu, 29 Aug 2024 20:18:56 +0000
Subject: [PATCH] dg1d: Teach `MeshInterpolator` how to deal with different DG
 kinds (https://git.tpi.uni-jena.de/dg/dg1d.jl/-/merge_requests/220)

---
 src/mesh.jl | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/mesh.jl b/src/mesh.jl
index 0202180b..d400bfd9 100644
--- a/src/mesh.jl
+++ b/src/mesh.jl
@@ -687,14 +687,28 @@ function MeshInterpolator(smpl_x::AbstractArray{<:Float64}, ref_mesh::Mesh1d)
     # find all sample indices of nodes which fall into the same reference cell
     same_idxs = findall(ref_idx -> ref_idx == cell_idx, ref_cell_indices)
     smpl_idxs = [ current_idx ]
-    if length(same_idxs) == 1
+    if length(same_idxs) != 1
       append!(smpl_idxs, same_idxs[2:end])
     end
     # extract the sample nodes
     smpl_xs = smpl_x[smpl_idxs]
+
+    # generate interpolation matrix
+    box = ref_mesh.boxes[cell_idx]
+    (xmin, xmax), = box.extends
+    ref_xs = @. (2*smpl_xs - (xmax+xmin))/(xmax-xmin)
     # generate interpolation matrix
-    push!(interpolation_matrices,
-          (cell_idx, dg1d.barycentric_interp_matrix(smpl_xs, ref_x[:,cell_idx])))
+    if ref_mesh.element.kind === :modal_bspline1
+      push!(interpolation_matrices,
+            (cell_idx, dg1d.Bspline.vandermonde_matrix(ref_xs, ref_mesh.element.bs1)))
+    elseif ref_mesh.element.kind === :modal_bsplinea2
+      push!(interpolation_matrices,
+            (cell_idx, dg1d.Bspline.vandermonde_matrix(ref_xs, ref_mesh.element.bs2)))
+    else
+      push!(interpolation_matrices,
+            (cell_idx, dg1d.barycentric_interp_matrix(smpl_xs, ref_x[:,cell_idx])))
+    end
+
 
     current_idx += length(smpl_idxs)
     if current_idx > length(ref_cell_indices)
-- 
GitLab