diff --git a/src/feedback/GEAR/stellar_evolution.c b/src/feedback/GEAR/stellar_evolution.c index 2345fddd356669c35fb19919710609a7e5ff23fe..52f41cf5067fa2b685f3a6b91615ab9eee401c91 100644 --- a/src/feedback/GEAR/stellar_evolution.c +++ b/src/feedback/GEAR/stellar_evolution.c @@ -636,6 +636,21 @@ int stellar_evolution_get_element_index(const struct stellar_model* sm, return -1; } +/** + * @brief Get the solar abundance of the element . + * + * @param sm The #stellar_model. + * @param element_name The element name. + */ +float stellar_evolution_get_solar_abundance(const struct stellar_model* sm, + const char* element_name) { + + int element_index = stellar_evolution_get_element_index(sm, element_name); + float solar_abundance = sm->solar_abundances[element_index]; + + return solar_abundance; +} + /** * @brief Read the name of all the elements present in the tables. * @@ -689,6 +704,46 @@ void stellar_evolution_read_elements(struct stellar_model* sm, } } +/** + * @brief Read the solar abundances. + * + * @param parameter_file The parsed parameter file. + * @param data The properties to initialise. + */ +void stellar_evolution_read_solar_abundances(struct stellar_model* sm, + struct swift_params* params) { + +#if defined(HAVE_HDF5) + + /* Get the yields table */ + char filename[DESCRIPTION_BUFFER_SIZE]; + parser_get_param_string(params, "GEARFeedback:yields_table", filename); + + /* Open file. */ + hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); + if (file_id < 0) error("unable to open file %s.\n", filename); + + /* Open group. */ + hid_t group_id = H5Gopen(file_id, "Data", H5P_DEFAULT); + if (group_id < 0) error("unable to open group Data.\n"); + + /* Read the data */ + io_read_array_attribute(group_id, "SolarMassAbundances", FLOAT, + sm->solar_abundances, GEAR_CHEMISTRY_ELEMENT_COUNT); + + /* Close group */ + hid_t status = H5Gclose(group_id); + if (status < 0) error("error closing group."); + + /* Close file */ + status = H5Fclose(file_id); + if (status < 0) error("error closing file."); + +#else + message("Cannot read the solar abundances without HDF5"); +#endif +} + /** * @brief Initialize the global properties of the stellar evolution scheme. * @@ -707,6 +762,9 @@ void stellar_evolution_props_init(struct stellar_model* sm, /* Read the list of elements */ stellar_evolution_read_elements(sm, params); + /* Read the solar abundances */ + stellar_evolution_read_solar_abundances(sm, params); + /* Use the discrete yields approach? */ sm->discrete_yields = parser_get_param_int(params, "GEARFeedback:discrete_yields"); diff --git a/src/feedback/GEAR/stellar_evolution.h b/src/feedback/GEAR/stellar_evolution.h index b2229b2c42040fd651eccbe28e3c25600d8fa015..a5afdf9079c07f42d673a6ec62b0954b8d3044f8 100644 --- a/src/feedback/GEAR/stellar_evolution.h +++ b/src/feedback/GEAR/stellar_evolution.h @@ -62,9 +62,12 @@ const char* stellar_evolution_get_element_name(const struct stellar_model* sm, int i); int stellar_evolution_get_element_index(const struct stellar_model* sm, const char* element_name); - +float stellar_evolution_get_solar_abundance(const struct stellar_model* sm, + const char* element_name); void stellar_evolution_read_elements(struct stellar_model* sm, struct swift_params* params); +void stellar_evolution_read_solar_abundances(struct stellar_model* sm, + struct swift_params* params); void stellar_evolution_props_init(struct stellar_model* sm, const struct phys_const* phys_const, const struct unit_system* us, @@ -79,5 +82,4 @@ void stellar_evolution_clean(struct stellar_model* sm); float stellar_evolution_compute_initial_mass( const struct spart* restrict sp, const struct stellar_model* sm, const struct phys_const* phys_consts); - #endif // SWIFT_STELLAR_EVOLUTION_GEAR_H diff --git a/src/feedback/GEAR/stellar_evolution_struct.h b/src/feedback/GEAR/stellar_evolution_struct.h index d3de0f1aa215c181bcd3f93ce3f7247f82d70c6e..7103c277d3f85cd528675a6e079a405e0ae14516 100644 --- a/src/feedback/GEAR/stellar_evolution_struct.h +++ b/src/feedback/GEAR/stellar_evolution_struct.h @@ -191,6 +191,9 @@ struct stellar_model { /*! Name of the different elements */ char elements_name[GEAR_CHEMISTRY_ELEMENT_COUNT * GEAR_LABELS_SIZE]; + /* Solar mass abundances read from the chemistry table */ + float solar_abundances[GEAR_CHEMISTRY_ELEMENT_COUNT]; + /*! The initial mass function */ struct initial_mass_function imf;