ASCOT5
Loading...
Searching...
No Matches
mccc_coefs.h
Go to the documentation of this file.
1
5#ifndef MCCC_COEFS_H
6#define MCCC_COEFS_H
7
8#include <math.h>
9#include "../../ascot5.h"
10#include "../../consts.h"
11#include "mccc.h"
12
25#define mccc_coefs_cab(qa, qb, nb, clogab) ( \
26 nb * qa*qa * qb*qb * clogab / ( 4 * CONST_PI * CONST_E0*CONST_E0 ) )
27
43#define mccc_coefs_Q(ma, qa, mb, qb, nb, vb, clogab, mu0) ( \
44 -mccc_coefs_cab(qa, qb, nb, clogab) * mu0 / ( ma * mb * vb*vb ) )
45
61#define mccc_coefs_dQ(ma, qa, mb, qb, nb, vb, clogab, dmu0) ( \
62 -mccc_coefs_cab(qa, qb, nb, clogab) * dmu0 / ( ma * mb * vb*vb*vb ) )
63
80#define mccc_coefs_F(ma, qa, mb, qb, nb, vb, clogab, mu0) ( \
81 -( 1/mb + 1/ma ) * mccc_coefs_cab(qa, qb, nb, clogab) * mu0 \
82 / ( ma * vb*vb ) )
83
103#define mccc_coefs_Dpara(ma, qa, va, qb, nb, vb, clogab, mu0) ( \
104 ( va > 0 ) ? \
105 mccc_coefs_cab(qa, qb, nb, clogab) * mu0 / ( 2 * ma*ma * va ) : \
106 mccc_coefs_cab(qa, qb, nb, clogab) * 4 \
107 / ( 6 * CONST_SQRTPI * ma*ma * vb ) )
108
126#define mccc_coefs_dDpara(ma, qa, va, qb, nb, vb, clogab, mu0, dmu0) ( \
127 mccc_coefs_cab(qa, qb, nb, clogab) * ( dmu0/vb - mu0/va ) \
128 / ( 2 * ma*ma * va ) )
129
150#define mccc_coefs_Dperp(ma, qa, va, qb, nb, vb, clogab, mu1) ( \
151 ( va > 0 ) ? \
152 mccc_coefs_cab(qa, qb, nb, clogab) * mu1 / ( 2 * ma*ma * va ) : \
153 mccc_coefs_cab(qa, qb, nb, clogab) * 4 \
154 / ( 6 * CONST_SQRTPI * ma*ma * vb ) )
155
167#define mccc_coefs_K(va, Dpara, dDpara, Q) ( \
168 Q + dDpara + 2*Dpara / va )
169
180 #define mccc_coefs_nu(va, Dperp) ( \
181 2 * Dperp / ( va * va ) )
182
195#define mccc_coefs_DX(xi, Dpara, Dperp, gyrofreq) ( \
196 ( 0.5 * ( Dpara - Dperp ) * ( 1 - xi*xi ) + Dperp ) \
197 / (gyrofreq*gyrofreq) )
198
199GPU_DECLARE_TARGET_SIMD_UNIFORM(mdata)
200static void mccc_coefs_mufun(real mufun[3], real x, mccc_data* mdata);
201DECLARE_TARGET_END
202
203GPU_DECLARE_TARGET_SIMD_UNIFORM(nspec, mb, qb, nb, Tb)
204inline static void mccc_coefs_clog(
205 real* clogab, real ma, real qa, real va, int nspec,
206 const real* mb, const real* qb, const real* nb, const real* Tb);
207DECLARE_TARGET_END
208
228inline static void mccc_coefs_clog(
229 real* clogab, real ma, real qa, real va, int nspec, const real* mb,
230 const real* qb, const real* nb, const real* Tb) {
231
232 /* Evaluate Debye length */
233 real sum = 0;
234 GPU_SEQUENTIAL_LOOP
235 for(int i = 0; i < nspec; i++){
236 sum += nb[i] * qb[i] * qb[i] / Tb[i];
237 }
238 real debyeLength = sqrt(CONST_E0/sum);
239
240 /* Evaluate classical and quantum mechanical impact parameter. The one *
241 * that is larger is used to evaluate Coulomb logarithm. */
242 GPU_SEQUENTIAL_LOOP
243 for(int i=0; i < nspec; i++){
244 real vbar = va * va + 2 * Tb[i] / mb[i];
245 real mr = ma * mb[i] / ( ma + mb[i] );
246 real bcl = fabs( qa * qb[i] / ( 4*CONST_PI*CONST_E0 * mr * vbar ) );
247 real bqm = fabs( CONST_HBAR / ( 2 * mr * sqrt( vbar ) ) );
248
249 if(bcl > bqm){
250 clogab[i] = log( debyeLength / bcl );
251 }
252 else{
253 clogab[i] = log( debyeLength / bqm );
254 }
255 }
256}
257
275inline static void mccc_coefs_mufun(real mufun[3], real x, mccc_data* mdata) {
276
277 if(!mdata->usetabulated && x!= 0) {
278 real expm2x = exp(-x*x);
279 real erfx = erf(x);
280
281 mufun[0] = ( erfx - 2 * x * expm2x / CONST_SQRTPI ) / (x*x);
282 mufun[1] = erfx - 0.5 * mufun[0];
283 mufun[2] = 4 * expm2x / CONST_SQRTPI - 2 * mufun[0] / x;
284 }
285 else if(mdata->usetabulated && x != 0) {
286 // TODO implement me
287 }
288 else {
289 mufun[0] = 0;
290 mufun[1] = 0;
291 mufun[2] = 4 / ( 3 * CONST_SQRTPI );
292 }
293
294}
295#endif
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file containing physical and mathematical constants.
#define CONST_PI
pi
Definition consts.h:11
#define CONST_E0
Electric constant [m^-3*kg^-1*s^4*A^2]
Definition consts.h:41
#define CONST_HBAR
Reduced Planck constant [m^2*kg/s]
Definition consts.h:44
#define CONST_SQRTPI
sqrt(pi)
Definition consts.h:17
Header file for math.c.
Header file for mccc package.
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
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
Parameters and data required to evaluate Coulomb collisions.
Definition mccc.h:27
int usetabulated
Definition mccc.h:28