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_data* data, char* qid);
19int hdf5_mhd_read_nonstat(hid_t f, mhd_nonstat_data* data, char* qid);
20
31int hdf5_mhd_init(hid_t f, mhd_data* data, char* qid) {
32
33 char path[256];
34 int err = 1;
35
36 /* Read data the QID corresponds to */
37 hdf5_gen_path("/mhd/MHD_STAT_XXXXXXXXXX", qid, path);
38 if( !hdf5_find_group(f, path) ) {
39 data->type = mhd_type_stat;
40 err = hdf5_mhd_read_stat(f, &data->stat, qid);
41 }
42 hdf5_gen_path("/mhd/MHD_NONSTAT_XXXXXXXXXX", qid, path);
43 if( !hdf5_find_group(f, path) ) {
44 data->type = mhd_type_nonstat;
45 err = hdf5_mhd_read_nonstat(f, &data->nonstat, qid);
46 }
47 return err;
48}
49
59int hdf5_mhd_read_stat(hid_t f, mhd_stat_data* data, char* qid) {
60 #undef MHDPATH
61 #define MHDPATH "/mhd/MHD_STAT_XXXXXXXXXX/"
62
63 int nmode, nrho;
64 real rhomin, rhomax;
65 if( hdf5_read_int( MHDPATH "nmode", &nmode,
66 f, qid, __FILE__, __LINE__) ) {return 1;}
67 if( hdf5_read_int( MHDPATH "nrho", &nrho,
68 f, qid, __FILE__, __LINE__) ) {return 1;}
69 if( hdf5_read_double(MHDPATH "rhomin", &rhomin,
70 f, qid, __FILE__, __LINE__) ) {return 1;}
71 if( hdf5_read_double(MHDPATH "rhomax", &rhomax,
72 f, qid, __FILE__, __LINE__) ) {return 1;}
73
74 int* moden = (int*) malloc( nmode * sizeof(int) );
75 int* modem = (int*) malloc( nmode * sizeof(int) );
76 real* omega_nm = (real*) malloc( nmode * sizeof(real) );
77 real* phase_nm = (real*) malloc( nmode * sizeof(real) );
78 real* amplitude_nm = (real*)malloc( nmode * sizeof(real) );
79 if( hdf5_read_int( MHDPATH "nmodes", moden,
80 f, qid, __FILE__, __LINE__) ) {return 1;}
81 if( hdf5_read_int( MHDPATH "mmodes", modem,
82 f, qid, __FILE__, __LINE__) ) {return 1;}
83 if( hdf5_read_double(MHDPATH "omega", omega_nm,
84 f, qid, __FILE__, __LINE__) ) {return 1;}
85 if( hdf5_read_double(MHDPATH "phase", phase_nm,
86 f, qid, __FILE__, __LINE__) ) {return 1;}
87 if( hdf5_read_double(MHDPATH "amplitude", amplitude_nm,
88 f, qid, __FILE__, __LINE__) ) {return 1;}
89
90 /* Allocate offload array */
91 real* phi = (real*) malloc( nrho * nmode * sizeof(real) );
92 real* alpha = (real*) malloc( nrho * nmode * sizeof(real) );
93 if( hdf5_read_double(MHDPATH "alpha", alpha,
94 f, qid, __FILE__, __LINE__) ) {return 1;}
95 if( hdf5_read_double(MHDPATH "phi", phi,
96 f, qid, __FILE__, __LINE__) ) {return 1;}
97
98 int err = mhd_stat_init(data, nmode, nrho, rhomin, rhomax, moden, modem,
99 amplitude_nm, omega_nm, phase_nm, alpha, phi);
100 return err;
101}
102
112int hdf5_mhd_read_nonstat(hid_t f, mhd_nonstat_data* data, char* qid) {
113 #undef MHDPATH
114 #define MHDPATH "/mhd/MHD_NONSTAT_XXXXXXXXXX/"
115
116 int nmode, nrho, ntime;
117 real rhomin, rhomax, tmin, tmax;
118 if( hdf5_read_int( MHDPATH "nmode", &nmode,
119 f, qid, __FILE__, __LINE__) ) {return 1;}
120 if( hdf5_read_int( MHDPATH "nrho", &nrho,
121 f, qid, __FILE__, __LINE__) ) {return 1;}
122 if( hdf5_read_double(MHDPATH "rhomin", &rhomin,
123 f, qid, __FILE__, __LINE__) ) {return 1;}
124 if( hdf5_read_double(MHDPATH "rhomax", &rhomax,
125 f, qid, __FILE__, __LINE__) ) {return 1;}
126 if( hdf5_read_int( MHDPATH "ntime", &ntime,
127 f, qid, __FILE__, __LINE__) ) {return 1;}
128 if( hdf5_read_double(MHDPATH "tmin", &tmin,
129 f, qid, __FILE__, __LINE__) ) {return 1;}
130 if( hdf5_read_double(MHDPATH "tmax", &tmax,
131 f, qid, __FILE__, __LINE__) ) {return 1;}
132
133 int* moden = (int*) malloc( nmode * sizeof(int) );
134 int* modem = (int*) malloc( nmode * sizeof(int) );
135 real* omega_nm = (real*) malloc( nmode * sizeof(real) );
136 real* phase_nm = (real*) malloc( nmode * sizeof(real) );
137 real* amplitude_nm = (real*)malloc( nmode * sizeof(real) );
138 if( hdf5_read_int( MHDPATH "nmodes", moden,
139 f, qid, __FILE__, __LINE__) ) {return 1;}
140 if( hdf5_read_int( MHDPATH "mmodes", modem,
141 f, qid, __FILE__, __LINE__) ) {return 1;}
142 if( hdf5_read_double(MHDPATH "omega", omega_nm,
143 f, qid, __FILE__, __LINE__) ) {return 1;}
144 if( hdf5_read_double(MHDPATH "phase", phase_nm,
145 f, qid, __FILE__, __LINE__) ) {return 1;}
146 if( hdf5_read_double(MHDPATH "amplitude", amplitude_nm,
147 f, qid, __FILE__, __LINE__) ) {return 1;}
148
149 /* Allocate offload array */
150 real* phi = (real*) malloc( nrho * ntime * nmode * sizeof(real) );
151 real* alpha = (real*) malloc( nrho * ntime * nmode * sizeof(real) );
152 if( hdf5_read_double(MHDPATH "alpha", alpha,
153 f, qid, __FILE__, __LINE__) ) {return 1;}
154 if( hdf5_read_double(MHDPATH "phi", phi,
155 f, qid, __FILE__, __LINE__) ) {return 1;}
156
157 int err = mhd_nonstat_init(data, nmode, nrho, ntime, rhomin, rhomax,
158 tmin, tmax, moden, modem, amplitude_nm,
159 omega_nm, phase_nm, alpha, phi);
160 return err;
161}
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_init(hid_t f, mhd_data *data, char *qid)
Initialize MHD data from HDF5 file.
Definition hdf5_mhd.c:31
int hdf5_mhd_read_nonstat(hid_t f, mhd_nonstat_data *data, char *qid)
Read nonstationary MHD data from HDF5 file.
Definition hdf5_mhd.c:112
#define MHDPATH
Definition hdf5_mhd.c:16
int hdf5_mhd_read_stat(hid_t f, mhd_stat_data *data, char *qid)
Read stationary MHD data from HDF5 file.
Definition hdf5_mhd.c:59
Header file for hdf5_mhd.c.
Header file for mhd.c.
@ mhd_type_stat
Definition mhd.h:25
@ mhd_type_nonstat
Definition mhd.h:26
int mhd_nonstat_init(mhd_nonstat_data *data, int nmode, int nrho, int ntime, real rhomin, real rhomax, real tmin, real tmax, int *moden, int *modem, real *amplitude_nm, real *omega_nm, real *phase_nm, real *alpha, real *phi)
Load MHD data.
Definition mhd_nonstat.c:23
Header file for mhd_nonstat.c.
int mhd_stat_init(mhd_stat_data *data, int nmode, int nrho, real rhomin, real rhomax, int *moden, int *modem, real *amplitude_nm, real *omega_nm, real *phase_nm, real *alpha, real *phi)
Load MHD data.
Definition mhd_stat.c:23
Header file for mhd_stat.c.
MHD simulation data.
Definition mhd.h:35
mhd_type type
Definition mhd.h:36
mhd_stat_data stat
Definition mhd.h:37
mhd_nonstat_data nonstat
Definition mhd.h:38
MHD parameters.
Definition mhd_nonstat.h:18
MHD stat parameters on the target.
Definition mhd_stat.h:18