# Line mesh in a 2D space

**URL:** https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066
**Category:** mesh
**Created:** [December 9, 2019, 4:44pm UTC](https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066 "2019-12-09T16:44:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tjhAB](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@tjhAB](https://fenicsproject.discourse.group/u/tjhAB)
#### Post date: [December 9, 2019, 4:44pm UTC](https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066/1 "2019-12-09T16:44:39Z")

</div>

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:

```python
// 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:

```auto
  <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:

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

```

But get the following error:

```python
*** -------------------------------------------------------------------------
*** 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.

---

<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: [December 9, 2019, 5:01pm UTC](https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066/2 "2019-12-09T17:01:56Z")

</div>

Hi,  
Please consider the following code:

```auto
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](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412)  
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.

---

<div class="post-metadata">

### Author: ![tjhAB](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@tjhAB](https://fenicsproject.discourse.group/u/tjhAB)
#### Post date: [December 9, 2019, 5:08pm UTC](https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066/3 "2019-12-09T17:08:29Z")

</div>

Hi dokken,

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

---

<div class="post-metadata">

### Author: ![ausler](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/ausler/32/8877_2.png) [@ausler](https://fenicsproject.discourse.group/u/ausler)
#### Post date: [March 8, 2023, 1:13am UTC](https://fenicsproject.discourse.group/t/line-mesh-in-a-2d-space/2066/4 "2023-03-08T01:13:03Z")

</div>

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.
