ImpactX
Loading...
Searching...
No Matches
Waterbag.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: Ji Qiang, Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_DISTRIBUTION_WATERBAG
11#define IMPACTX_DISTRIBUTION_WATERBAG
12
14
15#include <ablastr/constant.H>
16
17#include <AMReX_Random.H>
18#include <AMReX_REAL.H>
19
20#include <cmath>
21
22
24{
25 struct Waterbag
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 amrex::ParticleReal meanx=0.0,
50 amrex::ParticleReal meany=0.0,
51 amrex::ParticleReal meant=0.0,
52 amrex::ParticleReal meanpx=0.0,
53 amrex::ParticleReal meanpy=0.0,
54 amrex::ParticleReal meanpt=0.0,
55 amrex::ParticleReal dispx=0.0,
56 amrex::ParticleReal disppx=0.0,
57 amrex::ParticleReal dispy=0.0,
58 amrex::ParticleReal disppy=0.0
59 )
60 : m_lambdaX(lambdax), m_lambdaY(lambday), m_lambdaT(lambdat), m_lambdaPx(lambdapx), m_lambdaPy(lambdapy),
61 m_lambdaPt(lambdapt), m_muxpx(muxpx), m_muypy(muypy), m_mutpt(mutpt), m_meanx(meanx), m_meany(meany),
62 m_meant(meant), m_meanpx(meanpx), m_meanpy(meanpy), m_meanpt(meanpt), m_dispx(dispx), m_disppx(disppx),
63 m_dispy(dispy), m_disppy(disppy)
64 {
65 }
66
74 void initialize ([[maybe_unused]] amrex::ParticleReal bunch_charge, [[maybe_unused]] RefPart const & ref)
75 {
76 }
77
82 void
84 {
85 }
86
99 amrex::ParticleReal & AMREX_RESTRICT x,
100 amrex::ParticleReal & AMREX_RESTRICT y,
101 amrex::ParticleReal & AMREX_RESTRICT t,
102 amrex::ParticleReal & AMREX_RESTRICT px,
103 amrex::ParticleReal & AMREX_RESTRICT py,
104 amrex::ParticleReal & AMREX_RESTRICT pt,
105 amrex::RandomEngine const & engine
106 ) const
107 {
108 using namespace amrex::literals;
110
111 amrex::ParticleReal ln1,norm,u1,u2;
112 amrex::ParticleReal g1,g2,g3,g4,g5,g6;
113 amrex::ParticleReal root,a1,a2;
114
115 // Generate six standard normal random variables using Box-Muller:
116 u1 = amrex::Random(engine);
117 u2 = amrex::Random(engine);
118 ln1 = std::sqrt(-2_prt*std::log(u1));
119 g1 = ln1*std::cos(2_prt*pi*u2);
120 g2 = ln1*std::sin(2_prt*pi*u2);
121 u1 = amrex::Random(engine);
122 u2 = amrex::Random(engine);
123 ln1 = std::sqrt(-2_prt*std::log(u1));
124 g3 = ln1*std::cos(2_prt*pi*u2);
125 g4 = ln1*std::sin(2_prt*pi*u2);
126 u1 = amrex::Random(engine);
127 u2 = amrex::Random(engine);
128 ln1 = std::sqrt(-2_prt*std::log(u1));
129 g5 = ln1*std::cos(2_prt*pi*u2);
130 g6 = ln1*std::sin(2_prt*pi*u2);
131
132 // Normalize to produce uniform samples on the unit sphere:
133 norm = std::sqrt(g1*g1+g2*g2+g3*g3+g4*g4+g5*g5+g6*g6);
134 g1 /= norm;
135 g2 /= norm;
136 g3 /= norm;
137 g4 /= norm;
138 g5 /= norm;
139 g6 /= norm;
140
141 // Scale to produce uniform samples in a ball (unit variance):
142 u1 = amrex::Random(engine);
143 u2 = std::sqrt(8_prt)*std::pow(u1,1_prt/6_prt);
144 x = g1*u2;
145 y = g2*u2;
146 t = g3*u2;
147 px = g4*u2;
148 py = g5*u2;
149 pt = g6*u2;
150
151 // Transform to produce the desired second moments/correlations:
152 root = std::sqrt(1.0_prt-m_muxpx*m_muxpx);
153 a1 = m_lambdaX * x / root;
154 a2 = m_lambdaPx * (-m_muxpx * x / root + px);
155 x = a1;
156 px = a2;
157 root = std::sqrt(1.0_prt-m_muypy*m_muypy);
158 a1 = m_lambdaY * y / root;
159 a2 = m_lambdaPy * (-m_muypy * y / root + py);
160 y = a1;
161 py = a2;
162 root = std::sqrt(1.0_prt-m_mutpt*m_mutpt);
163 a1 = m_lambdaT * t / root;
164 a2 = m_lambdaPt * (-m_mutpt * t / root + pt);
165 t = a1;
166 pt = a2;
167
168 // Apply dispersive correlations
169 x = x - m_dispx * pt;
170 px = px - m_disppx * pt;
171 y = y - m_dispy * pt;
172 py = py - m_disppy * pt;
173
174 // Apply centroid translation
175 x = x + m_meanx;
176 px = px + m_meanpx;
177 y = y + m_meany;
178 py = py + m_meanpy;
179 t = t + m_meant;
180 pt = pt + m_meanpt;
181 }
182
183 amrex::ParticleReal m_lambdaX, m_lambdaY, m_lambdaT;
184 amrex::ParticleReal m_lambdaPx, m_lambdaPy, m_lambdaPt;
185 amrex::ParticleReal m_muxpx, m_muypy, m_mutpt;
186 amrex::ParticleReal m_meanx, m_meany, m_meant;
187 amrex::ParticleReal m_meanpx, m_meanpy, m_meanpt;
188 amrex::ParticleReal m_dispx, m_disppx, m_dispy, m_disppy;
189 };
190
191} // namespace impactx::distribution
192
193#endif // IMPACTX_DISTRIBUTION_WATERBAG
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
static constexpr amrex::Real pi
Real Random()
Definition All.H:27
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
Definition ReferenceParticle.H:31
amrex::ParticleReal m_lambdaX
Definition Waterbag.H:183
amrex::ParticleReal m_muypy
Definition Waterbag.H:185
amrex::ParticleReal m_meany
Definition Waterbag.H:186
amrex::ParticleReal m_meanx
correlation length-momentum
Definition Waterbag.H:186
amrex::ParticleReal m_dispx
momentum coordinates of centroid offset
Definition Waterbag.H:188
amrex::ParticleReal m_muxpx
related momentum axis intercepts of the phase space ellipse
Definition Waterbag.H:185
Waterbag(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 Waterbag.H:39
amrex::ParticleReal m_mutpt
Definition Waterbag.H:185
amrex::ParticleReal m_dispy
Definition Waterbag.H:188
void finalize()
Definition Waterbag.H:83
void initialize(amrex::ParticleReal bunch_charge, RefPart const &ref)
Definition Waterbag.H:74
amrex::ParticleReal m_meant
Definition Waterbag.H:186
amrex::ParticleReal m_meanpt
Definition Waterbag.H:187
amrex::ParticleReal m_disppy
Definition Waterbag.H:188
amrex::ParticleReal m_lambdaPt
Definition Waterbag.H:184
amrex::ParticleReal m_lambdaT
Definition Waterbag.H:183
amrex::ParticleReal m_lambdaPx
related position axis intercepts (length) of the phase space ellipse
Definition Waterbag.H:184
amrex::ParticleReal m_lambdaPy
Definition Waterbag.H:184
amrex::ParticleReal m_lambdaY
Definition Waterbag.H:183
amrex::ParticleReal m_meanpx
spatial coordinates of centroid offset
Definition Waterbag.H:187
amrex::ParticleReal m_meanpy
Definition Waterbag.H:187
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 Waterbag.H:98
amrex::ParticleReal m_disppx
Definition Waterbag.H:188