ImpactX
ToFixedT.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_T_H
11 #define IMPACTX_TO_FIXED_T_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 ToFixedT
25  {
27 
35  ToFixedT (amrex::ParticleReal const ptd)
36  : m_ptd(ptd)
37  {
38  }
39 
50  PType& p,
51  amrex::ParticleReal & px,
52  amrex::ParticleReal & py,
53  amrex::ParticleReal & pt) const
54  {
55  using namespace amrex::literals;
56 
57  // access AoS data such as positions and cpu/id
58  amrex::ParticleReal const x = p.pos(RealAoS::x);
59  amrex::ParticleReal const y = p.pos(RealAoS::y);
60  amrex::ParticleReal const t = p.pos(RealAoS::t);
61 
62  // small tolerance to avoid NaN for pz<0:
63  constexpr amrex::ParticleReal tol = 1.0e-8_prt;
64 
65  // compute value of reference pzd = beta*gamma
66  amrex::ParticleReal const argd = -1.0_prt + pow(m_ptd, 2);
67  // AMREX_ASSERT_WITH_MESSAGE(argd > 0.0_prt, "invalid pzd arg (<=0)");
68  amrex::ParticleReal const pzdf = argd > 0.0_prt ? sqrt(argd) : tol;
69 
70  // transform momenta to dynamic units (eg, so that momenta are
71  // normalized by mc):
72  px = px * pzdf;
73  py = py * pzdf;
74  pt = pt * pzdf;
75 
76  // compute value of particle pz = beta*gamma
77  amrex::ParticleReal const arg = -1.0_prt + pow(m_ptd+pt, 2) - pow(px, 2) - pow(py, 2);
78  // AMREX_ASSERT_WITH_MESSAGE(arg > 0.0_prt, "invalid pz arg (<=0)");
79  amrex::ParticleReal const pzf = arg > 0.0_prt ? sqrt(arg) : tol;
80 
81  // transform position and momentum (from fixed s to fixed t)
82  p.pos(RealAoS::x) = x + px*t/(m_ptd+pt);
83  // px = px;
84  p.pos(RealAoS::y) = y + py*t/(m_ptd+pt);
85  // py = py;
86  p.pos(RealAoS::z) = pzf * t / (m_ptd + pt);
87  auto & pz = pt; // We store pz in the same memory slot as pt.
88  pz = pzf - pzdf;
89 
90  // transform momenta to static units (eg, so that momenta are
91  // normalized by pzdf):
92  px = px / pzdf;
93  py = py / pzdf;
94  pz = pz / pzdf;
95  }
96 
97  private:
98  amrex::ParticleReal m_ptd;
99  };
100 
101 } // namespace impactx::transformation
102 
103 #endif // IMPACTX_TO_FIXED_T_H
#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
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:48
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:50
@ z
position in z [m] (at fixed t)
Definition: ImpactXParticleContainer.H:56
Definition: ToFixedT.H:25
ToFixedT(amrex::ParticleReal const ptd)
Definition: ToFixedT.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PType &p, amrex::ParticleReal &px, amrex::ParticleReal &py, amrex::ParticleReal &pt) const
Definition: ToFixedT.H:49
amrex::ParticleReal m_ptd
Design value of pt/mc2 = -gamma.
Definition: ToFixedT.H:98
ImpactXParticleContainer::ParticleType PType
Definition: ToFixedT.H:26