ImpactX
Kurth6D.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_DISTRIBUTION_KURTH6D
11 #define IMPACTX_DISTRIBUTION_KURTH6D
12 
14 
15 #include <ablastr/constant.H>
16 
17 #include <AMReX_Random.H>
18 #include <AMReX_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx::distribution
24 {
25  struct Kurth6D
26  {
40  amrex::ParticleReal lambdax,
41  amrex::ParticleReal lambday,
42  amrex::ParticleReal lambdat,
43  amrex::ParticleReal lambdapx,
44  amrex::ParticleReal lambdapy,
45  amrex::ParticleReal lambdapt,
46  amrex::ParticleReal muxpx=0.0,
47  amrex::ParticleReal muypy=0.0,
48  amrex::ParticleReal mutpt=0.0
49  )
50  : m_lambdaX(lambdax), m_lambdaY(lambday), m_lambdaT(lambdat), m_lambdaPx(lambdapx), m_lambdaPy(lambdapy),
51  m_lambdaPt(lambdapt), m_muxpx(muxpx), m_muypy(muypy), m_mutpt(mutpt)
52  {
53  }
54 
62  void initialize ([[maybe_unused]] amrex::ParticleReal bunch_charge, [[maybe_unused]] RefPart const & ref)
63  {
64  }
65 
70  void
72  {
73  }
74 
87  amrex::ParticleReal & AMREX_RESTRICT x,
88  amrex::ParticleReal & AMREX_RESTRICT y,
89  amrex::ParticleReal & AMREX_RESTRICT t,
90  amrex::ParticleReal & AMREX_RESTRICT px,
91  amrex::ParticleReal & AMREX_RESTRICT py,
92  amrex::ParticleReal & AMREX_RESTRICT pt,
93  amrex::RandomEngine const & engine
94  ) const
95  {
96  using namespace amrex::literals;
98 
99  amrex::ParticleReal v,costheta,sintheta,phi,r;
100  amrex::ParticleReal L,alpha,pmax,pr,beta,p1,p2;
101  amrex::ParticleReal root,a1,a2;
102 
103  // Random samples used to define (x,y,z):
104  v = amrex::Random(engine);
105  costheta = amrex::Random(engine);
106  costheta = 2_prt*(costheta-0.5_prt);
107  sintheta = sqrt(1_prt-pow(costheta,2));
108  phi = amrex::Random(engine);
109  phi = 2_prt*pi*phi;
110 
111  // Transformations for (x,y,t):
112  r = pow(v,1_prt/3_prt);
113  x = r*sintheta*cos(phi);
114  y = r*sintheta*sin(phi);
115  t = r*costheta;
116 
117  // Random samples used to define L:
118  L = amrex::Random(engine);
119  L = r*sqrt(L);
120 
121  // Random samples used to define pr:
122  alpha = amrex::Random(engine);
123  alpha = pi*alpha;
124  pmax = 1_prt - pow(L/r,2) - pow(r,2) + pow(L,2);
125  pmax = sqrt(pmax);
126  pr = pmax*cos(alpha);
127 
128  // Random samples used to define ptangent:
129  beta = amrex::Random(engine);
130  beta = 2_prt*pi*beta;
131  p1 = L/r*cos(beta); // This is phi component
132  p2 = L/r*sin(beta); // This is theta component
133 
134  // Transformation from spherical to Cartesian coord.:
135  px = pr*sintheta*cos(phi) + p2*costheta*cos(phi) - p1*sin(phi);
136  py = pr*sintheta*sin(phi) + p2*costheta*sin(phi) + p1*cos(phi);
137  pt = pr*costheta - p2*sintheta;
138 
139  // Scale to produce the identity covariance matrix:
140  amrex::ParticleReal const c = sqrt(5.0_prt);
141  x = c*x;
142  y = c*y;
143  t = c*t;
144  px = c*px;
145  py = c*py;
146  pt = c*pt;
147 
148  // Transform to produce the desired second moments/correlations:
149  root = sqrt(1.0_prt-m_muxpx*m_muxpx);
150  a1 = m_lambdaX * x / root;
151  a2 = m_lambdaPx * (-m_muxpx * x / root + px);
152  x = a1;
153  px = a2;
154  root = sqrt(1.0_prt-m_muypy*m_muypy);
155  a1 = m_lambdaY * y / root;
156  a2 = m_lambdaPy * (-m_muypy * y / root + py);
157  y = a1;
158  py = a2;
159  root = sqrt(1.0_prt-m_mutpt*m_mutpt);
160  a1 = m_lambdaT * t / root;
161  a2 = m_lambdaPt * (-m_mutpt * t / root + pt);
162  t = a1;
163  pt = a2;
164  }
165 
166  private:
167  amrex::ParticleReal m_lambdaX, m_lambdaY, m_lambdaT;
168  amrex::ParticleReal m_lambdaPx, m_lambdaPy, m_lambdaPt;
169  amrex::ParticleReal m_muxpx, m_muypy, m_mutpt;
170  };
171 
172 } // namespace impactx::distribution
173 
174 #endif // IMPACTX_DISTRIBUTION_KURTH6D
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr amrex::Real pi
constexpr std::enable_if_t< std::is_floating_point_v< T >, T > pi()
Real Random()
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: All.H:27
@ t
fixed t as the independent variable
c
beta
Definition: ReferenceParticle.H:30
Definition: Kurth6D.H:26
void initialize([[maybe_unused]] amrex::ParticleReal bunch_charge, [[maybe_unused]] RefPart const &ref)
Definition: Kurth6D.H:62
amrex::ParticleReal m_lambdaPy
Definition: Kurth6D.H:168
amrex::ParticleReal m_lambdaT
Definition: Kurth6D.H:167
void finalize()
Definition: Kurth6D.H:71
Kurth6D(amrex::ParticleReal lambdax, amrex::ParticleReal lambday, amrex::ParticleReal lambdat, amrex::ParticleReal lambdapx, amrex::ParticleReal lambdapy, amrex::ParticleReal lambdapt, amrex::ParticleReal muxpx=0.0, amrex::ParticleReal muypy=0.0, amrex::ParticleReal mutpt=0.0)
Definition: Kurth6D.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT t, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, amrex::RandomEngine const &engine) const
Definition: Kurth6D.H:86
amrex::ParticleReal m_muypy
Definition: Kurth6D.H:169
amrex::ParticleReal m_muxpx
related momentum axis intercepts of the phase space ellipse
Definition: Kurth6D.H:169
amrex::ParticleReal m_lambdaY
Definition: Kurth6D.H:167
amrex::ParticleReal m_lambdaPx
related position axis intercepts (length) of the phase space ellipse
Definition: Kurth6D.H:168
amrex::ParticleReal m_mutpt
Definition: Kurth6D.H:169
amrex::ParticleReal m_lambdaPt
Definition: Kurth6D.H:168
amrex::ParticleReal m_lambdaX
Definition: Kurth6D.H:167