# Real-Time Interactive Parallel Visualization of Large-Scale Flow-Field Data
## 3 Data-Partitioning Strategy Based on Grid Segmentation
### Grid Topology Reconstruction
#### 3.2.2 Grid Construction and Mapping  
The traditional method of reading EnSight Gold format files involves using a file pointer to sequentially read each byte of the file from beginning to end. In our implementation, we adopted a preprocessing approach to partition the file grid and distribute it evenly among the processes. Additionally, we constructed metadata for the geometric model file to facilitate subsequent operations. With the assistance of metadata, we can move the pointer randomly within the area responsible for the process and directly obtain the required data, without having to move the pointer byte by byte. In the geometric model file, the keyword \"element id given\" indicates that the file will display the given cell ID. However, this ID is not the ID of the cell topology structure but is only used to display grid numbering. In the file, the ID of the cell topology structure is numbered from 0 by default and increases in storage order. When reading data serially, you can directly build grid topology in sequence according to the order in which they are read. Since our parallel reading strategy partitions and assigns grids to different processes, it is impossible to build grid topology in storage order. Therefore, we propose a sub-grid topology construction and cell ID mapping method that uses the new coordinate point set mapped in Section 3.2.1 to rebuild new grid topologies in each process and map grids in geometric model files to them.  
In Section 3.2.1, we maintained a vector called \(\mathrm{modelList_{ijk}}\) to store the topology information of cells. This information consists of continuous bytes and can be directly read and saved to the vector. Using \(\mathrm{metaInfo.preBlock_{ijk}}\) and \(\mathrm{metaInfo.curBlock_{ijk}}\) in the metadata, we can calculate the starting ID (\(\mathrm{id_{begin}}\)) and ending ID (\(\mathrm{id_{end}}\)) of the cells under \(\mathrm{element_{k}}\) in \(\mathrm{part_{l}}\) that process i should handle. These values serve as boundary conditions for determining whether sub-grid construction has ended. Since partitioned sub-grids no longer share a set of coordinate points but instead use the new point set mapped to each process in Section 3.2.1 to construct new topologies for sub-grids, each process needs to maintain a grid-mapping table called \(\mathrm{T}_{\mathrm{realCellId}}^{\mathrm{i}}\). The variable \(\mathrm{originalCellId_{ijk}}\) (from \(\mathrm{id_{begin}}\) to \(\mathrm{id_{end}}\)) is used to iteratively construct new sub-grid topologies. This variable represents the ID of the cell in the geometric model file. Whenever a new grid topology is constructed, the variable \(\mathrm{originalCellId_{ijk}}\) is saved to the grid-mapping table \(\mathrm{T}_{\mathrm{realCellId}}^{\mathrm{i}}\). The index of this grid-mapping table increases from 0, and its index and value form a mapping relationship between the new grid ID and the original grid ID.  
Figure 6 illustrates the process of constructing and mapping a grid. As an example, we consider a scenario in which four processes are used to handle a quad-type grid with 5,880,097 cells from a geometric model file. Our data preprocessing program evenly divides the grid and assigns it to the four processes. Process 0 is responsible for processing 1,470,025 cells, whereas the remaining three processes each process 1,470,024 cells. When processing its assigned sub-grid, process 1 can use metadata to calculate the starting and ending IDs as 1,470,026 and 2,940,049, respectively, and allocate memory space of size 1,470,024 for the grid-mapping table \(\mathrm{T}_{\mathrm{realCellId}}^{\mathrm{i}}\). For the cell with ID 1,470,026 in the geometric model file (comprised of four points: 170,023, 182,964, 32,689, and 763,284), our coordinate-mapping strategy maps its topology to 0, 1, 2, and 3 and its ID to 0. The other three processes similarly construct their sub-grids and map the grid IDs.