Commit 039540fd authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Re-factored the UnitSytem to use the same naming convention as the rest of the code.

parent 237a73ba
......@@ -351,7 +351,7 @@ int main(int argc, char *argv[]) {
#endif
/* Initialize unit system and constants */
struct UnitSystem us;
struct unit_system us;
struct phys_const prog_const;
units_init(&us, params, "InternalUnitSystem");
phys_const_init(&us, &prog_const);
......
......@@ -294,11 +294,11 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str) {
/**
* @brief Reads the Unit System from an IC file.
* @param h_file The (opened) HDF5 file from which to read.
* @param us The UnitSystem to fill.
* @param us The unit_system to fill.
*
* If the 'Units' group does not exist in the ICs, cgs units will be assumed
*/
void io_read_UnitSystem(hid_t h_file, struct UnitSystem* us) {
void io_read_unit_system(hid_t h_file, struct unit_system* us) {
hid_t h_grp = H5Gopen(h_file, "/Units", H5P_DEFAULT);
......@@ -334,10 +334,10 @@ void io_read_UnitSystem(hid_t h_file, struct UnitSystem* us) {
/**
* @brief Writes the current Unit System
* @param h_file The (opened) HDF5 file in which to write
* @param us The UnitSystem to dump
* @param us The unit_system to dump
* @param groupName The name of the HDF5 group to write to
*/
void io_write_UnitSystem(hid_t h_file, const struct UnitSystem* us,
void io_write_unit_system(hid_t h_file, const struct unit_system* us,
const char* groupName) {
hid_t h_grpunit = 0;
......
......@@ -68,8 +68,8 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str);
void io_write_code_description(hid_t h_file);
void io_read_UnitSystem(hid_t h_file, struct UnitSystem* us);
void io_write_UnitSystem(hid_t h_grp, const struct UnitSystem* us,
void io_read_unit_system(hid_t h_file, struct unit_system* us);
void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
const char* groupName);
#endif /* defined HDF5 */
......
......@@ -34,7 +34,7 @@
* @param cooling The cooling properties to initialize
*/
void cooling_init(const struct swift_params* parameter_file,
const struct UnitSystem* us,
const struct unit_system* us,
const struct phys_const* phys_const,
struct cooling_function_data* cooling) {
......
......@@ -42,7 +42,7 @@
/* Common functions */
void cooling_init(const struct swift_params* parameter_file,
const struct UnitSystem* us,
const struct unit_system* us,
const struct phys_const* phys_const,
struct cooling_function_data* cooling);
......
......@@ -58,7 +58,7 @@
*/
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us,
const struct unit_system* restrict us,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {
......@@ -103,7 +103,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us, const struct part* restrict p) {
const struct unit_system* restrict us, const struct part* restrict p) {
const float cooling_rate = cooling->cooling_rate;
const float internal_energy = hydro_get_internal_energy(p);
......@@ -153,7 +153,7 @@ __attribute__((always_inline)) INLINE static float cooling_get_radiated_energy(
* @param cooling The cooling properties to initialize
*/
static INLINE void cooling_init_backend(
const struct swift_params* parameter_file, const struct UnitSystem* us,
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const,
struct cooling_function_data* cooling) {
......
......@@ -45,7 +45,7 @@
* @param p Pointer to the particle data..
*/
__attribute__((always_inline)) INLINE static float cooling_rate(
const struct phys_const* const phys_const, const struct UnitSystem* us,
const struct phys_const* const phys_const, const struct unit_system* us,
const struct cooling_function_data* cooling, const struct part* p) {
/* Get particle density */
......@@ -72,7 +72,7 @@ __attribute__((always_inline)) INLINE static float cooling_rate(
*/
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us,
const struct unit_system* restrict us,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {
......@@ -112,7 +112,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us, const struct part* restrict p) {
const struct unit_system* restrict us, const struct part* restrict p) {
/* Get current internal energy */
const float u = hydro_get_internal_energy(p);
......@@ -158,7 +158,7 @@ __attribute__((always_inline)) INLINE static float cooling_get_radiated_energy(
* @param cooling The cooling properties to initialize
*/
static INLINE void cooling_init_backend(
const struct swift_params* parameter_file, const struct UnitSystem* us,
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const,
struct cooling_function_data* cooling) {
......
......@@ -49,7 +49,7 @@
*/
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us,
const struct unit_system* restrict us,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {}
......@@ -66,7 +66,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct UnitSystem* restrict us, const struct part* restrict p) {
const struct unit_system* restrict us, const struct part* restrict p) {
return FLT_MAX;
}
......@@ -107,7 +107,7 @@ __attribute__((always_inline)) INLINE static float cooling_get_radiated_energy(
* @param cooling The cooling properties to initialize
*/
static INLINE void cooling_init_backend(
const struct swift_params* parameter_file, const struct UnitSystem* us,
const struct swift_params* parameter_file, const struct unit_system* us,
const struct phys_const* phys_const,
struct cooling_function_data* cooling) {}
......
......@@ -3351,16 +3351,16 @@ void engine_dump_snapshot(struct engine *e) {
/* Dump... */
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel(e, e->snapshotBaseName, e->internalUnits,
write_output_parallel(e, e->snapshotBaseName, e->internal_units,
e->snapshotUnits, e->nodeID, e->nr_nodes,
MPI_COMM_WORLD, MPI_INFO_NULL);
#else
write_output_serial(e, e->snapshotBaseName, e->internalUnits,
write_output_serial(e, e->snapshotBaseName, e->internal_units,
e->snapshotUnits, e->nodeID, e->nr_nodes, MPI_COMM_WORLD,
MPI_INFO_NULL);
#endif
#else
write_output_single(e, e->snapshotBaseName, e->internalUnits,
write_output_single(e, e->snapshotBaseName, e->internal_units,
e->snapshotUnits);
#endif
......@@ -3448,7 +3448,7 @@ void engine_unpin() {
void engine_init(struct engine *e, struct space *s,
const struct swift_params *params, int nr_nodes, int nodeID,
int nr_threads, int with_aff, int policy, int verbose,
const struct UnitSystem *internal_units,
const struct unit_system *internal_units,
const struct phys_const *physical_constants,
const struct hydro_props *hydro,
const struct external_potential *potential,
......@@ -3480,7 +3480,7 @@ void engine_init(struct engine *e, struct space *s,
e->timeStep = 0.;
e->timeBase = 0.;
e->timeBase_inv = 0.;
e->internalUnits = internal_units;
e->internal_units = internal_units;
e->timeFirstSnapshot =
parser_get_param_double(params, "Snapshots:time_first");
e->deltaTimeSnapshot =
......@@ -3489,7 +3489,7 @@ void engine_init(struct engine *e, struct space *s,
parser_get_param_string(params, "Snapshots:basename", e->snapshotBaseName);
e->snapshotCompression =
parser_get_opt_param_int(params, "Snapshots:compression", 0);
e->snapshotUnits = malloc(sizeof(struct UnitSystem));
e->snapshotUnits = malloc(sizeof(struct unit_system));
units_init_default(e->snapshotUnits, params, "Snapshots", internal_units);
e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min");
e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max");
......
......@@ -135,7 +135,7 @@ struct engine {
size_t updates, g_updates, s_updates;
/* The internal system of units */
const struct UnitSystem *internalUnits;
const struct unit_system *internal_units;
/* Snapshot information */
double timeFirstSnapshot;
......@@ -143,7 +143,7 @@ struct engine {
integertime_t ti_nextSnapshot;
char snapshotBaseName[200];
int snapshotCompression;
struct UnitSystem *snapshotUnits;
struct unit_system *snapshotUnits;
/* Statistics information */
FILE *file_stats;
......@@ -219,7 +219,7 @@ void engine_dump_snapshot(struct engine *e);
void engine_init(struct engine *e, struct space *s,
const struct swift_params *params, int nr_nodes, int nodeID,
int nr_threads, int with_aff, int policy, int verbose,
const struct UnitSystem *internal_units,
const struct unit_system *internal_units,
const struct phys_const *physical_constants,
const struct hydro_props *hydro,
const struct external_potential *potential,
......
......@@ -47,7 +47,7 @@ struct io_props {
enum DATA_IMPORTANCE importance;
/* Units of the quantity */
enum UnitConversionFactor units;
enum unit_conversion_factor units;
/* Pointer to the field of the first particle in the array */
char* field;
......@@ -89,7 +89,7 @@ struct io_props {
struct io_props io_make_input_field_(char name[FIELD_BUFFER_SIZE],
enum IO_DATA_TYPE type, int dimension,
enum DATA_IMPORTANCE importance,
enum UnitConversionFactor units,
enum unit_conversion_factor units,
char* field, size_t partSize) {
struct io_props r;
strcpy(r.name, name);
......@@ -128,7 +128,7 @@ struct io_props io_make_input_field_(char name[FIELD_BUFFER_SIZE],
*/
struct io_props io_make_output_field_(char name[FIELD_BUFFER_SIZE],
enum IO_DATA_TYPE type, int dimension,
enum UnitConversionFactor units,
enum unit_conversion_factor units,
char* field, size_t partSize) {
struct io_props r;
strcpy(r.name, name);
......@@ -171,7 +171,7 @@ struct io_props io_make_output_field_(char name[FIELD_BUFFER_SIZE],
*/
struct io_props io_make_output_field_convert_part_(
char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension,
enum UnitConversionFactor units, char* field, size_t partSize,
enum unit_conversion_factor units, char* field, size_t partSize,
struct part* parts, float (*functionPtr)(struct engine*, struct part*)) {
struct io_props r;
......@@ -215,7 +215,7 @@ struct io_props io_make_output_field_convert_part_(
*/
struct io_props io_make_output_field_convert_gpart_(
char name[FIELD_BUFFER_SIZE], enum IO_DATA_TYPE type, int dimension,
enum UnitConversionFactor units, char* field, size_t partSize,
enum unit_conversion_factor units, char* field, size_t partSize,
struct gpart* gparts, float (*functionPtr)(struct engine*, struct gpart*)) {
struct io_props r;
......
......@@ -71,8 +71,8 @@
*/
void readArray(hid_t grp, const struct io_props prop, size_t N,
long long N_total, long long offset,
const struct UnitSystem* internal_units,
const struct UnitSystem* ic_units) {
const struct unit_system* internal_units,
const struct unit_system* ic_units) {
const size_t typeSize = io_sizeof_type(prop.type);
const size_t copySize = typeSize * prop.dimension;
......@@ -191,8 +191,8 @@ void readArray(hid_t grp, const struct io_props prop, size_t N,
* @param N The number of particles to write.
* @param N_total Total number of particles across all cores
* @param offset Offset in the array where this mpi task starts writing
* @param internal_units The #UnitSystem used internally
* @param snapshot_units The #UnitSystem used in the snapshots
* @param internal_units The #unit_system used internally
* @param snapshot_units The #unit_system used in the snapshots
*
* @todo A better version using HDF5 hyper-slabs to write the file directly from
* the part array will be written once the structures have been stabilized.
......@@ -201,8 +201,8 @@ void readArray(hid_t grp, const struct io_props prop, size_t N,
void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
char* partTypeGroupName, const struct io_props props, size_t N,
long long N_total, int mpi_rank, long long offset,
const struct UnitSystem* internal_units,
const struct UnitSystem* snapshot_units) {
const struct unit_system* internal_units,
const struct unit_system* snapshot_units) {
const size_t typeSize = io_sizeof_type(props.type);
const size_t copySize = typeSize * props.dimension;
......@@ -374,7 +374,7 @@ void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile,
* Calls #error() if an error occurs.
*
*/
void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
double dim[3], struct part** parts, struct gpart** gparts,
struct spart** sparts, size_t* Ngas, size_t* Ngparts,
size_t* Nstars, int* periodic, int* flag_entropy,
......@@ -458,9 +458,9 @@ void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
H5Gclose(h_grp);
/* Read the unit system used in the ICs */
struct UnitSystem* ic_units = malloc(sizeof(struct UnitSystem));
struct unit_system* ic_units = malloc(sizeof(struct unit_system));
if (ic_units == NULL) error("Unable to allocate memory for IC unit system");
io_read_UnitSystem(h_file, ic_units);
io_read_unit_system(h_file, ic_units);
/* Tell the user if a conversion will be needed */
if (mpi_rank == 0) {
......@@ -620,8 +620,8 @@ void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
*
* @param e The engine containing all the system.
* @param baseName The common part of the snapshot file name.
* @param internal_units The #UnitSystem used internally
* @param snapshot_units The #UnitSystem used in the snapshots
* @param internal_units The #unit_system used internally
* @param snapshot_units The #unit_system used in the snapshots
* @param mpi_rank The MPI rank of this node.
* @param mpi_size The number of MPI ranks.
* @param comm The MPI communicator.
......@@ -636,8 +636,8 @@ void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
*
*/
void write_output_parallel(struct engine* e, const char* baseName,
const struct UnitSystem* internal_units,
const struct UnitSystem* snapshot_units,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units,
int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info) {
......@@ -765,10 +765,10 @@ void write_output_parallel(struct engine* e, const char* baseName,
H5Gclose(h_grp);
/* Print the system of Units used in the spashot */
io_write_UnitSystem(h_file, snapshot_units, "Units");
io_write_unit_system(h_file, snapshot_units, "Units");
/* Print the system of Units used internally */
io_write_UnitSystem(h_file, internal_units, "InternalCodeUnits");
io_write_unit_system(h_file, internal_units, "InternalCodeUnits");
/* Tell the user if a conversion will be needed */
if (e->verbose && mpi_rank == 0) {
......
......@@ -34,7 +34,7 @@
#if defined(HAVE_HDF5) && defined(WITH_MPI) && defined(HAVE_PARALLEL_HDF5)
void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
double dim[3], struct part** parts, struct gpart** gparts,
struct spart** sparts, size_t* Ngas, size_t* Ngparts,
size_t* Nsparts, int* periodic, int* flag_entropy,
......@@ -43,8 +43,8 @@ void read_ic_parallel(char* fileName, const struct UnitSystem* internal_units,
int dry_run);
void write_output_parallel(struct engine* e, const char* baseName,
const struct UnitSystem* internal_units,
const struct UnitSystem* snapshot_units,
const struct unit_system* internal_units,
const struct unit_system* snapshot_units,
int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info);
#endif
......
......@@ -34,7 +34,8 @@
* @param us The current internal system of units.
* @param internal_const The physical constants to initialize.
*/
void phys_const_init(struct UnitSystem* us, struct phys_const* internal_const) {
void phys_const_init(struct unit_system* us,
struct phys_const* internal_const) {
/* Units are declared as {U_M, U_L, U_t, U_I, U_T} */
......
......@@ -78,7 +78,7 @@ struct phys_const {
double const_earth_mass;
};
void phys_const_init(struct UnitSystem* us, struct phys_const* internal_const);
void phys_const_init(struct unit_system* us, struct phys_const* internal_const);
void phys_const_print(struct phys_const* internal_const);
......
......@@ -36,7 +36,7 @@
*/
void potential_init(const struct swift_params* parameter_file,
const struct phys_const* phys_const,
const struct UnitSystem* us, const struct space* s,
const struct unit_system* us, const struct space* s,
struct external_potential* potential) {
potential_init_backend(parameter_file, phys_const, us, s, potential);
......
......@@ -43,7 +43,7 @@
/* Now, some generic functions, defined in the source file */
void potential_init(const struct swift_params* parameter_file,
const struct phys_const* phys_const,
const struct UnitSystem* us, const struct space* s,
const struct unit_system* us, const struct space* s,
struct external_potential* potential);
void potential_print(const struct external_potential* potential);
......
......@@ -195,7 +195,7 @@ external_gravity_get_potential_energy(
*/
static INLINE void potential_init_backend(
const struct swift_params* parameter_file,
const struct phys_const* phys_const, const struct UnitSystem* us,
const struct phys_const* phys_const, const struct unit_system* us,
const struct space* s, struct external_potential* potential) {
potential->surface_density = parser_get_param_double(
......
......@@ -163,7 +163,7 @@ external_gravity_get_potential_energy(
*/
static INLINE void potential_init_backend(
const struct swift_params* parameter_file,
const struct phys_const* phys_const, const struct UnitSystem* us,
const struct phys_const* phys_const, const struct unit_system* us,
const struct space* s, struct external_potential* potential) {
potential->x =
......
......@@ -99,7 +99,7 @@ external_gravity_get_potential_energy(
*/
static INLINE void potential_init_backend(
const struct swift_params* parameter_file,
const struct phys_const* phys_const, const struct UnitSystem* us,
const struct phys_const* phys_const, const struct unit_system* us,
const struct space* s, struct external_potential* potential) {}
/**
......
Markdown is supported
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