Skip to content
Snippets Groups Projects
Commit fad10f5c authored by Yves Revaz's avatar Yves Revaz Committed by Matthieu Schaller
Browse files

Gear feedback updates

parent 793d05e2
Branches
Tags
1 merge request!2128Gear feedback updates
......@@ -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");
......
......@@ -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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment