diff --git a/src/engine.c b/src/engine.c index 96d72669ca6eb4282e3baa4276fab2e7987bd97a..1ae4dff2517b22aa4760a690c082b64743f54243 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2672,7 +2672,7 @@ void engine_dump_snapshot(struct engine *e) { struct clocks_time time1, time2; clocks_gettime(&time1); - if (e->verbose) message("writing snapshot at t=%f.", e->time); + if (e->verbose) message("writing snapshot at t=%e.", e->time); /* Dump... */ #if defined(WITH_MPI) @@ -2808,7 +2808,7 @@ void engine_init(struct engine *e, struct space *s, e->ti_nextSnapshot = 0; parser_get_param_string(params, "Snapshots:basename", e->snapshotBaseName); e->snapshotUnits = malloc(sizeof(struct UnitSystem)); - units_init(e->snapshotUnits, params, "Snapshots"); + units_init_default(e->snapshotUnits, params, "Snapshots", internal_units); e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min"); e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max"); e->file_stats = NULL; @@ -3228,6 +3228,6 @@ void engine_compute_next_snapshot_time(struct engine *e) { const float next_snapshot_time = e->ti_nextSnapshot * e->timeBase + e->timeBegin; if (e->verbose) - message("Next output time set to t=%f.", next_snapshot_time); + message("Next output time set to t=%e.", next_snapshot_time); } } diff --git a/src/units.c b/src/units.c index 0284ebfb993c9c31d399a6ae45ec2b8d543e2a34..65d3ef5d6d838d028c47cb13688f0fcbf2d75237 100644 --- a/src/units.c +++ b/src/units.c @@ -66,6 +66,41 @@ void units_init(struct UnitSystem* us, const struct swift_params* params, us->UnitTemperature_in_cgs = parser_get_param_double(params, buffer); } +/** + * @brief Initialises the UnitSystem structure with the constants given in + * rhe parameter file. Uses a default if the values are not present in the file. + * + * @param us The UnitSystem to initialize. + * @param params The parsed parameter file. + * @param category The section of the parameter file to read from. + * @param def The default unit system to copy from if required. + */ +void units_init_default(struct UnitSystem* us, + const struct swift_params* params, const char* category, + const struct UnitSystem* def) { + + if (!def) error("Default UnitSystem not allocated"); + + char buffer[200]; + sprintf(buffer, "%s:UnitMass_in_cgs", category); + us->UnitMass_in_cgs = + parser_get_opt_param_double(params, buffer, def->UnitMass_in_cgs); + sprintf(buffer, "%s:UnitLength_in_cgs", category); + us->UnitLength_in_cgs = + parser_get_opt_param_double(params, buffer, def->UnitLength_in_cgs); + sprintf(buffer, "%s:UnitVelocity_in_cgs", category); + const double defaultVelocity = def->UnitLength_in_cgs / def->UnitTime_in_cgs; + const double unitVelocity = + parser_get_opt_param_double(params, buffer, defaultVelocity); + us->UnitTime_in_cgs = us->UnitLength_in_cgs / unitVelocity; + sprintf(buffer, "%s:UnitCurrent_in_cgs", category); + us->UnitCurrent_in_cgs = + parser_get_opt_param_double(params, buffer, def->UnitCurrent_in_cgs); + sprintf(buffer, "%s:UnitTemp_in_cgs", category); + us->UnitTemperature_in_cgs = + parser_get_opt_param_double(params, buffer, def->UnitTemperature_in_cgs); +} + /** * @brief Returns the base unit conversion factor for a given unit system * @param us The UnitSystem used diff --git a/src/units.h b/src/units.h index 29b4563163b4fe224c881b1c1055f2cbfbcc95a1..340a1f37301dfd499a9569ae31572d81d978b64e 100644 --- a/src/units.h +++ b/src/units.h @@ -94,6 +94,10 @@ enum UnitConversionFactor { void units_init(struct UnitSystem*, const struct swift_params*, const char* category); +void units_init_default(struct UnitSystem* us, + const struct swift_params* params, const char* category, + const struct UnitSystem* def); + int units_are_equal(const struct UnitSystem* a, const struct UnitSystem* b); /* Base units */