Skip to content
Snippets Groups Projects
Commit 8109e6ce authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Format

parent 4941f719
No related branches found
No related tags found
1 merge request!839Gear star formation
Showing
with 51 additions and 58 deletions
...@@ -690,6 +690,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, ...@@ -690,6 +690,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const,
* @param data The global star_formation information. * @param data The global star_formation information.
*/ */
__attribute__((always_inline)) INLINE static void star_formation_init_part( __attribute__((always_inline)) INLINE static void star_formation_init_part(
struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {} struct part* restrict p, struct xpart* restrict xp,
const struct star_formation* data) {}
#endif /* SWIFT_EAGLE_STAR_FORMATION_H */ #endif /* SWIFT_EAGLE_STAR_FORMATION_H */
...@@ -88,11 +88,11 @@ INLINE static void star_formation_logger_add( ...@@ -88,11 +88,11 @@ INLINE static void star_formation_logger_add(
} }
/** /**
* @brief add a star formation history struct to the engine star formation history * @brief add a star formation history struct to the engine star formation
* accumulator struct * history accumulator struct
* *
* @param sf_add the star formation accumulator struct which we want to add to the star * @param sf_add the star formation accumulator struct which we want to add to
* formation history * the star formation history
* @param sf_update the star formation structure which we want to update * @param sf_update the star formation structure which we want to update
*/ */
INLINE static void star_formation_logger_add_to_accumulator( INLINE static void star_formation_logger_add_to_accumulator(
...@@ -145,7 +145,6 @@ INLINE static void star_formation_logger_accumulator_init( ...@@ -145,7 +145,6 @@ INLINE static void star_formation_logger_accumulator_init(
sfh->SFR_inactive = 0.f; sfh->SFR_inactive = 0.f;
} }
/** /**
* @brief Write the final SFH to a file * @brief Write the final SFH to a file
* *
......
...@@ -34,7 +34,6 @@ struct star_formation_history { ...@@ -34,7 +34,6 @@ struct star_formation_history {
float SFRdt_active; float SFRdt_active;
}; };
/* Starformation history struct for the engine. /* Starformation history struct for the engine.
Allows to integrate in time some values. Allows to integrate in time some values.
Nothing to do in EAGLE => copy of star_formation_history */ Nothing to do in EAGLE => copy of star_formation_history */
...@@ -52,5 +51,4 @@ struct star_formation_history_accumulator { ...@@ -52,5 +51,4 @@ struct star_formation_history_accumulator {
float SFRdt_active; float SFRdt_active;
}; };
#endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */ #endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */
...@@ -59,8 +59,8 @@ INLINE static int star_formation_is_star_forming( ...@@ -59,8 +59,8 @@ INLINE static int star_formation_is_star_forming(
const struct cooling_function_data* restrict cooling, const struct cooling_function_data* restrict cooling,
const struct entropy_floor_properties* restrict entropy_floor) { const struct entropy_floor_properties* restrict entropy_floor) {
const float temperature = const float temperature = cooling_get_temperature(phys_const, hydro_props, us,
cooling_get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); cosmo, cooling, p, xp);
const float temperature_max = starform->maximal_temperature; const float temperature_max = starform->maximal_temperature;
...@@ -80,9 +80,12 @@ INLINE static int star_formation_is_star_forming( ...@@ -80,9 +80,12 @@ INLINE static int star_formation_is_star_forming(
const float mu = hydro_props->mu_neutral; const float mu = hydro_props->mu_neutral;
/* Compute the density criterion */ /* Compute the density criterion */
const float coef = M_PI_4 / (phys_const->const_newton_G * n_jeans_2_3 * h * h); const float coef =
const float density_criterion = coef * (hydro_gamma * phys_const->const_boltzmann_k * temperature M_PI_4 / (phys_const->const_newton_G * n_jeans_2_3 * h * h);
/ (mu * phys_const->const_proton_mass) + sigma2); const float density_criterion =
coef * (hydro_gamma * phys_const->const_boltzmann_k * temperature /
(mu * phys_const->const_proton_mass) +
sigma2);
/* Check the density criterion */ /* Check the density criterion */
return density > density_criterion; return density > density_criterion;
...@@ -91,7 +94,8 @@ INLINE static int star_formation_is_star_forming( ...@@ -91,7 +94,8 @@ INLINE static int star_formation_is_star_forming(
/** /**
* @brief Compute the star-formation rate of a given particle. * @brief Compute the star-formation rate of a given particle.
* *
* Nothing to do here. Everything is done in #star_formation_should_convert_to_star. * Nothing to do here. Everything is done in
* #star_formation_should_convert_to_star.
* *
* @param p #part. * @param p #part.
* @param xp the #xpart. * @param xp the #xpart.
...@@ -123,7 +127,7 @@ INLINE static int star_formation_should_convert_to_star( ...@@ -123,7 +127,7 @@ INLINE static int star_formation_should_convert_to_star(
const struct engine* e, const double dt_star) { const struct engine* e, const double dt_star) {
const struct phys_const* phys_const = e->physical_constants; const struct phys_const* phys_const = e->physical_constants;
const struct cosmology *cosmo = e->cosmology; const struct cosmology* cosmo = e->cosmology;
/* Check that we are running a full time step */ /* Check that we are running a full time step */
if (dt_star == 0.) { if (dt_star == 0.) {
...@@ -135,12 +139,14 @@ INLINE static int star_formation_should_convert_to_star( ...@@ -135,12 +139,14 @@ INLINE static int star_formation_should_convert_to_star(
const float density = hydro_get_physical_density(p, cosmo); const float density = hydro_get_physical_density(p, cosmo);
/* Compute the probability */ /* Compute the probability */
const float inv_free_fall_time = sqrtf(density * 32.f * G * 0.33333333f * M_1_PI); const float inv_free_fall_time =
const float prob = 1.f - exp(-starform->star_formation_efficiency * inv_free_fall_time * dt_star); sqrtf(density * 32.f * G * 0.33333333f * M_1_PI);
const float prob = 1.f - exp(-starform->star_formation_efficiency *
inv_free_fall_time * dt_star);
/* Roll the dice... */ /* Roll the dice... */
const float random_number = const float random_number =
random_unit_interval(p->id, e->ti_current, random_number_star_formation); random_unit_interval(p->id, e->ti_current, random_number_star_formation);
/* Can we form a star? */ /* Can we form a star? */
return random_number < prob; return random_number < prob;
...@@ -203,9 +209,8 @@ INLINE static void star_formation_copy_properties( ...@@ -203,9 +209,8 @@ INLINE static void star_formation_copy_properties(
sp->birth.density = hydro_get_physical_density(p, cosmo); sp->birth.density = hydro_get_physical_density(p, cosmo);
/* Store the birth temperature*/ /* Store the birth temperature*/
sp->birth.temperature = sp->birth.temperature = cooling_get_temperature(phys_const, hydro_props, us,
cooling_get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp);
cosmo, cooling, p, xp);
} }
/** /**
...@@ -227,11 +232,13 @@ INLINE static void starformation_print_backend( ...@@ -227,11 +232,13 @@ INLINE static void starformation_print_backend(
* @param cosmo The current cosmological model. * @param cosmo The current cosmological model.
*/ */
__attribute__((always_inline)) INLINE static void star_formation_end_density( __attribute__((always_inline)) INLINE static void star_formation_end_density(
struct part* restrict p, const struct star_formation* sf, const struct cosmology* cosmo) { struct part* restrict p, const struct star_formation* sf,
const struct cosmology* cosmo) {
// TODO move into pressure floor // TODO move into pressure floor
/* To finish the turbulence estimation we devide by the density */ /* To finish the turbulence estimation we devide by the density */
p->sf_data.sigma2 /= pow_dimension(p->h) * hydro_get_physical_density(p, cosmo); p->sf_data.sigma2 /=
pow_dimension(p->h) * hydro_get_physical_density(p, cosmo);
/* Add the cosmological factor */ /* Add the cosmological factor */
p->sf_data.sigma2 *= cosmo->a * cosmo->a; p->sf_data.sigma2 *= cosmo->a * cosmo->a;
...@@ -285,11 +292,10 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, ...@@ -285,11 +292,10 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo, const struct cosmology* restrict cosmo,
const struct star_formation* data, const struct star_formation* data,
struct part* restrict p, struct part* restrict p,
struct xpart* restrict xp) { struct xpart* restrict xp) {
/* Nothing special here */ /* Nothing special here */
star_formation_init_part(p, xp, data); star_formation_init_part(p, xp, data);
} }
#endif /* SWIFT_GEAR_STAR_FORMATION_H */ #endif /* SWIFT_GEAR_STAR_FORMATION_H */
...@@ -51,11 +51,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( ...@@ -51,11 +51,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation(
kernel_eval(sqrt(r2) / hj, &wj); kernel_eval(sqrt(r2) / hj, &wj);
/* Delta v */ /* Delta v */
float dv[3] = { float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]};
pi->v[0] - pj->v[0],
pi->v[1] - pj->v[1],
pi->v[2] - pj->v[2]
};
/* Norms at power 2 */ /* Norms at power 2 */
const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2];
...@@ -92,11 +88,7 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, ...@@ -92,11 +88,7 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj,
kernel_eval(sqrt(r2) / hi, &wi); kernel_eval(sqrt(r2) / hi, &wi);
/* Delta v */ /* Delta v */
float dv[3] = { float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]};
pi->v[0] - pj->v[0],
pi->v[1] - pj->v[1],
pi->v[2] - pj->v[2]
};
/* Norms at power 2 */ /* Norms at power 2 */
const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2];
......
...@@ -38,11 +38,10 @@ ...@@ -38,11 +38,10 @@
__attribute__((always_inline)) INLINE static int star_formation_write_particles( __attribute__((always_inline)) INLINE static int star_formation_write_particles(
const struct part* parts, const struct xpart* xparts, const struct part* parts, const struct xpart* xparts,
struct io_props* list) { struct io_props* list) {
/* Nothing to write here */ /* Nothing to write here */
return 0; return 0;
} }
/** /**
* @brief initialization of the star formation law * @brief initialization of the star formation law
* *
...@@ -60,20 +59,19 @@ INLINE static void starformation_init_backend( ...@@ -60,20 +59,19 @@ INLINE static void starformation_init_backend(
// TODO move into pressure floor // TODO move into pressure floor
starform->n_jeans_2_3 = starform->n_jeans_2_3 =
parser_get_param_float(parameter_file, "GEARStarFormation:NJeans"); parser_get_param_float(parameter_file, "GEARStarFormation:NJeans");
starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2./3.); starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2. / 3.);
/* Star formation efficiency */ /* Star formation efficiency */
starform->star_formation_efficiency = parser_get_param_double( starform->star_formation_efficiency = parser_get_param_double(
parameter_file, "GEARStarFormation:star_formation_efficiency"); parameter_file, "GEARStarFormation:star_formation_efficiency");
/* Maximum temperature for star formation */ /* Maximum temperature for star formation */
starform->maximal_temperature = starform->maximal_temperature = parser_get_param_double(
parser_get_param_double(parameter_file, parameter_file, "GEARStarFormation:maximal_temperature");
"GEARStarFormation:maximal_temperature");
/* Apply unit change */ /* Apply unit change */
starform->maximal_temperature *= starform->maximal_temperature *=
units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE);
} }
#endif /* SWIFT_STAR_FORMATION_GEAR_IO_H */ #endif /* SWIFT_STAR_FORMATION_GEAR_IO_H */
...@@ -166,8 +166,6 @@ INLINE static void star_formation_logger_log_inactive_part( ...@@ -166,8 +166,6 @@ INLINE static void star_formation_logger_log_inactive_part(
const struct part *p, const struct xpart *xp, const struct part *p, const struct xpart *xp,
struct star_formation_history *sf) {} struct star_formation_history *sf) {}
/** /**
* @brief add a star formation history struct to an other star formation history * @brief add a star formation history struct to an other star formation history
* struct * struct
......
...@@ -32,7 +32,8 @@ struct star_formation_history { ...@@ -32,7 +32,8 @@ struct star_formation_history {
}; };
/** /**
* Structure containing the global star formation information (including time integrated variables). * Structure containing the global star formation information (including time
* integrated variables).
*/ */
struct star_formation_history_accumulator { struct star_formation_history_accumulator {
/*! Total stellar mass from the begining of the simulation */ /*! Total stellar mass from the begining of the simulation */
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
*/ */
struct star_formation_xpart_data {}; struct star_formation_xpart_data {};
struct star_formation_part_data { struct star_formation_part_data {
// TODO move it to the pressure floor // TODO move it to the pressure floor
/*! Estimation of local turbulence (squared) */ /*! Estimation of local turbulence (squared) */
...@@ -38,7 +37,8 @@ struct star_formation_part_data { ...@@ -38,7 +37,8 @@ struct star_formation_part_data {
struct star_formation { struct star_formation {
// TODO move it to pressure floor // TODO move it to pressure floor
/*! Number of particle required to resolved the Jeans criterion (at power 2/3) */ /*! Number of particle required to resolved the Jeans criterion (at power 2/3)
*/
float n_jeans_2_3; float n_jeans_2_3;
/*! Maximal temperature for forming a star */ /*! Maximal temperature for forming a star */
......
...@@ -219,6 +219,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, ...@@ -219,6 +219,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const,
* @param data The global star_formation information. * @param data The global star_formation information.
*/ */
__attribute__((always_inline)) INLINE static void star_formation_init_part( __attribute__((always_inline)) INLINE static void star_formation_init_part(
struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {} struct part* restrict p, struct xpart* restrict xp,
const struct star_formation* data) {}
#endif /* SWIFT_NONE_STAR_FORMATION_H */ #endif /* SWIFT_NONE_STAR_FORMATION_H */
...@@ -59,13 +59,12 @@ INLINE static void star_formation_logger_add( ...@@ -59,13 +59,12 @@ INLINE static void star_formation_logger_add(
struct star_formation_history *sf_update, struct star_formation_history *sf_update,
const struct star_formation_history *sf_add) {} const struct star_formation_history *sf_add) {}
/** /**
* @brief add a star formation history accumulator struct to an other star formation history * @brief add a star formation history accumulator struct to an other star
* struct * formation history struct
* *
* @param sf_add the star formation accumulator struct which we want to add to the star * @param sf_add the star formation accumulator struct which we want to add to
* formation history * the star formation history
* @param sf_update the star formation structure which we want to update * @param sf_update the star formation structure which we want to update
*/ */
INLINE static void star_formation_logger_add_to_accumulator( INLINE static void star_formation_logger_add_to_accumulator(
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
/* Starformation history struct */ /* Starformation history struct */
struct star_formation_history {}; struct star_formation_history {};
/* Starformation history accumulator struct. /* Starformation history accumulator struct.
This structure is only defined in the engine and This structure is only defined in the engine and
allows the user to integrate some quantities over time. allows the user to integrate some quantities over time.
......
...@@ -76,10 +76,11 @@ INLINE static void stars_write_particles(const struct spart *sparts, ...@@ -76,10 +76,11 @@ INLINE static void stars_write_particles(const struct spart *sparts,
sparts, h); sparts, h);
list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts,
birth_time); birth_time);
list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY, sparts, list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY,
birth.density); sparts, birth.density);
list[7] = io_make_output_field("BirthTemperature", FLOAT, 1, UNIT_CONV_TEMPERATURE, sparts, list[7] =
birth.temperature); io_make_output_field("BirthTemperature", FLOAT, 1, UNIT_CONV_TEMPERATURE,
sparts, birth.temperature);
list[8] = io_make_output_field("BirthMass", FLOAT, 1, UNIT_CONV_MASS, sparts, list[8] = io_make_output_field("BirthMass", FLOAT, 1, UNIT_CONV_MASS, sparts,
birth.mass); birth.mass);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment