10#ifndef IMPACTX_RFCAVITY_H
11#define IMPACTX_RFCAVITY_H
53 4.3443060026047219e-002,
54 8.5602654094946495e-002,
58 -5.2579522442877296e-003,
59 -5.5025369142193678e-002,
60 4.6845673335028933e-002,
61 -2.3279346335638568e-002,
62 4.0800777539657775e-003,
63 4.1378326533752169e-003,
64 -2.5040533340490805e-003,
65 -4.0654981400000964e-003,
66 9.6630592067498289e-003,
67 -8.5275895985990214e-003,
68 -5.8078747006425020e-002,
69 -2.4044337836660403e-002,
70 1.0968240064697212e-002,
71 -3.4461179858301418e-003,
72 -8.1201564869443749e-004,
73 2.1438992904959380e-003,
74 -1.4997753525697276e-003,
75 1.8685171825676386e-004
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 inline std::map<int, std::vector<amrex::ParticleReal>>
h_cos_coef = {};
99 inline std::map<int, std::vector<amrex::ParticleReal>>
h_sin_coef = {};
102 inline std::map<int, amrex::Gpu::DeviceVector<amrex::ParticleReal>>
d_cos_coef = {};
104 inline std::map<int, amrex::Gpu::DeviceVector<amrex::ParticleReal>>
d_sin_coef = {};
117 static constexpr auto type =
"RFCavity";
139 amrex::ParticleReal
ds,
140 amrex::ParticleReal escale,
141 amrex::ParticleReal freq,
142 amrex::ParticleReal phase,
143 std::vector<amrex::ParticleReal> cos_coef,
144 std::vector<amrex::ParticleReal> sin_coef,
145 amrex::ParticleReal
dx = 0,
146 amrex::ParticleReal
dy = 0,
147 amrex::ParticleReal rotation_degree = 0,
152 std::optional<std::string>
name = std::nullopt
164 m_ncoef = int(cos_coef.size());
165 if (
m_ncoef !=
int(sin_coef.size()))
166 throw std::runtime_error(
"RFCavity: cos and sin coefficients must have same length!");
178 cos_coef.begin(), cos_coef.end(),
181 sin_coef.begin(), sin_coef.end(),
191 using BeamOptic::operator();
202 using namespace amrex::literals;
204 Alignment::compute_constants(refpart);
221 template<
typename T_Real=amrex::ParticleReal,
typename T_IdCpu=u
int64_t>
234 using namespace amrex::literals;
250 auto const out = R *
v;
274 using namespace amrex::literals;
278 amrex::ParticleReal
const x = refpart.x;
279 amrex::ParticleReal
const px = refpart.px;
280 amrex::ParticleReal
const y = refpart.y;
281 amrex::ParticleReal
const py = refpart.py;
282 amrex::ParticleReal
const z = refpart.z;
283 amrex::ParticleReal
const pz = refpart.pz;
284 amrex::ParticleReal
const pt = refpart.pt;
285 amrex::ParticleReal
const s = refpart.s;
286 amrex::ParticleReal
const sedge = refpart.sedge;
289 refpart.map =
decltype(refpart.map)::Identity();
292 amrex::ParticleReal
const slice_ds =
m_ds /
nslice();
295 amrex::ParticleReal
const bgi = std::sqrt(powi<2>(pt) - 1.0_prt);
298 amrex::ParticleReal
const zin =
s - sedge;
299 amrex::ParticleReal
const zout = zin + slice_ds;
303 amrex::ParticleReal
const ptf = refpart.pt;
306 refpart.x = x + slice_ds*px/bgi;
307 refpart.y = y + slice_ds*py/bgi;
308 refpart.z = z + slice_ds*pz/bgi;
311 amrex::ParticleReal
const bgf = std::sqrt(powi<2>(ptf) - 1.0_prt);
314 refpart.px = px*bgf/bgi;
315 refpart.py = py*bgf/bgi;
316 refpart.pz = pz*bgf/bgi;
319 amrex::ParticleReal scale_in = 1.0_prt;
320 amrex::ParticleReal scale_fin = 1.0_prt;
322 for (
int i=1; i<7; i++) {
323 for (
int j=1; j<7; j++) {
332 refpart.map(i, j) = refpart.map(i, j) * scale_in / scale_fin;
337 refpart.s =
s + slice_ds;
341 using LinearTransport::operator();
364 std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal>
368 using namespace amrex::literals;
373#if AMREX_DEVICE_COMPILE
383 amrex::ParticleReal
const zlen =
m_ds;
384 amrex::ParticleReal
const zmid = zlen * 0.5_prt;
387 amrex::ParticleReal efield = 0.0;
388 amrex::ParticleReal efieldp = 0.0;
389 amrex::ParticleReal efieldpp = 0.0;
390 amrex::ParticleReal efieldint = 0.0;
391 amrex::ParticleReal
const z = zeval - zmid;
393 if (std::abs(z) <= zmid)
395 efield = 0.5_prt*cos_data[0];
396 efieldint = z*efield;
397 for (
int j=1; j <
m_ncoef; ++j)
399 efield = efield + cos_data[j] * std::cos(j*2*pi*z/zlen) +
400 sin_data[j] * std::sin(j*2*pi*z/zlen);
401 efieldp = efieldp-j*2*pi*cos_data[j] * std::sin(j*2*pi*z/zlen)/zlen +
402 j*2*pi*sin_data[j] * std::cos(j*2*pi*z/zlen)/zlen;
403 efieldpp = efieldpp- powi<2>(j*2*pi*cos_data[j]/zlen) * std::cos(j*2*pi*z/zlen) -
404 powi<2>(j*2*pi*sin_data[j]/zlen) * std::sin(j*2*pi*z/zlen);
405 efieldint = efieldint + zlen*cos_data[j] * std::sin(j*2*pi*z/zlen)/(j*2*pi) -
406 zlen*sin_data[j] * std::cos(j*2*pi*z/zlen)/(j*2*pi);
411 efieldint = std::copysign(z, z)*zmid*0.5_prt*cos_data[0];;
412 for (
int j=1; j <
m_ncoef; ++j)
414 efieldint = efieldint - zlen*sin_data[j] * std::cos(j*pi)/(j*2*pi);
417 return std::make_tuple(efield, efieldp, efieldint);
429 void map3 (amrex::ParticleReal
const tau,
431 [[maybe_unused]] amrex::ParticleReal & zeval)
const
433 using namespace amrex::literals;
437 amrex::ParticleReal
const t = refpart.
t;
438 amrex::ParticleReal
const pt = refpart.
pt;
441 refpart.
t =
t + tau/std::sqrt(1.0_prt - powi<-2>(pt));
451 amrex::ParticleReal
const betgam = refpart.
beta_gamma();
453 refpart.
map(5,5) = R(5,5) + tau*R(6,5)/powi<3>(betgam);
454 refpart.
map(5,6) = R(5,6) + tau*R(6,6)/powi<3>(betgam);
466 void map2 (amrex::ParticleReal
const tau,
468 amrex::ParticleReal & zeval)
const
470 using namespace amrex::literals;
473 amrex::ParticleReal
const t = refpart.
t;
474 amrex::ParticleReal
const pt = refpart.
pt;
479 amrex::ParticleReal
const k = (2_prt*pi/c)*
m_freq;
480 amrex::ParticleReal
const phi =
m_phase*(pi/180_prt);
481 amrex::ParticleReal
const E0 =
m_escale;
484 auto [ez, ezp, ezint] =
RF_Efield(zeval);
492 amrex::ParticleReal
const s = tau/refpart.
beta_gamma();
493 amrex::ParticleReal
const L = E0*ezp * std::sin(k*
t+phi)/(2_prt*k);
495 refpart.
map(1,1) = (1_prt-
s*L)*R(1,1) +
s*R(2,1);
496 refpart.
map(1,2) = (1_prt-
s*L)*R(1,2) +
s*R(2,2);
497 refpart.
map(2,1) = -
s * powi<2>(L)*R(1,1) + (1_prt+
s*L)*R(2,1);
498 refpart.
map(2,2) = -
s * powi<2>(L)*R(1,2) + (1_prt+
s*L)*R(2,2);
500 refpart.
map(3,3) = (1_prt-
s*L)*R(3,3) +
s*R(4,3);
501 refpart.
map(3,4) = (1_prt-
s*L)*R(3,4) +
s*R(4,4);
502 refpart.
map(4,3) = -
s * powi<2>(L)*R(3,3) + (1_prt+
s*L)*R(4,3);
503 refpart.
map(4,4) = -
s * powi<2>(L)*R(3,4) + (1_prt+
s*L)*R(4,4);
515 void map1 (amrex::ParticleReal
const tau,
517 amrex::ParticleReal & zeval)
const
519 using namespace amrex::literals;
521 amrex::ParticleReal
const t = refpart.
t;
522 amrex::ParticleReal
const pt = refpart.
pt;
523 amrex::ParticleReal
const z = zeval;
528 amrex::ParticleReal
const k = (2_prt*pi/c)*
m_freq;
529 amrex::ParticleReal
const phi =
m_phase*(pi/180_prt);
530 amrex::ParticleReal
const E0 =
m_escale;
536 auto [ezf, ezpf, ezintf] =
RF_Efield(zeval);
540 refpart.
pt = pt - E0*(ezintf-ezint) * std::cos(k*
t+phi);
544 amrex::ParticleReal
const M = E0*(ezintf-ezint)*k * std::sin(k*
t+phi);
545 amrex::ParticleReal
const L = E0*(ezpf-ezp) * std::sin(k*
t+phi)/(2_prt*k)+M*0.5_prt;
547 refpart.
map(2,1) = L*R(1,1) + R(2,1);
548 refpart.
map(2,2) = L*R(1,2) + R(2,2);
550 refpart.
map(4,3) = L*R(3,3) + R(4,3);
551 refpart.
map(4,4) = L*R(3,4) + R(4,4);
553 refpart.
map(6,5) = M*R(5,5) + R(6,5);
554 refpart.
map(6,6) = M*R(5,6) + R(6,6);
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
T_ParticleType ParticleType
static constexpr amrex::Real pi
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
static constexpr HostToDevice hostToDevice
void streamSynchronize() noexcept
PODVector< T, ArenaAllocator< T > > DeviceVector
constexpr T powi(T x) noexcept
__host__ __device__ void ignore_unused(const Ts &...)
SmallMatrix< T, N, 1, Order::F, StartIndex > SmallVector
std::map< int, amrex::Gpu::DeviceVector< amrex::ParticleReal > > d_cos_coef
device: cosine coefficients in Fourier expansion of on-axis electric field Ez
Definition RFCavity.H:102
std::map< int, amrex::Gpu::DeviceVector< amrex::ParticleReal > > d_sin_coef
device: sine coefficients in Fourier expansion of on-axis electric field Ez
Definition RFCavity.H:104
std::map< int, std::vector< amrex::ParticleReal > > h_cos_coef
host: cosine coefficients in Fourier expansion of on-axis electric field Ez
Definition RFCavity.H:97
int next_id
last used id for a created RF cavity
Definition RFCavity.H:94
std::map< int, std::vector< amrex::ParticleReal > > h_sin_coef
host: sine coefficients in Fourier expansion of on-axis electric field Ez
Definition RFCavity.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp2_integrate_split3(RefPart &refpart, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, T_Element const &element)
Definition Integrators.H:79
@ s
fixed s as the independent variable
Definition ImpactXParticleContainer.H:37
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > Map6x6
Definition CovarianceMatrix.H:20
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity() noexcept
Definition ReferenceParticle.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition ReferenceParticle.H:110
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:40
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > map
linearized map
Definition ReferenceParticle.H:45
amrex::ParticleReal t
clock time * c in meters
Definition ReferenceParticle.H:36
amrex::Vector< amrex::ParticleReal > default_sin_coef
Definition RFCavity.H:78
amrex::Vector< amrex::ParticleReal > default_cos_coef
Definition RFCavity.H:50
amrex::ParticleReal * m_cos_d_data
non-owning pointer to host sine coefficients
Definition RFCavity.H:583
void compute_constants(RefPart const &refpart)
Definition RFCavity.H:200
std::tuple< amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RF_Efield(amrex::ParticleReal const zeval) const
Definition RFCavity.H:366
int m_ncoef
unique RF cavity id used for data lookup map
Definition RFCavity.H:580
static constexpr auto type
Definition RFCavity.H:117
RFCavity(amrex::ParticleReal ds, amrex::ParticleReal escale, amrex::ParticleReal freq, amrex::ParticleReal phase, std::vector< amrex::ParticleReal > cos_coef, std::vector< amrex::ParticleReal > sin_coef, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, amrex::ParticleReal aperture_x=0, amrex::ParticleReal aperture_y=0, int mapsteps=1, int nslice=1, std::optional< std::string > name=std::nullopt)
Definition RFCavity.H:138
int m_id
number of map integration steps per slice
Definition RFCavity.H:578
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map1(amrex::ParticleReal const tau, RefPart &refpart, amrex::ParticleReal &zeval) const
Definition RFCavity.H:515
amrex::ParticleReal m_escale
Definition RFCavity.H:574
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map3(amrex::ParticleReal const tau, RefPart &refpart, amrex::ParticleReal &zeval) const
Definition RFCavity.H:429
amrex::ParticleReal m_freq
scaling factor for RF electric field
Definition RFCavity.H:575
amrex::ParticleReal * m_sin_h_data
non-owning pointer to host cosine coefficients
Definition RFCavity.H:582
int m_mapsteps
RF driven phase in deg.
Definition RFCavity.H:577
amrex::ParticleReal * m_cos_h_data
number of Fourier coefficients
Definition RFCavity.H:581
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map2(amrex::ParticleReal const tau, RefPart &refpart, amrex::ParticleReal &zeval) const
Definition RFCavity.H:466
void finalize()
Definition RFCavity.H:560
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition RFCavity.H:349
amrex::ParticleReal * m_sin_d_data
non-owning pointer to device cosine coefficients
Definition RFCavity.H:584
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition RFCavity.H:223
ImpactXParticleContainer::ParticleType PType
Definition RFCavity.H:118
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition RFCavity.H:576
Definition alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py) const
Definition alignment.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:146
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:136
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py) const
Definition alignment.H:78
Definition beamoptic.H:219
Definition lineartransport.H:29
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:57
AMREX_FORCE_INLINE std::string name() const
Definition named.H:122
Definition pipeaperture.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void apply_aperture(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_IdCpu &AMREX_RESTRICT idcpu) const
Definition pipeaperture.H:59
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:101
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:32
Thick(amrex::ParticleReal ds, int nslice)
Definition thick.H:30
amrex::ParticleReal m_ds
Definition thick.H:58
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thick.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition thick.H:43