ASCOT5
Loading...
Searching...
No Matches
hdf5_neutral.c
Go to the documentation of this file.
1
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <hdf5.h>
13#include <hdf5_hl.h>
14#include "../ascot5.h"
15#include "../neutral.h"
16#include "../neutral/N0_1D.h"
17#include "../neutral/N0_3D.h"
18#include "../consts.h"
19#include "../math.h"
20#include "hdf5_neutral.h"
21#include "hdf5_helpers.h"
22
23#define NPATH
25int hdf5_neutral_read_1D(hid_t f, N0_1D_offload_data* offload_data,
26 real** offload_array, char* qid);
27int hdf5_neutral_read_3D(hid_t f, N0_3D_offload_data* offload_data,
28 real** offload_array, char* qid);
29
43 real** offload_array, char* qid) {
44
45 char path[256];
46 int err = 1;
47
48 /* Read data the QID corresponds to */
49
50 hdf5_gen_path("/neutral/N0_1D_XXXXXXXXXX", qid, path);
51 if( !hdf5_find_group(f, path) ) {
52 offload_data->type = neutral_type_1D;
53 err = hdf5_neutral_read_1D(f, &(offload_data->N01D),
54 offload_array, qid);
55 }
56
57 hdf5_gen_path("/neutral/N0_3D_XXXXXXXXXX", qid, path);
58 if( !hdf5_find_group(f, path) ) {
59 offload_data->type = neutral_type_3D;
60 err = hdf5_neutral_read_3D(f, &(offload_data->N03D),
61 offload_array, qid);
62 }
63
64 /* Initialize if data was read succesfully */
65 if(!err) {
66 err = neutral_init_offload(offload_data, offload_array);
67 }
68
69 return err;
70}
71
85int hdf5_neutral_read_1D(hid_t f, N0_1D_offload_data* offload_data,
86 real** offload_array, char* qid) {
87 #undef NPATH
88 #define NPATH "/neutral/N0_1D_XXXXXXXXXX/"
89
90 /* Read and initialize rho coordinate */
91 if( hdf5_read_int(NPATH "nrho", &(offload_data->n_rho),
92 f, qid, __FILE__, __LINE__) ) {return 1;}
93 if( hdf5_read_double(NPATH "rhomin", &(offload_data->rho_min),
94 f, qid, __FILE__, __LINE__) ) {return 1;}
95 if( hdf5_read_double(NPATH "rhomax", &(offload_data->rho_max),
96 f, qid, __FILE__, __LINE__) ) {return 1;}
97
98 /* Read n_species, anum, znum and distribution type */
99 if( hdf5_read_int(NPATH "nspecies", &(offload_data->n_species),
100 f, qid, __FILE__, __LINE__) ) {return 1;}
101 if( hdf5_read_int(NPATH "anum", offload_data->anum,
102 f, qid, __FILE__, __LINE__) ) {return 1;}
103 if( hdf5_read_int(NPATH "znum", offload_data->znum,
104 f, qid, __FILE__, __LINE__) ) {return 1;}
105 if( hdf5_read_int(NPATH "maxwellian", offload_data->maxwellian,
106 f, qid, __FILE__, __LINE__) ) {return 1;}
107
108 int N0_size = offload_data->n_rho;
109 int T0_size = offload_data->n_rho;
110
111 *offload_array = (real*) malloc(offload_data->n_species
112 * (N0_size + T0_size)
113 * sizeof(real));
114
115 /* Pointers to beginning of different data series to make code more
116 * readable */
117 real* n0 = &(*offload_array)[0];
118 real* t0 = &(*offload_array)[offload_data->n_species * N0_size];
119
120 /* Read the neutral density and temperature */
121 if( hdf5_read_double(NPATH "density", n0,
122 f, qid, __FILE__, __LINE__) ) {return 1;}
123 if( hdf5_read_double(NPATH "temperature", t0,
124 f, qid, __FILE__, __LINE__) ) {return 1;}
125
126 for(int i = 0; i < offload_data->n_species * T0_size; i++) {
127 t0[i] = t0[i] * CONST_E;
128 }
129
130 return 0;
131}
132
146int hdf5_neutral_read_3D(hid_t f, N0_3D_offload_data* offload_data,
147 real** offload_array, char* qid) {
148 #undef NPATH
149 #define NPATH "/neutral/N0_3D_XXXXXXXXXX/"
150
151 /* Read and initialize Rpz-grid */
152 if( hdf5_read_int(NPATH "nr", &(offload_data->n_r),
153 f, qid, __FILE__, __LINE__) ) {return 1;}
154 if( hdf5_read_int(NPATH "nphi", &(offload_data->n_phi),
155 f, qid, __FILE__, __LINE__) ) {return 1;}
156 if( hdf5_read_int(NPATH "nz", &(offload_data->n_z),
157 f, qid, __FILE__, __LINE__) ) {return 1;}
158 if( hdf5_read_double(NPATH "rmin", &(offload_data->r_min),
159 f, qid, __FILE__, __LINE__) ) {return 1;}
160 if( hdf5_read_double(NPATH "rmax", &(offload_data->r_max),
161 f, qid, __FILE__, __LINE__) ) {return 1;}
162 if( hdf5_read_double(NPATH "phimin", &(offload_data->phi_min),
163 f, qid, __FILE__, __LINE__) ) {return 1;}
164 if( hdf5_read_double(NPATH "phimax", &(offload_data->phi_max),
165 f, qid, __FILE__, __LINE__) ) {return 1;}
166 if( hdf5_read_double(NPATH "zmin", &(offload_data->z_min),
167 f, qid, __FILE__, __LINE__) ) {return 1;}
168 if( hdf5_read_double(NPATH "zmax", &(offload_data->z_max),
169 f, qid, __FILE__, __LINE__) ) {return 1;}
170
171 /* Convert to radians */
172 offload_data->phi_max = math_deg2rad(offload_data->phi_max);
173 offload_data->phi_min = math_deg2rad(offload_data->phi_min);
174
175 /* Read n_species, anum, znum and distribution type */
176 if( hdf5_read_int(NPATH "nspecies", &(offload_data->n_species),
177 f, qid, __FILE__, __LINE__) ) {return 1;}
178 if( hdf5_read_int(NPATH "anum", offload_data->anum,
179 f, qid, __FILE__, __LINE__) ) {return 1;}
180 if( hdf5_read_int(NPATH "znum", offload_data->znum,
181 f, qid, __FILE__, __LINE__) ) {return 1;}
182 if( hdf5_read_int(NPATH "maxwellian", offload_data->maxwellian,
183 f, qid, __FILE__, __LINE__) ) {return 1;}
184
185 int N0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
186 int T0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
187
188 *offload_array = (real*) malloc(
189 offload_data->n_species * (N0_size + T0_size) * sizeof(real));
190
191 /* Pointers to beginning of different data series to make code more
192 * readable */
193 real* n0 = &(*offload_array)[0];
194 real* t0 = &(*offload_array)[offload_data->n_species * N0_size];
195
196 /* Read the neutral density and temperature */
197 if( hdf5_read_double(NPATH "density", n0,
198 f, qid, __FILE__, __LINE__) ) {return 1;}
199 if( hdf5_read_double(NPATH "temperature", t0,
200 f, qid, __FILE__, __LINE__) ) {return 1;}
201
202 for(int i = 0; i < offload_data->n_species * T0_size; i++) {
203 t0[i] = t0[i] * CONST_E;
204 }
205
206 return 0;
207}
Header file for N0_1D.c.
Header file for N0_3D.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file containing physical and mathematical constants.
#define CONST_E
Elementary charge [C]
Definition consts.h:32
herr_t hdf5_find_group(hid_t loc, const char *path)
Checks if given group exists within given hdf5 file. Negative value is returned if the group doesn't ...
int hdf5_read_double(const char *var, real *ptr, hid_t file, char *qid, const char *errfile, int errline)
Read double-valued data from ASCOT5 HDF5 file.
char * hdf5_gen_path(const char *original, char *qid, char *path)
Generate a valid path from a given template and qid.
int hdf5_read_int(const char *var, int *ptr, hid_t file, char *qid, const char *errfile, int errline)
Read int-valued data from ASCOT5 HDF5 file.
Header file for hdf5_helpers.h.
int hdf5_neutral_init_offload(hid_t f, neutral_offload_data *offload_data, real **offload_array, char *qid)
Initialize neutral data from HDF5 file.
int hdf5_neutral_read_1D(hid_t f, N0_1D_offload_data *offload_data, real **offload_array, char *qid)
Load neutral data from HDF5 file and prepare parameters.
int hdf5_neutral_read_3D(hid_t f, N0_3D_offload_data *offload_data, real **offload_array, char *qid)
Load neutral data from HDF5 file and prepare parameters.
#define NPATH
Header file for hdf5_neutral.c.
Header file for math.c.
#define math_deg2rad(a)
Convert degrees to radians.
Definition math.h:107
int neutral_init_offload(neutral_offload_data *offload_data, real **offload_array)
Load neutral data and prepare parameters.
Definition neutral.c:41
Header file for neutral.c.
@ neutral_type_1D
Definition neutral.h:24
@ neutral_type_3D
Definition neutral.h:25
1D neutral parameters on the host
Definition N0_1D.h:13
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
3D neutral parameters on the host
Definition N0_3D.h:13
int znum[MAX_SPECIES]
Definition N0_3D.h:25
int maxwellian[MAX_SPECIES]
Definition N0_3D.h:26
int anum[MAX_SPECIES]
Definition N0_3D.h:24
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