aboutsummaryrefslogtreecommitdiff
path: root/Source/Diagnostics/ParticleIO.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Diagnostics/ParticleIO.cpp')
-rw-r--r--Source/Diagnostics/ParticleIO.cpp46
1 files changed, 5 insertions, 41 deletions
diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp
index e391cbf8b..d89b58ce1 100644
--- a/Source/Diagnostics/ParticleIO.cpp
+++ b/Source/Diagnostics/ParticleIO.cpp
@@ -7,7 +7,9 @@
* License: BSD-3-Clause-LBNL
*/
+#include "Particles/ParticleIO.H"
#include "Particles/MultiParticleContainer.H"
+#include "Particles/ParticleBuffer.H"
#include "Particles/PhysicalParticleContainer.H"
#include "Particles/RigidInjectedParticleContainer.H"
#include "Particles/SpeciesPhysicalProperties.H"
@@ -121,52 +123,14 @@ MultiParticleContainer::WriteHeader (std::ostream& os) const
}
}
-// Particle momentum is defined as gamma*velocity, which is neither
-// SI mass*gamma*velocity nor normalized gamma*velocity/c.
-// This converts momentum to SI units (or vice-versa) to write SI data
-// to file.
-// Photons are a special case, since particle momentum is defined as
-// (photon_energy/(m_e * c) ) * u, where u is the photon direction (a
-// unit vector).
void
-PhysicalParticleContainer::ConvertUnits(ConvertDirection convert_direction)
+PhysicalParticleContainer::ConvertUnits (ConvertDirection convert_direction)
{
WARPX_PROFILE("PhysicalParticleContainer::ConvertUnits()");
- // Compute conversion factor
- auto factor = 1_rt;
-
// Account for the special case of photons
const auto t_mass =
- AmIA<PhysicalSpecies::photon>() ? PhysConst::m_e : mass;
-
- if (convert_direction == ConvertDirection::WarpX_to_SI){
- factor = t_mass;
- } else if (convert_direction == ConvertDirection::SI_to_WarpX){
- factor = 1._rt/t_mass;
- }
+ this->AmIA<PhysicalSpecies::photon>() ? PhysConst::m_e : this->getMass();
- const int nLevels = finestLevel();
- for (int lev=0; lev<=nLevels; lev++){
-#ifdef AMREX_USE_OMP
-#pragma omp parallel if (Gpu::notInLaunchRegion())
-#endif
- for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti)
- {
- // - momenta are stored as a struct of array, in `attribs`
- auto& attribs = pti.GetAttribs();
- ParticleReal* AMREX_RESTRICT ux = attribs[PIdx::ux].dataPtr();
- ParticleReal* AMREX_RESTRICT uy = attribs[PIdx::uy].dataPtr();
- ParticleReal* AMREX_RESTRICT uz = attribs[PIdx::uz].dataPtr();
- // Loop over the particles and convert momentum
- const long np = pti.numParticles();
- ParallelFor( np,
- [=] AMREX_GPU_DEVICE (long i) {
- ux[i] *= factor;
- uy[i] *= factor;
- uz[i] *= factor;
- }
- );
- }
- }
+ particlesConvertUnits(convert_direction, this, t_mass);
}