Commit beaf5c3a authored by Loic Hausammann's avatar Loic Hausammann

Format

parent 41436dcb
......@@ -746,8 +746,8 @@ void cooling_cool_part(const struct phys_const* restrict phys_const,
const float u_old = hydro_get_physical_internal_energy(p, xp, cosmo);
/* Energy after the adiabatic cooling */
float u_ad_before = u_old +
dt_therm * hydro_get_physical_internal_energy_dt(p, cosmo);
float u_ad_before =
u_old + dt_therm * hydro_get_physical_internal_energy_dt(p, cosmo);
/* We now need to check that we are not going to go below any of the limits */
const double u_minimal = hydro_props->minimal_internal_energy;
......@@ -770,7 +770,8 @@ void cooling_cool_part(const struct phys_const* restrict phys_const,
/* Calculate the cooling rate */
float cool_du_dt = (u_new - u_ad_before) / dt_therm;
/* Check that the energy stays above the limits if the time step increase by 2 */
/* Check that the energy stays above the limits if the time step increase by 2
*/
/* Hydro */
double u_ad = u_new + hydro_du_dt * dt_therm;
if (u_ad < u_minimal) {
......@@ -787,11 +788,11 @@ void cooling_cool_part(const struct phys_const* restrict phys_const,
cool_du_dt = (u_new - u_old) / dt_therm;
/* Update the internal energy time derivative */
hydro_set_physical_internal_energy_dt(p, cosmo, cool_du_dt /* + hydro_du_dt */);
hydro_set_physical_internal_energy_dt(p, cosmo,
cool_du_dt /* + hydro_du_dt */);
/* Store the radiated energy */
xp->cooling_data.radiated_energy -=
hydro_get_mass(p) * cool_du_dt * dt_therm;
xp->cooling_data.radiated_energy -= hydro_get_mass(p) * cool_du_dt * dt_therm;
}
/**
......
......@@ -81,7 +81,8 @@ void initial_mass_function_print(const struct initial_mass_function *imf) {
* @param step_size The distance between two points.
*/
void initial_mass_function_integrate(const struct initial_mass_function *imf,
float *data, size_t count, float log_mass_min, float step_size) {
float *data, size_t count,
float log_mass_min, float step_size) {
/* Index in the data */
size_t j = 1;
......@@ -107,7 +108,8 @@ void initial_mass_function_integrate(const struct initial_mass_function *imf,
}
/* Integrate the data */
while ((m < imf->mass_limits[i + 1] || i == imf->n_parts - 1) && j < count) {
while ((m < imf->mass_limits[i + 1] || i == imf->n_parts - 1) &&
j < count) {
/* Compute the masses */
const float log_m1 = log_mass_min + (j - 1) * step_size;
......@@ -126,9 +128,7 @@ void initial_mass_function_integrate(const struct initial_mass_function *imf,
}
/* Compute the integral */
tmp[j] =
tmp[j - 1] +
0.5 * (imf_1 * data[j - 1] + imf_2 * data[j]) * dm;
tmp[j] = tmp[j - 1] + 0.5 * (imf_1 * data[j - 1] + imf_2 * data[j]) * dm;
/* Update j and m */
j += 1;
......
......@@ -27,7 +27,8 @@ float initial_mass_function_get_exponent(
void initial_mass_function_print(const struct initial_mass_function *imf);
void initial_mass_function_integrate(const struct initial_mass_function *imf,
float *data, size_t count, float log_mass_min, float step_size);
float *data, size_t count,
float log_mass_min, float step_size);
float initial_mass_function_get_coefficient(
const struct initial_mass_function *imf, float mass_min, float mass_max);
float initial_mass_function_get_integral_xi(
......
......@@ -161,7 +161,7 @@ __attribute__((always_inline)) static INLINE float interpolate_1d(
case boundary_condition_zero_const:
return 0;
case boundary_condition_const:
return interp->data[0];
return interp->data[0];
default:
error("Interpolation type not implemented");
}
......
......@@ -197,7 +197,6 @@ __attribute__((always_inline)) INLINE static void lifetime_init(
/* Change units from yr into Myr */
const int dim = 3;
lt->constant[dim - 1] -= 6;
}
/**
......
......@@ -94,8 +94,10 @@ int stellar_evolution_compute_integer_number_supernovae(
* (solMass)
* @param m_end_step Mass of a star ending its life at the end of the step
* (solMass)
* @param number_snia_f (Floating) Number of SNIa produced by the stellar particle.
* @param number_snii_f (Floating) Number of SNII produced by the stellar particle.
* @param number_snia_f (Floating) Number of SNIa produced by the stellar
* particle.
* @param number_snii_f (Floating) Number of SNII produced by the stellar
* particle.
*
*/
void stellar_evolution_compute_continuous_feedback_properties(
......@@ -107,15 +109,16 @@ void stellar_evolution_compute_continuous_feedback_properties(
/* Compute the mass ejected */
/* SNIa */
const float mass_snia =
supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia_f;
supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia_f;
/* SNII */
const float mass_frac_snii = supernovae_ii_get_ejected_mass_fraction_processed_from_integral(
const float mass_frac_snii =
supernovae_ii_get_ejected_mass_fraction_processed_from_integral(
&sm->snii, log_m_end_step, log_m_beg_step);
/* Sum the contributions from SNIa and SNII */
sp->feedback_data.mass_ejected = mass_frac_snii * sp->sf_data.birth_mass
+ mass_snia * phys_const->const_solar_mass;
sp->feedback_data.mass_ejected = mass_frac_snii * sp->sf_data.birth_mass +
mass_snia * phys_const->const_solar_mass;
if (sp->mass <= sp->feedback_data.mass_ejected) {
error("Stars cannot have negative mass. (%g <= %g). Initial mass = %g",
......@@ -132,21 +135,22 @@ void stellar_evolution_compute_continuous_feedback_properties(
/* Compute the SNII yields */
float snii_yields[GEAR_CHEMISTRY_ELEMENT_COUNT];
supernovae_ii_get_yields_from_integral(&sm->snii, log_m_end_step, log_m_beg_step,
snii_yields);
supernovae_ii_get_yields_from_integral(&sm->snii, log_m_end_step,
log_m_beg_step, snii_yields);
/* Compute the mass fraction of non processed elements */
const float non_processed = supernovae_ii_get_ejected_mass_fraction_non_processed_from_integral(
&sm->snii, log_m_end_step, log_m_beg_step);
const float non_processed =
supernovae_ii_get_ejected_mass_fraction_non_processed_from_integral(
&sm->snii, log_m_end_step, log_m_beg_step);
/* Set the yields */
for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
/* Compute the mass fraction of metals */
sp->feedback_data.metal_mass_ejected[i] =
/* Supernovae II yields */
snii_yields[i] +
/* Gas contained in stars initial metallicity */
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Supernovae II yields */
snii_yields[i] +
/* Gas contained in stars initial metallicity */
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */
sp->feedback_data.metal_mass_ejected[i] *= sp->sf_data.birth_mass;
......@@ -155,8 +159,7 @@ void stellar_evolution_compute_continuous_feedback_properties(
/* Add the Supernovae Ia */
sp->feedback_data.metal_mass_ejected[i] +=
snia_yields[i] * number_snia_f * phys_const->const_solar_mass;
snia_yields[i] * number_snia_f * phys_const->const_solar_mass;
}
}
......@@ -186,19 +189,21 @@ void stellar_evolution_compute_discrete_feedback_properties(
const float m_init, const int number_snia, const int number_snii) {
/* Compute the average mass */
const float m_avg = initial_mass_function_get_integral_imf(&sm->imf, m_end_step, m_beg_step) /
initial_mass_function_get_integral_xi(&sm->imf, m_end_step, m_beg_step);
const float m_avg =
initial_mass_function_get_integral_imf(&sm->imf, m_end_step, m_beg_step) /
initial_mass_function_get_integral_xi(&sm->imf, m_end_step, m_beg_step);
const float log_m_avg = log10(m_avg);
/* Compute the mass ejected */
/* SNIa */
const float mass_snia =
supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia;
supernovae_ia_get_ejected_mass_processed(&sm->snia) * number_snia;
/* SNII */
const float mass_snii =
supernovae_ii_get_ejected_mass_fraction_processed_from_raw(
&sm->snii, log_m_avg) * m_avg * number_snii;
supernovae_ii_get_ejected_mass_fraction_processed_from_raw(&sm->snii,
log_m_avg) *
m_avg * number_snii;
sp->feedback_data.mass_ejected = mass_snia + mass_snii;
......@@ -222,24 +227,23 @@ void stellar_evolution_compute_discrete_feedback_properties(
/* Compute the mass fraction of non processed elements */
const float non_processed =
supernovae_ii_get_ejected_mass_fraction_non_processed_from_raw(
&sm->snii, log_m_avg);
supernovae_ii_get_ejected_mass_fraction_non_processed_from_raw(&sm->snii,
log_m_avg);
/* Set the yields */
for (int i = 0; i < GEAR_CHEMISTRY_ELEMENT_COUNT; i++) {
/* Compute the mass fraction of metals */
sp->feedback_data.metal_mass_ejected[i] =
/* Supernovae II yields */
snii_yields[i] +
/* Gas contained in stars initial metallicity */
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Supernovae II yields */
snii_yields[i] +
/* Gas contained in stars initial metallicity */
chemistry_get_metal_mass_fraction_for_feedback(sp)[i] * non_processed;
/* Convert it to total mass */
sp->feedback_data.metal_mass_ejected[i] *= m_avg * number_snii;
/* Supernovae Ia yields */
sp->feedback_data.metal_mass_ejected[i] +=
snia_yields[i] * number_snia;
sp->feedback_data.metal_mass_ejected[i] += snia_yields[i] * number_snia;
/* Convert everything in code units */
sp->feedback_data.metal_mass_ejected[i] *= phys_const->const_solar_mass;
......@@ -306,12 +310,18 @@ void stellar_evolution_evolve_spart(
const float m_init = sp->sf_data.birth_mass / phys_const->const_solar_mass;
/* Compute number of SNIa */
const float number_snia_f = can_produce_snia ?
supernovae_ia_get_number_per_unit_mass(&sm->snia, m_end_step, m_beg_step) * m_init : 0;
const float number_snia_f = can_produce_snia
? supernovae_ia_get_number_per_unit_mass(
&sm->snia, m_end_step, m_beg_step) *
m_init
: 0;
/* Compute number of SNII */
const float number_snii_f = can_produce_snii ?
supernovae_ii_get_number_per_unit_mass(&sm->snii, m_end_step, m_beg_step) * m_init : 0;
const float number_snii_f = can_produce_snii
? supernovae_ii_get_number_per_unit_mass(
&sm->snii, m_end_step, m_beg_step) *
m_init
: 0;
/* Does this star produce a supernovae? */
if (number_snia_f == 0 && number_snii_f == 0) return;
......@@ -320,11 +330,11 @@ void stellar_evolution_evolve_spart(
if (sm->discrete_yields) {
/* Get the integer number of supernovae */
const int number_snia = stellar_evolution_compute_integer_number_supernovae(
sp, number_snia_f, ti_begin, random_number_stellar_feedback_1);
sp, number_snia_f, ti_begin, random_number_stellar_feedback_1);
/* Get the integer number of supernovae */
const int number_snii = stellar_evolution_compute_integer_number_supernovae(
sp, number_snii_f, ti_begin, random_number_stellar_feedback_2);
sp, number_snii_f, ti_begin, random_number_stellar_feedback_2);
/* Do we have a supernovae? */
if (number_snia == 0 && number_snii == 0) return;
......
......@@ -121,20 +121,23 @@ struct supernovae_ii {
/*! Total mass fraction ejected. */
struct interpolation_1d ejected_mass_processed;
/*! Mass fraction ejected and not processed (=> with the star metallicity). */
/*! Mass fraction ejected and not processed (=> with the star metallicity).
*/
struct interpolation_1d ejected_mass_non_processed;
} raw;
/*! Yields integrated */
struct {
/*! Integrated (over the IMF) mass fraction of metals ejected by a supernovae
/*! Integrated (over the IMF) mass fraction of metals ejected by a
* supernovae
*/
struct interpolation_1d yields[GEAR_CHEMISTRY_ELEMENT_COUNT];
/*! Total mass fraction ejected (integrated over the IMF) */
struct interpolation_1d ejected_mass_processed;
/*! Mass fraction ejected and not processed (=> with the star metallicity) */
/*! Mass fraction ejected and not processed (=> with the star metallicity)
*/
struct interpolation_1d ejected_mass_non_processed;
} integrated;
......
......@@ -123,8 +123,8 @@ float supernovae_ia_get_companion_fraction(const struct supernovae_ia *snia,
*
* @return The number of supernovae Ia per unit of mass.
*/
float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia, float m1,
float m2) {
float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia,
float m1, float m2) {
#ifdef SWIFT_DEBUG_CHECKS
if (m1 > m2) error("Mass 1 larger than mass 2 %g > %g.", m1, m2);
......@@ -222,7 +222,7 @@ void supernovae_ia_init_companion(struct supernovae_ia *snia) {
/* Get the exponent for the integral */
const float exp = snia->companion_exponent;
for (int i = 0; i < GEAR_NUMBER_TYPE_OF_COMPANION; i++) {
/* Compute the integral */
......@@ -231,7 +231,7 @@ void supernovae_ia_init_companion(struct supernovae_ia *snia) {
integral /= exp + 1.;
/* Update the coefficient for a normalization to 1 of the IMF */
snia->companion[i].coef /= exp * integral;
snia->companion[i].coef /= exp * integral;
}
}
......
......@@ -32,8 +32,8 @@ float supernovae_ia_get_ejected_mass_processed(
float supernovae_ia_get_companion_fraction(const struct supernovae_ia *snia,
float m1, float m2,
int companion_type);
float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia, float m1,
float m2);
float supernovae_ia_get_number_per_unit_mass(const struct supernovae_ia *snia,
float m1, float m2);
void supernovae_ia_read_yields(struct supernovae_ia *snia,
struct swift_params *params,
......
This diff is collapsed.
......@@ -31,16 +31,17 @@
void supernovae_ii_print(const struct supernovae_ii *snii);
int supernovae_ii_can_explode(const struct supernovae_ii *snii, float m_low,
float m_high);
float supernovae_ii_get_number_per_unit_mass(const struct supernovae_ii *snii, float m1,
float m2);
void supernovae_ii_get_yields_from_integral(const struct supernovae_ii *snii, float log_m1,
float log_m2, float *yields);
void supernovae_ii_get_yields_from_raw(const struct supernovae_ii *snii, float log_m,
float *yields);
float supernovae_ii_get_ejected_mass_fraction_non_processed_from_integral(const struct supernovae_ii *snii,
float log_m1, float log_m2);
float supernovae_ii_get_ejected_mass_fraction_non_processed_from_raw(const struct supernovae_ii *snii,
float log_m);
float supernovae_ii_get_number_per_unit_mass(const struct supernovae_ii *snii,
float m1, float m2);
void supernovae_ii_get_yields_from_integral(const struct supernovae_ii *snii,
float log_m1, float log_m2,
float *yields);
void supernovae_ii_get_yields_from_raw(const struct supernovae_ii *snii,
float log_m, float *yields);
float supernovae_ii_get_ejected_mass_fraction_non_processed_from_integral(
const struct supernovae_ii *snii, float log_m1, float log_m2);
float supernovae_ii_get_ejected_mass_fraction_non_processed_from_raw(
const struct supernovae_ii *snii, float log_m);
float supernovae_ii_get_ejected_mass_fraction_processed_from_integral(
const struct supernovae_ii *snii, float log_m1, float log_m2);
......@@ -48,9 +49,9 @@ float supernovae_ii_get_ejected_mass_fraction_processed_from_raw(
const struct supernovae_ii *snii, float log_m);
void supernovae_ii_read_yields_array(
struct supernovae_ii *snii, struct interpolation_1d *interp_raw,
struct interpolation_1d *interp_int,
const struct phys_const *phys_const, const struct stellar_model *sm,
hid_t group_id, const char *hdf5_dataset_name, hsize_t *previous_count,
struct interpolation_1d *interp_int, const struct phys_const *phys_const,
const struct stellar_model *sm, hid_t group_id,
const char *hdf5_dataset_name, hsize_t *previous_count,
int interpolation_size);
void supernovae_ii_read_yields(struct supernovae_ii *snii,
struct swift_params *params,
......
......@@ -76,7 +76,7 @@ pressure_floor_get_physical_pressure(const struct part* p,
/* Compute the pressure floor */
float floor = H_phys * H_phys * rho * pressure_floor_props.constants -
p->pressure_floor_data.sigma2;
p->pressure_floor_data.sigma2;
floor *= rho * hydro_one_over_gamma;
return fmaxf(pressure_physical, floor);
......
......@@ -86,9 +86,9 @@ INLINE static int star_formation_is_star_forming(
/* Compute the density criterion */
const float coef =
M_PI_4 / (phys_const->const_newton_G * n_jeans_2_3 * h * h);
const float density_criterion =
coef * hydro_gamma * phys_const->const_boltzmann_k * temperature /
(mu * phys_const->const_proton_mass);
const float density_criterion = coef * hydro_gamma *
phys_const->const_boltzmann_k * temperature /
(mu * phys_const->const_proton_mass);
/* Check the density criterion */
return density > density_criterion;
......
......@@ -47,9 +47,8 @@ INLINE static void stars_read_particles(struct spart *sparts,
UNIT_CONV_NO_UNITS, sparts, id);
list[4] = io_make_input_field("SmoothingLength", FLOAT, 1, OPTIONAL,
UNIT_CONV_LENGTH, sparts, h);
list[5] = io_make_input_field("BirthMass", FLOAT, 1, OPTIONAL,
UNIT_CONV_MASS, sparts, sf_data.birth_mass);
list[5] = io_make_input_field("BirthMass", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS,
sparts, sf_data.birth_mass);
list[6] = io_make_input_field("BirthTime", FLOAT, 1, OPTIONAL, UNIT_CONV_MASS,
sparts, birth_time);
......
Markdown is supported
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