Creating quad mesh using RectangleMesh

Hi everyone,

Is there a way to create a quadrilateral mesh similar to UnitSquareMesh.create(nx,ny,CellType.Type.Quadrilateral) on a rectangular domain (with diagonal points p0 and p1)?

Something like RectangleMesh.create(p0,p1,...) ?

RectangleMesh.create([p0,p1],[nx,ny],CellType.Type.quadrilateral) seems to work.

do you know how to output/input a quad mesh?

I don’t think importing external quad meshes is supported in dolfin as yet. It was not till dolfin-2018.1.0 at least. I haven’t checked 2019 but most probably it is not

There is a workaround to import external quad mesh (like GMSH) into FEniCS. For example you can check this out.

1 Like

@Leo does this work, for instance, for unstructured quad meshes ? I believe the Mesh function only works for layered (structured) quads, right ?

It works for any type of quad mesh. It does not matter if it is structured or not.

1 Like

That is good to know. Will try this out.

It seems to me that the code that you posted is not completely working with 2019.1.0, and when I looked through the link it seems that you were able to work through it in 2017.2. With some changes to the code, which basically amount to addressing a couple of formatting issues, it at least adds the vertices and cells correctly but fails with an ordering issue, which again is weird because it was apparently resolved as reported here

Here is a MWE that works in 2019.1.0

  • For simplicity assume that v is an object with v.point being the node coordinate(s)
msh = Mesh() 
editr = MeshEditor()
editr.open(msh,'quadrilateral',2,2) 
editr.init_vertices(num_points)
editr.init_cells(num_cells)


for i,v in enumerate(nodes):
    editr.add_vertex(i,[*v.point])

for j,e in enumerate(verts_mio):
    # list_of_nodes = [int(i) for i in np.array(e.points,int)]
    print(e.astype(np.uintp))
    editr.add_cell(j,e.astype(np.uintp))

editr.close()

with XDMFFile(comm,'trial.xdmf') as f:
    f.write(msh)

however fails with the exception

*** Error:   Unable to order quadrilateral cell.
*** Reason:  Cell is not orderable.
*** Where:   This error was encountered inside QuadrilateralCell.cpp.

You are right. The method I proposed works only in 2017 versions. version. It seems that quad mesh ordering issue still exists in 2019 versions.

But the corresponding issue is marked as resolved on bitbucket. I’ll look through this if there is an issue with my test mesh speifically. But if you were able to work through it in 2017.2 it should, in principle, work in 2019.1.0 too.

It also looks weird to me why it is marked as resolve. I have never used 2019 version but I am sure it works fine in 2017.

Hi,

I had a quad mesh generated using Tetgen and I wanted to load that in Fenics. Thus, I wrote a small C++ program that can read the Tetgen output files and can write a XML file compatible with Fenics. It works fine for me.

What version of dolfin are you using ? Also, I have used meshio-convert to interoperate between the .xdmf and .inp formats, which works seamlessly for 3D and simplical meshes.

After browsing the argument list for MeshEditor.close(), and passing order = False, I am able to read the mesh for the most part, except for one element. See here

Just to give an update, in dolfinx there is support for unordered quad meshes for most finite elements supported in dolfin, see Hexahedral mesh elements for an L Bracket? and previous posts in this thread for more info.

Hello @bhaveshshrimali . I am using this command RectangleMesh.create([p0,p1],[nx,ny],CellType.Type.quadrilateral), but it seems that it is not working accurately on the boundary edges. However, it was working fine for triangle elements. I wanted to ask is there any way to fix this issue?
(The domain is a simple square, and it does not have any complicated edge).

Thanks!

This should work fine for a simple quad mesh. What is the problem you are having?

Thanks for your reply.
I am imposing a simple load to the deformation vector by affine BC (e.g., 0.8 x[0], 1.1 x[1] ) , and then solve the problem WRT the deformation vector on a fine mesh. Then, when I project my calculations on the square elements (which are coarser), and Warp by vector, I see that BC is not accurately applied on the edges. I was doing the same procedure with triangle elements, and I didn’t have this problem.

Thank you so much for the help!

As the support for quadrilateral meshes is limited in dolfin, I would suggest using dolfinx as the support there has been vastly improved.

3 Likes