# Convert grid file of Comsol to xdmf

**URL:** <https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710>\
**Category:** mesh\
**Created:** [December 10, 2020, 11:30am UTC](https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710 "2020-12-10T11:30:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lx1998](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lx1998](https://fenicsproject.discourse.group/u/lx1998)\
**Post date:** [December 10, 2020, 11:30am UTC](https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710/1 "2020-12-10T11:30:21Z")

</div>

Hello everyone, greetings!  
I recently installed FEniCS. In my work, I need to convert .stl file to xdmf format, which is readable by FEniCS.  
The following code was used to convert a mesh from .stl format to xdmf format but I am getting an error:  
**meshio.write(“mesh.xdmf”,meshio.Mesh(points = msh.points,cells = {‘tetra’:msh.cells\_dict[‘tetra’]}))**  
**error message** :KeyError: ‘tetra’

Other methods of switching formats of comsol to xdmf are also needed

Could you please help me to resolve this issue?

Thank you,

-Xiao Li

---

<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 10, 2020, 11:36am UTC](https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710/2 "2020-12-10T11:36:36Z")

</div>

Your error message is quite clear, the read in mesh has no tetrahedral elements. What is the output of  
`print(msh.cells_dict.keys())`

---

<div class="post-metadata">

**Author:** ![lx1998](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lx1998](https://fenicsproject.discourse.group/u/lx1998)\
**Post date:** [December 10, 2020, 11:47am UTC](https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710/3 "2020-12-10T11:47:54Z")

</div>

Thank you very much for your reply.  
the output of print(msh.cells\_dict.keys()) is dict\_keys([‘tetra10’])

---

<div class="post-metadata">

**Author:** ![lx1998](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lx1998](https://fenicsproject.discourse.group/u/lx1998)\
**Post date:** [December 10, 2020, 11:49am UTC](https://fenicsproject.discourse.group/t/convert-grid-file-of-comsol-to-xdmf/4710/4 "2020-12-10T11:49:04Z")

</div>

With your help, the problem has been solved, thank you again!
