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 "BenchKernelD3Q19ListCommon.h"
36 void FNAME(D3Q19ListKernel)(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 // PdfT omegaOdd = 8.0*((2.0-omegaEven)/(8.0-omegaEven)); //"standard" trt odd relaxation parameter
51 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
52 PdfT omegaOdd = 1.0/( 0.5 + magicParam/(1.0/omega - 0.5) );
56 PdfT dir_indep_trm = 0.0;
59 PdfT w_1 = 1.0 / 18.0;
60 PdfT w_2 = 1.0 / 36.0;
62 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;
63 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;
68 // Declare pdf_N, pdf_E, pdf_S, pdf_W, ...
69 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
73 PdfT * src = kd->Pdfs[0];
74 PdfT * dst = kd->Pdfs[1];
77 int maxIterations = cd->MaxIterations;
78 int nFluid = kdl->nFluid;
79 int nCells = kdl->nCells;
81 uint32_t adjListIndex;
82 uint32_t * adjList = kdl->AdjList;
87 VtkWrite(ld, kd, cd, 0);
93 KernelStatistics(kd, ld, cd, 0);
96 // TODO: outer openmp parallel
97 for(int iter = 0; iter < maxIterations; ++iter) {
102 #pragma omp parallel for default(none) \
103 shared(nFluid, nCells, kd, kdl, adjList, src, dst, w_0, w_1, w_2, omegaEven, omegaOdd, \
104 w_1_x3, w_2_x3, w_1_nine_half, w_2_nine_half, cd) \
105 private(ux, uy, uz, ui, dens, dir_indep_trm, adjListIndex, \
107 pdf_N, pdf_E, pdf_S, pdf_W, \
108 pdf_NE, pdf_SE, pdf_SW, pdf_NW, \
109 pdf_T, pdf_TN, pdf_TE, pdf_TS, pdf_TW, \
110 pdf_B, pdf_BN, pdf_BE, pdf_BS, pdf_BW, \
111 evenPart, oddPart, w_1_indep, w_2_indep)
113 for (int index = 0; index < nFluid; ++index) {
115 #define I(index, dir) P_INDEX_3((nCells), (index), (dir))
117 #ifdef PROP_MODEL_PUSH
119 // Load PDFs of local cell: pdf_N = src[I(x, y, z, D3Q19_N)]; ...
120 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[I(index, idx)];
124 #elif PROP_MODEL_PULL
126 adjListIndex = index * N_D3Q19_IDX;
128 pdf_C = src[P_INDEX_3(nCells, index, D3Q19_C)];
130 // Load PDFs of local cell: pdf_N = src[adjList[adjListIndex + D3Q19_N]]; ...
131 #define X(name, idx, idxinv, _x, _y, _z) JOIN(pdf_,name) = src[adjList[adjListIndex + idx]];
136 #error No implementation for PROP_MODEL_NAME.
139 // #define LID_DRIVEN_CAVITY
141 #ifdef LID_DRIVEN_CAVITY
142 int nX = kd->Dims[0];
143 int nY = kd->Dims[1];
144 int nZ = kd->Dims[2];
146 int x = kdl->Coords[C_INDEX_X(index)];
147 int y = kdl->Coords[C_INDEX_Y(index)];
148 int z = kdl->Coords[C_INDEX_Z(index)];
150 if (z == nZ - 4 && x > 3 && x < (nX - 4) && y > 3 && y < (nY - 4)) {
156 ux = pdf_E + pdf_NE + pdf_SE + pdf_TE + pdf_BE -
157 pdf_W - pdf_NW - pdf_SW - pdf_TW - pdf_BW;
158 uy = pdf_N + pdf_NE + pdf_NW + pdf_TN + pdf_BN -
159 pdf_S - pdf_SE - pdf_SW - pdf_TS - pdf_BS;
160 uz = pdf_T + pdf_TE + pdf_TW + pdf_TN + pdf_TS -
161 pdf_B - pdf_BE - pdf_BW - pdf_BN - pdf_BS;
162 #ifdef LID_DRIVEN_CAVITY
167 pdf_N + pdf_E + pdf_S + pdf_W +
168 pdf_NE + pdf_SE + pdf_SW + pdf_NW +
169 pdf_T + pdf_TN + pdf_TE + pdf_TS + pdf_TW +
170 pdf_B + pdf_BN + pdf_BE + pdf_BS + pdf_BW;
172 dir_indep_trm = dens - (ux * ux + uy * uy + uz * uz)*3.0/2.0;
174 #ifdef PROP_MODEL_PUSH
176 adjListIndex = index * N_D3Q19_IDX;
179 dst[I(index, D3Q19_C) ] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
182 w_1_indep = w_1*dir_indep_trm;
185 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
186 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
187 dst[adjList[adjListIndex + D3Q19_N]] = pdf_N - evenPart - oddPart;
188 dst[adjList[adjListIndex + D3Q19_S]] = pdf_S - evenPart + oddPart;
191 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
192 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
193 dst[adjList[adjListIndex + D3Q19_E]] = pdf_E - evenPart - oddPart;
194 dst[adjList[adjListIndex + D3Q19_W]] = pdf_W - evenPart + oddPart;
197 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
198 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
199 dst[adjList[adjListIndex + D3Q19_T]] = pdf_T - evenPart - oddPart;
200 dst[adjList[adjListIndex + D3Q19_B]] = pdf_B - evenPart + oddPart;
203 w_2_indep = w_2*dir_indep_trm;
206 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
207 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
208 dst[adjList[adjListIndex + D3Q19_NW]] = pdf_NW - evenPart - oddPart;
209 dst[adjList[adjListIndex + D3Q19_SE]] = pdf_SE - evenPart + oddPart;
212 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
213 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
214 dst[adjList[adjListIndex + D3Q19_NE]] = pdf_NE - evenPart - oddPart;
215 dst[adjList[adjListIndex + D3Q19_SW]] = pdf_SW - evenPart + oddPart;
218 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
219 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
220 dst[adjList[adjListIndex + D3Q19_TW]] = pdf_TW - evenPart - oddPart;
221 dst[adjList[adjListIndex + D3Q19_BE]] = pdf_BE - evenPart + oddPart;
224 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
225 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
226 dst[adjList[adjListIndex + D3Q19_TE]] = pdf_TE - evenPart - oddPart;
227 dst[adjList[adjListIndex + D3Q19_BW]] = pdf_BW - evenPart + oddPart;
230 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
231 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
232 dst[adjList[adjListIndex + D3Q19_TS]] = pdf_TS - evenPart - oddPart;
233 dst[adjList[adjListIndex + D3Q19_BN]] = pdf_BN - evenPart + oddPart;
236 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
237 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
238 dst[adjList[adjListIndex + D3Q19_TN]] = pdf_TN - evenPart - oddPart;
239 dst[adjList[adjListIndex + D3Q19_BS]] = pdf_BS - evenPart + oddPart;
241 #elif PROP_MODEL_PULL
244 dst[I(index, D3Q19_C )] = pdf_C - omegaEven*(pdf_C - w_0*dir_indep_trm);
247 w_1_indep = w_1*dir_indep_trm;
250 evenPart = omegaEven*( 0.5*(pdf_N + pdf_S) - ui*ui*w_1_nine_half - w_1_indep );
251 oddPart = omegaOdd*(0.5*(pdf_N - pdf_S) - ui*w_1_x3 );
252 dst[I(index, D3Q19_N )] = pdf_N - evenPart - oddPart;
253 dst[I(index, D3Q19_S )] = pdf_S - evenPart + oddPart;
256 evenPart = omegaEven*( 0.5*(pdf_E + pdf_W) - ui*ui*w_1_nine_half - w_1_indep );
257 oddPart = omegaOdd*(0.5*(pdf_E - pdf_W) - ui*w_1_x3 );
258 dst[I(index, D3Q19_E )] = pdf_E - evenPart - oddPart;
259 dst[I(index, D3Q19_W )] = pdf_W - evenPart + oddPart;
262 evenPart = omegaEven*( 0.5*(pdf_T + pdf_B) - ui*ui*w_1_nine_half - w_1_indep );
263 oddPart = omegaOdd*(0.5*(pdf_T - pdf_B) - ui*w_1_x3 );
264 dst[I(index, D3Q19_T )] = pdf_T - evenPart - oddPart;
265 dst[I(index, D3Q19_B )] = pdf_B - evenPart + oddPart;
268 w_2_indep = w_2*dir_indep_trm;
271 evenPart = omegaEven*( 0.5*(pdf_NW + pdf_SE) - ui*ui*w_2_nine_half - w_2_indep );
272 oddPart = omegaOdd*(0.5*(pdf_NW - pdf_SE) - ui*w_2_x3 );
273 dst[I(index, D3Q19_NW)] = pdf_NW - evenPart - oddPart;
274 dst[I(index, D3Q19_SE)] = pdf_SE - evenPart + oddPart;
277 evenPart = omegaEven*( 0.5*(pdf_NE + pdf_SW) - ui*ui*w_2_nine_half - w_2_indep );
278 oddPart = omegaOdd*(0.5*(pdf_NE - pdf_SW) - ui*w_2_x3 );
279 dst[I(index, D3Q19_NE)] = pdf_NE - evenPart - oddPart;
280 dst[I(index, D3Q19_SW)] = pdf_SW - evenPart + oddPart;
283 evenPart = omegaEven*( 0.5*(pdf_TW + pdf_BE) - ui*ui*w_2_nine_half - w_2_indep );
284 oddPart = omegaOdd*(0.5*(pdf_TW - pdf_BE) - ui*w_2_x3 );
285 dst[I(index, D3Q19_TW)] = pdf_TW - evenPart - oddPart;
286 dst[I(index, D3Q19_BE)] = pdf_BE - evenPart + oddPart;
289 evenPart = omegaEven*( 0.5*(pdf_TE + pdf_BW) - ui*ui*w_2_nine_half - w_2_indep );
290 oddPart = omegaOdd*(0.5*(pdf_TE - pdf_BW) - ui*w_2_x3 );
291 dst[I(index, D3Q19_TE)] = pdf_TE - evenPart - oddPart;
292 dst[I(index, D3Q19_BW)] = pdf_BW - evenPart + oddPart;
295 evenPart = omegaEven*( 0.5*(pdf_TS + pdf_BN) - ui*ui*w_2_nine_half - w_2_indep );
296 oddPart = omegaOdd*(0.5*(pdf_TS - pdf_BN) - ui*w_2_x3 );
297 dst[I(index, D3Q19_TS)] = pdf_TS - evenPart - oddPart;
298 dst[I(index, D3Q19_BN)] = pdf_BN - evenPart + oddPart;
301 evenPart = omegaEven*( 0.5*(pdf_TN + pdf_BS) - ui*ui*w_2_nine_half - w_2_indep );
302 oddPart = omegaOdd*(0.5*(pdf_TN - pdf_BS) - ui*w_2_x3 );
303 dst[I(index, D3Q19_TN)] = pdf_TN - evenPart - oddPart;
304 dst[I(index, D3Q19_BS)] = pdf_BS - evenPart + oddPart;
308 } // loop over fluid nodes
311 kd->PdfsActive = dst;
312 KernelAddBodyForce(kd, ld, cd);
316 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
317 kd->PdfsActive = dst;
318 VtkWrite(ld, kd, cd, iter);
323 kd->PdfsActive = dst;
324 KernelStatistics(kd, ld, cd, iter);
332 } // for (int iter = 0; ...
336 kd->PdfsActive = src;
337 VtkWrite(ld, kd, cd, maxIterations);
342 kd->PdfsActive = src;
343 KernelStatistics(kd, ld, cd, maxIterations);