From 80ec719d01bea8c2ffad38663ce25231f21ec63c Mon Sep 17 00:00:00 2001 From: lhausamm <loic_hausammann@hotmail.com> Date: Wed, 18 Apr 2018 14:09:52 +0200 Subject: [PATCH] Rebasing corrections --- examples/main.c | 2 +- src/chemistry.c | 8 +++---- src/chemistry.h | 4 ++-- src/chemistry/gear/chemistry.h | 29 +++++------------------- src/chemistry/gear/chemistry_io.h | 27 ++++++++++++++++++++-- src/cooling/grackle/cooling.h | 37 +++++++++++++++++++++---------- src/engine.c | 4 ++-- src/runner.c | 2 +- src/space.c | 6 +++-- 9 files changed, 69 insertions(+), 50 deletions(-) diff --git a/examples/main.c b/examples/main.c index ca91c9e718..3917756098 100644 --- a/examples/main.c +++ b/examples/main.c @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) { /* Structs used by the engine. Declare now to make sure these are always in * scope. */ - struct chemistry_data chemistry; + struct chemistry_global_data chemistry; struct cooling_function_data cooling_func; struct cosmology cosmo; struct external_potential potential; diff --git a/src/chemistry.c b/src/chemistry.c index fb327a5ede..d9e36448bb 100644 --- a/src/chemistry.c +++ b/src/chemistry.c @@ -58,9 +58,9 @@ void chemistry_print(const struct chemistry_global_data* data) { * @param chemistry the struct * @param stream the file stream */ -void chemistry_struct_dump(const struct chemistry_data* chemistry, +void chemistry_struct_dump(const struct chemistry_global_data* chemistry, FILE* stream) { - restart_write_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, + restart_write_blocks((void*)chemistry, sizeof(struct chemistry_global_data), 1, stream, "chemistry", "chemistry function"); } @@ -71,8 +71,8 @@ void chemistry_struct_dump(const struct chemistry_data* chemistry, * @param chemistry the struct * @param stream the file stream */ -void chemistry_struct_restore(const struct chemistry_data* chemistry, +void chemistry_struct_restore(const struct chemistry_global_data* chemistry, FILE* stream) { - restart_read_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, + restart_read_blocks((void*)chemistry, sizeof(struct chemistry_global_data), 1, stream, NULL, "chemistry function"); } diff --git a/src/chemistry.h b/src/chemistry.h index d54c0c4801..77b8d5b5fa 100644 --- a/src/chemistry.h +++ b/src/chemistry.h @@ -51,9 +51,9 @@ void chemistry_init(const struct swift_params* parameter_file, void chemistry_print(const struct chemistry_global_data* data); /* Dump/restore. */ -void chemistry_struct_dump(const struct chemistry_data* chemistry, +void chemistry_struct_dump(const struct chemistry_global_data* chemistry, FILE* stream); -void chemistry_struct_restore(const struct chemistry_data* chemistry, +void chemistry_struct_restore(const struct chemistry_global_data* chemistry, FILE* stream); #endif /* SWIFT_CHEMISTRY_H */ diff --git a/src/chemistry/gear/chemistry.h b/src/chemistry/gear/chemistry.h index a73125e0a1..ba5e9ace83 100644 --- a/src/chemistry/gear/chemistry.h +++ b/src/chemistry/gear/chemistry.h @@ -38,18 +38,6 @@ #include "physical_constants.h" #include "units.h" -/** - * @brief Return a string containing the name of a given #chemistry_element. - */ -__attribute__((always_inline)) INLINE static const char* -chemistry_get_element_name(enum chemistry_element elem) { - - static const char* chemistry_element_names[chemistry_element_count] = { - "Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc", - "Strontium", "Yttrium", "Barium", "Europium"}; - - return chemistry_element_names[elem]; -} /** * @brief Compute the metal mass fraction @@ -81,16 +69,6 @@ static INLINE void chemistry_init_backend( chemistry_read_parameters(parameter_file, us, phys_const, data); } -/** - * @brief Prints the properties of the chemistry model to stdout. - * - * @brief The #chemistry_global_data containing information about the current model. - */ -static INLINE void chemistry_print_backend(const struct chemistry_global_data* data) { - - message("Chemistry function is 'Gear'."); -} - /** * @brief Prepares a particle for the smooth metal calculation. * @@ -155,8 +133,11 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( * @param data The global chemistry information. */ __attribute__((always_inline)) INLINE static void chemistry_first_init_part( - struct part* restrict p, struct xpart* restrict xp, - const struct chemistry_global_data* data) { + const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + const struct chemistry_global_data* data, + struct part* restrict p, struct xpart* restrict xp) { p->chemistry_data.Z = data->initial_metallicity; chemistry_init_part(p, data); diff --git a/src/chemistry/gear/chemistry_io.h b/src/chemistry/gear/chemistry_io.h index 33a099cb6f..8a084db25b 100644 --- a/src/chemistry/gear/chemistry_io.h +++ b/src/chemistry/gear/chemistry_io.h @@ -19,14 +19,37 @@ #ifndef SWIFT_CHEMISTRY_IO_GEAR_H #define SWIFT_CHEMISTRY_IO_GEAR_H -#include "chemistry.h" #include "chemistry_struct.h" +#include "error.h" #include "io_properties.h" #include "parser.h" #include "part.h" #include "physical_constants.h" #include "units.h" +/** + * @brief Return a string containing the name of a given #chemistry_element. + */ +__attribute__((always_inline)) INLINE static const char* +chemistry_get_element_name(enum chemistry_element elem) { + + static const char* chemistry_element_names[chemistry_element_count] = { + "Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc", + "Strontium", "Yttrium", "Barium", "Europium"}; + + return chemistry_element_names[elem]; +} + +/** + * @brief Prints the properties of the chemistry model to stdout. + * + * @brief The #chemistry_global_data containing information about the current model. + */ +static INLINE void chemistry_print_backend(const struct chemistry_global_data* data) { + + message("Chemistry function is 'Gear'."); +} + /** * @brief Specifies which particle fields to read from a dataset * @@ -91,7 +114,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( * @param h_grp The HDF5 group in which to write */ __attribute__((always_inline)) INLINE static void chemistry_write_flavour( - hid_t h_grpsph) { + hid_t h_grp) { io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); for (enum chemistry_element i = chemistry_element_O; diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index 9760499bee..d1e7c30c9c 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -47,12 +47,16 @@ /* prototypes */ static gr_float cooling_time( + const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, const struct cooling_function_data* restrict cooling, const struct part* restrict p, struct xpart* restrict xp); static double cooling_rate( const struct phys_const* restrict phys_const, const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, const struct cooling_function_data* restrict cooling, const struct part* restrict p, struct xpart* restrict xp, double dt); @@ -144,9 +148,12 @@ __attribute__((always_inline)) INLINE static int cooling_converged( * @param cooling The properties of the cooling function. */ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( + const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + const struct cooling_function_data* restrict cooling, const struct part* restrict p, - struct xpart* restrict xp, - const struct cooling_function_data* cooling) { + struct xpart* restrict xp) { /* get temporary data */ struct part p_tmp = *p; @@ -157,9 +164,9 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( /* compute time step */ const double alpha = 0.01; - double dt = fabs(cooling_time(&cooling_tmp, &p_tmp, xp)); - cooling_rate(NULL, NULL, &cooling_tmp, &p_tmp, xp, dt); - dt = alpha * fabs(cooling_time(&cooling_tmp, &p_tmp, xp)); + double dt = fabs(cooling_time(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp)); + cooling_rate(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp, dt); + dt = alpha * fabs(cooling_time(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp)); /* init simple variables */ int step = 0; @@ -173,7 +180,7 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( old = *xp; /* update chemistry */ - cooling_rate(NULL, NULL, &cooling_tmp, &p_tmp, xp, dt); + cooling_rate(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp, dt); } while (step < max_step && !cooling_converged(xp, &old, conv_limit)); if (step == max_step) @@ -191,8 +198,11 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( * @param cooling The properties of the cooling function. */ __attribute__((always_inline)) INLINE static void cooling_first_init_part( - const struct part* restrict p, struct xpart* restrict xp, - const struct cooling_function_data* cooling) { + const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + const struct cooling_function_data* cooling, + const struct part* restrict p, struct xpart* restrict xp) { xp->cooling_data.radiated_energy = 0.f; @@ -226,7 +236,7 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part( #endif // MODE >= 3 #if COOLING_GRACKLE_MODE > 0 - cooling_compute_equilibrium(p, xp, cooling); + cooling_compute_equilibrium(phys_const, us, cosmo, p, xp, cooling); #endif } @@ -567,6 +577,9 @@ __attribute__((always_inline)) INLINE static gr_float cooling_rate( * @return cooling time */ __attribute__((always_inline)) INLINE static gr_float cooling_time( + const struct phys_const* restrict phys_const, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, const struct cooling_function_data* restrict cooling, const struct part* restrict p, struct xpart* restrict xp) { @@ -592,8 +605,8 @@ __attribute__((always_inline)) INLINE static gr_float cooling_time( data.grid_end = grid_end; /* general particle data */ - const gr_float energy_before = hydro_get_internal_energy(p); - gr_float density = hydro_get_density(p); + const gr_float energy_before = hydro_get_physical_internal_energy(p, cosmo); + gr_float density = hydro_get_physical_density(p, cosmo); gr_float energy = energy_before; /* initialize density */ @@ -646,7 +659,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( const float hydro_du_dt = hydro_get_internal_energy_dt(p); /* compute cooling rate */ - const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p, dt); + const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p, xp, dt); /* record energy lost */ xp->cooling_data.radiated_energy += -du_dt * dt * hydro_get_mass(p); diff --git a/src/engine.c b/src/engine.c index b5c9c848db..d74a44b5cf 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5965,8 +5965,8 @@ void engine_struct_restore(struct engine *e, FILE *stream) { cooling_struct_restore(cooling_func, stream); e->cooling_func = cooling_func; - struct chemistry_data *chemistry = - (struct chemistry_data *)malloc(sizeof(struct chemistry_data)); + struct chemistry_global_data *chemistry = + (struct chemistry_global_data *)malloc(sizeof(struct chemistry_global_data)); chemistry_struct_restore(chemistry, stream); e->chemistry = chemistry; diff --git a/src/runner.c b/src/runner.c index 35996a3ba9..51801a7794 100644 --- a/src/runner.c +++ b/src/runner.c @@ -656,7 +656,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { const struct space *s = e->s; const struct hydro_space *hs = &s->hs; const struct cosmology *cosmo = e->cosmology; - const struct chemistry_data *chemistry = e->chemistry; + const struct chemistry_global_data *chemistry = e->chemistry; const float hydro_h_max = e->hydro_properties->h_max; const float eps = e->hydro_properties->h_tolerance; const float hydro_eta_dim = diff --git a/src/space.c b/src/space.c index 05a0719224..b1d25fb85f 100644 --- a/src/space.c +++ b/src/space.c @@ -2648,6 +2648,8 @@ void space_first_init_parts(struct space *s, struct xpart *restrict xp = s->xparts; const struct cosmology *cosmo = s->e->cosmology; + const struct phys_const *phys_const = s->e->physical_constants; + const struct unit_system *us = s->e->internal_units; const float a_factor_vel = cosmo->a * cosmo->a; const struct hydro_props *hydro_props = s->e->hydro_properties; @@ -2678,10 +2680,10 @@ void space_first_init_parts(struct space *s, if (u_min > 0.f) hydro_set_init_internal_energy(&p[i], u_min); /* Also initialise the chemistry */ - chemistry_first_init_part(&p[i], &xp[i], chemistry); + chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[i], &xp[i]); /* And the cooling */ - cooling_first_init_part(&p[i], &xp[i], cool_func); + cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[i], &xp[i]); #ifdef SWIFT_DEBUG_CHECKS p[i].ti_drift = 0; -- GitLab