Line mesh in a 2D space

Hi,

I’m currently trying to load in a mesh generated through gmsh and converted to .xdmf through meshio-convert. This mesh is simply a line with a 15 degree bend at a certain point. Here’s the .geo file:

// Gmsh project created on Mon Dec 09 14:38:39 2019
SetFactory("OpenCASCADE");
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {1000, 0, 0, 1.0};
//+
Point(3) = {965, 259, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Line(2) = {2, 3};
//+
Transfinite Curve {1} = 50 Using Progression 1;
//+
Transfinite Curve {2} = 40 Using Progression 1;

I noticed that the msh file does not convert to a xml file but converts to a xdmf file no problem. This is the .xdmf file:

  <Domain>
    <Grid Name="Grid">
      <Information Name="Information" Value="0"><![CDATA[<main/>]]></Information>
      <Geometry GeometryType="XYZ">
        <DataItem DataType="Float" Dimensions="89 3" Format="HDF" Precision="8">Geomnew.h5:/data0</DataItem>
      </Geometry>
      <Topology NumberOfElements="91" TopologyType="Mixed">
        <DataItem DataType="Int" Dimensions="358" Format="HDF" Precision="4">Geomnew.h5:/data1</DataItem>
      </Topology>
    </Grid>
  </Domain>
</Xdmf>

I then tried to load the file using:

from dolfin import *
mesh = Mesh()
filename = "Geomnew.xdmf"
f = XDMFFile(filename)
f.read(mesh)

But get the following error:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to recognise cell type.
*** Reason:  Unknown value "mixed".
*** Where:   This error was encountered inside XDMFFile.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** -------------------------------------------------------------------------

I’m wondering if there is a work around for this error as FEniCS doesn’t seem to like the mixed elements. Or is there a way of using IntervalMesh and rotating a region about a point? Any guidance would be much appreciated.

Cheers.

Hi,
Please consider the following code:

import meshio
msh = meshio.read("tjhAB.msh")
meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points[:,:2], cells={"line": msh.cells["line"]}))

from dolfin import *
mesh = Mesh()
filename = "mesh.xdmf"
f = XDMFFile(filename)
f.read(mesh)

outfile = XDMFFile("dolfin_mesh.xdmf").write(mesh)

Here I’ve used meshio’s python interface to save the mesh in a format that dolfin can handle.
For more info on that subject, with respect to markers etc. see: Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio
Note that I’ve removed the z-coordinate from the points array, as you have to tell dolfin that this mesh is a “2D” mesh.

3 Likes

Hi dokken,

Perfect, this is exactly what I was looking for. Thanks for your help.

I think that in more recent versions of meshio (I am using 5.3.4), msh.cells["line"] doesn’t work because the attribute cells is not a dictionary anymore. Instead, one can use msh.cells_dict["line"] (also “triangle”, “tetra”, etc.) in just the same way.

1 Like