diff --git a/src/chemistry/gear/chemistry.h b/src/chemistry/gear/chemistry.h index e9d3d00febe2438c52728f94d0136fb72ff8dc3b..8ccb29fa5edb136809f5773db7062107ac48b1bc 100644 --- a/src/chemistry/gear/chemistry.h +++ b/src/chemistry/gear/chemistry.h @@ -29,6 +29,7 @@ #include <math.h> /* Local includes. */ +#include "chemistry_io.h" #include "chemistry_struct.h" #include "error.h" #include "hydro.h" @@ -62,14 +63,18 @@ chemistry_get_element_name(enum chemistry_element elem) { */ static INLINE void chemistry_init_backend( const struct swift_params* parameter_file, const struct unit_system* us, - const struct phys_const* phys_const, struct chemistry_data* data) {} + const struct phys_const* phys_const, struct chemistry_global_data* data) { + + /* read parameters */ + chemistry_read_parameters(parameter_file, us, phys_const, data); +} /** * @brief Prints the properties of the chemistry model to stdout. * - * @brief The #chemistry_data containing information about the current model. + * @brief The #chemistry_global_data containing information about the current model. */ -static INLINE void chemistry_print_backend(const struct chemistry_data* data) { +static INLINE void chemistry_print_backend(const struct chemistry_global_data* data) { message("Chemistry function is 'Gear'."); } @@ -81,10 +86,10 @@ static INLINE void chemistry_print_backend(const struct chemistry_data* data) { * the various smooth metallicity tasks * * @param p The particle to act upon - * @param cd #chemistry_data containing chemistry informations. + * @param cd #chemistry_global_data containing chemistry informations. */ __attribute__((always_inline)) INLINE static void chemistry_init_part( - struct part* restrict p, const struct chemistry_data* cd) { + struct part* restrict p, const struct chemistry_global_data* cd) { struct chemistry_part_data* cpd = &p->chemistry_data; @@ -102,11 +107,11 @@ __attribute__((always_inline)) INLINE static void chemistry_init_part( * This function requires the #hydro_end_density to have been called. * * @param p The particle to act upon. - * @param cd #chemistry_data containing chemistry informations. + * @param cd #chemistry_global_data containing chemistry informations. * @param cosmo The current cosmological model. */ __attribute__((always_inline)) INLINE static void chemistry_end_density( - struct part* restrict p, const struct chemistry_data* cd, + struct part* restrict p, const struct chemistry_global_data* cd, const struct cosmology* cosmo) { /* Some smoothing length multiples. */ @@ -139,7 +144,7 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( */ __attribute__((always_inline)) INLINE static void chemistry_first_init_part( struct part* restrict p, struct xpart* restrict xp, - const struct chemistry_data* data) { + const struct chemistry_global_data* data) { chemistry_init_part(p, data); } diff --git a/src/chemistry/gear/chemistry_io.h b/src/chemistry/gear/chemistry_io.h index 9b0852fa2d23c8dd3e4d36406b55f4353d23b807..33a099cb6f6d0fa2d19ded6e48bc1ace2b171f9a 100644 --- a/src/chemistry/gear/chemistry_io.h +++ b/src/chemistry/gear/chemistry_io.h @@ -22,6 +22,10 @@ #include "chemistry.h" #include "chemistry_struct.h" #include "io_properties.h" +#include "parser.h" +#include "part.h" +#include "physical_constants.h" +#include "units.h" /** * @brief Specifies which particle fields to read from a dataset @@ -31,15 +35,30 @@ * * @return Returns the number of fields to read. */ -int chemistry_read_particles(struct part* parts, struct io_props* list) { +__attribute__((always_inline)) INLINE static int chemistry_read_particles( + struct part* parts, struct io_props* list) { /* List what we want to read */ list[0] = io_make_input_field( "ElementAbundance", FLOAT, chemistry_element_count, OPTIONAL, UNIT_CONV_NO_UNITS, parts, chemistry_data.metal_mass_fraction); - return 1; + list[1] = + io_make_input_field("Z", FLOAT, 1, OPTIONAL, UNIT_CONV_NO_UNITS, + parts, chemistry_data.Z); + + return 2; +} + +__attribute__((always_inline)) INLINE static void chemistry_read_parameters( + const struct swift_params* parameter_file, const struct unit_system* us, + const struct phys_const* phys_const, struct chemistry_global_data* data) { + + data->initial_metallicity = + parser_get_opt_param_float(parameter_file, "GearChemistry:InitialMetallicity", + -1); } + /** * @brief Specifies which particle fields to write to a dataset * @@ -48,18 +67,21 @@ int chemistry_read_particles(struct part* parts, struct io_props* list) { * * @return Returns the number of fields to write. */ -int chemistry_write_particles(const struct part* parts, struct io_props* list) { +__attribute__((always_inline)) INLINE static int chemistry_write_particles( + const struct part* parts, struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field( "SmoothedElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, parts, chemistry_data.smoothed_metal_mass_fraction); + list[1] = io_make_output_field("Z", FLOAT, 1, UNIT_CONV_NO_UNITS, + parts, chemistry_data.Z); - list[1] = io_make_output_field("ElementAbundance", FLOAT, + list[2] = io_make_output_field("ElementAbundance", FLOAT, chemistry_element_count, UNIT_CONV_NO_UNITS, parts, chemistry_data.metal_mass_fraction); - return 2; + return 3; } #ifdef HAVE_HDF5 @@ -68,7 +90,8 @@ int chemistry_write_particles(const struct part* parts, struct io_props* list) { * @brief Writes the current model of SPH to the file * @param h_grp The HDF5 group in which to write */ -void chemistry_write_flavour(hid_t h_grp) { +__attribute__((always_inline)) INLINE static void chemistry_write_flavour( + hid_t h_grpsph) { io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); for (enum chemistry_element i = chemistry_element_O; @@ -80,4 +103,5 @@ void chemistry_write_flavour(hid_t h_grp) { } #endif + #endif /* SWIFT_CHEMISTRY_IO_GEAR_H */ diff --git a/src/chemistry/gear/chemistry_struct.h b/src/chemistry/gear/chemistry_struct.h index b0ddee2b37c2d1126523ff7a4283f5c18ae3a7b4..c3443126cf0ac72c76774d9000fe218378cc6663 100644 --- a/src/chemistry/gear/chemistry_struct.h +++ b/src/chemistry/gear/chemistry_struct.h @@ -38,7 +38,11 @@ enum chemistry_element { /** * @brief Global chemical abundance information. */ -struct chemistry_data {}; +struct chemistry_global_data { + + /* Initial metallicity Z */ + float initial_metallicity; +}; /** * @brief Properties of the chemistry function. @@ -50,6 +54,8 @@ struct chemistry_part_data { /*! Smoothed fraction of the particle mass in a given element */ float smoothed_metal_mass_fraction[chemistry_element_count]; + + float Z; }; #endif /* SWIFT_CHEMISTRY_STRUCT_GEAR_H */ diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index 0493b0a2b4443afb263d5040483dd6a1fcca7c7d..8a337c60e3fa22abdae04543741ac6879ee037b9 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -810,7 +810,7 @@ __attribute__((always_inline)) INLINE static void cooling_init_backend( error("Grackle with multiple particles not implemented"); /* read parameters */ - cooling_parse_arguments(parameter_file, cooling); + cooling_read_parameters(parameter_file, cooling); /* Set up the units system. */ cooling_init_units(us, cooling); diff --git a/src/cooling/grackle/cooling_io.h b/src/cooling/grackle/cooling_io.h index 666e67ae9183d0e8edd2916b3dcc1b483c9ce9d5..3bdf0cfd798a034e0e9558f8a96fac458a49ea17 100644 --- a/src/cooling/grackle/cooling_io.h +++ b/src/cooling/grackle/cooling_io.h @@ -119,10 +119,11 @@ __attribute__((always_inline)) INLINE static int cooling_write_particles( /** * @brief Parser the parameter file and initialize the #cooling_function_data + * * @param parameter_file The parser parameter file * @param cooling The cooling properties to initialize */ -__attribute__((always_inline)) INLINE static void cooling_parse_arguments( +__attribute__((always_inline)) INLINE static void cooling_read_parameters( const struct swift_params* parameter_file, struct cooling_function_data* cooling) { @@ -146,7 +147,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments( cooling->self_shielding_method = parser_get_opt_param_int(parameter_file, "GrackleCooling:SelfShieldingMethod", 0); -#if COOLING_GRACKLE_MODE > 0 cooling->output_mode = parser_get_opt_param_int(parameter_file, "GrackleCooling:OutputMode", 0); @@ -158,7 +158,6 @@ __attribute__((always_inline)) INLINE static void cooling_parse_arguments( cooling->omega = parser_get_opt_param_double(parameter_file, "GrackleCooling:Omega", 0.8); -#endif }