# Q8 and Q9 elements

**URL:** <https://fenicsproject.discourse.group/t/q8-and-q9-elements/3279>\
**Category:** mesh\
**Created:** [May 21, 2020, 7:00pm UTC](https://fenicsproject.discourse.group/t/q8-and-q9-elements/3279 "2020-05-21T19:00:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amirr](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Amirr](https://fenicsproject.discourse.group/u/Amirr)\
**Post date:** [May 21, 2020, 7:00pm UTC](https://fenicsproject.discourse.group/t/q8-and-q9-elements/3279/1 "2020-05-21T19:00:40Z")

</div>

Hi everyone,

Is there anyway to use 8-node or 9-node quad elements in FEniCS? I am familiar with the following command:  
RectangleMesh.create([p0,p1],[nx,ny],CellType.Type.quadrilateral),  
but I think it will create 4-node quad element.

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

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [May 21, 2020, 7:20pm UTC](https://fenicsproject.discourse.group/t/q8-and-q9-elements/3279/2 "2020-05-21T19:20:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [May 21, 2020, 10:08pm UTC](https://fenicsproject.discourse.group/t/q8-and-q9-elements/3279/3 "2020-05-21T22:08:44Z")

</div>

As @nate said, you need to use [dolfinx](https://github.com/FEniCS/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

```auto
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.
    Input:
       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,
                                                MPI.COMM_WORLD.rank))
    file.write(mesh)
    # 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:
        file.write_mesh(mesh)
mesh_2D(True, "2")

```
