ASCOT5
Loading...
Searching...
No Matches
N0_1D.c
Go to the documentation of this file.
1
5#include <stdlib.h>
6#include <stdio.h>
7#include <math.h>
8#include <string.h>
9#include "../math.h"
10#include "../ascot5.h"
11#include "../error.h"
12#include "../print.h"
13#include "N0_1D.h"
14#include "../linint/linint.h"
15
30int N0_1D_init(N0_1D_data* data, int n_rho, real rho_min, real rho_max,
31 int n_species, int* anum, int* znum, int* maxwellian,
32 real* density, real* temperature) {
33
34 data->n_species = n_species;
35 data->anum = (int*) malloc(n_species * sizeof(int));
36 data->znum = (int*) malloc(n_species * sizeof(int));
37 data->maxwellian = (int*) malloc(n_species * sizeof(int));
38 data->n0 = (linint1D_data*) malloc( n_species * sizeof(linint1D_data) );
39 data->t0 = (linint1D_data*) malloc( n_species * sizeof(linint1D_data) );
40 for(int i = 0; i < data->n_species; i++) {
41 data->anum[i] = anum[i];
42 data->znum[i] = znum[i];
43 data->maxwellian[i] = maxwellian[i];
44
45 real* c = (real*) malloc(n_rho * sizeof(real));
46 for(int i = 0; i < n_rho; i++) {
47 c[i] = density[i];
48 }
49 linint1D_init(&data->n0[i], c, n_rho, NATURALBC, rho_min, rho_max);
50 c = (real*) malloc(n_rho * sizeof(real));
51 for(int i = 0; i < n_rho; i++) {
52 c[i] = temperature[i];
53 }
54 linint1D_init(&data->t0[i], c, n_rho, NATURALBC, rho_min, rho_max);
55 }
56
57 print_out(VERBOSE_IO, "\n1D neutral density and temperature (N0_1D)\n");
59 "Grid: nrho = %4.d rhomin = %3.3f rhomax = %3.3f\n",
60 n_rho, rho_min, rho_max);
61 print_out(VERBOSE_IO, " Number of neutral species = %d\n", data->n_species);
62 print_out(VERBOSE_IO, "Species Z/A (Maxwellian)\n");
63 for(int i=0; i < data->n_species; i++) {
65 " %3d/%3d (%1d) \n",
66 (int)(data->znum[i]),
67 (int)(data->anum[i]),
68 (int)(data->maxwellian[i]));
69 }
70
71 return 0;
72}
73
80 free(data->anum);
81 free(data->znum);
82 free(data->maxwellian);
83 for(int i = 0; i < data->n_species; i++) {
84 free(data->n0->c);
85 free(data->t0->c);
86 }
87}
88
95 //TODO: Implement
96}
97
111 a5err err = 0;
112 int interperr = 0; /* If error happened during interpolation */
113 for(int i=0; i<ndata->n_species; i++) {
114 interperr += linint1D_eval_f(&n0[i], &ndata->n0[i], rho);
115 }
116
117 if(interperr) {
118 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_1D);
119 }
120
121 return err;
122}
123
137 a5err err = 0;
138 int interperr = 0; /* If error happened during interpolation */
139 for(int i=0; i<ndata->n_species; i++) {
140 interperr += linint1D_eval_f(&t0[i], &ndata->t0[i], rho);
141 }
142
143 if(interperr) {
144 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_1D);
145 }
146
147 return err;
148}
149
158 return ndata->n_species;
159}
void N0_1D_offload(N0_1D_data *data)
Offload data to the accelerator.
Definition N0_1D.c:94
int N0_1D_init(N0_1D_data *data, int n_rho, real rho_min, real rho_max, int n_species, int *anum, int *znum, int *maxwellian, real *density, real *temperature)
Initialize data.
Definition N0_1D.c:30
void N0_1D_free(N0_1D_data *data)
Free allocated resources.
Definition N0_1D.c:79
a5err N0_1D_eval_n0(real *n0, real rho, N0_1D_data *ndata)
Evaluate neutral density.
Definition N0_1D.c:110
a5err N0_1D_eval_t0(real *t0, real rho, N0_1D_data *ndata)
Evaluate neutral temperature.
Definition N0_1D.c:136
int N0_1D_get_n_species(N0_1D_data *ndata)
Return number of neutral species.
Definition N0_1D.c:157
Header file for N0_1D.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_N0_1D
Definition error.h:33
@ 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
@ NATURALBC
Definition interp.h:37
Linear interpolation library.
int linint1D_eval_f(real *f, linint1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
Definition linint1D.c:47
void linint1D_init(linint1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
Initialize linear interpolation struct for scalar 1D data.
Definition linint1D.c:22
Header file for math.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
1D neutral parameters on the target
Definition N0_1D.h:14
int n_species
Definition N0_1D.h:15
int * anum
Definition N0_1D.h:16
linint1D_data * n0
Definition N0_1D.h:20
int * znum
Definition N0_1D.h:17
linint1D_data * t0
Definition N0_1D.h:21
int * maxwellian
Definition N0_1D.h:18
1D interpolation struct.
Definition linint.h:21
real * c
Definition linint.h:27