Loading [MathJax]/jax/output/HTML-CSS/config.js
Tatooine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
cell_partition.h
Go to the documentation of this file.
1#ifndef TATOOINE_CELL_PARTITION_H
2#define TATOOINE_CELL_PARTITION_H
3
4#include "grid.h"
5#include <omp.h>
6
7//==============================================================================
8namespace tatooine {
9//==============================================================================
11template <typename F, typename GridReal>
12auto cell_partition(F&& f, const grid<GridReal, 3>& g) {
13 using vec3 = vec<Real, 3>;
14#ifdef NDEBUG
15 omp_lock_t lock;
16 omp_init_lock(&lock);
17#pragma omp parallel for collapse(3)
18#endif
19 for (size_t iz = 0; iz < g.dimension(2).size() - 1; ++iz) {
20 for (size_t iy = 0; iy < g.dimension(1).size() - 1; ++iy) {
21 for (size_t ix = 0; ix < g.dimension(0).size() - 1; ++ix) {
22 const auto& x0 = g.dimension(0)[ix];
23 const auto& x1 = g.dimension(0)[ix + 1];
24 const auto& y0 = g.dimension(1)[iy];
25 const auto& y1 = g.dimension(1)[iy + 1];
26 const auto& z0 = g.dimension(2)[iz];
27 const auto& z1 = g.dimension(2)[iz + 1];
28 f(ix, iy, iz,
29 std::array{
30 vec{x0, y0, z0},
31 vec{x1, y0, z0},
32 vec{x0, y1, z0},
33 vec{x1, y1, z0},
34 vec{x0, y0, z1},
35 vec{x1, y0, z1},
36 vec{x0, y1, z1},
37 vec{x1, y1, z1},
38 }, lock);
39 }
40 }
41 }
42}
43//==============================================================================
44} // namespace tatooine
45//==============================================================================
46
47#endif
Definition: grid_edge.h:16
Definition: algorithm.h:6
auto size(vec< ValueType, N > const &v)
Definition: vec.h:148
auto cell_partition(F &&f, const grid< GridReal, 3 > &g)
iterates over all cells of the grid in parallel
Definition: cell_partition.h:12
Definition: vec.h:12