ASCOT5
Loading...
Searching...
No Matches
neutral.c
Go to the documentation of this file.
1
16#include <stdio.h>
17#include "ascot5.h"
18#include "error.h"
19#include "print.h"
20#include "neutral.h"
21#include "neutral/N0_1D.h"
22#include "neutral/N0_3D.h"
23
42 real** offload_array) {
43 int err = 0;
44
45 switch(offload_data->type) {
46 case neutral_type_1D:
47 err = N0_1D_init_offload(&(offload_data->N01D), offload_array);
48 offload_data->offload_array_length =
49 offload_data->N01D.offload_array_length;
50 break;
51 case neutral_type_3D:
52 err = N0_3D_init_offload(&(offload_data->N03D), offload_array);
53 offload_data->offload_array_length =
54 offload_data->N03D.offload_array_length;
55 break;
56 default:
57 /* Unregonized input. Produce error. */
58 print_err("Error: Unregonized neutral data type.");
59 err = 1;
60 break;
61 }
62 if(!err) {
63 print_out(VERBOSE_IO, "Estimated memory usage %.1f MB\n",
64 offload_data->offload_array_length
65 * sizeof(real) / (1024.0*1024.0) );
66 }
67
68 return err;
69}
70
82 real** offload_array) {
83 switch(offload_data->type) {
84 case neutral_type_1D:
85 N0_1D_free_offload(&(offload_data->N01D), offload_array);
86 break;
87 case neutral_type_3D:
88 N0_3D_free_offload(&(offload_data->N03D), offload_array);
89 break;
90 }
91}
92
107 real* offload_array) {
108 int err = 0;
109
110 switch(offload_data->type) {
111 case neutral_type_1D:
112 N0_1D_init(&(ndata->N01D),
113 &(offload_data->N01D), offload_array);
114 break;
115 case neutral_type_3D:
116 N0_3D_init(&(ndata->N03D),
117 &(offload_data->N03D), offload_array);
118 break;
119 default:
120 /* Unregonized input. Produce error. */
121 print_err("Error: Unregonized neutral data type.\n");
122 err = 1;
123 break;
124 }
125 ndata->type = offload_data->type;
126
127 return err;
128}
129
148 neutral_data* ndata) {
149 a5err err = 0;
150
151 switch(ndata->type) {
152 case neutral_type_1D:
153 err = N0_1D_eval_n0(n0, rho, &(ndata->N01D));
154 break;
155 case neutral_type_3D:
156 err = N0_3D_eval_n0(n0, r, phi, z, &(ndata->N03D));
157 break;
158 default:
159 /* Unregonized input. Produce error. */
160 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_NEUTRAL);
161 break;
162 }
163
164 if(err) {
165 /* Return some reasonable values to avoid further errors */
166 n0[0] = 0;
167 }
168
169 return err;
170}
171
190 neutral_data* ndata) {
191 a5err err = 0;
192
193 switch(ndata->type) {
194 case neutral_type_1D:
195 err = N0_1D_eval_t0(t0, rho, &(ndata->N01D));
196 break;
197 case neutral_type_3D:
198 err = N0_3D_eval_t0(t0, r, phi, z, &(ndata->N03D));
199 break;
200 default:
201 /* Unregonized input. Produce error. */
202 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_NEUTRAL);
203 break;
204 }
205
206 if(err) {
207 /* Return some reasonable values to avoid further errors */
208 t0[0] = 1;
209 }
210
211 return err;
212}
213
226 int n = 0;
227 switch(ndata->type) {
228 case neutral_type_1D:
229 n = N0_1D_get_n_species(&(ndata->N01D));
230 break;
231 case neutral_type_3D:
232 n = N0_3D_get_n_species(&(ndata->N03D));
233 break;
234 }
235
236 return n;
237}
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.
a5err N0_3D_eval_n0(real *n0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral density.
Definition N0_3D.c:129
int N0_3D_get_n_species(N0_3D_data *ndata)
Return number of neutral species.
Definition N0_3D.c:178
void N0_3D_free_offload(N0_3D_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition N0_3D.c:66
a5err N0_3D_eval_t0(real *t0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral temperature.
Definition N0_3D.c:157
void N0_3D_init(N0_3D_data *ndata, N0_3D_offload_data *offload_data, real *offload_array)
Initialize neutral data on target.
Definition N0_3D.c:86
int N0_3D_init_offload(N0_3D_offload_data *offload_data, real **offload_array)
Initialize offload data.
Definition N0_3D.c:24
Header file for N0_3D.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_NEUTRAL
Definition error.h:44
@ ERR_UNKNOWN_INPUT
Definition error.h:64
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
int neutral_init_offload(neutral_offload_data *offload_data, real **offload_array)
Load neutral data and prepare parameters.
Definition neutral.c:41
int neutral_get_n_species(neutral_data *ndata)
Get the number of neutral species.
Definition neutral.c:225
void neutral_free_offload(neutral_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition neutral.c:81
int neutral_init(neutral_data *ndata, neutral_offload_data *offload_data, real *offload_array)
Initialize neutral data struct on target.
Definition neutral.c:106
a5err neutral_eval_n0(real *n0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral density.
Definition neutral.c:147
a5err neutral_eval_t0(real *t0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral temperature.
Definition neutral.c:189
Header file for neutral.c.
@ neutral_type_1D
Definition neutral.h:24
@ neutral_type_3D
Definition neutral.h:25
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
int offload_array_length
Definition N0_1D.h:22
int offload_array_length
Definition N0_3D.h:28
Neutral simulation data.
Definition neutral.h:53
N0_1D_data N01D
Definition neutral.h:55
N0_3D_data N03D
Definition neutral.h:56
neutral_type type
Definition neutral.h:54
Neutral offload data.
Definition neutral.h:37
N0_1D_offload_data N01D
Definition neutral.h:39
N0_3D_offload_data N03D
Definition neutral.h:40
neutral_type type
Definition neutral.h:38