ASCOT5
Loading...
Searching...
No Matches
B_TC.c
Go to the documentation of this file.
1
23#include <stdlib.h>
24#include <stdio.h>
25#include <math.h>
26#include "../ascot5.h"
27#include "../math.h"
28#include "../error.h"
29#include "../print.h"
30#include "B_TC.h"
31
46int B_TC_init(B_TC_data* data, real axisr, real axisz, real psival, real rhoval,
47 real B[3], real dB[9]) {
48
49 data->axisr = axisr;
50 data->axisz = axisz;
51 data->psival = psival;
52 data->rhoval = rhoval;
53 data->B[0] = B[0];
54 data->B[1] = B[1];
55 data->B[2] = B[2];
56 for(int i = 0; i < 9; i++) {
57 data->dB[i] = dB[i];
58 }
59
61 "\nTrivial cartesian magnetic field (B_TC)\n"
62 "Magnetic axis at (R,z) = (%.1f,%.1f)\n"
63 "psi = %.1f, rho = %.1f\n"
64 "Magnetic field at origo\n"
65 "B_x = %.3f B_y = %.3f B_z = %.3f\n"
66 "Magnetic field gradient\n"
67 "dB_x/dx = %.3f dB_x/dy = %.3f B_x/dz = %.3f\n"
68 "dB_y/dx = %.3f dB_y/dy = %.3f B_y/dz = %.3f\n"
69 "dB_z/dx = %.3f dB_z/dy = %.3f B_z/dz = %.3f\n",
70 data->axisr, data->axisz,
71 data->psival, data->rhoval,
72 data->B[0], data->B[1], data->B[2],
73 data->dB[0], data->dB[1], data->dB[2],
74 data->dB[3], data->dB[4], data->dB[5],
75 data->dB[6], data->dB[7], data->dB[8]);
76
77 return 0;
78}
79
83void B_TC_free(B_TC_data* data) {
84 // No resources were dynamically allocated
85}
86
93 GPU_MAP_TO_DEVICE( data->B[0:3], data->dB[0:9] )
94}
95
108 B_TC_data* Bdata) {
109 psi[0] = Bdata->psival;
110
111 return 0;
112}
113
125a5err B_TC_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z,
126 B_TC_data* Bdata) {
127 psi_dpsi[0] = Bdata->psival;
128 psi_dpsi[1] = 0;
129 psi_dpsi[2] = 0;
130 psi_dpsi[3] = 0;
131
132 return 0;
133}
134
146a5err B_TC_eval_rho_drho(real rho_drho[4], real r, real phi, real z,
147 B_TC_data* Bdata) {
148 rho_drho[0] = Bdata->rhoval;
149
150 rho_drho[1] = 0;
151 rho_drho[2] = 0;
152 rho_drho[3] = 0;
153
154 return 0;
155}
156
169 real z, B_TC_data* Bdata) {
170 /* Find the Cartesian position and evaluate the field there */
171 real xyz[3];
172 real rpz[3] = {r, phi, z};
173 math_rpz2xyz(rpz, xyz);
174
175 real Bxyz[3];
176 Bxyz[0] = Bdata->B[0] + Bdata->dB[0]*xyz[0] + Bdata->dB[1]*xyz[1]
177 + Bdata->dB[2]*xyz[2];
178 Bxyz[1] = Bdata->B[1] + Bdata->dB[3]*xyz[0] + Bdata->dB[4]*xyz[1]
179 + Bdata->dB[5]*xyz[2];
180 Bxyz[2] = Bdata->B[2] + Bdata->dB[6]*xyz[0] + Bdata->dB[7]*xyz[1]
181 + Bdata->dB[8]*xyz[2];
182
183 /* Transform the Cartesian field vector to cylindrical coordinates */
184 math_vec_xyz2rpz(Bxyz, B, phi);
185
186 return 0;
187}
188
200a5err B_TC_eval_B_dB(real B_dB[12], real r, real phi, real z,
201 B_TC_data* Bdata) {
202 /* Find the Cartesian position and evaluate the field there */
203 real xyz[3];
204 real rpz[3] = {r, phi, z};
205 math_rpz2xyz(rpz, xyz);
206
207 real Bxyz[3];
208 Bxyz[0] = Bdata->B[0] + Bdata->dB[0]*xyz[0] + Bdata->dB[1]*xyz[1]
209 + Bdata->dB[2]*xyz[2];
210 Bxyz[1] = Bdata->B[1] + Bdata->dB[3]*xyz[0] + Bdata->dB[4]*xyz[1]
211 + Bdata->dB[5]*xyz[2];
212 Bxyz[2] = Bdata->B[2] + Bdata->dB[6]*xyz[0] + Bdata->dB[7]*xyz[1]
213 + Bdata->dB[8]*xyz[2];
214
215 /* Transform the Cartesian field vector and Jacobian
216 to cylindrical coordinates */
217 real Brpz[3];
218 math_vec_xyz2rpz(Bxyz, Brpz, phi);
219 B_dB[0] = Brpz[0];
220 B_dB[4] = Brpz[1];
221 B_dB[8] = Brpz[2];
222
223 real B_dBxyz[12] = {Bdata->B[0], Bdata->dB[0], Bdata->dB[1], Bdata->dB[2],
224 Bdata->B[1], Bdata->dB[3], Bdata->dB[4], Bdata->dB[5],
225 Bdata->B[2], Bdata->dB[6], Bdata->dB[7], Bdata->dB[8]};
226 math_jac_xyz2rpz(B_dBxyz, B_dB, r, phi);
227
228 return 0;
229}
230
240 a5err err = 0;
241 rz[0] = Bdata->axisr;
242 rz[1] = Bdata->axisz;
243 return err;
244}
void B_TC_offload(B_TC_data *data)
Offload data to the accelerator.
Definition B_TC.c:92
a5err B_TC_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_TC_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_TC.c:146
a5err B_TC_eval_psi(real *psi, real r, real phi, real z, B_TC_data *Bdata)
Evaluate poloidal flux psi.
Definition B_TC.c:107
a5err B_TC_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_TC_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_TC.c:125
a5err B_TC_eval_B_dB(real B_dB[12], real r, real phi, real z, B_TC_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_TC.c:200
int B_TC_init(B_TC_data *data, real axisr, real axisz, real psival, real rhoval, real B[3], real dB[9])
Initialize magnetic field data.
Definition B_TC.c:46
void B_TC_free(B_TC_data *data)
Free allocated resources.
Definition B_TC.c:83
a5err B_TC_get_axis_rz(real rz[2], B_TC_data *Bdata)
Return magnetic axis R-coordinate.
Definition B_TC.c:239
a5err B_TC_eval_B(real B[3], real r, real phi, real z, B_TC_data *Bdata)
Evaluate magnetic field.
Definition B_TC.c:168
Header file for B_TC.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
void math_jac_xyz2rpz(real *xyz, real *rpz, real r, real phi)
Convert a Jacobian from cartesian to cylindrical coordinates.
Definition math.c:103
Header file for math.c.
#define math_vec_xyz2rpz(vxyz, vrpz, phi)
Transform vector from cartesian to cylindrical basis: vxyz -> vrpz, phi is the toroidal angle in radi...
Definition math.h:90
#define math_rpz2xyz(rpz, xyz)
Convert cylindrical coordinates rpz to cartesian coordinates xyz.
Definition math.h:78
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
TC magnetic field parameters on the target.
Definition B_TC.h:16
real dB[9]
Definition B_TC.h:26
real psival
Definition B_TC.h:21
real axisz
Definition B_TC.h:19
real axisr
Definition B_TC.h:17
real B[3]
Definition B_TC.h:25
real rhoval
Definition B_TC.h:23