10#ifndef IMPACTX_EXACTCFBEND_H
11#define IMPACTX_EXACTCFBEND_H
59 static constexpr auto type =
"ExactCFbend";
91 std::vector<amrex::ParticleReal> k_normal,
92 std::vector<amrex::ParticleReal> k_skew,
102 std::optional<std::string>
name = std::nullopt
112 throw std::runtime_error(
"ExactCFbend: The order used for symplectic integration must be 2, 4 or 6.");
114 m_ncoef = int(k_normal.size());
115 if (
m_ncoef !=
int(k_skew.size()))
116 throw std::runtime_error(
"ExactCFbend: normal and skew coefficient arrays must have same length!");
131 using BeamOptic::operator();
144 Alignment::compute_constants(refpart);
161 m_rc = curvature == 0.0 ? 0.0_prt : 1.0_prt/curvature;
273 xout = x + tau * px * inv_pzden;
274 yout = y + tau * py * inv_pzden;
300 pxout = px * cos_phi + (pzi - rho /
m_rc) * sin_phi;
310 amrex::ParticleReal const theta = slice_phi + std::asin(px/pperp) - std::asin(pxout/pperp);
313 xout = -
m_rc + rho*cos_phi +
m_rc*(pzf + px*sin_phi - pzi*cos_phi);
314 yout = y + theta *
m_rc * py;
376 for (
int m = 1; m <
m_ncoef; m++) {
387 kn = std::pow(
m_rc, m) * kn;
388 ks = std::pow(
m_rc, m) * ks;
397 dpx += -rho*ln_rho*kn + y_scl*rho*ks;
398 dpy += y_scl*kn + 0.5_prt*(rho*rho - 1_prt)*ks;
401 dpx += 0.25_prt*rho*(1_prt + 2_prt*y_scl*y_scl - rho*rho + 2_prt*ln_rho)*kn + y_scl*rho*ln_rho*ks;
402 dpy += 0.5_prt*y_scl*(rho*rho - 1_prt)*kn + 0.25_prt*(1_prt - 2_prt*y_scl*y_scl - rho*rho + 2_prt*rho*rho*ln_rho)*ks;
405 dpx += -0.25_prt*(rho -
powi<3>(rho) + (rho - 2_prt*y_scl*y_scl*rho +
powi<3>(rho))*ln_rho)*kn
406 -1_prt/12_prt*y_scl*rho*(3_prt + 2_prt*y_scl*y_scl - 3_prt*rho*rho + 6_prt*ln_rho)*ks;
407 dpy += -1_prt/12_prt*y_scl*(-3_prt + 2_prt*y_scl*y_scl + 3_prt*rho*rho - 6_prt*rho*rho*ln_rho)*kn
408 -1_prt/16_prt*((-1_prt + 4_prt*y_scl*y_scl - rho*rho)*(-1_prt + rho*rho) + 4_prt*rho*rho*ln_rho)*ks;
412 dpx += -1_prt/192_prt*rho*(8_prt*
powi<4>(y_scl) - 24_prt*
powi<2>(y_scl)*(-1_prt + rho*rho)
414 +12_prt*(-1_prt + 4_prt*y_scl*y_scl - 2_prt*rho*rho)*ln_rho)*kn
415 +1_prt/12_prt*y_scl*rho*(3_prt*(-1_prt + rho*rho) + (2_prt*y_scl*y_scl - 3_prt*(1_prt + rho*rho))*ln_rho)*ks;
416 dpy += -1_prt/48_prt*y_scl*((-1_prt + rho*rho)*(4_prt*y_scl*y_scl - 3_prt*(1_prt + rho*rho)) + 12_prt*rho*rho*ln_rho)*kn
417 + 1_prt/192_prt*(3_prt + 8_prt*
powi<4>(y_scl) + 12_prt*rho*rho
418 - 15_prt*
powi<4>(rho) + 24_prt*y_scl*y_scl*(-1_prt + rho*rho)
419 +12_prt*rho*rho*(2_prt - 4_prt*y_scl*y_scl + rho*rho)*ln_rho)*ks;
428 pxout = pxout + tau * dpx;
429 pyout = pyout + tau * dpy;
464#if AMREX_DEVICE_COMPILE
480 refpart.x = x + step*px;
481 refpart.y = y + step*py;
482 refpart.z = z + step*pz;
483 refpart.t =
t - step*pt;
495 refpart.px = px*cos_theta - pz*sin_theta;
497 refpart.pz = pz*cos_theta + px*sin_theta;
500 refpart.x = x + (refpart.pz - pz)/B;
501 refpart.y = y + (theta/B)*py;
502 refpart.z = z - (refpart.px - px)/B;
503 refpart.t =
t - (theta/B)*pt;
508 refpart.s =
s + slice_ds;
562 R(1,1) = gx > 0_prt ? cosx : coshx;
563 R(1,2) = gx > 0_prt ? sinx / omega_x : sinhx / omega_x;
564 R(1,6) = gx > 0_prt ? -(1_prt - cosx) * igbrc : -(1_prt - coshx) * igbrc;
565 R(2,1) = gx > 0_prt ? -omega_x * sinx : omega_x * sinhx;
566 R(2,2) = gx > 0_prt ? cosx : coshx;
567 R(2,6) = gx > 0_prt ? -sinx * iobrc : -sinhx * iobrc;
568 R(3,3) = gy > 0_prt ? cosy : coshy;
569 R(3,4) = gy > 0_prt ? siny / omega_y : sinhy / omega_y;
570 R(4,3) = gy > 0_prt ? -omega_y * siny : omega_y * sinhy;
571 R(4,4) = gy > 0_prt ? cosy : coshy;
572 R(5,1) = gx > 0_prt ? sinx * iobrc : sinhx * iobrc;
573 R(5,2) = gx > 0_prt ? (1_prt - cosx) * igbrc : (1_prt - coshx) * igbrc;
574 R(5,6) = gx > 0_prt ?
575 slice_ds * ibetgam2 + (sinx - omega_x * slice_ds) * igobr :
576 slice_ds * ibetgam2 + (sinhx - omega_x * slice_ds) * igobr;
582 using LinearTransport::operator();
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
#define IMPACTX_PUSH_EXTERN_TEMPLATE(ElementType)
Definition PushAll.H:78
T_ParticleType ParticleType
#define IMPACTX_GPUDATA_EXTERN(ElementType)
Definition dynamicdata.H:169
amrex_particle_real ParticleReal
__host__ __device__ std::pair< double, double > sincos(double x)
constexpr T powi(T x) noexcept
SmallMatrix< T, N, 1, Order::F, StartIndex > SmallVector
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp4_integrate_particle(amrex::SmallVector< T_Real, 6, 1 > &particle, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, T_Element const &element)
Definition Integrators.H:225
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp6_integrate_particle(amrex::SmallVector< T_Real, 6, 1 > &particle, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, T_Element const &element)
Definition Integrators.H:284
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp2_integrate_particle(amrex::SmallVector< T_Real, 6, 1 > &particle, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, T_Element const &element)
Definition Integrators.H:178
@ 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:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition ReferenceParticle.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition ReferenceParticle.H:261
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:152
Definition ExactCFbend.H:45
mixin::TrackedVector< amrex::ParticleReal > k_normal
Definition ExactCFbend.H:46
mixin::TrackedVector< amrex::ParticleReal > k_skew
Definition ExactCFbend.H:47
Definition ExactCFbend.H:58
ImpactXParticleContainer::ParticleType PType
Definition ExactCFbend.H:60
int m_int_order
unit specification for Multipole strength
Definition ExactCFbend.H:586
amrex::ParticleReal m_ibeta
beta
Definition ExactCFbend.H:602
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map1(amrex::ParticleReal const tau, amrex::SmallVector< amrex::ParticleReal, 6, 1 > &particle, amrex::ParticleReal &zeval) const
Definition ExactCFbend.H:241
amrex::ParticleReal const * m_k_skew_d_data
non-owning pointer to device normal coefficients
Definition ExactCFbend.H:594
int m_id
number of integration steps per slice
Definition ExactCFbend.H:588
amrex::ParticleReal const * m_k_skew_h_data
non-owning pointer to host normal coefficients
Definition ExactCFbend.H:592
amrex::ParticleReal m_rc
magnetic ridigity in T-m
Definition ExactCFbend.H:604
int m_mapsteps
order used for the symplectic integration (2 or 4)
Definition ExactCFbend.H:587
mixin::GPUDataRegistry< CFbendCoefficients > DynamicData
Definition ExactCFbend.H:62
amrex::ParticleReal m_beta
1 / m_betgam2
Definition ExactCFbend.H:601
amrex::ParticleReal m_slice_ds
non-owning pointer to device skew coefficients
Definition ExactCFbend.H:599
int m_ncoef
unique ExactMultipole id used for data lookup map
Definition ExactCFbend.H:590
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map2(amrex::ParticleReal const tau, amrex::SmallVector< amrex::ParticleReal, 6, 1 > &particle, amrex::ParticleReal &zeval) const
Definition ExactCFbend.H:342
amrex::ParticleReal m_ibetgam2
m_ds / nslice();
Definition ExactCFbend.H:600
void compute_constants(RefPart const &refpart)
Definition ExactCFbend.H:140
amrex::ParticleReal const * m_k_normal_d_data
non-owning pointer to host skew coefficients
Definition ExactCFbend.H:593
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:519
amrex::ParticleReal m_brho
1 / m_beta
Definition ExactCFbend.H:603
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, uint64_t &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:182
amrex::ParticleReal const * m_k_normal_h_data
number of Fourier coefficients
Definition ExactCFbend.H:591
ExactCFbend(amrex::ParticleReal ds, std::vector< amrex::ParticleReal > k_normal, std::vector< amrex::ParticleReal > k_skew, int unit, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, amrex::ParticleReal aperture_x=0, amrex::ParticleReal aperture_y=0, int int_order=2, int mapsteps=1, int nslice=1, std::optional< std::string > name=std::nullopt)
Definition ExactCFbend.H:89
void reverse()
Definition ExactCFbend.H:128
int m_unit
Definition ExactCFbend.H:585
static constexpr auto type
Definition ExactCFbend.H:59
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:436
Definition dynamicdata.H:54
static std::shared_ptr< CFbendCoefficients > const & get(int id)
Definition dynamicdata.H:98
static CFbendCoefficients & emplace(int id, Args &&... args)
Definition dynamicdata.H:125
Definition lineartransport.H:50
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 nofinalize.H:22
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:68
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
Definition TrackedVector.H:49