From 46eba0134d4e213956a761609f306055685409a9 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Wed, 9 May 2018 16:09:23 +0200 Subject: [PATCH] Add a constructor for the unit system that gets the 5 base units as direct input. --- examples/main.c | 2 +- src/units.c | 24 ++++++++++++++++++++++-- src/units.h | 6 +++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/main.c b/examples/main.c index dfbfafdb7f..690cbba113 100644 --- a/examples/main.c +++ b/examples/main.c @@ -590,7 +590,7 @@ int main(int argc, char *argv[]) { /* Not restarting so look for the ICs. */ /* Initialize unit system and constants */ - units_init(&us, params, "InternalUnitSystem"); + units_init_from_params(&us, params, "InternalUnitSystem"); phys_const_init(&us, params, &prog_const); if (myrank == 0 && verbose > 0) { message("Internal unit system: U_M = %e g.", us.UnitMass_in_cgs); diff --git a/src/units.c b/src/units.c index 4b632e735b..826c005c5c 100644 --- a/src/units.c +++ b/src/units.c @@ -55,6 +55,25 @@ void units_init_cgs(struct unit_system* us) { us->UnitTemperature_in_cgs = 1.; } +/** + * @brief Initialise the unit_system with values for the base units. + * + * @param us The #unit_system to initialise. + * @param U_M_in_cgs The mass unit in [g]. + * @param U_L_in_cgs The length unit in [cm]. + * @param U_t_in_cgs The time unit in [s]. + * @param U_C_in_cgs The current unit in [A]. + * @param U_T_in_cgs The temperature unit in [K]. + */ +void units_init(struct unit_system* us, double U_M_in_cgs, double U_L_in_cgs, + double U_t_in_cgs, double U_C_in_cgs, double U_T_in_cgs) { + us->UnitMass_in_cgs = U_M_in_cgs; + us->UnitLength_in_cgs = U_L_in_cgs; + us->UnitTime_in_cgs = U_t_in_cgs; + us->UnitCurrent_in_cgs = U_C_in_cgs; + us->UnitTemperature_in_cgs = U_T_in_cgs; +} + /** * @brief Initialises the unit_system structure with the constants given in * the parameter file. @@ -63,8 +82,9 @@ void units_init_cgs(struct unit_system* us) { * @param params The parsed parameter file. * @param category The section of the parameter file to read from. */ -void units_init(struct unit_system* us, const struct swift_params* params, - const char* category) { +void units_init_from_params(struct unit_system* us, + const struct swift_params* params, + const char* category) { char buffer[200]; sprintf(buffer, "%s:UnitMass_in_cgs", category); diff --git a/src/units.h b/src/units.h index 87c44cc6eb..263ce8e128 100644 --- a/src/units.h +++ b/src/units.h @@ -28,7 +28,7 @@ /** * @brief The unit system used internally. * - * This structure contains the conversion factors to the 7 cgs base units to the + * This structure contains the conversion factors to the 5 cgs base units to the * internal units. It is used everytime a conversion is performed or an i/o * function is called. **/ @@ -96,8 +96,8 @@ enum unit_conversion_factor { }; void units_init_cgs(struct unit_system*); -void units_init(struct unit_system*, const struct swift_params*, - const char* category); +void units_init_from_params(struct unit_system*, const struct swift_params*, + const char* category); void units_init_default(struct unit_system* us, const struct swift_params* params, const char* category, const struct unit_system* def); -- GitLab