ImpactX
Loading...
Searching...
No Matches
Kurth4D.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_KURTH4D
11#define IMPACTX_DISTRIBUTION_KURTH4D
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 Kurth4D
27 {
42 amrex::ParticleReal lambdax,
43 amrex::ParticleReal lambday,
44 amrex::ParticleReal lambdat,
45 amrex::ParticleReal lambdapx,
46 amrex::ParticleReal lambdapy,
47 amrex::ParticleReal lambdapt,
48 amrex::ParticleReal muxpx=0.0,
49 amrex::ParticleReal muypy=0.0,
50 amrex::ParticleReal mutpt=0.0,
51 amrex::ParticleReal meanx=0.0,
52 amrex::ParticleReal meany=0.0,
53 amrex::ParticleReal meant=0.0,
54 amrex::ParticleReal meanpx=0.0,
55 amrex::ParticleReal meanpy=0.0,
56 amrex::ParticleReal meanpt=0.0,
57 amrex::ParticleReal dispx=0.0,
58 amrex::ParticleReal disppx=0.0,
59 amrex::ParticleReal dispy=0.0,
60 amrex::ParticleReal disppy=0.0
61 )
62 : m_lambdaX(lambdax), m_lambdaY(lambday), m_lambdaT(lambdat), m_lambdaPx(lambdapx), m_lambdaPy(lambdapy),
63 m_lambdaPt(lambdapt), m_muxpx(muxpx), m_muypy(muypy), m_mutpt(mutpt), m_meanx(meanx), m_meany(meany),
64 m_meant(meant), m_meanpx(meanpx), m_meanpy(meanpy), m_meanpt(meanpt), m_dispx(dispx), m_disppx(disppx),
65 m_dispy(dispy), m_disppy(disppy)
66 {
67 }
68
76 void initialize ([[maybe_unused]] amrex::ParticleReal bunch_charge, [[maybe_unused]] RefPart const & ref)
77 {
78 }
79
84 void
86 {
87 }
88
101 amrex::ParticleReal & AMREX_RESTRICT x,
102 amrex::ParticleReal & AMREX_RESTRICT y,
103 amrex::ParticleReal & AMREX_RESTRICT t,
104 amrex::ParticleReal & AMREX_RESTRICT px,
105 amrex::ParticleReal & AMREX_RESTRICT py,
106 amrex::ParticleReal & AMREX_RESTRICT pt,
107 amrex::RandomEngine const & engine
108 ) const
109 {
110 using namespace amrex::literals;
111 using amrex::Math::powi;
113
114 amrex::ParticleReal v,phi,r,u1,u2,ln1;
115 amrex::ParticleReal alpha,u,Lz,pmax,pr,pphi;
116 amrex::ParticleReal root,a1,a2;
117
118 // Sample and transform to define (x,y):
119 v = amrex::Random(engine);
120 phi = amrex::Random(engine);
121 phi = 2_prt*pi*phi;
122 r = std::sqrt(v);
123 x = r * std::cos(phi);
124 y = r * std::sin(phi);
125
126 // Random samples used to define Lz:
127 u = amrex::Random(engine);
128 Lz = r*(2.0_prt*u-1.0_prt);
129
130 // Random samples used to define pr:
131 alpha = amrex::Random(engine);
132 alpha = pi*alpha;
133 pmax = 1.0_prt - powi<2>((Lz/r)) - powi<2>(r) + powi<2>(Lz);
134 pmax = std::sqrt(pmax);
135 pr = pmax * std::cos(alpha);
136 pphi = Lz/r;
137
138 // Transformations used to obtain (px,py):
139 px = pr * std::cos(phi)-pphi * std::sin(phi);
140 py = pr * std::sin(phi)+pphi * std::cos(phi);
141
142 // Sample and transform to define (t,pt):
143 t = amrex::Random(engine);
144 t = 2.0_prt*(t-0.5_prt);
145 u1 = amrex::Random(engine);
146 u2 = amrex::Random(engine);
147 ln1 = std::sqrt(-2_prt*std::log(u1));
148 pt = ln1 * std::cos(2_prt*pi*u2);
149
150 // Scale to produce the identity covariance matrix:
151 amrex::ParticleReal const c = std::sqrt(3.0_prt);
152 x = 2_prt*x;
153 y = 2_prt*y;
154 t = c*t;
155 px = 2_prt*px;
156 py = 2_prt*py;
157 // pt = pt;
158
159 // Transform to produce the desired second moments/correlations:
160 root = std::sqrt(1.0_prt-m_muxpx*m_muxpx);
161 a1 = m_lambdaX * x / root;
162 a2 = m_lambdaPx * (-m_muxpx * x / root + px);
163 x = a1;
164 px = a2;
165 root = std::sqrt(1.0_prt-m_muypy*m_muypy);
166 a1 = m_lambdaY * y / root;
167 a2 = m_lambdaPy * (-m_muypy * y / root + py);
168 y = a1;
169 py = a2;
170 root = std::sqrt(1.0_prt-m_mutpt*m_mutpt);
171 a1 = m_lambdaT * t / root;
172 a2 = m_lambdaPt * (-m_mutpt * t / root + pt);
173 t = a1;
174 pt = a2;
175
176 // Apply dispersive correlations
177 x = x - m_dispx * pt;
178 px = px - m_disppx * pt;
179 y = y - m_dispy * pt;
180 py = py - m_disppy * pt;
181
182 // Apply centroid translation
183 x = x + m_meanx;
184 px = px + m_meanpx;
185 y = y + m_meany;
186 py = py + m_meanpy;
187 t = t + m_meant;
188 pt = pt + m_meanpt;
189 }
190
191 amrex::ParticleReal m_lambdaX, m_lambdaY, m_lambdaT;
192 amrex::ParticleReal m_lambdaPx, m_lambdaPy, m_lambdaPt;
193 amrex::ParticleReal m_muxpx, m_muypy, m_mutpt;
194 amrex::ParticleReal m_meanx, m_meany, m_meant;
195 amrex::ParticleReal m_meanpx, m_meanpy, m_meanpt;
196 amrex::ParticleReal m_dispx, m_disppx, m_dispy, m_disppy;
197 };
198
199} // namespace impactx::distribution
200
201#endif // IMPACTX_DISTRIBUTION_KURTH4D
#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_lambdaPt
Definition Kurth4D.H:192
amrex::ParticleReal m_disppx
Definition Kurth4D.H:196
amrex::ParticleReal m_meanpx
spatial coordinates of centroid offset
Definition Kurth4D.H:195
amrex::ParticleReal m_meanx
correlation length-momentum
Definition Kurth4D.H:194
amrex::ParticleReal m_meant
Definition Kurth4D.H:194
amrex::ParticleReal m_meanpy
Definition Kurth4D.H:195
amrex::ParticleReal m_meanpt
Definition Kurth4D.H:195
amrex::ParticleReal m_lambdaY
Definition Kurth4D.H:191
amrex::ParticleReal m_dispx
momentum coordinates of centroid offset
Definition Kurth4D.H:196
amrex::ParticleReal m_dispy
Definition Kurth4D.H:196
amrex::ParticleReal m_lambdaPy
Definition Kurth4D.H:192
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 Kurth4D.H:100
amrex::ParticleReal m_meany
Definition Kurth4D.H:194
amrex::ParticleReal m_lambdaT
Definition Kurth4D.H:191
amrex::ParticleReal m_lambdaPx
related position axis intercepts (length) of the phase space ellipse
Definition Kurth4D.H:192
amrex::ParticleReal m_muxpx
related momentum axis intercepts of the phase space ellipse
Definition Kurth4D.H:193
Kurth4D(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 Kurth4D.H:41
amrex::ParticleReal m_mutpt
Definition Kurth4D.H:193
amrex::ParticleReal m_disppy
Definition Kurth4D.H:196
void initialize(amrex::ParticleReal bunch_charge, RefPart const &ref)
Definition Kurth4D.H:76
amrex::ParticleReal m_lambdaX
Definition Kurth4D.H:191
amrex::ParticleReal m_muypy
Definition Kurth4D.H:193
void finalize()
Definition Kurth4D.H:85