Commit 767418e1 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Free the memory allocated by the feedback tables at the end of a run.

parent 325509d1
...@@ -1432,6 +1432,7 @@ int main(int argc, char *argv[]) { ...@@ -1432,6 +1432,7 @@ int main(int argc, char *argv[]) {
if (with_cosmology) cosmology_clean(e.cosmology); if (with_cosmology) cosmology_clean(e.cosmology);
if (with_self_gravity) pm_mesh_clean(e.mesh); if (with_self_gravity) pm_mesh_clean(e.mesh);
if (with_cooling || with_temperature) cooling_clean(&cooling_func); if (with_cooling || with_temperature) cooling_clean(&cooling_func);
if (with_feedback) feedback_clean(&feedback_properties);
engine_clean(&e, /*fof=*/0); engine_clean(&e, /*fof=*/0);
free(params); free(params);
......
...@@ -1076,6 +1076,60 @@ void feedback_restore_tables(struct feedback_props* fp) { ...@@ -1076,6 +1076,60 @@ void feedback_restore_tables(struct feedback_props* fp) {
compute_ejecta(fp); compute_ejecta(fp);
} }
/**
* @brief Clean-up the memory allocated for the feedback routines
*
* We simply free all the arrays.
*
* @param feedback_props the feedback data structure.
*/
void feedback_clean(struct feedback_props* feedback_props) {
swift_free("imf-tables", feedback_props->imf);
swift_free("imf-tables", feedback_props->imf_mass_bin);
swift_free("imf-tables", feedback_props->imf_mass_bin_log10);
swift_free("feedback-tables", feedback_props->yields_SNIa);
swift_free("feedback-tables", feedback_props->yield_SNIa_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_AGB.mass);
swift_free("feedback-tables", feedback_props->yield_AGB.metallicity);
swift_free("feedback-tables", feedback_props->yield_AGB.yield);
swift_free("feedback-tables", feedback_props->yield_AGB.yield_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_AGB.ejecta);
swift_free("feedback-tables", feedback_props->yield_AGB.ejecta_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_AGB.total_metals);
swift_free("feedback-tables",
feedback_props->yield_AGB.total_metals_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_SNII.mass);
swift_free("feedback-tables", feedback_props->yield_SNII.metallicity);
swift_free("feedback-tables", feedback_props->yield_SNII.yield);
swift_free("feedback-tables", feedback_props->yield_SNII.yield_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_SNII.ejecta);
swift_free("feedback-tables",
feedback_props->yield_SNII.ejecta_IMF_resampled);
swift_free("feedback-tables", feedback_props->yield_SNII.total_metals);
swift_free("feedback-tables",
feedback_props->yield_SNII.total_metals_IMF_resampled);
swift_free("feedback-tables", feedback_props->lifetimes.mass);
swift_free("feedback-tables", feedback_props->lifetimes.metallicity);
swift_free("feedback-tables", feedback_props->yield_mass_bins);
for (int i = 0; i < eagle_feedback_lifetime_N_metals; i++) {
free(feedback_props->lifetimes.dyingtime[i]);
}
free(feedback_props->lifetimes.dyingtime);
for (int i = 0; i < eagle_feedback_SNIa_N_elements; i++) {
free(feedback_props->SNIa_element_names[i]);
}
free(feedback_props->SNIa_element_names);
for (int i = 0; i < eagle_feedback_SNII_N_elements; i++) {
free(feedback_props->SNII_element_names[i]);
}
free(feedback_props->SNII_element_names);
for (int i = 0; i < eagle_feedback_AGB_N_elements; i++) {
free(feedback_props->AGB_element_names[i]);
}
free(feedback_props->AGB_element_names);
}
/** /**
* @brief Write a feedback struct to the given FILE as a stream of bytes. * @brief Write a feedback struct to the given FILE as a stream of bytes.
* *
......
...@@ -172,6 +172,8 @@ __attribute__((always_inline)) INLINE static void feedback_evolve_spart( ...@@ -172,6 +172,8 @@ __attribute__((always_inline)) INLINE static void feedback_evolve_spart(
sp->mass -= sp->feedback_data.to_distribute.mass; sp->mass -= sp->feedback_data.to_distribute.mass;
} }
void feedback_clean(struct feedback_props* feedback_props);
void feedback_struct_dump(const struct feedback_props* feedback, FILE* stream); void feedback_struct_dump(const struct feedback_props* feedback, FILE* stream);
void feedback_struct_restore(struct feedback_props* feedback, FILE* stream); void feedback_struct_restore(struct feedback_props* feedback, FILE* stream);
......
...@@ -114,6 +114,15 @@ __attribute__((always_inline)) INLINE static void feedback_evolve_spart( ...@@ -114,6 +114,15 @@ __attribute__((always_inline)) INLINE static void feedback_evolve_spart(
const struct cosmology* cosmo, const struct unit_system* us, const struct cosmology* cosmo, const struct unit_system* us,
const double star_age_beg_step, const double dt) {} const double star_age_beg_step, const double dt) {}
/**
* @brief Clean-up the memory allocated for the feedback routines
*
* We simply free all the arrays.
*
* @param feedback_props the feedback data structure.
*/
static INLINE void feedback_clean(struct feedback_props* feedback_props) {}
/** /**
* @brief Write a feedback struct to the given FILE as a stream of bytes. * @brief Write a feedback struct to the given FILE as a stream of bytes.
* *
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment