* @brief Updates the particle distribution functions for the new simulation * frame * */
| 251 | * |
| 252 | */ |
| 253 | void collide_stream(Simulation& sim) { |
| 254 | auto& ux = sim.ux; |
| 255 | auto& uy = sim.uy; |
| 256 | auto& rho = sim.rho; |
| 257 | auto& sigma = sim.sigma; |
| 258 | auto& f = sim.f; |
| 259 | auto& feq = sim.feq; |
| 260 | auto& set_boundaries = sim.set_boundaries; |
| 261 | |
| 262 | auto& ex = sim.ex; |
| 263 | auto& ey = sim.ey; |
| 264 | auto& wt = sim.wt; |
| 265 | auto& ex_ = sim.ex_; |
| 266 | auto& ey_ = sim.ey_; |
| 267 | auto& ex_T = sim.ex_T; |
| 268 | auto& ey_T = sim.ey_T; |
| 269 | auto& wt_T = sim.wt_T; |
| 270 | |
| 271 | auto density = sim.density; |
| 272 | auto velocity = sim.velocity; |
| 273 | auto reynolds = sim.reynolds; |
| 274 | auto xcount = sim.grid_width; |
| 275 | auto ycount = sim.grid_height; |
| 276 | |
| 277 | const float viscosity = |
| 278 | velocity * std::sqrt(static_cast<float>(xcount * ycount)) / reynolds; |
| 279 | const float tau = 0.5f + 3.0f * viscosity; |
| 280 | const float csky = 0.16f; |
| 281 | |
| 282 | auto edotu = ex_ * ux + ey_ * uy; |
| 283 | auto udotu = ux * ux + uy * uy; |
| 284 | |
| 285 | // Compute the new distribution function |
| 286 | feq = |
| 287 | rho * wt * (edotu * edotu * 4.5f - udotu * 1.5f + edotu * 3.0f + 1.0f); |
| 288 | |
| 289 | auto taut = |
| 290 | af::sqrt(sigma * (csky * csky * 18.0f * 0.25f) + (tau * tau * 0.25f)) - |
| 291 | (tau * 0.5f); |
| 292 | |
| 293 | // Compute the shifted distribution functions |
| 294 | auto fplus = f - (f - feq) / (taut + tau); |
| 295 | |
| 296 | // Compute new particle distribution according to the corresponding D2N9 |
| 297 | // weights |
| 298 | for (int i = 0; i < 9; ++i) { |
| 299 | int xshift = static_cast<int>(ex_vals[i]); |
| 300 | int yshift = static_cast<int>(ey_vals[i]); |
| 301 | |
| 302 | fplus(af::span, af::span, i) = |
| 303 | af::shift(fplus(af::span, af::span, i), xshift, yshift); |
| 304 | } |
| 305 | |
| 306 | // Keep the boundary conditions at the borders the same |
| 307 | af::replace(fplus, af::tile(!set_boundaries, af::dim4(1, 1, 9)), f); |
| 308 | |
| 309 | // Update the particle distribution |
| 310 | f = fplus; |