25 real* div_halo_frac,
int* nbeamlet,
real* beamlet_xyz) {
29 for(
int i=0; i<data->
ninj; i++) {
35 data->
inj[i].
efrac[0] = efrac[3*i+0];
36 data->
inj[i].
efrac[1] = efrac[3*i+1];
37 data->
inj[i].
efrac[2] = efrac[3*i+2];
43 data->
inj[i].
id =
id[i];
53 for(
int j = 0; j < n_beamlet; j++) {
54 data->
inj[i].
beamlet_x[j] = beamlet_xyz[idx + 0*n_beamlet + j];
55 data->
inj[i].
beamlet_y[j] = beamlet_xyz[idx + 1*n_beamlet + j];
56 data->
inj[i].
beamlet_z[j] = beamlet_xyz[idx + 2*n_beamlet + j];
57 data->
inj[i].
beamlet_dx[j] = beamlet_xyz[idx + 3*n_beamlet + j];
58 data->
inj[i].
beamlet_dy[j] = beamlet_xyz[idx + 4*n_beamlet + j];
59 data->
inj[i].
beamlet_dz[j] = beamlet_xyz[idx + 5*n_beamlet + j];
67 for(
int i=0; i < data->
ninj; i++) {
72 " Anum %d Znum %d mass %1.1e amu energy %1.1e eV\n",
76 " Energy fractions: %1.1e (Full) %1.1e (1/2) %1.1e (1/3)\n",
97 for(
int i=0; i<data->
ninj; i++) {
128 if(r < inj->efrac[0]) {
130 }
else if(r < inj->efrac[0] + inj->
efrac[1]) {
137 real dir[3], normalv[3], normalh[3], tmp[3];
142 real phi = atan2(dir[1], dir[0]);
143 real theta = acos(dir[2]);
145 normalv[0] = sin(theta+
CONST_PI/2) * cos(phi);
146 normalv[1] = sin(theta+
CONST_PI/2) * sin(phi);
169 tmp[0] = cos(div_h) * ( cos(div_v) * dir[0] + sin(div_v) * normalv[0] )
170 + sin(div_h) * normalh[0];
171 tmp[1] = cos(div_h) * ( cos(div_v) * dir[1] + sin(div_v) * normalv[1] )
172 + sin(div_h) * normalh[1];
173 tmp[2] = cos(div_h) * ( cos(div_v) * dir[2] + sin(div_v) * normalv[2] )
174 + sin(div_h) * normalh[2];
178 real absv = sqrt( 1.0 - 1.0 / (gamma * gamma) ) *
CONST_C;
179 vxyz[0] = absv * dir[0];
180 vxyz[1] = absv * dir[1];
181 vxyz[2] = absv * dir[2];
Main header file for ASCOT5.
Header file containing physical and mathematical constants.
#define CONST_U
Atomic mass unit in kilograms [kg]
#define CONST_C
Speed of light [m/s]
#define CONST_E
Elementary charge [C]
#define math_unit(a, b)
Calculate unit vector b from a 3D vector a.
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
int nbi_init(nbi_data *data, int ninj, int *id, int *anum, int *znum, real *mass, real *power, real *efrac, real *energy, real *div_h, real *div_v, real *div_halo_v, real *div_halo_h, real *div_halo_frac, int *nbeamlet, real *beamlet_xyz)
Initialize NBI data struct on target.
void nbi_free(nbi_data *data)
Free allocated resources.
void nbi_inject(real *xyz, real *vxyz, nbi_injector *inj, random_data *rng)
Sample injected marker's coordinates.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_Ekin(m, ekin)
Evaluate Lorentz factor from kinetic energy [J].
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Header file for random.c.
#define random_uniform(data)
#define random_normal(data)
NBI data consisting of ninj injectors.
Structure for describing an NBI injector.