ImpactX
beamoptic.H
Go to the documentation of this file.
1 /* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2  * Berkeley National Laboratory (subject to receipt of any required
3  * approvals from the U.S. Dept. of Energy). All rights reserved.
4  *
5  * This file is part of ImpactX.
6  *
7  * Authors: Axel Huebl
8  * License: BSD-3-Clause-LBNL
9  */
10 #ifndef IMPACTX_ELEMENTS_MIXIN_BEAMOPTIC_H
11 #define IMPACTX_ELEMENTS_MIXIN_BEAMOPTIC_H
12 
14 
15 #include <AMReX_Extension.H>
16 #include <AMReX_REAL.H>
17 
18 
20 {
21 namespace detail
22 {
36  template <typename T_Element>
38  {
40 
50  PushSingleParticle (T_Element element,
51  PType* AMREX_RESTRICT aos_ptr,
52  amrex::ParticleReal* AMREX_RESTRICT part_px,
53  amrex::ParticleReal* AMREX_RESTRICT part_py,
54  amrex::ParticleReal* AMREX_RESTRICT part_pt,
55  RefPart ref_part)
56  : m_element(std::move(element)), m_aos_ptr(aos_ptr),
57  m_part_px(part_px), m_part_py(part_py), m_part_pt(part_pt),
58  m_ref_part(std::move(ref_part))
59  {
60  }
61 
62  PushSingleParticle () = delete;
63  PushSingleParticle (PushSingleParticle const &) = default;
65  ~PushSingleParticle () = default;
66 
72  void
73  operator() (long i) const
74  {
75  // access AoS data such as positions and cpu/id
77 
78  // access SoA Real data
79  amrex::ParticleReal & AMREX_RESTRICT px = m_part_px[i];
80  amrex::ParticleReal & AMREX_RESTRICT py = m_part_py[i];
81  amrex::ParticleReal & AMREX_RESTRICT pt = m_part_pt[i];
82 
83  // push through element
84  m_element(p, px, py, pt, m_ref_part);
85 
86  }
87 
88  private:
89  T_Element const m_element;
91  amrex::ParticleReal* const AMREX_RESTRICT m_part_px;
92  amrex::ParticleReal* const AMREX_RESTRICT m_part_py;
93  amrex::ParticleReal* const AMREX_RESTRICT m_part_pt;
95  };
96 
99  template< typename T_Element >
102  RefPart & AMREX_RESTRICT ref_part,
103  T_Element & element
104  ) {
105  const int np = pti.numParticles();
106 
107  // preparing access to particle data: AoS
109  auto& aos = pti.GetArrayOfStructs();
110  PType* AMREX_RESTRICT aos_ptr = aos().dataPtr();
111 
112  // preparing access to particle data: SoA of Reals
113  auto& soa_real = pti.GetStructOfArrays().GetRealData();
114  amrex::ParticleReal* const AMREX_RESTRICT part_px = soa_real[RealSoA::ux].dataPtr();
115  amrex::ParticleReal* const AMREX_RESTRICT part_py = soa_real[RealSoA::uy].dataPtr();
116  amrex::ParticleReal* const AMREX_RESTRICT part_pt = soa_real[RealSoA::pt].dataPtr();
117 
118  detail::PushSingleParticle<T_Element> const pushSingleParticle(
119  element, aos_ptr, part_px, part_py, part_pt, ref_part);
120  // loop over beam particles in the box
121  amrex::ParallelFor(np, pushSingleParticle);
122  }
123 } // namespace detail
124 
130  template<typename T_Element>
131  struct BeamOptic
132  {
142  RefPart & AMREX_RESTRICT ref_part
143  ) {
144  T_Element& element = *static_cast<T_Element*>(this);
145  detail::push_all_particles<T_Element>(pti, ref_part, element);
146  }
147  };
148 
149 } // namespace impactx::elements
150 
151 #endif // IMPACTX_ELEMENTS_MIXIN_BEAMOPTIC_H
momentum in z, scaled by the magnitude of the reference momentum [unitless] (at fixed t) OR energy de...
Definition: ImpactXParticleContainer.H:57
amrex::ParticleReal *const AMREX_RESTRICT m_part_py
Definition: beamoptic.H:92
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void operator()(long i) const
Definition: beamoptic.H:73
Definition: ImpactXParticleContainer.H:80
SoARef GetStructOfArrays() const
momentum in y, scaled by the magnitude of the reference momentum [unitless] (at fixed t or s) ...
Definition: ImpactXParticleContainer.H:56
AoSRef GetArrayOfStructs() const
momentum in x, scaled by the magnitude of the reference momentum [unitless] (at fixed t or s) ...
Definition: ImpactXParticleContainer.H:55
RefPart const m_ref_part
Definition: beamoptic.H:94
STL namespace.
amrex::ParticleReal *const AMREX_RESTRICT m_part_pt
Definition: beamoptic.H:93
Definition: beamoptic.H:131
#define AMREX_FORCE_INLINE
int numParticles() const
std::enable_if_t< std::is_integral< T >::value > ParallelFor(TypeList< CTOs... >, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
#define AMREX_GPU_DEVICE
T_Element const m_element
Definition: beamoptic.H:89
PType *const AMREX_RESTRICT m_aos_ptr
Definition: beamoptic.H:90
Definition: ReferenceParticle.H:29
PushSingleParticle(T_Element element, PType *AMREX_RESTRICT aos_ptr, amrex::ParticleReal *AMREX_RESTRICT part_px, amrex::ParticleReal *AMREX_RESTRICT part_py, amrex::ParticleReal *AMREX_RESTRICT part_pt, RefPart ref_part)
Definition: beamoptic.H:50
ImpactXParticleContainer::ParticleType PType
Definition: beamoptic.H:39
Definition: beamoptic.H:19
#define AMREX_RESTRICT
amrex::ParticleReal *const AMREX_RESTRICT m_part_px
Definition: beamoptic.H:91
void push_all_particles(ImpactXParticleContainer::iterator &pti, RefPart &AMREX_RESTRICT ref_part, T_Element &element)
Definition: beamoptic.H:100