Importing geometry and giving new tags

Dear community,

I’d like to add a new numerical case to my study. It happens that the geometry is not super complex, but still almost impossible to do it by hand with gmsh python library.
I have the geometry in COMSOL, and I’d like to import it in FEniCSx. The most important point, is that I would need to import it in FEniCSx (or import the mesh, that would be even better), but I need to be able to give a tag to certain faces as it would be done with gmsh with gmsh.model.addPhysicalGroup(2, [s8, s7, s5, s2], tag=3). I have the COMSOL model, so I know the “label” of the surfaces if that’s needed.

Thank you for your advices, and if you need anything else to help, let me know !

What formats does COMSOL support exporting?
Meshio provides a converter between several formats: GitHub - nschloe/meshio: 🕸 input/output for many mesh formats
Including xdmf which can be read into DOLFINx with the XDMFFile.

DOLFINx can also read data from msh files, with dolfinx.io.gmshio.model_to_mesh

Alternatively, I’ve made a mesh reader from exodus 2 with facet markers:

For the geometry itself here are the available formats :

For the mesh, here are the available formats :

Do you have any advice about the format to use, and few code lines to import it and change the tag of the faces ?

Of those formats, I would guess reading the STL into GMSH to convert it would be one option.

Some support seems to exist in meshio (MED 4.0 to .msh or .xml with entities · Issue #347 · nschloe/meshio · GitHub).
Pinging @RemDelaporteMathurin for an update on this for DOLFINx:)

oof I haven’t worked with COMSOL files in FEniCSx yet. When I did it with legacy-fenics I remember using the Nastran format and then used meshio (with some fixes) to convert it to XDMF. This should also work with DOLFINx

1 Like