# Vectorized Numerical Algorithms to Solve Internal Problems of Computational Fluid Dynamics
## 4 Addressing Mesh Cells
### Flux Computation  
The face separating two neighboring cells is selected as the object to which the flux is assigned. Linking the flux to a face allows to avoid re-calculating it when implementing conservation laws for the control volume. The same flux value is involved in constructing balance relations for two neighboring cells (the flux entering a cell equals the flux leaving the neighboring cell), which ensures the conservativeness of the numerical scheme.  
When introducing ghost cells, all control volumes located inside the computational domain have neighbors, and the calculation of fluxes for all faces is carried out using a single algorithm. To calculate fluxes, two sets of index vectors are formed (Figure 4). One of these vectors, **pCFL**, defines the set of all cells located to the left of the face (Figure 4a), and  
Figure 3: Examples of index vectors corresponding to ghost cells.  
Figure 2: Example of extended computational domain.  
another index vector, **pCFR**, provides a wildcard addressing operation for the set of all right cells (Figure 4b). It is defined as follows  
\[\textbf{pCFR}=\textbf{pCFL}+m.\]  
The vector operation of numerical fluxes is provided by  
\[\textbf{F}(\textbf{pC})=\textbf{F}(\textbf{U}(\textbf{pCFL}),\,\textbf{U}( \textbf{pCFR})). \tag{3}\]  
The sequence of calculations written in ordinary index expressions has the form  
\[\textbf{F}_{i+1/2,j}=\textbf{F}(\textbf{U}_{i+1,j},\,\textbf{U}_{i,j}). \tag{4}\]  
Indices \(i\) and \(j\) refer to the center of the cell, and the index \(i+1/2\) corresponds to the face separating cells with indices \(i\) and \(i+1\).  
There is a difference between expressions (3) and (4). While relation (3) defines the entire set of threads, relation (4) requires a double round of calculations on indices \(i\) and \(j\). The advantages of the expression-based approach (3) are manifested when using computing environments that allow the execution of vectorized operations.  
Since the flux is assigned to the cell face, and flow quantities are assigned to cell center (Figure 5), it is necessary to determine the correspondence of index expressions for calculating the fluxes with the indices that define the cells of the computational domain. Even though a flux contains fewer elements than an extended set of cells, it makes sense to store it in a structure of the same size (although a number of elements are not used, but addressing convenience and clarity prevail over memory-saving considerations).  
Figure 4: Examples of sets of left and right cells to calculate fluxes on the left (**a**) and right (**b**) faces.  
An index vector is designed to determine the set of fluxes through the cell faces using a layout shown in Figure 6.  
With this data organization, vectorized balance relationships are written for each cell of computational domain. Addressing fluxes through a set of cell edges is shown in Figure 7. For all computational cells defined by the index vector **pC**, fluxes through their left faces are determined by the index vector **pC** - \(m\), and fluxes through the right faces are determined by the index vector **pC**. The value \(m\) represents the number of cells in the extended cell area column and determines the shift from a two-dimensional matrix structure to a linear arrangement of elements.