66 real* plasma_offload_array,
real* neutral_offload_array,
67 real* wall_offload_array,
int* wall_int_offload_array,
69 real* diag_offload_array) {
77 plasma_offload_array);
79 neutral_offload_array);
81 wall_int_offload_array);
83 asigma_offload_array);
98 int nprt_generated = 0;
106 nprt_inj = nprt - nprt_generated;
114 nprt_generated += nprt_inj;
116 "Generated %d markers for injector %d.\n", nprt_inj, i+1);
122 for(
int i = 0; i < nprt; i++) {
129 for(
int i = 0; i < nprt; i++) {
130 pq.
p[pq.
next++] = &((*p)[i]);
163 + (1.0/3) * inj->
efrac[2];
168 #pragma omp parallel for
169 for(
int i = 0; i < nprt; i++) {
173 real xyz[3], vxyz[3], rpz[3], vhat[3];
184 xyz[0] += ds * vhat[0];
185 xyz[1] += ds * vhat[1];
186 xyz[2] += ds * vhat[2];
200 p[i].
p_r = vrpz[0] * gamma * inj->
mass;
201 p[i].
p_phi = vrpz[1] * gamma * inj->
mass;
202 p[i].
p_z = vrpz[2] * gamma * inj->
mass;
211 p[i].
id = ngenerated + i + 1;
243 for(
int i=0; i<
NSIMD; i++) {
254 while(n_running > 0) {
257 for(
int i=0; i<
NSIMD; i++) {
275 real posrpz[3] = {p.
r[i], p.
phi[i], p.
z[i]};
276 real posxyz[3], fposxyz[3];
278 fposxyz[0] = posxyz[0] + pxyz[0] * hin[i] / (gamma * p.
mass[i]);
279 fposxyz[1] = posxyz[1] + pxyz[1] * hin[i] / (gamma * p.
mass[i]);
280 fposxyz[2] = posxyz[2] + pxyz[2] * hin[i] / (gamma * p.
mass[i]);
283 p.
r[i] = sqrt(fposxyz[0]*fposxyz[0] + fposxyz[1]*fposxyz[1]);
285 posxyz[0] * fposxyz[1] - posxyz[1] * fposxyz[0],
286 posxyz[0] * fposxyz[0] + posxyz[1] * fposxyz[1] );
291 p.
p_r[i] = pxyz[0] * cosp + pxyz[1] * sinp;
292 p.
p_phi[i] = -pxyz[0] * sinp + pxyz[1] * cosp;
305 if(!err && p.
rho[i] <= 1.0 && rho[0] > 1.0) {
314 p.
theta[i] = atan2(p.
z[i]-axisrz[1], p.
r[i]-axisrz[0]);
318 pls_dens, pls_temp, rho[0], p.
r[i], p.
phi[i], p.
z[i],
328 n_species-1, pls_znum, pls_anum, pls_temp[0],
332 rate = pls_dens[0] * sigmav;
334 remaining[i] *= exp(-rate * ds);
340 if(shinethrough[i]) {
342 p0.
r[i], p0.
phi[i], p0.
z[i],
348 p.
r[i] = p0.
r[i] + w*(p.
r[i] - p0.
r[i]);
350 p.
z[i] = p0.
z[i] + w*(p.
z[i] - p0.
z[i]);
360 if(remaining[i] < threshold[i]) {
374 for(
int i=0; i<
NSIMD; i++) {
395 p.
B_phi[i] = B_dB[4];
413 pdiag.
time[i] += hin[i];
414 pdiag.
weight[i] /= hin[i];
a5err B_field_eval_rho(real rho[2], real psi, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its psi derivative.
a5err B_field_eval_psi(real *psi, real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi.
a5err B_field_eval_B_dB(real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field and its derivatives.
int B_field_init(B_field_data *Bdata, B_field_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
a5err B_field_get_axis_rz(real rz[2], B_field_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Header file for B_field.c.
Main header file for ASCOT5.
#define NBI_MAX_DISTANCE
Maximum distance BBNBI traces markers in seconds.
#define NSIMD
Number of particles simulated simultaneously in a particle group operations.
#define MAX_SPECIES
Maximum number of plasma species.
int asigma_init(asigma_data *asigma_data, asigma_offload_data *offload_data, real *offload_array)
Initializes atomic reaction data struct on target.
a5err asigma_eval_bms(real *ratecoeff, int z_1, int a_1, real E, real mass, int nion, const int *znum, const int *anum, real T_e, real *n_i, asigma_data *asigma_data)
Evaluate beam stopping rate coefficient.
Header file for asigma.c.
void bbnbi_inject_markers(particle_state *p, int nprt, int ngenerated, real t0, real t1, nbi_injector *inj, sim_data *sim)
Inject neutrals from an injector.
void bbnbi_simulate(sim_offload_data *sim, int nprt, real t1, real t2, real *B_offload_array, real *plasma_offload_array, real *neutral_offload_array, real *wall_offload_array, int *wall_int_offload_array, real *asigma_offload_array, real *nbi_offload_array, particle_state **p, real *diag_offload_array)
Simulate NBI injection.
void bbnbi_trace_markers(particle_queue *pq, sim_data *sim)
Trace a neutral marker until it has ionized or hit wall.
Functions to execute bbnbi externally.
Header file containing physical and mathematical constants.
#define CONST_E
Elementary charge [C]
void diag_update_fo(diag_data *data, B_field_data *Bdata, particle_simd_fo *p_f, particle_simd_fo *p_i)
Collects diagnostics when marker represents a particle.
void diag_init(diag_data *data, diag_offload_data *offload_data, real *offload_array)
Initializes diagnostics from offload data.
Header file for endcond.c.
unsigned long int a5err
Simulation error flag.
#define math_vec_xyz2rpz(vxyz, vrpz, phi)
Transform vector from cartesian to cylindrical basis: vxyz -> vrpz, phi is the toroidal angle in radi...
#define math_unit(a, b)
Calculate unit vector b from a 3D vector a.
#define math_xyz2rpz(xyz, rpz)
Convert cartesian coordinates xyz to cylindrical coordinates rpz.
#define math_vec_rpz2xyz(vrpz, vxyz, phi)
Transform vector from cylindrical to cartesian basis: vrpz -> vxyz, phi is the toroidal angle in radi...
#define math_rpz2xyz(rpz, xyz)
Convert cylindrical coordinates rpz to cartesian coordinates xyz.
#define math_normc(a1, a2, a3)
Calculate norm of 3D vector from its components a1, a2, a3.
#define math_norm(a)
Calculate norm of 3D vector a.
void nbi_init(nbi_data *nbi, nbi_offload_data *offload_data, real *offload_array)
Initialize NBI data struct on target.
void nbi_inject(real *xyz, real *vxyz, nbi_injector *inj, random_data *rng)
Sample injected marker's coordinates.
int neutral_init(neutral_data *ndata, neutral_offload_data *offload_data, real *offload_array)
Initialize neutral data struct on target.
Header file for neutral.c.
void particle_allocate_fo(particle_simd_fo *p_fo, int nmrk)
Allocates struct representing particle markers.
int particle_cycle_fo(particle_queue *q, particle_simd_fo *p, B_field_data *Bdata, int *cycle)
Replace finished FO markers with new ones or dummies.
void particle_copy_fo(particle_simd_fo *p1, int i, particle_simd_fo *p2, int j)
Copy FO struct.
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_pnorm(m, p)
Evaluate Lorentz factor from momentum norm.
#define physlib_Ekin_pnorm(m, p)
Evaluate kinetic energy [J] from momentum norm.
#define physlib_gamma_vnorm(v)
Evaluate Lorentz factor from velocity norm.
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion species.
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
a5err plasma_eval_densandtemp(real *dens, real *temp, real rho, real r, real phi, real z, real t, plasma_data *pls_data)
Evaluate plasma density and temperature for all species.
int plasma_init(plasma_data *pls_data, plasma_offload_data *offload_data, real *offload_array)
Initialize plasma data struct on target.
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Header file for plasma.c.
Macros for printing console output.
#define print_out0(v, rank, root,...)
Print to standard output only for root process.
Header file for random.c.
#define random_uniform(data)
#define random_init(data, seed)
void sim_init(sim_data *sim, sim_offload_data *offload_data)
Initialize simulation data struct on target.
Header file for simulate.c.
nbi_injector inj[NBI_MAX_INJ]
Structure for describing an NBI injector.
Struct representing NSIMD particle markers.
General representation of a marker.
neutral_data neutral_data
Simulation offload struct.
B_field_offload_data B_offload_data
plasma_offload_data plasma_offload_data
neutral_offload_data neutral_offload_data
asigma_offload_data asigma_offload_data
wall_offload_data wall_offload_data
nbi_offload_data nbi_offload_data
diag_offload_data diag_offload_data
Header file for suzuki.c.
int wall_hit_wall(real r1, real phi1, real z1, real r2, real phi2, real z2, wall_data *w, real *w_coll)
Check if a given directed line segment intersects the wall.
int wall_init(wall_data *w, wall_offload_data *offload_data, real *offload_array, int *int_offload_array)
Initialize wall data struct on target.