Skip to content
Snippets Groups Projects
Commit c048bf07 authored by Folkert Nobels's avatar Folkert Nobels
Browse files

Update the time step calculating

parent 3d14636e
No related branches found
No related tags found
1 merge request!705Star formation following Schaye08
...@@ -475,6 +475,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { ...@@ -475,6 +475,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
const struct hydro_props *restrict hydro_props = e->hydro_properties; const struct hydro_props *restrict hydro_props = e->hydro_properties;
const struct unit_system *restrict us = e->internal_units; const struct unit_system *restrict us = e->internal_units;
struct cooling_function_data *restrict cooling = e->cooling_func; struct cooling_function_data *restrict cooling = e->cooling_func;
const double time_base = e->time_base;
const integertime_t ti_current = e->ti_current;
TIMER_TIC; TIMER_TIC;
...@@ -496,12 +498,27 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { ...@@ -496,12 +498,27 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
if (part_is_active(p, e)) { if (part_is_active(p, e)) {
/* Calculate the time step of the current particle*/
double dt_star;
if (with_cosmology) {
const integertime_t ti_step = get_integer_timestep(p->time_bin);
const integertime_t ti_begin =
get_integer_time_begin(ti_current - 1, p->time_bin);
dt_star =
cosmology_get_delta_time(cosmo, ti_begin, ti_begin + ti_step);
} else {
dt_star = get_timestep(p->time_bin, time_base);
}
// const float rho = hydro_get_physical_density(p, cosmo); // const float rho = hydro_get_physical_density(p, cosmo);
if (star_formation_convert_to_star(e, starform, p, xp, constants, cosmo, if (star_formation_convert_to_star(e, starform, p, xp, constants, cosmo,
hydro_props, us, cooling)) { hydro_props, us, cooling, dt_star)) {
/* Convert your particle to a star */ /* Convert your particle to a star */
struct spart* sp = cell_convert_part_to_spart(e, c, p, xp); struct spart* sp = cell_convert_part_to_spart(e, c, p, xp);
/* Copy the properties of the gas particle to the star particle */
star_formation_copy_properties(e, p, xp, sp, starform, constants, star_formation_copy_properties(e, p, xp, sp, starform, constants,
cosmo, with_cosmology); cosmo, with_cosmology);
// struct spart *sp = cell_conert_part_to_spart(c, p, ...); // struct spart *sp = cell_conert_part_to_spart(c, p, ...);
......
...@@ -156,7 +156,6 @@ INLINE static int star_formation_potential_to_become_star( ...@@ -156,7 +156,6 @@ INLINE static int star_formation_potential_to_become_star(
if (particle_density < rho_crit_times_min_over_den) if (particle_density < rho_crit_times_min_over_den)
return 0; return 0;
/* In this case there are actually multiple possibilities /* In this case there are actually multiple possibilities
* because we also need to check if the physical density exceeded * because we also need to check if the physical density exceeded
* the appropriate limit */ * the appropriate limit */
...@@ -165,14 +164,14 @@ INLINE static int star_formation_potential_to_become_star( ...@@ -165,14 +164,14 @@ INLINE static int star_formation_potential_to_become_star(
double density_threshold_metal_dep = double density_threshold_metal_dep =
starform->density_threshold * pow(Z * starform->Z0_inv, starform->n_Z0); starform->density_threshold * pow(Z * starform->Z0_inv, starform->n_Z0);
double density_threshold_current = min(density_threshold_metal_dep, starform->density_threshold_max); /* Calculate the maximum between both and convert to mass density instead of number density*/
double density_threshold_current = min(density_threshold_metal_dep, starform->density_threshold_max) * phys_const->const_proton_mass;
/* Check if it exceeded the maximum density */ /* Check if it exceeded the maximum density */
if (particle_density < density_threshold_current) if (particle_density*p->chemistry_data.smoothed_metal_mass_fraction[0] < density_threshold_current)
return 0; return 0;
/* Calculate the temperature */ /* Calculate the temperature */
const double temperature = cooling_get_temperature(phys_const, hydro_props, us, cosmo, const double temperature = cooling_get_temperature(phys_const, hydro_props, us, cosmo,
cooling, p, xp); cooling, p, xp);
...@@ -200,18 +199,19 @@ INLINE static int star_formation_convert_to_star( ...@@ -200,18 +199,19 @@ INLINE static int star_formation_convert_to_star(
const struct phys_const* const phys_const, const struct cosmology* cosmo, const struct phys_const* const phys_const, const struct cosmology* cosmo,
const struct hydro_props* restrict hydro_props, const struct hydro_props* restrict hydro_props,
const struct unit_system* restrict us, const struct unit_system* restrict us,
const struct cooling_function_data* restrict cooling) { const struct cooling_function_data* restrict cooling,
const double dt_star) {
if (star_formation_potential_to_become_star( if (star_formation_potential_to_become_star(
starform, p, xp, phys_const, cosmo, hydro_props, us, cooling)) { starform, p, xp, phys_const, cosmo, hydro_props, us, cooling)) {
/* Get the pressure */ /* Get the pressure */
const double pressure = const double pressure =
starform->EOS_pressure_norm * starform->EOS_pressure_norm *
pow(p->rho / starform->EOS_density_norm, starform->polytropic_index); pow(hydro_get_physical_density(p,cosmo) / starform->EOS_density_norm, starform->polytropic_index);
/* Calculate the propability of forming a star */ /* Calculate the propability of forming a star */
const double prop = starform->SF_normalization * const double prop = starform->SF_normalization *
pow(pressure, starform->SF_power_law) * p->time_bin; pow(pressure, starform->SF_power_law) * dt_star;
/* Calculate the seed */ /* Calculate the seed */
unsigned int seed = (p->id + e->ti_current) % 8191; unsigned int seed = (p->id + e->ti_current) % 8191;
...@@ -219,6 +219,8 @@ INLINE static int star_formation_convert_to_star( ...@@ -219,6 +219,8 @@ INLINE static int star_formation_convert_to_star(
/* Generate a random number between 0 and 1. */ /* Generate a random number between 0 and 1. */
const double randomnumber = rand_r(&seed) * starform->inv_RAND_MAX; const double randomnumber = rand_r(&seed) * starform->inv_RAND_MAX;
message("Passed whole boundary thing! random number = %e, prop = %e time_bin %d", randomnumber, prop, p->time_bin);
/* Calculate if we form a star */ /* Calculate if we form a star */
return (prop > randomnumber); return (prop > randomnumber);
...@@ -304,7 +306,7 @@ INLINE static void starformation_init_backend( ...@@ -304,7 +306,7 @@ INLINE static void starformation_init_backend(
/* Conversion of number density from cgs */ /* Conversion of number density from cgs */
static const float dimension_numb_den[5] = {0, -3, 0, 0, 0}; static const float dimension_numb_den[5] = {0, -3, 0, 0, 0};
const double conversion_numb_density = const double conversion_numb_density = 1/
units_general_cgs_conversion_factor(us, dimension_numb_den); units_general_cgs_conversion_factor(us, dimension_numb_den);
/* Quantities that have to do with the Normal Kennicutt- /* Quantities that have to do with the Normal Kennicutt-
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment