10 #ifndef IMPACTX_SOFTSOL_H
11 #define IMPACTX_SOFTSOL_H
55 4.409581845710694E-002,
56 -9.416427163897508E-006,
57 -2.459452716865687E-002,
58 -3.272762575737291E-002,
59 -2.936414401076162E-002,
60 -1.995780078926890E-002,
61 -9.102893342953847E-003,
62 -2.456410658713271E-006,
63 5.788233017324325E-003,
64 8.040408292420691E-003,
65 7.480064552867431E-003,
66 5.230254569468851E-003,
67 2.447614547094685E-003,
68 -1.095525090532255E-006,
69 -1.614586867387170E-003,
70 -2.281365457438345E-003,
71 -2.148709081338292E-003,
72 -1.522541739363011E-003,
73 -7.185505862719508E-004,
74 -6.171194824600157E-007,
75 4.842109305036943E-004,
76 6.874508102002901E-004,
77 6.535550288205728E-004,
78 4.648795813759210E-004,
79 2.216564722797528E-004,
80 -4.100982995210341E-007,
81 -1.499332112463395E-004,
82 -2.151538438342482E-004,
83 -2.044590946652016E-004,
84 -1.468242784844341E-004
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 namespace SoftSolenoidData
107 static inline std::map<int, std::vector<amrex::ParticleReal>>
h_cos_coef = {};
109 static inline std::map<int, std::vector<amrex::ParticleReal>>
h_sin_coef = {};
112 static inline std::map<int, amrex::Gpu::DeviceVector<amrex::ParticleReal>>
d_cos_coef = {};
114 static inline std::map<int, amrex::Gpu::DeviceVector<amrex::ParticleReal>>
d_sin_coef = {};
123 static constexpr
auto name =
"SoftSolenoid";
140 amrex::ParticleReal
ds,
141 amrex::ParticleReal bscale,
142 std::vector<amrex::ParticleReal> cos_coef,
143 std::vector<amrex::ParticleReal> sin_coef,
144 amrex::ParticleReal
dx = 0,
145 amrex::ParticleReal
dy = 0,
146 amrex::ParticleReal rotation_degree = 0,
159 if (
m_ncoef !=
int(sin_coef.size()))
160 throw std::runtime_error(
"SoftSolenoid: cos and sin coefficients must have same length!");
172 cos_coef.begin(), cos_coef.end(),
175 sin_coef.begin(), sin_coef.end(),
185 using BeamOptic::operator();
201 amrex::ParticleReal & AMREX_RESTRICT x,
202 amrex::ParticleReal & AMREX_RESTRICT y,
203 amrex::ParticleReal & AMREX_RESTRICT t,
204 amrex::ParticleReal & AMREX_RESTRICT px,
205 amrex::ParticleReal & AMREX_RESTRICT py,
206 amrex::ParticleReal & AMREX_RESTRICT pt,
207 [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
208 [[maybe_unused]]
RefPart const & refpart
211 using namespace amrex::literals;
217 amrex::ParticleReal xout =
x;
218 amrex::ParticleReal yout = y;
219 amrex::ParticleReal tout =
t;
222 amrex::ParticleReal pxout = px;
223 amrex::ParticleReal pyout = py;
224 amrex::ParticleReal ptout = pt;
236 xout = R(1,1)*
x + R(1,2)*px + R(1,3)*y
237 + R(1,4)*py + R(1,5)*
t + R(1,6)*pt;
238 pxout = R(2,1)*
x + R(2,2)*px + R(2,3)*y
239 + R(2,4)*py + R(2,5)*
t + R(2,6)*pt;
240 yout = R(3,1)*
x + R(3,2)*px + R(3,3)*y
241 + R(3,4)*py + R(3,5)*
t + R(3,6)*pt;
242 pyout = R(4,1)*
x + R(4,2)*px + R(4,3)*y
243 + R(4,4)*py + R(4,5)*
t + R(4,6)*pt;
244 tout = R(5,1)*
x + R(5,2)*px + R(5,3)*y
245 + R(5,4)*py + R(5,5)*
t + R(5,6)*pt;
246 ptout = R(6,1)*
x + R(6,2)*px + R(6,3)*y
247 + R(6,4)*py + R(6,5)*
t + R(6,6)*pt;
268 using namespace amrex::literals;
271 amrex::ParticleReal
const x = refpart.x;
272 amrex::ParticleReal
const px = refpart.px;
273 amrex::ParticleReal
const y = refpart.y;
274 amrex::ParticleReal
const py = refpart.py;
275 amrex::ParticleReal
const z = refpart.z;
276 amrex::ParticleReal
const pz = refpart.pz;
277 amrex::ParticleReal
const pt = refpart.pt;
278 amrex::ParticleReal
const s = refpart.s;
279 amrex::ParticleReal
const sedge = refpart.sedge;
282 for (
int i=1;
i<7;
i++) {
283 for (
int j=1; j<7; j++) {
284 auto const default_value = (
i == j) ? 1.0_prt : 0.0_prt;
285 refpart.map(
i, j) = default_value;
290 amrex::ParticleReal
const slice_ds =
m_ds /
nslice();
293 amrex::ParticleReal
const bgi =
sqrt(
pow(pt, 2) - 1.0_prt);
296 amrex::ParticleReal
const zin =
s - sedge;
297 amrex::ParticleReal
const zout = zin + slice_ds;
301 amrex::ParticleReal
const ptf = refpart.pt;
313 refpart.x =
x + slice_ds*px/bgi;
314 refpart.y = y + slice_ds*py/bgi;
315 refpart.z = z + slice_ds*pz/bgi;
318 amrex::ParticleReal
const bgf =
sqrt(
pow(ptf, 2) - 1.0_prt);
321 refpart.px = px*bgf/bgi;
322 refpart.py = py*bgf/bgi;
323 refpart.pz = pz*bgf/bgi;
326 refpart.s =
s + slice_ds;
335 std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal>
339 using namespace amrex::literals;
343 #if AMREX_DEVICE_COMPILE
353 amrex::ParticleReal
const zlen =
m_ds;
354 amrex::ParticleReal
const zmid = zlen / 2.0_prt;
357 amrex::ParticleReal bfield = 0.0;
358 amrex::ParticleReal bfieldp = 0.0;
359 amrex::ParticleReal bfieldint = 0.0;
360 amrex::ParticleReal
const z = zeval - zmid;
362 if (std::abs(z) <= zmid)
364 bfield = 0.5_prt*cos_data[0];
365 bfieldint = z*bfield;
366 for (
int j=1; j <
m_ncoef; ++j)
368 bfield = bfield + cos_data[j]*cos(j*2*
pi*z/zlen) +
369 sin_data[j]*sin(j*2*
pi*z/zlen);
370 bfieldp = bfieldp-j*2*
pi*cos_data[j]*sin(j*2*
pi*z/zlen)/zlen +
371 j*2*
pi*sin_data[j]*cos(j*2*
pi*z/zlen)/zlen;
372 bfieldint = bfieldint + zlen*cos_data[j]*sin(j*2*
pi*z/zlen)/(j*2*
pi) -
373 zlen*sin_data[j]*cos(j*2*
pi*z/zlen)/(j*2*
pi);
376 return std::make_tuple(bfield, bfieldp, bfieldint);
388 void map1 (amrex::ParticleReal
const tau,
390 [[maybe_unused]] amrex::ParticleReal & zeval)
const
392 using namespace amrex::literals;
395 amrex::ParticleReal
const t = refpart.
t;
396 amrex::ParticleReal
const pt = refpart.
pt;
397 amrex::ParticleReal
const z = zeval;
400 refpart.
t =
t + tau/
sqrt(1.0_prt -
pow(pt, -2));
412 amrex::ParticleReal
const betgam = refpart.
beta_gamma();
414 refpart.
map(1,1) = R(1,1) + tau*R(2,1);
415 refpart.
map(1,2) = R(1,2) + tau*R(2,2);
416 refpart.
map(1,3) = R(1,3) + tau*R(2,3);
417 refpart.
map(1,4) = R(1,4) + tau*R(2,4);
419 refpart.
map(3,1) = R(3,1) + tau*R(4,1);
420 refpart.
map(3,2) = R(3,2) + tau*R(4,2);
421 refpart.
map(3,3) = R(3,3) + tau*R(4,3);
422 refpart.
map(3,4) = R(3,4) + tau*R(4,4);
424 refpart.
map(5,5) = R(5,5) + tau*R(6,5)/
pow(betgam,2);
425 refpart.
map(5,6) = R(5,6) + tau*R(6,6)/
pow(betgam,2);
438 void map2 (amrex::ParticleReal
const tau,
440 amrex::ParticleReal & zeval)
const
442 using namespace amrex::literals;
444 amrex::ParticleReal
const t = refpart.
t;
445 amrex::ParticleReal
const pt = refpart.
pt;
448 amrex::ParticleReal
const B0 =
m_bscale;
459 amrex::ParticleReal
const alpha = B0*bz/2.0_prt;
460 amrex::ParticleReal
const alpha2 =
pow(
alpha,2);
462 refpart.
map(2,1) = R(2,1) - tau*alpha2*R(1,1);
463 refpart.
map(2,2) = R(2,2) - tau*alpha2*R(1,2);
464 refpart.
map(2,3) = R(2,3) - tau*alpha2*R(1,3);
465 refpart.
map(2,4) = R(2,4) - tau*alpha2*R(1,4);
467 refpart.
map(4,1) = R(4,1) - tau*alpha2*R(3,1);
468 refpart.
map(4,2) = R(4,2) - tau*alpha2*R(3,2);
469 refpart.
map(4,3) = R(4,3) - tau*alpha2*R(3,3);
470 refpart.
map(4,4) = R(4,4) - tau*alpha2*R(3,4);
483 void map3 (amrex::ParticleReal
const tau,
485 amrex::ParticleReal & zeval)
const
487 using namespace amrex::literals;
489 amrex::ParticleReal
const t = refpart.
t;
490 amrex::ParticleReal
const pt = refpart.
pt;
491 amrex::ParticleReal
const z = zeval;
494 amrex::ParticleReal
const B0 =
m_bscale;
505 amrex::ParticleReal
const theta = tau*B0*bz/2.0_prt;
506 amrex::ParticleReal
const cs = cos(theta);
507 amrex::ParticleReal
const sn = sin(theta);
509 refpart.
map(1,1) = R(1,1)*cs + R(3,1)*sn;
510 refpart.
map(1,2) = R(1,2)*cs + R(3,2)*sn;
511 refpart.
map(1,3) = R(1,3)*cs + R(3,3)*sn;
512 refpart.
map(1,4) = R(1,4)*cs + R(3,4)*sn;
514 refpart.
map(2,1) = R(2,1)*cs + R(4,1)*sn;
515 refpart.
map(2,2) = R(2,2)*cs + R(4,2)*sn;
516 refpart.
map(2,3) = R(2,3)*cs + R(4,3)*sn;
517 refpart.
map(2,4) = R(2,4)*cs + R(4,4)*sn;
519 refpart.
map(3,1) = R(3,1)*cs - R(1,1)*sn;
520 refpart.
map(3,2) = R(3,2)*cs - R(1,2)*sn;
521 refpart.
map(3,3) = R(3,3)*cs - R(1,3)*sn;
522 refpart.
map(3,4) = R(3,4)*cs - R(1,4)*sn;
524 refpart.
map(4,1) = R(4,1)*cs - R(2,1)*sn;
525 refpart.
map(4,2) = R(4,2)*cs - R(2,2)*sn;
526 refpart.
map(4,3) = R(4,3)*cs - R(2,3)*sn;
527 refpart.
map(4,4) = R(4,4)*cs - R(2,4)*sn;
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
T_ParticleType ParticleType
static constexpr amrex::Real pi
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
static constexpr HostToDevice hostToDevice
void streamSynchronize() noexcept
constexpr std::enable_if_t< std::is_floating_point< T >::value, T > pi()
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
static std::map< int, std::vector< amrex::ParticleReal > > h_cos_coef
host: cosine coefficients in Fourier expansion of on-axis magnetic field Bz
Definition: SoftSol.H:107
static int next_id
last used id for a created soft solenoid
Definition: SoftSol.H:104
static std::map< int, amrex::Gpu::DeviceVector< amrex::ParticleReal > > d_sin_coef
device: sine coefficients in Fourier expansion of on-axis magnetic field Bz
Definition: SoftSol.H:114
static std::map< int, std::vector< amrex::ParticleReal > > h_sin_coef
host: sine coefficients in Fourier expansion of on-axis magnetic field Bz
Definition: SoftSol.H:109
static std::map< int, amrex::Gpu::DeviceVector< amrex::ParticleReal > > d_cos_coef
device: cosine coefficients in Fourier expansion of on-axis magnetic field Bz
Definition: SoftSol.H:112
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void symp2_integrate_split3(RefPart &refpart, amrex::ParticleReal const zin, amrex::ParticleReal const zout, int const nsteps, T_Element const &element)
Definition: Integrators.H:51
Definition: ImpactX.cpp:33
@ t
fixed t as the independent variable
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition: ReferenceParticle.H:79
amrex::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
amrex::Array2D< amrex::ParticleReal, 1, 6, 1, 6 > map
linearized map
Definition: ReferenceParticle.H:44
amrex::ParticleReal t
clock time * c in meters
Definition: ReferenceParticle.H:35
Definition: SoftSol.H:122
void finalize()
Definition: SoftSol.H:534
static constexpr auto name
Definition: SoftSol.H:123
amrex::ParticleReal * m_cos_d_data
non-owning pointer to host sine coefficients
Definition: SoftSol.H:555
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map2(amrex::ParticleReal const tau, RefPart &refpart, amrex::ParticleReal &zeval) const
Definition: SoftSol.H:438
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map1(amrex::ParticleReal const tau, RefPart &refpart, [[maybe_unused]] amrex::ParticleReal &zeval) const
Definition: SoftSol.H:388
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, [[maybe_unused]] uint64_t &AMREX_RESTRICT idcpu, [[maybe_unused]] RefPart const &refpart) const
Definition: SoftSol.H:200
std::tuple< amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Sol_Bfield(amrex::ParticleReal const zeval) const
Definition: SoftSol.H:337
int m_ncoef
unique soft solenoid id used for data lookup map
Definition: SoftSol.H:552
amrex::ParticleReal * m_cos_h_data
number of Fourier coefficients
Definition: SoftSol.H:553
int m_mapsteps
scaling factor for solenoid Bz field
Definition: SoftSol.H:549
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void map3(amrex::ParticleReal const tau, RefPart &refpart, amrex::ParticleReal &zeval) const
Definition: SoftSol.H:483
SoftSolenoid(amrex::ParticleReal ds, amrex::ParticleReal bscale, std::vector< amrex::ParticleReal > cos_coef, std::vector< amrex::ParticleReal > sin_coef, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int mapsteps=1, int nslice=1)
Definition: SoftSol.H:139
int m_id
number of map integration steps per slice
Definition: SoftSol.H:550
amrex::ParticleReal * m_sin_h_data
non-owning pointer to host cosine coefficients
Definition: SoftSol.H:554
ImpactXParticleContainer::ParticleType PType
Definition: SoftSol.H:124
amrex::ParticleReal m_bscale
Definition: SoftSol.H:548
amrex::ParticleReal * m_sin_d_data
non-owning pointer to device cosine coefficients
Definition: SoftSol.H:556
amrex::Vector< amrex::ParticleReal > default_cos_coef
Definition: SoftSol.H:49
amrex::Vector< amrex::ParticleReal > default_sin_coef
Definition: SoftSol.H:87
Definition: alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:91
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition: alignment.H:120
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition: alignment.H:130
Definition: beamoptic.H:149
Thick(amrex::ParticleReal ds, int nslice)
Definition: thick.H:30
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
amrex::ParticleReal m_ds
Definition: thick.H:58