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[]) { ...@@ -590,7 +590,7 @@ int main(int argc, char *argv[]) {
/* Not restarting so look for the ICs. */ /* Not restarting so look for the ICs. */
/* Initialize unit system and constants */ /* Initialize unit system and constants */
units_init(&us, params, "InternalUnitSystem"); units_init_from_params(&us, params, "InternalUnitSystem");
phys_const_init(&us, params, &prog_const); phys_const_init(&us, params, &prog_const);
if (myrank == 0 && verbose > 0) { if (myrank == 0 && verbose > 0) {
message("Internal unit system: U_M = %e g.", us.UnitMass_in_cgs); message("Internal unit system: U_M = %e g.", us.UnitMass_in_cgs);
......
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
#endif
/* This object's header. */ /* This object's header. */
#include "units.h" #include "units.h"
...@@ -55,6 +50,25 @@ void units_init_cgs(struct unit_system* us) { ...@@ -55,6 +50,25 @@ void units_init_cgs(struct unit_system* us) {
us->UnitTemperature_in_cgs = 1.; 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 * @brief Initialises the unit_system structure with the constants given in
* the parameter file. * the parameter file.
...@@ -63,8 +77,9 @@ void units_init_cgs(struct unit_system* us) { ...@@ -63,8 +77,9 @@ void units_init_cgs(struct unit_system* us) {
* @param params The parsed parameter file. * @param params The parsed parameter file.
* @param category The section of the parameter file to read from. * @param category The section of the parameter file to read from.
*/ */
void units_init(struct unit_system* us, const struct swift_params* params, void units_init_from_params(struct unit_system* us,
const char* category) { const struct swift_params* params,
const char* category) {
char buffer[200]; char buffer[200];
sprintf(buffer, "%s:UnitMass_in_cgs", category); sprintf(buffer, "%s:UnitMass_in_cgs", category);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
/** /**
* @brief The unit system used internally. * @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 * internal units. It is used everytime a conversion is performed or an i/o
* function is called. * function is called.
**/ **/
...@@ -96,8 +96,10 @@ enum unit_conversion_factor { ...@@ -96,8 +96,10 @@ enum unit_conversion_factor {
}; };
void units_init_cgs(struct unit_system*); void units_init_cgs(struct unit_system*);
void units_init(struct unit_system*, const struct swift_params*, void units_init(struct unit_system* us, double U_M_in_cgs, double U_L_in_cgs,
const char* category); 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, void units_init_default(struct unit_system* us,
const struct swift_params* params, const char* category, const struct swift_params* params, const char* category,
const struct unit_system* def); 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