7 #ifndef WONTON_STRUCTURED_PARTITIONER_H 8 #define WONTON_STRUCTURED_PARTITIONER_H_ 24 std::vector<std::array<std::array<int64_t,D>,2>>
28 std::vector<int> nbins = equifactor(N, d, seed);
29 for (
int i = d; i < D; i++)
33 std::array<std::vector<int64_t>, D> bincounts;
35 for (
int i = 0; i < D; i++) {
36 int nperbin = ncells[i]/nbins[i];
37 int remainder = ncells[i]%nbins[i];
40 bincounts[i].assign(nbins[i], nperbin);
43 for (
int j = 0; j < remainder; j++)
48 std::array<std::vector<int64_t>, D> binoffsets;
50 for (
int i = 0; i < D; i++) {
51 binoffsets[i].resize(nbins[i]+1);
54 for (
int j = 1; j < nbins[i]+1; j++)
55 binoffsets[i][j] = binoffsets[i][j-1] + bincounts[i][j-1];
58 std::vector<std::array<std::array<int64_t,D>,2>> ilimits(N);
62 for (
int n = 0; n < N; n++) {
63 ilimits[n][0][0] = binoffsets[0][n];
64 ilimits[n][1][0] = binoffsets[0][n+1];
67 for (
int i = 0; i < nbins[0]; i++) {
68 for (
int j = 0; j < nbins[1]; j++) {
70 ilimits[n][0][0] = binoffsets[0][i];
71 ilimits[n][0][1] = binoffsets[1][j];
72 ilimits[n][1][0] = binoffsets[0][i+1];
73 ilimits[n][1][1] = binoffsets[1][j+1];
77 for (
int i = 0; i < nbins[0]; i++) {
79 for (
int j = 0; j < nbins[1]; j++) {
80 int n2 = (n1 + j)*nbins[2];
81 for (
int k = 0; k < nbins[2]; k++) {
83 ilimits[n][0][0] = binoffsets[0][i];
84 ilimits[n][0][1] = binoffsets[1][j];
85 ilimits[n][0][2] = binoffsets[2][k];
86 ilimits[n][1][0] = binoffsets[0][i+1];
87 ilimits[n][1][1] = binoffsets[1][j+1];
88 ilimits[n][1][2] = binoffsets[2][k+1];
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
std::vector< std::array< std::array< int64_t, D >, 2 > > structured_partitioner(int N, std::array< int64_t, D > ncells, int d=D, int seed=0)
Partition a D-dimensional structured grid along d axes into N subdomains.
Definition: structured_partitioner.h:25