10#ifndef IMPACTX_ELEMENTS_MIXIN_BEAMOPTIC_H
11#define IMPACTX_ELEMENTS_MIXIN_BEAMOPTIC_H
38 template <
typename T_Element,
bool UseSimd = true,
typename F>
67 template <
typename T,
typename =
void>
68 struct push_simd_ps : std::bool_constant<amrex::simd::is_vectorized<T>> {};
71 : std::bool_constant<T::simd_ps> {};
73 template <
typename T,
typename =
void>
74 struct push_simd_spin : std::bool_constant<amrex::simd::is_vectorized<T>> {};
77 : std::bool_constant<T::simd_spin> {};
92 template <
typename T,
typename IndexType>
96 if constexpr (std::is_integral_v<IndexType>) {
103 using DataType = std::conditional_t<
104 std::is_same_v<T, amrex::ParticleReal>,
114 val.copy_from(&ptr[i.index], stdx::element_aligned);
120 amrex::Abort(
"SIMD index used but SIMD is not enabled");
155 template <
auto P_Method,
int N,
bool ForceWriteback =
false,
156 typename T,
typename IndexType,
typename ValType>
166 constexpr bool is_simd = !std::is_integral_v<IndexType>;
168 if constexpr (is_simd) {
174 val.copy_to(&ptr[i.index], amrex::simd::stdx::element_aligned);
195 template <
typename T_Element,
bool T_DoAlignment>
249 template <
typename IndexType>
271 constexpr bool is_simd = !std::is_integral_v<IndexType>;
275 constexpr bool has_alignment = std::is_base_of_v<mixin::Alignment, T_Element> && T_DoAlignment;
276 constexpr bool has_aperture = std::is_base_of_v<mixin::PipeAperture, T_Element>;
279 if constexpr (has_alignment) {
285 m_element.spin_and_phasespace_push(x, y,
t, px, py, pt, sx, sy, sz, idcpu,
m_ref_part);
288 if constexpr (has_aperture) {
293 if constexpr (has_alignment) {
300 if constexpr (is_simd)
302 using RealType = std::decay_t<
decltype(x)>;
303 using IdCpuType = std::decay_t<
decltype(idcpu)>;
304 constexpr auto P_Method = &T_Element::template spin_and_phasespace_push<RealType, IdCpuType>;
310 constexpr bool wb_align = has_alignment;
311 constexpr bool wb_aperture = has_aperture;
356 template <
typename T_Element,
bool T_DoAlignment>
403 template <
typename IndexType>
422 constexpr bool is_simd = !std::is_integral_v<IndexType>;
426 constexpr bool has_alignment = std::is_base_of_v<mixin::Alignment, T_Element> && T_DoAlignment;
427 constexpr bool has_aperture = std::is_base_of_v<mixin::PipeAperture, T_Element>;
430 if constexpr (has_alignment) {
438 if constexpr (has_aperture) {
443 if constexpr (has_alignment) {
449 if constexpr (is_simd)
451 using RealType = std::decay_t<
decltype(x)>;
452 using IdCpuType = std::decay_t<
decltype(idcpu)>;
453 constexpr auto P_Method = &T_Element::template operator()<RealType, IdCpuType>;
458 constexpr bool wb_align = has_alignment;
459 constexpr bool wb_aperture = has_aperture;
494 template<
typename T_Element,
typename F >
497 if constexpr (std::is_base_of_v<mixin::Alignment, std::decay_t<T_Element>>) {
498#ifdef ImpactX_OPTIMIZE_ALIGNMENT
499 if (element.misaligned()) { f(std::true_type{}); }
500 else { f(std::false_type{}); }
506 f(std::false_type{});
512 template<
typename T_Element >
523 auto& soa_real = soa.GetRealData();
531 uint64_t*
const AMREX_RESTRICT part_idcpu = soa.GetIdCPUData().dataPtr();
534 if constexpr (std::is_base_of_v<mixin::SpinTransport, std::decay_t<T_Element>>) {
542 element, part_x, part_y, part_t, part_px, part_py, part_pt, part_sx, part_sy, part_sz, part_idcpu, ref_part);
546 throw std::runtime_error(
"Spin transport requested but element does not implement the `SpinTransport` interface class!");
553 element, part_x, part_y, part_t, part_px, part_py, part_pt, part_idcpu, ref_part);
565 template<
typename T_Element>
581 std::is_base_of_v<BeamOptic, T_Element>,
582 "BeamOptic can only be used as a mixin class!"
585 T_Element& element = *
static_cast<T_Element*
>(
this);
586 push_all(pc, element, step, period);
604 std::is_base_of_v<BeamOptic, T_Element>,
605 "BeamOptic can only be used as a mixin class!"
608 T_Element& element = *
static_cast<T_Element*
>(
this);
#define AMREX_FORCE_INLINE
auto numParticles() const
SoARef GetStructOfArrays() const
T_ParticleType ParticleType
Definition ImpactXParticleContainer.H:136
impactx::ParIterSoA iterator
amrex iterator for particle boxes
Definition ImpactXParticleContainer.H:139
amrex_particle_real ParticleReal
constexpr bool is_vectorized
constexpr bool is_nth_arg_non_const(R(*)(Args...), int n)
amrex::ParticleReal SIMDParticleReal
__host__ __device__ void ignore_unused(const Ts &...)
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
IndexTypeND< 3 > IndexType
void ParallelForSIMD(N n, L const &f) noexcept
void Abort(const std::string &msg)
AMREX_GPU_DEVICE AMREX_FORCE_INLINE decltype(auto) load_pdata(T *ptr, IndexType const i)
Definition beamoptic.H:94
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void store_pdata(ValType const &AMREX_RESTRICT val, T *const AMREX_RESTRICT ptr, IndexType const i)
Definition beamoptic.H:158
void dispatch_misalignment(T_Element &element, F &&f)
Definition beamoptic.H:495
void push_all_particles(ImpactXParticleContainer::iterator &pti, RefPart &AMREX_RESTRICT ref_part, T_Element &element, bool spin)
Definition beamoptic.H:513
Definition alignment.H:25
Definition CovarianceMatrixMath.H:25
void ParallelFor(int n, F &&f)
Definition beamoptic.H:39
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
void push_all(ImpactXParticleContainer &pc, T_Element &element, int step, int period, bool omp_parallel=true)
Definition PushAll.H:33
@ nattribs
the number of attributes above (always last)
Definition ImpactXParticleContainer.H:83
@ pt
energy deviation, scaled by speed of light * the magnitude of the reference momentum [unitless] (at f...
Definition ImpactXParticleContainer.H:53
@ y
position in y [m] (at fixed s or t)
Definition ImpactXParticleContainer.H:49
@ t
time-of-flight ct [m] (at fixed s)
Definition ImpactXParticleContainer.H:50
@ sz
spin vector z-component [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:56
@ sy
spin vector y-component [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:55
@ px
momentum in x, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:51
@ sx
spin vector x-component [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:54
@ nattribs
the number of attributes above (always last)
Definition ImpactXParticleContainer.H:59
@ py
momentum in y, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
Definition ImpactXParticleContainer.H:52
@ x
position in x [m] (at fixed s or t)
Definition ImpactXParticleContainer.H:48
Definition ReferenceParticle.H:33
Definition beamoptic.H:567
void operator()(ImpactXParticleContainer &pc, int step, int period)
Definition beamoptic.H:574
Definition beamoptic.H:358
PushSingleParticle()=delete
amrex::ParticleReal *const AMREX_RESTRICT m_part_py
Definition beamoptic.H:478
amrex::ParticleReal *const AMREX_RESTRICT m_part_pt
Definition beamoptic.H:479
uint64_t *const AMREX_RESTRICT m_part_idcpu
Definition beamoptic.H:480
PushSingleParticle(T_Element element, amrex::ParticleReal *AMREX_RESTRICT part_x, amrex::ParticleReal *AMREX_RESTRICT part_y, amrex::ParticleReal *AMREX_RESTRICT part_t, amrex::ParticleReal *AMREX_RESTRICT part_px, amrex::ParticleReal *AMREX_RESTRICT part_py, amrex::ParticleReal *AMREX_RESTRICT part_pt, uint64_t *AMREX_RESTRICT part_idcpu, RefPart ref_part)
Definition beamoptic.H:374
RefPart m_ref_part
Definition beamoptic.H:481
T_Element m_element
Definition beamoptic.H:473
amrex::ParticleTile< amrex::SoAParticle< RealSoA::nattribs, IntSoA::nattribs >, RealSoA::nattribs, IntSoA::nattribs > ParticleTileType
Definition beamoptic.H:360
amrex::ParticleReal *const AMREX_RESTRICT m_part_t
Definition beamoptic.H:476
amrex::ParticleReal *const AMREX_RESTRICT m_part_px
Definition beamoptic.H:477
amrex::ParticleReal *const AMREX_RESTRICT m_part_y
Definition beamoptic.H:475
ImpactXParticleContainer::ParticleType PType
Definition beamoptic.H:359
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void operator()(IndexType i) const
Definition beamoptic.H:406
amrex::ParticleReal *const AMREX_RESTRICT m_part_x
Definition beamoptic.H:474
~PushSingleParticle()=default
PushSingleParticle(PushSingleParticle &&)=default
PushSingleParticle(PushSingleParticle const &)=default
Definition beamoptic.H:197
amrex::ParticleReal *const AMREX_RESTRICT m_part_py
Definition beamoptic.H:333
uint64_t *const AMREX_RESTRICT m_part_idcpu
Definition beamoptic.H:338
amrex::ParticleReal *const AMREX_RESTRICT m_part_sx
Definition beamoptic.H:335
PushSingleParticleSpin(T_Element element, amrex::ParticleReal *AMREX_RESTRICT part_x, amrex::ParticleReal *AMREX_RESTRICT part_y, amrex::ParticleReal *AMREX_RESTRICT part_t, amrex::ParticleReal *AMREX_RESTRICT part_px, amrex::ParticleReal *AMREX_RESTRICT part_py, amrex::ParticleReal *AMREX_RESTRICT part_pt, amrex::ParticleReal *AMREX_RESTRICT part_sx, amrex::ParticleReal *AMREX_RESTRICT part_sy, amrex::ParticleReal *AMREX_RESTRICT part_sz, uint64_t *AMREX_RESTRICT part_idcpu, RefPart ref_part)
Definition beamoptic.H:216
amrex::ParticleReal *const AMREX_RESTRICT m_part_pt
Definition beamoptic.H:334
amrex::ParticleReal *const AMREX_RESTRICT m_part_t
Definition beamoptic.H:331
amrex::ParticleReal *const AMREX_RESTRICT m_part_px
Definition beamoptic.H:332
amrex::ParticleReal *const AMREX_RESTRICT m_part_sz
Definition beamoptic.H:337
amrex::ParticleReal *const AMREX_RESTRICT m_part_y
Definition beamoptic.H:330
amrex::ParticleTile< amrex::SoAParticle< RealSoA::nattribs, IntSoA::nattribs >, RealSoA::nattribs, IntSoA::nattribs > ParticleTileType
Definition beamoptic.H:199
amrex::ParticleReal *const AMREX_RESTRICT m_part_sy
Definition beamoptic.H:336
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void operator()(IndexType i) const
Definition beamoptic.H:252
T_Element m_element
Definition beamoptic.H:328
RefPart m_ref_part
Definition beamoptic.H:339
PushSingleParticleSpin(PushSingleParticleSpin &&)=default
ImpactXParticleContainer::ParticleType PType
Definition beamoptic.H:198
amrex::ParticleReal *const AMREX_RESTRICT m_part_x
Definition beamoptic.H:329
PushSingleParticleSpin(PushSingleParticleSpin const &)=default
PushSingleParticleSpin()=delete
~PushSingleParticleSpin()=default
Definition beamoptic.H:68
Definition beamoptic.H:74