ASCOT5
Loading...
Searching...
No Matches
step_gceom_mhd.h
Go to the documentation of this file.
1
5#ifndef STEP_GCEOM_MHD_H
6#define STEP_GCEOM_MHD_H
7
8#include <math.h>
9#include "../../ascot5.h"
10#include "../../math.h"
11#include "../../physlib.h"
12#include "../../consts.h"
13
14
27DECLARE_TARGET_SIMD
28inline static void step_gceom_mhd(real* ydot, real* y, real mass, real charge,
29 real* B_dB, real* E, real* mhd_dmhd) {
30
31 real B[3];
32 B[0] = B_dB[0];
33 B[1] = B_dB[4];
34 B[2] = B_dB[8];
35
36 real normB = sqrt(math_dot(B, B));
37 real gamma = physlib_gamma_ppar(mass, y[4], y[3], normB);
38
39 real gradB[3];
40 gradB[0] = (B[0]*B_dB[1] + B[1]*B_dB[5] + B[2]*B_dB[9]) / normB;
41 gradB[1] = (B[0]*B_dB[2] + B[1]*B_dB[6] + B[2]*B_dB[10])
42 / (normB * y[0]);
43 gradB[2] = (B[0]*B_dB[3] + B[1]*B_dB[7] + B[2]*B_dB[11]) / normB;
44
45 real gradBcrossB[3];
46 math_cross(gradB, B, gradBcrossB);
47
48 real curlB[3];
49 curlB[0] = B_dB[10] / y[0] - B_dB[7];
50 curlB[1] = B_dB[3] - B_dB[9];
51 curlB[2] = (B[1] - B_dB[2]) / y[0] + B_dB[5];
52
53 real gradalpha[3];
54 real alpha = mhd_dmhd[0];
55 gradalpha[0] = mhd_dmhd[2];
56 gradalpha[1] = mhd_dmhd[3];
57 gradalpha[2] = mhd_dmhd[4];
58
59 real gradalphacrossB[3];
60 math_cross(gradalpha, B, gradalphacrossB);
61
62 real Bstar[3];
63 Bstar[0] = B[0] + gradalphacrossB[0] + alpha * curlB[0]
64 + ( y[3] / charge ) * ( curlB[0] / normB
65 - gradBcrossB[0] / (normB*normB));
66 Bstar[1] = B[1] + gradalphacrossB[1] + alpha * curlB[1]
67 + ( y[3] / charge ) * ( curlB[1] / normB
68 - gradBcrossB[0] / (normB*normB));
69 Bstar[2] = B[2] + gradalphacrossB[2] + alpha * curlB[2]
70 + ( y[3] / charge ) * ( curlB[2] / normB
71 - gradBcrossB[2] / (normB*normB));
72
73 real Estar[3];
74 Estar[0] = E[0] - mhd_dmhd[7] - y[4] * gradB[0] / ( charge * gamma )
75 - B[0] * mhd_dmhd[1];
76 Estar[1] = E[1] - mhd_dmhd[8] - y[4] * gradB[1] / ( charge * gamma )
77 - B[1] * mhd_dmhd[1];
78 Estar[2] = E[2] - mhd_dmhd[9] - y[4] * gradB[2] / ( charge * gamma )
79 - B[2] * mhd_dmhd[1];
80
81 real Bhat[3];
82 Bhat[0] = B[0] / normB;
83 Bhat[1] = B[1] / normB;
84 Bhat[2] = B[2] / normB;
85
86 real BhatDotBstar = math_dot(Bhat, Bstar);
87
88 real EstarcrossBhat[3];
89 math_cross(Estar, Bhat, EstarcrossBhat);
90
91 ydot[0] = (y[3] * Bstar[0] / ( gamma * mass )
92 + EstarcrossBhat[0]) / BhatDotBstar;
93 ydot[1] = (y[3] * Bstar[1] / ( gamma * mass )
94 + EstarcrossBhat[1]) / (y[0]*BhatDotBstar);
95 ydot[2] = (y[3] * Bstar[2] / ( gamma * mass )
96 + EstarcrossBhat[2]) / BhatDotBstar;
97 ydot[3] = charge * math_dot(Bstar,Estar) / BhatDotBstar;
98 ydot[4] = 0;
99 ydot[5] = charge * normB / (gamma*mass);
100
101}
102
103
104#endif
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file containing physical and mathematical constants.
Header file for math.c.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
Definition math.h:28
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
Definition math.h:31
Methods to evaluate elementary physical quantities.
#define physlib_gamma_ppar(m, mu, ppar, B)
Evaluate Lorentz factor from parallel momentum.
Definition physlib.h:77
static DECLARE_TARGET_SIMD void step_gceom_mhd(real *ydot, real *y, real mass, real charge, real *B_dB, real *E, real *mhd_dmhd)
Calculate guiding center equations of motion for a single particle.