ImpactX
ToFixedS.H
Go to the documentation of this file.
1 /* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2  * Berkeley National Laboratory (subject to receipt of any required
3  * approvals from the U.S. Dept. of Energy). All rights reserved.
4  *
5  * This file is part of ImpactX.
6  *
7  * Authors: Chad Mitchell, Axel Huebl
8  * License: BSD-3-Clause-LBNL
9  */
10 #ifndef IMPACTX_TO_FIXED_S_H
11 #define IMPACTX_TO_FIXED_S_H
12 
14 
15 #include <AMReX_GpuQualifiers.H>
16 #include <AMReX_Math.H>
17 #include <AMReX_REAL.H>
18 
19 #include <cmath>
20 
21 
23 {
24  struct ToFixedS
25  {
27 
35  ToFixedS (amrex::ParticleReal const pzd)
36  : m_pzd(pzd)
37  {
38  }
39 
52  amrex::ParticleReal & x,
53  amrex::ParticleReal & y,
54  amrex::ParticleReal & z,
55  amrex::ParticleReal & px,
56  amrex::ParticleReal & py,
57  amrex::ParticleReal & pz) const
58  {
59  using namespace amrex::literals;
60 
61  // compute value of reference ptd = -gamma
62  amrex::ParticleReal const argd = 1.0_prt + pow(m_pzd, 2);
63  AMREX_ASSERT_WITH_MESSAGE(argd > 0.0_prt, "invalid ptd arg (<=0)");
64  amrex::ParticleReal const ptdf = argd > 0.0_prt ? -sqrt(argd) : -1.0_prt;
65 
66  // transform momenta to dynamic units (e.g., so that momenta are
67  // normalized by mc):
68  px = px * m_pzd;
69  py = py * m_pzd;
70  pz = pz * m_pzd;
71 
72  // compute value of particle pt = -gamma
73  amrex::ParticleReal const arg = 1.0_prt + pow(m_pzd + pz, 2) + pow(px, 2) + pow(py, 2);
74  AMREX_ASSERT_WITH_MESSAGE(arg > 0.0_prt, "invalid pt arg (<=0)");
75  amrex::ParticleReal const ptf = arg > 0.0_prt ? -sqrt(arg) : -1.0_prt;
76 
77  // transform position and momentum (from fixed t to fixed s)
78  x = x - px * z / (m_pzd + pz);
79  // px = px;
80  y = y - py * z / (m_pzd + pz);
81  // py = py;
82  auto & t = z; // We store t in the same memory slot as z.
83  t = ptf * z / (m_pzd + pz);
84  auto & pt = pz; // We store pt in the same memory slot as pz.
85  pt = ptf - ptdf;
86 
87  // transform momenta to static units (eg, so that momenta are
88  // normalized by pzd):
89  px = px / m_pzd;
90  py = py / m_pzd;
91  pt = pz / m_pzd;
92  }
93 
94  private:
95  amrex::ParticleReal m_pzd;
96  };
97 
98 } // namespace impactx::transformation
99 
100 #endif // IMPACTX_TO_FIXED_S_H
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T arg(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition: CoordinateTransformation.cpp:23
@ t
fixed t as the independent variable
Definition: ToFixedS.H:25
ToFixedS(amrex::ParticleReal const pzd)
Definition: ToFixedS.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &x, amrex::ParticleReal &y, amrex::ParticleReal &z, amrex::ParticleReal &px, amrex::ParticleReal &py, amrex::ParticleReal &pz) const
Definition: ToFixedS.H:51
ImpactXParticleContainer::ParticleType PType
Definition: ToFixedS.H:26
amrex::ParticleReal m_pzd
Design value of pz/mc = beta*gamma.
Definition: ToFixedS.H:95