10#ifndef IMPACTX_EXACTCFBEND_H
11#define IMPACTX_EXACTCFBEND_H
61 static constexpr auto type =
"ExactCFbend";
93 std::vector<amrex::ParticleReal> k_normal,
94 std::vector<amrex::ParticleReal> k_skew,
104 std::optional<std::string>
name = std::nullopt
114 throw std::runtime_error(
"ExactCFbend: The order used for symplectic integration must be 2, 4 or 6.");
116 m_ncoef = int(k_normal.size());
117 if (
m_ncoef !=
int(k_skew.size()))
118 throw std::runtime_error(
"ExactCFbend: normal and skew coefficient arrays must have same length!");
133 using BeamOptic::operator();
146 Alignment::compute_constants(refpart);
163 m_rc = curvature == 0.0 ? 0.0_prt : 1.0_prt/curvature;
267 xout = x + tau * px * inv_pzden;
268 yout = y + tau * py * inv_pzden;
294 pxout = px * cos_phi + (pzi - rho /
m_rc) * sin_phi;
304 amrex::ParticleReal const theta = slice_phi + std::asin(px/pperp) - std::asin(pxout/pperp);
307 xout = -
m_rc + rho*cos_phi +
m_rc*(pzf + px*sin_phi - pzi*cos_phi);
308 yout = y + theta *
m_rc * py;
372 for (
int m = 1; m <
m_ncoef; m++) {
391 dpx += -rho*ln_rho*kn + y_scl*rho*ks;
392 dpy += y_scl*kn + 0.5_prt*(rho*rho - 1_prt)*ks;
395 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;
396 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;
399 dpx += -0.25_prt*(rho -
powi<3>(rho) + (rho - 2_prt*y_scl*y_scl*rho +
powi<3>(rho))*ln_rho)*kn
400 -1_prt/12_prt*y_scl*rho*(3_prt + 2_prt*y_scl*y_scl - 3_prt*rho*rho + 6_prt*ln_rho)*ks;
401 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
402 -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;
405 dpx += -1_prt/192_prt*rho*(8_prt*
powi<4>(y_scl) - 24_prt*
powi<2>(y_scl)*(-1_prt + rho*rho)
407 +12_prt*(-1_prt + 4_prt*y_scl*y_scl - 2_prt*rho*rho)*ln_rho)*kn
408 +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;
409 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
410 + 1_prt/192_prt*(3_prt + 8_prt*
powi<4>(y_scl) + 12_prt*rho*rho
411 - 15_prt*
powi<4>(rho) + 24_prt*y_scl*y_scl*(-1_prt + rho*rho)
412 +12_prt*rho*rho*(2_prt - 4_prt*y_scl*y_scl + rho*rho)*ln_rho)*ks;
421 pxout = pxout + tau * dpx;
422 pyout = pyout + tau * dpy;
445 template<
typename T_Real>
462 T_Real lambdax = 0_prt;
463 T_Real lambday = 0_prt;
464 T_Real lambdaz = 0_prt;
466 T_Real
const x = particle(1);
467 T_Real
const px = particle(2);
468 T_Real
const y = particle(3);
469 T_Real
const py = particle(4);
471 T_Real
const pt = particle(6);
472 T_Real sx = particle_spin(1);
473 T_Real sy = particle_spin(2);
474 T_Real sz = particle_spin(3);
476#if AMREX_DEVICE_COMPILE
496 for (
int m = 0; m <
m_ncoef; m++) {
517 Bx += y_scl*kn + 0.5_prt*(rho*rho - 1_prt)*ks;
518 By += -(-rho*ln_rho*kn + y_scl*rho*ks);
521 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;
522 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);
525 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
526 -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;
527 By += -(-0.25_prt*(rho -
powi<3>(rho) + (rho - 2_prt*y_scl*y_scl*rho +
powi<3>(rho))*ln_rho)*kn
528 -1_prt/12_prt*y_scl*rho*(3_prt + 2_prt*y_scl*y_scl - 3_prt*rho*rho + 6_prt*ln_rho)*ks);
531 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
532 + 1_prt/192_prt*(3_prt + 8_prt*
powi<4>(y_scl) + 12_prt*rho*rho
533 - 15_prt*
powi<4>(rho) + 24_prt*y_scl*y_scl*(-1_prt + rho*rho)
534 +12_prt*rho*rho*(2_prt - 4_prt*y_scl*y_scl + rho*rho)*ln_rho)*ks;
535 By += -(-1_prt/192_prt*rho*(8_prt*
powi<4>(y_scl) - 24_prt*
powi<2>(y_scl)*(-1_prt + rho*rho)
537 +12_prt*(-1_prt + 4_prt*y_scl*y_scl - 2_prt*rho*rho)*ln_rho)*kn
538 +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);
546 Bx = Bx *
m_beta * gamma_ref / rho;
547 By = By *
m_beta * gamma_ref / rho;
550 T_Real
const Ex = 0.0_prt;
551 T_Real
const Ey = 0.0_prt;
552 T_Real
const Ez = 0.0_prt;
555 T_Real
const Pnorm =
sqrt(1_prt - 2_prt * pt *
m_ibeta + pt*pt);
556 T_Real
const iPnorm = 1_prt/Pnorm;
557 T_Real
const Ps =
sqrt(Pnorm*Pnorm - px*px - py*py);
558 T_Real
const gamma = gamma_ref * (1_prt - pt*
m_beta);
559 T_Real
const ux = px * iPnorm;
560 T_Real
const uy = py * iPnorm;
561 T_Real
const uz = Ps * iPnorm;
567 tbmt_precession_vector(x,ux,uy,uz,gamma,h,gyro_anomaly,Bx,By,Bz,Ex,Ey,Ez,lambdax,lambday,lambdaz);
578 particle_spin(1) = sx;
579 particle_spin(2) = sy;
580 particle_spin(3) = sz;
609#if AMREX_DEVICE_COMPILE
625 refpart.x = x + step*px;
626 refpart.y = y + step*py;
627 refpart.z = z + step*pz;
628 refpart.t =
t - step*pt;
640 refpart.px = px*cos_theta - pz*sin_theta;
642 refpart.pz = pz*cos_theta + px*sin_theta;
645 refpart.x = x + (refpart.pz - pz)/B;
646 refpart.y = y + (theta/B)*py;
647 refpart.z = z - (refpart.px - px)/B;
648 refpart.t =
t - (theta/B)*pt;
653 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
mixin::TrackedVector< amrex::ParticleReal > k_normal
Definition ExactCFbend.H:47
mixin::TrackedVector< amrex::ParticleReal > k_skew
Definition ExactCFbend.H:48
Definition ExactCFbend.H:60
ImpactXParticleContainer::ParticleType PType
Definition ExactCFbend.H:62
int m_int_order
unit specification for Multipole strength
Definition ExactCFbend.H:796
amrex::ParticleReal m_ibeta
beta
Definition ExactCFbend.H:812
amrex::ParticleReal const * m_k_skew_d_data
non-owning pointer to device normal coefficients
Definition ExactCFbend.H:804
int m_id
number of integration steps per slice
Definition ExactCFbend.H:798
amrex::ParticleReal const * m_k_skew_h_data
non-owning pointer to host normal coefficients
Definition ExactCFbend.H:802
amrex::ParticleReal m_rc
magnetic ridigity in T-m
Definition ExactCFbend.H:814
int m_mapsteps
order used for the symplectic integration (2 or 4)
Definition ExactCFbend.H:797
mixin::GPUDataRegistry< CFbendCoefficients > DynamicData
Definition ExactCFbend.H:64
amrex::ParticleReal m_beta
1 / m_betgam2
Definition ExactCFbend.H:811
amrex::ParticleReal m_slice_ds
non-owning pointer to device skew coefficients
Definition ExactCFbend.H:809
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:447
int m_ncoef
unique ExactMultipole id used for data lookup map
Definition ExactCFbend.H:800
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:337
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:183
amrex::ParticleReal m_ibetgam2
m_ds / nslice();
Definition ExactCFbend.H:810
void compute_constants(RefPart const &refpart)
Definition ExactCFbend.H:142
amrex::ParticleReal const * m_k_normal_d_data
non-owning pointer to host skew coefficients
Definition ExactCFbend.H:803
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:813
amrex::ParticleReal const * m_k_normal_h_data
number of Fourier coefficients
Definition ExactCFbend.H:801
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:91
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:234
void reverse()
Definition ExactCFbend.H:130
int m_unit
Definition ExactCFbend.H:795
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:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:179
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:263
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
Definition beamoptic.H:529
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 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
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
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