Commit | Line | Data |
---|---|---|
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 | // | |
8cafd9ea MW |
11 | // Michael Hussnaetter, 2017-2018 |
12 | // University of Erlangen-Nuremberg, Germany | |
13 | // michael.hussnaetter -at- fau.de | |
14 | // | |
10988083 MW |
15 | // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels). |
16 | // | |
17 | // LbmBenchKernels is free software: you can redistribute it and/or modify | |
18 | // it under the terms of the GNU General Public License as published by | |
19 | // the Free Software Foundation, either version 3 of the License, or | |
20 | // (at your option) any later version. | |
21 | // | |
22 | // LbmBenchKernels is distributed in the hope that it will be useful, | |
23 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | // GNU General Public License for more details. | |
26 | // | |
27 | // You should have received a copy of the GNU General Public License | |
28 | // along with LbmBenchKernels. If not, see <http://www.gnu.org/licenses/>. | |
29 | // | |
30 | // -------------------------------------------------------------------------- | |
31 | #ifndef __KERNEL_H__ | |
32 | #define __KERNEL_H__ | |
33 | ||
34 | #include "Base.h" | |
35 | #include "Lattice.h" | |
36 | ||
37 | #ifdef DATA_LAYOUT_NAME | |
38 | #error DATA_LAYOUT_NAME must not be defined here. | |
39 | #endif | |
40 | ||
41 | #ifdef PROP_MODEL_NAME | |
42 | #error PROP_MODEL_NAME must not be defined here. | |
43 | #endif | |
44 | ||
45 | ||
46 | #ifdef DATA_LAYOUT_SOA | |
47 | #define DATA_LAYOUT_NAME SoA | |
48 | #endif | |
49 | ||
50 | #ifdef DATA_LAYOUT_AOS | |
51 | #define DATA_LAYOUT_NAME AoS | |
52 | #endif | |
53 | ||
8cafd9ea MW |
54 | #ifdef DATA_LAYOUT_AOSOA |
55 | #define DATA_LAYOUT_NAME AoSoA | |
56 | // number of cells consecutively stored (-> array length) | |
57 | #define AOSOA_BLOCK_SIZE 8 | |
58 | #endif | |
59 | ||
10988083 MW |
60 | #ifdef PROP_MODEL_PUSH |
61 | #define PROP_MODEL_NAME Push | |
62 | #endif | |
63 | ||
64 | #ifdef PROP_MODEL_PULL | |
65 | #define PROP_MODEL_NAME Pull | |
66 | #endif | |
67 | ||
68 | #ifdef PROP_MODEL_AA | |
e3f82424 | 69 | #define PROP_MODEL_NAME Aa |
10988083 MW |
70 | #endif |
71 | ||
72 | ||
0fde6e45 MW |
73 | #ifdef PRECISION_DP |
74 | typedef double PdfT; | |
75 | #elif defined(PRECISION_SP) | |
76 | typedef float PdfT; | |
77 | #else | |
78 | #error PRECISION must be defined as dp or sp. | |
79 | #endif | |
10988083 | 80 | |
0fde6e45 | 81 | #define F(number) (PdfT)(number) |
10988083 MW |
82 | |
83 | ||
84 | #define D3Q19 | |
85 | ||
86 | ||
87 | #define N_D3Q19 19 | |
88 | ||
89 | #define D3Q19_N 0 | |
90 | #define D3Q19_S 1 | |
91 | #define D3Q19_E 2 | |
92 | #define D3Q19_W 3 | |
93 | ||
94 | #define D3Q19_NE 4 | |
95 | #define D3Q19_SE 5 | |
96 | #define D3Q19_NW 6 | |
97 | #define D3Q19_SW 7 | |
98 | ||
99 | #define D3Q19_T 8 | |
100 | #define D3Q19_TN 9 | |
101 | #define D3Q19_TE 10 | |
102 | #define D3Q19_TW 11 | |
103 | #define D3Q19_TS 12 | |
104 | ||
105 | #define D3Q19_B 13 | |
106 | #define D3Q19_BS 14 | |
107 | #define D3Q19_BN 15 | |
108 | #define D3Q19_BW 16 | |
109 | #define D3Q19_BE 17 | |
110 | ||
111 | #define D3Q19_C 18 // IMPORTANT: Center particle must be the last one. | |
112 | ||
113 | // --- | |
114 | ||
115 | #ifdef X | |
116 | #error X is not allowed to be defined here! | |
117 | #endif | |
118 | ||
119 | // The following list must be sorted ascending according | |
120 | // to the index of the direction, i.e. D3Q19_N, D3Q19_S, ... | |
121 | #define D3Q19_LIST \ | |
122 | X(N, D3Q19_N, D3Q19_S, 0, 1, 0) \ | |
123 | X(S, D3Q19_S, D3Q19_N, 0, -1, 0) \ | |
124 | X(E, D3Q19_E, D3Q19_W, 1, 0, 0) \ | |
125 | X(W, D3Q19_W, D3Q19_E, -1, 0, 0) \ | |
126 | X(NE, D3Q19_NE, D3Q19_SW, 1, 1, 0) \ | |
127 | X(SE, D3Q19_SE, D3Q19_NW, 1, -1, 0) \ | |
128 | X(NW, D3Q19_NW, D3Q19_SE, -1, 1, 0) \ | |
129 | X(SW, D3Q19_SW, D3Q19_NE, -1, -1, 0) \ | |
130 | X(T, D3Q19_T, D3Q19_B, 0, 0, 1) \ | |
131 | X(TN, D3Q19_TN, D3Q19_BS, 0, 1, 1) \ | |
132 | X(TE, D3Q19_TE, D3Q19_BW, 1, 0, 1) \ | |
133 | X(TW, D3Q19_TW, D3Q19_BE, -1, 0, 1) \ | |
134 | X(TS, D3Q19_TS, D3Q19_BN, 0, -1, 1) \ | |
135 | X(B, D3Q19_B, D3Q19_T, 0, 0, -1) \ | |
136 | X(BS, D3Q19_BS, D3Q19_TN, 0, -1, -1) \ | |
137 | X(BN, D3Q19_BN, D3Q19_TS, 0, 1, -1) \ | |
138 | X(BW, D3Q19_BW, D3Q19_TE, -1, 0, -1) \ | |
139 | X(BE, D3Q19_BE, D3Q19_TW, 1, 0, -1) \ | |
140 | X(C, D3Q19_C, D3Q19_C, 0, 0, 0) | |
141 | ||
142 | #define D3Q19_LIST_WO_C \ | |
143 | X(N, D3Q19_N, D3Q19_S, 0, 1, 0) \ | |
144 | X(S, D3Q19_S, D3Q19_N, 0, -1, 0) \ | |
145 | X(E, D3Q19_E, D3Q19_W, 1, 0, 0) \ | |
146 | X(W, D3Q19_W, D3Q19_E, -1, 0, 0) \ | |
147 | X(NE, D3Q19_NE, D3Q19_SW, 1, 1, 0) \ | |
148 | X(SE, D3Q19_SE, D3Q19_NW, 1, -1, 0) \ | |
149 | X(NW, D3Q19_NW, D3Q19_SE, -1, 1, 0) \ | |
150 | X(SW, D3Q19_SW, D3Q19_NE, -1, -1, 0) \ | |
151 | X(T, D3Q19_T, D3Q19_B, 0, 0, 1) \ | |
152 | X(TN, D3Q19_TN, D3Q19_BS, 0, 1, 1) \ | |
153 | X(TE, D3Q19_TE, D3Q19_BW, 1, 0, 1) \ | |
154 | X(TW, D3Q19_TW, D3Q19_BE, -1, 0, 1) \ | |
155 | X(TS, D3Q19_TS, D3Q19_BN, 0, -1, 1) \ | |
156 | X(B, D3Q19_B, D3Q19_T, 0, 0, -1) \ | |
157 | X(BS, D3Q19_BS, D3Q19_TN, 0, -1, -1) \ | |
158 | X(BN, D3Q19_BN, D3Q19_TS, 0, 1, -1) \ | |
159 | X(BW, D3Q19_BW, D3Q19_TE, -1, 0, -1) \ | |
160 | X(BE, D3Q19_BE, D3Q19_TW, 1, 0, -1) | |
161 | ||
162 | ||
163 | extern int D3Q19_X[N_D3Q19]; | |
164 | extern int D3Q19_Y[N_D3Q19]; | |
165 | extern int D3Q19_Z[N_D3Q19]; | |
166 | extern int D3Q19_INV[N_D3Q19]; | |
167 | ||
168 | extern const char * D3Q19_NAMES[N_D3Q19]; | |
169 | ||
170 | ||
171 | ||
172 | typedef struct CaseData_ { | |
173 | PdfT Omega; | |
174 | PdfT RhoIn; | |
175 | PdfT RhoOut; | |
176 | PdfT Ux; | |
177 | PdfT Uy; | |
178 | PdfT Uz; | |
179 | PdfT XForce; | |
180 | int MaxIterations; | |
181 | int VtkOutput; | |
182 | int VtkModulus; | |
183 | int StatisticsModulus; | |
184 | } CaseData; | |
185 | ||
186 | ||
187 | typedef struct KernelData_ { | |
188 | PdfT * Pdfs[2]; | |
189 | PdfT * SrcPdfs; | |
190 | PdfT * DstPdfs; | |
191 | PdfT * PdfsActive; | |
192 | int Dims[3]; | |
193 | int GlobalDims[3]; | |
194 | int Offsets[3]; | |
195 | int * ObstIndices; | |
196 | int nObstIndices; | |
197 | int * BounceBackPdfsSrc; | |
198 | int * BounceBackPdfsDst; | |
199 | int nBounceBackPdfs; | |
8cafd9ea MW |
200 | double LoopBalance; // loopBalance when set in kernel init, Main.c may use it to derive metrics |
201 | double Duration; // duration when set in kernel routine, Main.c may use it to derive metrics | |
10988083 MW |
202 | |
203 | void (* BoundaryConditionsGetPdf)(struct KernelData_ * kd, int x, int y, int z, int dir, PdfT * pdf); | |
204 | void (* BoundaryConditionsSetPdf)(struct KernelData_ * kd, int x, int y, int z, int dir, PdfT pdf); | |
205 | ||
206 | void (* GetNode)(struct KernelData_ * kd, int x, int y, int z, PdfT * pdfs); | |
207 | void (* SetNode)(struct KernelData_ * kd, int x, int y, int z, PdfT * pdfs); | |
208 | ||
209 | void (* Kernel)(LatticeDesc * ld, struct KernelData_ * kd, CaseData * cd); | |
210 | ||
211 | } KernelData; | |
212 | ||
8cafd9ea MW |
213 | |
214 | #define X_KERNEL_START(_kd) do { _kd->Duration = Time(); } while (0) | |
215 | #define X_KERNEL_END(_kd) do { _kd->Duration = Time() - _kd->Duration; } while (0) | |
216 | ||
10988083 MW |
217 | typedef struct Parameters_ { |
218 | int nArgs; | |
219 | char ** Args; | |
220 | int nKernelArgs; | |
221 | char ** KernelArgs; | |
222 | } Parameters; | |
223 | ||
224 | void KernelComputeBoundaryConditions(KernelData * kd, LatticeDesc * ld, CaseData * cd); | |
225 | ||
226 | PdfT KernelDensity(KernelData * kd, LatticeDesc * ld); | |
227 | ||
228 | void KernelStatistics(KernelData * kd, LatticeDesc * ld, CaseData * cd, int iteration); | |
229 | void KernelStatisticsAdv(KernelData * kd, LatticeDesc * ld, CaseData * cd, int iteration, int forceOutput); | |
230 | ||
231 | ||
232 | void KernelSetInitialDensity (LatticeDesc * ld, KernelData * kd, CaseData * cd); | |
233 | void KernelSetInitialVelocity(LatticeDesc * ld, KernelData * kd, CaseData * cd); | |
234 | ||
235 | void KernelVerifiy(LatticeDesc * ld, KernelData * kd, CaseData * cd, PdfT * errorNorm); | |
236 | ||
237 | void KernelAddBodyForce(KernelData * kd, LatticeDesc * ld, CaseData * cd); | |
238 | ||
239 | #endif // __KERNEL_H__ |