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
25 real** offload_array) {
26 int N0_size = offload_data->n_rho;
27 int T0_size = offload_data->n_rho;
28
29 offload_data->offload_array_length = offload_data->n_species * N0_size
30 + offload_data->n_species * T0_size;
31
32 print_out(VERBOSE_IO, "\n1D neutral density and temperature (N0_1D)\n");
33 print_out(VERBOSE_IO, "Grid: nrho = %4.d rhomin = %3.3f rhomax = %3.3f\n",
34 offload_data->n_rho,
35 offload_data->rho_min, offload_data->rho_max);
37 " Number of neutral species = %d\n",
38 offload_data->n_species);
40 "Species Z/A (Maxwellian)\n");
41 for(int i=0; i < offload_data->n_species; i++) {
43 " %3d/%3d (%1d) \n",
44 (int)(offload_data->znum[i]),
45 (int)(offload_data->anum[i]),
46 (int)(offload_data->maxwellian[i]));
47 }
48
49 return 0;
50}
51
61 real** offload_array) {
62 free(*offload_array);
63 *offload_array = NULL;
64}
65
80void N0_1D_init(N0_1D_data* ndata, N0_1D_offload_data* offload_data,
81 real* offload_array) {
82 int N0_size = offload_data->n_rho;
83 int T0_size = offload_data->n_rho;
84 ndata->n_species = offload_data->n_species;
85 for(int i = 0; i < offload_data->n_species; i++) {
86 ndata->anum[i] = offload_data->anum[i];
87 ndata->znum[i] = offload_data->znum[i];
88 ndata->maxwellian[i] = offload_data->maxwellian[i];
89
91 &ndata->n0[i], &offload_array[i * N0_size],
92 offload_data->n_rho, NATURALBC,
93 offload_data->rho_min, offload_data->rho_max);
94
96 &ndata->t0[i],
97 &offload_array[i * T0_size + offload_data->n_species * N0_size],
98 offload_data->n_rho, NATURALBC,
99 offload_data->rho_min, offload_data->rho_max);
100 }
101}
102
116 a5err err = 0;
117 int interperr = 0; /* If error happened during interpolation */
118 for(int i=0; i<ndata->n_species; i++) {
119 interperr += linint1D_eval_f(&n0[i], &ndata->n0[i], rho);
120 }
121
122 if(interperr) {
123 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_1D);
124 }
125
126 return err;
127}
128
142 a5err err = 0;
143 int interperr = 0; /* If error happened during interpolation */
144 for(int i=0; i<ndata->n_species; i++) {
145 interperr += linint1D_eval_f(&t0[i], &ndata->t0[i], rho);
146 }
147
148 if(interperr) {
149 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_1D);
150 }
151
152 return err;
153}
154
163 return ndata->n_species;
164}
int N0_1D_init_offload(N0_1D_offload_data *offload_data, real **offload_array)
Initialize offload data.
Definition N0_1D.c:24
a5err N0_1D_eval_n0(real *n0, real rho, N0_1D_data *ndata)
Evaluate neutral density.
Definition N0_1D.c:115
void N0_1D_free_offload(N0_1D_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition N0_1D.c:60
a5err N0_1D_eval_t0(real *t0, real rho, N0_1D_data *ndata)
Evaluate neutral temperature.
Definition N0_1D.c:141
void N0_1D_init(N0_1D_data *ndata, N0_1D_offload_data *offload_data, real *offload_array)
Initialize neutral data on target.
Definition N0_1D.c:80
int N0_1D_get_n_species(N0_1D_data *ndata)
Return number of neutral species.
Definition N0_1D.c:162
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:28
int n_species
Definition N0_1D.h:29
int znum[MAX_SPECIES]
Definition N0_1D.h:31
int anum[MAX_SPECIES]
Definition N0_1D.h:30
linint1D_data t0[MAX_SPECIES]
Definition N0_1D.h:36
int maxwellian[MAX_SPECIES]
Definition N0_1D.h:32
linint1D_data n0[MAX_SPECIES]
Definition N0_1D.h:34
1D neutral parameters on the host
Definition N0_1D.h:13
int offload_array_length
Definition N0_1D.h:22
int maxwellian[MAX_SPECIES]
Definition N0_1D.h:20
int znum[MAX_SPECIES]
Definition N0_1D.h:19
int anum[MAX_SPECIES]
Definition N0_1D.h:18