add citation information
[LbmBenchmarkKernelsPublic.git] / src / BenchKernelD3Q19ListCommon.h
CommitLineData
10988083
MW
1// --------------------------------------------------------------------------
2//
3// Copyright
4// Markus Wittmann, 2016-2017
5// RRZE, University of Erlangen-Nuremberg, Germany
6// markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
7//
8// Viktor Haag, 2016
9// LSS, University of Erlangen-Nuremberg, Germany
10//
11// This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
12//
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.
17//
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.
22//
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/>.
25//
26// --------------------------------------------------------------------------
27#ifndef __BENCH_KERNEL_D3Q19_LIST_COMMON_H__
28#define __BENCH_KERNEL_D3Q19_LIST_COMMON_H__
29
30
31#include "Kernel.h"
32
33#include <inttypes.h>
34
35#define N_D3Q19_IDX 18
36
37typedef struct KernelDataList_
38{
39 KernelData kd;
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!
47} KernelDataList;
48
49
50// Macro for casting KernelData * to KernelDataList *.
51#define KDL(_x_) ((KernelDataList *)(_x_))
52
53
54
55
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))
60
61#ifndef DATA_LAYOUT_NAME
62 #error DATA_LAYOUT_NAME must be defined
63#endif
64
65#ifndef PROP_MODEL_NAME
66 #error PROP_MODEL_NAME must be defined
67#endif
68
69// -----------------------------------------------------------------------
70// Index function for accesssing PDF array for different data layouts.
71
72#define P_INDEX_3 FNAME(PINDEX3)
73
74static inline int FNAME(PINDEX3)(int nCells, int cellIndex, int d)
75{
76 Assert(nCells > 0);
77 Assert(cellIndex >= 0);
78 Assert(cellIndex < nCells);
79
80 Assert(d >= 0);
81 #ifdef D3Q19
82 Assert(d < N_D3Q19);
83 #else
84 #error Not implemented for this discretization.
85 #endif
86
87#ifdef DATA_LAYOUT_SOA
88 return d * nCells + cellIndex;
89#elif DATA_LAYOUT_AOS
90 return cellIndex * N_D3Q19 + d;
91#else
92 #error P_INDEX_3 function not implemented for chosen data layout.
93#endif
94}
95
96#define P_INDEX_5 FNAME(PINDEX5)
97
98static inline int FNAME(PINDEX5)(KernelDataList * kdl, int x, int y, int z, int d)
99{
100 Assert(kdl != NULL);
101#ifdef DEBUG
102 uint32_t * grid = kdl->Grid;
103 int * dims = kdl->kd.Dims;
104
105 Assert(grid != NULL);
106 Assert(dims != NULL);
107 Assert(dims[0] > 0);
108 Assert(dims[1] > 0);
109 Assert(dims[2] > 0);
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);
114#endif
115
116 return P_INDEX_3(kdl->nCells, kdl->Grid[L_INDEX_4(kdl->kd.Dims, x, y, z)], d);
117}
118
119// -----------------------------------------------------------------------
120// Macros for accessing coord array
121
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)
125
126static inline int C_INDEX(int cellIndex, int xyz)
127{
128 Assert(cellIndex >= 0);
129 Assert(xyz >= 0);
130 Assert(xyz < 3);
131
132 return cellIndex * 3 + xyz;
133}
134
135
136#endif // __BENCH_KERNEL_D3Q19_LIST_COMMON_H__
This page took 0.062925 seconds and 5 git commands to generate.