Skip to content
Snippets Groups Projects
Commit 0b650d6b authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Allow the users to overwrite the value of Newton's constant via the YAML file.

parent a0e0089d
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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.
......
......@@ -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",
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment