Commit 1aee343e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Sampled stellar evolution

parent bde56afa
......@@ -32,6 +32,7 @@ examples/*/*/*.dat
examples/*/*/*.png
examples/*/*/*.pdf
examples/*/*/*.mp4
examples/*/*/*.txt
examples/*/*/*.rst
examples/*/*/*.hdf5
examples/*/*/*.csv
......
......@@ -666,6 +666,8 @@ Supernova feedback: Dalla Vecchia+2012 & Schaye+2015
SNIa_DTD_exp_timescale_Gyr: 2.0 # Time-scale of the SNIa delay time distribution in the exponential DTD case (in Gyr).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -162,6 +162,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -163,6 +163,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -163,6 +163,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -157,6 +157,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -165,6 +165,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -156,6 +156,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -166,6 +166,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -141,6 +141,8 @@ EAGLEFeedback:
SNIa_DTD_power_law_norm_p_Msun: 0.0012 # Normalization of the SNIa delay time distribution (in Msun^-1).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Age in Gyr above which the enrichment is downsampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -17,7 +17,7 @@ TimeIntegration:
Snapshots:
basename: stellar_evolution # Common part of the name of output files
time_first: 0. # Time of the first output (in internal units)
delta_time: 3.e-5 # Time difference between consecutive outputs without cosmology (internal units)
delta_time: 3.e-5 # Time difference between consecutive outputs (internal units)
compression: 4
# Parameters governing the conserved quantities statistics
......@@ -106,6 +106,8 @@ EAGLEFeedback:
SNIa_DTD_exp_norm_p_Msun: 0.002 # Normalisation of the SNIa rates in inverse solar masses.
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Age in Gyr above which the enrichment is downsampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -412,6 +412,8 @@ EAGLEFeedback:
SNIa_DTD_exp_timescale_Gyr: 2.0 # Time-scale of the SNIa delay time distribution in the exponential DTD case (in Gyr).
SNIa_energy_erg: 1.0e51 # Energy of one SNIa explosion in ergs.
AGB_ejecta_velocity_km_p_s: 10.0 # Velocity of the AGB ejectas in km/s.
stellar_evolution_age_cut_Gyr: 0.1 # Stellar age in Gyr above which the enrichment is down-sampled.
stellar_evolution_sampling_rate: 10 # Number of time-steps in-between two enrichment events for a star above the age threshold.
SNII_yield_factor_Hydrogen: 1.0 # (Optional) Correction factor to apply to the Hydrogen yield from the SNII channel.
SNII_yield_factor_Helium: 1.0 # (Optional) Correction factor to apply to the Helium yield from the SNII channel.
SNII_yield_factor_Carbon: 0.5 # (Optional) Correction factor to apply to the Carbon yield from the SNII channel.
......
......@@ -840,6 +840,9 @@ void compute_stellar_evolution(const struct feedback_props* feedback_props,
#ifdef SWIFT_DEBUG_CHECKS
if (age < 0.f) error("Negative age for a star.");
if (sp->count_since_last_enrichment != 0)
error("Computing feedback on a star that should not");
#endif
/* Convert dt and stellar age from internal units to Gyr. */
......@@ -981,6 +984,8 @@ void feedback_props_init(struct feedback_props* fp,
const struct hydro_props* hydro_props,
const struct cosmology* cosmo) {
const double Gyr_in_cgs = 1.0e9 * 365.25 * 24. * 3600.;
/* Main operation modes ------------------------------------------------- */
fp->with_SNII_feedback =
......@@ -1027,7 +1032,6 @@ void feedback_props_init(struct feedback_props* fp,
if (!fp->SNII_sampled_delay) {
/* Set the delay time before SNII occur */
const double Gyr_in_cgs = 1.0e9 * 365.25 * 24. * 3600.;
fp->SNII_wind_delay =
parser_get_param_double(params, "EAGLEFeedback:SNII_wind_delay_Gyr") *
Gyr_in_cgs / units_cgs_conversion_factor(us, UNIT_CONV_TIME);
......@@ -1148,6 +1152,28 @@ void feedback_props_init(struct feedback_props* fp,
fp->AGB_ejecta_specific_kinetic_energy =
0.5f * ejecta_velocity * ejecta_velocity;
/* Properties of the enrichment down-sampling ----------------------------- */
fp->stellar_evolution_age_cut =
parser_get_param_double(params,
"EAGLEFeedback:stellar_evolution_age_cut_Gyr") *
Gyr_in_cgs / units_cgs_conversion_factor(us, UNIT_CONV_TIME);
fp->stellar_evolution_sampling_rate = parser_get_param_double(
params, "EAGLEFeedback:stellar_evolution_sampling_rate");
if (fp->stellar_evolution_sampling_rate < 1 ||
fp->stellar_evolution_sampling_rate >= (1 << (8 * sizeof(char) - 1)))
error("Stellar evolution sampling rate too large. Must be >0 and <%d",
(1 << (8 * sizeof(char) - 1)));
/* Check that we are not downsampling before reaching the SNII delay */
if (!fp->SNII_sampled_delay &&
fp->stellar_evolution_age_cut < fp->SNII_wind_delay)
error(
"Time at which the enrichment downsampling stars is lower than the "
"SNII wind delay!");
/* Gather common conversion factors --------------------------------------- */
/* Calculate internal mass to solar mass conversion factor */
......
......@@ -33,17 +33,6 @@ void compute_stellar_evolution(const struct feedback_props* feedback_props,
const struct unit_system* us, const double age,
const double dt);
/**
* @brief Should we do feedback for this star?
*
* @param sp The star to consider.
*/
__attribute__((always_inline)) INLINE static int feedback_do_feedback(
const struct spart* sp) {
return (sp->birth_time != -1.);
}
/**
* @brief Should this particle be doing any feedback-related operation?
*
......@@ -56,13 +45,7 @@ __attribute__((always_inline)) INLINE static int feedback_is_active(
const struct spart* sp, const float time, const struct cosmology* cosmo,
const int with_cosmology) {
if (sp->birth_time == -1.) return 0;
if (with_cosmology) {
return ((float)cosmo->a) > sp->birth_scale_factor;
} else {
return time > sp->birth_time;
}
return (sp->birth_time != -1.) && (sp->count_since_last_enrichment == 0);
}
/**
......@@ -77,6 +60,30 @@ __attribute__((always_inline)) INLINE static void feedback_init_spart(
sp->feedback_data.to_collect.ngb_mass = 0.f;
}
/**
* @brief Returns the length of time since the particle last did
* enrichment/feedback.
*
* @param sp The #spart.
* @param with_cosmology Are we running with cosmological time integration on?
* @param cosmo The cosmological model.
* @param time The current time (since the Big Bang / start of the run) in
* internal units.
* @param dt_star the length of this particle's time-step in internal units.
* @return The length of the enrichment step in internal units.
*/
INLINE static double feedback_get_enrichment_timestep(
const struct spart* sp, const int with_cosmology,
const struct cosmology* cosmo, const double time, const double dt_star) {
if (with_cosmology) {
return cosmology_get_delta_time_from_scale_factors(
cosmo, (double)sp->last_enrichment_time, cosmo->a);
} else {
return time - sp->last_enrichment_time;
}
}
/**
* @brief Prepares a star's feedback field before computing what
* needs to be distributed.
......@@ -153,11 +160,14 @@ __attribute__((always_inline)) INLINE static void feedback_prepare_spart(
* @param star_age_beg_step The age of the star at the star of the time-step in
* internal units.
* @param dt The time-step size of this star in internal units.
* @param time The physical time in internal units.
* @param with_cosmology Are we running with cosmology on?
*/
__attribute__((always_inline)) INLINE static void feedback_evolve_spart(
struct spart* restrict sp, const struct feedback_props* feedback_props,
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, const double time,
const int with_cosmology) {
#ifdef SWIFT_DEBUG_CHECKS
if (sp->birth_time == -1.) error("Evolving a star particle that should not!");
......@@ -170,6 +180,64 @@ __attribute__((always_inline)) INLINE static void feedback_evolve_spart(
/* Decrease star mass by amount of mass distributed to gas neighbours */
sp->mass -= sp->feedback_data.to_distribute.mass;
/* Mark this is the last time we did enrichment */
if (with_cosmology)
sp->last_enrichment_time = cosmo->a;
else
sp->last_enrichment_time = time;
}
/**
* @brief Will this star particle want to do feedback during the next time-step?
*
* @param sp The star of interest.
* @param feedback_props The properties of the feedback model.
* @param age_of_star Age of the star in internal units.
*/
__attribute__((always_inline)) INLINE static int feedback_will_do_feedback(
struct spart* restrict sp, const struct feedback_props* feedback_props,
const int with_cosmology, const struct cosmology* cosmo,
const double time) {
/* Calculate age of the star at current time */
double age_of_star;
if (with_cosmology) {
age_of_star = cosmology_get_delta_time_from_scale_factors(
cosmo, (double)sp->birth_scale_factor, cosmo->a);
} else {
age_of_star = time - (double)sp->birth_time;
}
/* Is the star still young? */
if (age_of_star < feedback_props->stellar_evolution_age_cut) {
/* Set the counter to "let's do enrichment" */
sp->count_since_last_enrichment = 0;
/* Say we want to do feedback */
return 1;
} else {
/* Increment counter */
sp->count_since_last_enrichment++;
if ((sp->count_since_last_enrichment %
feedback_props->stellar_evolution_sampling_rate) == 0) {
/* Reset counter */
sp->count_since_last_enrichment = 0;
/* Say we want to do feedback */
return 1;
} else {
/* Say we don't want to do feedback */
return 0;
}
}
}
void feedback_clean(struct feedback_props* feedback_props);
......
......@@ -91,6 +91,11 @@ runner_iact_nonsym_feedback_apply(const float r2, const float *dx,
const struct cosmology *cosmo,
const integertime_t ti_current) {
#ifdef SWIFT_DEBUG_CHECKS
if (si->count_since_last_enrichment != 0)
error("Computing feedback from a star that should not");
#endif
/* Get r. */
const float r = sqrtf(r2);
......@@ -113,8 +118,10 @@ runner_iact_nonsym_feedback_apply(const float r2, const float *dx,
#ifdef SWIFT_DEBUG_CHECKS
if (Omega_frac < 0. || Omega_frac > 1.01)
error("Invalid fraction of material to distribute. Omega_frac=%e",
Omega_frac);
error(
"Invalid fraction of material to distribute for star ID=%lld "
"Omega_frac=%e count since last enrich=%d",
si->id, Omega_frac, si->count_since_last_enrichment);
#endif
/* Update particle mass */
......
......@@ -264,6 +264,15 @@ struct feedback_props {
/*! Slope of the metallicity dependance of the feedback energy fraction model
*/
double n_Z;
/* ------------ Enrichment sampling properties ------------ */
/*! Star age above which the enrichment will be downsampled (in internal
* units) */
double stellar_evolution_age_cut;
/*! Number of time-steps in-between two enrichment events */
int stellar_evolution_sampling_rate;
};
void feedback_props_init(struct feedback_props *fp,
......
......@@ -64,6 +64,29 @@ __attribute__((always_inline)) INLINE static int feedback_is_active(
return 1;
}
/**
* @brief Returns the length of time since the particle last did
* enrichment/feedback.
*
* We just return the normal time-step here since particles do something every
* regular time-step.
*
* @param sp The #spart.
* @param with_cosmology Are we running with cosmological time integration on?
* @param cosmo The cosmological model.
* @param time The current time (since the Big Bang / start of the run) in
* internal units.
* @param dt_star the length of this particle's time-step in internal units.
* @return The length of the enrichment step in internal units.
*/
INLINE static double feedback_get_enrichment_timestep(
const struct spart* sp, const int with_cosmology,
const struct cosmology* cosmo, const double time, const double dt_star) {
/* Just return the regular step length */
return dt_star;
}
/**
* @brief Prepares a star's feedback field before computing what
* needs to be distributed.
......@@ -108,11 +131,30 @@ __attribute__((always_inline)) INLINE static void feedback_prepare_spart(
* @param star_age_beg_step The age of the star at the star of the time-step in
* internal units.
* @param dt The time-step size of this star in internal units.
* @param time The physical time in internal units.
* @param with_cosmology Are we running with cosmology on?
*/
__attribute__((always_inline)) INLINE static void feedback_evolve_spart(
struct spart* restrict sp, const struct feedback_props* feedback_props,
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, const double time,
const int with_cosmology) {}
/**
* @brief Will this star particle want to do feedback during the next time-step?
*
* @param sp The star of interest.
* @param feedback_props The properties of the feedback model.
* @param with_cosmology Are we running with cosmological time integration?
* @param cosmo The #cosmology object.
* @param time The current time (since the Big Bang).
*/
__attribute__((always_inline)) INLINE static int feedback_will_do_feedback(
struct spart* restrict sp, const struct feedback_props* feedback_props,
const int with_cosmology, const struct cosmology* cosmo,
const double time) {
return 1;
}
/**
* @brief Clean-up the memory allocated for the feedback routines
......
......@@ -204,19 +204,19 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
stars_reset_feedback(sp);
/* Only do feedback if stars have a reasonable birth time */
if (feedback_do_feedback(sp)) {
if (feedback_is_active(sp, e->time, cosmo, with_cosmology)) {
const integertime_t ti_step = get_integer_timestep(sp->time_bin);
const integertime_t ti_begin =
get_integer_time_begin(e->ti_current - 1, sp->time_bin);
/* Get particle time-step */
double dt;
double dt_star;
if (with_cosmology) {
dt = cosmology_get_delta_time(e->cosmology, ti_begin,
dt_star = cosmology_get_delta_time(e->cosmology, ti_begin,
ti_begin + ti_step);
} else {
dt = get_timestep(sp->time_bin, e->time_base);
dt_star = get_timestep(sp->time_bin, e->time_base);
}
/* Calculate age of the star at current time */
......@@ -226,19 +226,22 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
cosmology_get_delta_time_from_scale_factors(
cosmo, (double)sp->birth_scale_factor, cosmo->a);
} else {
star_age_end_of_step = (float)e->time - sp->birth_time;
star_age_end_of_step = e->time - (double)sp->birth_time;
}
/* Has this star been around for a while ? */
if (star_age_end_of_step > 0.) {
/* Age of the star at the start of the step */
/* Get the length of the enrichment time-step */
const double dt_enrichment = feedback_get_enrichment_timestep(
sp, with_cosmology, cosmo, e->time, dt_star);
const double star_age_beg_of_step =
max(star_age_end_of_step - dt, 0.);
star_age_end_of_step - dt_enrichment;
/* Compute the stellar evolution */
feedback_evolve_spart(sp, feedback_props, cosmo, us,
star_age_beg_of_step, dt);
star_age_beg_of_step, dt_enrichment,
e->time, with_cosmology);
} else {
/* Reset the feedback fields of the star particle */
......@@ -345,40 +348,43 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
stars_reset_feedback(sp);
/* Only do feedback if stars have a reasonable birth time */
if (feedback_do_feedback(sp)) {
if (feedback_is_active(sp, e->time, cosmo, with_cosmology)) {
const integertime_t ti_step = get_integer_timestep(sp->time_bin);
const integertime_t ti_begin =
get_integer_time_begin(e->ti_current - 1, sp->time_bin);
/* Get particle time-step */
double dt;
double dt_star;
if (with_cosmology) {
dt = cosmology_get_delta_time(e->cosmology, ti_begin,
dt_star = cosmology_get_delta_time(e->cosmology, ti_begin,
ti_begin + ti_step);
} else {
dt = get_timestep(sp->time_bin, e->time_base);
dt_star = get_timestep(sp->time_bin, e->time_base);
}
/* Calculate age of the star at current time */
double star_age_end_of_step;
if (with_cosmology) {
star_age_end_of_step = cosmology_get_delta_time_from_scale_factors(
cosmo, sp->birth_scale_factor, (float)cosmo->a);
cosmo, (double)sp->birth_scale_factor, cosmo->a);
} else {
star_age_end_of_step = (float)e->time - sp->birth_time;
star_age_end_of_step = e->time - (double)sp->birth_time;
}
/* Has this star been around for a while ? */
if (star_age_end_of_step > 0.) {
/* Age of the star at the start of the step */
/* Get the length of the enrichment time-step */
const double dt_enrichment = feedback_get_enrichment_timestep(
sp, with_cosmology, cosmo, e->time, dt_star);
const double star_age_beg_of_step =
max(star_age_end_of_step - dt, 0.);
star_age_end_of_step - dt_enrichment;
/* Compute the stellar evolution */
feedback_evolve_spart(sp, feedback_props, cosmo, us,
star_age_beg_of_step, dt);
star_age_beg_of_step, dt_enrichment, e->time,
with_cosmology);
} else {
/* Reset the feedback fields of the star particle */
......
......@@ -30,6 +30,7 @@
#include "black_holes.h"
#include "cell.h"
#include "engine.h"
#include "feedback.h"
#include "kick.h"
#include "timers.h"
#include "timestep.h"
......@@ -746,6 +747,9 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
sp->time_bin = get_time_bin(ti_new_step);
sp->gpart->time_bin = get_time_bin(ti_new_step);
feedback_will_do_feedback(sp, e->feedback_props, with_cosmology,
e->cosmology, e->time);
/* Number of updated s-particles */
s_updated++;
g_updated++;
......
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