From 9fa3a16002c585720e1741b5fdbe5e6d5b974af9 Mon Sep 17 00:00:00 2001 From: Dave Grote Date: Thu, 8 Aug 2019 16:27:54 -0700 Subject: Implemented ApplyInverseVolumeScalingToChargeDensity --- Source/FieldSolver/WarpXPushFieldsEM.cpp | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'Source/FieldSolver/WarpXPushFieldsEM.cpp') diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 21000424d..f199e0660 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -671,4 +671,53 @@ WarpX::ApplyInverseVolumeScalingToCurrentDensity (MultiFab* Jx, MultiFab* Jy, Mu }); } } + +void +WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int icomp, int lev) +{ + const long ngRho = Rho->nGrow(); + const std::array& dx = WarpX::CellSize(lev); + const Real dr = dx[0]; + + Box tilebox; + + for ( MFIter mfi(*Rho, TilingIfNotGPU()); mfi.isValid(); ++mfi ) + { + + Array4 const& Rho_arr = Rho->array(mfi); + + tilebox = mfi.tilebox(); + Box tb = convert(tilebox, IntVect::TheUnitVector()); + + // 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& xyzmin = WarpX::LowerCorner(tilebox, lev); + const Dim3 lo = lbound(tilebox); + const Real rmin = xyzmin[0]; + const int irmin = lo.x; + + // Rescale charge in r-z mode since the inverse volume factor was not + // included in the charge deposition. + amrex::ParallelFor(tb, + [=] AMREX_GPU_DEVICE (int i, int j, int k) + { + // Wrap the charge density deposited in the guard cells around + // to the cells above the axis. + // Rho is located on the boundary + if (rmin == 0. && 0 < i && i <= ngRho) { + Rho_arr(i,j,0,icomp) += Rho_arr(-i,j,0,icomp); + } + + // Apply the inverse volume scaling + const amrex::Real r = std::abs(rmin + (i - irmin)*dr); + if (r == 0.) { + // Verboncoeur JCP 164, 421-427 (2001) : corrected volume on axis + Rho_arr(i,j,0,icomp) /= (MathConst::pi*dr/3.); + } else { + Rho_arr(i,j,0,icomp) /= (2.*MathConst::pi*r); + } + }); + } +} #endif -- cgit v1.2.3 From 006c27ae9eb5ed31fdb4824b1c7e602712d5132f Mon Sep 17 00:00:00 2001 From: Dave Grote Date: Thu, 8 Aug 2019 16:56:27 -0700 Subject: Moved loop over ncomps into ApplyInverseVolumeScalingToChargeDensity --- Source/Evolve/WarpXEvolveEM.cpp | 8 +++----- Source/FieldSolver/WarpXPushFieldsEM.cpp | 6 +++--- Source/WarpX.H | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'Source/FieldSolver/WarpXPushFieldsEM.cpp') diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index e05fde03e..170a8f604 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -489,11 +489,9 @@ WarpX::PushParticlesandDepose (int lev, Real cur_time) ApplyInverseVolumeScalingToCurrentDensity(current_buf[lev][0].get(), current_buf[lev][1].get(), current_buf[lev][2].get(), lev-1); } if (rho_fp[lev].get()) { - for (int icomp = 0 ; icomp < rho_fp[lev].get()->nComp() ; icomp++) { - ApplyInverseVolumeScalingToChargeDensity(rho_fp[lev].get(), icomp, lev); - if (charge_buf[lev].get()) { - ApplyInverseVolumeScalingToChargeDensity(charge_buf[lev].get(), icomp, lev-1); - } + ApplyInverseVolumeScalingToChargeDensity(rho_fp[lev].get(), lev); + if (charge_buf[lev].get()) { + ApplyInverseVolumeScalingToChargeDensity(charge_buf[lev].get(), lev-1); } } #endif diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index f199e0660..1df05bc0f 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -673,7 +673,7 @@ WarpX::ApplyInverseVolumeScalingToCurrentDensity (MultiFab* Jx, MultiFab* Jy, Mu } void -WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int icomp, int lev) +WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int lev) { const long ngRho = Rho->nGrow(); const std::array& dx = WarpX::CellSize(lev); @@ -699,8 +699,8 @@ WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int icomp, int l // Rescale charge in r-z mode since the inverse volume factor was not // included in the charge deposition. - amrex::ParallelFor(tb, - [=] AMREX_GPU_DEVICE (int i, int j, int k) + amrex::ParallelFor(tb, Rho->nComp(), + [=] AMREX_GPU_DEVICE (int i, int j, int k, int icomp) { // Wrap the charge density deposited in the guard cells around // to the cells above the axis. diff --git a/Source/WarpX.H b/Source/WarpX.H index 67d2366d4..8d910dd4a 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -185,7 +185,6 @@ public: int lev); void ApplyInverseVolumeScalingToChargeDensity(amrex::MultiFab* Rho, - int icomp, int lev); #endif -- cgit v1.2.3