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

Commit be7945b2 authored by James Willis's avatar James Willis
Browse files

Add group ID to the hydro part in the snapshot.

parent 48314229
......@@ -786,6 +786,28 @@ void io_convert_part_f_mapper(void* restrict temp, int N,
&temp_f[i * dim]);
}
/**
* @brief Mapper function to copy #part into a buffer of ints using a
* conversion function.
*/
void io_convert_part_i_mapper(void* restrict temp, int N,
void* restrict extra_data) {
const struct io_props props = *((const struct io_props*)extra_data);
const struct part* restrict parts = props.parts;
const struct xpart* restrict xparts = props.xparts;
const struct engine* e = props.e;
const size_t dim = props.dimension;
/* How far are we with this chunk? */
int* restrict temp_i = (int*)temp;
const ptrdiff_t delta = (temp_i - props.start_temp_i) / dim;
for (int i = 0; i < N; i++)
props.convert_part_i(e, parts + delta + i, xparts + delta + i,
&temp_i[i * dim]);
}
/**
* @brief Mapper function to copy #part into a buffer of doubles using a
* conversion function.
......@@ -995,6 +1017,18 @@ void io_copy_temp_buffer(void* temp, const struct engine* e,
io_convert_part_f_mapper, temp_f, N, copySize, 0,
(void*)&props);
} else if (props.convert_part_i != NULL) {
/* Prepare some parameters */
int* temp_i = (int*)temp;
props.start_temp_i = (int*)temp;
props.e = e;
/* Copy the whole thing into a buffer */
threadpool_map((struct threadpool*)&e->threadpool,
io_convert_part_i_mapper, temp_i, N, copySize, 0,
(void*)&props);
} else if (props.convert_part_d != NULL) {
/* Prepare some parameters */
......
......@@ -128,6 +128,16 @@ INLINE static void convert_part_potential(const struct engine* e,
ret[0] = 0.f;
}
INLINE static void convert_part_group_id(const struct engine* e,
const struct part* p,
const struct xpart* xp, int* ret) {
if (p->gpart != NULL)
ret[0] = p->gpart->group_id;
else
ret[0] = 0;
}
/**
* @brief Specifies which particle fields to write to a dataset
*
......@@ -141,7 +151,7 @@ INLINE static void hydro_write_particles(const struct part* parts,
struct io_props* list,
int* num_fields) {
*num_fields = 10;
*num_fields = 11;
/* List what we want to write */
list[0] = io_make_output_field_convert_part("Coordinates", DOUBLE, 3,
......@@ -168,6 +178,10 @@ INLINE static void hydro_write_particles(const struct part* parts,
list[9] = io_make_output_field_convert_part("Potential", FLOAT, 1,
UNIT_CONV_POTENTIAL, parts,
xparts, convert_part_potential);
list[10] = io_make_output_field_convert_part("GroupID", INT, 1,
UNIT_CONV_NO_UNITS, parts,
xparts, convert_part_group_id);
#ifdef DEBUG_INTERACTIONS_SPH
......
......@@ -40,6 +40,9 @@ enum DATA_IMPORTANCE { COMPULSORY = 1, OPTIONAL = 0, UNUSED = -1 };
typedef void (*conversion_func_part_float)(const struct engine*,
const struct part*,
const struct xpart*, float*);
typedef void (*conversion_func_part_int)(const struct engine*,
const struct part*,
const struct xpart*, int*);
typedef void (*conversion_func_part_double)(const struct engine*,
const struct part*,
const struct xpart*, double*);
......@@ -86,6 +89,7 @@ struct io_props {
/* Pointer to the start of the temporary buffer used in i/o */
char* start_temp_c;
int* start_temp_i;
float* start_temp_f;
double* start_temp_d;
long long* start_temp_l;
......@@ -107,6 +111,7 @@ struct io_props {
/* Conversion function for part */
conversion_func_part_float convert_part_f;
conversion_func_part_int convert_part_i;
conversion_func_part_double convert_part_d;
conversion_func_part_long_long convert_part_l;
......@@ -226,6 +231,52 @@ INLINE static struct io_props io_make_output_field_(
io_make_output_field_convert_part_##type( \
name, type, dim, units, sizeof(part[0]), part, xpart, convert)
/**
* @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 (1D, 3D, ...)
* @param units The units of the dataset
* @param partSize The size in byte of the particle
* @param parts The particle array
* @param xparts The xparticle array
* @param functionPtr The function used to convert a particle to an int
*
* Do not call this function directly. Use the macro defined above.
*/
INLINE static struct io_props io_make_output_field_convert_part_INT(
const char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension,
enum unit_conversion_factor units, size_t partSize,
const struct part* parts, const struct xpart* xparts,
conversion_func_part_int functionPtr) {
struct io_props r;
strcpy(r.name, name);
r.type = type;
r.dimension = dimension;
r.importance = UNUSED;
r.units = units;
r.field = NULL;
r.partSize = partSize;
r.parts = parts;
r.xparts = xparts;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = functionPtr;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
r.convert_gpart_f = NULL;
r.convert_gpart_d = NULL;
r.convert_gpart_l = NULL;
r.convert_spart_f = NULL;
r.convert_spart_d = NULL;
r.convert_spart_l = NULL;
return r;
}
/**
* @brief Construct an #io_props from its parameters
*
......@@ -259,6 +310,7 @@ INLINE static struct io_props io_make_output_field_convert_part_FLOAT(
r.gparts = NULL;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = functionPtr;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -305,6 +357,7 @@ INLINE static struct io_props io_make_output_field_convert_part_DOUBLE(
r.gparts = NULL;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = functionPtr;
r.convert_part_l = NULL;
......@@ -351,6 +404,7 @@ INLINE static struct io_props io_make_output_field_convert_part_LONGLONG(
r.gparts = NULL;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = functionPtr;
......@@ -403,6 +457,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_FLOAT(
r.gparts = gparts;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -447,6 +502,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_DOUBLE(
r.gparts = gparts;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -491,6 +547,7 @@ INLINE static struct io_props io_make_output_field_convert_gpart_LONGLONG(
r.gparts = gparts;
r.sparts = NULL;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -543,6 +600,7 @@ INLINE static struct io_props io_make_output_field_convert_spart_FLOAT(
r.gparts = NULL;
r.sparts = sparts;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -587,6 +645,7 @@ INLINE static struct io_props io_make_output_field_convert_spart_DOUBLE(
r.gparts = NULL;
r.sparts = sparts;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......@@ -631,6 +690,7 @@ INLINE static struct io_props io_make_output_field_convert_spart_LONGLONG(
r.gparts = NULL;
r.sparts = sparts;
r.conversion = 1;
r.convert_part_i = NULL;
r.convert_part_f = NULL;
r.convert_part_d = NULL;
r.convert_part_l = NULL;
......
......@@ -1136,12 +1136,12 @@ void write_output_serial(struct engine* e, const char* baseName,
if (swift_memalign("parts_written", (void**)&parts_written,
part_align,
Ngas_written * sizeof(struct part)) != 0)
error("Error while allocating temporart memory for parts");
error("Error while allocating temporary memory for parts");
if (swift_memalign("xparts_written", (void**)&xparts_written,
xpart_align,
Ngas_written * sizeof(struct xpart)) != 0)
error("Error while allocating temporart memory for xparts");
error("Error while allocating temporary memory for xparts");
/* Collect the particles we want to write */
io_collect_parts_to_write(parts, xparts, parts_written,
xparts_written, Ngas, Ngas_written);
......
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