diff --git a/src/cache.h b/src/cache.h index 295a9d9a64bc865fb9998a1d4095e235ddf92e60..0986ced872faac734c9b9429182442da3a7fa1cf 100644 --- a/src/cache.h +++ b/src/cache.h @@ -270,6 +270,41 @@ __attribute__((always_inline)) INLINE void cache_read_two_cells( } } +__attribute__((always_inline)) INLINE void cache_read_cell_sorted( + const struct cell *const ci, struct cache *const ci_cache, const struct entry *restrict sort_i, const double *const shift) { + + int idx; + /* Shift the particles positions to a local frame (ci frame) so single precision can be + * used instead of double precision. Also shift the cell ci, particles positions due to BCs but leave cell cj. */ +#ifdef WITH_VECTORIZATION +#pragma simd +#endif + for (int i = 0; i < ci->count; i++) { + idx = sort_i[i].i; + + ci_cache->x[i] = ci->parts[idx].x[0] - ci->loc[0] - shift[0]; + ci_cache->y[i] = ci->parts[idx].x[1] - ci->loc[1] - shift[1]; + ci_cache->z[i] = ci->parts[idx].x[2] - ci->loc[2] - shift[2]; + ci_cache->h[i] = ci->parts[idx].h; + + ci_cache->m[i] = ci->parts[idx].mass; + ci_cache->vx[i] = ci->parts[idx].v[0]; + ci_cache->vy[i] = ci->parts[idx].v[1]; + ci_cache->vz[i] = ci->parts[idx].v[2]; + +#ifdef DOPAIR1_AUTO_VEC + ci_cache->rho[i] = 0.0f; + ci_cache->rho_dh[i] = 0.0f; + ci_cache->wcount[i] = 0.0f; + ci_cache->wcount_dh[i] = 0.0f; + ci_cache->div_v[i] = 0.0f; + ci_cache->curl_vx[i] = 0.0f; + ci_cache->curl_vy[i] = 0.0f; + ci_cache->curl_vz[i] = 0.0f; +#endif + } +} + /** * @brief Populate cache by reading in the particles from two cells in sorted order. *