Commit 856ed10d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Fully working updated i/o for Gadget-SPH in single mode

parent be507607
......@@ -20,17 +20,11 @@
#include "io_properties.h"
/**
* @brief Read dark matter particles from HDF5.
*
* @param h_grp The HDF5 group in which to read the arrays.
* @param N The number of particles on that MPI rank.
* @param N_total The total number of particles (only used in MPI mode)
* @param offset The offset of the particles for this MPI rank (only used in MPI
* mode)
* @param gparts The particle array
* @param internal_units The #UnitSystem used internally
* @param ic_units The #UnitSystem used in the snapshots
* @brief Specifies which g-particle fields to read from a dataset
*
* @param gparts The g-particle array.
* @param list The list of i/o properties to read.
* @param num_fields The number of i/o fields to read.
*/
void darkmatter_read_particles(struct gpart* gparts, struct io_props* list,
int* num_fields) {
......@@ -50,45 +44,27 @@ void darkmatter_read_particles(struct gpart* gparts, struct io_props* list,
}
/**
* @brief Writes the different particles to the HDF5 file
*
* @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode).
* @param partTypeGroupName The name of the group containing the particles in
* the HDF5 file.
* @param xmfFile The XMF file to write to (unused in MPI mode).
* @param Ndm The number of DM particles on that MPI rank.
* @param Ndm_total The total number of g-particles (only used in MPI mode)
* @param mpi_rank The MPI rank of this node (only used in MPI mode)
* @param offset The offset of the particles for this MPI rank (only used in MPI
* mode)
* @param gparts The #gpart array
* @param internal_units The #UnitSystem used internally
* @param snapshot_units The #UnitSystem used in the snapshots
* @brief Specifies which g-particle fields to write to a dataset
*
* @param gparts The g-particle array.
* @param list The list of i/o properties to write.
* @param num_fields The number of i/o fields to write.
*/
__attribute__((always_inline)) INLINE static void darkmatter_write_particles(
hid_t h_grp, char* fileName, char* partTypeGroupName, FILE* xmfFile,
int Ndm, long long Ndm_total, int mpi_rank, long long offset,
struct gpart* gparts, const struct UnitSystem* internal_units,
const struct UnitSystem* snapshot_units) {
void darkmatter_write_particles(struct gpart* gparts, struct io_props* list,
int* num_fields) {
/* Write arrays */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates",
* DOUBLE, */
/* Ndm, 3, gparts, Ndm_total, mpi_rank, offset, x, internal_units,
*/
/* snapshot_units, UNIT_CONV_LENGTH); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT,
* Ndm, */
/* 1, gparts, Ndm_total, mpi_rank, offset, mass, internal_units, */
/* snapshot_units, UNIT_CONV_MASS); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities",
* FLOAT, */
/* Ndm, 3, gparts, Ndm_total, mpi_rank, offset, v_full, */
/* internal_units, snapshot_units, UNIT_CONV_SPEED); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs", */
/* ULONGLONG, Ndm, 1, gparts, Ndm_total, mpi_rank, offset, */
/* id_or_neg_offset, internal_units, snapshot_units, */
/* UNIT_CONV_NO_UNITS); */
/* Say how much we want to read */
*num_fields = 5;
/* List what we want to read */
list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH,
gparts, x);
list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED,
gparts, v_full);
list[2] =
io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, gparts, mass);
list[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset);
list[4] = io_make_output_field("Acceleration", FLOAT, 3,
UNIT_CONV_ACCELERATION, gparts, a_grav);
}
......@@ -52,66 +52,34 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
}
/**
* @brief Writes the different particles to the HDF5 file
*
* @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode).
* @param partTypeGroupName The name of the group containing the particles in
* the HDF5 file.
* @param xmfFile The XMF file to write to (unused in MPI mode).
* @param N The number of particles on that MPI rank.
* @param N_total The total number of particles (only used in MPI mode)
* @param mpi_rank The MPI rank of this node (only used in MPI mode)
* @param offset The offset of the particles for this MPI rank (only used in MPI
* mode)
* @param parts The particle array
* @param internal_units The #UnitSystem used internally
* @param snapshot_units The #UnitSystem used in the snapshots
* @brief Specifies which particle fields to write to a dataset
*
* @param parts The particle array.
* @param list The list of i/o properties to write.
* @param num_fields The number of i/o fields to write.
*/
void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) {
*num_fields = 1;
*num_fields = 8;
/* List what we want to read */
/* List what we want to write */
list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH,
parts, x);
/* Write arrays */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates",
* DOUBLE, */
/* N, 3, parts, N_total, mpi_rank, offset, x, internal_units, */
/* snapshot_units, UNIT_CONV_LENGTH); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities",
* FLOAT, */
/* N, 3, parts, N_total, mpi_rank, offset, v, internal_units, */
/* snapshot_units, UNIT_CONV_SPEED); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT, N,
* 1, */
/* parts, N_total, mpi_rank, offset, mass, internal_units, */
/* snapshot_units, UNIT_CONV_MASS); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "SmoothingLength",
*/
/* FLOAT, N, 1, parts, N_total, mpi_rank, offset, h,
* internal_units, */
/* snapshot_units, UNIT_CONV_LENGTH); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Entropy", FLOAT,
* N, */
/* 1, parts, N_total, mpi_rank, offset, entropy, internal_units, */
/* snapshot_units, UNIT_CONV_ENTROPY_PER_UNIT_MASS); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs", */
/* ULONGLONG, N, 1, parts, N_total, mpi_rank, offset, id, */
/* internal_units, snapshot_units, UNIT_CONV_NO_UNITS); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Acceleration",
* FLOAT, */
/* N, 3, parts, N_total, mpi_rank, offset, a_hydro, internal_units,
*/
/* snapshot_units, UNIT_CONV_ACCELERATION); */
/* writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Density", FLOAT,
* N, */
/* 1, parts, N_total, mpi_rank, offset, rho, internal_units, */
/* snapshot_units, UNIT_CONV_DENSITY); */
list[1] =
io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, v);
list[2] =
io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass);
list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH,
parts, h);
list[4] = io_make_output_field(
"Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy);
list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
UNIT_CONV_NO_UNITS, parts, id);
list[6] = io_make_output_field("Acceleration", FLOAT, 3,
UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] =
io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho);
}
/**
......
......@@ -52,9 +52,8 @@
/**
* @brief Reads a data array from a given HDF5 group.
*
* @param grp The group from which to read.
* @param h_grp The group from which to read.
* @param prop The #io_props of the field to read
* @param type The #DATA_TYPE of the attribute.
* @param N The number of particles.
* @param internal_units The #UnitSystem used internally
* @param ic_units The #UnitSystem used in the ICs
......@@ -156,20 +155,14 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N,
* @param fileName The name of the file in which the data is written
* @param xmfFile The FILE used to write the XMF description
* @param partTypeGroupName The name of the group containing the particles in
*the HDF5 file.
* @param name The name of the array to write.
* @param type The #DATA_TYPE of the array.
* the HDF5 file.
* @param props The #io_props of the field to read
* @param N The number of particles to write.
* @param dim The dimension of the data (1 for scalar, 3 for vector)
* @param part_c A (char*) pointer on the first occurrence of the field of
*interest in the parts array.
* @param partSize The size in bytes of the particle structure.
* @param internal_units The #UnitSystem used internally
* @param snapshot_units The #UnitSystem used in the snapshots
* @param convFactor The UnitConversionFactor for this array
*
* @todo A better version using HDF5 hyper-slabs to write the file directly from
*the part array
* the part array
* will be written once the structures have been stabilized.
*/
void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
......@@ -181,7 +174,7 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
const size_t copySize = typeSize * props.dimension;
const size_t num_elements = N * props.dimension;
/* message("Writing '%s' array...", props.name); */
message("Writing '%s' array...", props.name);
/* Allocate temporary buffer */
void* temp = malloc(num_elements * sizeOfType(props.type));
......@@ -304,6 +297,8 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile,
* @param Ngas (output) number of Gas particles read.
* @param Ngparts (output) The number of #gpart read.
* @param periodic (output) 1 if the volume is periodic, 0 if not.
* @param flag_entropy 1 if the ICs contained Entropy in the InternalEnergy
* field
* @param dry_run If 1, don't read the particle. Only allocates the arrays.
*
* Opens the HDF5 file fileName and reads the particles contained
......@@ -653,11 +648,10 @@ void write_output_single(struct engine* e, const char* baseName,
/* Collect the DM particles from gpart */
collect_dm_gparts(gparts, Ntot, dmparts, Ndm);
/* /\* Write DM particles *\/ */
/* darkmatter_write_particles(h_grp, fileName, partTypeGroupName, xmfFile,
*/
/* Ndm, Ndm, 0, 0, dmparts, internal_units, */
/* snapshot_units); */
/* Write DM particles */
N = Ndm;
darkmatter_write_particles(dmparts, list, &num_fields);
break;
default:
error("Particle Type %d not yet supported. Aborting", ptype);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment