ASCOT5
Loading...
Searching...
No Matches
B_field.c
Go to the documentation of this file.
1
16#include <stdio.h>
17#include "ascot5.h"
18#include "error.h"
19#include "print.h"
20#include "B_field.h"
21#include "Bfield/B_GS.h"
22#include "Bfield/B_2DS.h"
23#include "Bfield/B_3DS.h"
24#include "Bfield/B_STS.h"
25#include "Bfield/B_TC.h"
26
33 switch(data->type) {
34 case B_field_type_GS:
35 B_GS_free(&(data->BGS));
36 break;
37
39 B_2DS_free(&(data->B2DS));
40 break;
41
43 B_3DS_free(&(data->B3DS));
44 break;
45
47 B_STS_free(&(data->BSTS));
48 break;
49
50 case B_field_type_TC:
51 B_TC_free(&(data->BTC));
52 break;
53 }
54}
55
62 switch(data->type) {
63 case B_field_type_GS:
64 B_GS_offload(&(data->BGS));
65 break;
66
68 B_2DS_offload(&(data->B2DS));
69 break;
70
72 B_3DS_offload(&(data->B3DS));
73 break;
74
76 B_STS_offload(&(data->BSTS));
77 break;
78
79 case B_field_type_TC:
80 B_TC_offload(&(data->BTC));
81 break;
82 }
83}
84
103 B_field_data* Bdata) {
104 a5err err = 0;
105
106 switch(Bdata->type) {
107 case B_field_type_GS:
108 err = B_GS_eval_psi(psi, r, phi, z, &(Bdata->BGS));
109 break;
110
111 case B_field_type_2DS:
112 err = B_2DS_eval_psi(psi, r, phi, z, &(Bdata->B2DS));
113 break;
114
115 case B_field_type_3DS:
116 err = B_3DS_eval_psi(psi, r, phi, z, &(Bdata->B3DS));
117 break;
118
119 case B_field_type_STS:
120 err = B_STS_eval_psi(psi, r, phi, z, &(Bdata->BSTS));
121 break;
122
123 case B_field_type_TC:
124 err = B_TC_eval_psi(psi, r, phi, z, &(Bdata->BTC));
125 break;
126
127 default:
128 /* Unregonized input. Produce error. */
129 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
130 break;
131 }
132
133 if(err) {
134 /* In case of error, return some reasonable value to avoid further
135 complications */
136 psi[0] = 1;
137 }
138
139 return err;
140}
141
167 B_field_data* Bdata) {
168 a5err err = 0;
169
170 switch(Bdata->type) {
171 case B_field_type_GS:
172 err = B_GS_eval_psi_dpsi(psi_dpsi, r, phi, z, &(Bdata->BGS));
173 break;
174
175 case B_field_type_2DS:
176 err = B_2DS_eval_psi_dpsi(psi_dpsi, r, phi, z, &(Bdata->B2DS));
177 break;
178
179 case B_field_type_3DS:
180 err = B_3DS_eval_psi_dpsi(psi_dpsi, r, phi, z, &(Bdata->B3DS));
181 break;
182
183 case B_field_type_STS:
184 err = B_STS_eval_psi_dpsi(psi_dpsi, r, phi, z, &(Bdata->BSTS));
185 break;
186
187 case B_field_type_TC:
188 err = B_TC_eval_psi_dpsi(psi_dpsi, r, phi, z, &(Bdata->BTC));
189 break;
190
191 default:
192 /* Unregonized input. Produce error. */
193 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
194 break;
195 }
196
197 if(err) {
198 /* In case of error, return some reasonable values to avoid further
199 complications */
200 psi_dpsi[0] = 1;
201 for(int k=1; k<4; k++) {psi_dpsi[k] = 0;}
202 }
203
204 return err;
205}
206
229 a5err err = 0;
230
231 real psi0 = 0.0, psi1 = 1.0;
232 switch(Bdata->type) {
233 case B_field_type_GS:
234 psi0 = Bdata->BGS.psi0;
235 psi1 = Bdata->BGS.psi1;
236 break;
237
238 case B_field_type_2DS:
239 psi0 = Bdata->B2DS.psi0;
240 psi1 = Bdata->B2DS.psi1;
241 break;
242
243 case B_field_type_3DS:
244 psi0 = Bdata->B3DS.psi0;
245 psi1 = Bdata->B3DS.psi1;
246 break;
247
248 case B_field_type_STS:
249 psi0 = Bdata->BSTS.psi0;
250 psi1 = Bdata->BSTS.psi1;
251 break;
252
253 case B_field_type_TC:
254 psi0 = Bdata->BTC.psival - Bdata->BTC.rhoval * Bdata->BTC.rhoval;
255 psi1 = Bdata->BTC.psival - Bdata->BTC.rhoval * Bdata->BTC.rhoval
256 + 1.0;
257 break;
258
259 default:
260 /* Unregonized input. Produce error. */
261 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
262 break;
263 }
264
265 real delta = (psi1 - psi0);
266 if( (psi - psi0) / delta < 0 ) {
267 err = error_raise( ERR_INPUT_UNPHYSICAL, __LINE__, EF_B_FIELD );
268 } else {
269 rho[0] = sqrt( (psi - psi0) / delta );
270 rho[1] = 1.0 / (2*delta*rho[0]);
271 }
272
273 if(err) {
274 /* In case of error, return some reasonable value to avoid further
275 complications */
276 rho[0] = 1;
277 rho[1] = 0;
278 }
279
280 return err;
281}
282
313 B_field_data* Bdata) {
314 a5err err = 0;
315
316 switch(Bdata->type) {
317 case B_field_type_GS:
318 err = B_GS_eval_rho_drho(rho_drho, r, phi, z, &(Bdata->BGS));
319 break;
320
321 case B_field_type_2DS:
322 err = B_2DS_eval_rho_drho(rho_drho, r, phi, z, &(Bdata->B2DS));
323 break;
324
325 case B_field_type_3DS:
326 err = B_3DS_eval_rho_drho(rho_drho, r, phi, z, &(Bdata->B3DS));
327 break;
328
329 case B_field_type_STS:
330 err = B_STS_eval_rho_drho(rho_drho, r, phi, z, &(Bdata->BSTS));
331 break;
332
333 case B_field_type_TC:
334 err = B_TC_eval_rho_drho(rho_drho, r, phi, z, &(Bdata->BTC));
335 break;
336
337 default:
338 /* Unregonized input. Produce error. */
339 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
340 break;
341 }
342
343 if(err) {
344 /* In case of error, return some reasonable values to avoid further
345 complications */
346 rho_drho[0] = 1;
347 for(int k=1; k<4; k++) {rho_drho[k] = 0;}
348 }
349
350 return err;
351}
352
375 B_field_data* Bdata) {
376 a5err err = 0;
377
378 switch(Bdata->type) {
379 case B_field_type_GS:
380 err = B_GS_eval_B(B, r, phi, z, &(Bdata->BGS));
381 break;
382
383 case B_field_type_2DS:
384 err = B_2DS_eval_B(B, r, phi, z, &(Bdata->B2DS));
385 break;
386
387 case B_field_type_3DS:
388 err = B_3DS_eval_B(B, r, phi, z, &(Bdata->B3DS));
389 break;
390
391 case B_field_type_STS:
392 err = B_STS_eval_B(B, r, phi, z, &(Bdata->BSTS));
393 break;
394
395 case B_field_type_TC:
396 err = B_TC_eval_B(B, r, phi, z, &(Bdata->BTC));
397 break;
398
399 default:
400 /* Unregonized input. Produce error. */
401 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
402 break;
403 }
404
405 if(err) {
406 /* In case of error, return some reasonable values to avoid further
407 complications */
408 B[0] = 1;
409 for(int k=1; k<3; k++) {B[k] = 0;}
410 }
411
412 return err;
413}
414
450 B_field_data* Bdata) {
451 a5err err = 0;
452
453 switch(Bdata->type) {
454 case B_field_type_GS:
455 err = B_GS_eval_B_dB(B_dB, r, phi, z, &(Bdata->BGS));
456 break;
457
458 case B_field_type_2DS:
459 err = B_2DS_eval_B_dB(B_dB, r, phi, z, &(Bdata->B2DS));
460 break;
461
462 case B_field_type_3DS:
463 err = B_3DS_eval_B_dB(B_dB, r, phi, z, &(Bdata->B3DS));
464 break;
465
466 case B_field_type_STS:
467 err = B_STS_eval_B_dB(B_dB, r, phi, z, &(Bdata->BSTS));
468 break;
469
470 case B_field_type_TC:
471 err = B_TC_eval_B_dB(B_dB, r, phi, z, &(Bdata->BTC));
472 break;
473
474 default:
475 /* Unregonized input. Produce error. */
476 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
477 break;
478 }
479
480 if(err) {
481 /* In case of error, return some reasonable values to avoid further
482 complications */
483 B_dB[0] = 1;
484 for(int k=1; k<12; k++) {B_dB[k] = 0;}
485 }
486
487 return err;
488}
489
502 a5err err = 0;
503
504 switch(Bdata->type) {
505 case B_field_type_GS:
506 err = B_GS_get_axis_rz(rz, &(Bdata->BGS));
507 break;
508
509 case B_field_type_2DS:
510 err = B_2DS_get_axis_rz(rz, &(Bdata->B2DS));
511 break;
512
513 case B_field_type_3DS:
514 err = B_3DS_get_axis_rz(rz, &(Bdata->B3DS));
515 break;
516
517 case B_field_type_STS:
518 err = B_STS_get_axis_rz(rz, &(Bdata->BSTS), phi);
519 break;
520
521 case B_field_type_TC:
522 err = B_TC_get_axis_rz(rz, &(Bdata->BTC));
523 break;
524
525 default:
526 /* Unregonized input. Produce error. */
527 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_B_FIELD );
528 break;
529 }
530
531 if(err) {
532 /* In case of error, return some reasonable values to avoid further
533 complications */
534 rz[0] = 1.0;
535 rz[1] = 0.0;
536 }
537
538 return err;
539}
a5err B_2DS_eval_psi(real *psi, real r, real phi, real z, B_2DS_data *Bdata)
Evaluate poloidal flux psi.
Definition B_2DS.c:158
a5err B_2DS_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_2DS_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_2DS.c:181
a5err B_2DS_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_2DS_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_2DS.c:212
a5err B_2DS_eval_B(real B[3], real r, real phi, real z, B_2DS_data *Bdata)
Evaluate magnetic field.
Definition B_2DS.c:250
void B_2DS_offload(B_2DS_data *data)
Offload data to the accelerator.
Definition B_2DS.c:137
void B_2DS_free(B_2DS_data *data)
Free allocated resources.
Definition B_2DS.c:125
a5err B_2DS_get_axis_rz(real rz[2], B_2DS_data *Bdata)
Return magnetic axis R-coordinate.
Definition B_2DS.c:365
a5err B_2DS_eval_B_dB(real B_dB[12], real r, real phi, real z, B_2DS_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_2DS.c:296
Header file for B_2DS.c.
a5err B_3DS_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_3DS.c:279
a5err B_3DS_eval_B(real B[3], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate magnetic field.
Definition B_3DS.c:317
a5err B_3DS_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_3DS.c:248
void B_3DS_free(B_3DS_data *data)
Free allocated resources.
Definition B_3DS.c:191
real psi0
Definition B_3DS.c:59
a5err B_3DS_get_axis_rz(real rz[2], B_3DS_data *Bdata)
Return magnetic axis R-coordinate.
Definition B_3DS.c:428
a5err B_3DS_eval_psi(real *psi, real r, real phi, real z, B_3DS_data *Bdata)
Evaluate poloidal flux psi.
Definition B_3DS.c:224
void B_3DS_offload(B_3DS_data *data)
Offload data to the accelerator.
Definition B_3DS.c:203
a5err B_3DS_eval_B_dB(real B_dB[12], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_3DS.c:364
real psi1
Definition B_3DS.c:60
Header file for B_3DS.c.
a5err B_GS_eval_psi(real *psi, real r, real phi, real z, B_GS_data *Bdata)
Evaluate poloidal flux psi.
Definition B_GS.c:174
a5err B_GS_eval_B(real B[3], real r, real phi, real z, B_GS_data *Bdata)
Evaluate magnetic field.
Definition B_GS.c:327
a5err B_GS_eval_B_dB(real B_dB[12], real r, real phi, real z, B_GS_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_GS.c:406
void B_GS_free(B_GS_data *data)
Free allocated resources.
Definition B_GS.c:150
a5err B_GS_get_axis_rz(real rz[2], B_GS_data *Bdata)
Return magnetic axis R-coordinate.
Definition B_GS.c:557
a5err B_GS_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_GS_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_GS.c:296
a5err B_GS_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_GS_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_GS.c:227
void B_GS_offload(B_GS_data *data)
Offload data to the accelerator.
Definition B_GS.c:159
Header file for B_GS.c.
void B_STS_offload(B_STS_data *data)
Offload data to the accelerator.
Definition B_STS.c:189
a5err B_STS_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_STS_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_STS.c:286
a5err B_STS_eval_B_dB(real B_dB[12], real r, real phi, real z, B_STS_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_STS.c:370
void B_STS_free(B_STS_data *data)
Free allocated resources.
Definition B_STS.c:177
a5err B_STS_eval_psi(real *psi, real r, real phi, real z, B_STS_data *Bdata)
Evaluate poloidal flux psi.
Definition B_STS.c:212
a5err B_STS_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_STS_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_STS.c:244
a5err B_STS_get_axis_rz(real rz[2], B_STS_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Definition B_STS.c:421
a5err B_STS_eval_B(real B[3], real r, real phi, real z, B_STS_data *Bdata)
Evaluate magnetic field.
Definition B_STS.c:335
Header file for B_STS.c.
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
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.
void B_field_offload(B_field_data *data)
Offload data to the accelerator.
Definition B_field.c:61
a5err B_field_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_field.c:166
a5err B_field_eval_rho(real rho[2], real psi, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its psi derivative.
Definition B_field.c:228
a5err B_field_eval_psi(real *psi, real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi.
Definition B_field.c:102
void B_field_free(B_field_data *data)
Free allocated resources.
Definition B_field.c:32
a5err B_field_eval_B_dB(real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_field.c:449
a5err B_field_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_field.c:312
a5err B_field_get_axis_rz(real rz[2], B_field_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Definition B_field.c:501
a5err B_field_eval_B(real B[3], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field.
Definition B_field.c:374
Header file for B_field.c.
@ B_field_type_2DS
Definition B_field.h:29
@ B_field_type_TC
Definition B_field.h:32
@ B_field_type_3DS
Definition B_field.h:30
@ B_field_type_STS
Definition B_field.h:31
@ B_field_type_GS
Definition B_field.h:28
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
@ EF_B_FIELD
Definition error.h:46
@ ERR_UNKNOWN_INPUT
Definition error.h:64
@ ERR_INPUT_UNPHYSICAL
Definition error.h:65
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
Macros for printing console output.
Magnetic field simulation data.
Definition B_field.h:41
B_STS_data BSTS
Definition B_field.h:46
B_TC_data BTC
Definition B_field.h:47
B_2DS_data B2DS
Definition B_field.h:44
B_field_type type
Definition B_field.h:42
B_GS_data BGS
Definition B_field.h:43
B_3DS_data B3DS
Definition B_field.h:45