Skip to content
Snippets Groups Projects
Commit d61ee7c0 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Pass the engine to the conversion function

parent 452819da
No related branches found
No related tags found
1 merge request!201i/o conversion
...@@ -52,7 +52,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -52,7 +52,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_DENSITY, parts, rho); UNIT_CONV_DENSITY, parts, rho);
} }
float convert_u(struct part* p) { float convert_u(struct engine* e, struct part* p) {
return p->entropy * pow_gamma_minus_one(p->rho) * return p->entropy * pow_gamma_minus_one(p->rho) *
hydro_one_over_gamma_minus_one; hydro_one_over_gamma_minus_one;
......
...@@ -60,10 +60,10 @@ struct io_props { ...@@ -60,10 +60,10 @@ struct io_props {
struct gpart* gparts; struct gpart* gparts;
/* Conversion function for part */ /* Conversion function for part */
float (*convert_part)(struct part*); float (*convert_part)(struct engine*, struct part*);
/* Conversion function for part */ /* Conversion function for part */
float (*convert_gpart)(struct gpart*); float (*convert_gpart)(struct engine*, struct gpart*);
}; };
/** /**
...@@ -173,7 +173,7 @@ struct io_props io_make_output_field_(char name[FIELD_BUFFER_SIZE], ...@@ -173,7 +173,7 @@ struct io_props io_make_output_field_(char name[FIELD_BUFFER_SIZE],
struct io_props io_make_output_field_convert_part_( struct io_props io_make_output_field_convert_part_(
char name[FIELD_BUFFER_SIZE], enum DATA_TYPE type, int dimension, char name[FIELD_BUFFER_SIZE], enum DATA_TYPE type, int dimension,
enum UnitConversionFactor units, char* field, size_t partSize, enum UnitConversionFactor units, char* field, size_t partSize,
struct part* parts, float (*functionPtr)(struct part*)) { struct part* parts, float (*functionPtr)(struct engine*, struct part*)) {
struct io_props r; struct io_props r;
strcpy(r.name, name); strcpy(r.name, name);
...@@ -218,7 +218,7 @@ struct io_props io_make_output_field_convert_part_( ...@@ -218,7 +218,7 @@ struct io_props io_make_output_field_convert_part_(
struct io_props io_make_output_field_convert_gpart_( struct io_props io_make_output_field_convert_gpart_(
char name[FIELD_BUFFER_SIZE], enum DATA_TYPE type, int dimension, char name[FIELD_BUFFER_SIZE], enum DATA_TYPE type, int dimension,
enum UnitConversionFactor units, char* field, size_t partSize, enum UnitConversionFactor units, char* field, size_t partSize,
struct gpart* gparts, float (*functionPtr)(struct gpart*)) { struct gpart* gparts, float (*functionPtr)(struct engine*, struct gpart*)) {
struct io_props r; struct io_props r;
strcpy(r.name, name); strcpy(r.name, name);
......
...@@ -181,6 +181,7 @@ void readArray(hid_t grp, const struct io_props prop, size_t N, ...@@ -181,6 +181,7 @@ void readArray(hid_t grp, const struct io_props prop, size_t N,
/** /**
* @brief Writes a data array in given HDF5 group. * @brief Writes a data array in given HDF5 group.
* *
* @param e The #engine we are writing from.
* @param grp The group in which to write. * @param grp The group in which to write.
* @param fileName The name of the file in which the data is written * @param fileName The name of the file in which the data is written
* @param xmfFile The FILE used to write the XMF description * @param xmfFile The FILE used to write the XMF description
...@@ -194,7 +195,7 @@ void readArray(hid_t grp, const struct io_props prop, size_t N, ...@@ -194,7 +195,7 @@ void readArray(hid_t grp, const struct io_props prop, size_t N,
* the part array will be written once the structures have been stabilized. * the part array will be written once the structures have been stabilized.
* *
*/ */
void writeArray(hid_t grp, char* fileName, FILE* xmfFile, void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
char* partTypeGroupName, const struct io_props props, size_t N, char* partTypeGroupName, const struct io_props props, size_t N,
long long N_total, int mpi_rank, long long offset, long long N_total, int mpi_rank, long long offset,
const struct UnitSystem* internal_units, const struct UnitSystem* internal_units,
...@@ -222,13 +223,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, ...@@ -222,13 +223,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_part(&props.parts[i]); temp_f[i] = props.convert_part(e, &props.parts[i]);
} else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_gpart(&props.gparts[i]); temp_f[i] = props.convert_gpart(e, &props.gparts[i]);
} }
/* Unit conversion if necessary */ /* Unit conversion if necessary */
...@@ -781,7 +782,7 @@ void write_output_parallel(struct engine* e, const char* baseName, ...@@ -781,7 +782,7 @@ void write_output_parallel(struct engine* e, const char* baseName,
/* Write everything */ /* Write everything */
for (int i = 0; i < num_fields; ++i) for (int i = 0; i < num_fields; ++i)
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N,
N_total[ptype], mpi_rank, offset[ptype], internal_units, N_total[ptype], mpi_rank, offset[ptype], internal_units,
snapshot_units); snapshot_units);
......
...@@ -261,6 +261,7 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, ...@@ -261,6 +261,7 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile,
/** /**
* @brief Writes a data array in given HDF5 group. * @brief Writes a data array in given HDF5 group.
* *
* @param e The #engine we are writing from.
* @param grp The group in which to write. * @param grp The group in which to write.
* @param fileName The name of the file in which the data is written * @param fileName The name of the file in which the data is written
* @param xmfFile The FILE used to write the XMF description * @param xmfFile The FILE used to write the XMF description
...@@ -276,7 +277,7 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, ...@@ -276,7 +277,7 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile,
* @param us The UnitSystem currently in use * @param us The UnitSystem currently in use
* @param convFactor The UnitConversionFactor for this arrayo * @param convFactor The UnitConversionFactor for this arrayo
*/ */
void writeArray(hid_t grp, char* fileName, FILE* xmfFile, void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
char* partTypeGroupName, const struct io_props props, size_t N, char* partTypeGroupName, const struct io_props props, size_t N,
long long N_total, int mpi_rank, long long offset, long long N_total, int mpi_rank, long long offset,
const struct UnitSystem* internal_units, const struct UnitSystem* internal_units,
...@@ -309,13 +310,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, ...@@ -309,13 +310,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_part(&props.parts[i]); temp_f[i] = props.convert_part(e, &props.parts[i]);
} else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_gpart(&props.gparts[i]); temp_f[i] = props.convert_gpart(e, &props.gparts[i]);
} }
/* Unit conversion if necessary */ /* Unit conversion if necessary */
...@@ -868,7 +869,7 @@ void write_output_serial(struct engine* e, const char* baseName, ...@@ -868,7 +869,7 @@ void write_output_serial(struct engine* e, const char* baseName,
/* Write everything */ /* Write everything */
for (int i = 0; i < num_fields; ++i) for (int i = 0; i < num_fields; ++i)
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N,
N_total[ptype], mpi_rank, offset[ptype], internal_units, N_total[ptype], mpi_rank, offset[ptype], internal_units,
snapshot_units); snapshot_units);
......
...@@ -152,6 +152,7 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N, ...@@ -152,6 +152,7 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N,
/** /**
* @brief Writes a data array in given HDF5 group. * @brief Writes a data array in given HDF5 group.
* *
* @param e The #engine we are writing from.
* @param grp The group in which to write. * @param grp The group in which to write.
* @param fileName The name of the file in which the data is written * @param fileName The name of the file in which the data is written
* @param xmfFile The FILE used to write the XMF description * @param xmfFile The FILE used to write the XMF description
...@@ -165,7 +166,7 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N, ...@@ -165,7 +166,7 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N,
* @todo A better version using HDF5 hyper-slabs to write the file directly from * @todo A better version using HDF5 hyper-slabs to write the file directly from
* the part array will be written once the structures have been stabilized. * the part array will be written once the structures have been stabilized.
*/ */
void writeArray(hid_t grp, char* fileName, FILE* xmfFile, void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
char* partTypeGroupName, const struct io_props props, size_t N, char* partTypeGroupName, const struct io_props props, size_t N,
const struct UnitSystem* internal_units, const struct UnitSystem* internal_units,
const struct UnitSystem* snapshot_units) { const struct UnitSystem* snapshot_units) {
...@@ -192,13 +193,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, ...@@ -192,13 +193,13 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_part(&props.parts[i]); temp_f[i] = props.convert_part(e, &props.parts[i]);
} else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/
float* temp_f = temp; float* temp_f = temp;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
temp_f[i] = props.convert_gpart(&props.gparts[i]); temp_f[i] = props.convert_gpart(e, &props.gparts[i]);
} }
/* Unit conversion if necessary */ /* Unit conversion if necessary */
...@@ -678,7 +679,7 @@ void write_output_single(struct engine* e, const char* baseName, ...@@ -678,7 +679,7 @@ void write_output_single(struct engine* e, const char* baseName,
/* Write everything */ /* Write everything */
for (int i = 0; i < num_fields; ++i) for (int i = 0; i < num_fields; ++i)
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, list[i], N, writeArray(e, h_grp, fileName, xmfFile, partTypeGroupName, list[i], N,
internal_units, snapshot_units); internal_units, snapshot_units);
/* Free temporary array */ /* Free temporary array */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment