Commit 225ca214 authored by Folkert Nobels's avatar Folkert Nobels
Browse files

Protect the feedback from 0 ngb stellar evolution and allow a lower thermal...

Protect the feedback from 0 ngb stellar evolution and allow a lower thermal energy after enrichment because it can physical happen
parent c7a81a61
......@@ -717,6 +717,14 @@ void compute_stellar_evolution(const struct feedback_props* feedback_props,
/* Properties collected in the stellar density loop. */
const float ngb_gas_mass = sp->feedback_data.to_collect.ngb_mass;
/* Check if there are neighbours, otherwise exit */
if (ngb_gas_mass == 0.f) {
feedback_reset_feedback(sp, feedback_props);
return;
}
/* Update the enrichment weights */
const float enrichment_weight_inv =
sp->feedback_data.to_collect.enrichment_weight_inv;
......@@ -727,8 +735,7 @@ void compute_stellar_evolution(const struct feedback_props* feedback_props,
feedback_reset_feedback(sp, feedback_props);
/* Update the weights used for distribution */
const float enrichment_weight =
(enrichment_weight_inv != 0.f) ? 1.f / enrichment_weight_inv : 0.f;
const float enrichment_weight = 1.f / enrichment_weight_inv;
sp->feedback_data.to_distribute.enrichment_weight = enrichment_weight;
/* Compute properties of the stochastic SNII feedback model. */
......
......@@ -249,7 +249,11 @@ runner_iact_nonsym_feedback_apply(const float r2, const float *dx,
const double injected_energy =
si->feedback_data.to_distribute.energy * Omega_frac;
/* Apply energy conservation to recover the new thermal energy of the gas */
/* Apply energy conservation to recover the new thermal energy of the gas
* Note: in some specific cases the new_thermal_energy could be lower
* than the current_thermal_energy, this is mainly the case if the change
* in mass is relatively small and the velocity vectors between both the
* gas particle and the star particle have a small angle. */
const double new_thermal_energy = current_kinetic_energy_gas +
current_thermal_energy + injected_energy -
new_kinetic_energy_gas;
......@@ -257,11 +261,6 @@ runner_iact_nonsym_feedback_apply(const float r2, const float *dx,
/* Convert this to a specific thermal energy */
const double u_new_enrich = new_thermal_energy * new_mass_inv;
#ifdef SWIFT_DEBUG_CHECKS
if (new_thermal_energy < 0.99 * current_thermal_energy)
error("Enrichment is cooling the gas");
#endif
/* Do the energy injection. */
hydro_set_physical_internal_energy(pj, xpj, cosmo, u_new_enrich);
hydro_set_drifted_physical_internal_energy(pj, cosmo, u_new_enrich);
......
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