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
41int E_1DS_init_offload(E_1DS_offload_data* offload_data, real** offload_array) {
42
43 /* Spline initialization. */
44 int err = 0;
45 real* dV_drho = (real*) malloc(NSIZE_COMP1D * offload_data->n_rho
46 * sizeof(real));
47 err += interp1Dcomp_init_coeff(dV_drho, *offload_array,
48 offload_data->n_rho,
50 offload_data->rho_min,
51 offload_data->rho_max);
52 if(err) {
53 print_err("Error: Failed to initialize splines.\n");
54 return err;
55 }
56
57 /* Free the offload array and replace it with the coefficient array */
58 free(*offload_array);
59 *offload_array = dV_drho;
60 offload_data->offload_array_length = NSIZE_COMP1D * offload_data->n_rho;
61
62 /* Print some sanity check on data */
63 print_out(VERBOSE_IO, "\nRadial electric field (E_1DS)");
64 print_out(VERBOSE_IO, "(n_rho, rho_min, rho_max) = (%d, %le, %le)\n",
65 offload_data->n_rho,offload_data->rho_min,
66 offload_data->rho_max);
67 return err;
68}
69
79 real** offload_array) {
80 free(*offload_array);
81 *offload_array = NULL;
82}
83
95void E_1DS_init(E_1DS_data* Edata, E_1DS_offload_data* offload_data,
96 real* offload_array) {
97 interp1Dcomp_init_spline(&Edata->dV, offload_array,
98 offload_data->n_rho,
100 offload_data->rho_min,
101 offload_data->rho_max);
102}
103
123 B_field_data* Bdata) {
124 a5err err = 0;
125 int interperr = 0; /* If error happened during interpolation */
126 real rho_drho[4];
127 err = B_field_eval_rho_drho(rho_drho, r, phi, z, Bdata);
128 if(err) {
129 return error_raise( ERR_INPUT_EVALUATION, __LINE__, EF_E_1DS );
130 }
131 /* Convert partial derivative to gradient */
132 rho_drho[2] = rho_drho[2]/r;
133 /* We set the field to zero if outside the profile. */
134 if (rho_drho[0] < Edata->dV.x_min || rho_drho[0] > Edata->dV.x_max ) {
135 E[0] = 0;
136 E[1] = 0;
137 E[2] = 0;
138 return err;
139 }
140 real dV;
141 interperr += interp1Dcomp_eval_f(&dV, &Edata->dV, rho_drho[0]);
142
143 E[0] = -dV * rho_drho[1];
144 E[1] = -dV * rho_drho[2];
145 E[2] = -dV * rho_drho[3];
146
147 if(interperr) {
148 err = error_raise( ERR_INPUT_EVALUATION, __LINE__, EF_E_1DS );
149 }
150
151 return err;
152}
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:410
Header file for B_field.c.
void E_1DS_free_offload(E_1DS_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition E_1DS.c:78
int E_1DS_init_offload(E_1DS_offload_data *offload_data, real **offload_array)
Initialize 1DS electric field data.
Definition E_1DS.c:41
void E_1DS_init(E_1DS_data *Edata, E_1DS_offload_data *offload_data, real *offload_array)
Initialize 1D spline electric field data struct on target.
Definition E_1DS.c:95
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:122
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
int interp1Dcomp_init_coeff(real *c, real *f, int n_x, int bc_x, real x_min, real x_max)
Calculate cubic spline interpolation coefficients for scalar 1D data.
a5err interp1Dcomp_eval_f(real *f, interp1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
void interp1Dcomp_init_spline(interp1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
Initialize a cubic spline.
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:63
1D spline electric field parameters on the target
Definition E_1DS.h:30
interp1D_data dV
Definition E_1DS.h:31
1D spline electric field parameters that will be offloaded to target
Definition E_1DS.h:20
int offload_array_length
Definition E_1DS.h:24
real x_min
Definition interp.h:59
real x_max
Definition interp.h:60