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
47int B_TC_init_offload(B_TC_offload_data* offload_data, real** offload_array) {
48 // No initialization done
49 offload_data->offload_array_length = 0;
50 *offload_array = NULL;
51
53 "\nTrivial cartesian magnetic field (B_TC)\n"
54 "Magnetic axis at (R,z) = (%.1f,%.1f)\n"
55 "psi = %.1f, rho = %.1f\n"
56 "Magnetic field at origo\n"
57 "B_x = %.3f B_y = %.3f B_z = %.3f\n"
58 "Magnetic field gradient\n"
59 "dB_x/dx = %.3f dB_x/dy = %.3f B_x/dz = %.3f\n"
60 "dB_y/dx = %.3f dB_y/dy = %.3f B_y/dz = %.3f\n"
61 "dB_z/dx = %.3f dB_z/dy = %.3f B_z/dz = %.3f\n",
62 offload_data->axisr, offload_data->axisz,
63 offload_data->psival, offload_data->rhoval,
64 offload_data->B[0], offload_data->B[1], offload_data->B[2],
65 offload_data->dB[0], offload_data->dB[1], offload_data->dB[2],
66 offload_data->dB[3], offload_data->dB[4], offload_data->dB[5],
67 offload_data->dB[6], offload_data->dB[7], offload_data->dB[8]);
68
69 return 0;
70}
71
79 real** offload_array) {
80 free(*offload_array);
81 *offload_array = NULL;
82}
83
91void B_TC_init(B_TC_data* Bdata, B_TC_offload_data* offload_data,
92 real* offload_array) {
93 Bdata->rhoval = offload_data->rhoval;
94 Bdata->psival = offload_data->psival;
95 Bdata->axisr = offload_data->axisr;
96 Bdata->axisz = offload_data->axisz;
97
98 Bdata->B = offload_data->B;
99 Bdata->dB = offload_data->dB;
100
101}
102
115 B_TC_data* Bdata) {
116 psi[0] = Bdata->psival;
117
118 return 0;
119}
120
132a5err B_TC_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z,
133 B_TC_data* Bdata) {
134 psi_dpsi[0] = Bdata->psival;
135 psi_dpsi[1] = 0;
136 psi_dpsi[2] = 0;
137 psi_dpsi[3] = 0;
138
139 return 0;
140}
141
153a5err B_TC_eval_rho_drho(real rho_drho[4], real r, real phi, real z,
154 B_TC_data* Bdata) {
155 rho_drho[0] = Bdata->rhoval;
156
157 rho_drho[1] = 0;
158 rho_drho[2] = 0;
159 rho_drho[3] = 0;
160
161 return 0;
162}
163
176 real z, B_TC_data* Bdata) {
177 /* Find the Cartesian position and evaluate the field there */
178 real xyz[3];
179 real rpz[3] = {r, phi, z};
180 math_rpz2xyz(rpz, xyz);
181
182 real Bxyz[3];
183 Bxyz[0] = Bdata->B[0] + Bdata->dB[0]*xyz[0] + Bdata->dB[1]*xyz[1]
184 + Bdata->dB[2]*xyz[2];
185 Bxyz[1] = Bdata->B[1] + Bdata->dB[3]*xyz[0] + Bdata->dB[4]*xyz[1]
186 + Bdata->dB[5]*xyz[2];
187 Bxyz[2] = Bdata->B[2] + Bdata->dB[6]*xyz[0] + Bdata->dB[7]*xyz[1]
188 + Bdata->dB[8]*xyz[2];
189
190 /* Transform the Cartesian field vector to cylindrical coordinates */
191 math_vec_xyz2rpz(Bxyz, B, phi);
192
193 return 0;
194}
195
207a5err B_TC_eval_B_dB(real B_dB[12], real r, real phi, real z,
208 B_TC_data* Bdata) {
209 /* Find the Cartesian position and evaluate the field there */
210 real xyz[3];
211 real rpz[3] = {r, phi, z};
212 math_rpz2xyz(rpz, xyz);
213
214 real Bxyz[3];
215 Bxyz[0] = Bdata->B[0] + Bdata->dB[0]*xyz[0] + Bdata->dB[1]*xyz[1]
216 + Bdata->dB[2]*xyz[2];
217 Bxyz[1] = Bdata->B[1] + Bdata->dB[3]*xyz[0] + Bdata->dB[4]*xyz[1]
218 + Bdata->dB[5]*xyz[2];
219 Bxyz[2] = Bdata->B[2] + Bdata->dB[6]*xyz[0] + Bdata->dB[7]*xyz[1]
220 + Bdata->dB[8]*xyz[2];
221
222 /* Transform the Cartesian field vector and Jacobian
223 to cylindrical coordinates */
224 real Brpz[3];
225 math_vec_xyz2rpz(Bxyz, Brpz, phi);
226 B_dB[0] = Brpz[0];
227 B_dB[4] = Brpz[1];
228 B_dB[8] = Brpz[2];
229
230 real B_dBxyz[12] = {Bdata->B[0], Bdata->dB[0], Bdata->dB[1], Bdata->dB[2],
231 Bdata->B[1], Bdata->dB[3], Bdata->dB[4], Bdata->dB[5],
232 Bdata->B[2], Bdata->dB[6], Bdata->dB[7], Bdata->dB[8]};
233 math_jac_xyz2rpz(B_dBxyz, B_dB, r, phi);
234
235 return 0;
236}
237
247 a5err err = 0;
248 rz[0] = Bdata->axisr;
249 rz[1] = Bdata->axisz;
250 return err;
251}
void B_TC_free_offload(B_TC_offload_data *offload_data, real **offload_array)
Free offload array.
Definition B_TC.c:78
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:153
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:114
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:132
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:207
void B_TC_init(B_TC_data *Bdata, B_TC_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
Definition B_TC.c:91
int B_TC_init_offload(B_TC_offload_data *offload_data, real **offload_array)
Initialize magnetic field offload data.
Definition B_TC.c:47
a5err B_TC_get_axis_rz(real rz[2], B_TC_data *Bdata)
Return magnetic axis R-coordinate.
Definition B_TC.c:246
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:175
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:37
TC magnetic field parameters that will be offloaded to target.
Definition B_TC.h:16
int offload_array_length
Definition B_TC.h:30
real dB[9]
Definition B_TC.h:26
real B[3]
Definition B_TC.h:25