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 
13 #include <AMReX_Random.H>
14 #include <AMReX_REAL.H>
15 
16 #include <cmath>
17 
18 
19 namespace impactx::distribution
20 {
21  struct Kurth6D
22  {
35  Kurth6D(amrex::ParticleReal const sigx, amrex::ParticleReal const sigy,
36  amrex::ParticleReal const sigt,amrex::ParticleReal const sigpx,
37  amrex::ParticleReal const sigpy,amrex::ParticleReal const sigpt,
38  amrex::ParticleReal const muxpx=0.0, amrex::ParticleReal const muypy=0.0,
39  amrex::ParticleReal const mutpt=0.0
40  )
41  : m_sigmaX(sigx),m_sigmaY(sigy),m_sigmaT(sigt),m_sigmaPx(sigpx),m_sigmaPy(sigpy),
42  m_sigmaPt(sigpt),m_muxpx(muxpx),m_muypy(muypy),m_mutpt(mutpt)
43  {
44  }
45 
58  amrex::ParticleReal & x,
59  amrex::ParticleReal & y,
60  amrex::ParticleReal & t,
61  amrex::ParticleReal & px,
62  amrex::ParticleReal & py,
63  amrex::ParticleReal & pt,
64  amrex::RandomEngine const& engine) const {
65 
66  using namespace amrex::literals;
67 
68  amrex::ParticleReal v,costheta,sintheta,phi,r;
69  amrex::ParticleReal L,alpha,pmax,pr,beta,p1,p2;
70  amrex::ParticleReal root,a1,a2;
71 
72  constexpr amrex::ParticleReal pi = 3.14159265358979_prt;
73 
74  // Random samples used to define (x,y,z):
75  v = amrex::Random(engine);
76  costheta = amrex::Random(engine);
77  costheta = 2_prt*(costheta-0.5_prt);
78  sintheta = sqrt(1_prt-pow(costheta,2));
79  phi = amrex::Random(engine);
80  phi = 2_prt*pi*phi;
81 
82  // Transformations for (x,y,t):
83  r = pow(v,1_prt/3_prt);
84  x = r*sintheta*cos(phi);
85  y = r*sintheta*sin(phi);
86  t = r*costheta;
87 
88  // Random samples used to define L:
89  L = amrex::Random(engine);
90  L = r*sqrt(L);
91 
92  // Random samples used to define pr:
93  alpha = amrex::Random(engine);
94  alpha = pi*alpha;
95  pmax = 1_prt - pow(L/r,2) - pow(r,2) + pow(L,2);
96  pmax = sqrt(pmax);
97  pr = pmax*cos(alpha);
98 
99  // Random samples used to define ptangent:
100  beta = amrex::Random(engine);
101  beta = 2_prt*pi*beta;
102  p1 = L/r*cos(beta); // This is phi component
103  p2 = L/r*sin(beta); // This is theta component
104 
105  // Transformation from spherical to Cartesian coord.:
106  px = pr*sintheta*cos(phi) + p2*costheta*cos(phi) - p1*sin(phi);
107  py = pr*sintheta*sin(phi) + p2*costheta*sin(phi) + p1*cos(phi);
108  pt = pr*costheta - p2*sintheta;
109 
110  // Scale to produce the identity covariance matrix:
111  amrex::ParticleReal const c = sqrt(5.0_prt);
112  x = c*x;
113  y = c*y;
114  t = c*t;
115  px = c*px;
116  py = c*py;
117  pt = c*pt;
118 
119  // Transform to produce the desired second moments/correlations:
120  root = sqrt(1.0_prt-m_muxpx*m_muxpx);
121  a1 = m_sigmaX*x/root;
122  a2 = m_sigmaPx*(-m_muxpx*x/root+px);
123  x = a1;
124  px = a2;
125  root = sqrt(1.0_prt-m_muypy*m_muypy);
126  a1 = m_sigmaY*y/root;
127  a2 = m_sigmaPy*(-m_muypy*y/root+py);
128  y = a1;
129  py = a2;
130  root = sqrt(1.0_prt-m_mutpt*m_mutpt);
131  a1 = m_sigmaT*t/root;
132  a2 = m_sigmaPt*(-m_mutpt*t/root+pt);
133  t = a1;
134  pt = a2;
135  }
136  private:
137  amrex::ParticleReal m_sigmaX,m_sigmaY,m_sigmaT;
138  amrex::ParticleReal m_sigmaPx,m_sigmaPy,m_sigmaPt;
139  amrex::ParticleReal m_muxpx,m_muypy,m_mutpt;
140  };
141 
142 } // namespace impactx::distribution
143 
144 #endif // IMPACTX_DISTRIBUTION_KURTH6D
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
constexpr std::enable_if_t< std::is_floating_point< T >::value, 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:26
c
beta
Definition: Kurth6D.H:22
amrex::ParticleReal m_sigmaT
Definition: Kurth6D.H:137
amrex::ParticleReal m_sigmaX
Definition: Kurth6D.H:137
amrex::ParticleReal m_muypy
Definition: Kurth6D.H:139
amrex::ParticleReal m_sigmaY
Definition: Kurth6D.H:137
amrex::ParticleReal m_muxpx
RMS momentum.
Definition: Kurth6D.H:139
amrex::ParticleReal m_sigmaPx
related RMS sizes (length)
Definition: Kurth6D.H:138
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &x, amrex::ParticleReal &y, amrex::ParticleReal &t, amrex::ParticleReal &px, amrex::ParticleReal &py, amrex::ParticleReal &pt, amrex::RandomEngine const &engine) const
Definition: Kurth6D.H:57
amrex::ParticleReal m_sigmaPt
Definition: Kurth6D.H:138
amrex::ParticleReal m_mutpt
Definition: Kurth6D.H:139
Kurth6D(amrex::ParticleReal const sigx, amrex::ParticleReal const sigy, amrex::ParticleReal const sigt, amrex::ParticleReal const sigpx, amrex::ParticleReal const sigpy, amrex::ParticleReal const sigpt, amrex::ParticleReal const muxpx=0.0, amrex::ParticleReal const muypy=0.0, amrex::ParticleReal const mutpt=0.0)
Definition: Kurth6D.H:35
amrex::ParticleReal m_sigmaPy
Definition: Kurth6D.H:138