ASCOT5
Loading...
Searching...
No Matches
E_1DS.c
Go to the documentation of this file.
1
8#include <stdio.h>
9#include <stdlib.h>
10#include "../ascot5.h"
11#include "../error.h"
12#include "../print.h"
13#include "../B_field.h"
14#include "../spline/interp.h"
15#include "E_1DS.h"
16
29int E_1DS_init(E_1DS_data* data, int nrho, real rhomin, real rhomax, real reff,
30 real* dvdrho) {
31
32 int err = 0;
33 /* Scale derivatives by effective minor radius */
34 real* temp = (real*) malloc( nrho * sizeof(real) );
35 for(int i = 0; i < nrho; i++) {
36 temp[i] = reff * dvdrho[i];
37 }
38 err = interp1Dcomp_setup(&data->dV, dvdrho, nrho, NATURALBC,
39 rhomin, rhomax);
40 free(temp);
41 if(err) {
42 print_err("Error: Failed to initialize splines.\n");
43 return err;
44 }
45
46 /* Print some sanity check on data */
47 print_out(VERBOSE_IO, "\nRadial electric field (E_1DS)");
48 print_out(VERBOSE_IO, "(n_rho, rho_min, rho_max) = (%d, %le, %le)\n",
49 nrho, rhomin, rhomax);
50 return err;
51}
52
59 free(data->dV.c);
60}
61
68 GPU_MAP_TO_DEVICE( data->dV, data->dV.c[0:data->dV.n_x*NSIZE_COMP1D] )
69}
70
89a5err E_1DS_eval_E(real E[3], real r, real phi, real z, E_1DS_data* Edata,
90 B_field_data* Bdata) {
91 a5err err = 0;
92 int interperr = 0; /* If error happened during interpolation */
93 real rho_drho[4];
94 err = B_field_eval_rho_drho(rho_drho, r, phi, z, Bdata);
95 if(err) {
96 return error_raise( ERR_INPUT_EVALUATION, __LINE__, EF_E_1DS );
97 }
98 /* Convert partial derivative to gradient */
99 rho_drho[2] = rho_drho[2]/r;
100 /* We set the field to zero if outside the profile. */
101 if (rho_drho[0] < Edata->dV.x_min || rho_drho[0] > Edata->dV.x_max ) {
102 E[0] = 0;
103 E[1] = 0;
104 E[2] = 0;
105 return err;
106 }
107 real dV;
108 interperr += interp1Dcomp_eval_f(&dV, &Edata->dV, rho_drho[0]);
109
110 E[0] = -dV * rho_drho[1];
111 E[1] = -dV * rho_drho[2];
112 E[2] = -dV * rho_drho[3];
113
114 if(interperr) {
115 err = error_raise( ERR_INPUT_EVALUATION, __LINE__, EF_E_1DS );
116 }
117
118 return err;
119}
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
Header file for B_field.c.
void E_1DS_free(E_1DS_data *data)
Free allocated resources.
Definition E_1DS.c:58
void E_1DS_offload(E_1DS_data *data)
Offload data to the accelerator.
Definition E_1DS.c:67
int E_1DS_init(E_1DS_data *data, int nrho, real rhomin, real rhomax, real reff, real *dvdrho)
Initialize 1DS electric field data.
Definition E_1DS.c:29
a5err E_1DS_eval_E(real E[3], real r, real phi, real z, E_1DS_data *Edata, B_field_data *Bdata)
Evaluate 1D spline radial electric field.
Definition E_1DS.c:89
Header file for E_1DS.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_1DS
Definition error.h:45
@ ERR_INPUT_EVALUATION
Definition error.h:63
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
Spline interpolation library.
@ NATURALBC
Definition interp.h:37
a5err interp1Dcomp_eval_f(real *f, interp1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
int interp1Dcomp_setup(interp1D_data *str, real *f, int n_x, int bc_x, real x_min, real x_max)
Set up splines to interpolate 1D scalar data.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
#define print_err(...)
Print to standard error.
Definition print.h:42
Magnetic field simulation data.
Definition B_field.h:41
1D spline electric field parameters on the target
Definition E_1DS.h:20
interp1D_data dV
Definition E_1DS.h:21
real x_min
Definition interp.h:59
real x_max
Definition interp.h:60
real * c
Definition interp.h:62