Skip to content

Commit

Permalink
Change LowerCorner to return XDim3, add InvCellSize
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Jun 10, 2024
1 parent 810c249 commit 0557ba3
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 267 deletions.
2 changes: 1 addition & 1 deletion Source/AcceleratorLattice/LatticeElementFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ LatticeElementFinder::UpdateIndices (int const lev, amrex::MFIter const& a_mfi,
// Note that the current box is used since the box may have been updated since
// the initialization in InitElementFinder.
const amrex::Box box = a_mfi.tilebox();
m_zmin = WarpX::LowerCorner(box, lev, 0._rt)[2];
m_zmin = WarpX::LowerCorner(box, lev, 0._rt).z;
m_time = warpx.gett_new(lev);

if (accelerator_lattice.h_quad.nelements > 0) {
Expand Down
4 changes: 2 additions & 2 deletions Source/BoundaryConditions/WarpXFieldBoundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ WarpX::ApplyFieldBoundaryOnAxis (amrex::MultiFab* Er, amrex::MultiFab* Et, amrex
// Lower corner of tile box physical domain
// Note that this is done before the tilebox.grow so that
// these do not include the guard cells.
const std::array<amrex::Real, 3>& xyzmin = LowerCorner(tilebox, lev, 0._rt);
const amrex::Real rmin = xyzmin[0];
const amrex::XDim3 xyzmin = LowerCorner(tilebox, lev, 0._rt);
const amrex::Real rmin = xyzmin.x;

// Skip blocks that don't touch the axis
if (rmin > 0._rt) { continue; }
Expand Down
8 changes: 3 additions & 5 deletions Source/Diagnostics/ReducedDiags/ColliderRelevant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ void ColliderRelevant::ComputeDiags (int step)
const int lev = 0;

// define variables in preparation for field gathering
const std::array<amrex::Real,3>& dx = WarpX::CellSize(std::max(lev, 0));
const amrex::XDim3 dinv = amrex::XDim3{1._rt/dx[0], 1._rt/dx[1], 1._rt/dx[2]};
const amrex::XDim3 dinv = WarpX::InvCellSize(std::max(lev, 0));
const amrex::MultiFab & Ex = warpx.getField(FieldType::Efield_aux, lev,0);
const amrex::MultiFab & Ey = warpx.getField(FieldType::Efield_aux, lev,1);
const amrex::MultiFab & Ez = warpx.getField(FieldType::Efield_aux, lev,2);
Expand Down Expand Up @@ -478,8 +477,7 @@ void ColliderRelevant::ComputeDiags (int step)
amrex::Box box = pti.tilebox();
box.grow(ngEB);
const amrex::Dim3 lo = amrex::lbound(box);
const std::array<amrex::Real, 3>& xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const amrex::XDim3 gridmins = amrex::XDim3{xyzmin[0], xyzmin[1], xyzmin[2]};
const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const amrex::Array4<const amrex::Real> & ex_arr = Ex[pti].array();
const amrex::Array4<const amrex::Real> & ey_arr = Ey[pti].array();
const amrex::Array4<const amrex::Real> & ez_arr = Ez[pti].array();
Expand Down Expand Up @@ -515,7 +513,7 @@ void ColliderRelevant::ComputeDiags (int step)
ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
ex_type, ey_type, ez_type,
bx_type, by_type, bz_type,
dinv, gridmins, lo,
dinv, xyzmin, lo,
n_rz_azimuthal_modes, nox, galerkin_interpolation);
// compute chi
amrex::Real chi = 0.0_rt;
Expand Down
4 changes: 2 additions & 2 deletions Source/Diagnostics/ReducedDiags/FieldEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ FieldEnergy::ComputeNorm2RZ(const amrex::MultiFab& field, const int lev)
amrex::Box tb = convert(tilebox, field.ixType().toIntVect());

// Lower corner of tile box physical domain
const std::array<amrex::Real, 3>& xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const amrex::XDim3 xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const Dim3 lo = lbound(tilebox);
const Dim3 hi = ubound(tilebox);
const Real rmin = xyzmin[0] + (tb.ixType().nodeCentered(0) ? 0._rt : 0.5_rt*dr);
const Real rmin = xyzmin.x + (tb.ixType().nodeCentered(0) ? 0._rt : 0.5_rt*dr);
const int irmin = lo.x;
const int irmax = hi.x;

Expand Down
9 changes: 3 additions & 6 deletions Source/Diagnostics/ReducedDiags/FieldProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,8 @@ void FieldProbe::ComputeDiags (int step)

auto * const AMREX_RESTRICT idcpu = pti.GetStructOfArrays().GetIdCPUData().data();

const auto &xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const std::array<Real, 3> &dx = WarpX::CellSize(lev);

const amrex::XDim3 gridmins = amrex::XDim3{xyzmin[0], xyzmin[1], xyzmin[2]};
const amrex::XDim3 dinv = amrex::XDim3{1._rt/dx[0], 1._rt/dx[1], 1._rt/dx[2]};
const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const amrex::XDim3 dinv = WarpX::InvCellSize(lev);
const Dim3 lo = lbound(box);

// Temporarily defining modes and interp outside ParallelFor to avoid GPU compilation errors.
Expand All @@ -509,7 +506,7 @@ void FieldProbe::ComputeDiags (int step)
doGatherShapeN(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
arrEx, arrEy, arrEz, arrBx, arrBy, arrBz,
Extype, Eytype, Eztype, Bxtype, Bytype, Bztype,
dinv, gridmins, lo, temp_modes,
dinv, xyzmin, lo, temp_modes,
temp_interp_order, false);

//Calculate the Poynting Vector S
Expand Down
8 changes: 3 additions & 5 deletions Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ void ParticleExtrema::ComputeDiags (int step)
for (int lev = 0; lev <= level_number; ++lev)
{
// define variables in preparation for field gathering
const std::array<amrex::Real,3>& dx = WarpX::CellSize(std::max(lev, 0));
const amrex::XDim3 dinv = amrex::XDim3{1._rt/dx[0], 1._rt/dx[1], 1._rt/dx[2]};
const amrex::XDim3 dinv = WarpX::InvCellSize(std::max(lev, 0));

const amrex::MultiFab & Ex = warpx.getField(FieldType::Efield_aux, lev,0);
const amrex::MultiFab & Ey = warpx.getField(FieldType::Efield_aux, lev,1);
Expand Down Expand Up @@ -301,8 +300,7 @@ void ParticleExtrema::ComputeDiags (int step)
amrex::Box box = pti.tilebox();
box.grow(ngEB);
const amrex::Dim3 lo = amrex::lbound(box);
const std::array<amrex::Real, 3>& xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const amrex::XDim3 gridmins = amrex::XDim3{xyzmin[0], xyzmin[1], xyzmin[2]};
const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev, 0._rt);
const auto& ex_arr = Ex[pti].array();
const auto& ey_arr = Ey[pti].array();
const auto& ez_arr = Ez[pti].array();
Expand Down Expand Up @@ -338,7 +336,7 @@ void ParticleExtrema::ComputeDiags (int step)
ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
ex_type, ey_type, ez_type,
bx_type, by_type, bz_type,
dinv, gridmins, lo,
dinv, xyzmin, lo,
n_rz_azimuthal_modes, nox, galerkin_interpolation);
// compute chi
amrex::Real chi = 0.0_rt;
Expand Down
4 changes: 2 additions & 2 deletions Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ SpectralFieldDataRZ::SpectralFieldDataRZ (const int lev,
#endif

// Create the Hankel transformer for each box.
std::array<amrex::Real,3> xmax = WarpX::UpperCorner(mfi.tilebox(), lev, 0._rt);
multi_spectral_hankel_transformer[mfi] = SpectralHankelTransformer(grid_size[0], n_rz_azimuthal_modes, xmax[0]);
amrex::XDim3 xyzmax = WarpX::UpperCorner(mfi.tilebox(), lev, 0._rt);
multi_spectral_hankel_transformer[mfi] = SpectralHankelTransformer(grid_size[0], n_rz_azimuthal_modes, xyzmax.x);
}
}

Expand Down
16 changes: 8 additions & 8 deletions Source/FieldSolver/WarpXPushFieldsEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,11 @@ WarpX::ApplyInverseVolumeScalingToCurrentDensity (MultiFab* Jx, MultiFab* Jy, Mu
// Lower corner of tile box physical domain
// Note that this is done before the tilebox.grow so that
// these do not include the guard cells.
const std::array<amrex::Real, 3>& xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const Real rmin = xyzmin[0];
const Real rminr = xyzmin[0] + (tbr.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Real rmint = xyzmin[0] + (tbt.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Real rminz = xyzmin[0] + (tbz.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const amrex::XDim3 xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const Real rmin = xyzmin.x;
const Real rminr = xyzmin.x + (tbr.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Real rmint = xyzmin.x + (tbt.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Real rminz = xyzmin.x + (tbz.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Dim3 lo = lbound(tilebox);
const int irmin = lo.x;

Expand Down Expand Up @@ -1416,10 +1416,10 @@ WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int lev)
// Lower corner of tile box physical domain
// Note that this is done before the tilebox.grow so that
// these do not include the guard cells.
const std::array<amrex::Real, 3>& xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const amrex::XDim3 xyzmin = WarpX::LowerCorner(tilebox, lev, 0._rt);
const Dim3 lo = lbound(tilebox);
const Real rmin = xyzmin[0];
const Real rminr = xyzmin[0] + (tb.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const Real rmin = xyzmin.x;
const Real rminr = xyzmin.x + (tb.type(0) == NODE ? 0._rt : 0.5_rt*dx[0]);
const int irmin = lo.x;
const int ishift = (rminr > rmin ? 1 : 0);

Expand Down
24 changes: 12 additions & 12 deletions Source/Particles/Deposition/ChargeDeposition.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* \param rho_fab FArrayBox of charge density, either full array or tile.
* \param np_to_deposit Number of particles for which current is deposited.
* \param dinv 3D cell size inverse
* \param gridmins The lower bounds of the domain
* \param xyzmin The lower bounds of the domain
* \param lo Index lower bounds of domain.
* \param q species charge.
* \param n_rz_azimuthal_modes Number of azimuthal modes when using RZ geometry.
Expand All @@ -41,7 +41,7 @@ void doChargeDepositionShapeN (const GetParticlePosition<PIdx>& GetPosition,
amrex::FArrayBox& rho_fab,
long np_to_deposit,
const amrex::XDim3 & dinv,
const amrex::XDim3 & gridmins,
const amrex::XDim3 & xyzmin,
amrex::Dim3 lo,
amrex::Real q,
[[maybe_unused]] int n_rz_azimuthal_modes)
Expand Down Expand Up @@ -83,9 +83,9 @@ void doChargeDepositionShapeN (const GetParticlePosition<PIdx>& GetPosition,
const amrex::Real costheta = (rp > 0._rt ? xp/rp : 1._rt);
const amrex::Real sintheta = (rp > 0._rt ? yp/rp : 0._rt);
const Complex xy0 = Complex{costheta, sintheta};
const amrex::Real x = (rp - gridmins.x)*dinv.x;
const amrex::Real x = (rp - xyzmin.x)*dinv.x;
#else
const amrex::Real x = (xp - gridmins.x)*dinv.x;
const amrex::Real x = (xp - xyzmin.x)*dinv.x;
#endif

// Compute shape factor along x
Expand All @@ -100,7 +100,7 @@ void doChargeDepositionShapeN (const GetParticlePosition<PIdx>& GetPosition,
#endif //defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_3D)
#if defined(WARPX_DIM_3D)
// y direction
const amrex::Real y = (yp - gridmins.y)*dinv.y;
const amrex::Real y = (yp - xyzmin.y)*dinv.y;
amrex::Real sy[depos_order + 1] = {0._rt};
int j = 0;
if (rho_type[1] == NODE) {
Expand All @@ -110,7 +110,7 @@ void doChargeDepositionShapeN (const GetParticlePosition<PIdx>& GetPosition,
}
#endif
// z direction
const amrex::Real z = (zp - gridmins.z)*dinv.z;
const amrex::Real z = (zp - xyzmin.z)*dinv.z;
amrex::Real sz[depos_order + 1] = {0._rt};
int k = 0;
if (rho_type[WARPX_ZINDEX] == NODE) {
Expand Down Expand Up @@ -169,7 +169,7 @@ void doChargeDepositionShapeN (const GetParticlePosition<PIdx>& GetPosition,
* \param ix_type
* \param np_to_deposit Number of particles for which charge is deposited.
* \param dinv 3D cell size inverse
* \param gridmins The lower bounds of the domain
* \param xyzmin The lower bounds of the domain
* \param lo Index lower bounds of domain.
* \param q species charge.
* \param n_rz_azimuthal_modes Number of azimuthal modes when using RZ geometry.
Expand All @@ -187,7 +187,7 @@ void doChargeDepositionSharedShapeN (const GetParticlePosition<PIdx>& GetPositio
const amrex::IntVect& ix_type,
const long np_to_deposit,
const amrex::XDim3 & dinv,
const amrex::XDim3 & gridmins,
const amrex::XDim3 & xyzmin,
const amrex::Dim3 lo,
const amrex::Real q,
[[maybe_unused]]const int n_rz_azimuthal_modes,
Expand Down Expand Up @@ -331,9 +331,9 @@ void doChargeDepositionSharedShapeN (const GetParticlePosition<PIdx>& GetPositio
sintheta = 0._rt;
}
const Complex xy0 = Complex{costheta, sintheta};
const amrex::Real x = (rp - gridmins.x)*dinv.x;
const amrex::Real x = (rp - xyzmin.x)*dinv.x;
#else
const amrex::Real x = (xp - gridmins.x)*dinv.x;
const amrex::Real x = (xp - xyzmin.x)*dinv.x;
#endif

// Compute shape factor along x
Expand All @@ -348,7 +348,7 @@ void doChargeDepositionSharedShapeN (const GetParticlePosition<PIdx>& GetPositio
#endif //defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_3D)
#if defined(WARPX_DIM_3D)
// y direction
const amrex::Real y = (yp - gridmins.y)*dinv.y;
const amrex::Real y = (yp - xyzmin.y)*dinv.y;
amrex::Real sy[depos_order + 1] = {0._rt};
int j = 0;
if (rho_type[1] == NODE) {
Expand All @@ -358,7 +358,7 @@ void doChargeDepositionSharedShapeN (const GetParticlePosition<PIdx>& GetPositio
}
#endif
// z direction
const amrex::Real z = (zp - gridmins.z)*dinv.z;
const amrex::Real z = (zp - xyzmin.z)*dinv.z;
amrex::Real sz[depos_order + 1] = {0._rt};
int k = 0;
if (rho_type[WARPX_ZINDEX] == NODE) {
Expand Down
Loading

0 comments on commit 0557ba3

Please sign in to comment.