WarpX
ParticleIO.H
Go to the documentation of this file.
1 /* Copyright 2021 Axel Huebl
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef PARTICLEIO_H_
8 #define PARTICLEIO_H_
9 
11 
12 #include <AMReX_AmrParticles.H>
13 #include <AMReX_Gpu.H>
14 #include <AMReX_REAL.H>
15 
16 
32 template< typename T_ParticleContainer >
33 void
34 particlesConvertUnits (ConvertDirection convert_direction, T_ParticleContainer* pc, amrex::ParticleReal const mass )
35 {
36  using namespace amrex;
37 
38  // Compute conversion factor
39  auto factor = 1_rt;
40 
41  if (convert_direction == ConvertDirection::WarpX_to_SI){
42  factor = mass;
43  } else if (convert_direction == ConvertDirection::SI_to_WarpX){
44  factor = 1._rt/mass;
45  }
46 
47  const int nLevels = pc->finestLevel();
48  for (int lev=0; lev<=nLevels; lev++){
49 #ifdef AMREX_USE_OMP
50 #pragma omp parallel if (Gpu::notInLaunchRegion())
51 #endif
52  for (WarpXParIter pti(*pc, lev); pti.isValid(); ++pti)
53  {
54  // - momenta are stored as a struct of array, in `attribs`
55  auto& attribs = pti.GetAttribs();
56  ParticleReal* AMREX_RESTRICT ux = attribs[PIdx::ux].dataPtr();
57  ParticleReal* AMREX_RESTRICT uy = attribs[PIdx::uy].dataPtr();
58  ParticleReal* AMREX_RESTRICT uz = attribs[PIdx::uz].dataPtr();
59  // Loop over the particles and convert momentum
60  const long np = pti.numParticles();
61  ParallelFor( np,
62  [=] AMREX_GPU_DEVICE (long i) {
63  ux[i] *= factor;
64  uy[i] *= factor;
65  uz[i] *= factor;
66  }
67  );
68  }
69  }
70 }
71 
72 #endif /* PARTICLEIO_H_ */
Definition: WarpXParticleContainer_fwd.H:28
void particlesConvertUnits(ConvertDirection convert_direction, T_ParticleContainer *pc, amrex::ParticleReal const mass)
Definition: ParticleIO.H:34
Definition: WarpXParticleContainer_fwd.H:28
def uz
Definition: read_lab_particles.py:29
ConvertDirection
Definition: WarpXParticleContainer_fwd.H:22
Definition: WarpXParticleContainer_fwd.H:28
i
Definition: check_interp_points_and_weights.py:171
def ux
Definition: read_lab_particles.py:28
Definition: WarpXParticleContainer.H:58
Definition: BreitWheelerEngineWrapper.H:35