.med file format

About the development of the FEM module/workbench.

Moderator: bernd

joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

vocx wrote: Sun Apr 21, 2019 9:32 pm How to continue what? Is support for MED not currently implemented? Does libmed not compile-link? Can FEM not read nor write in this format? By reading your other thread it is not clear to me what is missing and what needs to be done.
Yeah the support is there, but it seems at least for me, that there are incompatibilities between different versions of the MED format. It would be fine if FreeCAD could read arbitrary versions of MED and could write arbitrary versions such that the communication to external programs could be easier.

From my post above, for me at the moment it would be nice to support the transfer between gmsh and FreeCAD by MED because of the reasons you mentioned. Unfortunately I was not able up to now to find out which version of MED FreeCAD actually can write and read. From MED files from gmsh I only get either a strange exception message that FreeCAD has not "the right version" to read the gmsh files or the mesh is generated but nothing happens (there is also no contents in the mesh).

Best wishes
Johannes
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: .med file format

Post by wmayer »

joha2 wrote:Anyway, I did not manage to create a MED file with gmsh and read it back into FreeCAD maybe due to binary incompatibilities between the version with which gmsh was compiled and the one for FreeCAD.
I was able to:
  1. Create a MED file with gmsh (v2.9.3) and read it into FreeCAD
  2. Create an FEM mesh in FreeCAD, export and import as MED file
There are two things to consider:
  1. When I read in the STEP file into gmsh then the output file must have the same base name (e.g. torus.stp -> torus.med) because otherwise gmsh creates an empty file and raises an error that it couldn't open the file
  2. For some reason inside the MED file format a name is stored that must match with the base name of the file. So, if you rename an existing MED file then FreeCAD will fail to load the file while gmsh is still able to load it.
See also:
https://forum.freecadweb.org/viewtopic. ... 143p131143
https://github.com/FreeCAD/FreeCAD/pull/221
https://github.com/FreeCAD/FreeCAD/pull/216
https://forum.freecadweb.org/viewtopic. ... 20#p131007
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

wmayer wrote: Mon Apr 22, 2019 8:47 am
  1. Create a MED file with gmsh (v2.9.3) and read it into FreeCAD
  2. Create an FEM mesh in FreeCAD, export and import as MED file
Hey Werner! Thanks for your response! Could you also try this process with the newest gmsh 4.3.0? Does it still work? My problem arises when I use a gmsh compiled on my own (due to multi thread support) and a FreeCAD also compiled on my own with uptodate master.

For implementing the new features of gmsh (i.e. multi thread support and usage of HXT algorithm) I don't know whether one can use such an old version. Maybe I should also study the changelog of gmsh to be able to find some useful standard choices for different versions. But this is another issue.

I opened some PRs in bernds femdev branch which address some of the issues for mesh improvement mentioned at the beginning of the thread. Maybe you can have a look at them if there is some time for this.

Best wishes and thank you
Johannes
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: .med file format

Post by wmayer »

With v4.3.0. gmsh refuses to create the MED file. It always aborts with the error: Unable to write MED descriptor
And when trying to load an existing MED file gmsh always stops with a segfault.

So, there is definitely something broken with gmsh.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

Thanks for testing! Which OS? Sounds strange. The descriptor error messages refers to https://gitlab.onelab.info/gmsh/gmsh/bl ... D.cpp#L597 but I don't know whether this is an API function of the MED library or a function within gmsh.
I just tested with the scripts generated by bernds meshing code (i.e. modified the /tmp/shape2geo.geo script). Did you generate your own mesh with gmsh and tested these things? For extension of bernds gmsh code it is maybe most important to
  • export .MED from gmsh (after running the shape2geo script)
  • import .MED by FreeCAD (to speedup the UNV import which also fills my RAM (8 GB) on my laptop with a 2 to 3 million element mesh of the standard FreeCAD cube)
Maybe we should focus on these tasks?

Best wishes
Johannes

EDIT: Inserted the source location of the "descriptor error message" in gmsh repo.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: .med file format

Post by wmayer »

Thanks for testing! Which OS? Sounds strange.
Windows.

The function MEDfichDesEcr is part of the MED library version 2.x (see med_proto.h) and in MED 3.x it's apparently called MEDfileCommentWr.
Did you generate your own mesh with gmsh and tested these things?
I created a simple STEP file (with a torus) and imported it into gmsh. There I did the meshing and when trying to export as .med it stopped with the error message. And when I tried to import the .med files created with FreeCAD or the old gmsh version then it crashed all the time.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

And when I tried to import the .med files created with FreeCAD or the old gmsh version then it crashed all the time.
I checked the second point with gmsh 4.3.0 64 bit Linux binary (directly downloaded from gmsh.info) and freecad-daily (FreeCAD 0.18, Libs: 0.18R16093 (Git)) and this worked for me. It is a Linux Mint 18.3 with the following version string
Linux 4.15.0-47-generic #50~16.04.1-Ubuntu SMP Fri Mar 15 16:06:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
This makes it more strange. Seems that there are serious differences between the Windows binary and the Linux binary. I will test also the first point with this configuration, i.e.: Making a torus in FreeCAD and importing it into gmsh, meshing it, exporting as .MED file and reimporting it into freecad.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

The second step failed also for me:

Code: Select all

MEDversionedApi3C.c [50] : Cette bibliothèque MED n'est pas capable de lire un fichier MED dont le mineur de la versionexcède celui de la bibliothèque.
MEDversionedApi3C.c [51] : La version demandée est :
MEDversionedApi3C.c [51] : _fversionMMR = 400
MEDversionedApi3C.c [116] : Impossible d'obtenir une implémentation de : 
MEDversionedApi3C.c [117] : key = "_MEDmeshnAxisByName"
MEDversionedApi3C.c [118] : en version :
MEDversionedApi3C.c [119] : _fversionMMR = 400
MEDversionedApi3C.c [120] : Vérifiez votre fichier .med
MEDmeshnAxis.c [56] : Erreur d'appel de l'API 
MEDmeshnAxis.c [56] : du maillage 
MEDmeshnAxis.c [57] : _meshname = "torus"
MEDmeshnAxis.c [57] : _meshpath = "/ENS_MAA/"
MEDmeshnAxis.c [57] : "MEDmeshnAxisByName" = "MEDmeshnAxisByName"
Used gmsh 4.3.0 Linux 64 binary together with freecad-daily. There I built the torus, exported the STEP file, imported it into gmsh, made a 3D mesh and exported the 3D mesh as 'torus.med'. Seems like the mentioned binary incompatibility. The mesh itself in FreeCAD was created, but it was empty.

Best wishes
Johannes
User avatar
kkremitzki
Veteran
Posts: 2515
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: .med file format

Post by kkremitzki »

Does adding the -3 flag to gmsh make any difference?
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
joha2
Posts: 303
Joined: Tue Oct 11, 2016 9:48 pm

Re: .med file format

Post by joha2 »

Does adding the -3 flag to gmsh make any difference?
I generated the torus.stp file from FreeCAD and performed a gmsh meshing with an old gmsh (2.12) in FreeCAD. Then I took the shape2mesh.geo file from the /tmp/ directory and modified it to MeshFormat 33 (med) and an appropriate output file value. I called it with (is this correct?)

Code: Select all

gmsh -3 - shape2mesh.geo
Import into FreeCAD leads to the same result than above with one additional fact: The Report View shows the following message:

Code: Select all

- Trace /build/freecad-daily-n64mm7/freecad-daily-0.18~rc+git201903142046~ubuntu16.04.1/src/3rdParty/salomesmesh/src/SMESH/DriverMED_R_SMESHDS_Mesh.cpp [995] : The following exception was caught:
	Not enough memory available
Very strange!

Best wishes
Johannes
Post Reply