4.3.3. 结构网格

(1) 单块结构网格

CGNS 以树状结构存储数据,下图为单块结构网格的结构图。

../../_images/tree_cartesian.gif

下图为单块结构网格上网格中心格式流场数据的结构图,以下 node 为 Zone node 的子节点。

../../_images/tree_cartesian_solC.gif

基于 pyCGNS 的网格/流场输出 :

 1import CGNS.MAP as MAP
 2import CGNS.PAT.cgnslib as CL
 3import CGNS.PAT.cgnskeywords as CK
 4
 5#* Grid points
 6x = np.zeros([NI,NJ,NK])
 7y = np.zeros([NI,NJ,NK])
 8z = np.zeros([NI,NJ,NK])
 9
10#* Cell-centered flow solution
11density  = np.zeros([NI-1,NJ-1,NK-1])
12pressure = np.zeros([NI-1,NJ-1,NK-1])
13
14#* Create a new tree (i.e., root, CGNSTree_t node)
15Tree = CL.newCGNSTree()
16
17#* Add `Base` (CGNSBase_t node) to `Tree`
18nCellDim = 3
19nPhysDim = 3
20Base = CL.newBase(Tree, 'Base', nCellDim, nPhysDim)
21
22#* Add `Zone` (Zone_t node) to `Base`
23ZoneDims = np.array([[NI,NI-1,0],[NJ,NJ-1,0],[NK,NK-1,0]],
24                    dtype=np.int32, order='F')
25
26Zone = CL.newZone(Base, 'Zone_1', zsize=ZoneDims,
27                  ztype=CK.Structured_s, family='Example')
28
29#* Add `Grid` (GridCoordinates_t node) to `Zone`
30Grid = CL.newGridCoordinates(Zone, CK.GridCoordinates_s)
31
32# Add coordinates (DataArray_t node) to `Grid`
33cx = CL.newDataArray(Grid, CK.CoordinateX_s, x)
34cy = CL.newDataArray(Grid, CK.CoordinateY_s, y)
35cz = CL.newDataArray(Grid, CK.CoordinateZ_s, z)
36
37#* Add flow solution (FlowSolution_t node) to `Zone`
38Sol = CL.newFlowSolution(Zone, 'FlowSolution', CK.CellCenter_s)
39
40# Add data (DataArray_t node) to `Sol`
41sd = CL.newDataArray(Sol, CK.Density_s,  density)
42sp = CL.newDataArray(Sol, CK.Pressure_s, pressure)
43
44#* Output CGNS file
45filename = '../figures/example-01-structured.cgns'
46
47status = MAP.save(filename, Tree)