Greetings
I am very new to the FeniCs project and do not even know what it can’t do.
I have a .vtu file which consists of 3-D unstructured mesh (high-order VTK hex & prisms) and fields of several variables on it. I want to read it on FeNiCs and solve a certain Poisson equation, the homogeneous term being a function of the some available variable fields. Is it possible to read in high-order VTK and solve the equation keeping the high-order accuracy?

To avoid any problems related with it, i subdivided and tetrahedralized my mesh. My version of fenicsx is v0.4.1.2. Using the guide from https://jsdokken.com/dolfinx_docs/meshes.html , i try to load my mesh and create the dolfinx mesh. The following code fails with some “core dumped” error messages.

import pyvista as pv
import numpy as np
from mpi4py import MPI
from dolfinx.mesh import create_mesh
import ufl
# Read the .vtu file using PyVista
mesh_pv = pv.read("minimalExample.vtu")
# Extract points
points = np.array(mesh_pv.points)
# Extract cells (assuming tetrahedrons)
cells = mesh_pv.cells_dict[pv.CellType.TETRA]
# Define the cell type
cell_type = ufl.Mesh(ufl.VectorElement("Lagrange", ufl.tetrahedron, 1))
# Create the DolfinX mesh
mesh = create_mesh(MPI.COMM_WORLD, points, cells, cell_type)
# Print mesh information
print(f"Number of cells: {mesh.topology.index_map(dolfinx.mesh.MeshEntityType.cell).size_local}")
print(f"Number of vertices: {mesh.topology.index_map(dolfinx.mesh.MeshEntityType.vertex).size_local}")

I simply clipped the original mesh on Paraview, and then tetrahedralized it to have a tetra-only mesh. “clean to grid” filter was also useful to merge the common nodes on the neighboring cells.

I have another problem: What if I also want to load a field from the .vtu file for use in the source terms later?

What i did was

#define fem function space
V = fem.functionspace(domain, ("Lagrange", 1))
# Create a dolfinx Function to hold the field data
u_pressure = fem.Function(V)
# Assuming field_data is ordered according to the vertices
field_data=mesh_pv.point_data["Pressure"]

which resulted in a messy field as i wrote it in another .vtu file. Then I fixed it with:

# Map the field data to the dolfinx vertices
# Create a KDTree for efficient nearest-neighbor search
from scipy.spatial import KDTree
kdtree = KDTree(points)
_, vertex_indices = kdtree.query(domain.geometry.x)
u_pressure.vector.array[:] = field_data[vertex_indices]

, which seems to work. Is there an elegant way to read a field, without using KDtrees? For large problems, this may be a little prohibitive.

I would suggest that you have a look at: Reading node based data from "Legacy" XDMFFile · Issue #16 · jorgensd/adios4dolfinx · GitHub as it describes the logic given XDMF/h5 files.
The logic there uses some functions from adios4dolfinx to ensure that the code would work in serial and parallel. Please note that vtu files are not well-suited for parallel reading, as it is hard/impossible to partition the data when reading it.

I can also export my msh as .pvtu, that is, as an already partitioned mesh from my solver. I reckon though, it could be really painstaking to get dolfinx to know the connectivitiy between the partitions. another thing i can do is to save the vtu (or pvtu) as xdmf on Paraview.

There is also another impeding issue: definition of periodic boundary condition on dolfinx. Given that, I think i will give up because this turned out to be more complicated than i thought at first…