From 28632968a3742bf8925c0090dcb52bfd0cd724c4 Mon Sep 17 00:00:00 2001
From: Darwin <darwin.roduit@unige.ch>
Date: Wed, 12 Mar 2025 17:55:23 +0000
Subject: [PATCH] GEAR: Fix improper handling of IMF transition in
 star_population_continuous_IMF

---
 src/feedback/GEAR/stellar_evolution.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/feedback/GEAR/stellar_evolution.c b/src/feedback/GEAR/stellar_evolution.c
index 98b0436700..fd6ec03f19 100644
--- a/src/feedback/GEAR/stellar_evolution.c
+++ b/src/feedback/GEAR/stellar_evolution.c
@@ -492,16 +492,25 @@ void stellar_evolution_evolve_spart(
   /* Star particles representing only the continuous part of the IMF need a
   special treatment. They do not contain stars above the mass that separate the
   IMF into two parts (variable called minimal_discrete_mass_Msun in the sink
-  module). So, if m_beg_step > minimal_discrete_mass_Msun, you don't do
+  module). So, if m_end_step > minimal_discrete_mass_Msun, you don't do
   feedback. Note that the sm structure contains different information for the
   'first stars' and the 'late stars'. The right sm data is passed to this
   function so we do not need any special treatment here. */
   if (sp->star_type == star_population_continuous_IMF) {
     /* If it's not time yet for feedback, exit. Notice that both masses are in
       solar mass. */
-    if (m_beg_step > sm->imf.minimal_discrete_mass_Msun) {
+    if (m_end_step > sm->imf.minimal_discrete_mass_Msun) {
       return;
     }
+
+    /* If we are in a case where
+                m_beg_step > minimal_discrete_mass_Msun > m_end_step,
+       then we need to be careful. We don't want feedback from the discrete
+       part, only the continuous part. Hence, we need to update m_beg_step.
+    */
+    if (m_beg_step > sm->imf.minimal_discrete_mass_Msun) {
+      m_beg_step = sm->imf.minimal_discrete_mass_Msun;
+    }
   }
 
   /* Check if the star can produce a supernovae */
-- 
GitLab