Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of bins for neighbor list construction #3195

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Src/Particle/AMReX_DenseBins.H
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public:
index_type uix = amrex::min(nx-1,amrex::max(0,iv3.x));
index_type uiy = amrex::min(ny-1,amrex::max(0,iv3.y));
index_type uiz = amrex::min(nz-1,amrex::max(0,iv3.z));
return (uix * ny + uiy) * nz + uiz;
return (uiz * ny + uiy) * nx + uix;
});
}

Expand Down Expand Up @@ -289,7 +289,7 @@ public:
index_type uix = amrex::min(nx-1,amrex::max(0,iv3.x));
index_type uiy = amrex::min(ny-1,amrex::max(0,iv3.y));
index_type uiz = amrex::min(nz-1,amrex::max(0,iv3.z));
return (uix * ny + uiy) * nz + uiz;
return (uiz * ny + uiy) * nx + uix;
});
}

Expand Down Expand Up @@ -428,7 +428,7 @@ public:
index_type uix = amrex::min(nx-1,amrex::max(0,iv3.x));
index_type uiy = amrex::min(ny-1,amrex::max(0,iv3.y));
index_type uiz = amrex::min(nz-1,amrex::max(0,iv3.z));
return (uix * ny + uiy) * nz + uiz;
return (uiz * ny + uiy) * nx + uix;
});
}

Expand Down
12 changes: 6 additions & 6 deletions Src/Particle/AMReX_NeighborList.H
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ public:
int ny = hi_p[type].y-lo_p[type].y+1;
int nz = hi_p[type].z-lo_p[type].z+1;

for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz-1); ++kk) {
for (int jj = amrex::max(iy-num_cells, 0); jj <= amrex::min(iy+num_cells, ny-1); ++jj) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz-1); ++kk) {
int index = (ii * ny + jj) * nz + kk + off_bins;
for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) {
int index = (kk * ny + jj) * nx + ii + off_bins;
for (auto p = poffset[index]; p < poffset[index+1]; ++p) {
const auto& pid = pperm[p];
bool ghost_pid = (pid >= np_real);
Expand Down Expand Up @@ -428,10 +428,10 @@ public:
int ny = hi_p[type].y-lo_p[type].y+1;
int nz = hi_p[type].z-lo_p[type].z+1;

for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz-1); ++kk) {
for (int jj = amrex::max(iy-num_cells, 0); jj <= amrex::min(iy+num_cells, ny-1); ++jj) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz-1); ++kk) {
int index = (ii * ny + jj) * nz + kk + off_bins;
for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) {
int index = (kk * ny + jj) * nx + ii + off_bins;
for (auto p = poffset[index]; p < poffset[index+1]; ++p) {
const auto& pid = pperm[p];
bool ghost_pid = (pid >= np_real);
Expand Down
6 changes: 3 additions & 3 deletions Src/Particle/AMReX_NeighborParticlesI.H
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@ selectActualNeighbors (CheckPair&& check_pair, int num_cells)
int nz = hi.z-lo.z+1;

bool isActualNeighbor = false;
for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx); ++ii) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz); ++kk) {
for (int jj = amrex::max(iy-num_cells, 0); jj <= amrex::min(iy+num_cells, ny); ++jj) {
for (int kk = amrex::max(iz-num_cells, 0); kk <= amrex::min(iz+num_cells, nz); ++kk) {
for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx); ++ii) {
if (isActualNeighbor) break;
int nbr_cell_id = (ii * ny + jj) * nz + kk;
int nbr_cell_id = (kk * ny + jj) * nx + ii;
for (auto p = poffset[nbr_cell_id]; p < poffset[nbr_cell_id+1]; ++p) {
if (pperm[p] == i) continue;
if (call_check_pair(check_pair, ptile_data, ptile_data, i, pperm[p])) {
Expand Down
6 changes: 3 additions & 3 deletions Src/Particle/AMReX_ParticleLocator.H
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ struct AssignGrid
int iy_hi = amrex::min((lo.y + nGrow - m_lo.y) / m_bin_size.y, m_num_bins.y-1);
int iz_hi = amrex::min((lo.z + nGrow - m_lo.z) / m_bin_size.z, m_num_bins.z-1);
int loc = -1;
for (int ii = ix_lo; ii <= ix_hi; ++ii) {
for (int kk = iz_lo; kk <= iz_hi; ++kk) {
for (int jj = iy_lo; jj <= iy_hi; ++jj) {
for (int kk = iz_lo; kk <= iz_hi; ++kk) {
int index = (ii * m_num_bins.y + jj) * m_num_bins.z + kk;
for (int ii = ix_lo; ii <= ix_hi; ++ii) {
int index = (kk * m_num_bins.y + jj) * m_num_bins.x + ii;
for (const auto& nbor : m_bif.getBinIterator(index)) {
Box bx = nbor.second;
if (bx.contains(iv)) {
Expand Down
2 changes: 1 addition & 1 deletion Src/Particle/AMReX_ParticleUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ struct BinMapper
int uix = amrex::min(nx-1,amrex::max(0,iv3.x));
int uiy = amrex::min(ny-1,amrex::max(0,iv3.y));
int uiz = amrex::min(nz-1,amrex::max(0,iv3.z));
return static_cast<unsigned int>( (uix * ny + uiy) * nz + uiz + offset );
return static_cast<unsigned int>( (uiz * ny + uiy) * nx + uix + offset );
}

private:
Expand Down