1 // --------------------------------------------------------------------------
4 // Markus Wittmann, 2016-2017
5 // RRZE, University of Erlangen-Nuremberg, Germany
6 // markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
9 // LSS, University of Erlangen-Nuremberg, Germany
11 // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
13 // LbmBenchKernels is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
18 // LbmBenchKernels is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
23 // You should have received a copy of the GNU General Public License
24 // along with LbmBenchKernels. If not, see <http://www.gnu.org/licenses/>.
26 // --------------------------------------------------------------------------
27 #ifndef __BENCH_KERNEL_D3Q19_LIST_COMMON_H__
28 #define __BENCH_KERNEL_D3Q19_LIST_COMMON_H__
35 #define N_D3Q19_IDX 18
37 typedef struct KernelDataList_
40 uint32_t * AdjList; // Stores PDF indices, which are the destination for propagation.
41 // Determine the destination for node index n and direction d via:
42 // (n * N_D3Q19_IDX) + d
43 uint32_t * Grid; // Stores the node indices; use L_INDEX_4 macro for access.
44 uint32_t * Coords; // Map node indices to coordiantes; use C_INDEX_* macro for access.
45 int nFluid; // Number of fluid nodes allocated, i.e. length of adjList * N_D3Q19_IDX.
46 int nCells; // Total number of nodes allocated, including nodes for padding!
50 // Macro for casting KernelData * to KernelDataList *.
51 #define KDL(_x_) ((KernelDataList *)(_x_))
56 // Build a function name extended by the propagation model name and the data layout.
57 // FNANEM(test) will be expanded to test_PushSoA if DATA_LAYOUT_NAME is defined
58 // as SoA and PROP_MODEL is defined as Push.
59 #define FNAME(functionName) JOIN(JOIN(functionName,_),JOIN(PROP_MODEL_NAME,DATA_LAYOUT_NAME))
61 #ifndef DATA_LAYOUT_NAME
62 #error DATA_LAYOUT_NAME must be defined
65 #ifndef PROP_MODEL_NAME
66 #error PROP_MODEL_NAME must be defined
69 // -----------------------------------------------------------------------
70 // Index function for accesssing PDF array for different data layouts.
72 #define P_INDEX_3 FNAME(PINDEX3)
74 static inline int FNAME(PINDEX3)(int nCells, int cellIndex, int d)
77 Assert(cellIndex >= 0);
78 Assert(cellIndex < nCells);
84 #error Not implemented for this discretization.
87 #ifdef DATA_LAYOUT_SOA
88 return d * nCells + cellIndex;
90 return cellIndex * N_D3Q19 + d;
92 #error P_INDEX_3 function not implemented for chosen data layout.
96 #define P_INDEX_5 FNAME(PINDEX5)
98 static inline int FNAME(PINDEX5)(KernelDataList * kdl, int x, int y, int z, int d)
102 uint32_t * grid = kdl->Grid;
103 int * dims = kdl->kd.Dims;
105 Assert(grid != NULL);
106 Assert(dims != NULL);
110 Assert(x >= 0 && x < dims[0]);
111 Assert(y >= 0 && y < dims[1]);
112 Assert(z >= 0 && z < dims[2]);
113 Assert(d >= 0 && d < N_D3Q19);
116 return P_INDEX_3(kdl->nCells, kdl->Grid[L_INDEX_4(kdl->kd.Dims, x, y, z)], d);
119 // -----------------------------------------------------------------------
120 // Macros for accessing coord array
122 #define C_INDEX_X(cellIndex) C_INDEX(cellIndex, 0)
123 #define C_INDEX_Y(cellIndex) C_INDEX(cellIndex, 1)
124 #define C_INDEX_Z(cellIndex) C_INDEX(cellIndex, 2)
126 static inline int C_INDEX(int cellIndex, int xyz)
128 Assert(cellIndex >= 0);
132 return cellIndex * 3 + xyz;
136 #endif // __BENCH_KERNEL_D3Q19_LIST_COMMON_H__