diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index c3170414a375a5dfd54029cdc500c1cbcb764f6f..80ea547a7657c426d8ad228a4895512fcdf95adc 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -60,6 +60,9 @@ struct xpart { /* Additional data used by the tracers */ struct tracers_xpart_data tracers_data; + /* SFR label */ + float SFR; + #ifdef WITH_LOGGER /* Additional data for the particle logger */ struct logger_part_data logger_data; diff --git a/src/runner.c b/src/runner.c index 71001321c1a222c00e90635bcf28171a3dd8a4bc..1d8b961fe2064a30a661e56a9ea16ac94feb9e31 100644 --- a/src/runner.c +++ b/src/runner.c @@ -515,7 +515,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { // const float rho = hydro_get_physical_density(p, cosmo); if (star_formation_convert_to_star(e, starform, p, xp, constants, cosmo, - hydro_props, us, cooling, dt_star)) { + hydro_props, us, cooling, dt_star, with_cosmology)) { /* Convert your particle to a star */ struct spart *sp = cell_convert_part_to_spart(e, c, p, xp); diff --git a/src/starformation/schaye08/starformation.h b/src/starformation/schaye08/starformation.h index 5990e534b9dedb15f80124b2b3c8659bed069a69..02dd462e398bd217041040a81fa4615ba5d7219c 100644 --- a/src/starformation/schaye08/starformation.h +++ b/src/starformation/schaye08/starformation.h @@ -200,12 +200,12 @@ INLINE static int star_formation_potential_to_become_star( */ INLINE static int star_formation_convert_to_star( const struct engine* e, const struct star_formation* starform, - const struct part* restrict p, const struct xpart* restrict xp, + const struct part* restrict p, struct xpart* restrict xp, const struct phys_const* const phys_const, const struct cosmology* cosmo, const struct hydro_props* restrict hydro_props, const struct unit_system* restrict us, const struct cooling_function_data* restrict cooling, - const double dt_star) { + const double dt_star, const int with_cosmology) { if (dt_star == 0.f) return 0; @@ -219,9 +219,14 @@ INLINE static int star_formation_convert_to_star( starform->EOS_density_norm / phys_const->const_proton_mass, starform->polytropic_index); + /* Calculate the star formation rate */ + const double SFRpergasmass = starform->SF_normalization * + pow(pressure, starform->SF_power_law); + + xp->SFR = SFRpergasmass * p->mass; + /* Calculate the propability of forming a star */ - const double prop = starform->SF_normalization * - pow(pressure, starform->SF_power_law) * dt_star; + const double prop = SFRpergasmass * dt_star; /* Calculate the seed */ unsigned int seed = (p->id + e->ti_current) % 8191; @@ -234,6 +239,15 @@ INLINE static int star_formation_convert_to_star( /* Calculate if we form a star */ return (prop > randomnumber); + } + + /* Check if it is the first time steps after star formation */ + if (xp->SFR>0.f) { + if (with_cosmology) { + xp->SFR = - cosmo->a; + } else { + xp->SFR = - e->time; + } } return 0;