ASCOT5
Loading...
Searching...
No Matches
atomic.c
Go to the documentation of this file.
1
14#include <stdlib.h>
15#include <stdio.h>
16#include "../ascot5.h"
17#include "../math.h"
18#include "../physlib.h"
19#include "../consts.h"
20#include "../error.h"
21#include "../print.h"
22#include "../particle.h"
23#include "../plasma.h"
24#include "../random.h"
25#include "../asigma.h"
26#include "atomic.h"
27
28#ifndef GPU
29#pragma omp declare target
30DECLARE_TARGET_SIMD_UNIFORM(asigma)
31#endif
33 real* rate_eff_ion, real* rate_eff_rec, int z_1, int a_1, real m_1,
34 const int* z_2, const int* a_2, const real* m_2, asigma_data* asigma,
35 int q, real E, int N_pls_spec, int N_ntl_spec, real* T, real* T_0,
36 real* n, real* n_0);
37#ifndef GPU
38#pragma omp end declare target
39#endif
40#ifndef GPU
41DECLARE_TARGET_SIMD
42#endif
44 int* q, real dt, real rate_eff_ion, real rate_eff_rec, int z_1, real rnd);
45
57 plasma_data* p_data, neutral_data* n_data,
58 random_data* r_data, asigma_data* asigmadata) {
59
60 /* Generate random numbers and get plasma information before going to the *
61 * SIMD loop */
62 real rnd[NSIMD];
63 random_uniform_simd(r_data, NSIMD, rnd);
64
65 int N_pls_spec = plasma_get_n_species(p_data);
66 int N_ntl_spec = neutral_get_n_species(n_data);
67 const real* m_2 = plasma_get_species_mass(p_data);
68 const int* z_2 = plasma_get_species_znum(p_data);
69 const int* a_2 = plasma_get_species_anum(p_data);
70
71 #pragma omp simd
72 for(int i = 0; i < NSIMD; i++) {
73 if(p->running[i]) {
74 a5err errflag = 0;
75
76 /* Calculate kinetic energy of test particle */
77 real p_comps[3];
78 p_comps[0] = p->p_r[i];
79 p_comps[1] = p->p_phi[i];
80 p_comps[2] = p->p_z[i];
81 real p_norm = math_norm(p_comps);
82 real E = physlib_Ekin_pnorm(p->mass[i], p_norm);
83
84 /* Evaluate plasma density and temperature */
85 real n_2[MAX_SPECIES], T_2[MAX_SPECIES];
86 if(!errflag) {
87 errflag = plasma_eval_densandtemp(n_2, T_2, p->rho[i],
88 p->r[i], p->phi[i], p->z[i],
89 p->time[i], p_data);
90 }
91
92 /* Evaluate neutral density and temperature */
93 real n_0[MAX_SPECIES], T_0[MAX_SPECIES];
94 if(!errflag) {
95 errflag = neutral_eval_n0(n_0, p->rho[i],
96 p->r[i], p->phi[i], p->z[i],
97 p->time[i], n_data);
98 }
99 if(!errflag) {
100 errflag = neutral_eval_t0(T_0, p->rho[i],
101 p->r[i], p->phi[i], p->z[i],
102 p->time[i], n_data);
103 }
104
105 /* Evaluate the reaction rates for ionizing (charge-increasing) *
106 and recombining (charge-decreasing) reactions */
107 int q = (int)round(p->charge[i]/CONST_E);
108 real rate_eff_ion, rate_eff_rec;
109 if(!errflag) {
110 errflag = atomic_rates(
111 &rate_eff_ion, &rate_eff_rec, p->znum[i], p->anum[i],
112 p->mass[i], z_2, a_2, m_2, asigmadata,
113 q, E, N_pls_spec, N_ntl_spec, T_2, T_0, n_2, n_0);
114 }
115
116 /* Determine if an atomic reaction occurs */
117 if(!errflag) {
118 int q_prev = q;
119 errflag = atomic_react(
120 &q, h[i], rate_eff_ion, rate_eff_rec, p->znum[i], rnd[i]);
121 if(q != q_prev) {
122 /* A reaction has occured, change particle charge */
123 p->charge[i] = q*CONST_E;
124 }
125 }
126
127 /* Error handling */
128 if(errflag) {
129 p->err[i] = errflag;
130 p->running[i] = 0;
131 }
132 }
133 }
134}
135
165 real* rate_eff_ion, real* rate_eff_rec, int z_1, int a_1, real m_1,
166 const int* z_2, const int* a_2, const real* m_2, asigma_data* asigmadata,
167 int q, real E, int N_pls_spec, int N_ntl_spec, real* T, real* T_0,
168 real* n, real* n_0) {
169 a5err err = 0;
170
171 /* Define a helper variable for storing rate coefficients, and
172 initialize the reaction rate variables */
173 real coeff;
174 *rate_eff_rec = 0;
175 *rate_eff_ion = 0;
176
177 /* Calculate ionization and recombination probabilities based on charge
178 * state*/
179 if(q == 1) {
180 /* Only CX is implemented */
181 err = asigma_eval_cx(
182 &coeff, z_1, a_1, E, m_1, N_ntl_spec, z_2, a_2,
183 T_0[0], n_0, asigmadata);
184 *rate_eff_rec += coeff;
185 } else if(q == 0) {
186 /* Only BMS is implemented */
187 err = asigma_eval_bms(
188 &coeff, z_1, a_1, E, m_1, (N_pls_spec-1),
189 z_2, a_2, T[0], &n[1], asigmadata);
190 *rate_eff_ion += coeff * n[0];
191 } else {
192 /* q > 1 not yet implemented */
193 err = error_raise( ERR_ATOMIC_EVALUATION, __LINE__, EF_ATOMIC );
194 }
195
196 return err;
197}
198
216 int* q, real dt, real rate_eff_ion, real rate_eff_rec, int z_1, real rnd) {
217 a5err err = 0;
218
219 /* Calculate the reaction probabilities for ionizing (charge-increasing)
220 and recombining (charge-decreasing) atomic reactions. But first,
221 a fail-safe against zero rate values. */
222 real prob_eff_ion;
223 real prob_eff_rec;
224 if(rate_eff_ion == 0.0) {
225 prob_eff_ion = 0.0;
226 } else {
227 prob_eff_ion = rate_eff_ion/(rate_eff_ion+rate_eff_rec)
228 *(1.0-exp(-(rate_eff_ion+rate_eff_rec)*dt));
229 }
230 if(rate_eff_rec == 0.0) {
231 prob_eff_rec = 0.0;
232 } else {
233 prob_eff_rec = rate_eff_rec/(rate_eff_ion+rate_eff_rec)
234 *(1.0-exp(-(rate_eff_ion+rate_eff_rec)*dt));
235 }
236
237 /* Check if reaction occurs, and update charge state accordingly */
238 if(*q < z_1 && rnd < prob_eff_ion) {
239 *q += 1;
240 } else if(*q > 0 && rnd < (prob_eff_ion+prob_eff_rec)) {
241 *q -= 1;
242 }
243
244 return err;
245}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
#define NSIMD
Number of particles simulated simultaneously in a particle group operations.
Definition ascot5.h:91
#define MAX_SPECIES
Maximum number of plasma species.
Definition ascot5.h:95
a5err asigma_eval_cx(real *ratecoeff, int z_1, int a_1, real E, real mass, int nspec, const int *znum, const int *anum, real T_0, real *n_0, asigma_data *asigma_data)
Evaluate charge exchange rate coefficient.
Definition asigma.c:262
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.
Definition asigma.c:308
Header file for asigma.c.
a5err atomic_rates(real *rate_eff_ion, real *rate_eff_rec, int z_1, int a_1, real m_1, const int *z_2, const int *a_2, const real *m_2, asigma_data *asigma, int q, real E, int N_pls_spec, int N_ntl_spec, real *T, real *T_0, real *n, real *n_0)
Determines atomic reaction rates.
Definition atomic.c:164
void atomic_fo(particle_simd_fo *p, real *h, plasma_data *p_data, neutral_data *n_data, random_data *r_data, asigma_data *asigmadata)
Determine if atomic reactions occur during time-step and change charge.
Definition atomic.c:56
DECLARE_TARGET_SIMD a5err atomic_react(int *q, real dt, real rate_eff_ion, real rate_eff_rec, int z_1, real rnd)
Determines if an atomic reaction occurs during one time step.
Definition atomic.c:215
Header file for atomic.c.
Header file containing physical and mathematical constants.
#define CONST_E
Elementary charge [C]
Definition consts.h:32
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
@ EF_ATOMIC
Definition error.h:50
@ ERR_ATOMIC_EVALUATION
Definition error.h:71
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
Header file for math.c.
#define math_norm(a)
Calculate norm of 3D vector a.
Definition math.h:64
int neutral_get_n_species(neutral_data *ndata)
Get the number of neutral species.
Definition neutral.c:225
a5err neutral_eval_n0(real *n0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral density.
Definition neutral.c:147
a5err neutral_eval_t0(real *t0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral temperature.
Definition neutral.c:189
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_Ekin_pnorm(m, p)
Evaluate kinetic energy [J] from momentum norm.
Definition physlib.h:115
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
Definition plasma.c:361
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion species.
Definition plasma.c:419
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
Definition plasma.c:331
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.
Definition plasma.c:280
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Definition plasma.c:447
Header file for plasma.c.
Macros for printing console output.
Header file for random.c.
void * random_data
Definition random.h:87
#define random_uniform_simd(data, n, r)
Definition random.h:100
Atomic reaction simulation data.
Definition asigma.h:66
Neutral simulation data.
Definition neutral.h:53
Struct representing NSIMD particle markers.
Definition particle.h:210
integer * running
Definition particle.h:252
Plasma simulation data.
Definition plasma.h:57