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()
with d.XDMFFile('quadratic.xdmf') as infile:
V = d.VectorFunctionSpace(mesh, 'CG', 2)
u = d.Function(V)
xdmf = d.XDMFFile(mesh.mpi_comm(), 'quadratic_fenics.xdmf')
xdmf.write_checkpoint(u, 'u', 0, d.XDMFFile.Encoding.HDF5, False)
Thank you for your previous answers.
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:
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.
##-------------------- Minimal example
from mpi4py import MPI
import numpy as np
# Mesh construction
filename = "meshes/FFH6R_msh.xdmf"
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, filename, "r" ) as file:
mesh = file.read_mesh(name="Grid")
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_All_val = np.genfromtxt(fileresult, usecols=(3), usemask=True)
res.vector.array = res_All_val
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "output/res1mini_x.xdmf", "w") as xdmf:
res.name = "U (mm)"
I have a second question regarding the capability of DOLFINx to handle p-version of finite element analysis (increasing Legendre polynomial shape functions).
Are we able to use FeniCs for 3D linear elasticity problem and Legendre polynomial shape functions of order p>4 considering the complexity to build the stiffness matrix in these conditions.
Thank you in advance.