ASCOT5
Loading...
Searching...
No Matches
hdf5_efield.c
Go to the documentation of this file.
1
17#include <stdio.h>
18#include <stdlib.h>
19#include <hdf5.h>
20#include <hdf5_hl.h>
21#include "../ascot5.h"
22#include "../E_field.h"
23#include "../Efield/E_TC.h"
24#include "../Efield/E_1DS.h"
25#include "../print.h"
26#include "hdf5_helpers.h"
27#include "hdf5_efield.h"
28
29#define EPATH
31int hdf5_efield_read_1DS(hid_t f, E_1DS_offload_data* offload_data,
32 real** offload_array, char* qid);
33int hdf5_efield_read_TC(hid_t f, E_TC_offload_data* offload_data,
34 real** offload_array, char* qid);
35
58 real** offload_array, char* qid) {
59 char path[256];
60 int err = 1;
61
62 /* Read data the QID corresponds to */
63
64 hdf5_gen_path("/efield/E_TC_XXXXXXXXXX", qid, path);
65 if( !hdf5_find_group(f, path) ) {
66 offload_data->type = E_field_type_TC;
67 err = hdf5_efield_read_TC(f, &(offload_data->ETC),
68 offload_array, qid);
69 }
70
71 hdf5_gen_path("/efield/E_1DS_XXXXXXXXXX", qid, path);
72 if(hdf5_find_group(f, path) == 0) {
73 offload_data->type = E_field_type_1DS;
74 err = hdf5_efield_read_1DS(f, &(offload_data->E1DS),
75 offload_array, qid);
76 }
77
78 /* Initialize if data was read succesfully */
79 if(!err) {
80 err = E_field_init_offload(offload_data, offload_array);
81 }
82
83 return err;
84}
85
96int hdf5_efield_read_1DS(hid_t f, E_1DS_offload_data* offload_data,
97 real** offload_array, char* qid) {
98 #undef EPATH
99 #define EPATH "/efield/E_1DS_XXXXXXXXXX/"
100
101 if( hdf5_read_int(EPATH "nrho", &(offload_data->n_rho),
102 f, qid, __FILE__, __LINE__) ) {return 1;}
103 if( hdf5_read_double(EPATH "rhomin", &(offload_data->rho_min),
104 f, qid, __FILE__, __LINE__) ) {return 1;}
105 if( hdf5_read_double(EPATH "rhomax", &(offload_data->rho_max),
106 f, qid, __FILE__, __LINE__) ) {return 1;}
107
108 /* Allocate n_rho space for dV/drho */
109 *offload_array = (real*) malloc(offload_data->n_rho*sizeof(real));
110
111 if( hdf5_read_double(EPATH "dvdrho", *offload_array,
112 f, qid, __FILE__, __LINE__) ) {return 1;}
113
114 /* Effective minor radius */
115 real r_eff;
116 if( hdf5_read_double(EPATH "reff", &(r_eff),
117 f, qid, __FILE__, __LINE__) ) {return 1;}
118
119 /* Scale derivatives by effective minor radius */
120 for(int i = 0; i < offload_data->n_rho; i++) {
121 (*offload_array)[i] = r_eff * (*offload_array)[i];
122 }
123
124 return 0;
125}
126
146int hdf5_efield_read_TC(hid_t f, E_TC_offload_data* offload_data,
147 real** offload_array, char* qid) {
148 #undef EPATH
149 #define EPATH "/efield/E_TC_XXXXXXXXXX/"
150
151 *offload_array = NULL;
152
153 if( hdf5_read_double(EPATH "exyz", offload_data->Exyz,
154 f, qid, __FILE__, __LINE__) ) {return 1;}
155
156 return 0;
157}
Header file for E_1DS.c.
Header file for E_TC.c.
int E_field_init_offload(E_field_offload_data *offload_data, real **offload_array)
Load electric field data and prepare parameters.
Definition E_field.c:41
Header file for E_field.c.
@ E_field_type_TC
Definition E_field.h:26
@ E_field_type_1DS
Definition E_field.h:27
Main header file for ASCOT5.
double real
Definition ascot5.h:85
int hdf5_efield_read_1DS(hid_t f, E_1DS_offload_data *offload_data, real **offload_array, char *qid)
Read E1DS electric field data from HDF5 file.
Definition hdf5_efield.c:96
int hdf5_efield_init_offload(hid_t f, E_field_offload_data *offload_data, real **offload_array, char *qid)
Read electric field data from HDF5 file.
Definition hdf5_efield.c:57
#define EPATH
Definition hdf5_efield.c:29
int hdf5_efield_read_TC(hid_t f, E_TC_offload_data *offload_data, real **offload_array, char *qid)
Read magnetic field data of type E_TC.
Header file for hdf5_efielc.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.
Macros for printing console output.
1D spline electric field parameters that will be offloaded to target
Definition E_1DS.h:20
Trivial Cartesian electric field offload data.
Definition E_TC.h:18
real Exyz[3]
Definition E_TC.h:19
Electric field offload data.
Definition E_field.h:39
E_TC_offload_data ETC
Definition E_field.h:41
E_1DS_offload_data E1DS
Definition E_field.h:42
E_field_type type
Definition E_field.h:40