10#ifndef IMPACTX_EXACTCFBEND_H
11#define IMPACTX_EXACTCFBEND_H
61 static constexpr auto type =
"ExactCFbend";
97 std::vector<amrex::ParticleReal> k_normal,
98 std::vector<amrex::ParticleReal> k_skew,
118 throw std::runtime_error(
"ExactCFbend: The order used for symplectic integration must be 2, 4 or 6.");
120 m_ncoef = int(k_normal.size());
121 if (
m_ncoef !=
int(k_skew.size()))
122 throw std::runtime_error(
"ExactCFbend: normal and skew coefficient arrays must have same length!");
137 using BeamOptic::operator();
150 Alignment::compute_constants(refpart);
167 m_rc = curvature == 0.0 ? 0.0_prt : 1.0_prt/curvature;
271 xout = x + tau * px * inv_pzden;
272 yout = y + tau * py * inv_pzden;
298 pxout = px * cos_phi + (pzi - rho /
m_rc) * sin_phi;
308 amrex::ParticleReal const theta = slice_phi + std::asin(px/pperp) - std::asin(pxout/pperp);
311 xout = -
m_rc + rho*cos_phi +
m_rc*(pzf + px*sin_phi - pzi*cos_phi);
312 yout = y + theta *
m_rc * py;
376 for (
int m = 1; m <
m_ncoef; m++) {
395 dpx += -rho*ln_rho*kn + y_scl*rho*ks;
396 dpy += y_scl*kn + 0.5_prt*(rho*rho - 1_prt)*ks;
399 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;
400 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;
403 dpx += -0.25_prt*(rho -
powi<3>(rho) + (rho - 2_prt*y_scl*y_scl*rho +
powi<3>(rho))*ln_rho)*kn
404 -1_prt/12_prt*y_scl*rho*(3_prt + 2_prt*y_scl*y_scl - 3_prt*rho*rho + 6_prt*ln_rho)*ks;
405 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
406 -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;
409 dpx += -1_prt/192_prt*rho*(8_prt*
powi<4>(y_scl) - 24_prt*
powi<2>(y_scl)*(-1_prt + rho*rho)
411 +12_prt*(-1_prt + 4_prt*y_scl*y_scl - 2_prt*rho*rho)*ln_rho)*kn
412 +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;
413 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
414 + 1_prt/192_prt*(3_prt + 8_prt*
powi<4>(y_scl) + 12_prt*rho*rho
415 - 15_prt*
powi<4>(rho) + 24_prt*y_scl*y_scl*(-1_prt + rho*rho)
416 +12_prt*rho*rho*(2_prt - 4_prt*y_scl*y_scl + rho*rho)*ln_rho)*ks;
425 pxout = pxout + tau * dpx;
426 pyout = pyout + tau * dpy;
448 template<
typename T_Real>
465 T_Real lambdax = 0_prt;
466 T_Real lambday = 0_prt;
467 T_Real lambdaz = 0_prt;
469 T_Real
const x = particle(1);
470 T_Real
const px = particle(2);
471 T_Real
const y = particle(3);
472 T_Real
const py = particle(4);
474 T_Real
const pt = particle(6);
475 T_Real sx = particle_spin(1);
476 T_Real sy = particle_spin(2);
477 T_Real sz = particle_spin(3);
479#if AMREX_DEVICE_COMPILE
499 for (
int m = 0; m <
m_ncoef; m++) {
520 Bx += y_scl*kn + 0.5_prt*(rho*rho - 1_prt)*ks;
521 By += -(-rho*ln_rho*kn + y_scl*rho*ks);
524 Bx += 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;
525 By += -(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);
528 Bx += -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
529 -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;
530 By += -(-0.25_prt*(rho -
powi<3>(rho) + (rho - 2_prt*y_scl*y_scl*rho +
powi<3>(rho))*ln_rho)*kn
531 -1_prt/12_prt*y_scl*rho*(3_prt + 2_prt*y_scl*y_scl - 3_prt*rho*rho + 6_prt*ln_rho)*ks);
534 Bx += -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
535 + 1_prt/192_prt*(3_prt + 8_prt*
powi<4>(y_scl) + 12_prt*rho*rho
536 - 15_prt*
powi<4>(rho) + 24_prt*y_scl*y_scl*(-1_prt + rho*rho)
537 +12_prt*rho*rho*(2_prt - 4_prt*y_scl*y_scl + rho*rho)*ln_rho)*ks;
538 By += -(-1_prt/192_prt*rho*(8_prt*
powi<4>(y_scl) - 24_prt*
powi<2>(y_scl)*(-1_prt + rho*rho)
540 +12_prt*(-1_prt + 4_prt*y_scl*y_scl - 2_prt*rho*rho)*ln_rho)*kn
541 +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);
549 Bx = Bx *
m_beta * gamma_ref / rho;
550 By = By *
m_beta * gamma_ref / rho;
553 T_Real
const Ex = 0.0_prt;
554 T_Real
const Ey = 0.0_prt;
555 T_Real
const Ez = 0.0_prt;
558 T_Real
const Pnorm =
sqrt(1_prt - 2_prt * pt *
m_ibeta + pt*pt);
559 T_Real
const iPnorm = 1_prt/Pnorm;
560 T_Real
const Ps =
sqrt(Pnorm*Pnorm - px*px - py*py);
561 T_Real
const gamma = gamma_ref * (1_prt - pt*
m_beta);
562 T_Real
const ux = px * iPnorm;
563 T_Real
const uy = py * iPnorm;
564 T_Real
const uz = Ps * iPnorm;
570 tbmt_precession_vector(x,ux,uy,uz,gamma,h,gyro_anomaly,Bx,By,Bz,Ex,Ey,Ez,lambdax,lambday,lambdaz);
581 particle_spin(1) = sx;
582 particle_spin(2) = sy;
583 particle_spin(3) = sz;
611#if AMREX_DEVICE_COMPILE
627 refpart.x = x + step*px;
628 refpart.y = y + step*py;
629 refpart.z = z + step*pz;
630 refpart.t =
t - step*pt;
642 refpart.px = px*cos_theta - pz*sin_theta;
644 refpart.pz = pz*cos_theta + px*sin_theta;
647 refpart.x = x + (refpart.pz - pz)/B;
648 refpart.y = y + (theta/B)*py;
649 refpart.z = z - (refpart.px - px)/B;
650 refpart.t =
t - (theta/B)*pt;
655 refpart.s =
s + slice_ds;
707 R(1,1) = gx > 0_prt ? cosx : coshx;
708 R(1,2) = gx > 0_prt ? sinx / omega_x : sinhx / omega_x;
709 R(1,6) = gx > 0_prt ? -(1_prt - cosx) * igbrc : -(1_prt - coshx) * igbrc;
710 R(2,1) = gx > 0_prt ? -omega_x * sinx : omega_x * sinhx;
711 R(2,2) = gx > 0_prt ? cosx : coshx;
712 R(2,6) = gx > 0_prt ? -sinx * iobrc : -sinhx * iobrc;
713 R(3,3) = gy > 0_prt ? cosy : coshy;
714 R(3,4) = gy > 0_prt ? siny / omega_y : sinhy / omega_y;
715 R(4,3) = gy > 0_prt ? -omega_y * siny : omega_y * sinhy;
716 R(4,4) = gy > 0_prt ? cosy : coshy;
717 R(5,1) = gx > 0_prt ? sinx * iobrc : sinhx * iobrc;
718 R(5,2) = gx > 0_prt ? (1_prt - cosx) * igbrc : (1_prt - coshx) * igbrc;
719 R(5,6) = gx > 0_prt ?
720 slice_ds * ibetgam2 + (sinx - omega_x * slice_ds) * igobr :
721 slice_ds * ibetgam2 + (sinhx - omega_x * slice_ds) * igobr;
742 template<
typename T_Real=amrex::ParticleReal,
typename T_IdCpu=u
int64_t>
785 sx = particle_spin(1);
786 sy = particle_spin(2);
787 sz = particle_spin(3);
792 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
constexpr T powi(T x) noexcept
__host__ __device__ std::pair< double, double > sincos(double x)
SmallMatrix< T, N, 1, Order::F, StartIndex > SmallVector
__host__ __device__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
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, RefPart const &refpart, T_Element const &element)
Definition Integrators.H:182
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, RefPart const &refpart, T_Element const &element)
Definition Integrators.H:231
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp_integrate_particle_spin(amrex::SmallVector< T_Real, 6, 1 > &particle, amrex::SmallVector< T_Real, 3, 1 > &particle_spin, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, int int_order, RefPart const &refpart, T_Element const &element)
Definition Integrators.H:493
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, RefPart const &refpart, T_Element const &element)
Definition Integrators.H:292
@ 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:167
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition ReferenceParticle.H:260
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:151
Definition ExactCFbend.H:46
amrex::Gpu::TrackedVector< amrex::ParticleReal > k_skew
Definition ExactCFbend.H:48
amrex::Gpu::TrackedVector< amrex::ParticleReal > k_normal
Definition ExactCFbend.H:47
Definition ExactCFbend.H:60
ImpactXParticleContainer::ParticleType PType
Definition ExactCFbend.H:62
int m_int_order
unit specification for Multipole strength
Definition ExactCFbend.H:795
amrex::ParticleReal m_ibeta
beta
Definition ExactCFbend.H:811
static constexpr int DEFAULT_mapsteps
Definition ExactCFbend.H:68
amrex::ParticleReal const * m_k_skew_d_data
non-owning pointer to device normal coefficients
Definition ExactCFbend.H:803
int m_id
number of integration steps per slice
Definition ExactCFbend.H:797
amrex::ParticleReal const * m_k_skew_h_data
non-owning pointer to host normal coefficients
Definition ExactCFbend.H:801
amrex::ParticleReal m_rc
magnetic ridigity in T-m
Definition ExactCFbend.H:813
int m_mapsteps
order used for the symplectic integration (2 or 4)
Definition ExactCFbend.H:796
ExactCFbend(amrex::ParticleReal ds, std::vector< amrex::ParticleReal > k_normal, std::vector< amrex::ParticleReal > k_skew, int unit=DEFAULT_unit, amrex::ParticleReal dx=DEFAULT_dx, amrex::ParticleReal dy=DEFAULT_dy, amrex::ParticleReal rotation_degree=DEFAULT_rotation_degree, amrex::ParticleReal aperture_x=DEFAULT_aperture_x, amrex::ParticleReal aperture_y=DEFAULT_aperture_y, int int_order=DEFAULT_int_order, int mapsteps=DEFAULT_mapsteps, int nslice=DEFAULT_nslice, std::optional< std::string > name=DEFAULT_name)
Definition ExactCFbend.H:95
mixin::GPUDataRegistry< CFbendCoefficients > DynamicData
Definition ExactCFbend.H:64
amrex::ParticleReal m_beta
1 / m_betgam2
Definition ExactCFbend.H:810
amrex::ParticleReal m_slice_ds
non-owning pointer to device skew coefficients
Definition ExactCFbend.H:808
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void spin_and_phasespace_push(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_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy, T_Real &AMREX_RESTRICT sz, T_IdCpu const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:744
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map3(amrex::ParticleReal const tau, amrex::SmallVector< T_Real, 6, 1 > &particle, amrex::SmallVector< T_Real, 3, 1 > &particle_spin, amrex::ParticleReal &zeval, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:450
int m_ncoef
unique ExactMultipole id used for data lookup map
Definition ExactCFbend.H:799
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map2(amrex::ParticleReal const tau, amrex::SmallVector< amrex::ParticleReal, 6, 1 > &particle, amrex::ParticleReal &zeval, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:341
static constexpr int DEFAULT_unit
Definition ExactCFbend.H:66
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 const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:187
amrex::ParticleReal m_ibetgam2
m_ds / nslice();
Definition ExactCFbend.H:809
void compute_constants(RefPart const &refpart)
Definition ExactCFbend.H:146
amrex::ParticleReal const * m_k_normal_d_data
non-owning pointer to host skew coefficients
Definition ExactCFbend.H:802
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:664
amrex::ParticleReal m_brho
1 / m_beta
Definition ExactCFbend.H:812
static constexpr int DEFAULT_int_order
Definition ExactCFbend.H:67
amrex::ParticleReal const * m_k_normal_h_data
number of Fourier coefficients
Definition ExactCFbend.H:800
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map1(amrex::ParticleReal const tau, amrex::SmallVector< amrex::ParticleReal, 6, 1 > &particle, amrex::ParticleReal &zeval, RefPart const &AMREX_RESTRICT refpart) const
Definition ExactCFbend.H:238
void reverse()
Definition ExactCFbend.H:134
int m_unit
Definition ExactCFbend.H:794
static constexpr auto type
Definition ExactCFbend.H:61
Definition alignment.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:193
static constexpr amrex::ParticleReal DEFAULT_dy
Definition alignment.H:34
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:183
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:267
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
Definition beamoptic.H:567
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
static constexpr std::nullopt_t DEFAULT_name
Definition named.H:30
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:59
AMREX_FORCE_INLINE std::string name() const
Definition named.H:124
Definition nofinalize.H:22
Definition pipeaperture.H:26
static constexpr amrex::ParticleReal DEFAULT_aperture_x
Definition pipeaperture.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:104
static constexpr amrex::ParticleReal DEFAULT_aperture_y
Definition pipeaperture.H:28
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:35
Definition spintransport.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void tbmt_precession_vector(T_Real const &AMREX_RESTRICT x, T_Real const &AMREX_RESTRICT ux, T_Real const &AMREX_RESTRICT uy, T_Real const &AMREX_RESTRICT uz, T_Real const &AMREX_RESTRICT gamma, amrex::ParticleReal const &AMREX_RESTRICT h, amrex::ParticleReal const &AMREX_RESTRICT gyro_anomaly, T_Real const &AMREX_RESTRICT Bx, T_Real const &AMREX_RESTRICT By, T_Real const &AMREX_RESTRICT Bz, T_Real const &AMREX_RESTRICT Ex, T_Real const &AMREX_RESTRICT Ey, T_Real const &AMREX_RESTRICT Ez, T_Real &AMREX_RESTRICT Omegax, T_Real &AMREX_RESTRICT Omegay, T_Real &AMREX_RESTRICT Omegaz) const
Definition spintransport.H:121
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rotate_spin(T_Real const &AMREX_RESTRICT lambdax, T_Real const &AMREX_RESTRICT lambday, T_Real const &AMREX_RESTRICT lambdaz, T_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy, T_Real &AMREX_RESTRICT sz) const
Definition spintransport.H:48
static constexpr int DEFAULT_nslice
Definition thick.H:25
Thick(amrex::ParticleReal ds, int nslice)
Definition thick.H:32
amrex::ParticleReal m_ds
Definition thick.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thick.H:55
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition thick.H:45