@@ -42,10 +42,12 @@ namespace
42
42
*/
43
43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
44
44
void AddOneBeamParticle (
45
- const BeamTileInit::ParticleTileDataType& ptd, const amrex::Real& x,
46
- const amrex::Real& y, const amrex::Real& z, const amrex::Real& ux, const amrex::Real& uy,
47
- const amrex::Real& uz, const amrex::Real& weight, const amrex::Long pid,
48
- const amrex::Long ip, const amrex::Real& speed_of_light, const EnforceBC& enforceBC) noexcept
45
+ const BeamTileInit::ParticleTileDataType& ptd,
46
+ const amrex::Real& x, const amrex::Real& y, const amrex::Real& z,
47
+ const amrex::Real& ux, const amrex::Real& uy, const amrex::Real& uz,
48
+ const amrex::Real& sx, const amrex::Real& sy, const amrex::Real& sz,
49
+ const amrex::Real& weight, const amrex::Long pid, const amrex::Long ip,
50
+ const amrex::Real& speed_of_light, const EnforceBC& enforceBC, bool do_spin) noexcept
49
51
{
50
52
amrex::Real xp = x;
51
53
amrex::Real yp = y;
@@ -59,6 +61,11 @@ namespace
59
61
ptd.rdata (BeamIdx::ux )[ip] = uxp;
60
62
ptd.rdata (BeamIdx::uy )[ip] = uyp;
61
63
ptd.rdata (BeamIdx::uz )[ip] = uz * speed_of_light;
64
+ if (do_spin) {
65
+ ptd.m_runtime_rdata [0 ][ip] = sx;
66
+ ptd.m_runtime_rdata [1 ][ip] = sy;
67
+ ptd.m_runtime_rdata [2 ][ip] = sz;
68
+ }
62
69
ptd.rdata (BeamIdx::w )[ip] = std::abs (weight);
63
70
64
71
ptd.idcpu (ip) = pid + ip;
@@ -790,6 +797,7 @@ InitBeamFromFile (const std::string input_file,
790
797
std::string name_particle =" " ;
791
798
std::string name_r =" " , name_rx =" " , name_ry =" " , name_rz =" " ;
792
799
std::string name_u =" " , name_ux =" " , name_uy =" " , name_uz =" " ;
800
+ std::string name_s =" " , name_sx =" " , name_sy =" " , name_sz =" " ;
793
801
std::string name_m =" " , name_mm =" " ;
794
802
std::string name_q =" " , name_qq =" " ;
795
803
std::string name_g =" " , name_gg =" " ;
@@ -873,6 +881,24 @@ InitBeamFromFile (const std::string input_file,
873
881
}
874
882
}
875
883
}
884
+ else if (units == std::array<double ,7 > {2 ., 1 ., -1 ., 0 ., 0 ., 0 ., 0 .} &&
885
+ m_do_spin_tracking) {
886
+ // spin
887
+ if (physical_quantity.first == " spin" ) {
888
+ name_s = physical_quantity.first ;
889
+ for ( auto const & axes_direction : physical_quantity.second ) {
890
+ if (axes_direction.first == " x" || axes_direction.first == " X" ) {
891
+ name_sx = axes_direction.first ;
892
+ }
893
+ if (axes_direction.first == " y" || axes_direction.first == " Y" ) {
894
+ name_sy = axes_direction.first ;
895
+ }
896
+ if (axes_direction.first == " z" || axes_direction.first == " Z" ) {
897
+ name_sz = axes_direction.first ;
898
+ }
899
+ }
900
+ }
901
+ }
876
902
}
877
903
}
878
904
}
@@ -953,15 +979,28 @@ InitBeamFromFile (const std::string input_file,
953
979
}
954
980
}
955
981
982
+ if (m_do_spin_tracking) {
983
+ for (std::string name_s_c : {name_sx, name_sy, name_sz}) {
984
+ if (!series.iterations [num_iteration].particles [name_particle][name_s].contains (name_s_c)) {
985
+ amrex::Abort (" Beam input file does not contain " + name_s_c + " coordinate in " +
986
+ name_s + " (spin). An attempt to read these was done because " +
987
+ " do_spin_tracking is on for at least one beam.\n " );
988
+ }
989
+ }
990
+ }
956
991
// print the names of the arrays in the file that are used for the simulation
957
992
if (Hipace::m_verbose >= 3 ){
958
993
amrex::Print () << " Beam Input File '" << input_file << " ' in Iteration '" << num_iteration
959
994
<< " ' and Paricle '" << name_particle
960
- << " ' imported with:\n Positon '" << name_r << " ' (coordinates '" << name_rx << " ', '"
995
+ << " ' imported with:\n Position '" << name_r << " ' (coordinates '" << name_rx << " ', '"
961
996
<< name_ry << " ', '" << name_rz << " ')\n "
962
997
<< momentum_type << " '" << name_u << " ' (coordinates '" << name_ux
963
998
<< " ', '" << name_uy << " ', '" << name_uz << " ')\n "
964
999
<< weighting_type << " '" << name_w << " ' (in '" << name_ww << " ')\n " ;
1000
+ if (m_do_spin_tracking) {
1001
+ amrex::Print () << name_u << " ' (coordinates '" << name_ux
1002
+ << " ', '" << name_uy << " ', '" << name_uz << " ')\n " ;
1003
+ }
965
1004
}
966
1005
967
1006
auto electrons = series.iterations [num_iteration].particles [name_particle];
@@ -987,6 +1026,15 @@ InitBeamFromFile (const std::string input_file,
987
1026
amrex::The_Pinned_Arena ()->alloc (sizeof (input_type)*num_to_add) ), del};
988
1027
std::shared_ptr<input_type> u_z_data{ reinterpret_cast <input_type*>(
989
1028
amrex::The_Pinned_Arena ()->alloc (sizeof (input_type)*num_to_add) ), del};
1029
+ std::shared_ptr<input_type> s_x_data{ reinterpret_cast <input_type*>(
1030
+ amrex::The_Pinned_Arena ()->alloc (m_do_spin_tracking ?
1031
+ sizeof (input_type)*num_to_add : 0 ) ), del};
1032
+ std::shared_ptr<input_type> s_y_data{ reinterpret_cast <input_type*>(
1033
+ amrex::The_Pinned_Arena ()->alloc (m_do_spin_tracking ?
1034
+ sizeof (input_type)*num_to_add : 0 ) ), del};
1035
+ std::shared_ptr<input_type> s_z_data{ reinterpret_cast <input_type*>(
1036
+ amrex::The_Pinned_Arena ()->alloc (m_do_spin_tracking ?
1037
+ sizeof (input_type)*num_to_add: 0 ) ), del};
990
1038
std::shared_ptr<input_type> w_w_data{ reinterpret_cast <input_type*>(
991
1039
amrex::The_Pinned_Arena ()->alloc (sizeof (input_type)*num_to_add) ), del};
992
1040
@@ -997,6 +1045,11 @@ InitBeamFromFile (const std::string input_file,
997
1045
electrons[name_u][name_uy].loadChunk <input_type>(u_y_data, {0u }, {num_to_add});
998
1046
electrons[name_u][name_uz].loadChunk <input_type>(u_z_data, {0u }, {num_to_add});
999
1047
electrons[name_w][name_ww].loadChunk <input_type>(w_w_data, {0u }, {num_to_add});
1048
+ if (m_do_spin_tracking) {
1049
+ electrons[name_s][name_sx].loadChunk <input_type>(s_x_data, {0u }, {num_to_add});
1050
+ electrons[name_s][name_sy].loadChunk <input_type>(s_y_data, {0u }, {num_to_add});
1051
+ electrons[name_s][name_sz].loadChunk <input_type>(s_z_data, {0u }, {num_to_add});
1052
+ }
1000
1053
1001
1054
series.flush ();
1002
1055
@@ -1052,6 +1105,7 @@ InitBeamFromFile (const std::string input_file,
1052
1105
auto old_size = particle_tile.size ();
1053
1106
auto new_size = old_size + num_to_add;
1054
1107
particle_tile.resize (new_size);
1108
+
1055
1109
const auto ptd = particle_tile.getParticleTileData ();
1056
1110
const auto enforceBC = EnforceBC ();
1057
1111
@@ -1064,7 +1118,11 @@ InitBeamFromFile (const std::string input_file,
1064
1118
const input_type * const u_x_ptr = u_x_data.get ();
1065
1119
const input_type * const u_y_ptr = u_y_data.get ();
1066
1120
const input_type * const u_z_ptr = u_z_data.get ();
1121
+ const input_type * const s_x_ptr = m_do_spin_tracking ? s_x_data.get () : nullptr ;
1122
+ const input_type * const s_y_ptr = m_do_spin_tracking ? s_y_data.get () : nullptr ;
1123
+ const input_type * const s_z_ptr = m_do_spin_tracking ? s_z_data.get () : nullptr ;
1067
1124
const input_type * const w_w_ptr = w_w_data.get ();
1125
+ const bool do_spin_tracking = m_do_spin_tracking;
1068
1126
1069
1127
amrex::ParallelFor (amrex::Long (num_to_add),
1070
1128
[=] AMREX_GPU_DEVICE (const amrex::Long i) {
@@ -1075,8 +1133,11 @@ InitBeamFromFile (const std::string input_file,
1075
1133
static_cast <amrex::Real>(u_x_ptr[i] * unit_ux), // = gamma * beta
1076
1134
static_cast <amrex::Real>(u_y_ptr[i] * unit_uy),
1077
1135
static_cast <amrex::Real>(u_z_ptr[i] * unit_uz),
1136
+ do_spin_tracking ? static_cast <amrex::Real>(s_x_ptr[i]) : 0 .,
1137
+ do_spin_tracking ? static_cast <amrex::Real>(s_y_ptr[i]) : 0 .,
1138
+ do_spin_tracking ? static_cast <amrex::Real>(s_z_ptr[i]) : 0 .,
1078
1139
static_cast <amrex::Real>(w_w_ptr[i] * unit_ww),
1079
- pid, i, phys_const.c , enforceBC);
1140
+ pid, i, phys_const.c , enforceBC, do_spin_tracking );
1080
1141
});
1081
1142
1082
1143
amrex::Gpu::streamSynchronize ();
0 commit comments