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 > 0.0);
47 Assert(cd->Omega < 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*((2.0-omegaEven)/(8.0-omegaEven)); //"standard" trt odd relaxation parameter
65 PdfT magicParam = 1.0/12.0; // 1/4: best stability; 1/12: removes third-order advection error (best advection); 1/6: removes fourth-order diffusion error (best diffusion); 3/16: exact location of bounce back for poiseuille flow
66 PdfT omegaOdd = 1.0/( 0.5 + magicParam/(1.0/omega - 0.5) );
70 PdfT dir_indep_trm = 0.0;
73 PdfT w_1 = 1.0 / 18.0;
74 PdfT w_2 = 1.0 / 36.0;
76 PdfT w_1_x3 = w_1 * 3.0; PdfT w_1_nine_half = w_1 * 9.0/2.0; PdfT w_1_indep = 0.0;
77 PdfT w_2_x3 = w_2 * 3.0; PdfT w_2_nine_half = w_2 * 9.0/2.0; PdfT w_2_indep = 0.0;
82 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
83 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
87 PdfT * src = kd->Pdfs[0];
88 PdfT * dst = kd->Pdfs[1];
91 int maxIterations = cd->MaxIterations;
96 VtkWrite(ld, kd, cd, 0);
100 for (int iter = 0; iter < maxIterations; ++iter) {
102 X_LIKWID_START("os");
105 #pragma omp parallel for collapse(3) default(none) \
106 shared(gDims,src, dst, w_0, w_1, w_2, omegaEven, omegaOdd, \
107 w_1_x3, w_2_x3, w_1_nine_half, w_2_nine_half, cd, \
108 oX, oY, oZ, nX, nY, nZ) \
109 private(ux, uy, uz, ui, dens, dir_indep_trm, \
111 pdf_N, pdf_E, pdf_S, pdf_W, \
112 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
113 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
114 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW, \
115 evenPart, oddPart, w_1_indep, w_2_indep)
118 for (int x = oX; x < nX + oX; ++x) {
119 for (int y = oY; y < nY + oY; ++y) {
120 for (int z = oZ; z < nZ + oZ; ++z) {
121 #define I(x, y, z, dir) P_INDEX_5(gDims, (x), (y), (z), (dir))
123 #ifdef PROP_MODEL_PUSH
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(x, y, z, idx)];
127 //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);}
131 #elif PROP_MODEL_PULL
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 - _x, y - _y, z - _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);}
140 #error No implementation for PROP_MODEL_NAME.
143 // #define LID_DRIVEN_CAVITY
145 #ifdef LID_DRIVEN_CAVITY
147 if (z == nZ - 4 + oZ && x > 3 + oX && x < (nX - 4 + oX) && y > 3 + oY && y < (nY - 4 + oY)) {
154 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
155 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
156 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
157 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
158 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
159 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
160 #ifdef LID_DRIVEN_CAVITY
166 pdf_N + pdf_E + pdf_S + pdf_W +
167 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
168 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
169 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
171 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*3.0/2.0;
173 #ifdef PROP_MODEL_PUSH
176 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
179 w_1_indep = w_1*dir_indep_trm;
182 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
183 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
184 dst[I(x, y + 1, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
185 dst[I(x, y - 1, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
188 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
189 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
190 dst[I(x + 1, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
191 dst[I(x - 1, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
194 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
195 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
196 dst[I(x, y, z + 1, D3Q19_T)] = pdf_T - evenPart - oddPart;
197 dst[I(x, y, z - 1, D3Q19_B)] = pdf_B - evenPart + oddPart;
200 w_2_indep = w_2*dir_indep_trm;
203 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
204 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
205 dst[I(x - 1, y + 1, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
206 dst[I(x + 1, y - 1, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
209 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
210 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
211 dst[I(x + 1, y + 1, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
212 dst[I(x - 1, y - 1, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
215 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
216 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
217 dst[I(x - 1, y, z + 1, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
218 dst[I(x + 1, y, z - 1, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
221 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
222 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
223 dst[I(x + 1, y, z + 1, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
224 dst[I(x - 1, y, z - 1, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
227 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
228 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
229 dst[I(x, y - 1, z + 1, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
230 dst[I(x, y + 1, z - 1, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
233 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
234 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
235 dst[I(x, y + 1, z + 1, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
236 dst[I(x, y - 1, z - 1, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
238 #elif PROP_MODEL_PULL
241 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
244 w_1_indep = w_1*dir_indep_trm;
247 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
248 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
249 dst[I(x, y, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
250 dst[I(x, y, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
253 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
254 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
255 dst[I(x, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
256 dst[I(x, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
259 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
260 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
261 dst[I(x, y, z, D3Q19_T)] = pdf_T - evenPart - oddPart;
262 dst[I(x, y, z, D3Q19_B)] = pdf_B - evenPart + oddPart;
265 w_2_indep = w_2*dir_indep_trm;
268 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
269 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
270 dst[I(x, y, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
271 dst[I(x, y, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
274 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
275 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
276 dst[I(x, y, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
277 dst[I(x, y, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
280 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
281 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
282 dst[I(x, y, z, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
283 dst[I(x, y, z, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
286 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
287 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
288 dst[I(x, y, z, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
289 dst[I(x, y, z, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
292 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
293 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
294 dst[I(x, y, z, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
295 dst[I(x, y, z, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
298 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
299 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
300 dst[I(x, y, z, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
301 dst[I(x, y, z, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
304 #error No implementation for PROP_MODEL_NAME.
310 } // z, y, x (from inner to outer)
312 // Stop counters before bounce back. Else computing loop balance will be incorrect.
315 // Fixup bounce back PDFs.
317 #pragma omp parallel for default(none) \
320 for (int i = 0; i < kd->nBounceBackPdfs; ++i) {
321 dst[kd->BounceBackPdfsDst[i]] = dst[kd->BounceBackPdfsSrc[i]];
325 kd->PdfsActive = dst;
326 KernelAddBodyForce(kd, ld, cd);
331 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
332 kd->PdfsActive = dst;
333 VtkWrite(ld, kd, cd, iter);
339 kd->PdfsActive = dst;
340 KernelStatistics(kd, ld, cd, iter);
348 } // for (int iter = 0; ...
353 kd->PdfsActive = src;
354 VtkWrite(ld, kd, cd, maxIterations);
363 void FNAME(D3Q19BlkKernel)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
366 Assert(kernelData != NULL);
369 Assert(cd->Omega > 0.0);
370 Assert(cd->Omega < 2.0);
372 KernelData * kd = (KernelData *)kernelData;
375 int nX = ld->Dims[0];
376 int nY = ld->Dims[1];
377 int nZ = ld->Dims[2];
379 int * gDims = kd->GlobalDims;
381 int oX = kd->Offsets[0];
382 int oY = kd->Offsets[1];
383 int oZ = kd->Offsets[2];
385 KernelDataEx * kdex = (KernelDataEx *)kd;
388 blk[0] = kdex->Blk[0];
389 blk[1] = kdex->Blk[1];
390 blk[2] = kdex->Blk[2];
392 PdfT omega = cd->Omega;
393 PdfT omegaEven = omega;
394 // PdfT omegaOdd = 8.0*((2.0-omegaEven)/(8.0-omegaEven)); //"standard" trt odd relaxation parameter
395 PdfT magicParam = 1.0/12.0; // 1/4: best stability; 1/12: removes third-order advection error (best advection); 1/6: removes fourth-order diffusion error (best diffusion); 3/16: exact location of bounce back for poiseuille flow
396 PdfT omegaOdd = 1.0/( 0.5 + magicParam/(1.0/omega - 0.5) );
400 PdfT dir_indep_trm = 0.0;
402 PdfT w_0 = 1.0 / 3.0;
403 PdfT w_1 = 1.0 / 18.0;
404 PdfT w_2 = 1.0 / 36.0;
406 PdfT w_1_x3 = w_1 * 3.0; PdfT w_1_nine_half = w_1 * 9.0/2.0; PdfT w_1_indep = 0.0;
407 PdfT w_2_x3 = w_2 * 3.0; PdfT w_2_nine_half = w_2 * 9.0/2.0; PdfT w_2_indep = 0.0;
412 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
413 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
417 PdfT * src = kd->Pdfs[0];
418 PdfT * dst = kd->Pdfs[1];
421 int maxIterations = cd->MaxIterations;
425 kd->PdfsActive = src;
426 VtkWrite(ld, kd, cd, 0);
433 nThreads = omp_get_max_threads();
436 for (int iter = 0; iter < maxIterations; ++iter) {
439 #pragma omp parallel default(none) \
440 shared(gDims,src, dst, w_0, w_1, w_2, omegaEven, omegaOdd, \
441 w_1_x3, w_2_x3, w_1_nine_half, w_2_nine_half, cd, \
442 oX, oY, oZ, nX, nY, nZ, blk, nThreads) \
443 private(ux, uy, uz, ui, dens, dir_indep_trm, \
445 pdf_N, pdf_E, pdf_S, pdf_W, \
446 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
447 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
448 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW, \
449 evenPart, oddPart, w_1_indep, w_2_indep)
452 X_LIKWID_START("blk-os");
454 int threadId = omp_get_thread_num();
456 int threadStartX = nX / nThreads * threadId;
457 int threadEndX = nX / nThreads * (threadId + 1);
459 if (nX % nThreads > 0) {
460 if (nX % nThreads > threadId) {
461 threadStartX += threadId;
462 threadEndX += threadId + 1;
465 threadStartX += nX % nThreads;
466 threadEndX += nX % nThreads;
470 for (int bX = oX + threadStartX; bX < threadEndX + oX; bX += blk[0]) {
471 for (int bY = oY; bY < nY + oY; bY += blk[1]) {
472 for (int bZ = oZ; bZ < nZ + oZ; bZ += blk[2]) {
474 // Must do everything here, else it would break collapse.
475 int eZ = MIN(bZ + blk[2], nZ + oZ);
476 int eY = MIN(bY + blk[1], nY + oY);
477 int eX = MIN(bX + blk[0], threadEndX + oX);
479 for (int x = bX; x < eX; ++x) {
480 for (int y = bY; y < eY; ++y) {
481 for (int z = bZ; z < eZ; ++z) {
483 #define I(x, y, z, dir) P_INDEX_5(gDims, (x), (y), (z), (dir))
485 #ifdef PROP_MODEL_PUSH
487 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
488 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x, y, z, idx)];
492 #elif PROP_MODEL_PULL
494 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
495 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(x - _x, y - _y, z - _z, idx)];
500 #error No implementation for PROP_MODEL_NAME.
503 // #define LID_DRIVEN_CAVITY
505 #ifdef LID_DRIVEN_CAVITY
507 if (z == nZ - 4 + oZ && x > 3 + oX && x < (nX - 4 + oX) && y > 3 + oY && y < (nY - 4 + oY)) {
514 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
515 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
516 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
517 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
518 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
519 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
520 #ifdef LID_DRIVEN_CAVITY
526 pdf_N + pdf_E + pdf_S + pdf_W +
527 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
528 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
529 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
531 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*3.0/2.0;
533 #ifdef PROP_MODEL_PUSH
536 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
539 w_1_indep = w_1*dir_indep_trm;
542 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
543 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
544 dst[I(x, y + 1, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
545 dst[I(x, y - 1, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
548 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
549 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
550 dst[I(x + 1, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
551 dst[I(x - 1, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
554 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
555 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
556 dst[I(x, y, z + 1, D3Q19_T)] = pdf_T - evenPart - oddPart;
557 dst[I(x, y, z - 1, D3Q19_B)] = pdf_B - evenPart + oddPart;
560 w_2_indep = w_2*dir_indep_trm;
563 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
564 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
565 dst[I(x - 1, y + 1, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
566 dst[I(x + 1, y - 1, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
569 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
570 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
571 dst[I(x + 1, y + 1, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
572 dst[I(x - 1, y - 1, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
575 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
576 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
577 dst[I(x - 1, y, z + 1, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
578 dst[I(x + 1, y, z - 1, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
581 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
582 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
583 dst[I(x + 1, y, z + 1, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
584 dst[I(x - 1, y, z - 1, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
587 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
588 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
589 dst[I(x, y - 1, z + 1, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
590 dst[I(x, y + 1, z - 1, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
593 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
594 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
595 dst[I(x, y + 1, z + 1, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
596 dst[I(x, y - 1, z - 1, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
598 #elif PROP_MODEL_PULL
601 dst[I(x, y, z, D3Q19_C)] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
604 w_1_indep = w_1*dir_indep_trm;
607 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
608 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
609 dst[I(x, y, z, D3Q19_N)] = pdf_N - evenPart - oddPart;
610 dst[I(x, y, z, D3Q19_S)] = pdf_S - evenPart + oddPart;
613 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
614 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
615 dst[I(x, y, z, D3Q19_E)] = pdf_E - evenPart - oddPart;
616 dst[I(x, y, z, D3Q19_W)] = pdf_W - evenPart + oddPart;
619 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
620 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
621 dst[I(x, y, z, D3Q19_T)] = pdf_T - evenPart - oddPart;
622 dst[I(x, y, z, D3Q19_B)] = pdf_B - evenPart + oddPart;
625 w_2_indep = w_2*dir_indep_trm;
628 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
629 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
630 dst[I(x, y, z, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
631 dst[I(x, y, z, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
634 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
635 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
636 dst[I(x, y, z, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
637 dst[I(x, y, z, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
640 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
641 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
642 dst[I(x, y, z, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
643 dst[I(x, y, z, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
646 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
647 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
648 dst[I(x, y, z, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
649 dst[I(x, y, z, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
652 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
653 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
654 dst[I(x, y, z, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
655 dst[I(x, y, z, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
658 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
659 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
660 dst[I(x, y, z, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
661 dst[I(x, y, z, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
664 #error No implementation for PROP_MODEL_NAME.
670 } // z, y, x (from inner to outer)
673 } // z, y, x (from inner to outer)
675 X_LIKWID_STOP("blk-os");
678 // Stop counters before bounce back. Else computing loop balance will be incorrect.
680 // Fixup bounce back PDFs.
682 #pragma omp parallel for default(none) \
685 for (int i = 0; i < kd->nBounceBackPdfs; ++i) {
686 dst[kd->BounceBackPdfsDst[i]] = dst[kd->BounceBackPdfsSrc[i]];
690 kd->PdfsActive = dst;
691 KernelAddBodyForce(kd, ld, cd);
696 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
697 kd->PdfsActive = dst;
698 VtkWrite(ld, kd, cd, iter);
704 kd->PdfsActive = dst;
705 KernelStatistics(kd, ld, cd, iter);
713 } // for (int iter = 0; ...
718 kd->PdfsActive = src;
719 VtkWrite(ld, kd, cd, maxIterations);