Commit c4d1b553 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'multi_types_xmf' into 'master'

Support for XMF file descriptors with multiple particle types.

This fixes #127 and adds support for all particle types within the XMF files. Both in single node and MPI modes.

See merge request !126
parents f6f7239b 2d3e60b5
...@@ -362,8 +362,8 @@ int main(int argc, char *argv[]) { ...@@ -362,8 +362,8 @@ int main(int argc, char *argv[]) {
if (myrank == 0) clocks_gettime(&tic); if (myrank == 0) clocks_gettime(&tic);
#if defined(WITH_MPI) #if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5) #if defined(HAVE_PARALLEL_HDF5)
read_ic_parallel(ICfileName, dim, &parts, &Ngas, &periodic, myrank, nr_nodes, read_ic_parallel(ICfileName, dim, &parts, &gparts, &Ngas, &Ngpart, &periodic,
MPI_COMM_WORLD, MPI_INFO_NULL); myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL);
#else #else
read_ic_serial(ICfileName, dim, &parts, &gparts, &Ngas, &Ngpart, &periodic, read_ic_serial(ICfileName, dim, &parts, &gparts, &Ngas, &Ngpart, &periodic,
myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL); myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL);
......
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
#include "kernel.h" #include "kernel.h"
#include "version.h" #include "version.h"
const char* particle_type_names[NUM_PARTICLE_TYPES] = {
"Gas", "DM", "Boundary", "Dummy", "Star", "BH"};
/** /**
* @brief Converts a C data type to the HDF5 equivalent. * @brief Converts a C data type to the HDF5 equivalent.
* *
...@@ -402,52 +405,68 @@ void createXMFfile() { ...@@ -402,52 +405,68 @@ void createXMFfile() {
*snapshot *snapshot
* *
* @param xmfFile The file to write in. * @param xmfFile The file to write in.
* @param Nparts The number of particles.
* @param hdfFileName The name of the HDF5 file corresponding to this output. * @param hdfFileName The name of the HDF5 file corresponding to this output.
* @param time The current simulation time. * @param time The current simulation time.
*/ */
void writeXMFheader(FILE* xmfFile, long long Nparts, char* hdfFileName, void writeXMFoutputheader(FILE* xmfFile, char* hdfFileName, float time) {
float time) {
/* Write end of file */ /* Write end of file */
fprintf(xmfFile, "<!-- XMF description for file: %s -->\n", hdfFileName);
fprintf(xmfFile, fprintf(xmfFile,
"<Grid GridType=\"Collection\" CollectionType=\"Spatial\">\n"); "<Grid GridType=\"Collection\" CollectionType=\"Spatial\">\n");
fprintf(xmfFile, "<Time Type=\"Single\" Value=\"%f\"/>\n", time); fprintf(xmfFile, "<Time Type=\"Single\" Value=\"%f\"/>\n", time);
fprintf(xmfFile, "<Grid Name=\"Gas\" GridType=\"Uniform\">\n");
fprintf(xmfFile,
"<Topology TopologyType=\"Polyvertex\" Dimensions=\"%lld\"/>\n",
Nparts);
fprintf(xmfFile, "<Geometry GeometryType=\"XYZ\">\n");
fprintf(xmfFile,
"<DataItem Dimensions=\"%lld 3\" NumberType=\"Double\" "
"Precision=\"8\" "
"Format=\"HDF\">%s:/PartType0/Coordinates</DataItem>\n",
Nparts, hdfFileName);
fprintf(xmfFile, "</Geometry>");
} }
/** /**
* @brief Writes the end of the XMF file (closes all open markups) * @brief Writes the end of the XMF file (closes all open markups)
* *
* @param xmfFile The file to write in. * @param xmfFile The file to write in.
* @param output The number of this output.
* @param time The current simulation time.
*/ */
void writeXMFfooter(FILE* xmfFile) { void writeXMFoutputfooter(FILE* xmfFile, int output, float time) {
/* Write end of the section of this time step */ /* Write end of the section of this time step */
fprintf(xmfFile, "\n</Grid>\n"); fprintf(xmfFile,
fprintf(xmfFile, "</Grid>\n"); "\n</Grid> <!-- End of meta-data for output=%03i, time=%f -->\n",
fprintf(xmfFile, "\n</Grid>\n"); output, time);
fprintf(xmfFile, "\n</Grid> <!-- timeSeries -->\n");
fprintf(xmfFile, "</Domain>\n"); fprintf(xmfFile, "</Domain>\n");
fprintf(xmfFile, "</Xdmf>\n"); fprintf(xmfFile, "</Xdmf>\n");
fclose(xmfFile); fclose(xmfFile);
} }
void writeXMFgroupheader(FILE* xmfFile, char* hdfFileName, size_t N,
enum PARTICLE_TYPE ptype) {
fprintf(xmfFile, "\n<Grid Name=\"%s\" GridType=\"Uniform\">\n",
particle_type_names[ptype]);
fprintf(xmfFile,
"<Topology TopologyType=\"Polyvertex\" Dimensions=\"%zi\"/>\n", N);
fprintf(xmfFile, "<Geometry GeometryType=\"XYZ\">\n");
fprintf(xmfFile,
"<DataItem Dimensions=\"%zi 3\" NumberType=\"Double\" "
"Precision=\"8\" "
"Format=\"HDF\">%s:/PartType%d/Coordinates</DataItem>\n",
N, hdfFileName, ptype);
fprintf(xmfFile,
"</Geometry>\n <!-- Done geometry for %s, start of particle fields "
"list -->\n",
particle_type_names[ptype]);
}
void writeXMFgroupfooter(FILE* xmfFile, enum PARTICLE_TYPE ptype) {
fprintf(xmfFile, "</Grid> <!-- End of meta-data for parttype=%s -->\n",
particle_type_names[ptype]);
}
/** /**
* @brief Writes the lines corresponding to an array of the HDF5 output * @brief Writes the lines corresponding to an array of the HDF5 output
* *
* @param xmfFile The file in which to write * @param xmfFile The file in which to write
* @param fileName The name of the HDF5 file associated to this XMF descriptor. * @param fileName The name of the HDF5 file associated to this XMF descriptor.
* @param partTypeGroupName The name of the group containing the particles in
*the HDF5 file.
* @param name The name of the array in the HDF5 file. * @param name The name of the array in the HDF5 file.
* @param N The number of particles. * @param N The number of particles.
* @param dim The dimension of the quantity (1 for scalars, 3 for vectors). * @param dim The dimension of the quantity (1 for scalars, 3 for vectors).
...@@ -455,21 +474,21 @@ void writeXMFfooter(FILE* xmfFile) { ...@@ -455,21 +474,21 @@ void writeXMFfooter(FILE* xmfFile) {
* *
* @todo Treat the types in a better way. * @todo Treat the types in a better way.
*/ */
void writeXMFline(FILE* xmfFile, char* fileName, char* name, long long N, void writeXMFline(FILE* xmfFile, char* fileName, char* partTypeGroupName,
int dim, enum DATA_TYPE type) { char* name, size_t N, int dim, enum DATA_TYPE type) {
fprintf(xmfFile, fprintf(xmfFile,
"<Attribute Name=\"%s\" AttributeType=\"%s\" Center=\"Node\">\n", "<Attribute Name=\"%s\" AttributeType=\"%s\" Center=\"Node\">\n",
name, dim == 1 ? "Scalar" : "Vector"); name, dim == 1 ? "Scalar" : "Vector");
if (dim == 1) if (dim == 1)
fprintf(xmfFile, fprintf(xmfFile,
"<DataItem Dimensions=\"%lld\" NumberType=\"Double\" " "<DataItem Dimensions=\"%zi\" NumberType=\"Double\" "
"Precision=\"%d\" Format=\"HDF\">%s:/PartType0/%s</DataItem>\n", "Precision=\"%d\" Format=\"HDF\">%s:%s/%s</DataItem>\n",
N, type == FLOAT ? 4 : 8, fileName, name); N, type == FLOAT ? 4 : 8, fileName, partTypeGroupName, name);
else else
fprintf(xmfFile, fprintf(xmfFile,
"<DataItem Dimensions=\"%lld %d\" NumberType=\"Double\" " "<DataItem Dimensions=\"%zi %d\" NumberType=\"Double\" "
"Precision=\"%d\" Format=\"HDF\">%s:/PartType0/%s</DataItem>\n", "Precision=\"%d\" Format=\"HDF\">%s:%s/%s</DataItem>\n",
N, dim, type == FLOAT ? 4 : 8, fileName, name); N, dim, type == FLOAT ? 4 : 8, fileName, partTypeGroupName, name);
fprintf(xmfFile, "</Attribute>\n"); fprintf(xmfFile, "</Attribute>\n");
} }
......
...@@ -70,6 +70,8 @@ enum PARTICLE_TYPE { ...@@ -70,6 +70,8 @@ enum PARTICLE_TYPE {
NUM_PARTICLE_TYPES NUM_PARTICLE_TYPES
}; };
extern const char* particle_type_names[];
#define FILENAME_BUFFER_SIZE 150 #define FILENAME_BUFFER_SIZE 150
#define PARTICLE_GROUP_BUFFER_SIZE 20 #define PARTICLE_GROUP_BUFFER_SIZE 20
...@@ -95,10 +97,13 @@ void writeAttribute_s(hid_t grp, char* name, const char* str); ...@@ -95,10 +97,13 @@ void writeAttribute_s(hid_t grp, char* name, const char* str);
void createXMFfile(); void createXMFfile();
FILE* prepareXMFfile(); FILE* prepareXMFfile();
void writeXMFfooter(FILE* xmfFile); void writeXMFoutputheader(FILE* xmfFile, char* hdfFileName, float time);
void writeXMFheader(FILE* xmfFile, long long N, char* hdfFileName, float time); void writeXMFoutputfooter(FILE* xmfFile, int outputCount, float time);
void writeXMFline(FILE* xmfFile, char* fileName, char* name, long long N, void writeXMFgroupheader(FILE* xmfFile, char* hdfFileName, size_t N,
int dim, enum DATA_TYPE type); enum PARTICLE_TYPE ptype);
void writeXMFgroupfooter(FILE* xmfFile, enum PARTICLE_TYPE ptype);
void writeXMFline(FILE* xmfFile, char* fileName, char* partTypeGroupName,
char* name, size_t N, int dim, enum DATA_TYPE type);
void writeCodeDescription(hid_t h_file); void writeCodeDescription(hid_t h_file);
void writeSPHflavour(hid_t h_file); void writeSPHflavour(hid_t h_file);
......
...@@ -48,6 +48,8 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles( ...@@ -48,6 +48,8 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles(
* *
* @param h_grp The HDF5 group in which to write the arrays. * @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode). * @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 xmfFile The XMF file to write to (unused in MPI mode).
* @param Ndm The number of DM particles on that MPI rank. * @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 Ndm_total The total number of g-particles (only used in MPI mode)
...@@ -59,17 +61,20 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles( ...@@ -59,17 +61,20 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles(
* *
*/ */
__attribute__((always_inline)) INLINE static void darkmatter_write_particles( __attribute__((always_inline)) INLINE static void darkmatter_write_particles(
hid_t h_grp, char* fileName, FILE* xmfFile, int Ndm, long long Ndm_total, hid_t h_grp, char* fileName, char* partTypeGroupName, FILE* xmfFile,
int mpi_rank, long long offset, struct gpart* gparts, int Ndm, long long Ndm_total, int mpi_rank, long long offset,
struct UnitSystem* us) { struct gpart* gparts, struct UnitSystem* us) {
/* Write arrays */ /* Write arrays */
writeArray(h_grp, fileName, xmfFile, "Coordinates", DOUBLE, Ndm, 3, gparts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates", DOUBLE,
Ndm_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH); Ndm, 3, gparts, Ndm_total, mpi_rank, offset, x, us,
writeArray(h_grp, fileName, xmfFile, "Masses", FLOAT, Ndm, 1, gparts, UNIT_CONV_LENGTH);
Ndm_total, mpi_rank, offset, mass, us, UNIT_CONV_MASS); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT, Ndm,
writeArray(h_grp, fileName, xmfFile, "Velocities", FLOAT, Ndm, 3, gparts, 1, gparts, Ndm_total, mpi_rank, offset, mass, us, UNIT_CONV_MASS);
Ndm_total, mpi_rank, offset, v_full, us, UNIT_CONV_SPEED); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities", FLOAT,
writeArray(h_grp, fileName, xmfFile, "ParticleIDs", ULONGLONG, Ndm, 1, gparts, Ndm, 3, gparts, Ndm_total, mpi_rank, offset, v_full, us,
Ndm_total, mpi_rank, offset, id, us, UNIT_CONV_NO_UNITS); UNIT_CONV_SPEED);
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs",
ULONGLONG, Ndm, 1, gparts, Ndm_total, mpi_rank, offset, id, us,
UNIT_CONV_NO_UNITS);
} }
...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
* @param h_grp The HDF5 group in which to write the arrays. * @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode). * @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 xmfFile The XMF file to write to (unused in MPI mode).
* @param N The number of particles on that MPI rank. * @param N The number of particles on that MPI rank.
* @param N_total The total number of particles (only used in MPI mode) * @param N_total The total number of particles (only used in MPI mode)
...@@ -67,26 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -67,26 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
*/ */
__attribute__((always_inline)) INLINE static void hydro_write_particles( __attribute__((always_inline)) INLINE static void hydro_write_particles(
hid_t h_grp, char* fileName, FILE* xmfFile, int N, long long N_total, hid_t h_grp, char* fileName, char* partTypeGroupName, FILE* xmfFile, int N,
int mpi_rank, long long offset, struct part* parts, struct UnitSystem* us) { long long N_total, int mpi_rank, long long offset, struct part* parts,
struct UnitSystem* us) {
/* Write arrays */ /* Write arrays */
writeArray(h_grp, fileName, xmfFile, "Coordinates", DOUBLE, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates", DOUBLE,
N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH); N, 3, parts, N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH);
writeArray(h_grp, fileName, xmfFile, "Velocities", FLOAT, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities", FLOAT,
N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED); N, 3, parts, N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED);
writeArray(h_grp, fileName, xmfFile, "Masses", FLOAT, N, 1, parts, N_total, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT, N, 1,
mpi_rank, offset, mass, us, UNIT_CONV_MASS); parts, N_total, mpi_rank, offset, mass, us, UNIT_CONV_MASS);
writeArray(h_grp, fileName, xmfFile, "SmoothingLength", FLOAT, N, 1, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "SmoothingLength",
N_total, mpi_rank, offset, h, us, UNIT_CONV_LENGTH); FLOAT, N, 1, parts, N_total, mpi_rank, offset, h, us,
writeArray(h_grp, fileName, xmfFile, "InternalEnergy", FLOAT, N, 1, parts, UNIT_CONV_LENGTH);
N_total, mpi_rank, offset, u, us, UNIT_CONV_ENERGY_PER_UNIT_MASS); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "InternalEnergy",
writeArray(h_grp, fileName, xmfFile, "ParticleIDs", ULONGLONG, N, 1, parts, FLOAT, N, 1, parts, N_total, mpi_rank, offset, u, us,
N_total, mpi_rank, offset, id, us, UNIT_CONV_NO_UNITS); UNIT_CONV_ENERGY_PER_UNIT_MASS);
writeArray(h_grp, fileName, xmfFile, "Acceleration", FLOAT, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs",
N_total, mpi_rank, offset, a_hydro, us, UNIT_CONV_ACCELERATION); ULONGLONG, N, 1, parts, N_total, mpi_rank, offset, id, us,
writeArray(h_grp, fileName, xmfFile, "Density", FLOAT, N, 1, parts, N_total, UNIT_CONV_NO_UNITS);
mpi_rank, offset, rho, us, UNIT_CONV_DENSITY); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Acceleration", FLOAT,
N, 3, parts, N_total, mpi_rank, offset, a_hydro, us,
UNIT_CONV_ACCELERATION);
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Density", FLOAT, N,
1, parts, N_total, mpi_rank, offset, rho, us, UNIT_CONV_DENSITY);
} }
/** /**
......
...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
* @param h_grp The HDF5 group in which to write the arrays. * @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode). * @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 xmfFile The XMF file to write to (unused in MPI mode).
* @param N The number of particles on that MPI rank. * @param N The number of particles on that MPI rank.
* @param N_total The total number of particles (only used in MPI mode) * @param N_total The total number of particles (only used in MPI mode)
...@@ -67,27 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -67,27 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
*/ */
__attribute__((always_inline)) INLINE static void hydro_write_particles( __attribute__((always_inline)) INLINE static void hydro_write_particles(
hid_t h_grp, char* fileName, FILE* xmfFile, int N, long long N_total, hid_t h_grp, char* fileName, char* partTypeGroupName, FILE* xmfFile, int N,
int mpi_rank, long long offset, struct part* parts, struct UnitSystem* us) { long long N_total, int mpi_rank, long long offset, struct part* parts,
struct UnitSystem* us) {
/* Write arrays */ /* Write arrays */
writeArray(h_grp, fileName, xmfFile, "Coordinates", DOUBLE, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates", DOUBLE,
N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH); N, 3, parts, N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH);
writeArray(h_grp, fileName, xmfFile, "Velocities", FLOAT, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities", FLOAT,
N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED); N, 3, parts, N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED);
writeArray(h_grp, fileName, xmfFile, "Masses", FLOAT, N, 1, parts, N_total, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT, N, 1,
mpi_rank, offset, mass, us, UNIT_CONV_MASS); parts, N_total, mpi_rank, offset, mass, us, UNIT_CONV_MASS);
writeArray(h_grp, fileName, xmfFile, "SmoothingLength", FLOAT, N, 1, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "SmoothingLength",
N_total, mpi_rank, offset, h, us, UNIT_CONV_LENGTH); FLOAT, N, 1, parts, N_total, mpi_rank, offset, h, us,
writeArray(h_grp, fileName, xmfFile, "InternalEnergy", FLOAT, N, 1, parts, UNIT_CONV_LENGTH);
N_total, mpi_rank, offset, entropy, us, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "InternalEnergy",
FLOAT, N, 1, parts, N_total, mpi_rank, offset, entropy, us,
UNIT_CONV_ENTROPY_PER_UNIT_MASS); UNIT_CONV_ENTROPY_PER_UNIT_MASS);
writeArray(h_grp, fileName, xmfFile, "ParticleIDs", ULONGLONG, N, 1, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs",
N_total, mpi_rank, offset, id, us, UNIT_CONV_NO_UNITS); ULONGLONG, N, 1, parts, N_total, mpi_rank, offset, id, us,
writeArray(h_grp, fileName, xmfFile, "Acceleration", FLOAT, N, 3, parts, UNIT_CONV_NO_UNITS);
N_total, mpi_rank, offset, a_hydro, us, UNIT_CONV_ACCELERATION); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Acceleration", FLOAT,
writeArray(h_grp, fileName, xmfFile, "Density", FLOAT, N, 1, parts, N_total, N, 3, parts, N_total, mpi_rank, offset, a_hydro, us,
mpi_rank, offset, rho, us, UNIT_CONV_DENSITY); UNIT_CONV_ACCELERATION);
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Density", FLOAT, N,
1, parts, N_total, mpi_rank, offset, rho, us, UNIT_CONV_DENSITY);
} }
/** /**
......
...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -56,6 +56,8 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
* @param h_grp The HDF5 group in which to write the arrays. * @param h_grp The HDF5 group in which to write the arrays.
* @param fileName The name of the file (unsued in MPI mode). * @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 xmfFile The XMF file to write to (unused in MPI mode).
* @param N The number of particles on that MPI rank. * @param N The number of particles on that MPI rank.
* @param N_total The total number of particles (only used in MPI mode) * @param N_total The total number of particles (only used in MPI mode)
...@@ -67,26 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles( ...@@ -67,26 +69,31 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
* *
*/ */
__attribute__((always_inline)) INLINE static void hydro_write_particles( __attribute__((always_inline)) INLINE static void hydro_write_particles(
hid_t h_grp, char* fileName, FILE* xmfFile, int N, long long N_total, hid_t h_grp, char* fileName, char* partTypeGroupName, FILE* xmfFile, int N,
int mpi_rank, long long offset, struct part* parts, struct UnitSystem* us) { long long N_total, int mpi_rank, long long offset, struct part* parts,
struct UnitSystem* us) {
/* Write arrays */ /* Write arrays */
writeArray(h_grp, fileName, xmfFile, "Coordinates", DOUBLE, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Coordinates", DOUBLE,
N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH); N, 3, parts, N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH);
writeArray(h_grp, fileName, xmfFile, "Velocities", FLOAT, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Velocities", FLOAT,
N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED); N, 3, parts, N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED);
writeArray(h_grp, fileName, xmfFile, "Masses", FLOAT, N, 1, parts, N_total, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Masses", FLOAT, N, 1,
mpi_rank, offset, mass, us, UNIT_CONV_MASS); parts, N_total, mpi_rank, offset, mass, us, UNIT_CONV_MASS);
writeArray(h_grp, fileName, xmfFile, "SmoothingLength", FLOAT, N, 1, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "SmoothingLength",
N_total, mpi_rank, offset, h, us, UNIT_CONV_LENGTH); FLOAT, N, 1, parts, N_total, mpi_rank, offset, h, us,
writeArray(h_grp, fileName, xmfFile, "InternalEnergy", FLOAT, N, 1, parts, UNIT_CONV_LENGTH);
N_total, mpi_rank, offset, u, us, UNIT_CONV_ENERGY_PER_UNIT_MASS); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "InternalEnergy",
writeArray(h_grp, fileName, xmfFile, "ParticleIDs", ULONGLONG, N, 1, parts, FLOAT, N, 1, parts, N_total, mpi_rank, offset, u, us,
N_total, mpi_rank, offset, id, us, UNIT_CONV_NO_UNITS); UNIT_CONV_ENERGY_PER_UNIT_MASS);
writeArray(h_grp, fileName, xmfFile, "Acceleration", FLOAT, N, 3, parts, writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "ParticleIDs",
N_total, mpi_rank, offset, a_hydro, us, UNIT_CONV_ACCELERATION); ULONGLONG, N, 1, parts, N_total, mpi_rank, offset, id, us,
writeArray(h_grp, fileName, xmfFile, "Density", FLOAT, N, 1, parts, N_total, UNIT_CONV_NO_UNITS);
mpi_rank, offset, rho, us, UNIT_CONV_DENSITY); writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Acceleration", FLOAT,
N, 3, parts, N_total, mpi_rank, offset, a_hydro, us,
UNIT_CONV_ACCELERATION);
writeArray(h_grp, fileName, xmfFile, partTypeGroupName, "Density", FLOAT, N,
1, parts, N_total, mpi_rank, offset, rho, us, UNIT_CONV_DENSITY);
} }
/** /**
......
...@@ -178,9 +178,10 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, ...@@ -178,9 +178,10 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N,
* *
* Calls #error() if an error occurs. * Calls #error() if an error occurs.
*/ */
void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
enum DATA_TYPE type, int N, int dim, long long N_total, char* partTypeGroupName, char* name, enum DATA_TYPE type,
int mpi_rank, long long offset, char* part_c, int N, int dim, long long N_total, int mpi_rank,
long long offset, char* part_c, size_t partSize,
struct UnitSystem* us, struct UnitSystem* us,
enum UnitConversionFactor convFactor) { enum UnitConversionFactor convFactor) {
hid_t h_data = 0, h_err = 0, h_memspace = 0, h_filespace = 0, h_plist_id = 0; hid_t h_data = 0, h_err = 0, h_memspace = 0, h_filespace = 0, h_plist_id = 0;
...@@ -189,7 +190,6 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, ...@@ -189,7 +190,6 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
int i = 0, rank = 0; int i = 0, rank = 0;
const size_t typeSize = sizeOfType(type); const size_t typeSize = sizeOfType(type);
const size_t copySize = typeSize * dim; const size_t copySize = typeSize * dim;
const size_t partSize = sizeof(struct part);
char* temp_c = 0; char* temp_c = 0;
char buffer[150]; char buffer[150];
...@@ -269,7 +269,9 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, ...@@ -269,7 +269,9 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
} }
/* Write XMF description for this data set */ /* Write XMF description for this data set */
if (mpi_rank == 0) writeXMFline(xmfFile, fileName, name, N_total, dim, type); if (mpi_rank == 0)
writeXMFline(xmfFile, fileName, partTypeGroupName, name, N_total, dim,
type);
/* Write unit conversion factors for this data set */ /* Write unit conversion factors for this data set */
conversionString(buffer, us, convFactor); conversionString(buffer, us, convFactor);
...@@ -328,14 +330,16 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, ...@@ -328,14 +330,16 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
* @param convFactor The UnitConversionFactor for this array * @param convFactor The UnitConversionFactor for this array
* *
*/ */
#define writeArray(grp, fileName, xmfFile, name, type, N, dim, part, N_total, \ #define writeArray(grp, fileName, xmfFile, pTypeGroupName, name, type, N, dim, \
mpi_rank, offset, field, us, convFactor) \ part, N_total, mpi_rank, offset, field, us, convFactor) \
writeArrayBackEnd(grp, fileName, xmfFile, name, type, N, dim, N_total, \ writeArrayBackEnd(grp, fileName, xmfFile, pTypeGroupName, name, type, N, \
mpi_rank, offset, (char*)(&(part[0]).field), us, \ dim, N_total, mpi_rank, offset, (char*)(&(part[0]).field), \
convFactor) sizeof(part[0]), us, convFactor)
/* Import the right hydro definition */ /* Import the right hydro definition */
#include "hydro_io.h" #include "hydro_io.h"
/* Import the right gravity definition */
#include "gravity_io.h"
/** /**
* @brief Reads an HDF5 initial condition file (GADGET-3 type) in parallel * @brief Reads an HDF5 initial condition file (GADGET-3 type) in parallel
...@@ -357,16 +361,17 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, ...@@ -357,16 +361,17 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
* *
*/ */
void read_ic_parallel(char* fileName, double dim[3], struct part** parts, void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
size_t* N, int* periodic, int mpi_rank, int mpi_size, struct gpart** gparts, size_t* Ngas, size_t* Ngparts,
MPI_Comm comm, MPI_Info info) { int* periodic, int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info) {
hid_t h_file = 0, h_grp = 0; hid_t h_file = 0, h_grp = 0;
double boxSize[3] = { /* GADGET has only cubic boxes (in cosmological mode) */
0.0, -1.0, -1.0}; /* GADGET has only cubic boxes (in cosmological mode) */ double boxSize[3] = {0.0, -1.0, -1.0};
int numParticles[6] = { int numParticles[NUM_PARTICLE_TYPES] = {0};
0}; /* GADGET has 6 particle types. We only keep the type 0*/ int numParticles_highWord[NUM_PARTICLE_TYPES] = {0};
int numParticles_highWord[6] = {0}; size_t N[NUM_PARTICLE_TYPES] = {0};
long long offset = 0; long long N_total[NUM_PARTICLE_TYPES] = {0};
long long N_total = 0; long long offset[NUM_PARTICLE_TYPES] = {0};
/* Open file */ /* Open file */
/* message("Opening file '%s' as IC.", fileName); */ /* message("Opening file '%s' as IC.", fileName); */
...@@ -398,58 +403,116 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts, ...@@ -398,58 +403,116 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
readAttribute(h_grp, "NumPart_Total", UINT, numParticles); readAttribute(h_grp, "NumPart_Total", UINT, numParticles);
readAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticles_highWord); readAttribute(h_grp, "NumPart_Total_HighWord", UINT, numParticles_highWord);
N_total = ((long long)numParticles[0]) + for (int ptype = 0; ptype < NUM_PARTICLE_TYPES; ++ptype)
((long long)numParticles_highWord[0] << 32); N_total[ptype] = ((long long)numParticles[ptype]) +
((long long)numParticles_highWord[ptype] << 32);
dim[0] = boxSize[0];