ASCOT5
Loading...
Searching...
No Matches
mccc_fo_euler.c
Go to the documentation of this file.
1
5#include <math.h>
6#include "../../ascot5.h"
7#include "../../consts.h"
8#include "../../math.h"
9#include "../../error.h"
10#include "../../physlib.h"
11#include "../../particle.h"
12#include "../../plasma.h"
13#include "../../random.h"
14#include "mccc_coefs.h"
15#include "mccc.h"
16
28 mccc_data* mdata, real* rnd) {
29
30 /* Get plasma information before going to the SIMD loop */
31 int n_species = plasma_get_n_species(pdata);
32 const real* qb = plasma_get_species_charge(pdata);
33 const real* mb = plasma_get_species_mass(pdata);
34
35 GPU_DATA_IS_MAPPED(h[0:p->n_mrk], rnd[0:3*p->n_mrk])
36 GPU_PARALLEL_LOOP_ALL_LEVELS
37 for(int i = 0; i < p->n_mrk; i++) {
38 if(p->running[i]) {
39 a5err errflag = 0;
40
41 /* These are needed twice to transform velocity to cartesian and *
42 * back to cylindrical coordinates. Position does not change */
43 real sinphi = sin(p->phi[i]);
44 real cosphi = cos(p->phi[i]);
45
46 real pnorm = sqrt( p->p_r[i] * p->p_r[i] + p->p_phi[i] * p->p_phi[i]
47 + p->p_z[i] * p->p_z[i] );
48 real gamma = physlib_gamma_pnorm(p->mass[i], pnorm);
49
50 real vin_xyz[3];
51 vin_xyz[0] = ( p->p_r[i] * cosphi - p->p_phi[i] * sinphi )
52 / ( gamma * p->mass[i] );
53 vin_xyz[1] = ( p->p_r[i] * sinphi + p->p_phi[i] * cosphi )
54 / ( gamma * p->mass[i] );
55 vin_xyz[2] = p->p_z[i] / ( gamma * p->mass[i] );
56 real vin = math_norm(vin_xyz);
57
58 /* Evaluate plasma density and temperature */
60 if(!errflag) {
61 errflag = plasma_eval_densandtemp(nb, Tb, p->rho[i],
62 p->r[i], p->phi[i], p->z[i],
63 p->time[i], pdata);
64 }
65
66 /* Coulomb logarithm */
67 real clogab[MAX_SPECIES];
68 mccc_coefs_clog(clogab, p->mass[i], p->charge[i], vin,
69 n_species, mb, qb, nb, Tb);
70
71 /* Evaluate collision coefficients and sum them for each *
72 * species */
73 real F = 0, Dpara = 0, Dperp = 0;
74 GPU_SEQUENTIAL_LOOP
75 for(int j = 0; j < n_species; j++) {
76 real vb = sqrt( 2 * Tb[j] / mb[j] );
77 real x = vin / vb;
78 real mufun[3];
79 mccc_coefs_mufun(mufun, x, mdata);
80
81 F += mccc_coefs_F(p->mass[i], p->charge[i], mb[j], qb[j],
82 nb[j], vb, clogab[j], mufun[0]);
83 Dpara += mccc_coefs_Dpara(p->mass[i], p->charge[i], vin, qb[j],
84 nb[j], vb, clogab[j], mufun[0]);
85 Dperp += mccc_coefs_Dperp(p->mass[i], p->charge[i], vin, qb[j],
86 nb[j], vb, clogab[j], mufun[1]);
87 }
88
89 /* Evaluate collisions */
90 real sdt = sqrt(h[i]);
91 real dW[3];
92 dW[0] = sdt * rnd[0*p->n_mrk + i];
93 dW[1] = sdt * rnd[1*p->n_mrk + i];
94 dW[2] = sdt * rnd[2*p->n_mrk + i];
95
96 real vhat[3];
97 math_unit(vin_xyz, vhat);
98
99 real t1 = math_dot(vhat, dW);
100 real k1 = F*h[i];
101 real k2 = sqrt(2*Dpara)*t1;
102 real k3 = sqrt(2*Dperp);
103
104 real vout_xyz[3];
105 vout_xyz[0] = vin_xyz[0] + k1*vhat[0] + k2*vhat[0]
106 + k3*(dW[0] - t1*vhat[0]);
107 vout_xyz[1] = vin_xyz[1] + k1*vhat[1] + k2*vhat[1]
108 + k3*(dW[1] - t1*vhat[1]);
109 vout_xyz[2] = vin_xyz[2] + k1*vhat[2] + k2*vhat[2]
110 + k3*(dW[2] - t1*vhat[2]);
111
112 /* Transform back to cylindrical coordinates. */
113
114 real vnorm = math_norm(vout_xyz);
115 gamma = physlib_gamma_vnorm(vnorm);
116 if(!errflag) {
117 p->p_r[i] = ( vout_xyz[0] * cosphi + vout_xyz[1] * sinphi )
118 * gamma * p->mass[i];
119 p->p_phi[i] = ( -vout_xyz[0] * sinphi + vout_xyz[1] * cosphi )
120 * gamma * p->mass[i];
121 p->p_z[i] = vout_xyz[2] * gamma * p->mass[i];
122 }
123
124 /* Error handling */
125 if(errflag) {
126 p->err[i] = errflag;
127 p->running[i] = 0;
128 }
129 }
130 }
131}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
#define MAX_SPECIES
Maximum number of plasma species.
Definition ascot5.h:95
Header file containing physical and mathematical constants.
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
Header file for math.c.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
Definition math.h:28
#define math_unit(a, b)
Calculate unit vector b from a 3D vector a.
Definition math.h:70
#define math_norm(a)
Calculate norm of 3D vector a.
Definition math.h:64
Header file for mccc package.
Routines to evaluate coefficients needed to evaluate collisions.
#define mccc_coefs_Dpara(ma, qa, va, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic parallel diffusion coefficient [m^2/s^3].
Definition mccc_coefs.h:103
static void mccc_coefs_mufun(real mufun[3], real x, mccc_data *mdata)
Evaluate special functions needed by collision coefficients.
Definition mccc_coefs.h:275
#define mccc_coefs_Dperp(ma, qa, va, qb, nb, vb, clogab, mu1)
Evaluate non-relativistic perpendicular diffusion coefficient [m^2/s^3].
Definition mccc_coefs.h:150
#define mccc_coefs_F(ma, qa, mb, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic friction coefficient [m/s^2].
Definition mccc_coefs.h:80
static DECLARE_TARGET_END void mccc_coefs_clog(real *clogab, real ma, real qa, real va, int nspec, const real *mb, const real *qb, const real *nb, const real *Tb)
Evaluate Coulomb logarithm.
Definition mccc_coefs.h:228
void mccc_fo_euler(particle_simd_fo *p, real *h, plasma_data *pdata, mccc_data *mdata, real *rnd)
Integrate collisions for one time-step.
Header file for particle.c.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_pnorm(m, p)
Evaluate Lorentz factor from momentum norm.
Definition physlib.h:46
#define physlib_gamma_vnorm(v)
Evaluate Lorentz factor from velocity norm.
Definition physlib.h:21
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
Definition plasma.c:361
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
Definition plasma.c:331
const real * plasma_get_species_charge(plasma_data *pls_data)
Get charge of all plasma species.
Definition plasma.c:391
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
Header file for plasma.c.
Header file for random.c.
Parameters and data required to evaluate Coulomb collisions.
Definition mccc.h:27
Struct representing NSIMD particle markers.
Definition particle.h:210
integer * running
Definition particle.h:252
Plasma simulation data.
Definition plasma.h:57