Skip to content
Snippets Groups Projects
Commit 603f71da authored by Loic Hausammann's avatar Loic Hausammann
Browse files

update with recent changes in SWIFT

parent 3e774136
No related branches found
No related tags found
1 merge request!12update with recent changes in SWIFT
...@@ -179,7 +179,9 @@ class ParameterFile: ...@@ -179,7 +179,9 @@ class ParameterFile:
"GEARFeedback": { "GEARFeedback": {
"supernovae_energy_erg": 1e51, "supernovae_energy_erg": 1e51,
"yields_table": "chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5", "yields_table": "chemistry-AGB+OMgSFeZnSrYBaEu-16072013.h5",
"discrete_yields": 0 "discrete_yields": 0,
"elements": ["Fe", "Mg", "O", "S", "Zn", "Sr", "Y", "Ba", "Eu"],
"metallicity_max_first_stars": -1,
}, },
} }
""" """
......
...@@ -154,20 +154,19 @@ PyObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -154,20 +154,19 @@ PyObject* pycooling_rate(PyObject* self, PyObject* args) {
hydro_set_physical_internal_energy_dt(&p, &cosmo, 0); hydro_set_physical_internal_energy_dt(&p, &cosmo, 0);
for(int j = 0; j < GEAR_CHEMISTRY_ELEMENT_COUNT; j++) { for(int j = 0; j < GEAR_CHEMISTRY_ELEMENT_COUNT; j++) {
p.chemistry_data.smoothed_metal_mass_fraction[j] = p.chemistry_data.metal_mass_fraction[j]; p.chemistry_data.smoothed_metal_mass_fraction[j] = p.chemistry_data.metal_mass[j] / hydro_get_mass(&p);
} }
/* compute cooling rate */ /* compute cooling rate */
cooling_cool_part(&pconst, &us, &cosmo, &hydro_props, cooling_cool_part(&pconst, &us, &cosmo, &hydro_props,
&floor_props, &cooling, &p, &xp, /* Time */0, dt, dt); &floor_props, &cooling, &p, &xp, dt, dt, /* Time */ 0);
float *tmp = PyArray_GETPTR1(rate, i); float *tmp = PyArray_GETPTR1(rate, i);
*tmp = hydro_get_physical_internal_energy_dt(&p, &cosmo); *tmp = hydro_get_physical_internal_energy_dt(&p, &cosmo);
} }
/* Cleanup */ /* Clean the memory */
cosmology_clean(&cosmo); PYSWIFTSIM_CLEAN_STRUCTS();
cooling_clean(&cooling); cooling_clean(&cooling);
return (PyObject *) rate; return (PyObject *) rate;
......
...@@ -44,32 +44,39 @@ enum error_code { ...@@ -44,32 +44,39 @@ enum error_code {
int pytools_check_array(PyArrayObject *obj, int dim, int type, const char* name); int pytools_check_array(PyArrayObject *obj, int dim, int type, const char* name);
#define PYSWIFTSIM_INIT_STRUCTS() \ #define PYSWIFTSIM_INIT_STRUCTS() \
\ \
/* Initialize parser */ \ /* Initialize parser */ \
struct swift_params params; \ struct swift_params params; \
parser_read_file(filename, &params); \ parser_read_file(filename, &params); \
\ \
/* Init unit system */ \ /* Init unit system */ \
struct unit_system us; \ struct unit_system us; \
units_init_from_params(&us, &params, "InternalUnitSystem"); \ units_init_from_params(&us, &params, "InternalUnitSystem"); \
\ \
/* Init physical constant */ \ /* Init physical constant */ \
struct phys_const pconst; \ struct phys_const pconst; \
phys_const_init(&us, &params, &pconst); \ phys_const_init(&us, &params, &pconst); \
\ \
/* Init cosmo */ \ /* Init cosmo */ \
struct cosmology cosmo; \ struct cosmology cosmo; \
\ \
if (with_cosmo) \ if (with_cosmo) \
cosmology_init(&params, &us, &pconst, &cosmo); \ cosmology_init(&params, &us, &pconst, &cosmo); \
else \ else \
cosmology_init_no_cosmo(&cosmo); \ cosmology_init_no_cosmo(&cosmo); \
\ \
/* Init hydro prop */ \ /* Init hydro prop */ \
struct hydro_props hydro_props; \ struct hydro_props hydro_props; \
hydro_props_init(&hydro_props, &pconst, &us, &params); \ hydro_props_init(&hydro_props, &pconst, &us, &params); \
#define PYSWIFTSIM_CLEAN_STRUCTS() \
/* No need to clean swift_params */ \
/* No need to clean unit_system */ \
/* No need to clean phys_const */ \
cosmology_clean(&cosmo); \
#endif // __PYSWIFTSIM_TOOLS_H__ #endif // __PYSWIFTSIM_TOOLS_H__
...@@ -77,6 +77,10 @@ PyObject* pyinitial_mass_function(PyObject* self, PyObject* args) { ...@@ -77,6 +77,10 @@ PyObject* pyinitial_mass_function(PyObject* self, PyObject* args) {
*imf_i /= pconst.const_solar_mass; *imf_i /= pconst.const_solar_mass;
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) imf; return (PyObject *) imf;
} }
...@@ -142,6 +146,10 @@ PyObject* pylifetime_from_mass(PyObject* self, PyObject* args) { ...@@ -142,6 +146,10 @@ PyObject* pylifetime_from_mass(PyObject* self, PyObject* args) {
*tau = pow(10, *tau) * pconst.const_year * 1e6; *tau = pow(10, *tau) * pconst.const_year * 1e6;
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) lifetime; return (PyObject *) lifetime;
} }
...@@ -207,6 +215,10 @@ PyObject* pymass_from_lifetime(PyObject* self, PyObject* args) { ...@@ -207,6 +215,10 @@ PyObject* pymass_from_lifetime(PyObject* self, PyObject* args) {
*m = pow(10, *m) * pconst.const_solar_mass; *m = pow(10, *m) * pconst.const_solar_mass;
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) mass; return (PyObject *) mass;
} }
...@@ -289,6 +301,10 @@ PyObject* pysupernovae_ia_rate(PyObject* self, PyObject* args) { ...@@ -289,6 +301,10 @@ PyObject* pysupernovae_ia_rate(PyObject* self, PyObject* args) {
*r /= pconst.const_solar_mass * pconst.const_year * 1e6; *r /= pconst.const_solar_mass * pconst.const_year * 1e6;
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) rate; return (PyObject *) rate;
} }
...@@ -370,6 +386,10 @@ PyObject* pysupernovae_ii_rate(PyObject* self, PyObject* args) { ...@@ -370,6 +386,10 @@ PyObject* pysupernovae_ii_rate(PyObject* self, PyObject* args) {
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) rate; return (PyObject *) rate;
} }
...@@ -443,6 +463,10 @@ PyObject* pysupernovae_ii_yields(PyObject* self, PyObject* args) { ...@@ -443,6 +463,10 @@ PyObject* pysupernovae_ii_yields(PyObject* self, PyObject* args) {
} }
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) yields_out; return (PyObject *) yields_out;
} }
...@@ -510,6 +534,10 @@ PyObject* pysupernovae_ii_mass_ejected(PyObject* self, PyObject* args) { ...@@ -510,6 +534,10 @@ PyObject* pysupernovae_ii_mass_ejected(PyObject* self, PyObject* args) {
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) mass_ejected; return (PyObject *) mass_ejected;
} }
...@@ -577,6 +605,10 @@ PyObject* pysupernovae_ii_mass_ejected_non_processed(PyObject* self, PyObject* a ...@@ -577,6 +605,10 @@ PyObject* pysupernovae_ii_mass_ejected_non_processed(PyObject* self, PyObject* a
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) mass_ejected; return (PyObject *) mass_ejected;
} }
...@@ -622,6 +654,10 @@ PyObject* pysupernovae_ia_yields(PyObject* self, PyObject* args) { ...@@ -622,6 +654,10 @@ PyObject* pysupernovae_ia_yields(PyObject* self, PyObject* args) {
*y = yields[i] / fp.stellar_model.snia.mass_white_dwarf; *y = yields[i] / fp.stellar_model.snia.mass_white_dwarf;
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) yields_out; return (PyObject *) yields_out;
} }
...@@ -663,6 +699,10 @@ PyObject* pysupernovae_ia_mass_ejected(PyObject* self, PyObject* args) { ...@@ -663,6 +699,10 @@ PyObject* pysupernovae_ia_mass_ejected(PyObject* self, PyObject* args) {
*y = supernovae_ia_get_ejected_mass_processed(&fp.stellar_model.snia) / fp.stellar_model.snia.mass_white_dwarf; *y = supernovae_ia_get_ejected_mass_processed(&fp.stellar_model.snia) / fp.stellar_model.snia.mass_white_dwarf;
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return (PyObject *) mass_ejected; return (PyObject *) mass_ejected;
} }
...@@ -707,6 +747,10 @@ PyObject* pystellar_get_elements(PyObject* self, PyObject* args) { ...@@ -707,6 +747,10 @@ PyObject* pystellar_get_elements(PyObject* self, PyObject* args) {
} }
} }
/* Clean the memory */
PYSWIFTSIM_CLEAN_STRUCTS();
feedback_clean(&fp);
return t; return t;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment