INP-PM / FEDM

Finite Element Discharge Modelling code
https://inp-pm.github.io/FEDM/
GNU Lesser General Public License v3.0
10 stars 4 forks source link

Creating and importing a mesh from GMSH #16

Closed RaphaelPile closed 1 year ago

RaphaelPile commented 1 year ago

Hello,

I am having a lot of difficulties to create and import a mesh from GMSH. (h5py incompatibilities with the docker container, Dolfin mesh object incomplete ...).

I was wondering how did you create the mesh.xml file from the examples ? Do you have a simple procedure that I could follow to recreate that type of mesh ?

Thank you in advance for any help,

Raphaël

AleksandarJ1984 commented 1 year ago

Hi Raphaël,

I did not have these kinds of difficulties, so it has to be due to the way how you convert your mesh. I will try to briefly describe how I export my meshes from the gmsh, which might help you overcome this problem.

I usually use gmsh 4.11.0 (older versions also work just fine) to create a mesh and then export it as an msh file. Be sure that you choose version 2 when you export it. The next step is to convert the mesh into some format that is supported by FEniCS, i.e. xml or XDMF. For this, I use the meshio version 4.2 (note that I have not tried newer versions, the latest being 5.3.4). The script is as follows:

import meshio
mesh = meshio.read('input_file.msh')
mesh.prune()
mesh.write('output_mesh.xml')
mesh.write('output_mesh.xdmf')

noting that the prune step is required to reduce the dimension of the mesh (gmsh exports a 3D mesh).

There are alternative procedures, and quite a lengthy discussion about them can be found here. It is mainly focused on XDMF format, but it might be useful. Note that the new version of FEniCS(x) only supports the XDMF format, so it is suggested to switch to it anyway.

Best regards, Aleksandar

RaphaelPile commented 1 year ago

Many thanks, it worked! The "version 2" of Gmsh export and the prune step were the solutions to the problem.