Commit 691a2037 authored by Loic Hausammann's avatar Loic Hausammann Committed by Matthieu Schaller
Browse files

SF split: update s->mass_*_min and small fixes

parent e13260c8
......@@ -5036,6 +5036,12 @@ void engine_recompute_displacement_constraint(struct engine *e) {
float min_mass[swift_type_count] = {
e->s->min_part_mass, e->s->min_gpart_mass, FLT_MAX, FLT_MAX,
e->s->min_spart_mass, e->s->min_bpart_mass};
#ifdef WITH_MPI
MPI_Allreduce(MPI_IN_PLACE, min_mass, swift_type_count, MPI_FLOAT, MPI_MIN,
MPI_COMM_WORLD);
#endif
#ifdef SWIFT_DEBUG_CHECKS
/* Check that the minimal mass collection worked */
float min_part_mass_check = FLT_MAX;
......@@ -5044,15 +5050,10 @@ void engine_recompute_displacement_constraint(struct engine *e) {
min_part_mass_check =
min(min_part_mass_check, hydro_get_mass(&e->s->parts[i]));
}
if (min_part_mass_check != min_mass[swift_type_gas])
if (min_part_mass_check < min_mass[swift_type_gas])
error("Error collecting minimal mass of gas particles.");
#endif
#ifdef WITH_MPI
MPI_Allreduce(MPI_IN_PLACE, min_mass, swift_type_count, MPI_FLOAT, MPI_MIN,
MPI_COMM_WORLD);
#endif
/* Do the same for the velocity norm sum */
float vel_norm[swift_type_count] = {
e->s->sum_part_vel_norm, e->s->sum_gpart_vel_norm, 0.f, 0.f,
......
......@@ -336,6 +336,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
if (swift_star_formation_model_creates_stars) {
/* Check if we should create a new particle or transform one */
if (spawn_spart) {
/* Spawn a new spart (+ gpart) */
sp = cell_spawn_new_spart_from_part(e, c, p, xp);
} else {
/* Convert the gas particle to a star particle */
......@@ -354,7 +355,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
/* Copy the properties of the gas particle to the star particle */
star_formation_copy_properties(
p, xp, sp, e, sf_props, cosmo, with_cosmology, phys_const,
hydro_props, us, cooling, spawn_spart);
hydro_props, us, cooling, !spawn_spart);
/* Update the Star formation history */
star_formation_logger_log_new_spart(sp, &c->stars.sfh);
......
......@@ -387,5 +387,4 @@ void space_struct_restore(struct space *s, FILE *stream);
void space_write_cell_hierarchy(const struct space *s, int j);
void space_compute_star_formation_stats(const struct space *s,
struct star_formation *star_form);
#endif /* SWIFT_SPACE_H */
......@@ -235,17 +235,16 @@ INLINE static void star_formation_copy_properties(
/* Store the current mass */
const float mass_gas = hydro_get_mass(p);
if (!convert_part) {
const float mass_star = starform->mass_stars;
const float new_mass_gas = mass_gas - mass_star;
/* Update the spart */
const float min_mass =
starform->mass_stars * starform->min_mass_frac_plus_one;
const float mass_star =
mass_gas > min_mass ? starform->mass_stars : mass_gas;
sp->mass = mass_star;
sp->gpart->mass = mass_star;
/* Update the part */
hydro_set_mass(p, mass_gas - mass_star);
p->gpart->mass = mass_gas - mass_star;
hydro_set_mass(p, new_mass_gas);
p->gpart->mass = new_mass_gas;
} else {
sp->mass = mass_gas;
}
......@@ -408,10 +407,11 @@ star_formation_first_init_stats(struct star_formation* star_form,
MPI_COMM_WORLD);
#endif
star_form->mass_stars = avg_mass / e->total_nr_parts;
star_form->mass_stars =
avg_mass / (e->total_nr_parts * star_form->n_stars_per_part);
if (e->nodeID == 0) {
message("Average hydro mass: %g", star_form->mass_stars);
message("Mass new stars: %g", star_form->mass_stars);
}
}
......
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