# Problem with mesh

**URL:** <https://fenicsproject.discourse.group/t/problem-with-mesh/6183>\
**Category:** mesh\
**Created:** [July 7, 2021, 3:35pm UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183 "2021-07-07T15:35:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 7, 2021, 3:35pm UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/1 "2021-07-07T15:35:44Z")

</div>

I created a brain mesh with Tetgen and I have obtained a file .mesh.  
In order to use it with Fenics I used dolfin-converter but it creates me problems since the previous mesh was high quality but using dolfin\_converter it gets worse.  
The error that Fenics gave me is the following:

\*\*\* Error: Unable to compute tetrahedron point collision.  
\*\*\* Reason: Not implemented for degenerate tetrahedron.  
\*\*\* Where: This error was encountered inside CollisionPredicates.cpp.  
\*\*\* Process: 0

* * *

\*\*\* DOLFIN version: 2019.1.0  
\*\*\* Git changeset: 68992f956799dc3f153b3d59b8f60cf1a72b9b9e

Any suggestion?

---

<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:** [July 7, 2021, 6:42pm UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/2 "2021-07-07T18:42:19Z")

</div>

When you say dolfin converter, what do you mean? The dolfin-convert script? This script has not been maintained, and it is suggested to use meshio, as described here: [Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio - #174 by dokken](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/174)

---

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 8, 2021, 7:00am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/3 "2021-07-08T07:00:52Z")

</div>

Yes I mean the dolfin-convert script. Thank you for the suggestion, I will try to use meshio.

---

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 11, 2021, 10:27am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/4 "2021-07-11T10:27:15Z")

</div>

I managed to convert it using meshio from a file .mesh to a file .xml.  
I have only one question: is it possible to keep the labels (an integer) that every tetheadron has in the file .mesh also in the output file?  
In order to convert it I use the command: meshio-convert input.mesh output.xml  
Could I set an option in order to include those label?

---

<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:** [July 11, 2021, 11:00am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/5 "2021-07-11T11:00:42Z")

</div>

I do not know how to do it using the meshio-convert script, as I use the meshio Python API. In the script I’ve linked to, it saves the cell data (loaded as a dictionary with key `"gmsh:physical"`)

---

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 11, 2021, 4:11pm UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/6 "2021-07-11T16:11:30Z")

</div>

Perfect, I used your script and I saw the dictionary. But if I load the output.xml in another script fenics as mesh, how can I access to that dictionary?  
I mean, if I load it as:  
mesh= Mesh(“output.xml”)  
and then I want to create a MeshFunction using the information in that dictionary, how can I do?

---

<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:** [July 11, 2021, 5:38pm UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/7 "2021-07-11T17:38:56Z")

</div>

See: [Bitbucket](https://bitbucket.org/fenics-project/dolfin/src/b55804ecca7d010ff976967af869571b56364975/python/test/unit/io/test_XML_mesh.py?at=master#lines-106)

---

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 12, 2021, 9:21am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/8 "2021-07-12T09:21:05Z")

</div>

I cannot understand. In my script I want to create a MeshFunction with the integer values that I have for each tetraedra and they are saved in this way:  
{‘name\_to\_read’: {‘tetra’: array([2, 2, 2, …, 2, 2, 2])}}  
(using the command print(tetra\_mesh.cell\_data\_dict) in the conversion file)

So I think to proceed in this way:

mf = MeshFunction(“int”, mesh, mesh.topology().dim())  
mf.array()[:] = some\_array

and some\_array should be the previous array, but I definitely do not know how to do.

---

<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:** [July 12, 2021, 9:30am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/9 "2021-07-12T09:30:20Z")

</div>

As you have still not supplied me with a mesh, I cannot do much to help you.  
What I am linking you to in the previous post is that the xml file most likely contains the domain markers, and you can extract them from it.

If you want to make something that works in parallel, you need to do the following:

1. Use the meshio python interface to convert your mesh from your `.mesh` format to XDMF, as described in: [Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio - #174 by dokken](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/174), where the `cell_data` variable is replaced with the array you are describing (one integer per cell).
2. Read in meshvalue collections and place then in a MeshFunction, as described in: [Need help converting GMSH to FEniCS - #17 by dokken](https://fenicsproject.discourse.group/t/need-help-converting-gmsh-to-fenics/5192/17)

---

<div class="post-metadata">

**Author:** ![Francesca\_Ballatore](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/francesca_ballatore/32/2510_2.png) [@Francesca\_Ballatore](https://fenicsproject.discourse.group/u/Francesca_Ballatore)\
**Post date:** [July 12, 2021, 10:12am UTC](https://fenicsproject.discourse.group/t/problem-with-mesh/6183/11 "2021-07-12T10:12:00Z")

</div>

Thank you so much! Exactly what I needed!
