From 32c12e5395c778a9462aa7f0f79c95d5d7eed588 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Fri, 10 Mar 2023 12:13:15 -0800 Subject: [PATCH 1/4] fix order of bins for neighbor list construction --- Src/Particle/AMReX_DenseBins.H | 6 +++--- Src/Particle/AMReX_NeighborList.H | 4 ++-- Src/Particle/AMReX_NeighborParticlesI.H | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Particle/AMReX_DenseBins.H b/Src/Particle/AMReX_DenseBins.H index fb1b66457fb..bc582377cc7 100644 --- a/Src/Particle/AMReX_DenseBins.H +++ b/Src/Particle/AMReX_DenseBins.H @@ -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; }); } @@ -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; }); } @@ -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; }); } diff --git a/Src/Particle/AMReX_NeighborList.H b/Src/Particle/AMReX_NeighborList.H index 88d9eabcc2e..0b733075bcd 100644 --- a/Src/Particle/AMReX_NeighborList.H +++ b/Src/Particle/AMReX_NeighborList.H @@ -371,7 +371,7 @@ public: for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) { 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; + 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); @@ -431,7 +431,7 @@ public: for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx-1); ++ii) { 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; + 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); diff --git a/Src/Particle/AMReX_NeighborParticlesI.H b/Src/Particle/AMReX_NeighborParticlesI.H index ed2e1844725..cb8032f3ac1 100644 --- a/Src/Particle/AMReX_NeighborParticlesI.H +++ b/Src/Particle/AMReX_NeighborParticlesI.H @@ -1058,7 +1058,7 @@ selectActualNeighbors (CheckPair&& check_pair, int num_cells) 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) { 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])) { From bb3e1d4abc60c260602b2ab510fbbaae282a2d12 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Fri, 10 Mar 2023 13:45:31 -0800 Subject: [PATCH 2/4] a couple that I missed --- Src/Particle/AMReX_ParticleLocator.H | 2 +- Src/Particle/AMReX_ParticleUtil.H | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Particle/AMReX_ParticleLocator.H b/Src/Particle/AMReX_ParticleLocator.H index 88b4de19ab5..99a0918aacb 100644 --- a/Src/Particle/AMReX_ParticleLocator.H +++ b/Src/Particle/AMReX_ParticleLocator.H @@ -67,7 +67,7 @@ struct AssignGrid for (int ii = ix_lo; ii <= ix_hi; ++ii) { 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; + 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)) { diff --git a/Src/Particle/AMReX_ParticleUtil.H b/Src/Particle/AMReX_ParticleUtil.H index c09afdeb571..54859db9030 100644 --- a/Src/Particle/AMReX_ParticleUtil.H +++ b/Src/Particle/AMReX_ParticleUtil.H @@ -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( (uix * ny + uiy) * nz + uiz + offset ); + return static_cast( (uiz * ny + uiy) * nx + uix + offset ); } private: From 0c5f182a043029db35cbeddbcc1db07d80d6aba7 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Sat, 11 Mar 2023 03:13:36 -0800 Subject: [PATCH 3/4] change order of for loops too --- Src/Particle/AMReX_NeighborList.H | 8 ++++---- Src/Particle/AMReX_NeighborParticlesI.H | 4 ++-- Src/Particle/AMReX_ParticleLocator.H | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Src/Particle/AMReX_NeighborList.H b/Src/Particle/AMReX_NeighborList.H index 0b733075bcd..40de6b8112a 100644 --- a/Src/Particle/AMReX_NeighborList.H +++ b/Src/Particle/AMReX_NeighborList.H @@ -368,9 +368,9 @@ 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(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx-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) { + for (int ii = amrex::max(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz-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]; @@ -428,9 +428,9 @@ 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(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx-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) { + for (int ii = amrex::max(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz-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]; diff --git a/Src/Particle/AMReX_NeighborParticlesI.H b/Src/Particle/AMReX_NeighborParticlesI.H index cb8032f3ac1..e2c8162ef21 100644 --- a/Src/Particle/AMReX_NeighborParticlesI.H +++ b/Src/Particle/AMReX_NeighborParticlesI.H @@ -1054,9 +1054,9 @@ 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(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx); ++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(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz); ++ii) { if (isActualNeighbor) break; int nbr_cell_id = (kk * ny + jj) * nx + ii; for (auto p = poffset[nbr_cell_id]; p < poffset[nbr_cell_id+1]; ++p) { diff --git a/Src/Particle/AMReX_ParticleLocator.H b/Src/Particle/AMReX_ParticleLocator.H index 99a0918aacb..40e8cd4573d 100644 --- a/Src/Particle/AMReX_ParticleLocator.H +++ b/Src/Particle/AMReX_ParticleLocator.H @@ -64,9 +64,9 @@ 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 = ix_lo; kk <= ix_hi; ++kk) { for (int jj = iy_lo; jj <= iy_hi; ++jj) { - for (int kk = iz_lo; kk <= iz_hi; ++kk) { + for (int ii = iz_lo; ii <= iz_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; From adf95f18d78a5a1059b6b68d0e61f723714249da Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Mon, 13 Mar 2023 10:25:36 -0700 Subject: [PATCH 4/4] Fix loops correctly --- Src/Particle/AMReX_NeighborList.H | 8 ++++---- Src/Particle/AMReX_NeighborParticlesI.H | 4 ++-- Src/Particle/AMReX_ParticleLocator.H | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Src/Particle/AMReX_NeighborList.H b/Src/Particle/AMReX_NeighborList.H index 40de6b8112a..32d380ce8aa 100644 --- a/Src/Particle/AMReX_NeighborList.H +++ b/Src/Particle/AMReX_NeighborList.H @@ -368,9 +368,9 @@ 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 kk = amrex::max(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx-1); ++kk) { + 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 ii = amrex::max(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz-1); ++ii) { + 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]; @@ -428,9 +428,9 @@ 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 kk = amrex::max(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx-1); ++kk) { + 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 ii = amrex::max(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz-1); ++ii) { + 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]; diff --git a/Src/Particle/AMReX_NeighborParticlesI.H b/Src/Particle/AMReX_NeighborParticlesI.H index e2c8162ef21..dd6f2012b7d 100644 --- a/Src/Particle/AMReX_NeighborParticlesI.H +++ b/Src/Particle/AMReX_NeighborParticlesI.H @@ -1054,9 +1054,9 @@ selectActualNeighbors (CheckPair&& check_pair, int num_cells) int nz = hi.z-lo.z+1; bool isActualNeighbor = false; - for (int kk = amrex::max(ix-num_cells, 0); kk <= amrex::min(ix+num_cells, nx); ++kk) { + 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 ii = amrex::max(iz-num_cells, 0); ii <= amrex::min(iz+num_cells, nz); ++ii) { + for (int ii = amrex::max(ix-num_cells, 0); ii <= amrex::min(ix+num_cells, nx); ++ii) { if (isActualNeighbor) break; int nbr_cell_id = (kk * ny + jj) * nx + ii; for (auto p = poffset[nbr_cell_id]; p < poffset[nbr_cell_id+1]; ++p) { diff --git a/Src/Particle/AMReX_ParticleLocator.H b/Src/Particle/AMReX_ParticleLocator.H index 40e8cd4573d..ca591e501f9 100644 --- a/Src/Particle/AMReX_ParticleLocator.H +++ b/Src/Particle/AMReX_ParticleLocator.H @@ -64,9 +64,9 @@ 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 kk = ix_lo; kk <= ix_hi; ++kk) { + for (int kk = iz_lo; kk <= iz_hi; ++kk) { for (int jj = iy_lo; jj <= iy_hi; ++jj) { - for (int ii = iz_lo; ii <= iz_hi; ++ii) { + 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;