ASCOT5
Loading...
Searching...
No Matches
hdf5_mhd.c
Go to the documentation of this file.
1
6#include <stdlib.h>
7#include <hdf5.h>
8#include <hdf5_hl.h>
9#include "../ascot5.h"
10#include "../mhd.h"
11#include "../mhd/mhd_stat.h"
12#include "../mhd/mhd_nonstat.h"
13#include "hdf5_helpers.h"
14#include "hdf5_mhd.h"
15
16#define MHDPATH
18int hdf5_mhd_read_stat(hid_t f, mhd_stat_offload_data* offload_data,
19 real** offload_array, char* qid);
20int hdf5_mhd_read_nonstat(hid_t f, mhd_nonstat_offload_data* offload_data,
21 real** offload_array, char* qid);
22
35int hdf5_mhd_init_offload(hid_t f, mhd_offload_data* offload_data,
36 real** offload_array, char* qid) {
37
38 char path[256];
39 int err = 1;
40
41 /* Read data the QID corresponds to */
42 hdf5_gen_path("/mhd/MHD_STAT_XXXXXXXXXX", qid, path);
43 if( !hdf5_find_group(f, path) ) {
44 offload_data->type = mhd_type_stat;
45 err = hdf5_mhd_read_stat(f, &(offload_data->stat),
46 offload_array, qid);
47 }
48
49 hdf5_gen_path("/mhd/MHD_NONSTAT_XXXXXXXXXX", qid, path);
50 if( !hdf5_find_group(f, path) ) {
51 offload_data->type = mhd_type_nonstat;
52 err = hdf5_mhd_read_nonstat(f, &(offload_data->nonstat),
53 offload_array, qid);
54 }
55
56 /* Initialize if data was read succesfully */
57 if(!err) {
58 err = mhd_init_offload(offload_data, offload_array);
59 }
60
61 return err;
62}
63
74int hdf5_mhd_read_stat(hid_t f, mhd_stat_offload_data* offload_data,
75 real** offload_array, char* qid) {
76 #undef MHDPATH
77 #define MHDPATH "/mhd/MHD_STAT_XXXXXXXXXX/"
78
79 /* Read parameters. */
80 if( hdf5_read_int( MHDPATH "nmode", &(offload_data->n_modes),
81 f, qid, __FILE__, __LINE__) ) {return 1;}
82 if( hdf5_read_int( MHDPATH "nrho", &(offload_data->nrho),
83 f, qid, __FILE__, __LINE__) ) {return 1;}
84 if( hdf5_read_double(MHDPATH "rhomin", &(offload_data->rho_min),
85 f, qid, __FILE__, __LINE__) ) {return 1;}
86 if( hdf5_read_double(MHDPATH "rhomax", &(offload_data->rho_max),
87 f, qid, __FILE__, __LINE__) ) {return 1;}
88 if( hdf5_read_int( MHDPATH "nmodes", offload_data->nmode,
89 f, qid, __FILE__, __LINE__) ) {return 1;}
90 if( hdf5_read_int( MHDPATH "mmodes", offload_data->mmode,
91 f, qid, __FILE__, __LINE__) ) {return 1;}
92 if( hdf5_read_double(MHDPATH "amplitude", offload_data->amplitude_nm,
93 f, qid, __FILE__, __LINE__) ) {return 1;}
94 if( hdf5_read_double(MHDPATH "omega", offload_data->omega_nm,
95 f, qid, __FILE__, __LINE__) ) {return 1;}
96 if( hdf5_read_double(MHDPATH "phase", offload_data->phase_nm,
97 f, qid, __FILE__, __LINE__) ) {return 1;}
98
99 /* Allocate offload array */
100 int datasize = offload_data->nrho * offload_data->n_modes;
101 *offload_array = (real*) malloc( 2 * datasize * sizeof(real) );
102
103 /* Read data to offload array */
104 if( hdf5_read_double(MHDPATH "alpha", &(*offload_array)[0],
105 f, qid, __FILE__, __LINE__) ) {return 1;}
106 if( hdf5_read_double(MHDPATH "phi", &(*offload_array)[datasize],
107 f, qid, __FILE__, __LINE__) ) {return 1;}
108
109 return 0;
110}
111
123 real** offload_array, char* qid) {
124 #undef MHDPATH
125 #define MHDPATH "/mhd/MHD_NONSTAT_XXXXXXXXXX/"
126
127 /* Read parameters. */
128 if( hdf5_read_int( MHDPATH "nmode", &(offload_data->n_modes),
129 f, qid, __FILE__, __LINE__) ) {return 1;}
130 if( hdf5_read_int( MHDPATH "nrho", &(offload_data->nrho),
131 f, qid, __FILE__, __LINE__) ) {return 1;}
132 if( hdf5_read_double(MHDPATH "rhomin", &(offload_data->rho_min),
133 f, qid, __FILE__, __LINE__) ) {return 1;}
134 if( hdf5_read_double(MHDPATH "rhomax", &(offload_data->rho_max),
135 f, qid, __FILE__, __LINE__) ) {return 1;}
136 if( hdf5_read_int( MHDPATH "ntime", &(offload_data->ntime),
137 f, qid, __FILE__, __LINE__) ) {return 1;}
138 if( hdf5_read_double(MHDPATH "tmin", &(offload_data->t_min),
139 f, qid, __FILE__, __LINE__) ) {return 1;}
140 if( hdf5_read_double(MHDPATH "tmax", &(offload_data->t_max),
141 f, qid, __FILE__, __LINE__) ) {return 1;}
142 if( hdf5_read_int( MHDPATH "nmodes", offload_data->nmode,
143 f, qid, __FILE__, __LINE__) ) {return 1;}
144 if( hdf5_read_int( MHDPATH "mmodes", offload_data->mmode,
145 f, qid, __FILE__, __LINE__) ) {return 1;}
146 if( hdf5_read_double(MHDPATH "amplitude", offload_data->amplitude_nm,
147 f, qid, __FILE__, __LINE__) ) {return 1;}
148 if( hdf5_read_double(MHDPATH "omega", offload_data->omega_nm,
149 f, qid, __FILE__, __LINE__) ) {return 1;}
150 if( hdf5_read_double(MHDPATH "phase", offload_data->phase_nm,
151 f, qid, __FILE__, __LINE__) ) {return 1;}
152
153 /* Allocate offload array */
154 int datasize = offload_data->nrho * offload_data->ntime
155 * offload_data->n_modes;
156 *offload_array = (real*) malloc( 2 * datasize * sizeof(real) );
157
158 /* Read data to offload array */
159 if( hdf5_read_double(MHDPATH "alpha", &(*offload_array)[0],
160 f, qid, __FILE__, __LINE__) ) {return 1;}
161 if( hdf5_read_double(MHDPATH "phi", &(*offload_array)[datasize],
162 f, qid, __FILE__, __LINE__) ) {return 1;}
163
164 return 0;
165}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
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_mhd_read_stat(hid_t f, mhd_stat_offload_data *offload_data, real **offload_array, char *qid)
Read stationary MHD data from HDF5 file.
Definition hdf5_mhd.c:74
int hdf5_mhd_init_offload(hid_t f, mhd_offload_data *offload_data, real **offload_array, char *qid)
Initialize MHD offload data from HDF5 file.
Definition hdf5_mhd.c:35
#define MHDPATH
Definition hdf5_mhd.c:16
int hdf5_mhd_read_nonstat(hid_t f, mhd_nonstat_offload_data *offload_data, real **offload_array, char *qid)
Read nonstationary MHD data from HDF5 file.
Definition hdf5_mhd.c:122
Header file for hdf5_mhd.c.
int mhd_init_offload(mhd_offload_data *offload_data, real **offload_array)
Load MHD data and prepare parameters.
Definition mhd.c:45
Header file for mhd.c.
@ mhd_type_stat
Definition mhd.h:28
@ mhd_type_nonstat
Definition mhd.h:29
Header file for mhd_nonstat.c.
Header file for mhd_stat.c.
MHD parameters that will be offloaded to target.
Definition mhd_nonstat.h:17
real omega_nm[MHD_MODES_MAX_NUM]
Definition mhd_nonstat.h:29
int nmode[MHD_MODES_MAX_NUM]
Definition mhd_nonstat.h:26
real amplitude_nm[MHD_MODES_MAX_NUM]
Definition mhd_nonstat.h:28
int mmode[MHD_MODES_MAX_NUM]
Definition mhd_nonstat.h:27
real phase_nm[MHD_MODES_MAX_NUM]
Definition mhd_nonstat.h:31
MHD offload data.
Definition mhd.h:41
mhd_type type
Definition mhd.h:42
mhd_nonstat_offload_data nonstat
Definition mhd.h:44
mhd_stat_offload_data stat
Definition mhd.h:43
MHD stat parameters that will be offloaded to target.
Definition mhd_stat.h:17
int mmode[MHD_MODES_MAX_NUM]
Definition mhd_stat.h:24
real phase_nm[MHD_MODES_MAX_NUM]
Definition mhd_stat.h:28
int nmode[MHD_MODES_MAX_NUM]
Definition mhd_stat.h:23
real amplitude_nm[MHD_MODES_MAX_NUM]
Definition mhd_stat.h:25
real omega_nm[MHD_MODES_MAX_NUM]
Definition mhd_stat.h:26