From ee98feb72d6df609facf18bf448a92ee5e7023a2 Mon Sep 17 00:00:00 2001 From: atmyers Date: Mon, 23 Jan 2017 17:09:03 -0800 Subject: Add ability to inject several species at once. --- Source/WarpXEvolve.cpp | 150 +++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 72 deletions(-) (limited to 'Source/WarpXEvolve.cpp') diff --git a/Source/WarpXEvolve.cpp b/Source/WarpXEvolve.cpp index 3f1001a42..975d54d6a 100644 --- a/Source/WarpXEvolve.cpp +++ b/Source/WarpXEvolve.cpp @@ -272,45 +272,10 @@ WarpX::ComputeDt () } void -WarpX::MoveWindow () -{ - - if (do_moving_window == 0) return; - - // compute the number of cells to shift - int dir = moving_window_dir; - Real new_lo[BL_SPACEDIM]; - Real new_hi[BL_SPACEDIM]; - const Real* current_lo = geom[0].ProbLo(); - const Real* current_hi = geom[0].ProbHi(); - const Real* dx = geom[0].CellSize(); - moving_window_x += moving_window_v * dt[0]; - int num_shift = (moving_window_x - current_lo[dir]) / dx[dir]; - - if (num_shift == 0) return; - - // update the problem domain - for (int i=0; iGetParticleContainer(ispecies); - const BoxArray& ba = myspc.ParticleBoxArray(0); - const DistributionMapping& dm = myspc.ParticleDistributionMap(0); + WarpXParticleContainer* myspc = &(mypc->GetParticleContainer(0)); + const BoxArray& ba = myspc->ParticleBoxArray(0); + const DistributionMapping& dm = myspc->ParticleDistributionMap(0); MultiFab dummy_mf(ba, 1, 0, dm, Fab_noallocate); // For each grid, loop only over the cells in the new region @@ -355,40 +311,90 @@ WarpX::MoveWindow () for (int k = 0; k < nz; k++) { for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { - for (int i_part=0; i_partGetParticleContainer(ispecies)); + for (int i_part=0; i_part < injected_plasma_ppc[ispec]; i_part++) { + Real particle_shift = (0.5+i_part)/injected_plasma_ppc[ispec]; #if (BL_SPACEDIM == 3) - Real x = intersectRealBox.lo(0) + (i + particle_shift)*dx[0]; - Real y = intersectRealBox.lo(1) + (j + particle_shift)*dx[1]; - Real z = intersectRealBox.lo(2) + (k + particle_shift)*dx[2]; + Real x = intersectRealBox.lo(0) + (i + particle_shift)*dx[0]; + Real y = intersectRealBox.lo(1) + (j + particle_shift)*dx[1]; + Real z = intersectRealBox.lo(2) + (k + particle_shift)*dx[2]; #elif (BL_SPACEDIM == 2) - Real x = intersectRealBox.lo(0) + (i + particle_shift)*dx[0]; - Real y = 0.0; - Real z = intersectRealBox.lo(1) + (k + particle_shift)*dx[1]; + Real x = intersectRealBox.lo(0) + (i + particle_shift)*dx[0]; + Real y = 0.0; + Real z = intersectRealBox.lo(1) + (k + particle_shift)*dx[1]; #endif - int id = ParticleBase::NextID(); - int cpu = ParallelDescriptor::MyProc(); + int id = ParticleBase::NextID(); + int cpu = ParallelDescriptor::MyProc(); - std::vector pos(3, 0.0); + std::vector pos(3, 0.0); #if (BL_SPACEDIM == 3) - pos[0] = x; - pos[1] = y; - pos[2] = z; + pos[0] = x; + pos[1] = y; + pos[2] = z; #elif (BL_SPACEDIM == 2) - pos[0] = x; - pos[1] = z; + pos[0] = x; + pos[1] = z; +#endif + + std::vector attributes(PIdx::nattribs, 0.0); + + Real weight = injected_plasma_density[ispec]; +#if BL_SPACEDIM==3 + weight *= dx[0]*dx[1]*dx[2]/injected_plasma_ppc[ispec]; +#elif BL_SPACEDIM==2 + weight *= dx[0]*dx[1]/injected_plasma_ppc[ispec]; #endif - - std::vector attributes(PIdx::nattribs, 0.0); - attributes[PIdx::w] = weight; - myspc.addOneParticle(id, cpu, pos, attributes); - } - } + attributes[PIdx::w] = weight; + myspc->addOneParticle(id, cpu, pos, attributes); + } + } + } } } } } +} + +void +WarpX::MoveWindow () +{ + + if (do_moving_window == 0) return; + + // compute the number of cells to shift + int dir = moving_window_dir; + Real new_lo[BL_SPACEDIM]; + Real new_hi[BL_SPACEDIM]; + const Real* current_lo = geom[0].ProbLo(); + const Real* current_hi = geom[0].ProbHi(); + const Real* dx = geom[0].CellSize(); + moving_window_x += moving_window_v * dt[0]; + int num_shift = (moving_window_x - current_lo[dir]) / dx[dir]; + + if (num_shift == 0) return; + + // update the problem domain + for (int i=0; iRedistribute(false); -- cgit v1.2.3