Interpolation of a grid function from a hexahedral to a tetrahedral mesh

Hi everyone,

I am having an issue trying to interpolate a GridFunction defined on a hexahedral mesh to an equivalent structured tetrahedral mesh. On some elements, the function is always set to 0 even though it is well defined there; c.f. the figure below. I have also noticed that if I try to evaluate the GridFunction on the integration points corresponding to points inside those elements, I get a Meshpoint not in mesh error.

What is the best way to initialize the GridFunction on the tetrahedral mesh in this case?

Below is the code used to generate the example in the figure above.

from ngsolve import *
from ngsolve.meshes import MakeHexMesh, MakeStructured3DMesh
import numpy as np

n = 8

hex_mesh = MakeHexMesh(n, n, n)
tet_mesh = MakeStructured3DMesh(False, n, n, n)

l2_fes_hex = L2(hex_mesh, order=0)
l2_fes_tet = L2(tet_mesh, order=0)

gf_hex = GridFunction(l2_fes_hex)
gf_tet = GridFunction(l2_fes_tet)

gf_hex.vec.FV().NumPy()[:] = np.arange(n**3) + 1
gf_tet.Set(gf_hex)

vtk_hex = VTKOutput(hex_mesh, coefs=[gf_hex], names=["gf_hex"], filename="hex_mesh_debug")
vtk_hex.Do()

vtk_tet = VTKOutput(tet_mesh, coefs=[gf_tet], names=["gf_tet"], filename="tet_mesh_debug")
vtk_tet.Do()

Thanks in advance,
Filipe

Can you try newest nightly release?

pip install --pre --upgrade ngsolve

With this it is working for me.
Best
Christopher

Indeed, it works just fine with the nightly release. Thank you!

Just pushed 2601 out :slight_smile: