@@ -72,7 +72,31 @@ namespace impactx::elements
72
72
/* * Push all particles */
73
73
using BeamOptic::operator ();
74
74
75
+ /* * Compute and cache the constants for the push.
76
+ *
77
+ * In particular, used to pre-compute and cache variables that are
78
+ * independent of the individually tracked particle.
79
+ *
80
+ * @param refpart reference particle
81
+ */
82
+ void compute_constants (RefPart const & refpart)
83
+ {
84
+ using namespace amrex ::literals; // for _rt and _prt
85
+
86
+ Alignment::compute_constants (refpart);
87
+
88
+ // length of the current slice
89
+ m_slice_ds = m_ds / nslice ();
90
+
91
+ // find beta*gamma^2
92
+ m_betgam2 = std::pow (refpart.pt , 2 ) - 1 .0_prt;
93
+
94
+ m_slice_bg = m_slice_ds / m_betgam2;
95
+ }
96
+
75
97
/* * This is a drift functor, so that a variable of this type can be used like a drift function.
98
+ *
99
+ * The @see compute_constants method must be called before pushing particles through this operator.
76
100
*
77
101
* @param x particle position in x
78
102
* @param y particle position in y
@@ -81,7 +105,7 @@ namespace impactx::elements
81
105
* @param py particle momentum in y
82
106
* @param pt particle momentum in t
83
107
* @param idcpu particle global index
84
- * @param refpart reference particle
108
+ * @param refpart reference particle (unused)
85
109
*/
86
110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
87
111
void operator () (
@@ -92,7 +116,7 @@ namespace impactx::elements
92
116
amrex::ParticleReal & AMREX_RESTRICT py,
93
117
amrex::ParticleReal & AMREX_RESTRICT pt,
94
118
uint64_t & AMREX_RESTRICT idcpu,
95
- RefPart const & refpart
119
+ [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
96
120
) const
97
121
{
98
122
using namespace amrex ::literals; // for _rt and _prt
@@ -108,19 +132,12 @@ namespace impactx::elements
108
132
amrex::ParticleReal pyout = py;
109
133
amrex::ParticleReal ptout = pt;
110
134
111
- // length of the current slice
112
- amrex::ParticleReal const slice_ds = m_ds / nslice ();
113
-
114
- // access reference particle values to find beta*gamma^2
115
- amrex::ParticleReal const pt_ref = refpart.pt ;
116
- amrex::ParticleReal const betgam2 = std::pow (pt_ref, 2 ) - 1 .0_prt;
117
-
118
135
// advance position and momentum (drift)
119
- xout = x + slice_ds * px;
136
+ xout = x + m_slice_ds * px;
120
137
// pxout = px;
121
- yout = y + slice_ds * py;
138
+ yout = y + m_slice_ds * py;
122
139
// pyout = py;
123
- tout = t + (slice_ds/betgam2) * pt;
140
+ tout = t + m_slice_bg * pt;
124
141
// ptout = pt;
125
142
126
143
// assign updated values
@@ -202,6 +219,13 @@ namespace impactx::elements
202
219
203
220
return R;
204
221
}
222
+
223
+ private:
224
+ // constants that are independent of the individually tracked particle,
225
+ // see: compute_constants() to refresh
226
+ amrex::ParticleReal m_slice_ds; // ! m_ds / nslice();
227
+ amrex::ParticleReal m_betgam2; // ! beta*gamma^2
228
+ amrex::ParticleReal m_slice_bg; // ! m_slice_ds / m_betgam2
205
229
};
206
230
207
231
} // namespace impactx
0 commit comments