gitlab is upgraded to version 13, please report any issues and enjoy

Commit 222bf7c8 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Reading arrays now uses new io_props structure

parent acdfeda0
......@@ -345,8 +345,8 @@ int main(int argc, char *argv[]) {
MPI_INFO_NULL, dry_run);
#endif
#else
read_ic_single(ICfileName, &us, dim, &parts, &gparts, &Ngas, &Ngpart, &periodic,
&flag_entropy_ICs, dry_run);
read_ic_single(ICfileName, &us, dim, &parts, &gparts, &Ngas, &Ngpart,
&periodic, &flag_entropy_ICs, dry_run);
#endif
if (myrank == 0) {
clocks_gettime(&toc);
......
......@@ -54,7 +54,7 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
# Include files for distribution, not installation.
nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \
vector.h runner_doiact.h runner_doiact_grav.h units.h intrinsics.h minmax.h kick.h \
timestep.h drift.h \
timestep.h drift.h io_properties.h \
gravity.h gravity_io.h \
gravity/Default/gravity.h gravity/Default/gravity_iact.h gravity/Default/gravity_io.h \
gravity/Default/gravity_debug.h gravity/Default/gravity_part.h \
......
......@@ -649,25 +649,4 @@ void collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
count, Ndm);
}
/**
* @brief Construct an #io_props from its parameters
*/
struct io_props io_make_input_field_(char name[FIELD_BUFFER_SIZE],
enum DATA_TYPE type, int dimension,
enum DATA_IMPORTANCE importance,
enum UnitConversionFactor units,
char* field, size_t partSize) {
struct io_props r;
strcpy(r.name, name);
r.type = type;
r.dimension = dimension;
r.importance = importance;
r.units = units;
r.field = field;
r.partSize = partSize;
return r;
}
#endif
......@@ -45,13 +45,6 @@ enum DATA_TYPE {
CHAR
};
/**
* @brief The two sorts of data present in the GADGET IC files: compulsory to
*start a run or optional.
*
*/
enum DATA_IMPORTANCE { COMPULSORY = 1, OPTIONAL = 0 };
/**
* @brief The different particle types present in a GADGET IC file
*
......@@ -110,46 +103,6 @@ void readUnitSystem(hid_t h_file, struct UnitSystem* us);
void writeUnitSystem(hid_t h_grp, const struct UnitSystem* us,
const char* groupName);
/**
* @brief The properties of a given dataset for i/o
*/
struct io_props {
/* Name */
char name[FIELD_BUFFER_SIZE];
/* Type of the field */
enum DATA_TYPE type;
/* Dimension (1D, 3D, ...) */
int dimension;
/* Is it compulsory ? (input only) */
enum DATA_IMPORTANCE importance;
/* Units of the quantity */
enum UnitConversionFactor units;
/* Pointer to the field of the first particle in the array */
char* field;
/* The size of the particles */
size_t partSize;
};
/**
* @brief Constructs an #io_props from its attributes
*/
#define io_make_input_field(name, type, dim, importance, units, part, field) \
io_make_input_field_(name, type, dim, importance, units, \
(char*)(&(part[0]).field), sizeof(part[0]))
struct io_props io_make_input_field_(char name[FIELD_BUFFER_SIZE],
enum DATA_TYPE type, int dimension,
enum DATA_IMPORTANCE importance,
enum UnitConversionFactor units,
char* field, size_t partSize);
#endif /* defined HDF5 */
#endif /* SWIFT_COMMON_IO_H */
......@@ -30,13 +30,11 @@
* @param ic_units The #UnitSystem used in the snapshots
*
*/
__attribute__((always_inline)) INLINE static void darkmatter_read_particles(
hid_t h_grp, int N, long long N_total, long long offset,
struct gpart* gparts, const struct UnitSystem* internal_units,
struct UnitSystem* ic_units) {
void darkmatter_read_particles(struct gpart* gparts, struct io_props* list,
int* num_fields) {
const int num_fields = 4;
struct io_props list[num_fields];
/* Say how much we want to read */
*num_fields = 4;
/* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
......@@ -46,7 +44,7 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles(
list[2] = io_make_input_field("Masses", FLOAT, 1, COMPULSORY, UNIT_CONV_MASS,
gparts, mass);
list[3] = io_make_input_field("ParticleIDs", ULONGLONG, 1, COMPULSORY,
UNIT_CONV_NO_UNITS, gparts, id);
UNIT_CONV_NO_UNITS, gparts, id_or_neg_offset);
/* Read arrays */
/* readArray(h_grp, "Coordinates", DOUBLE, N, 3, gparts, N_total, offset, x,
......@@ -62,8 +60,9 @@ __attribute__((always_inline)) INLINE static void darkmatter_read_particles(
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_NO_UNITS); */
/* And read everything */
for (int i = 0; i < num_fields; ++i)
readArray(h_grp, list[i], N, N_total, offset, internal_units, ic_units);
/* for (int i = 0; i < num_fields; ++i) */
/* readArray(h_grp, list[i], N, N_total, offset, internal_units, ic_units);
*/
}
/**
......@@ -101,6 +100,7 @@ __attribute__((always_inline)) INLINE static void darkmatter_write_particles(
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,
internal_units, snapshot_units, UNIT_CONV_NO_UNITS);
ULONGLONG, Ndm, 1, gparts, Ndm_total, mpi_rank, offset,
id_or_neg_offset, internal_units, snapshot_units,
UNIT_CONV_NO_UNITS);
}
......@@ -30,12 +30,10 @@
* @param ic_units The #UnitSystem used in the snapshots
*
*/
__attribute__((always_inline)) INLINE static void hydro_read_particles(
hid_t h_grp, int N, long long N_total, long long offset, struct part* parts,
const struct UnitSystem* internal_units, struct UnitSystem* ic_units) {
void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) {
const int num_fields = 8;
struct io_props list[num_fields];
*num_fields = 8;
/* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
......@@ -54,32 +52,6 @@ __attribute__((always_inline)) INLINE static void hydro_read_particles(
UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, rho);
/* Read arrays */
/* readArray(h_grp, "Coordinates", DOUBLE, N, 3, parts, N_total, offset, x, */
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_LENGTH); */
/* readArray(h_grp, "Velocities", FLOAT, N, 3, parts, N_total, offset, v, */
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_SPEED); */
/* readArray(h_grp, "Masses", FLOAT, N, 1, parts, N_total, offset, mass, */
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_MASS); */
/* readArray(h_grp, "SmoothingLength", FLOAT, N, 1, parts, N_total, offset, h,
*/
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_LENGTH); */
/* readArray(h_grp, "InternalEnergy", FLOAT, N, 1, parts, N_total, offset, */
/* entropy, COMPULSORY, internal_units, ic_units, UNIT_CONV_ENERGY);
*/
/* readArray(h_grp, "ParticleIDs", ULONGLONG, N, 1, parts, N_total, offset,
* id, */
/* COMPULSORY, internal_units, ic_units, UNIT_CONV_NO_UNITS); */
/* readArray(h_grp, "Acceleration", FLOAT, N, 3, parts, N_total, offset,
* a_hydro, */
/* OPTIONAL, internal_units, ic_units, UNIT_CONV_ACCELERATION); */
/* readArray(h_grp, "Density", FLOAT, N, 1, parts, N_total, offset, rho, */
/* OPTIONAL, internal_units, ic_units, UNIT_CONV_DENSITY); */
/* And read everything */
for (int i = 0; i < num_fields; ++i)
readArray(h_grp, list[i], N, N_total, offset, internal_units, ic_units);
}
/**
......
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef SWIFT_IO_PROPERTIES_H
#define SWIFT_IO_PROPERTIES_H
/* Config parameters. */
#include "../config.h"
/**
* @brief The two sorts of data present in the GADGET IC files: compulsory to
* start a run or optional.
*/
enum DATA_IMPORTANCE { COMPULSORY = 1, OPTIONAL = 0 };
/**
* @brief The properties of a given dataset for i/o
*/
struct io_props {
/* Name */
char name[FIELD_BUFFER_SIZE];
/* Type of the field */
enum DATA_TYPE type;
/* Dimension (1D, 3D, ...) */
int dimension;
/* Is it compulsory ? (input only) */
enum DATA_IMPORTANCE importance;
/* Units of the quantity */
enum UnitConversionFactor units;
/* Pointer to the field of the first particle in the array */
char* field;
/* The size of the particles */
size_t partSize;
};
/**
* @brief Constructs an #io_props from its parameters
*/
#define io_make_input_field(name, type, dim, importance, units, part, field) \
io_make_input_field_(name, type, dim, importance, units, \
(char*)(&(part[0]).field), sizeof(part[0]))
/**
* @brief Construct an #io_props from its parameters
*
* @param name Name of the field to read
* @param type The type of the data
* @param dimension Dataset dimension (!D, 3D, ...)
* @param importance Is this dataset compulsory ?
* @param units The units of the dataset
* @param field Pointer to the field of the first particle
* @param partSize The size in byte of the particle
*
* Do not call this function directly. Use the macro defined above.
*/
struct io_props io_make_input_field_(char name[FIELD_BUFFER_SIZE],
enum DATA_TYPE type, int dimension,
enum DATA_IMPORTANCE importance,
enum UnitConversionFactor units,
char* field, size_t partSize) {
struct io_props r;
strcpy(r.name, name);
r.type = type;
r.dimension = dimension;
r.importance = importance;
r.units = units;
r.field = field;
r.partSize = partSize;
return r;
}
/**
* @brief Constructs an #io_props from its parameters
*/
#define io_make_output_field(name, type, dim, units, part, field) \
io_make_output_field_(name, type, dim, units, \
(char*)(&(part[0]).field), sizeof(part[0]))
/**
* @brief Construct an #io_props from its parameters
*
* @param name Name of the field to read
* @param type The type of the data
* @param dimension Dataset dimension (!D, 3D, ...)
* @param units The units of the dataset
* @param field Pointer to the field of the first particle
* @param partSize The size in byte of the particle
*
* Do not call this function directly. Use the macro defined above.
*/
struct io_props io_make_output_field_(char name[FIELD_BUFFER_SIZE],
enum DATA_TYPE type, int dimension,
enum UnitConversionFactor units,
char* field, size_t partSize) {
struct io_props r;
strcpy(r.name, name);
r.type = type;
r.dimension = dimension;
r.importance = 0;
r.units = units;
r.field = field;
r.partSize = partSize;
return r;
}
#endif /* SWIFT_IO_PROPERTIES_H */
......@@ -45,8 +45,9 @@
void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
struct gpart** gparts, size_t* Ngas, size_t* Ngparts,
int* periodic, int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info, int dry_run) {}
int* periodic, int* flag_entropy, int mpi_rank,
int mpi_size, MPI_Comm comm, MPI_Info info, int dry_run) {
}
void write_output_parallel(struct engine* e, const char* baseName,
struct UnitSystem* us, int mpi_rank, int mpi_size,
......
......@@ -38,6 +38,7 @@
#include "common_io.h"
#include "engine.h"
#include "error.h"
#include "io_properties.h"
#include "kernel_hydro.h"
#include "part.h"
#include "units.h"
......@@ -50,32 +51,17 @@
* @brief Reads a data array from a given HDF5 group.
*
* @param grp The group from which to read.
* @param name The name of the array 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 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 importance If COMPULSORY, the data must be present in the IC file. If
*OPTIONAL, the array will be zeroed when the data is not present.
* @param internal_units The #UnitSystem used internally
* @param ic_units The #UnitSystem used in the ICs
* @param convFactor The UnitConversionFactor for this array
*
* @todo A better version using HDF5 hyper-slabs to read the file directly into
*the part array
* will be written once the structures have been stabilized.
*/
/* void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, */
/* int dim, char* part_c, size_t partSize, */
/* enum DATA_IMPORTANCE importance, */
/* const struct UnitSystem* internal_units, */
/* const struct UnitSystem* ic_units, */
/* enum UnitConversionFactor convFactor) { */
void readArray(hid_t h_grp, const struct io_props prop, int N,
long long N_total, long long offset,
void readArray(hid_t h_grp, const struct io_props prop, size_t N,
const struct UnitSystem* internal_units,
const struct UnitSystem* ic_units) {
......@@ -304,34 +290,6 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
H5Sclose(h_space);
}
/**
* @brief A helper macro to call the readArrayBackEnd function more easily.
*
* @param grp The group from which to read.
* @param name The name of the array to read.
* @param type The #DATA_TYPE of the attribute.
* @param N The number of particles.
* @param dim The dimension of the data (1 for scalar, 3 for vector)
* @param part The array of particles to fill
* @param N_total Unused parameter in non-MPI mode
* @param offset Unused parameter in non-MPI mode
* @param field The name of the field (C code name as defined in part.h) to fill
* @param importance Is the data compulsory or not
* @param internal_units The #UnitSystem used internally
* @param ic_units The #UnitSystem used in the ICs
* @param convFactor The UnitConversionFactor for this array
*
*/
/* #define readArray(grp, name, type, N, dim, part, N_total, offset, field, \
*/
/* importance, internal_units, ic_units, convFactor) \
*/
/* readArrayBackEnd(grp, name, type, N, dim, (char*)(&(part[0]).field), \
*/
/* sizeof(part[0]), importance, internal_units, ic_units, \
*/
/* convFactor) */
/**
* @brief A helper macro to call the readArrayBackEnd function more easily.
*
......@@ -390,7 +348,8 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
*/
void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
double dim[3], struct part** parts, struct gpart** gparts,
size_t* Ngas, size_t* Ngparts, int* periodic, int* flag_entropy, int dry_run) {
size_t* Ngas, size_t* Ngparts, int* periodic,
int* flag_entropy, int dry_run) {
hid_t h_file = 0, h_grp = 0;
/* GADGET has only cubic boxes (in cosmological mode) */
......@@ -514,27 +473,32 @@ void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
error("Error while opening particle group %s.", partTypeGroupName);
}
/* message("Group %s found - reading...", partTypeGroupName); */
int num_fields = 0;
struct io_props list[100];
size_t N;
/* Read particle fields into the particle structure */
/* Read particle fields into the structure */
switch (ptype) {
case GAS:
if (!dry_run)
hydro_read_particles(h_grp, *Ngas, *Ngas, 0, *parts, internal_units,
ic_units);
N = *Ngas;
hydro_read_particles(*parts, list, &num_fields);
break;
case DM:
if (!dry_run)
darkmatter_read_particles(h_grp, Ndm, Ndm, 0, *gparts, internal_units,
ic_units);
N = Ndm;
darkmatter_read_particles(*gparts, list, &num_fields);
break;
default:
message("Particle Type %d not yet supported. Particles ignored", ptype);
}
/* Read everything */
if (!dry_run)
for (int i = 0; i < num_fields; ++i)
readArray(h_grp, list[i], N, internal_units, ic_units);
/* Close particle group */
H5Gclose(h_grp);
}
......
......@@ -31,7 +31,8 @@
void read_ic_single(char* fileName, const struct UnitSystem* internal_units,
double dim[3], struct part** parts, struct gpart** gparts,
size_t* Ngas, size_t* Ndm, int* periodic, int* flag_entropy, int dry_run);
size_t* Ngas, size_t* Ndm, int* periodic, int* flag_entropy,
int dry_run);
void write_output_single(struct engine* e, const char* baseName,
const struct UnitSystem* internal_units,
......
Markdown is supported
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