MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / update

Function update

examples/pde/boltzmann_cfd.cpp:370–405  ·  view source on GitHub ↗

* @brief Updates the velocity field, density and strain at each point in the * grid * */

Source from the content-addressed store, hash-verified

368 *
369 */
370void update(Simulation& sim) {
371 auto& ux = sim.ux;
372 auto& uy = sim.uy;
373 auto& rho = sim.rho;
374 auto& sigma = sim.sigma;
375 auto& f = sim.f;
376 auto& feq = sim.feq;
377 auto& ex = sim.ex;
378 auto& ey = sim.ey;
379
380 auto e_tile = af::join(3, af::constant(1, 1, 1, 9), ex, ey);
381 auto result = af::sum(f * e_tile, 2);
382
383 rho = result(af::span, af::span, af::span, 0);
384 result /= rho;
385 ux = result(af::span, af::span, af::span, 1);
386 uy = result(af::span, af::span, af::span, 2);
387
388 // Above code equivalent to
389 // rho = af::sum(f, 2);
390 // ux = af::sum(f * ex, 2) / rho;
391 // uy = af::sum(f * ey, 2) / rho;
392
393 auto product = f - feq;
394 auto e_product = af::join(3, ex * ex, ex * ey * std::sqrt(2), ey * ey);
395
396 sigma = af::sqrt(af::sum(af::pow(af::sum(product * e_product, 2), 2), 3));
397
398 // Above code equivalent to
399
400 // auto xx = af::sum(product * ex * ex, 2);
401 // auto xy = af::sum(product * ex * ey, 2);
402 // auto yy = af::sum(product * ey * ey, 2);
403
404 // sigma = af::sqrt(xx * xx + xy * xy * 2 + yy * yy);
405}
406
407af::array generate_image(size_t width, size_t height, const Simulation& sim) {
408 const auto& ux = sim.ux;

Callers 1

Calls 6

constantFunction · 0.85
resultClass · 0.85
sqrtFunction · 0.85
powFunction · 0.85
joinFunction · 0.50
sumFunction · 0.50

Tested by

no test coverage detected