diff --git a/src/engine.c b/src/engine.c index f4df8132e01e25f4b369fab7a4fbaf1009995cf0..4f1f368566a229dba7f269e6491281159d73e80e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -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, diff --git a/src/runner_others.c b/src/runner_others.c index 6e4f353e4e6771c01c6495a040bf638c679eb8d3..9a7978daeae80e57ec48af0c57f96d3feafe2382 100644 --- a/src/runner_others.c +++ b/src/runner_others.c @@ -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); diff --git a/src/space.h b/src/space.h index e98b1b1a0e91fc5decf18485fec192a18b2313eb..acb55bd26128364c69f56dc557a5877115e30804 100644 --- a/src/space.h +++ b/src/space.h @@ -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 */ diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index 27980271b39c137dfa85b2a6a5e3b81f2f1b5a6f..e5f550036aa362efde2cfc3e1bfa6afd6ac24b68 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.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); } }