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 "BenchKernelD3Q19Common.h"
40 void FNAME(D3Q19Kernel)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
43 Assert(kernelData != NULL);
46 Assert(cd->Omega > F(0.0));
47 Assert(cd->Omega < F(2.0));
49 KernelData * kd = (KernelData *)kernelData;
56 int * gDims = kd->GlobalDims;
58 int oX = kd->Offsets[0];
59 int oY = kd->Offsets[1];
60 int oZ = kd->Offsets[2];
62 PdfT omega = cd->Omega;
63 PdfT omegaEven = omega;
64 // PdfT omegaOdd = 8.0*((F(2.0)-omegaEven)/(8.0-omegaEven)); //"standard" trt odd relaxation parameter
65 PdfT magicParam = F(1.0) / F(12.0);
66 // 1/ 4: best stability;
67 // 1/12: removes third-order advection error (best advection);
68 // 1/ 6: removes fourth-order diffusion error (best diffusion);
69 // 3/16: exact location of bounce back for poiseuille flow
70 PdfT omegaOdd = F(1.0) / (F(0.5) + magicParam / (F(1.0) / omega - F(0.5)));
72 PdfT evenPart = F(0.0);
73 PdfT oddPart = F(0.0);
74 PdfT dir_indep_trm = F(0.0);
76 PdfT w_0 = F(1.0) / F( 3.0);
77 PdfT w_1 = F(1.0) / F(18.0);
78 PdfT w_2 = F(1.0) / F(36.0);
80 PdfT w_1_x3 = w_1 * F(3.0); PdfT w_1_nine_half = w_1 * F(9.0)/F(2.0); PdfT w_1_indep = F(0.0);
81 PdfT w_2_x3 = w_2 * F(3.0); PdfT w_2_nine_half = w_2 * F(9.0)/F(2.0); PdfT w_2_indep = F(0.0);
86 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
87 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
91 PdfT * src = kd->Pdfs[0];
92 PdfT * dst = kd->Pdfs[1];
95 int maxIterations = cd->MaxIterations;
100 VtkWrite(ld, kd, cd, 0);
104 for (int iter = 0; iter < maxIterations; ++iter) {
106 X_LIKWID_START("os");
109 #pragma omp parallel for collapse(2) default(none) \
110 shared(gDims,src, dst, w_0, w_1, w_2, omegaEven, omegaOdd, \
111 w_1_x3, w_2_x3, w_1_nine_half, w_2_nine_half, cd, \
112 oX, oY, oZ, nX, nY, nZ) \
113 private(ux, uy, uz, ui, dens, dir_indep_trm, \
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, \
119 evenPart, oddPart, w_1_indep, w_2_indep)
121 for (int x = oX; x < nX + oX; ++x) {
122 for (int y = oY; y < nY + oY; ++y) {
123 #ifdef INTEL_OPT_DIRECTIVES
125 #pragma vector always
128 for (int z = oZ; z < nZ + oZ; ++z) {
129 #define I(x, y, z, dir) P_INDEX_5(gDims, (x), (y), (z), (dir))
131 #ifdef PROP_MODEL_PUSH
133 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
134 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x, y, z, idx)];
135 //if (isnan(JOIN(pdf_,name))) { printf("iter: %d %d %d %d %d %s nan\n", iter, x-oX, y-oY, z-oZ, idx, D3Q19_NAMES[idx]); exit(1);}
139 #elif PROP_MODEL_PULL
141 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
142 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x - _x, y - _y, z - _z, idx)];
143 //if (isnan(JOIN(pdf_,name))) { printf("iter: %d %d %d %d %d %s nan\n", iter, x-oX, y-oY, z-oZ, idx, D3Q19_NAMES[idx]); exit(1);}
148 #error No implementation for PROP_MODEL_NAME.
151 // #define LID_DRIVEN_CAVITY
153 #ifdef LID_DRIVEN_CAVITY
155 if (z == nZ - 4 + oZ && x > 3 + oX && x < (nX - 4 + oX) && y > 3 + oY && y < (nY - 4 + oY)) {
162 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
163 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
164 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
165 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
166 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
167 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
168 #ifdef LID_DRIVEN_CAVITY
174 pdf_N + pdf_E + pdf_S + pdf_W +
175 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
176 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
177 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
179 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz) * F(3.0) / F(2.0);
181 #ifdef PROP_MODEL_PUSH
184 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
187 w_1_indep = w_1*dir_indep_trm;
190 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
191 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
192 dst[I(x, y + 1, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
193 dst[I(x, y - 1, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
196 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
197 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
198 dst[I(x + 1, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
199 dst[I(x - 1, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
202 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
203 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
204 dst[I(x, y, z + 1, D3Q19_T)] = pdf_T - evenPart - oddPart;
205 dst[I(x, y, z - 1, D3Q19_B)] = pdf_B - evenPart + oddPart;
208 w_2_indep = w_2*dir_indep_trm;
211 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
212 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
213 dst[I(x - 1, y + 1, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
214 dst[I(x + 1, y - 1, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
217 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
218 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
219 dst[I(x + 1, y + 1, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
220 dst[I(x - 1, y - 1, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
223 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
224 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
225 dst[I(x - 1, y, z + 1, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
226 dst[I(x + 1, y, z - 1, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
229 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
230 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
231 dst[I(x + 1, y, z + 1, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
232 dst[I(x - 1, y, z - 1, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
235 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
236 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
237 dst[I(x, y - 1, z + 1, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
238 dst[I(x, y + 1, z - 1, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
241 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
242 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
243 dst[I(x, y + 1, z + 1, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
244 dst[I(x, y - 1, z - 1, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
246 #elif PROP_MODEL_PULL
249 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
252 w_1_indep = w_1*dir_indep_trm;
255 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
256 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
257 dst[I(x, y, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
258 dst[I(x, y, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
261 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
262 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
263 dst[I(x, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
264 dst[I(x, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
267 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
268 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
269 dst[I(x, y, z, D3Q19_T)] = pdf_T - evenPart - oddPart;
270 dst[I(x, y, z, D3Q19_B)] = pdf_B - evenPart + oddPart;
273 w_2_indep = w_2*dir_indep_trm;
276 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
277 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
278 dst[I(x, y, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
279 dst[I(x, y, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
282 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
283 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
284 dst[I(x, y, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
285 dst[I(x, y, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
288 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
289 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
290 dst[I(x, y, z, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
291 dst[I(x, y, z, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
294 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
295 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
296 dst[I(x, y, z, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
297 dst[I(x, y, z, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
300 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
301 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
302 dst[I(x, y, z, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
303 dst[I(x, y, z, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
306 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
307 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
308 dst[I(x, y, z, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
309 dst[I(x, y, z, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
312 #error No implementation for PROP_MODEL_NAME.
318 } // z, y, x (from inner to outer)
320 // Stop counters before bounce back. Else computing loop balance will be incorrect.
323 // Fixup bounce back PDFs.
325 #pragma omp parallel for default(none) \
328 for (int i = 0; i < kd->nBounceBackPdfs; ++i) {
329 dst[kd->BounceBackPdfsDst[i]] = dst[kd->BounceBackPdfsSrc[i]];
333 kd->PdfsActive = dst;
334 KernelAddBodyForce(kd, ld, cd);
339 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
340 kd->PdfsActive = dst;
341 VtkWrite(ld, kd, cd, iter);
347 kd->PdfsActive = dst;
348 KernelStatistics(kd, ld, cd, iter);
356 } // for (int iter = 0; ...
361 kd->PdfsActive = src;
362 VtkWrite(ld, kd, cd, maxIterations);
371 void FNAME(D3Q19BlkKernel)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
374 Assert(kernelData != NULL);
377 Assert(cd->Omega > F(0.0));
378 Assert(cd->Omega < F(2.0));
380 KernelData * kd = (KernelData *)kernelData;
383 int nX = ld->Dims[0];
384 int nY = ld->Dims[1];
385 int nZ = ld->Dims[2];
387 int * gDims = kd->GlobalDims;
389 int oX = kd->Offsets[0];
390 int oY = kd->Offsets[1];
391 int oZ = kd->Offsets[2];
393 KernelDataEx * kdex = (KernelDataEx *)kd;
396 blk[0] = kdex->Blk[0];
397 blk[1] = kdex->Blk[1];
398 blk[2] = kdex->Blk[2];
400 PdfT omega = cd->Omega;
401 PdfT omegaEven = omega;
402 // PdfT omegaOdd = 8.0*((F(2.0)-omegaEven)/(8.0-omegaEven)); //"standard" trt odd relaxation parameter
403 PdfT magicParam = F(1.0)/F(12.0);
404 // 1/ 4: best stability;
405 // 1/12: removes third-order advection error (best advection);
406 // 1/ 6: removes fourth-order diffusion error (best diffusion);
407 // 3/16: exact location of bounce back for poiseuille flow
408 PdfT omegaOdd = F(1.0) / (F(0.5) + magicParam / (F(1.0) / omega - F(0.5)));
410 PdfT evenPart = F(0.0);
411 PdfT oddPart = F(0.0);
412 PdfT dir_indep_trm = F(0.0);
414 PdfT w_0 = F(1.0) / F( 3.0);
415 PdfT w_1 = F(1.0) / F(18.0);
416 PdfT w_2 = F(1.0) / F(36.0);
418 PdfT w_1_x3 = w_1 * F(3.0); PdfT w_1_nine_half = w_1 * F(9.0)/F(2.0); PdfT w_1_indep = F(0.0);
419 PdfT w_2_x3 = w_2 * F(3.0); PdfT w_2_nine_half = w_2 * F(9.0)/F(2.0); PdfT w_2_indep = F(0.0);
424 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
425 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
429 PdfT * src = kd->Pdfs[0];
430 PdfT * dst = kd->Pdfs[1];
433 int maxIterations = cd->MaxIterations;
437 kd->PdfsActive = src;
438 VtkWrite(ld, kd, cd, 0);
445 nThreads = omp_get_max_threads();
448 for (int iter = 0; iter < maxIterations; ++iter) {
451 #pragma omp parallel default(none) \
452 shared(gDims,src, dst, w_0, w_1, w_2, omegaEven, omegaOdd, \
453 w_1_x3, w_2_x3, w_1_nine_half, w_2_nine_half, cd, \
454 oX, oY, oZ, nX, nY, nZ, blk, nThreads) \
455 private(ux, uy, uz, ui, dens, dir_indep_trm, \
457 pdf_N, pdf_E, pdf_S, pdf_W, \
458 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
459 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
460 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW, \
461 evenPart, oddPart, w_1_indep, w_2_indep)
464 X_LIKWID_START("blk-os");
466 int threadId = omp_get_thread_num();
468 int threadStartX = nX / nThreads * threadId;
469 int threadEndX = nX / nThreads * (threadId + 1);
471 if (nX % nThreads > 0) {
472 if (nX % nThreads > threadId) {
473 threadStartX += threadId;
474 threadEndX += threadId + 1;
477 threadStartX += nX % nThreads;
478 threadEndX += nX % nThreads;
482 for (int bX = oX + threadStartX; bX < threadEndX + oX; bX += blk[0]) {
483 for (int bY = oY; bY < nY + oY; bY += blk[1]) {
484 for (int bZ = oZ; bZ < nZ + oZ; bZ += blk[2]) {
486 // Must do everything here, else it would break collapse.
487 int eZ = MIN(bZ + blk[2], nZ + oZ);
488 int eY = MIN(bY + blk[1], nY + oY);
489 int eX = MIN(bX + blk[0], threadEndX + oX);
491 for (int x = bX; x < eX; ++x) {
492 for (int y = bY; y < eY; ++y) {
493 #ifdef INTEL_OPT_DIRECTIVES
495 #pragma vector always
498 for (int z = bZ; z < eZ; ++z) {
500 #define I(x, y, z, dir) P_INDEX_5(gDims, (x), (y), (z), (dir))
502 #ifdef PROP_MODEL_PUSH
504 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
505 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x, y, z, idx)];
509 #elif PROP_MODEL_PULL
511 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
512 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x - _x, y - _y, z - _z, idx)];
517 #error No implementation for PROP_MODEL_NAME.
520 // #define LID_DRIVEN_CAVITY
522 #ifdef LID_DRIVEN_CAVITY
524 if (z == nZ - 4 + oZ && x > 3 + oX && x < (nX - 4 + oX) && y > 3 + oY && y < (nY - 4 + oY)) {
531 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
532 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
533 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
534 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
535 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
536 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
537 #ifdef LID_DRIVEN_CAVITY
543 pdf_N + pdf_E + pdf_S + pdf_W +
544 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
545 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
546 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
548 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz) * F(3.0) / F(2.0);
550 #ifdef PROP_MODEL_PUSH
553 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
556 w_1_indep = w_1*dir_indep_trm;
559 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
560 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
561 dst[I(x, y + 1, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
562 dst[I(x, y - 1, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
565 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
566 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
567 dst[I(x + 1, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
568 dst[I(x - 1, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
571 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
572 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
573 dst[I(x, y, z + 1, D3Q19_T)] = pdf_T - evenPart - oddPart;
574 dst[I(x, y, z - 1, D3Q19_B)] = pdf_B - evenPart + oddPart;
577 w_2_indep = w_2*dir_indep_trm;
580 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
581 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
582 dst[I(x - 1, y + 1, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
583 dst[I(x + 1, y - 1, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
586 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
587 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
588 dst[I(x + 1, y + 1, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
589 dst[I(x - 1, y - 1, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
592 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
593 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
594 dst[I(x - 1, y, z + 1, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
595 dst[I(x + 1, y, z - 1, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
598 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
599 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
600 dst[I(x + 1, y, z + 1, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
601 dst[I(x - 1, y, z - 1, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
604 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
605 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
606 dst[I(x, y - 1, z + 1, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
607 dst[I(x, y + 1, z - 1, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
610 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
611 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
612 dst[I(x, y + 1, z + 1, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
613 dst[I(x, y - 1, z - 1, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
615 #elif PROP_MODEL_PULL
618 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
621 w_1_indep = w_1*dir_indep_trm;
624 evenPart = omegaEven*( F(0.5)*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
625 oddPart = omegaOdd*(F(0.5)*(pdf_N - pdf_S) - ui*w_1_x3 );
626 dst[I(x, y, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
627 dst[I(x, y, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
630 evenPart = omegaEven*( F(0.5)*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
631 oddPart = omegaOdd*(F(0.5)*(pdf_E - pdf_W) - ui*w_1_x3 );
632 dst[I(x, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
633 dst[I(x, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
636 evenPart = omegaEven*( F(0.5)*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
637 oddPart = omegaOdd*(F(0.5)*(pdf_T - pdf_B) - ui*w_1_x3 );
638 dst[I(x, y, z, D3Q19_T)] = pdf_T - evenPart - oddPart;
639 dst[I(x, y, z, D3Q19_B)] = pdf_B - evenPart + oddPart;
642 w_2_indep = w_2*dir_indep_trm;
645 evenPart = omegaEven*( F(0.5)*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
646 oddPart = omegaOdd*(F(0.5)*(pdf_NW - pdf_SE) - ui*w_2_x3 );
647 dst[I(x, y, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
648 dst[I(x, y, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
651 evenPart = omegaEven*( F(0.5)*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
652 oddPart = omegaOdd*(F(0.5)*(pdf_NE - pdf_SW) - ui*w_2_x3 );
653 dst[I(x, y, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
654 dst[I(x, y, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
657 evenPart = omegaEven*( F(0.5)*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
658 oddPart = omegaOdd*(F(0.5)*(pdf_TW - pdf_BE) - ui*w_2_x3 );
659 dst[I(x, y, z, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
660 dst[I(x, y, z, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
663 evenPart = omegaEven*( F(0.5)*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
664 oddPart = omegaOdd*(F(0.5)*(pdf_TE - pdf_BW) - ui*w_2_x3 );
665 dst[I(x, y, z, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
666 dst[I(x, y, z, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
669 evenPart = omegaEven*( F(0.5)*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
670 oddPart = omegaOdd*(F(0.5)*(pdf_TS - pdf_BN) - ui*w_2_x3 );
671 dst[I(x, y, z, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
672 dst[I(x, y, z, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
675 evenPart = omegaEven*( F(0.5)*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
676 oddPart = omegaOdd*(F(0.5)*(pdf_TN - pdf_BS) - ui*w_2_x3 );
677 dst[I(x, y, z, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
678 dst[I(x, y, z, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
681 #error No implementation for PROP_MODEL_NAME.
687 } // z, y, x (from inner to outer)
690 } // z, y, x (from inner to outer)
692 X_LIKWID_STOP("blk-os");
695 // Stop counters before bounce back. Else computing loop balance will be incorrect.
697 // Fixup bounce back PDFs.
699 #pragma omp parallel for default(none) \
702 for (int i = 0; i < kd->nBounceBackPdfs; ++i) {
703 dst[kd->BounceBackPdfsDst[i]] = dst[kd->BounceBackPdfsSrc[i]];
707 kd->PdfsActive = dst;
708 KernelAddBodyForce(kd, ld, cd);
713 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
714 kd->PdfsActive = dst;
715 VtkWrite(ld, kd, cd, iter);
721 kd->PdfsActive = dst;
722 KernelStatistics(kd, ld, cd, iter);
730 } // for (int iter = 0; ...
735 kd->PdfsActive = src;
736 VtkWrite(ld, kd, cd, maxIterations);