diff options
Diffstat (limited to 'Source/Particles/WarpXParticleContainer.cpp')
-rw-r--r-- | Source/Particles/WarpXParticleContainer.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index b5ed32c94..427b58121 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -139,13 +139,6 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, const ParticleReal* vx, const ParticleReal* vy, const ParticleReal* vz, int nattr, const ParticleReal* attr, int uniqueparticles, amrex::Long id) { - // nattr is unused below but needed in the BL_ASSERT - amrex::ignore_unused(nattr); - - BL_ASSERT(nattr == 1); - - const ParticleReal* weight = attr; - int ibegin, iend; if (uniqueparticles) { ibegin = 0; @@ -175,6 +168,9 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, std::size_t np = iend-ibegin; + // treat weight as a special attr since it will always be specified + Vector<ParticleReal> weight(np); + #ifdef WARPX_DIM_RZ Vector<ParticleReal> theta(np); #endif @@ -204,16 +200,15 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, p.pos(1) = z[i]; #endif - if ( (NumRuntimeRealComps()>0) || (NumRuntimeIntComps()>0) ){ - DefineAndReturnParticleTile(0, 0, 0); - } - pinned_tile.push_back(p); + + // grab weight from the attr array + weight[i-ibegin] = attr[i*nattr]; } if (np > 0) { - pinned_tile.push_back_real(PIdx::w , weight + ibegin, weight + iend); + pinned_tile.push_back_real(PIdx::w , weight.data(), weight.data() + np); pinned_tile.push_back_real(PIdx::ux, vx + ibegin, vx + iend); pinned_tile.push_back_real(PIdx::uy, vy + ibegin, vy + iend); pinned_tile.push_back_real(PIdx::uz, vz + ibegin, vz + iend); @@ -236,9 +231,20 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, #endif } - for (int i = PIdx::nattribs; i < NumRealComps(); ++i) + for (int j = PIdx::nattribs; j < NumRealComps(); ++j) { - pinned_tile.push_back_real(i, 0.0); + if (j - PIdx::nattribs < nattr - 1) { + // get the next attribute from attr array + Vector<ParticleReal> attr_vals(np); + for (int i = ibegin; i < iend; ++i) + { + attr_vals[i-ibegin] = attr[j - PIdx::nattribs + 1 + i*nattr]; + } + pinned_tile.push_back_real(j, attr_vals.data(), attr_vals.data() + np); + } + else { + pinned_tile.push_back_real(j, np, 0.0); + } } auto old_np = particle_tile.numParticles(); |