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 > 0.0);
43 Assert(cd->Omega < 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 = 1.0/12.0;
55 PdfT omegaOdd = 1.0/( 0.5 + magicParam/(1.0/omega - 0.5) );
59 PdfT dir_indep_trm = 0.0;
61 const PdfT w_0 = 1.0 / 3.0;
62 const PdfT w_1 = 1.0 / 18.0;
63 const PdfT w_2 = 1.0 / 36.0;
65 const PdfT w_1_x3 = w_1 * 3.0; const PdfT w_1_nine_half = w_1 * 9.0/2.0; PdfT w_1_indep = 0.0;
66 const PdfT w_2_x3 = w_2 * 3.0; const PdfT w_2_nine_half = w_2 * 9.0/2.0; PdfT w_2_indep = 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 for (int index = 0; index < nFluid; ++index) {
123 #define I(index, dir) P_INDEX_3((nCells), (index), (dir))
125 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
126 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(index, idx)];
130 // #define LID_DRIVEN_CAVITY
132 #ifdef LID_DRIVEN_CAVITY
133 int nX = kd->Dims[0];
134 int nY = kd->Dims[1];
135 int nZ = kd->Dims[2];
137 int x = kdl->Coords[C_INDEX_X(index)];
138 int y = kdl->Coords[C_INDEX_Y(index)];
139 int z = kdl->Coords[C_INDEX_Z(index)];
141 if (z == nZ - 4 && x > 3 && x < (nX - 4) && y > 3 && y < (nY - 4)) {
147 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
148 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
149 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
150 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
151 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
152 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
153 #ifdef LID_DRIVEN_CAVITY
158 pdf_N + pdf_E + pdf_S + pdf_W +
159 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
160 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
161 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
163 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*3.0/2.0;
166 src[I(index, D3Q19_C) ] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
169 w_1_indep = w_1*dir_indep_trm;
172 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
173 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
174 src[I(index, D3Q19_S)] = pdf_N - evenPart - oddPart;
175 src[I(index, D3Q19_N)] = pdf_S - evenPart + oddPart;
178 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
179 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
180 src[I(index, D3Q19_W)] = pdf_E - evenPart - oddPart;
181 src[I(index, D3Q19_E)] = pdf_W - evenPart + oddPart;
184 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
185 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
186 src[I(index, D3Q19_B)] = pdf_T - evenPart - oddPart;
187 src[I(index, D3Q19_T)] = pdf_B - evenPart + oddPart;
190 w_2_indep = w_2*dir_indep_trm;
193 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
194 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
195 src[I(index, D3Q19_SE)] = pdf_NW - evenPart - oddPart;
196 src[I(index, D3Q19_NW)] = pdf_SE - evenPart + oddPart;
199 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
200 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
201 src[I(index, D3Q19_SW)] = pdf_NE - evenPart - oddPart;
202 src[I(index, D3Q19_NE)] = pdf_SW - evenPart + oddPart;
205 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
206 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
207 src[I(index, D3Q19_BE)] = pdf_TW - evenPart - oddPart;
208 src[I(index, D3Q19_TW)] = pdf_BE - evenPart + oddPart;
211 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
212 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
213 src[I(index, D3Q19_BW)] = pdf_TE - evenPart - oddPart;
214 src[I(index, D3Q19_TE)] = pdf_BW - evenPart + oddPart;
217 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
218 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
219 src[I(index, D3Q19_BN)] = pdf_TS - evenPart - oddPart;
220 src[I(index, D3Q19_TS)] = pdf_BN - evenPart + oddPart;
223 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
224 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
225 src[I(index, D3Q19_BS)] = pdf_TN - evenPart - oddPart;
226 src[I(index, D3Q19_TN)] = pdf_BS - evenPart + oddPart;
228 } // loop over fluid nodes
230 X_LIKWID_STOP("list-aa-even");
232 // save current iteration
233 kdl->Iteration = iter;
235 kd->PdfsActive = src;
236 KernelAddBodyForce(kd, ld, cd);
239 // --------------------------------------------------------------------
242 X_LIKWID_START("list-aa-odd");
245 #pragma omp parallel for default(none) \
246 shared(nFluid, nCells, kd, kdl, adjList, omegaOdd, omegaEven, src) \
247 private(ux, uy, uz, dens, adjListIndex, evenPart, oddPart, dir_indep_trm, w_1_indep, w_2_indep, ui,\
249 pdf_N, pdf_E, pdf_S, pdf_W, \
250 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
251 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
252 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW)
254 for (int index = 0; index < nFluid; ++index) {
257 adjListIndex = index * N_D3Q19_IDX;
259 // Load PDFs of local cell: pdf_N = src[adjList[adjListIndex + D3Q19_S]]; ...
260 pdf_C = src[P_INDEX_3(nCells, index, D3Q19_C)];
262 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[adjList[adjListIndex + idxinv]];
266 #ifdef LID_DRIVEN_CAVITY
267 int nX = kd->Dims[0];
268 int nY = kd->Dims[1];
269 int nZ = kd->Dims[2];
271 int x = kdl->Coords[C_INDEX_X(index)];
272 int y = kdl->Coords[C_INDEX_Y(index)];
273 int z = kdl->Coords[C_INDEX_Z(index)];
275 if (z == nZ - 4 && x > 3 && x < (nX - 4) && y > 3 && y < (nY - 4)) {
281 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
282 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
283 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
284 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
285 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
286 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
287 #ifdef LID_DRIVEN_CAVITY
292 pdf_N + pdf_E + pdf_S + pdf_W +
293 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
294 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
295 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
297 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*3.0/2.0;
299 adjListIndex = index * N_D3Q19_IDX;
302 src[I(index, D3Q19_C) ] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
305 w_1_indep = w_1*dir_indep_trm;
308 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
309 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
310 src[adjList[adjListIndex + D3Q19_N]] = pdf_N - evenPart - oddPart;
311 src[adjList[adjListIndex + D3Q19_S]] = pdf_S - evenPart + oddPart;
314 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
315 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
316 src[adjList[adjListIndex + D3Q19_E]] = pdf_E - evenPart - oddPart;
317 src[adjList[adjListIndex + D3Q19_W]] = pdf_W - evenPart + oddPart;
320 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
321 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
322 src[adjList[adjListIndex + D3Q19_T]] = pdf_T - evenPart - oddPart;
323 src[adjList[adjListIndex + D3Q19_B]] = pdf_B - evenPart + oddPart;
326 w_2_indep = w_2*dir_indep_trm;
329 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
330 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
331 src[adjList[adjListIndex + D3Q19_NW]] = pdf_NW - evenPart - oddPart;
332 src[adjList[adjListIndex + D3Q19_SE]] = pdf_SE - evenPart + oddPart;
335 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
336 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
337 src[adjList[adjListIndex + D3Q19_NE]] = pdf_NE - evenPart - oddPart;
338 src[adjList[adjListIndex + D3Q19_SW]] = pdf_SW - evenPart + oddPart;
341 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
342 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
343 src[adjList[adjListIndex + D3Q19_TW]] = pdf_TW - evenPart - oddPart;
344 src[adjList[adjListIndex + D3Q19_BE]] = pdf_BE - evenPart + oddPart;
347 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
348 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
349 src[adjList[adjListIndex + D3Q19_TE]] = pdf_TE - evenPart - oddPart;
350 src[adjList[adjListIndex + D3Q19_BW]] = pdf_BW - evenPart + oddPart;
353 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
354 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
355 src[adjList[adjListIndex + D3Q19_TS]] = pdf_TS - evenPart - oddPart;
356 src[adjList[adjListIndex + D3Q19_BN]] = pdf_BN - evenPart + oddPart;
359 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
360 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
361 src[adjList[adjListIndex + D3Q19_TN]] = pdf_TN - evenPart - oddPart;
362 src[adjList[adjListIndex + D3Q19_BS]] = pdf_BS - evenPart + oddPart;
365 } // loop over fluid nodes
367 X_LIKWID_STOP("list-aa-odd");
369 // save current iteration
370 kdl->Iteration = iter + 1;
373 kd->PdfsActive = src;
374 KernelAddBodyForce(kd, ld, cd);
378 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
379 kd->PdfsActive = src;
380 VtkWrite(ld, kd, cd, iter);
385 kd->PdfsActive = src;
386 KernelStatistics(kd, ld, cd, iter);
390 } // for (int iter = 0; ...
395 kd->PdfsActive = src;
396 VtkWrite(ld, kd, cd, maxIterations);
401 kd->PdfsActive = src;
402 KernelStatistics(kd, ld, cd, maxIterations);