@@ -72,6 +72,18 @@ namespace impactx::elements
72
72
/* * Push all particles */
73
73
using BeamOptic::operator ();
74
74
75
+ void calc_constants (RefPart const & refpart)
76
+ {
77
+ using namespace amrex ::literals; // for _rt and _prt
78
+
79
+ // length of the current slice
80
+ m_slice_ds = m_ds / nslice ();
81
+
82
+ amrex::ParticleReal const pt_ref = refpart.pt ;
83
+ // find beta*gamma^2
84
+ m_betgam2 = std::pow (pt_ref, 2 ) - 1 .0_prt;
85
+ }
86
+
75
87
/* * This is a drift functor, so that a variable of this type can be used like a drift function.
76
88
*
77
89
* @param x particle position in x
@@ -92,7 +104,7 @@ namespace impactx::elements
92
104
amrex::ParticleReal & AMREX_RESTRICT py,
93
105
amrex::ParticleReal & AMREX_RESTRICT pt,
94
106
uint64_t & AMREX_RESTRICT idcpu,
95
- RefPart const & refpart
107
+ RefPart const &
96
108
) const
97
109
{
98
110
using namespace amrex ::literals; // for _rt and _prt
@@ -108,19 +120,12 @@ namespace impactx::elements
108
120
amrex::ParticleReal pyout = py;
109
121
amrex::ParticleReal ptout = pt;
110
122
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
123
// advance position and momentum (drift)
119
- xout = x + slice_ds * px;
124
+ xout = x + m_slice_ds * px;
120
125
// pxout = px;
121
- yout = y + slice_ds * py;
126
+ yout = y + m_slice_ds * py;
122
127
// pyout = py;
123
- tout = t + (slice_ds/betgam2 ) * pt;
128
+ tout = t + (m_slice_ds/m_betgam2 ) * pt;
124
129
// ptout = pt;
125
130
126
131
// assign updated values
@@ -202,6 +207,11 @@ namespace impactx::elements
202
207
203
208
return R;
204
209
}
210
+
211
+ private:
212
+ // constants
213
+ amrex::ParticleReal m_slice_ds; // ! m_ds / nslice();
214
+ amrex::ParticleReal m_betgam2; // ! beta*gamma^2
205
215
};
206
216
207
217
} // namespace impactx
0 commit comments