Hi there,
i am very confused about a one problem with FreeFem. I am trying to import a 2D Geometry from Salome in FreeFem. So first i sketched the geometry in Salome and then i saved it with “.brep” format. After that i opened it in Gmsh and mesh it and then i save it with two formats: .msh and . mesh.
at the next step i tried to read one of the files in FreeFem. The problem arises here. by reading the file i wabt to have a 2D geomery so i wrote:
mesh Th = readmesh(“Rectangle_1.mesh”);
the error is following:
Error Opening file Rectangle_1.mesh, Erreur Lecture 1, good=0, bad=1, fail=0, eof=0 Line 1
the next character :
current line = 5
Exec error : Mesh IO Error
– number :1
Exec error : Mesh IO Error
– number :1
err code 8 , mpirank 0
so i tried to run another command:
mesh Th = gmshload(“Rectangle_1.mesh”);
the following error comes out:
Unable to open file Rectangle_1.mesh
so with the .msh file is the same and freefem cannot open the file. Does anyone have any idea about that?
First, I see a mistake here. if you are going to use GMSH and .msh format, use gmshload to load the mesh into FreeFEM (as already discussed several times in this forum). you have called gmshload on the .mesh file instead of the GMSH file (.msh) file.
Second, do you have an error like “dimenstion is not 2” before the error you posted here? for importing 2D mesh files into FF, they should be actually 2D and not 3D with 0 for the Z component. you can open your mesh file in a text editor and check if this is the case. this frequently happens when you import a geometry into GMSH (especially from SALOME), so you need to remove all the third components of the points coordinates. I use meshio for doing this (I don’t know if there is a simpler solution or not), so the command will be something like this: meshio-convert Rectangle_1.mesh Rectangle_1-2d.mesh --prune-z-0.
then, you can import the new file, Rectangle_1-2d.mesh, into FF (check it with a text editor to be sure that it’s a 2D mesh now).
Third, I have recently written a blog post about importing 3D mesh files from SALOME into FF, but same techniques can be used to import 2D mesh files. you can find it at https://mbarzegary.github.io/2021/07/31/import-3d-mesh-into-freefem-part1/. you should remember that since SALOME is a 3D CAD program, it writes the mesh of 2D entities in a 3D file, but you can easily use meshio (as mentioned above) to convert the mesh to a 2D one.