# How to import xdmf mesh generated by gmsh into fenics

**URL:** <https://fenicsproject.discourse.group/t/how-to-import-xdmf-mesh-generated-by-gmsh-into-fenics/10045>\
**Category:** General\
**Created:** [December 27, 2022, 2:30am UTC](https://fenicsproject.discourse.group/t/how-to-import-xdmf-mesh-generated-by-gmsh-into-fenics/10045 "2022-12-27T02:30:05Z")\
**Posts on this page:** 1\
**Showing post:** 23

<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 30, 2022, 3:11pm UTC](https://fenicsproject.discourse.group/t/how-to-import-xdmf-mesh-generated-by-gmsh-into-fenics/10045/23 "2022-12-30T15:11:00Z")

</div>

As i do not know what meshing tool you use to go from an image to a mesh, it is hard to give you any specific tips.

If you use Gmsh for this, there might be a tutorial on their webpage:  
[https://gmsh.info/](https://gmsh.info/)

> [@taytay33](#):
>
> 2nd option is quite complex.

The second option doesn’t take many lines of Python to program. See for instance:

> [@How to create lists of cell neighbours?](https://fenicsproject.discourse.group/t/how-to-create-lists-of-cell-neighbours/4728/2):
>
> Instead of using the filter function, you can simply unwrap it in multiple loops: from dolfin import \* mesh = UnitSquareMesh(2, 2) # Init facet-cell connectivity tdim = mesh.topology().dim() mesh.init(tdim - 1, tdim) # For every cell, build a list of cells that are connected to its facets # but are not the iterated cell cell\_neighbours = {} for cell in cells(mesh): index = cell.index() cell\_neighbours[index] = [] for facet in facets(cell): facet\_cells = facet.entities(tdi…

---

_[View the full topic](https://fenicsproject.discourse.group/t/how-to-import-xdmf-mesh-generated-by-gmsh-into-fenics/10045)._
