ImpactX
Loading...
Searching...
No Matches
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_Math.H>
18#include <AMReX_Random.H>
19#include <AMReX_REAL.H>
20
21#include <cmath>
22
23
25{
26 struct Kurth6D
27 {
44 amrex::ParticleReal lambdax,
45 amrex::ParticleReal lambday,
46 amrex::ParticleReal lambdat,
47 amrex::ParticleReal lambdapx,
48 amrex::ParticleReal lambdapy,
49 amrex::ParticleReal lambdapt,
50 amrex::ParticleReal muxpx=0.0,
51 amrex::ParticleReal muypy=0.0,
52 amrex::ParticleReal mutpt=0.0,
53 amrex::ParticleReal meanx=0.0,
54 amrex::ParticleReal meany=0.0,
55 amrex::ParticleReal meant=0.0,
56 amrex::ParticleReal meanpx=0.0,
57 amrex::ParticleReal meanpy=0.0,
58 amrex::ParticleReal meanpt=0.0,
59 amrex::ParticleReal dispx=0.0,
60 amrex::ParticleReal disppx=0.0,
61 amrex::ParticleReal dispy=0.0,
62 amrex::ParticleReal disppy=0.0
63 )
64 : m_lambdaX(lambdax), m_lambdaY(lambday), m_lambdaT(lambdat), m_lambdaPx(lambdapx), m_lambdaPy(lambdapy),
65 m_lambdaPt(lambdapt), m_muxpx(muxpx), m_muypy(muypy), m_mutpt(mutpt), m_meanx(meanx), m_meany(meany),
66 m_meant(meant), m_meanpx(meanpx), m_meanpy(meanpy), m_meanpt(meanpt), m_dispx(dispx), m_disppx(disppx),
67 m_dispy(dispy), m_disppy(disppy)
68 {
69 }
70
78 void initialize ([[maybe_unused]] amrex::ParticleReal bunch_charge, [[maybe_unused]] RefPart const & ref)
79 {
80 }
81
86 void
88 {
89 }
90
103 amrex::ParticleReal & AMREX_RESTRICT x,
104 amrex::ParticleReal & AMREX_RESTRICT y,
105 amrex::ParticleReal & AMREX_RESTRICT t,
106 amrex::ParticleReal & AMREX_RESTRICT px,
107 amrex::ParticleReal & AMREX_RESTRICT py,
108 amrex::ParticleReal & AMREX_RESTRICT pt,
109 amrex::RandomEngine const & engine
110 ) const
111 {
112 using namespace amrex::literals;
113 using amrex::Math::powi;
115
116 amrex::ParticleReal v,costheta,sintheta,phi,r;
117 amrex::ParticleReal L,alpha,pmax,pr,beta,p1,p2;
118 amrex::ParticleReal root,a1,a2;
119
120 // Random samples used to define (x,y,z):
121 v = amrex::Random(engine);
122 costheta = amrex::Random(engine);
123 costheta = 2_prt*(costheta-0.5_prt);
124 sintheta = std::sqrt(1_prt-powi<2>(costheta));
125 phi = amrex::Random(engine);
126 phi = 2_prt*pi*phi;
127
128 // Transformations for (x,y,t):
129 r = std::pow(v,1_prt/3_prt);
130 x = r*sintheta * std::cos(phi);
131 y = r*sintheta * std::sin(phi);
132 t = r*costheta;
133
134 // Random samples used to define L:
135 L = amrex::Random(engine);
136 L = r*std::sqrt(L);
137
138 // Random samples used to define pr:
139 alpha = amrex::Random(engine);
140 alpha = pi*alpha;
141 pmax = 1_prt - powi<2>(L/r) - powi<2>(r) + powi<2>(L);
142 pmax = std::sqrt(pmax);
143 pr = pmax * std::cos(alpha);
144
145 // Random samples used to define ptangent:
146 beta = amrex::Random(engine);
147 beta = 2_prt*pi*beta;
148 p1 = L/r * std::cos(beta); // This is phi component
149 p2 = L/r * std::sin(beta); // This is theta component
150
151 // Transformation from spherical to Cartesian coord.:
152 px = pr*sintheta * std::cos(phi) + p2*costheta * std::cos(phi) - p1 * std::sin(phi);
153 py = pr*sintheta * std::sin(phi) + p2*costheta * std::sin(phi) + p1 * std::cos(phi);
154 pt = pr*costheta - p2*sintheta;
155
156 // Scale to produce the identity covariance matrix:
157 amrex::ParticleReal const c = std::sqrt(5.0_prt);
158 x = c*x;
159 y = c*y;
160 t = c*t;
161 px = c*px;
162 py = c*py;
163 pt = c*pt;
164
165 // Transform to produce the desired second moments/correlations:
166 root = std::sqrt(1.0_prt-m_muxpx*m_muxpx);
167 a1 = m_lambdaX * x / root;
168 a2 = m_lambdaPx * (-m_muxpx * x / root + px);
169 x = a1;
170 px = a2;
171 root = std::sqrt(1.0_prt-m_muypy*m_muypy);
172 a1 = m_lambdaY * y / root;
173 a2 = m_lambdaPy * (-m_muypy * y / root + py);
174 y = a1;
175 py = a2;
176 root = std::sqrt(1.0_prt-m_mutpt*m_mutpt);
177 a1 = m_lambdaT * t / root;
178 a2 = m_lambdaPt * (-m_mutpt * t / root + pt);
179 t = a1;
180 pt = a2;
181
182 // Apply dispersive correlations
183 x = x - m_dispx * pt;
184 px = px - m_disppx * pt;
185 y = y - m_dispy * pt;
186 py = py - m_disppy * pt;
187
188 // Apply centroid translation
189 x = x + m_meanx;
190 px = px + m_meanpx;
191 y = y + m_meany;
192 py = py + m_meanpy;
193 t = t + m_meant;
194 pt = pt + m_meanpt;
195 }
196
197 amrex::ParticleReal m_lambdaX, m_lambdaY, m_lambdaT;
198 amrex::ParticleReal m_lambdaPx, m_lambdaPy, m_lambdaPt;
199 amrex::ParticleReal m_muxpx, m_muypy, m_mutpt;
200 amrex::ParticleReal m_meanx, m_meany, m_meant;
201 amrex::ParticleReal m_meanpx, m_meanpy, m_meanpt;
202 amrex::ParticleReal m_dispx, m_disppx, m_dispy, m_disppy;
203 };
204
205} // namespace impactx::distribution
206
207#endif // IMPACTX_DISTRIBUTION_KURTH6D
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
static constexpr amrex::Real pi
constexpr T powi(T x) noexcept
Real Random()
Definition All.H:27
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
Definition ReferenceParticle.H:31
amrex::ParticleReal m_disppy
Definition Kurth6D.H:202
amrex::ParticleReal m_meant
Definition Kurth6D.H:200
amrex::ParticleReal m_lambdaPy
Definition Kurth6D.H:198
amrex::ParticleReal m_lambdaT
Definition Kurth6D.H:197
void finalize()
Definition Kurth6D.H:87
amrex::ParticleReal m_dispx
momentum coordinates of centroid offset
Definition Kurth6D.H:202
amrex::ParticleReal m_meanx
correlation length-momentum
Definition Kurth6D.H:200
amrex::ParticleReal m_meanpy
Definition Kurth6D.H:201
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:102
amrex::ParticleReal m_disppx
Definition Kurth6D.H:202
void initialize(amrex::ParticleReal bunch_charge, RefPart const &ref)
Definition Kurth6D.H:78
amrex::ParticleReal m_muypy
Definition Kurth6D.H:199
amrex::ParticleReal m_meany
Definition Kurth6D.H:200
amrex::ParticleReal m_muxpx
related momentum axis intercepts of the phase space ellipse
Definition Kurth6D.H:199
amrex::ParticleReal m_lambdaY
Definition Kurth6D.H:197
amrex::ParticleReal m_lambdaPx
related position axis intercepts (length) of the phase space ellipse
Definition Kurth6D.H:198
amrex::ParticleReal m_meanpt
Definition Kurth6D.H:201
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, amrex::ParticleReal meanx=0.0, amrex::ParticleReal meany=0.0, amrex::ParticleReal meant=0.0, amrex::ParticleReal meanpx=0.0, amrex::ParticleReal meanpy=0.0, amrex::ParticleReal meanpt=0.0, amrex::ParticleReal dispx=0.0, amrex::ParticleReal disppx=0.0, amrex::ParticleReal dispy=0.0, amrex::ParticleReal disppy=0.0)
Definition Kurth6D.H:43
amrex::ParticleReal m_meanpx
spatial coordinates of centroid offset
Definition Kurth6D.H:201
amrex::ParticleReal m_mutpt
Definition Kurth6D.H:199
amrex::ParticleReal m_dispy
Definition Kurth6D.H:202
amrex::ParticleReal m_lambdaPt
Definition Kurth6D.H:198
amrex::ParticleReal m_lambdaX
Definition Kurth6D.H:197