 Hello everyone,

I am working with a sector of a cylinder mesh in 2D and I was wondering if reading a mesh with quadratic elements is possible. For example, I created a mesh in Gmsh (and converted it to XDMF using meshio) with quadratic triangles as shown in the figure.

The ideal case would be that I can read that mesh with dolfin and, when creating a quadratic continuous space the middle nodes were the same as the ones in the file. I tried to do that using the following code:

import dolfin as d
mesh = d.Mesh()

V = d.VectorFunctionSpace(mesh, 'CG', 2)
u = d.Function(V)

xdmf.write_checkpoint(u, 'u', 0, d.XDMFFile.Encoding.HDF5, False)
xdmf.close()

but the result is this

I know I can load a linear mesh and FEniCS will interpolate the elements to create the middle nodes like this:

But I lose geometrical accuracy that will matter in the convergence of my problem.

I do not know if this is possible or not. I will appreciate your guidance.

Hi, high-order geometry is supported in dolfin-x only.

1 Like

Examples of how to read higher order Gmsh meshes into dolfin-X is covered in:
https://github.com/FEniCS/dolfinx/blob/master/python/demo/gmsh/demo_gmsh.py
and
https://github.com/FEniCS/dolfinx/blob/master/python/test/unit/io/test_xdmf_mesh.py#L98

2 Likes

Hello,
In my case I have a xdmf file with quadratic tetrahedron that I want to import in Dolfinx.
I defined a function of degree 2 for the displacements but I have problems when I use xdmf.write_function, I got the following error.

The error above is due to the fact that DOLFINx is not able to to pull the degrees of freedom back to the reference element when interpolating the function you are writing to file to a CG-1 function space:

(You error should be easy to reproduce with the eval function as covered here: dolfinx/test_function.py at main · FEniCS/dolfinx · GitHub

An alternative workaround is to use the VTX writer, as it does not pull back values to the reference element; see for instance dolfinx/test_adios2.py at 114c268aab752b6669abc2718837116cec90dba6 · FEniCS/dolfinx · GitHub

Thank you very much for answering.
Regarding the mesh, it is a .inp mesh converted to .xdmf using meshio (the original mesh comes for a CT scan, elements are quadratic tetrahedron)

Regarding the function space I wrote

So I don’t completely understand what you said about the function interpolation to a CG-1 function space because I fixed a degree = 2. Thanks !

To be more specific, when you use the function XDMFFile.write_function it in turn calls compute_point_values, which computes an interpolation of your function onto the mesh nodes (10 nodes per tetrahedron).
This interpolation requires a pull_back, which causes the issue you describe above.

For me to be able to be of any further assistance, you need to supply a minimal code example which can reproduce your issue.

This is a minimal example where my issue appears.

##-------------------- Minimal example
import dolfinx
from mpi4py import MPI
import ufl
import dolfinx.io
import numpy as np

# Mesh construction
filename = "meshes/FFH6R_msh.xdmf"
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, filename, "r" ) as file:

tdim=3 # problem in 3D
# Function space
element_res = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=2)
V_res = dolfinx.FunctionSpace(mesh, element_res)
res = dolfinx.Function(V_res)

# Values imported from the original file
fileresult = "FFH6R_B_590N_All_nodes_UVW.txt"

res.vector.array = res_All_val

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "output/res1mini_x.xdmf", "w") as xdmf:
xdmf.write_mesh(mesh)
res.name = "U (mm)"
xdmf.write_function(res)

Thanks again

First of all, you need to either supply your xdmf/h5 file or an XML version of the xdmf file, such that one can redproduce your error message.

Secondly, I do not think you need the line:

to produce the error.

Another option would be to supply the .inp file and your meshio conversion script.