CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Json (https://www.cfd-online.com/Forums/openfoam-programming-development/115875-json.html)

lakeat April 8, 2013 15:49

Json
 
I am wondering why doesn't OpenFOAM go with JSON format for its files? That would be easier for other programmers to parse.

haakon April 8, 2013 16:12

There is absolutely no rational reason for a tool like OpenFOAM to use JSON, XML or any other text/ASCII/UTF-8 based storage format. This is simply because 99.99999% (approx.) of the data stored as results from a CFD simulation is floating point numbers. Storing this as text is highly inefficient, independent on the format chosen (current format/JSON/XML etc.).

In my opinion, the only sensible choice is to store the data in a binary format. This should be based on commonly available and freely licensed APIs. My suggestions is HDF5 or CGNS, witch are two quite different formats (HDF5 is a general HPC data container, while CGNS is a CFD-specific file format).

lakeat April 8, 2013 16:29

Thanks, It is actually just this (1-99.99999%=0.00001%) files like fvSchemes or fvSolution that are what I am interested in and are what I would like to parse with. The information in these files is "kind of" "config" information.

Anyway, my point is, no matter what format OF uses, either HDF5 or CGNS or any other "popular" format, the outsiders can then use a relatively "standalone" program to parse OF files "cleanly" without calling OF libraries.

gschaider April 8, 2013 17:56

Quote:

Originally Posted by lakeat (Post 419195)
Thanks, It is actually just this (1-99.99999%=0.00001%) files like fvSchemes or fvSolution that are what I am interested in and are what I would like to parse with. The information in these files is "kind of" "config" information.

Anyway, my point is, no matter what format OF uses, either HDF5 or CGNS or any other "popular" format, the outsiders can then use a relatively "standalone" program to parse OF files "cleanly" without calling OF libraries.

In addition to what Hakon said there is also a pragmatic reason: when you look at http://en.wikipedia.org/wiki/JSON you see that this format was first conceived in 2001 and became popular around 2005. The OpenFOAM file-format originates (if I'm not mistaken) from the mid-90s ... around the time or even before XML was specified.

Writing a parser for the OpenFOAM-format is not THAT difficult. I mean: I managed with the parser that is in PyFoam. There are some interesting corner-cases but if you use a parser-generator then writing a parser that correctly reads >90% of all OF-files is pretty straight forward. And in principle the OF-format is just lists and dictionaries so if your programming language supports these then you "only" have to map the parsed data onto those data structures

lakeat April 8, 2013 17:58

Quote:

Originally Posted by gschaider (Post 419207)
Writing a parser for the OpenFOAM-format is not THAT difficult. I mean: I managed with the parser that is in PyFoam. There are some interesting corner-cases but if you use a parser-generator then writing a parser that correctly reads >90% of all OF-files is pretty straight forward. And in principle the OF-format is just lists and dictionaries so if your programming language supports these then you "only" have to map the parsed data onto those data structures

That is what I am doing right now.:)


All times are GMT -4. The time now is 20:48.