The pyCGNS Python module is a collection of 7 modules around the CGNS standard. Before v4, these modules were independent Python modules with more or less dependancies to each other. We gather all of them to have a common build/install/doc and test process, moreover this insures a better consistency between them.
The pyCGNS module now includes (former package names)
- MAP, the Mapper, new in v4 gives basic load/save
- function from/to CGNS/SIDS and CGNS/HDF5. This very sinple module is able to read/write GCNS/HDF5 files and translate them to CGNS/Python. This is the main feature of pyCGNS v4.0.
- PAT, the PatterMaker, a full CGNS/SIDS patterns using
- the CGNS/Python mapping. This is pure python module, it creates and modify CGNS/Python trees without the help of any HDF5 or even ADf calls.
- NAV, the Navigater (pyS7), a graphical browser that can
- handle CGNS/Python, CGNS/HDF5 and CGNS/ADF file formats. It is slightly different to adfviewer because it actually a tree editor, you can copy/cut/paste CGNS/Python trees and quickly draft or modify your CGNS tree.
- WRA, the Wrapper (pyCGNS), is a CGNS/MLL and
- CGNS/ADF Python wrapping. All the CGNS/MLL functions are mapped to their Python clone.
VAL,the Validater (pyC5), an XML grammar based validation of a CGNS/Python tree, for example produced using MAP or PAT. Unsuable in v4.0
TRA, the Translater (pyCRAB), a set of translators from/to various formats. Unsuable in v4.0
DAT, the DataTracer (pyDAX), some DBMS services for CGNS/HDF5 files. Unsuable in v4.0
The CGNS.MAP module implements the CGNS/Python mapping. You can load/save a CGNS/HDF5 file using the simple MAP functions (below, the >>> string is the python interpreter prompt):
>>>import CGNS.MAP
>>>(tree,links)=CGNS.MAP.load("./001Disk.hdf",CGNS.MAP.S2P_FOLLOWLINKS)
>>>print tree
['CGNSTree', None, [['CGNSLibraryVersion',array([ 2.4000001],dtype=float32),
[], 'CGNSLibraryVersion_t'], ['Disk', array([3, 3], dtype=int32),
[['.Solver#Command', ...
Now tree is a Python list with the whole`` ./001Disk.hdf`` CGNS tree into, with the data structure as described in SIDS-to-Python.
The previously loaded CGNS/Python tree is modified using plain Python functions and types. The CGNS.APP module contains utilities, we use the getNodeByPath function which returns a CGNS/Python node with the target tree and the target node path as parameters.:
import CGNS.APP.path_utils as U
node=U.getNodeByPath("/Disk/zone1/ZoneBC/ext1/PointRange",tree)
The returned node is a list of 4 Python values, the name (a string), the value of the node (a Numpy array), the list of children and the CGNS type of the node (string).
We want to create a CGNS/HDF5 file with a simple base and a reference state:
import CGNS.MAP
import CGNS.PAT
T=CGNS.PAT.newCGNS()
CGNS.PAT.newBase(T,'Test Case 01',3,3) # name, physical dim, topological dim
CGNS.PAT.newSimulationType(T)
CGNS.PAT.newReferenceState(T)
If you really want to use CGNS/MLL, for example if you have a large toolbox with old pyCGNS scripts, you can import CGNS.WRA but you have to change your imports:
import CGNS.WRA.wrapper
filesol=CGNS.WRA.wrapper.pyCGNS(sname,CGNS.WRA.wrapper.MODE_WRITE)
filesol.basewrite('Base',3,3)
filesol.close()