Q8 and Q9 elements

Hi everyone,

Is there anyway to use 8-node or 9-node quad elements in FEniCS? I am familiar with the following command:
but I think it will create 4-node quad element.

Can I write Q8 mesh myself or import it from another software?

High order geometry representation is supported in dolfin-x. Old dolfin only has very simple implementations of tri6 quad8 and other high order geometry elements.

1 Like

As @nate said, you need to use dolfinx for this behavior. There you can in theory do arbitrary order quadrilateral meshes (as long as you give the right input order). There is a quite straightforward interface to pygmsh for up to third order quadrilaterals. I will attach a code i created for dolfinx to import a first, second or third order quadrilateral or triangular mesh

import numpy as np
import pygmsh
from mpi4py import MPI

from dolfinx import cpp
from dolfinx.cpp.io import cell_perm_gmsh, cell_perm_vtk
from dolfinx.io import VTKFile, XDMFFile, ufl_mesh_from_gmsh
from dolfinx.mesh import create as create_mesh

def mesh_2D(quad, order):
    Function returning a mesh of a disk.
       quad (bool): Mesh consisting of quadrilateral (True)
                    or triangular (False) cells
       order (str): "1", "2," or ", "3" describing the order for the cell.
    geom = pygmsh.opencascade.Geometry()
    geom.add_disk([0.0, 0.0, 0.0], 1.0, char_length=0.2)
    if quad:
        geom.add_raw_code("Recombine Surface {:};")
        geom.add_raw_code("Mesh.RecombinationAlgorithm = 2;")
    pygmsh_mesh = pygmsh.generate_mesh(geom,
                                       extra_gmsh_arguments=["-order", order])

    # Extract the topology and geometry data
    cells, x = pygmsh_mesh.cells[-1].data, pygmsh_mesh.points
    pygmsh_cell = pygmsh_mesh.cells[-1].type

    # Broadcast cell type data and geometric dimension
    cell_type, gdim, num_nodes = MPI.COMM_WORLD.bcast([pygmsh_cell, x.shape[1],
                                                       cells.shape[1]], root=0)
    # Permute the mesh topology from VTK ordering to DOLFIN-X ordering
    cells_dolfin = cells[:, cell_perm_gmsh(cell_type)]
    mesh = create_mesh(MPI.COMM_SELF, cells_dolfin, x,
                       ufl_mesh_from_gmsh(cell_type, x.shape[1]))

    # Write mesh to file for visualization with VTK
    file = VTKFile("{}_mesh_rank_{}.pvd".format(pygmsh_cell,
    # Write mesh to file for visualization with XDMF
    with XDMFFile(MPI.COMM_SELF, "{}_mesh_rank_{}.xdmf"
                  .format(pygmsh_cell, MPI.COMM_WORLD.rank), "w") as file:
mesh_2D(True, "2")