CGNS: A Standard Library for Computational Fluid Dynamics Data in C++
CGNS (CFD General Notation System) is a standardized file format and library for storing and exchanging computational fluid dynamics (CFD) data. It is widely used in aerospace, automotive engineering, and other fields that require fluid dynamics simulations. The CGNS library provides a rich set of functionalities for creating, reading, and manipulating CFD data, supporting multiple programming languages, including C++.
Core Features of CGNS
The core feature of CGNS is to store and manage grid data, physical field data, and related parameters in CFD simulations through standardized data structures. It supports various types of grids, including structured and unstructured grids. Each cell in a structured grid has fixed connectivity, while unstructured grids allow for more flexible cell shapes and connectivity.
In C++, the CGNS library provides a set of APIs for creating and manipulating CGNS files. For example, users can open a CGNS file using the cg_open function, create a new data base using the cg_base_write function, and define grid zones using the cg_zone_write function. These functions enable C++ developers to easily write CFD data to CGNS files or read data from CGNS files.

C++ Implementation of CGNS
cpp_cgns is a C++ library based on CGNS that provides functionality to map the CGNS tree structure into C++ memory. This mapping allows C++ developers to operate on CGNS data more naturally without directly handling the underlying CGNS file format details. The cpp_cgns library also offers utility functions for manipulating and transforming the CGNS tree structure, such as adding, deleting, or modifying nodes.
The dependencies of cpp_cgns include the std_e library, which provides generic algorithms and multidimensional array functionalities. Additionally, cpp_cgns supports interoperability with Python, enabling seamless integration with scientific computing libraries in Python, such as NumPy.
Application Scenarios of CGNS
CGNS is particularly important in aerospace engineering. For instance, during the aircraft design process, engineers need to perform CFD simulations on components like wings and fuselage to optimize their aerodynamic performance. CGNS files can store the grid data and computational results of these simulations, facilitating data exchange between different software tools.
Moreover, CGNS supports the connectivity of multi-zone grids. For example, in a multi-zone structured grid, the connections between adjacent zones can be defined using CGNS’s 1-to-1 connectivity feature. This functionality allows complex CFD simulations to be decomposed into multiple sub-regions, each of which can be computed independently, and the results can be merged later through CGNS files.
Advantages of CGNS
The main advantages of CGNS lie in its standardization and cross-platform characteristics. As an international standard, CGNS has received widespread support and recognition. Whether on Windows, Linux, or other operating systems, the CGNS library operates seamlessly, making it an ideal choice for data exchange in the CFD field.
Additionally, CGNS supports the storage of non-dimensional data. In CFD simulations, non-dimensional parameters (such as Mach number and Reynolds number) are crucial for understanding fluid behavior. CGNS allows users to store these non-dimensional parameters in files and provides detailed data classes and reference states for them.
Conclusion
CGNS is a powerful tool that provides a standardized solution for the storage and exchange of CFD data. Through the C++ library cpp_cgns, developers can easily integrate CGNS functionalities into their applications. Whether in aerospace engineering, automotive design, or other fields requiring CFD simulations, CGNS offers reliable data management support.