import meshes from OpenFOAM

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
filip2109
Posts: 12
Joined: Thu Nov 26, 2015 11:35 am

import meshes from OpenFOAM

Post by filip2109 »

Hello everyone,

I'm facing a little problem as I have to import a mesh from OpenFOAM into CS (4.2).
Is there any tool available to export meshes from OF to CS?

I currently have both software installed, so I tried the VTK export (but CS doesn't support VTK meshes?).
I tried the foamToEnsightParts but even though there is a partsInfo with the boundary names, when I run the preprocessor, no boundaries are detected. Is there any way to select the boundaries in CS?

Or maybe there is any other way to get the mesh? Maybe through Salome?

Sorry for the many questions and thank you very much for all help,
Kind regards

Filip
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: import meshes from OpenFOAM

Post by Yvan Fournier »

Hello,

Does the foamToEnsightParts tool have any options ? When reading an EnSight file, the Code_Saturne preprocessor will generate boundary information if the EnSight file contains the "node id given" option (in the .case file), so if the converter can generate such a file, you should be OK.

Other users might have some converters they could share, but there is no "standard" converter yet (we would like to add a direct foam reader in Code_Saturne, but this probably won't be done before a year or two.

On the SALOME forum, I have seen posts about MED to openFoam conversion, but unfortunately, I have not seen anything about openFoam to MED (though I have not checked recently).

Best regards,

Yvan
filip2109
Posts: 12
Joined: Thu Nov 26, 2015 11:35 am

Re: import meshes from OpenFOAM

Post by filip2109 »

Hi Yvan,

thank you for your reply. I don't think there is such an option in foamToEnsightParts, but given my little experience with it I may be totally wrong.

I've found a way to solve the problem and if it's ok I'd like to post it?
I've found a tool: foamMeshToMED, by mortbauer: https://github.com/mortbauer/foamMeshToMED which as the name implies converts a mesh to MED, including all boundaries. I've tested it on a couple of meshes and it seems to do a good job, I haven't found any issue with it.

If someone wants to try it, the only warning is that it needs OpenFOAM 2.3 installed. I tried at first using OF3 but it won't compile due to some issues with the openfoam library. With OF2.3 it installs without problems, once the location of hdf5.h and med.h is pointed out in the "Make/options" file.
Hope this helps.

Thank you again for your time Yvan,
Kind Regards
Filip
kkumar20
Posts: 12
Joined: Fri Jun 12, 2020 12:03 pm

Re: import meshes from OpenFOAM

Post by kkumar20 »

Dear Yuan,

Is there any new development on the work towards a direct foam reader in code_saturne? I have also tried various other indirect ways using Paraview and Gmsh as intermediaries but nothing really seems to work.. Thank you,

Kumar
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: import meshes from OpenFOAM

Post by Yvan Fournier »

Hello,

No, there has not been any work on an internal converter so far. I'd like to to, but is is low priority on our side. Anthor issue is that the OpenFoam documentation explains to "logical" contents of a mesh file, but not its binary structure (and being limited to text variants seems less interesting). And parsing the OpenFoam code to see how it i done is not an easy task for someone not already familiar with it... Pointers to relevant documentation is welcome. An I certainly would want to avoid a dependency to OpenFoam libraries in the main code_saturne build system (it is way complicated enough, especially with linear solver and in-situ postprocessing libraries). Though a standalone converter to the native code_saturne mesh format (compiled separately) could be a more realistic approach.

Did you try the Foam to MED tool mentioned in the post above. I know quite a few people have used it successfully. If it "partially works", please let me know and we can try to solve remaining issues.

Otherwise, if you have any possibility of exporting from OpenFoam to CGNS, that would seem to be a good option (whether directly or through a combination of tools).

Best regards,

Yvan
Luciano Garelli
Posts: 280
Joined: Fri Dec 04, 2015 1:42 pm

Re: import meshes from OpenFOAM

Post by Luciano Garelli »

Hello Kumar,

I'm using the foamMeshToMED converter mentioned in the previous post. I'm using it to convert snappyHexMesh and CfMesh meshes to CS without any problem. Boundary conditions and cell zones are correctly transferred to CS.

It's compiled with OF 4.x.

Regards,
Luciano
kkumar20
Posts: 12
Joined: Fri Jun 12, 2020 12:03 pm

Re: import meshes from OpenFOAM

Post by kkumar20 »

Thank you Yvan for your prompt explanation!

I haven't tried the foamMeshToMED utility as I thought it is fairly old and will not compile with the newest OF version I have (7 and 8). However I will give it a try. There is also another tool foamToCGNS as described here but that may as well be not usable since it was originally written for OF-1.5.

https://openfoamwiki.net/index.php/Sig_ ... Converters

However there could be other ways using a combination of Paraview, Gmsh and Salome. Paraview can export to CGNS which Salome should be able to read and further export to MED. It seems to work but for the mesh I tried, code_saturne preprocessor threw errors. But my Salome version was old so may be that is the reason.

I will investigate this further after upgrading both Salome and Gmsh and will report back. Thanks once again.

Kumar
kkumar20
Posts: 12
Joined: Fri Jun 12, 2020 12:03 pm

Re: import meshes from OpenFOAM

Post by kkumar20 »

Hello Luciano,

Thanks for your reply. I have only OF 7 and 8 and if this tool compiles with 4.x, may be there is a chance that it will compile with 7 as well with minimal changes. I will give it a shot.

Kumar
kkumar20
Posts: 12
Joined: Fri Jun 12, 2020 12:03 pm

Re: import meshes from OpenFOAM

Post by kkumar20 »

Hello Yvan,

I repeated the exercise for a few OpenFOAM meshes after upgrading both Paraview (5.6.0) and Salome (9.5.0) but was not really successful. Here are the sequence of steps I performed:

(1) open the mesh in Paraview (internalMesh + all the boundary patches) with the decompose Polyhedra option turned on

(2) Saved the mesh data in cgns format

(3) Imported the .cgns mesh in Salome MESH module ==> Salome reads the mesh correctly (actually Salome imports the mesh as two separate meshes: Base_Volume_Elements and Base_Surface_Elements containing all boundary patches)

(4) Formed a compound mesh of Base_Volume_Elements + Base_Surface_Elements and exported this mesh into .med format

Upto this stage, everything works perfectly. Now when I read this .med mesh into Code_Saturne preprocessor, various problems crop up including orientation and connectivity errors and the preprocessor stops.

Attached is a simple mesh and the code_saturne preprocessor output. From the output, it looks like cs is able to recognize the internal volume as well as the boundry patches but not able to do further processing.

Is there a way to overcome the problem in Salome? Thank you,

Kumar
Attachments
preprocessor.log
(4.47 KiB) Downloaded 167 times
Tank.med
(549.92 KiB) Downloaded 154 times
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: import meshes from OpenFOAM

Post by Yvan Fournier »

Hello,

If you have already used the "reorient" feature (as it seems) and it is not sufficient, there may be highly warped cells which are difficult to handle.

Did you try the Foam2med tool, which should (I hope; never tested it myself) be able to handle polyhedra directly and avoid requiring the ""decompose-polyhedra" step, and also better keep the mesh groups ?

Otherwise, you would need to use the error visualization output from the code_saturne preprocessor to check where you have negative volumes, and remove and remesh those portions (possibly under Salome).

Best regards,

Yvan
Post Reply