CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Parse OpenFoam polyMesh in binary stream format

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   March 6, 2018, 06:13
Default Parse OpenFoam polyMesh in binary stream format
New Member
Daniel Dumitrascu
Join Date: Mar 2018
Posts: 2
Rep Power: 0
Daniel1966 is on a distinguished road
Hi guys,

I'm working on a tool that needs to parse the OpenFoam polyMesh files (points, faces, boundary).

At this moment the tool can only parse the ASCII format of the polyMesh files and what I will need to add is the support for binary as well.

Unfortunately, I don't know how to interpret the binary stream format.
Is there any documentation on how OpenFoam parses these binary files ?
Or, can anyone direct me on the OpenFoam code that handles polyMesh binary stream ?

Any help is greatly appreciated.

Thank you in advance,
Daniel1966 is offline   Reply With Quote

Old   March 22, 2018, 06:12
Default Found the way to parse the binary files in polyMesh
New Member
Daniel Dumitrascu
Join Date: Mar 2018
Posts: 2
Rep Power: 0
Daniel1966 is on a distinguished road
After a little research I've managed to parse all 3 binary files.

boundary file was the easiest because even if the format from the header said that the file is in binary mode that was not the case for me. The file was in plain text (ASCII) so the parsing was easy to make.

points file was a little harder to parse because even if the header was in ASCII, the data itself was stored in binary. If you look at the ASCII format for the points file from a polyMesh you will see that we have the number of points and then the points represented as below:

(-0.03975 0.0026372 -0.00919138)
(-0.03975 0.00280753 -0.00910861)
(-0.03975 0.00297785 -0.00902584)
(-0.03975 0.00314818 -0.00894307)
(-0.03975 0.00331851 -0.0088603)
(-0.03975 0.00348883 -0.00877753)

In binary, the points are represented one after another so everything you need to do is to read chunks of 3 doubles till to reach the end. And that's it for the points.

The faces file was a little bit trickier. In ASCII the data is represented as below:

4(702 982 3040 1080)
4(19 1080 3040 346)
4(1 346 3040 982)
4(0 1 982 702)
4(0 702 1080 19)
4(0 19 346 1)

You have the number of faces (4789790 in this example) then, in front of every face the number of integers (4 in this example) forming the actual face, and the data for that face. In binary, you have the header which is in ASCII and then 2 vectors, one after another. The first one represents indexes for the data stored in the second vector. Why indexes? Well, because the faces don't have a constant number of integers (like in my example 4). You can find faces with 4, 5 or 6 integers and without the indexes telling you the start and end you wouldn't know how to read the data from the second vector. By the way, the indexes and the actual data are both integers.

I've spend some time finding this information, hope this will help anyone who is trying to work with polyMesh files in binary format.
Daniel1966 is offline   Reply With Quote

Old   September 24, 2020, 10:12
Default More info
Bob Tipton
Join Date: Apr 2020
Posts: 30
Rep Power: 5
Bob Tipton is on a distinguished road
There are few details that were unexpected.

Despite the file's ascii headers - they are binary files and need to be opened using ifstream::binary. Otherwise erroneous EOFs occur.

The vector sizes are ascii numbers followed by the same ()s as in the ascii format. Only the data within in the ()s is actually binary.

This requires some odd trickery of when to read as ascii ints and when to read binary ints. It's not obvious.
Bob Tipton is offline   Reply With Quote


ascii, binary, parse, polymesh, stream

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM] Using ASCII rather than binary VTK format because floatScalar and/or label are .... quarkz ParaView 0 November 22, 2017 21:58
[snappyHexMesh] How to define to right point for locationInMesh Mirage12 OpenFOAM Meshing & Mesh Conversion 7 March 13, 2016 15:07
[General] A "clean" solution to export binary ensight gold format from Fortran to Paraview? flotus1 ParaView 1 June 23, 2015 12:59
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 07:25
Sliding mesh error Karl Kevala FLUENT 4 February 21, 2001 16:52

All times are GMT -4. The time now is 06:57.