Commit 46eba013 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Add a constructor for the unit system that gets the 5 base units as direct input.

parent e3a01e02
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
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