28#define PLASMA_1DS_NONEG 1
31#define PLASMA_1DS_LOG 1
34#define PLASMA_1DS_SQRT 2
44 int nion,
int* anum,
int* znum,
real* mass,
real* charge,
48 data->
anum = (
int*) malloc( nion*
sizeof(
int) );
49 data->
znum = (
int*) malloc( nion*
sizeof(
int) );
52 for(
int i = 0; i < data->
n_species; i++) {
54 data->
znum[i] = znum[i];
55 data->
anum[i] = anum[i];
57 data->
mass[i] = mass[i];
58 data->
charge[i] = charge[i];
64 real* ni_scaled = (
real*) malloc( nion*nrho*
sizeof(
real) );
65 for(
int i=0; i < nrho; i++) {
66#if PLASMA_1DS_NONEG == PLASMA_1DS_LOG
67 Te_scaled[i] = log(Te[i]);
68 Ti_scaled[i] = log(Ti[i]);
69 ne_scaled[i] = log(ne[i]);
70 for(
int j = 0; j < nion; j++) {
71 ni_scaled[j*nrho + i] = log(ni[j*nrho + i]);
73#elif PLASMA_1DS_NONEG == PLASMA_1DS_SQRT
74 Te_scaled[i] = sqrt(Te[i]);
75 Ti_scaled[i] = sqrt(Ti[i]);
76 ne_scaled[i] = sqrt(ne[i]);
77 for(
int j = 0; j < nion; j++) {
78 ni_scaled[j*nrho + i] = sqrt(ni[j*nrho + i]);
85 print_err(
"Error: Failed to initialize splines.\n");
95 print_err(
"Error: Failed to initialize splines.\n");
107 print_err(
"Error: Failed to initialize splines.\n");
115 for(
int i = 0; i < nion; i++) {
119 print_err(
"Error: Failed to initialize splines.\n");
135 "Min rho = %1.2le, Max rho = %1.2le,"
136 " Number of rho grid points = %d,"
137 " Number of ion species = %d\n",
138 rhomin, rhomax, nrho, nion);
140 "Species Z/A charge [e]/mass [amu] Density [m^-3] at Min/Max rho"
141 " Temperature [eV] at Min/Max rho\n");
143 for(
int i=0; i < nion; i++) {
149 " %3d /%3d %3d /%7.3f %1.2le/%1.2le "
162 "[electrons] %3d /%7.3f %1.2le/%1.2le "
165 real quasineutrality = 0;
166 for(
int k = 0; k < nrho; k++) {
167 real rho = rhomin + k * (rhomax - rhomin) / (nrho - 1);
171 for(
int i=0; i < nion; i++) {
175 quasineutrality = fmax( quasineutrality,
176 fabs( 1 - ion_qdens / ele_qdens ) );
179 " %.2f\n", 1+quasineutrality);
194 for(
int i = 0; i < data->
n_species; i++) {
195 free(data->
dens[i].
c);
213 for (
int i = 0; i < data->
n_species; i++) {
214 GPU_MAP_TO_DEVICE( data->
dens[i].
c[0:data->
dens[i].
n_x*NSIZE_COMP1D] )
238#if PLASMA_1DS_NONEG == PLASMA_1DS_LOG
240#elif PLASMA_1DS_NONEG == PLASMA_1DS_SQRT
241 *temp = (*temp) * (*temp);
243 if(!err && *temp < 0){
270#if PLASMA_1DS_NONEG == PLASMA_1DS_LOG
272#elif PLASMA_1DS_NONEG == PLASMA_1DS_SQRT
273 *dens = (*dens) * (*dens);
275 if(!err && *dens < 0){
314#if PLASMA_1DS_NONEG == PLASMA_1DS_LOG
316 dens[i] = exp(dens[i]);
317 temp[i] = exp(temp[i]);
319#elif PLASMA_1DS_NONEG == PLASMA_1DS_SQRT
321 dens[i] = dens[i]*dens[i];
322 temp[i] = temp[i]*temp[i];
326 if(!err && (dens[i] < 0 || temp[i] < 0) ) {
Main header file for ASCOT5.
Header file containing physical and mathematical constants.
#define CONST_U
Atomic mass unit in kilograms [kg]
#define CONST_M_E
Electron mass [kg]
#define CONST_E
Elementary charge [C]
unsigned long int a5err
Simulation error flag.
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Spline interpolation library.
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.
a5err plasma_1DS_eval_densandtemp(real *dens, real *temp, real rho, plasma_1DS_data *plasma_data)
Evaluate plasma density and temperature for all species.
int plasma_1DS_init(plasma_1DS_data *data, int nrho, real rhomin, real rhomax, int nion, int *anum, int *znum, real *mass, real *charge, real *Te, real *Ti, real *ne, real *ni)
Initialize 1DS plasma data and check inputs.
a5err plasma_1DS_eval_dens(real *dens, real rho, int species, plasma_1DS_data *plasma_data)
Evaluate plasma density.
void plasma_1DS_free(plasma_1DS_data *data)
Free allocated resources.
a5err plasma_1DS_eval_temp(real *temp, real rho, int species, plasma_1DS_data *plasma_data)
Evaluate plasma temperature.
void plasma_1DS_offload(plasma_1DS_data *data)
Offload data to the accelerator.
Header file for plasma_1DS.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
#define print_err(...)
Print to standard error.
Cubic interpolation struct.
1D spline plasma parameters on the target