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 #include "BenchKernelD3Q19ListAaCommon.h"
36 void FNAME(D3Q19ListAaKernel)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
39 Assert(kernelData != NULL);
42 Assert(cd->Omega > F(0.0));
43 Assert(cd->Omega < F(2.0));
45 KernelData * kd = (KernelData *)kernelData;
46 KernelDataList * kdl = (KernelDataList *)kernelData;
48 PdfT omega = cd->Omega;
49 PdfT omegaEven = omega;
50 // 1/4: best stability;
51 // 1/12: removes third-order advection error (best advection);
52 // 1/6: removes fourth-order diffusion error (best diffusion);
53 // 3/16: exact location of bounce back for poiseuille flow
54 PdfT magicParam = F(1.0)/F(12.0);
55 PdfT omegaOdd = F(1.0)/( F(0.5) + magicParam/(F(1.0)/omega - F(0.5)) );
57 PdfT evenPart = F(0.0);
58 PdfT oddPart = F(0.0);
59 PdfT dir_indep_trm = F(0.0);
61 const PdfT w_0 = F(1.0) / F(3.0);
62 const PdfT w_1 = F(1.0) / F(18.0);
63 const PdfT w_2 = F(1.0) / F(36.0);
65 const PdfT w_1_x3 = w_1 * F(3.0); const PdfT w_1_nine_half = w_1 * F(9.0)/F(2.0); PdfT w_1_indep = F(0.0);
66 const PdfT w_2_x3 = w_2 * F(3.0); const PdfT w_2_nine_half = w_2 * F(9.0)/F(2.0); PdfT w_2_indep = F(0.0);
73 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
74 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
78 PdfT * src = kd->Pdfs[0];
80 int maxIterations = cd->MaxIterations;
81 int nFluid = kdl->nFluid;
82 int nCells = kdl->nCells;
84 uint32_t adjListIndex;
85 uint32_t * adjList = kdl->AdjList;
92 VtkWrite(ld, kd, cd, -1);
98 KernelStatistics(kd, ld, cd, 0);
101 // TODO: outer openmp parallel
102 for(int iter = 0; iter < maxIterations; iter += 2) {
105 // --------------------------------------------------------------------
108 X_LIKWID_START("list-aa-even");
111 #pragma omp parallel for default(none) \
112 shared(nFluid, nCells, kd, kdl, adjList, omegaOdd, omegaEven, src) \
113 private(ux, uy, uz, dens, adjListIndex, evenPart, oddPart, dir_indep_trm, w_1_indep, w_2_indep, ui,\
115 pdf_N, pdf_E, pdf_S, pdf_W, \
116 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
117 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
118 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW)
120 #ifdef INTEL_OPT_DIRECTIVES
122 #pragma vector always
125 for (int index = 0; index < nFluid; ++index) {
128 #define I(index, dir) P_INDEX_3((nCells), (index), (dir))
130 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
131 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(index, idx)];
135 // #define LID_DRIVEN_CAVITY
137 #ifdef LID_DRIVEN_CAVITY
138 int nX = kd->Dims[0];
139 int nY = kd->Dims[1];
140 int nZ = kd->Dims[2];
142 int x = kdl->Coords[C_INDEX_X(index)];
143 int y = kdl->Coords[C_INDEX_Y(index)];
144 int z = kdl->Coords[C_INDEX_Z(index)];
146 if (z == nZ - 4 && x > 3 && x < (nX - 4) && y > 3 && y < (nY - 4)) {
152 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
153 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
154 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
155 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
156 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
157 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
158 #ifdef LID_DRIVEN_CAVITY
163 pdf_N + pdf_E + pdf_S + pdf_W +
164 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
165 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
166 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
168 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*F(3.0)/F(2.0);
171 src[I(index, D3Q19_C) ] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
174 w_1_indep = w_1*dir_indep_trm;
177 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
178 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
179 src[I(index, D3Q19_S)] = pdf_N - evenPart - oddPart;
180 src[I(index, D3Q19_N)] = pdf_S - evenPart + oddPart;
183 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
184 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
185 src[I(index, D3Q19_W)] = pdf_E - evenPart - oddPart;
186 src[I(index, D3Q19_E)] = pdf_W - evenPart + oddPart;
189 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
190 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
191 src[I(index, D3Q19_B)] = pdf_T - evenPart - oddPart;
192 src[I(index, D3Q19_T)] = pdf_B - evenPart + oddPart;
195 w_2_indep = w_2*dir_indep_trm;
198 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
199 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
200 src[I(index, D3Q19_SE)] = pdf_NW - evenPart - oddPart;
201 src[I(index, D3Q19_NW)] = pdf_SE - evenPart + oddPart;
204 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
205 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
206 src[I(index, D3Q19_SW)] = pdf_NE - evenPart - oddPart;
207 src[I(index, D3Q19_NE)] = pdf_SW - evenPart + oddPart;
210 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
211 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
212 src[I(index, D3Q19_BE)] = pdf_TW - evenPart - oddPart;
213 src[I(index, D3Q19_TW)] = pdf_BE - evenPart + oddPart;
216 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
217 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
218 src[I(index, D3Q19_BW)] = pdf_TE - evenPart - oddPart;
219 src[I(index, D3Q19_TE)] = pdf_BW - evenPart + oddPart;
222 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
223 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
224 src[I(index, D3Q19_BN)] = pdf_TS - evenPart - oddPart;
225 src[I(index, D3Q19_TS)] = pdf_BN - evenPart + oddPart;
228 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
229 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
230 src[I(index, D3Q19_BS)] = pdf_TN - evenPart - oddPart;
231 src[I(index, D3Q19_TN)] = pdf_BS - evenPart + oddPart;
233 } // loop over fluid nodes
235 X_LIKWID_STOP("list-aa-even");
237 // save current iteration
238 kdl->Iteration = iter;
240 kd->PdfsActive = src;
241 KernelAddBodyForce(kd, ld, cd);
244 // --------------------------------------------------------------------
247 X_LIKWID_START("list-aa-odd");
250 #pragma omp parallel for default(none) \
251 shared(nFluid, nCells, kd, kdl, adjList, omegaOdd, omegaEven, src) \
252 private(ux, uy, uz, dens, adjListIndex, evenPart, oddPart, dir_indep_trm, w_1_indep, w_2_indep, ui,\
254 pdf_N, pdf_E, pdf_S, pdf_W, \
255 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
256 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
257 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW)
259 #ifdef INTEL_OPT_DIRECTIVES
262 for (int index = 0; index < nFluid; ++index) {
265 adjListIndex = index * N_D3Q19_IDX;
267 // Load PDFs of local cell: pdf_N = src[adjList[adjListIndex + D3Q19_S]]; ...
268 pdf_C = src[P_INDEX_3(nCells, index, D3Q19_C)];
270 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[adjList[adjListIndex + idxinv]];
274 #ifdef LID_DRIVEN_CAVITY
275 int nX = kd->Dims[0];
276 int nY = kd->Dims[1];
277 int nZ = kd->Dims[2];
279 int x = kdl->Coords[C_INDEX_X(index)];
280 int y = kdl->Coords[C_INDEX_Y(index)];
281 int z = kdl->Coords[C_INDEX_Z(index)];
283 if (z == nZ - 4 && x > 3 && x < (nX - 4) && y > 3 && y < (nY - 4)) {
284 ux = F(0.1) * F(0.5)77;
289 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
290 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
291 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
292 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
293 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
294 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
295 #ifdef LID_DRIVEN_CAVITY
300 pdf_N + pdf_E + pdf_S + pdf_W +
301 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
302 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
303 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
305 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*F(3.0)/F(2.0);
307 adjListIndex = index * N_D3Q19_IDX;
310 src[I(index, D3Q19_C) ] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
313 w_1_indep = w_1*dir_indep_trm;
316 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
317 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
318 src[adjList[adjListIndex + D3Q19_N]] = pdf_N - evenPart - oddPart;
319 src[adjList[adjListIndex + D3Q19_S]] = pdf_S - evenPart + oddPart;
322 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
323 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
324 src[adjList[adjListIndex + D3Q19_E]] = pdf_E - evenPart - oddPart;
325 src[adjList[adjListIndex + D3Q19_W]] = pdf_W - evenPart + oddPart;
328 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
329 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
330 src[adjList[adjListIndex + D3Q19_T]] = pdf_T - evenPart - oddPart;
331 src[adjList[adjListIndex + D3Q19_B]] = pdf_B - evenPart + oddPart;
334 w_2_indep = w_2*dir_indep_trm;
337 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
338 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
339 src[adjList[adjListIndex + D3Q19_NW]] = pdf_NW - evenPart - oddPart;
340 src[adjList[adjListIndex + D3Q19_SE]] = pdf_SE - evenPart + oddPart;
343 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
344 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
345 src[adjList[adjListIndex + D3Q19_NE]] = pdf_NE - evenPart - oddPart;
346 src[adjList[adjListIndex + D3Q19_SW]] = pdf_SW - evenPart + oddPart;
349 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
350 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
351 src[adjList[adjListIndex + D3Q19_TW]] = pdf_TW - evenPart - oddPart;
352 src[adjList[adjListIndex + D3Q19_BE]] = pdf_BE - evenPart + oddPart;
355 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
356 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
357 src[adjList[adjListIndex + D3Q19_TE]] = pdf_TE - evenPart - oddPart;
358 src[adjList[adjListIndex + D3Q19_BW]] = pdf_BW - evenPart + oddPart;
361 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
362 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
363 src[adjList[adjListIndex + D3Q19_TS]] = pdf_TS - evenPart - oddPart;
364 src[adjList[adjListIndex + D3Q19_BN]] = pdf_BN - evenPart + oddPart;
367 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
368 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
369 src[adjList[adjListIndex + D3Q19_TN]] = pdf_TN - evenPart - oddPart;
370 src[adjList[adjListIndex + D3Q19_BS]] = pdf_BS - evenPart + oddPart;
373 } // loop over fluid nodes
375 X_LIKWID_STOP("list-aa-odd");
377 // save current iteration
378 kdl->Iteration = iter + 1;
381 kd->PdfsActive = src;
382 KernelAddBodyForce(kd, ld, cd);
386 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
387 kd->PdfsActive = src;
388 VtkWrite(ld, kd, cd, iter);
393 kd->PdfsActive = src;
394 KernelStatistics(kd, ld, cd, iter);
398 } // for (int iter = 0; ...
403 kd->PdfsActive = src;
404 VtkWrite(ld, kd, cd, maxIterations);
409 kd->PdfsActive = src;
410 KernelStatistics(kd, ld, cd, maxIterations);