Importing Mesh from COMSOL

Has anyone extracted a mesh from COMSOL and imported it into FreeFem?

I am exporting a 2d mesh from COMSOL. There are different formats that I can extract. I extract and tried all of them, but I cannot import it into FreeFem.

Does anyone know what format I should do and what procedure I should follow?

I appreciate your help.
Best

What format did you try?

Thank you for your reply. I tried all the formats.
mphbin, mphtxt: these two weren’t useful because freefem and also Gmsh cannot open them.

.nas: I could open this with Gmsh and save it as msh file. But I wasn’t able to open it with code.

.vtu: THis one was also not readable in freefem.

Could you please tell me what to do? Thank you.

If you can open with Gmsh and then export to .mesh or .msh, then that should be alright.

Thank you again.

I saved it .msh file, but it is not opening if freefem.

Here:
load “gmsh”
mesh Th=gmshload(“Mesh4.msh”);

this is the error:
mshptg bug in number of points 1 > 1 == max nb points
Sorry Error build delaunay triangle error = 1
current line = 3
Exec error : Error mshptg8_
– number :1
Exec error : Error mshptg8_
– number :1
err code 8 , mpirank 0
try getConsole C:\Users\ava\Desktop\My FreeFem\reading.edp
save log in : ‘C:\Users\ava\Desktop\My FreeFem\reading.log’
wait enter ?

Please let me know what I should do.

Can I give you my .nas or .msh file and you check it, please?

Sure, upload the .msh.

Thank you.

I appreciate your help.
Mesh1.mesh (836.8 KB)

Your mesh has no boundary elements, so it cannot be read by FreeFEM. You need to define the surface of the circle.

Could you please help me how I can do that?

The file that I sent you is the result of gmsh from .nas of the COMSOL.

Some time ago I used feconv to convert a 3D mesh from mphtxt format to gmsh format. Check out the software. Maybe it also works for 2D meshes.

1 Like

Hello,
I recently have tried feconv that @henkel suggested and it worked! Thanks to him!
I wanted to import in freefem a mesh of a 2d square with a slit from COMSOL.

Firstly, you need to choose .mphtxt and check all the 4 first v’s on the export menu, that is:

  • domain elements
  • boundary elements
  • vertex elements
  • geometric entity information

But then all I had to do was to write in cmd (though installing feconv is a bit hard):

  1. cd <go to a place where feconv is>
  2. feconv -ff <yourfile.mphtxt> <newfile.msh>
    -ff is for when .msh file appears, you choose for freefem. You could also write -gm for gmsh.
  3. And then you just read it in freefem:
    mesh Th = readmesh("newfile.msh");
    plot(Th, wait=1);

P.S. At least that’s what I had come to, through trying and failing.

P.S.S. If you need to deal with labels, I just printed them out with cout << labels(Th)<< endl; and it’s just numbers. I deformed the square by the numbers one by one until I finally discovered every sides’ labels.

P.S.S.S. If you read somewhere that for importing 2d-mesh you need to remove z-axis from your file because freefem can’t read because of it, don’t trust them. Freefem reads 2d meshes just fine with readmesh().