ASCOT5
Loading...
Searching...
No Matches
E_2DS.c
Go to the documentation of this file.
1
5#include <stdlib.h>
6#include "../ascot5.h"
7#include "../offload.h"
8#include "../print.h"
9#include "../error.h"
10#include "../spline/interp.h"
11#include "E_2DS.h"
12
13int E_2DS_init(E_2DS_data* data, int nr, real rmin, real rmax, int nz,
14 real zmin, real zmax, real* vpot) {
15
16 int err = 0;
17
18 /* Set up the splines */
19 err = interp2Dcomp_setup(&data->vpot, vpot, nr, nz, NATURALBC, NATURALBC,
20 rmin, rmax, zmin, zmax);
21
22 if(err) {
23 print_err("Error: Failed to initialize splines.\n");
24 return 1;
25 }
26
27 return 0;
28}
29
30
31void E_2DS_free(E_2DS_data* data) {
32 free(data->vpot.c);
33}
34
35
36void E_2DS_offload(E_2DS_data* data) {
37 GPU_MAP_TO_DEVICE(
38 data->vpot, data->vpot.c[0:data->vpot.n_x*data->vpot.n_y*NSIZE_COMP2D]
39 )
40}
41
42
43a5err E_2DS_eval_E(real E[3], real r, real z, E_2DS_data* Edata) {
44 real vdv[6];
45 int interperr = 0;
46 interperr += interp2Dcomp_eval_df(vdv, &Edata->vpot, r, z);
47
48 a5err err = 0;
49 if(interperr) {
50 err = error_raise( ERR_INPUT_EVALUATION, __LINE__, EF_E_2DS );
51 }
52
53 E[0] = -vdv[1];
54 E[1] = 0;
55 E[2] = -vdv[2];
56
57 return err;
58}
Header file for E_2DS.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
@ EF_E_2DS
Definition error.h:55
@ ERR_INPUT_EVALUATION
Definition error.h:65
Spline interpolation library.
int interp2Dcomp_setup(interp2D_data *str, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Set up splines to interpolate 2D scalar data.
@ NATURALBC
Definition interp.h:37
DECLARE_TARGET_END a5err interp2Dcomp_eval_df(real *f_df, interp2D_data *str, real x, real y)
Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
Macros for printing console output.
#define print_err(...)
Print to standard error.
Definition print.h:42
2D spline electric field parameters
Definition E_2DS.h:17
interp2D_data vpot
Definition E_2DS.h:18
real * c
Definition interp.h:79