Commit 9f239167 authored by Loic Hausammann's avatar Loic Hausammann Committed by Matthieu Schaller

First stars

parent b8dcf120
#!/bin/bash #!/bin/bash
wget https://obswww.unige.ch/lastro/projects/Clastro/PySWIFTsim/chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5 wget https://obswww.unige.ch/lastro/projects/Clastro/PySWIFTsim/chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5
wget https://obswww.unige.ch/lastro/projects/Clastro/PySWIFTsim/chemistry-PopIII.hdf5
...@@ -527,9 +527,12 @@ EAGLEFeedback: ...@@ -527,9 +527,12 @@ EAGLEFeedback:
# GEAR feedback model # GEAR feedback model
GEARFeedback: GEARFeedback:
supernovae_energy_erg: 0.135e51 # Energy released by a single supernovae. supernovae_energy_erg: 0.1e51 # Energy released by a single supernovae.
yields_table: chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5 # Table containing the yields. yields_table: chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5 # Table containing the yields.
yields_table: chemistry-PopIII.hdf5 # Table containing the yields of the first stars.
metallicity_max_first_stars: -1 # Maximal metallicity (in mass fraction) for a first star (-1 to deactivate).
discrete_yields: 0 # Should we use discrete yields or the IMF integrated one? discrete_yields: 0 # Should we use discrete yields or the IMF integrated one?
elements: [Fe, Mg, O, S, Zn, Sr, Y, Ba, Eu] # Elements to read in the yields table. The number of element should be one less than the number of elements (N) requested during the configuration (--with-chemistry=GEAR_N).
# Parameters related to AGN models ----------------------------------------------- # Parameters related to AGN models -----------------------------------------------
......
...@@ -242,10 +242,17 @@ void feedback_evolve_spart(struct spart* restrict sp, ...@@ -242,10 +242,17 @@ void feedback_evolve_spart(struct spart* restrict sp,
sp->feedback_data.enrichment_weight *= hi_inv_dim; sp->feedback_data.enrichment_weight *= hi_inv_dim;
/* Pick the correct table. (if only one table, threshold is < 0) */
const float metal = chemistry_get_total_metal_mass_fraction_for_feedback(sp);
const float threshold = feedback_props->metallicity_max_first_stars;
const struct stellar_model* model =
metal < threshold ? &feedback_props->stellar_model_first_stars
: &feedback_props->stellar_model;
/* Compute the stellar evolution */ /* Compute the stellar evolution */
stellar_evolution_evolve_spart(sp, &feedback_props->stellar_model, cosmo, us, stellar_evolution_evolve_spart(sp, model, cosmo, us, phys_const, ti_begin,
phys_const, ti_begin, star_age_beg_step_safe, star_age_beg_step_safe, dt);
dt);
/* Transform the number of SN to the energy */ /* Transform the number of SN to the energy */
sp->feedback_data.energy_ejected = sp->feedback_data.energy_ejected =
...@@ -264,6 +271,9 @@ void feedback_struct_dump(const struct feedback_props* feedback, FILE* stream) { ...@@ -264,6 +271,9 @@ void feedback_struct_dump(const struct feedback_props* feedback, FILE* stream) {
stream, "feedback", "feedback function"); stream, "feedback", "feedback function");
stellar_evolution_dump(&feedback->stellar_model, stream); stellar_evolution_dump(&feedback->stellar_model, stream);
if (feedback->metallicity_max_first_stars != -1) {
stellar_evolution_dump(&feedback->stellar_model_first_stars, stream);
}
} }
/** /**
...@@ -279,6 +289,10 @@ void feedback_struct_restore(struct feedback_props* feedback, FILE* stream) { ...@@ -279,6 +289,10 @@ void feedback_struct_restore(struct feedback_props* feedback, FILE* stream) {
NULL, "feedback function"); NULL, "feedback function");
stellar_evolution_restore(&feedback->stellar_model, stream); stellar_evolution_restore(&feedback->stellar_model, stream);
if (feedback->metallicity_max_first_stars != -1) {
stellar_evolution_restore(&feedback->stellar_model_first_stars, stream);
}
} }
/** /**
...@@ -289,4 +303,7 @@ void feedback_struct_restore(struct feedback_props* feedback, FILE* stream) { ...@@ -289,4 +303,7 @@ void feedback_struct_restore(struct feedback_props* feedback, FILE* stream) {
void feedback_clean(struct feedback_props* feedback) { void feedback_clean(struct feedback_props* feedback) {
stellar_evolution_clean(&feedback->stellar_model); stellar_evolution_clean(&feedback->stellar_model);
if (feedback->metallicity_max_first_stars != -1) {
stellar_evolution_clean(&feedback->stellar_model_first_stars);
}
} }
...@@ -31,11 +31,14 @@ struct feedback_props { ...@@ -31,11 +31,14 @@ struct feedback_props {
/*! Energy per supernovae */ /*! Energy per supernovae */
float energy_per_supernovae; float energy_per_supernovae;
/*! filename of the chemistry table */
char filename[PARSER_MAX_LINE_SIZE];
/*! The stellar model */ /*! The stellar model */
struct stellar_model stellar_model; struct stellar_model stellar_model;
/*! The stellar model for first stars */
struct stellar_model stellar_model_first_stars;
/* Metallicity limits for the first stars */
float metallicity_max_first_stars;
}; };
/** /**
...@@ -51,13 +54,36 @@ __attribute__((always_inline)) INLINE static void feedback_props_print( ...@@ -51,13 +54,36 @@ __attribute__((always_inline)) INLINE static void feedback_props_print(
return; return;
} }
/* Print the name of the elements */
char txt[GEAR_CHEMISTRY_ELEMENT_COUNT * (GEAR_LABELS_SIZE + 2)] = "";
for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
if (i != 0) {
strcat(txt, ", ");
}
strcat(txt, stellar_evolution_get_element_name(
&feedback_props->stellar_model, i));
}
if (engine_rank == 0) {
message("Chemistry elements: %s", txt);
}
/* Print the feedback properties */ /* Print the feedback properties */
message("Energy per supernovae = %.2g", message("Energy per supernovae = %.2g",
feedback_props->energy_per_supernovae); feedback_props->energy_per_supernovae);
message("Yields table = %s", feedback_props->filename); message("Yields table = %s", feedback_props->stellar_model.yields_table);
/* Print the stellar model */ /* Print the stellar model */
stellar_model_print(&feedback_props->stellar_model); stellar_model_print(&feedback_props->stellar_model);
/* Print the first stars */
if (feedback_props->metallicity_max_first_stars != -1) {
message("Yields table first stars = %s",
feedback_props->stellar_model_first_stars.yields_table);
stellar_model_print(&feedback_props->stellar_model_first_stars);
message("Metallicity max for the first stars (in mass fraction) = %g",
feedback_props->metallicity_max_first_stars);
}
} }
/** /**
...@@ -81,13 +107,33 @@ __attribute__((always_inline)) INLINE static void feedback_props_init( ...@@ -81,13 +107,33 @@ __attribute__((always_inline)) INLINE static void feedback_props_init(
e_feedback /= units_cgs_conversion_factor(us, UNIT_CONV_ENERGY); e_feedback /= units_cgs_conversion_factor(us, UNIT_CONV_ENERGY);
fp->energy_per_supernovae = e_feedback; fp->energy_per_supernovae = e_feedback;
/* filename of the chemistry table */ /* filename of the chemistry tables. */
parser_get_param_string(params, "GEARFeedback:yields_table", fp->filename); parser_get_param_string(params, "GEARFeedback:yields_table",
fp->stellar_model.yields_table);
/* Initialize the stellar model */ /* Initialize the stellar models. */
stellar_evolution_props_init(&fp->stellar_model, phys_const, us, params, stellar_evolution_props_init(&fp->stellar_model, phys_const, us, params,
cosmo); cosmo);
/* Now the same for first stars. */
fp->metallicity_max_first_stars = parser_get_opt_param_float(
params, "GEARFeedback:metallicity_max_first_stars", -1);
if (fp->metallicity_max_first_stars == -1) {
message("First stars are disabled.");
} else {
if (fp->metallicity_max_first_stars < 0) {
error(
"The metallicity threshold for the first stars is in mass fraction. "
"It cannot be lower than 0.");
}
message("Reading the stellar model for the first stars");
parser_get_param_string(params, "GEARFeedback:yields_table_first_stars",
fp->stellar_model_first_stars.yields_table);
stellar_evolution_props_init(&fp->stellar_model_first_stars, phys_const, us,
params, cosmo);
}
/* Print the stellar properties */ /* Print the stellar properties */
feedback_props_print(fp); feedback_props_print(fp);
......
...@@ -333,15 +333,15 @@ void initial_mass_function_compute_coefficients( ...@@ -333,15 +333,15 @@ void initial_mass_function_compute_coefficients(
* *
* @param imf The #initial_mass_function. * @param imf The #initial_mass_function.
* @param params The #swift_params. * @param params The #swift_params.
* @param filename The filename of the chemistry table.
*/ */
void initial_mass_function_read_from_table(struct initial_mass_function *imf, void initial_mass_function_read_from_table(struct initial_mass_function *imf,
struct swift_params *params) { struct swift_params *params,
const char *filename) {
hid_t file_id, group_id; hid_t file_id, group_id;
/* Open IMF group */ /* Open IMF group */
char filename[FILENAME_BUFFER_SIZE];
parser_get_param_string(params, "GEARFeedback:yields_table", filename);
h5_open_group(filename, "Data/IMF", &file_id, &group_id); h5_open_group(filename, "Data/IMF", &file_id, &group_id);
/* Read number of parts */ /* Read number of parts */
...@@ -381,58 +381,6 @@ void initial_mass_function_read_from_table(struct initial_mass_function *imf, ...@@ -381,58 +381,6 @@ void initial_mass_function_read_from_table(struct initial_mass_function *imf,
h5_close_group(file_id, group_id); h5_close_group(file_id, group_id);
} }
/**
* @brief Reads the parameters file and if required overwrites the parameters
* found in the yields table.
*
* @param imf The #initial_mass_function.
* @param params The #swift_params.
*/
void initial_mass_function_read_from_params(struct initial_mass_function *imf,
struct swift_params *params) {
/* Read the number of elements */
const int n_parts = parser_get_opt_param_int(
params, "GEARInitialMassFunction:number_function_part", imf->n_parts);
const int n_parts_changed = n_parts != imf->n_parts;
imf->n_parts = n_parts;
/* Reallocate the exponent memory */
if (n_parts_changed) {
free(imf->exp);
if ((imf->exp = (float *)malloc(sizeof(float) * imf->n_parts)) == NULL)
error("Failed to allocate the IMF exponents.");
}
/* Read the exponents */
const char *exponent_name = "GEARInitialMassFunction:exponents";
if (n_parts_changed) {
parser_get_param_float_array(params, exponent_name, imf->n_parts, imf->exp);
} else {
parser_get_opt_param_float_array(params, exponent_name, imf->n_parts,
imf->exp);
}
/* Reallocate the mass limits memory */
if (n_parts_changed) {
free(imf->mass_limits);
if ((imf->mass_limits =
(float *)malloc(sizeof(float) * (imf->n_parts + 1))) == NULL)
error("Failed to allocate the IMF masses.");
}
/* Read the mass limits */
const char *mass_limits_name = "GEARInitialMassFunction:mass_limits_msun";
if (n_parts_changed) {
parser_get_param_float_array(params, mass_limits_name, imf->n_parts + 1,
imf->mass_limits);
} else {
parser_get_opt_param_float_array(params, mass_limits_name, imf->n_parts + 1,
imf->mass_limits);
}
}
/** /**
* @brief Initialize the initial mass function. * @brief Initialize the initial mass function.
* *
...@@ -440,17 +388,16 @@ void initial_mass_function_read_from_params(struct initial_mass_function *imf, ...@@ -440,17 +388,16 @@ void initial_mass_function_read_from_params(struct initial_mass_function *imf,
* @param phys_const The #phys_const. * @param phys_const The #phys_const.
* @param us The #unit_system. * @param us The #unit_system.
* @param params The #swift_params. * @param params The #swift_params.
* @param filename The filename of the chemistry table.
*/ */
void initial_mass_function_init(struct initial_mass_function *imf, void initial_mass_function_init(struct initial_mass_function *imf,
const struct phys_const *phys_const, const struct phys_const *phys_const,
const struct unit_system *us, const struct unit_system *us,
struct swift_params *params) { struct swift_params *params,
const char *filename) {
/* Read the parameters from the yields table */ /* Read the parameters from the yields table */
initial_mass_function_read_from_table(imf, params); initial_mass_function_read_from_table(imf, params, filename);
/* Overwrites the parameters if found in the params file */
initial_mass_function_read_from_params(imf, params);
/* Write the masses in the correct attributes */ /* Write the masses in the correct attributes */
imf->mass_min = imf->mass_limits[0]; imf->mass_min = imf->mass_limits[0];
......
...@@ -41,14 +41,14 @@ void initial_mass_function_compute_coefficients( ...@@ -41,14 +41,14 @@ void initial_mass_function_compute_coefficients(
struct initial_mass_function *imf); struct initial_mass_function *imf);
void initial_mass_function_read_from_table(struct initial_mass_function *imf, void initial_mass_function_read_from_table(struct initial_mass_function *imf,
struct swift_params *params); struct swift_params *params,
void initial_mass_function_read_from_params(struct initial_mass_function *imf, const char *filename);
struct swift_params *params);
void initial_mass_function_init(struct initial_mass_function *imf, void initial_mass_function_init(struct initial_mass_function *imf,
const struct phys_const *phys_const, const struct phys_const *phys_const,
const struct unit_system *us, const struct unit_system *us,
struct swift_params *params); struct swift_params *params,
const char *filename);
void initial_mass_function_dump(const struct initial_mass_function *imf, void initial_mass_function_dump(const struct initial_mass_function *imf,
FILE *stream, const struct stellar_model *sm); FILE *stream, const struct stellar_model *sm);
......
...@@ -124,15 +124,14 @@ lifetime_get_log_mass_from_lifetime(const struct lifetime* life, float log_time, ...@@ -124,15 +124,14 @@ lifetime_get_log_mass_from_lifetime(const struct lifetime* life, float log_time,
* *
* @param lt The #lifetime. * @param lt The #lifetime.
* @param params The #swift_params. * @param params The #swift_params.
* @param filename The filename of the chemistry table.
*/ */
__attribute__((always_inline)) INLINE static void lifetime_read_from_tables( __attribute__((always_inline)) INLINE static void lifetime_read_from_tables(
struct lifetime* lt, struct swift_params* params) { struct lifetime* lt, struct swift_params* params, const char* filename) {
hid_t file_id, group_id; hid_t file_id, group_id;
/* Open IMF group */ /* Open IMF group */
char filename[256];
parser_get_param_string(params, "GEARFeedback:yields_table", filename);
h5_open_group(filename, "Data/LifeTimes", &file_id, &group_id); h5_open_group(filename, "Data/LifeTimes", &file_id, &group_id);
/* Allocate the temporary array */ /* Allocate the temporary array */
...@@ -156,28 +155,6 @@ __attribute__((always_inline)) INLINE static void lifetime_read_from_tables( ...@@ -156,28 +155,6 @@ __attribute__((always_inline)) INLINE static void lifetime_read_from_tables(
h5_close_group(file_id, group_id); h5_close_group(file_id, group_id);
} }
/**
* @brief Read lifetime parameters from params.
*
* @param lt The #lifetime.
* @param params The #swift_params.
*/
__attribute__((always_inline)) INLINE static void lifetime_read_from_params(
struct lifetime* lt, struct swift_params* params) {
/* Read quadratic terms */
parser_get_opt_param_float_array(params, "GEARLifetime:quadratic", 3,
lt->quadratic);
/* Read linear terms */
parser_get_opt_param_float_array(params, "GEARLifetime:linear", 3,
lt->linear);
/* Read constant terms */
parser_get_opt_param_float_array(params, "GEARLifetime:constant", 3,
lt->constant);
}
/** /**
* @brief Inititialize the Lifetime. * @brief Inititialize the Lifetime.
* *
...@@ -185,16 +162,15 @@ __attribute__((always_inline)) INLINE static void lifetime_read_from_params( ...@@ -185,16 +162,15 @@ __attribute__((always_inline)) INLINE static void lifetime_read_from_params(
* @param phys_const The #phys_const. * @param phys_const The #phys_const.
* @param us The #unit_system. * @param us The #unit_system.
* @param params The #swift_params. * @param params The #swift_params.
* @param filename The filename of the chemistry table.
*/ */
__attribute__((always_inline)) INLINE static void lifetime_init( __attribute__((always_inline)) INLINE static void lifetime_init(
struct lifetime* lt, const struct phys_const* phys_const, struct lifetime* lt, const struct phys_const* phys_const,
const struct unit_system* us, struct swift_params* params) { const struct unit_system* us, struct swift_params* params,
const char* filename) {
/* Read params from yields table */ /* Read params from yields table */
lifetime_read_from_tables(lt, params); lifetime_read_from_tables(lt, params, filename);
/* overwrite the parameters if found in the params */
lifetime_read_from_params(lt, params);
/* Change units from yr into Myr */ /* Change units from yr into Myr */
const int dim = 3; const int dim = 3;
......
...@@ -382,42 +382,37 @@ const char* stellar_evolution_get_element_name(const struct stellar_model* sm, ...@@ -382,42 +382,37 @@ const char* stellar_evolution_get_element_name(const struct stellar_model* sm,
void stellar_evolution_read_elements(struct stellar_model* sm, void stellar_evolution_read_elements(struct stellar_model* sm,
struct swift_params* params) { struct swift_params* params) {
hid_t file_id, group_id; /* Read the elements from the parameter file. */
int nval = -1;
/* Open IMF group */ char** elements;
h5_open_group(sm->yields_table, "Data", &file_id, &group_id); parser_get_param_string_array(params, "GEARFeedback:elements", &nval,
&elements);
/* Read the elements */
io_read_string_array_attribute(group_id, "elts", sm->elements_name, /* Check that we have the correct number of elements. */
GEAR_CHEMISTRY_ELEMENT_COUNT, if (nval != GEAR_CHEMISTRY_ELEMENT_COUNT - 1) {
GEAR_LABELS_SIZE);
/* Check that we received correctly the metals */
if (strcmp(stellar_evolution_get_element_name(
sm, GEAR_CHEMISTRY_ELEMENT_COUNT - 1),
"Metals") != 0) {
error( error(
"The chemistry table should contain the metals in the last column " "You need to provide %i elements but found %i. "
"(found %s)", "If you wish to provide a different number of elements, "
stellar_evolution_get_element_name(sm, "you need to compile with --with-chemistry=GEAR_N where N "
GEAR_CHEMISTRY_ELEMENT_COUNT - 1)); "is the number of elements + 1.",
GEAR_CHEMISTRY_ELEMENT_COUNT, nval);
} }
/* Print the name of the elements */ /* Copy the elements into the stellar model. */
char txt[GEAR_CHEMISTRY_ELEMENT_COUNT * (GEAR_LABELS_SIZE + 2)] = ""; for (int i = 0; i < nval; i++) {
for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) { if (strlen(elements[i]) >= GEAR_LABELS_SIZE) {
if (i != 0) { error("Element name '%s' too long", elements[i]);
strcat(txt, ", ");
} }
strcat(txt, stellar_evolution_get_element_name(sm, i)); strcpy(sm->elements_name + i * GEAR_LABELS_SIZE, elements[i]);
} }
if (engine_rank == 0) { /* Cleanup. */
message("Chemistry elements: %s", txt); parser_free_param_string_array(nval, elements);
}
/* Cleanup everything */ /* Add the metals to the end. */
h5_close_group(file_id, group_id); strcpy(
sm->elements_name + (GEAR_CHEMISTRY_ELEMENT_COUNT - 1) * GEAR_LABELS_SIZE,
"Metals");
} }
/** /**
...@@ -435,10 +430,6 @@ void stellar_evolution_props_init(struct stellar_model* sm, ...@@ -435,10 +430,6 @@ void stellar_evolution_props_init(struct stellar_model* sm,
struct swift_params* params, struct swift_params* params,
const struct cosmology* cosmo) { const struct cosmology* cosmo) {
/* Get filename. */
parser_get_param_string(params, "GEARFeedback:yields_table",
sm->yields_table);
/* Read the list of elements */ /* Read the list of elements */
stellar_evolution_read_elements(sm, params); stellar_evolution_read_elements(sm, params);
...@@ -447,10 +438,11 @@ void stellar_evolution_props_init(struct stellar_model* sm, ...@@ -447,10 +438,11 @@ void stellar_evolution_props_init(struct stellar_model* sm,
parser_get_param_int(params, "GEARFeedback:discrete_yields"); parser_get_param_int(params, "GEARFeedback:discrete_yields");
/* Initialize the initial mass function */ /* Initialize the initial mass function */
initial_mass_function_init(&sm->imf, phys_const, us, params); initial_mass_function_init(&sm->imf, phys_const, us, params,
sm->yields_table);
/* Initialize the lifetime model */ /* Initialize the lifetime model */
lifetime_init(&sm->lifetime, phys_const, us, params); lifetime_init(&sm->lifetime, phys_const, us, params, sm->yields_table);
/* Initialize the supernovae Ia model */ /* Initialize the supernovae Ia model */
supernovae_ia_init(&sm->snia, phys_const, us, params, sm); supernovae_ia_init(&sm->snia, phys_const, us, params, sm);
......
...@@ -168,26 +168,32 @@ float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia, ...@@ -168,26 +168,32 @@ float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia,
* @param snia The #supernovae_ia model. * @param snia The #supernovae_ia model.
* @param params The #swift_params. * @param params The #swift_params.
* @param sm The #stellar_model. * @param sm The #stellar_model.
* @param filename The filename of the chemistry table.
*/ */
void supernovae_ia_read_yields(struct supernovae_ia *snia, void supernovae_ia_read_yields(struct supernovae_ia *snia,
struct swift_params *params, struct swift_params *params,
const struct stellar_model *sm) { const struct stellar_model *sm,
const char *filename) {
hid_t file_id, group_id; hid_t file_id, group_id;
const int number_labels = GEAR_CHEMISTRY_ELEMENT_COUNT + 2;
/* Open IMF group */ /* Open IMF group */
char filename[FILENAME_BUFFER_SIZE];
parser_get_param_string(params, "GEARFeedback:yields_table", filename);
h5_open_group(filename, "Data/SNIa/Metals", &file_id, &group_id); h5_open_group(filename, "Data/SNIa/Metals", &file_id, &group_id);
/* Get the number of elements. */
const hid_t attr = H5Aopen(group_id, "elts", H5P_DEFAULT);
if (attr < 0) error("Error while opening attribute elts in Data/SNIa/Metals");
size_t nval = io_get_number_element_in_attribute(attr);
H5Aclose(attr);
/* Read the yields */ /* Read the yields */
float *yields = (float *)malloc(sizeof(float) * number_labels); float *yields = (float *)malloc(sizeof(float) * nval);
io_read_array_attribute(group_id, "data", FLOAT, yields, number_labels); io_read_array_attribute(group_id, "data", FLOAT, yields, nval);
/* Read the labels */ /* Read the labels */
char labels[(GEAR_CHEMISTRY_ELEMENT_COUNT + 2) * GEAR_LABELS_SIZE] = ""; char *labels = malloc(nval * GEAR_LABELS_SIZE);
io_read_string_array_attribute(group_id, "elts", labels, number_labels, io_read_string_array_attribute(group_id, "elts", labels, nval,
GEAR_LABELS_SIZE); GEAR_LABELS_SIZE);
/* Save the yields */ /* Save the yields */
...@@ -195,7 +201,7 @@ void supernovae_ia_read_yields(struct supernovae_ia *snia, ...@@ -195,7 +201,7 @@ void supernovae_ia_read_yields(struct supernovae_ia *snia,
for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) { for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
int found = 0; int found = 0;
/* Loop over SNIa yields labels */ /* Loop over SNIa yields labels */
for (int j = 0; j < number_labels; j++) { for (size_t j = 0; j < nval; j++) {
const char *s1 = labels + j * GEAR_LABELS_SIZE; const char *s1 = labels + j * GEAR_LABELS_SIZE;
const char *s2 = stellar_evolution_get_element_name(sm, i); const char *s2 = stellar_evolution_get_element_name(sm, i);
if (strcmp(s1, s2) == 0) { if (strcmp(s1, s2) == 0) {
...@@ -207,13 +213,14 @@ void supernovae_ia_read_yields(struct supernovae_ia *snia, ...@@ -207,13 +213,14 @@ void supernovae_ia_read_yields(struct supernovae_ia *snia,
/* Check if found an element */ /* Check if found an element */
if (!found) { if (!found) {
error("Cannot find element %s in SNIa yields", error("Cannot find element '%s' in SNIa yields",
stellar_evolution_get_element_name(sm, i)); stellar_evolution_get_element_name(sm, i));
} }
} }
/* Cleanup everything */ /* Cleanup everything */
free(yields); free(yields);
free(labels);
h5_close_group(file_id, group_id); h5_close_group(file_id, group_id);
}; };
...@@ -242,15 +249,15 @@ void supernovae_ia_init_companion(struct supernovae_ia *snia) { ...@@ -242,15 +249,15 @@ void supernovae_ia_init_companion(struct supernovae_ia *snia) {
* *
* @param snia The #supernovae_ia model. * @param snia The #supernovae_ia model.
* @param params The simulation parameters. * @param params The simulation parameters.
* @param filename The filename of the chemistry table.
*/ */
void supernovae_ia_read_from_tables(struct supernovae_ia *snia, void supernovae_ia_read_from_tables(struct supernovae_ia *snia,
struct swift_params *params) { struct swift_params *params,
const char *filename) {
hid_t file_id, group_id; hid_t file_id, group_id;
/* Open IMF group */ /* Open IMF group */
char filename[FILENAME_BUFFER_SIZE];
parser_get_param_string(params, "GEARFeedback:yields_table", filename);
h5_open_group(filename, "Data/SNIa", &file_id, &group_id); h5_open_group(filename, "Data/SNIa", &file_id, &group_id);
/* Read the exponent of the IMF for companion */ /* Read the exponent of the IMF for companion */
...@@ -295,62 +302,6 @@ void supernovae_ia_read_from_tables(struct supernovae_ia *snia, ...@@ -295,62 +302,6 @@ void supernovae_ia_read_from_tables(struct supernovae_ia *snia,
h5_close_group(file_id, group_id); h5_close_group(file_id, group_id);
} }
/**
* @brief Reads the supernovae Ia parameters from the parameters file.
*
* @param snia The #supernovae_ia model.
* @param params The simulation parameters.
*/
void supernovae_ia_read_from_params(struct supernovae_ia *snia,
struct swift_params *params) {
/* Read the exponent of the IMF for companion */
snia->companion_exponent = parser_get_opt_param_float(
params, "GEARSupernovaeIa:exponent", snia->companion_exponent);
/* Read the minimal mass for a white dwarf */
snia->mass_min_progenitor = parser_get_opt_param_float(
params, "GEARSupernovaeIa:min_mass_white_dwarf_progenitor",
snia->mass_min_progenitor);
/* Read the maximal mass for a white dwarf */
snia->mass_max_progenitor = parser_get_opt_param_float(
params, "GEARSupernovaeIa:max_mass_white_dwarf_progenitor",
snia->mass_max_progenitor);
/* Read the maximal mass of a red giant companion */
snia->companion[0].mass_max =
parser_get_opt_param_float(params, "GEARSupernovaeIa:max_mass_red_giant",
snia->companion[0].mass_max);