diff --git a/examples/main.c b/examples/main.c index 4b4c36c68cd4420a0d831b9709eff4fd25256a70..c8af2d98bd3b3962b3c288cf21544d5f081a398b 100644 --- a/examples/main.c +++ b/examples/main.c @@ -589,7 +589,7 @@ int main(int argc, char *argv[]) { /* Not restarting so look for the ICs. */ /* Initialize unit system and constants */ units_init(&us, params, "InternalUnitSystem"); - phys_const_init(&us, &prog_const); + phys_const_init(&us, params, &prog_const); if (myrank == 0 && verbose > 0) { message("Internal unit system: U_M = %e g.", us.UnitMass_in_cgs); message("Internal unit system: U_L = %e cm.", us.UnitLength_in_cgs); diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 36da7a1e9971e03124927d0dbb7fe0ca52772eb1..5d5c8b7784f6a3408bf0e28e97d83855fa62e1d2 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -6,6 +6,10 @@ InternalUnitSystem: UnitCurrent_in_cgs: 1 # Amperes UnitTemp_in_cgs: 1 # Kelvin +# Values of some physical constants +PhysicalConstants: + G: 6.67408e-8 # (Optional) Overwrite the value of Newton's constant used internally by the code. + # Parameters for the task scheduling Scheduler: nr_queues: 0 # (Optional) The number of task queues to use. Use 0 to let the system decide. diff --git a/src/physical_constants.c b/src/physical_constants.c index 86b6d353cbe76a50cb42ae9dbc0a817667eeb3fb..b1dbeaeecfbf2e056a68b7866766bb07efb5efba 100644 --- a/src/physical_constants.c +++ b/src/physical_constants.c @@ -32,10 +32,14 @@ /** * @brief Converts physical constants to the internal unit system * + * Some constants can be overwritten by the YAML file values. + * * @param us The current internal system of units. + * @param params The parsed parameter file. * @param internal_const The physical constants to initialize. */ void phys_const_init(const struct unit_system *us, + const struct swift_params *params, struct phys_const *internal_const) { /* Units are declared as {U_M, U_L, U_t, U_I, U_T} */ @@ -44,6 +48,10 @@ void phys_const_init(const struct unit_system *us, internal_const->const_newton_G = const_newton_G_cgs / units_general_cgs_conversion_factor(us, dimension_G); + /* Overwrite G if present in the file */ + internal_const->const_newton_G = parser_get_opt_param_double( + params, "PhysicalConstants:G", internal_const->const_newton_G); + const float dimension_c[5] = {0, 1, -1, 0, 0}; internal_const->const_speed_light_c = const_speed_light_c_cgs / @@ -111,6 +119,11 @@ void phys_const_init(const struct unit_system *us, units_general_cgs_conversion_factor(us, dimension_length); } +/** + * @brief Print the value of the physical constants to stdout. + * + * @param internal_const The constants in the internal unit system. + */ void phys_const_print(const struct phys_const *internal_const) { message("%25s = %e", "Gravitational constant", diff --git a/src/physical_constants.h b/src/physical_constants.h index 20b97761aac2570dc35937bd00d79ffb14f96679..b0f929632ba8a55a57376975597e444a8344e4fc 100644 --- a/src/physical_constants.h +++ b/src/physical_constants.h @@ -29,6 +29,7 @@ #include "../config.h" /* Local includes. */ +#include "parser.h" #include "units.h" /** @@ -89,6 +90,7 @@ struct phys_const { }; void phys_const_init(const struct unit_system* us, + const struct swift_params* params, struct phys_const* internal_const); void phys_const_print(const struct phys_const* internal_const);