ASCOT5
Loading...
Searching...
No Matches
hdf5_asigma.c
Go to the documentation of this file.
1
9#include <stdio.h>
10#include <stdlib.h>
11#include <hdf5.h>
12#include <hdf5_hl.h>
13#include "../ascot5.h"
14#include "../asigma.h"
16#include "hdf5_helpers.h"
17#include "hdf5_asigma.h"
18
19int hdf5_asigma_read_loc(hid_t f, asigma_loc_offload_data* offload_data,
20 real** offload_array, char* qid);
21
37 real** offload_array, char* qid) {
38
39 char path[256];
40 int err = 1;
41
42 /* Read data the QID corresponds to */
43 hdf5_gen_path("/asigma/asigma_loc_XXXXXXXXXX", qid, path);
44 if(hdf5_find_group(f, path) == 0) {
45 offload_data->type = asigma_type_loc;
46 err = hdf5_asigma_read_loc(f, &(offload_data->asigma_loc),
47 offload_array, qid);
48 }
49
50 /* Initialize if data was read succesfully */
51 if(!err) {
52 err = asigma_init_offload(offload_data, offload_array);
53 }
54
55 return err;
56}
57
69 real** offload_array, char* qid) {
71 #undef ASGMPATH
72 #define ASGMPATH "/asigma/asigma_loc_XXXXXXXXXX/"
74
75 /* Read number of reactions */
76 if (hdf5_read_int(ASGMPATH "nreac", &offload_data->N_reac,
77 f, qid, __FILE__, __LINE__) ) {return 1;}
78
79 /* Read dimensionalities to allow memory alloction for offload array */
80 if (hdf5_read_int(ASGMPATH "nenergy", offload_data->N_E,
81 f, qid, __FILE__, __LINE__) ) {return 1;}
82 if (hdf5_read_int(ASGMPATH "ndensity", offload_data->N_n,
83 f, qid, __FILE__, __LINE__) ) {return 1;}
84 if (hdf5_read_int(ASGMPATH "ntemperature", offload_data->N_T,
85 f, qid, __FILE__, __LINE__) ) {return 1;}
86
87 /* Helper variables for number of reactions and abscissa dimensions */
88 int N_reac = offload_data->N_reac;
89
90 /* Allocate data for the abscissa limits [Emin,Emax,nmin,nmax,Tmin,Tmax]
91 * and then for the actual data */
92 offload_data->offload_array_length = 6*N_reac;
93 for(int i_reac = 0; i_reac < N_reac; i_reac++) {
94 offload_data->offload_array_length +=
95 offload_data->N_E[i_reac] * offload_data->N_n[i_reac]
96 * offload_data->N_T[i_reac];
97 }
98 *offload_array = (real*) malloc(offload_data->offload_array_length
99 *sizeof(real));
100
101 real* E_min = &(*offload_array)[0*N_reac];
102 real* E_max = &(*offload_array)[1*N_reac];
103 real* n_min = &(*offload_array)[2*N_reac];
104 real* n_max = &(*offload_array)[3*N_reac];
105 real* T_min = &(*offload_array)[4*N_reac];
106 real* T_max = &(*offload_array)[5*N_reac];
107 real* sigma = &(*offload_array)[6*N_reac];
108
109 /* Read reaction identifiers, rest of abscissa parameters and
110 reaction data into the offload array*/
111 if (hdf5_read_int(ASGMPATH "z1", offload_data->z_1,
112 f, qid, __FILE__, __LINE__) ) {return 1;}
113 if (hdf5_read_int(ASGMPATH "a1", offload_data->a_1,
114 f, qid, __FILE__, __LINE__) ) {return 1;}
115 if (hdf5_read_int(ASGMPATH "z2", offload_data->z_2,
116 f, qid, __FILE__, __LINE__) ) {return 1;}
117 if (hdf5_read_int(ASGMPATH "a2", offload_data->a_2,
118 f, qid, __FILE__, __LINE__) ) {return 1;}
119 if (hdf5_read_int(ASGMPATH "reactype", offload_data->reac_type,
120 f, qid, __FILE__, __LINE__) ) {return 1;}
121
122 if (hdf5_read_double(ASGMPATH "energymin", E_min,
123 f, qid, __FILE__, __LINE__) ) {return 1;}
124 if (hdf5_read_double(ASGMPATH "energymax", E_max,
125 f, qid, __FILE__, __LINE__) ) {return 1;}
126 if (hdf5_read_double(ASGMPATH "densitymin", n_min,
127 f, qid, __FILE__, __LINE__) ) {return 1;}
128 if (hdf5_read_double(ASGMPATH "densitymax", n_max,
129 f, qid, __FILE__, __LINE__) ) {return 1;}
130 if (hdf5_read_double(ASGMPATH "temperaturemin", T_min,
131 f, qid, __FILE__, __LINE__) ) {return 1;}
132 if (hdf5_read_double(ASGMPATH "temperaturemax", T_max,
133 f, qid, __FILE__, __LINE__) ) {return 1;}
134 if( hdf5_read_double(ASGMPATH "sigma", sigma,
135 f, qid, __FILE__, __LINE__) ) {return 1;}
136
137 return 0;
138}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
int asigma_init_offload(asigma_offload_data *offload_data, real **offload_array)
Load atomic reaction data and prepare parameters.
Definition asigma.c:66
Header file for asigma.c.
@ asigma_type_loc
Definition asigma.h:24
Header file for asigma_loc.c.
int hdf5_asigma_init_offload(hid_t f, asigma_offload_data *offload_data, real **offload_array, char *qid)
Read atomic data from HDF5 file.
Definition hdf5_asigma.c:36
int hdf5_asigma_read_loc(hid_t f, asigma_loc_offload_data *offload_data, real **offload_array, char *qid)
Read atomic sigma data from HDF5 file.
Definition hdf5_asigma.c:68
Header file for hdf5_asigma.c.
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.
Local-files atomic reaction offload data.
Definition asigma_loc.h:15
int a_2[MAX_ATOMIC]
Definition asigma_loc.h:20
int z_1[MAX_ATOMIC]
Definition asigma_loc.h:17
int reac_type[MAX_ATOMIC]
Definition asigma_loc.h:24
int N_n[MAX_ATOMIC]
Definition asigma_loc.h:22
int a_1[MAX_ATOMIC]
Definition asigma_loc.h:18
int N_E[MAX_ATOMIC]
Definition asigma_loc.h:21
int z_2[MAX_ATOMIC]
Definition asigma_loc.h:19
int N_T[MAX_ATOMIC]
Definition asigma_loc.h:23
Atomic reaction offload data.
Definition asigma.h:53
asigma_type type
Definition asigma.h:54
asigma_loc_offload_data asigma_loc
Definition asigma.h:55