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

Merge branch 'unit_initialisation' into 'master'

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

See merge request !539
parents e3a01e02 b8008198
No related branches found
No related tags found
1 merge request!539Add a constructor for the unit system that gets the 5 base units as direct input.
......@@ -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);
......
......@@ -28,11 +28,6 @@
#include <stdlib.h>
#include <string.h>
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
#endif
/* This object's header. */
#include "units.h"
......@@ -55,6 +50,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 +77,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,10 @@ 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(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);
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment