diff options
-rw-r--r-- | Source/ParticleContainer.H | 10 | ||||
-rw-r--r-- | Source/ParticleContainer.cpp | 11 | ||||
-rw-r--r-- | Source/PhysicalParticleContainer.cpp | 97 | ||||
-rw-r--r-- | Source/WarpX.cpp | 10 | ||||
-rw-r--r-- | Source/WarpXParticleContainer.H | 2 |
5 files changed, 82 insertions, 48 deletions
diff --git a/Source/ParticleContainer.H b/Source/ParticleContainer.H index 8a4033795..1b955d55f 100644 --- a/Source/ParticleContainer.H +++ b/Source/ParticleContainer.H @@ -152,6 +152,14 @@ public: int nSpecies() const {return nspecies;} + int nSpeciesDepositOnMainGrid () const { + int r = 0; + for (int i : deposit_on_main_grid) { + if (i) ++r; + } + return r; + } + int L_lower_order_in_v() {return l_lower_order_in_v;} bool Use_fdtd_nci_corr() {return use_fdtd_nci_corr;} @@ -181,6 +189,8 @@ protected: std::vector<std::string> species_names; + std::vector<int> deposit_on_main_grid; + std::vector<PCTypes> species_types; private: diff --git a/Source/ParticleContainer.cpp b/Source/ParticleContainer.cpp index 02de0a4db..66a5736ab 100644 --- a/Source/ParticleContainer.cpp +++ b/Source/ParticleContainer.cpp @@ -23,6 +23,7 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) else if (species_types[i] == PCTypes::RigidInjected) { allcontainers[i].reset(new RigidInjectedParticleContainer(amr_core, i, species_names[i])); } + allcontainers[i]->deposit_on_main_grid = deposit_on_main_grid[i]; } if (WarpX::use_laser) { allcontainers[n-1].reset(new LaserParticleContainer(amr_core,n-1)); @@ -44,6 +45,16 @@ MultiParticleContainer::ReadParameters () pp.getarr("species_names", species_names); BL_ASSERT(species_names.size() == nspecies); + deposit_on_main_grid.resize(nspecies, 0); + std::vector<std::string> tmp; + pp.queryarr("deposit_on_main_grid", tmp); + for (auto const& name : tmp) { + auto it = std::find(species_names.begin(), species_names.end(), name); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.deposit_on_main_grid must be part of particles.species_names"); + int i = std::distance(species_names.begin(), it); + deposit_on_main_grid[i] = 1; + } + species_types.resize(nspecies, PCTypes::Physical); std::vector<std::string> rigid_injected_species; diff --git a/Source/PhysicalParticleContainer.cpp b/Source/PhysicalParticleContainer.cpp index ddb066301..d9136579a 100644 --- a/Source/PhysicalParticleContainer.cpp +++ b/Source/PhysicalParticleContainer.cpp @@ -891,6 +891,10 @@ PhysicalParticleContainer::Evolve (int lev, } } + if (deposit_on_main_grid && lev > 0) { + nfine_current = 0; + } + if (nfine_current != np || nfine_gather != np) { particle_tmp.resize(np); @@ -1175,51 +1179,54 @@ PhysicalParticleContainer::Evolve (int lev, const std::array<Real, 3>& xyzmin = xyzmin_tile; - tbx.grow(ngJ); - tby.grow(ngJ); - tbz.grow(ngJ); - - local_jx.resize(tbx); - local_jy.resize(tby); - local_jz.resize(tbz); - - local_jx = 0.0; - local_jy = 0.0; - local_jz = 0.0; - - jx_ptr = local_jx.dataPtr(); - jy_ptr = local_jy.dataPtr(); - jz_ptr = local_jz.dataPtr(); - - jxntot = local_jx.length(); - jyntot = local_jy.length(); - jzntot = local_jz.length(); - - warpx_current_deposition( - jx_ptr, &ngJ, jxntot, - jy_ptr, &ngJ, jyntot, - jz_ptr, &ngJ, jzntot, - &np_current, xp.data(), yp.data(), zp.data(), - uxp.data(), uyp.data(), uzp.data(), - giv.data(), wp.data(), &this->charge, - &xyzmin[0], &xyzmin[1], &xyzmin[2], - &dt, &dx[0], &dx[1], &dx[2], - &WarpX::nox,&WarpX::noy,&WarpX::noz, - &lvect,&WarpX::current_deposition_algo); - - BL_PROFILE_VAR_STOP(blp_pxr_cd); - - BL_PROFILE_VAR_START(blp_accumulate); - const int ncomp = 1; - amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jx), - BL_TO_FORTRAN_3D(jxfab), ncomp); - - amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jy), - BL_TO_FORTRAN_3D(jyfab), ncomp); - - amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jz), - BL_TO_FORTRAN_3D(jzfab), ncomp); - BL_PROFILE_VAR_STOP(blp_accumulate); + if (np_current > 0) + { + tbx.grow(ngJ); + tby.grow(ngJ); + tbz.grow(ngJ); + + local_jx.resize(tbx); + local_jy.resize(tby); + local_jz.resize(tbz); + + local_jx = 0.0; + local_jy = 0.0; + local_jz = 0.0; + + jx_ptr = local_jx.dataPtr(); + jy_ptr = local_jy.dataPtr(); + jz_ptr = local_jz.dataPtr(); + + jxntot = local_jx.length(); + jyntot = local_jy.length(); + jzntot = local_jz.length(); + + warpx_current_deposition( + jx_ptr, &ngJ, jxntot, + jy_ptr, &ngJ, jyntot, + jz_ptr, &ngJ, jzntot, + &np_current, xp.data(), yp.data(), zp.data(), + uxp.data(), uyp.data(), uzp.data(), + giv.data(), wp.data(), &this->charge, + &xyzmin[0], &xyzmin[1], &xyzmin[2], + &dt, &dx[0], &dx[1], &dx[2], + &WarpX::nox,&WarpX::noy,&WarpX::noz, + &lvect,&WarpX::current_deposition_algo); + + BL_PROFILE_VAR_STOP(blp_pxr_cd); + + BL_PROFILE_VAR_START(blp_accumulate); + const int ncomp = 1; + amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jx), + BL_TO_FORTRAN_3D(jxfab), ncomp); + + amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jy), + BL_TO_FORTRAN_3D(jyfab), ncomp); + + amrex_atomic_accumulate_fab(BL_TO_FORTRAN_3D(local_jz), + BL_TO_FORTRAN_3D(jzfab), ncomp); + BL_PROFILE_VAR_STOP(blp_accumulate); + } if (np_current < np) { diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 9ca17c759..3e1b225ac 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -521,14 +521,18 @@ WarpX::AllocLevelData (int lev, const BoxArray& ba, const DistributionMapping& d #if (AMREX_SPACEDIM == 3) IntVect ngE(ngx,ngy,ngz); IntVect ngJ(ngx,ngy,ngz_nonci); - IntVect ngRho = ngJ + 1; // One extra ghost cell, so that it's safe to deposit charge density - // after pushing particle. #elif (AMREX_SPACEDIM == 2) IntVect ngE(ngx,ngz); IntVect ngJ(ngx,ngz_nonci); - IntVect ngRho = ngJ + 1; #endif + IntVect ngRho = ngJ+1; //One extra ghost cell, so that it's safe to deposit charge density + // after pushing particle. + + if (mypc->nSpeciesDepositOnMainGrid() && n_current_deposition_buffer == 0) { + n_current_deposition_buffer = 1; + } + if (n_current_deposition_buffer < 0) { n_current_deposition_buffer = ngJ.max(); } diff --git a/Source/WarpXParticleContainer.H b/Source/WarpXParticleContainer.H index 2138a07a5..9f311c84c 100644 --- a/Source/WarpXParticleContainer.H +++ b/Source/WarpXParticleContainer.H @@ -179,6 +179,8 @@ protected: amrex::Real charge; amrex::Real mass; + bool deposit_on_main_grid = false; + static int do_not_push; }; |