ASCOT5
Loading...
Searching...
No Matches
biosaw.c
Go to the documentation of this file.
1
5#include "ascot5.h"
6#include "biosaw.h"
7#include "consts.h"
8#include "math.h"
9
27void biosaw_calc_B(int n, real* x, real* y, real* z,
28 int coil_n, real* coil_x, real* coil_y, real* coil_z,
29 real* Bx, real* By, real* Bz) {
30
31 #pragma omp parallel for
32 for(int ix = 0; ix < n; ix++) {
33 Bx[ix] = 0;
34 By[ix] = 0;
35 Bz[ix] = 0;
36
37 real p1[3], p2[3];
38 p2[0] = coil_x[0];
39 p2[1] = coil_y[0];
40 p2[2] = coil_z[0];
41
42 for(int i = 1; i < coil_n; i++) {
43 math_copy(p1, p2);
44
45 p2[0] = coil_x[i];
46 p2[1] = coil_y[i];
47 p2[2] = coil_z[i];
48
49 real p1p2[3];
50 p1p2[0] = p2[0] - p1[0];
51 p1p2[1] = p2[1] - p1[1];
52 p1p2[2] = p2[2] - p1[2];
53
54 real p1x[3];
55 p1x[0] = x[ix] - p1[0];
56 p1x[1] = y[ix] - p1[1];
57 p1x[2] = z[ix] - p1[2];
58
59 real p2x[3];
60 p2x[0] = x[ix] - p2[0];
61 p2x[1] = y[ix] - p2[1];
62 p2x[2] = z[ix] - p2[2];
63
64 real d1 = math_norm(p1x);
65 real d2 = math_norm(p2x);
66 real l = math_norm(p1p2);
67 real s = math_dot(p1p2, p1x) / math_dot(p1p2, p1p2);
68 real h = s * l;
69
70 real xs[3];
71 xs[0] = p1[0] + s*p1p2[0] - x[ix];
72 xs[1] = p1[1] + s*p1p2[1] - y[ix];
73 xs[2] = p1[2] + s*p1p2[2] - z[ix];
74
75 real d = math_norm(xs);
76
77 real abs_B = CONST_MU0 / (4*CONST_PI) * ((l-h)/d2 + h/d1)/d;
78
79 real dir_B[3];
80 math_cross(p1x, p2x, dir_B);
81
82 Bx[ix] += abs_B * dir_B[0] / math_norm(dir_B);
83 By[ix] += abs_B * dir_B[1] / math_norm(dir_B);
84 Bz[ix] += abs_B * dir_B[2] / math_norm(dir_B);
85 }
86 }
87}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
void biosaw_calc_B(int n, real *x, real *y, real *z, int coil_n, real *coil_x, real *coil_y, real *coil_z, real *Bx, real *By, real *Bz)
Evaluate magnetic field due to a coil at given points.
Definition biosaw.c:27
Header file for biosaw.c.
Header file containing physical and mathematical constants.
#define CONST_PI
pi
Definition consts.h:11
#define CONST_MU0
Magnetic constant [kg*m*s^-2*A^-2]
Definition consts.h:47
Header file for math.c.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
Definition math.h:28
#define math_copy(a, b)
Copies elements of vector b to vector a.
Definition math.h:21
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
Definition math.h:31
#define math_norm(a)
Calculate norm of 3D vector a.
Definition math.h:64