I’m encountering an error when transferring a function from a coarse to a refined mesh using DG0 function space. The code works perfectly with both meshes with CG1 function space, and also with DG0 but with simpler geometries, but fails with a hollow pressure vessel with DG0.
The error is:
Reason: Mesh entity index -1 out of range [0, 7328] for entity of dimension 2.
It seems related to the mesh complexity or geometry. Has anyone encountered this issue or have insights on handling DG0 transfers on complex surface meshes? I have the minimum code to replicate this issue.
from dolfin import *
import numpy as np
# Define the function to transfer functions between spaces
def transfer(from_fun, to_fun_space):
from_fun.set_allow_extrapolation(True)
V1 = from_fun.function_space()
V2 = to_fun_space
A = PETScDMCollection.create_transfer_matrix(V1, V2)
f2 = Function(V2)
f2.vector()[:] = A * from_fun.vector()
return f2
mesh_list = ["senp/mesh.xdmf","pressure/mesh.xdmf"]
mesh = Mesh()
with XDMFFile(mesh_list[0]) as infile: # 0 works but 1 does not
infile.read(mesh)
mesh_fine = refine(mesh)
V_coarse = FunctionSpace(mesh, "DG", 0)
V_fine = FunctionSpace(mesh_fine, "DG", 0)
# Define a sample function on the coarse mesh
from_fun = Function(V_coarse)
from_fun.vector()[:] = np.random.rand(V_coarse.dim()) # Random values for testing
# Perform the transfer
to_fun = transfer(from_fun, V_fine)
Here is the link to the mesh files: mesh.zip - Google Drive
I have also tried to use L2 projection, but get the same error with the pressure vessel.