Commit daa00858 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'snapshot_labels' into 'master'

Add option to label snapshots by the time

See merge request !601
parents 399b5a1a bbb17d29
......@@ -75,8 +75,7 @@ Snapshots:
time_first: 0. # (Optional) Time of the first output if non-cosmological time-integration (in internal units)
delta_time: 0.01 # Time difference between consecutive outputs (in internal units)
compression: 0 # (Optional) Set the level of compression of the HDF5 datasets [0-9]. 0 does no compression.
label_first: 0 # (Optional) An additional offset for the snapshot output label
label_delta: 1 # (Optional) Set the integer increment between snapshot output labels
int_time_label_on: 0 # (Optional) Enable to label the snapshots using the time rounded to an integer (in internal units)
UnitMass_in_cgs: 1 # (Optional) Unit system for the outputs (Grams)
UnitLength_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters)
UnitVelocity_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters per second)
......
......@@ -5898,12 +5898,8 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params,
parser_get_param_string(params, "Snapshots:basename", e->snapshot_base_name);
e->snapshot_compression =
parser_get_opt_param_int(params, "Snapshots:compression", 0);
e->snapshot_label_first =
parser_get_opt_param_int(params, "Snapshots:label_first", 0);
if (e->snapshot_label_first < 0)
error("Snapshots:label_first must be zero or positive");
e->snapshot_label_delta =
parser_get_opt_param_int(params, "Snapshots:label_delta", 1);
e->snapshot_int_time_label_on =
parser_get_opt_param_int(params, "Snapshots:int_time_label_on", 0);
e->snapshot_units = (struct unit_system *)malloc(sizeof(struct unit_system));
units_init_default(e->snapshot_units, params, "Snapshots", internal_units);
e->snapshot_output_count = 0;
......@@ -6265,6 +6261,10 @@ void engine_config(int restart, struct engine *e, struct swift_params *params,
"(t_beg = %e)",
e->time_end, e->time_begin);
/* Check we don't have inappropriate time labels */
if ((e->snapshot_int_time_label_on == 1) && (e->time_end <= 1.f))
error("Snapshot integer time labels enabled but end time <= 1");
/* Check we have sensible time-step values */
if (e->dt_min > e->dt_max)
error(
......
......@@ -223,8 +223,7 @@ struct engine {
char snapshot_base_name[PARSER_MAX_LINE_SIZE];
int snapshot_compression;
int snapshot_label_first;
int snapshot_label_delta;
int snapshot_int_time_label_on;
struct unit_system *snapshot_units;
int snapshot_output_count;
......
......@@ -931,13 +931,12 @@ void prepare_file(struct engine* e, const char* baseName, long long N_total[6],
/* HDF5 File name */
char fileName[FILENAME_BUFFER_SIZE];
if (e->snapshot_label_delta == 1)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count + e->snapshot_label_first);
else
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
e->snapshot_output_count * e->snapshot_label_delta +
e->snapshot_label_first);
(int)round(e->time));
else
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
/* Open HDF5 file with the chosen parameters */
hid_t h_file = H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
......@@ -1212,13 +1211,12 @@ void write_output_parallel(struct engine* e, const char* baseName,
/* HDF5 File name */
char fileName[FILENAME_BUFFER_SIZE];
if (e->snapshot_label_delta == 1)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count + e->snapshot_label_first);
else
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
e->snapshot_output_count * e->snapshot_label_delta +
e->snapshot_label_first);
(int)round(e->time));
else
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
/* Prepare some file-access properties */
hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
......
......@@ -758,13 +758,12 @@ void write_output_serial(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
if (e->snapshot_label_delta == 1)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count + e->snapshot_label_first);
else
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
e->snapshot_output_count * e->snapshot_label_delta +
e->snapshot_label_first);
(int)round(e->time));
else
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
/* Compute offset in the file and total number of particles */
size_t N[swift_type_count] = {Ngas, Ndm, 0, 0, Nstars, 0};
......
......@@ -624,13 +624,12 @@ void write_output_single(struct engine* e, const char* baseName,
/* File name */
char fileName[FILENAME_BUFFER_SIZE];
if (e->snapshot_label_delta == 1)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count + e->snapshot_label_first);
else
if (e->snapshot_int_time_label_on)
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%06i.hdf5", baseName,
e->snapshot_output_count * e->snapshot_label_delta +
e->snapshot_label_first);
(int)round(e->time));
else
snprintf(fileName, FILENAME_BUFFER_SIZE, "%s_%04i.hdf5", baseName,
e->snapshot_output_count);
/* First time, we need to create the XMF file */
if (e->snapshot_output_count == 0) xmf_create_file(baseName);
......
......@@ -44,7 +44,6 @@ void select_output_engine_init(struct engine *e, struct space *s,
e->time = 0;
e->snapshot_output_count = 0;
e->snapshot_compression = 0;
e->snapshot_label_delta = 1;
};
void select_output_space_init(struct space *s, double *dim, int periodic,
......
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