From c797081cf88165e636604d9c26879de312509463 Mon Sep 17 00:00:00 2001 From: Fabien Jeanquartier Date: Wed, 12 Jun 2019 14:41:42 +0200 Subject: [PATCH 01/16] Apply patch from github merge request #13 --- src/cell.c | 2 +- src/runner.c | 18 +- src/runner_doiact.h | 232 +++++++++++++---- src/space.c | 2 +- src/star_formation/GEAR/star_formation.h | 243 +++++++++++++++--- src/star_formation/GEAR/star_formation_iact.h | 37 ++- src/star_formation/GEAR/star_formation_io.h | 2 +- .../GEAR/star_formation_logger.h | 127 +++++++-- .../GEAR/star_formation_logger_struct.h | 19 +- .../GEAR/star_formation_struct.h | 24 +- src/stars/GEAR/stars.h | 173 +++++++++++++ src/stars/GEAR/stars_debug.h | 32 +++ src/stars/GEAR/stars_iact.h | 95 +++++++ src/stars/GEAR/stars_io.h | 215 ++++++++++++++++ src/stars/GEAR/stars_part.h | 151 +++++++++++ src/tools.c | 20 +- 16 files changed, 1255 insertions(+), 137 deletions(-) create mode 100644 src/stars/GEAR/stars.h create mode 100644 src/stars/GEAR/stars_debug.h create mode 100644 src/stars/GEAR/stars_iact.h create mode 100644 src/stars/GEAR/stars_io.h create mode 100644 src/stars/GEAR/stars_part.h diff --git a/src/cell.c b/src/cell.c index f4903f024..0649d31b3 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4413,7 +4413,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { if (part_is_active(p, e)) { hydro_init_part(p, &e->s->hs); chemistry_init_part(p, e->chemistry); - star_formation_init_part(p, e->star_formation); + star_formation_init_part(p, xp, e->star_formation); tracers_after_init(p, xp, e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); diff --git a/src/runner.c b/src/runner.c index 7320fd874..0977d9e2e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1185,7 +1185,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { hydro_props, us, cooling); /* Update the Star formation history */ - star_formation_logger_log_new_spart(sp, &c->stars.sfh); + star_formation_logger_log_new_spart(sp, &c->stars.sfh,e->time_step); } } @@ -2125,7 +2125,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Finish the density calculation */ hydro_end_density(p, cosmo); chemistry_end_density(p, chemistry, cosmo); - star_formation_end_density(p, star_formation, cosmo); + star_formation_end_density(p, xp, star_formation, cosmo); /* Compute one step of the Newton-Raphson scheme */ const float n_sum = p->density.wcount * h_old_dim; @@ -2272,7 +2272,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Re-initialise everything */ hydro_init_part(p, hs); chemistry_init_part(p, chemistry); - star_formation_init_part(p, star_formation); + star_formation_init_part(p, xp, star_formation); tracers_after_init(p, xp, e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); @@ -2379,23 +2379,23 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Self-interaction? */ if (l->t->type == task_type_self) - runner_doself_subset_branch_density(r, finger, parts, pid, count); + runner_doself_subset_branch_density(r, finger, parts, xparts, pid, count); /* Otherwise, pair interaction? */ else if (l->t->type == task_type_pair) { /* Left or right? */ if (l->t->ci == finger) - runner_dopair_subset_branch_density(r, finger, parts, pid, + runner_dopair_subset_branch_density(r, finger, parts, xparts, pid, count, l->t->cj); else - runner_dopair_subset_branch_density(r, finger, parts, pid, + runner_dopair_subset_branch_density(r, finger, parts, xparts, pid, count, l->t->ci); } /* Otherwise, sub-self interaction? */ else if (l->t->type == task_type_sub_self) - runner_dosub_subset_density(r, finger, parts, pid, count, NULL, + runner_dosub_subset_density(r, finger, parts, xparts, pid, count, NULL, 1); /* Otherwise, sub-pair interaction? */ @@ -2403,10 +2403,10 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Left or right? */ if (l->t->ci == finger) - runner_dosub_subset_density(r, finger, parts, pid, count, + runner_dosub_subset_density(r, finger, parts, xparts, pid, count, l->t->cj, 1); else - runner_dosub_subset_density(r, finger, parts, pid, count, + runner_dosub_subset_density(r, finger, parts, xparts, pid, count, l->t->ci, 1); } } diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 6caa287cf..0505efbf8 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -148,7 +148,13 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_i = ci->hydro.xparts; +#endif struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif /* Cosmological terms */ const float a = cosmo->a; @@ -167,7 +173,10 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, for (int pid = 0; pid < count_i; pid++) { /* Get a hold of the ith part in ci. */ - struct part *restrict pi = &parts_i[pid]; +struct part *restrict pi = &parts_i[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts_i[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -184,6 +193,9 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -213,7 +225,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } if (r2 < hjg2 && pj_active) { @@ -225,7 +237,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } @@ -258,7 +270,13 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_i = ci->hydro.xparts; +#endif struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif /* Cosmological terms */ const float a = cosmo->a; @@ -277,7 +295,10 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, for (int pid = 0; pid < count_i; pid++) { /* Get a hold of the ith part in ci. */ - struct part *restrict pi = &parts_i[pid]; +struct part *restrict pi = &parts_i[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts_i[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -294,6 +315,9 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -325,14 +349,14 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (pi_active) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (pj_active) { @@ -343,7 +367,7 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } @@ -377,12 +401,18 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts = c->hydro.xparts; +#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -399,6 +429,9 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -431,14 +464,14 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doj) { @@ -449,7 +482,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over the parts in cj. */ @@ -482,12 +515,18 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts = c->hydro.xparts; +#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -504,6 +543,9 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -536,14 +578,14 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doj) { @@ -554,7 +596,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over the parts in cj. */ @@ -578,7 +620,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, int *restrict ind, + struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, int count, struct cell *restrict cj, const double *shift) { @@ -589,6 +631,9 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif /* Cosmological terms */ const float a = cosmo->a; @@ -599,6 +644,9 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpi = &xparts_i[ind[pid]]; +#endif double pix[3]; for (int k = 0; k < 3; k++) pix[k] = pi->x[k] - shift[k]; const float hi = pi->h; @@ -614,6 +662,9 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -640,7 +691,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, pj->h, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the parts in cj. */ @@ -664,7 +715,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, int *restrict ind, int count, + struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, int count, struct cell *restrict cj, const int sid, const int flipped, const double *shift) { @@ -675,6 +726,9 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif /* Cosmological terms */ const float a = cosmo->a; @@ -692,6 +746,9 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpi = &xparts_i[ind[pid]]; +#endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); const double piz = pi->x[2] - (shift[2]); @@ -705,6 +762,9 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -733,7 +793,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the parts in cj. */ @@ -748,6 +808,9 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpi = &xparts_i[ind[pid]]; +#endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); const double piz = pi->x[2] - (shift[2]); @@ -761,6 +824,9 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -789,7 +855,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the parts in cj. */ @@ -812,7 +878,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, * @param cj The second #cell. */ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, int *restrict ind, + struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, int count, struct cell *restrict cj) { const struct engine *e = r->e; @@ -848,15 +914,15 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, #endif #if defined(SWIFT_USE_NAIVE_INTERACTIONS) - DOPAIR_SUBSET_NAIVE(r, ci, parts_i, ind, count, cj, shift); + DOPAIR_SUBSET_NAIVE(r, ci, parts_i, xparts_i, ind, count, cj, shift); #elif defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) if (sort_is_face(sid)) runner_dopair_subset_density_vec(r, ci, parts_i, ind, count, cj, sid, flipped, shift); else - DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); + DOPAIR_SUBSET(r, ci, parts_i, xparts_i,ind, count, cj, sid, flipped, shift); #else - DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); + DOPAIR_SUBSET(r, ci, parts_i, xparts_i, ind, count, cj, sid, flipped, shift); #endif } @@ -871,7 +937,7 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, int *restrict ind, int count) { + struct part *restrict parts, struct xpart *restrict xparts, int *restrict ind, int count) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -884,12 +950,17 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; struct part *restrict parts_j = ci->hydro.parts; - + #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = ci->hydro.xparts; + #endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *pi = &parts[ind[pid]]; + #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts[ind[pid]]; + #endif const float pix[3] = {(float)(pi->x[0] - ci->loc[0]), (float)(pi->x[1] - ci->loc[1]), (float)(pi->x[2] - ci->loc[2])}; @@ -905,6 +976,9 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -932,7 +1006,7 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the parts in cj. */ @@ -952,13 +1026,13 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, int *restrict ind, + struct part *restrict parts, struct xpart *restrict xparts, int *restrict ind, int count) { #if defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) runner_doself_subset_density_vec(r, ci, parts, ind, count); #else - DOSELF_SUBSET(r, ci, parts, ind, count); + DOSELF_SUBSET(r, ci, parts, xparts, ind, count); #endif } @@ -1006,7 +1080,13 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_i = ci->hydro.xparts; +#endif struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif const double di_max = sort_i[count_i - 1].d - rshift; const double dj_min = sort_j[0].d; const float dx_max = (ci->hydro.dx_max_sort + cj->hydro.dx_max_sort); @@ -1023,6 +1103,9 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[sort_i[pid].i]; + #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xpi = &xparts_i[sort_i[pid].i]; +#endif const float hi = pi->h; /* Skip inactive particles */ @@ -1043,6 +1126,9 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1096,7 +1182,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the parts in cj. */ @@ -1111,6 +1197,9 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; +#endif const float hj = pj->h; /* Skip inactive particles */ @@ -1131,6 +1220,9 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts_i[sort_i[pid].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1184,7 +1276,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over the parts in ci. */ @@ -1331,7 +1423,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_i = ci->hydro.xparts; +#endif struct part *restrict parts_j = cj->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts_j = cj->hydro.xparts; +#endif /* Cosmological terms */ const float a = cosmo->a; @@ -1398,6 +1496,9 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *pi = &parts_i[sort_i[pid].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts_i[sort_i[pid].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1484,7 +1585,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over the active parts in cj. */ @@ -1497,6 +1598,9 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1555,13 +1659,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } @@ -1578,6 +1682,9 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1664,7 +1771,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } /* loop over the active parts in ci. */ @@ -1678,6 +1785,9 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts_i[sort_i[pid].i]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1737,13 +1847,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } else { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } @@ -1867,6 +1977,9 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { TIMER_TIC; struct part *restrict parts = c->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts = c->hydro.xparts; +#endif const int count = c->hydro.count; /* Set up indt. */ @@ -1890,6 +2003,9 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1908,6 +2024,9 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; + #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[indt[pjd]]; +#endif const float hj = pj->h; #ifdef SWIFT_DEBUG_CHECKS @@ -1932,7 +2051,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over all other particles. */ @@ -1949,6 +2068,9 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1984,14 +2106,14 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else if (doj) { @@ -2001,7 +2123,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } @@ -2063,6 +2185,9 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { TIMER_TIC; struct part *restrict parts = c->hydro.parts; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *restrict xparts = c->hydro.xparts; +#endif const int count = c->hydro.count; /* Set up indt. */ @@ -2086,6 +2211,9 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpi = &xparts[pid]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -2104,6 +2232,9 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; + #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[indt[pjd]]; +#endif const float hj = pj->h; /* Compute the pairwise distance. */ @@ -2128,7 +2259,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); #endif } } /* loop over all other particles. */ @@ -2145,6 +2276,9 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[pjd]; +#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -2175,13 +2309,13 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); #endif } } @@ -2438,7 +2572,7 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) { } void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, - int *ind, int count, struct cell *cj, int gettimer) { + struct xpart *xparts, int *ind, int count, struct cell *cj, int gettimer) { const struct engine *e = r->e; struct space *s = e->s; @@ -2473,16 +2607,16 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, if (cell_can_recurse_in_self_hydro_task(ci)) { /* Loop over all progeny. */ - DOSUB_SUBSET(r, sub, parts, ind, count, NULL, 0); + DOSUB_SUBSET(r, sub, parts, xparts, ind, count, NULL, 0); for (int j = 0; j < 8; j++) if (ci->progeny[j] != sub && ci->progeny[j] != NULL) - DOSUB_SUBSET(r, sub, parts, ind, count, ci->progeny[j], 0); + DOSUB_SUBSET(r, sub, parts, xparts, ind, count, ci->progeny[j], 0); } /* Otherwise, compute self-interaction. */ else - DOSELF_SUBSET_BRANCH(r, ci, parts, ind, count); + DOSELF_SUBSET_BRANCH(r, ci, parts, xparts, ind, count); } /* self-interaction. */ /* Otherwise, it's a pair interaction. */ @@ -2501,10 +2635,10 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, const int pid = csp->pairs[k].pid; const int pjd = csp->pairs[k].pjd; if (ci->progeny[pid] == sub && cj->progeny[pjd] != NULL) - DOSUB_SUBSET(r, ci->progeny[pid], parts, ind, count, cj->progeny[pjd], + DOSUB_SUBSET(r, ci->progeny[pid], parts, xparts, ind, count, cj->progeny[pjd], 0); if (ci->progeny[pid] != NULL && cj->progeny[pjd] == sub) - DOSUB_SUBSET(r, cj->progeny[pjd], parts, ind, count, ci->progeny[pid], + DOSUB_SUBSET(r, cj->progeny[pjd], parts, xparts, ind, count, ci->progeny[pid], 0); } } @@ -2515,7 +2649,7 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, /* Do any of the cells need to be drifted first? */ if (!cell_are_part_drifted(cj, e)) error("Cell should be drifted!"); - DOPAIR_SUBSET_BRANCH(r, ci, parts, ind, count, cj); + DOPAIR_SUBSET_BRANCH(r, ci, parts, xparts, ind, count, cj); } } /* otherwise, pair interaction. */ diff --git a/src/space.c b/src/space.c index 49c714743..250af5efa 100644 --- a/src/space.c +++ b/src/space.c @@ -4365,7 +4365,7 @@ void space_init_parts_mapper(void *restrict map_data, int count, for (int k = 0; k < count; k++) { hydro_init_part(&parts[k], hs); chemistry_init_part(&parts[k], e->chemistry); - star_formation_init_part(&parts[k], e->star_formation); + star_formation_init_part(&parts[k], &xparts[k], e->star_formation); tracers_after_init(&parts[k], &xparts[k], e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index c479feb5c..3215b0aea 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -28,13 +28,58 @@ #include "part.h" #include "physical_constants.h" #include "units.h" +#include "star_formation_struct.h" +#include "random.h" +#include "cooling.h" +#include "engine.h" + +/** + * @brief Compute the temperature of a #part based on the cooling function. + * + * @param phys_const #phys_const data structure. + * @param hydro_props The properties of the hydro scheme. + * @param us The internal system of units. + * @param cosmo #cosmology data structure. + * @param cooling #cooling_function_data struct. + * @param p #part data. + * @param xp Pointer to the #xpart data. + */ +INLINE static float get_temperature( + const struct phys_const* restrict phys_const, + const struct hydro_props* restrict hydro_props, + const struct unit_system* restrict us, + const struct cosmology* restrict cosmo, + const struct cooling_function_data* restrict cooling, + const struct part* restrict p, const struct xpart* restrict xp) { + + /* Physical constants */ + const double m_H = phys_const->const_proton_mass; + const double k_B = phys_const->const_boltzmann_k; + + /* Gas properties */ + const double T_transition = hydro_props->hydrogen_ionization_temperature; + const double mu_neutral = hydro_props->mu_neutral; + const double mu_ionised = hydro_props->mu_ionised; + + /* Particle temperature */ + const double u = hydro_get_physical_internal_energy(p, xp, cosmo); + + /* Temperature over mean molecular weight */ + const double T_over_mu = hydro_gamma_minus_one * u * m_H / k_B; + + /* Are we above or below the HII -> HI transition? */ + if (T_over_mu > (T_transition + 1.) / mu_ionised) + return T_over_mu * mu_ionised; + else if (T_over_mu < (T_transition - 1.) / mu_neutral) + return T_over_mu * mu_neutral; + else + return T_transition; +} /** * @brief Calculate if the gas has the potential of becoming * a star. * - * No star formation should occur, so return 0. - * * @param starform the star formation law properties to use. * @param p the gas particles. * @param xp the additional properties of the gas particles. @@ -45,24 +90,63 @@ * @param cooling The cooling data struct. * */ -INLINE static int star_formation_is_star_forming( - const struct part* restrict p, const struct xpart* restrict xp, +INLINE static int star_formation_is_star_forming( + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* starform, const struct phys_const* phys_const, const struct cosmology* cosmo, const struct hydro_props* restrict hydro_props, const struct unit_system* restrict us, const struct cooling_function_data* restrict cooling, - const struct entropy_floor_properties* restrict entropy_floor) { - - return 0; + const struct entropy_floor_properties* restrict entropy_floor) + { + /* Some useful constants */ + const double G = phys_const->const_newton_G; + const double kb = phys_const->const_boltzmann_k; + const double mH = phys_const->const_proton_mass; + /* We first check if we are supposed to include turbulence estimation + * otherewise we keep 0 */ + float sigma2=0.f; + if(starform->with_sigma>0) + { + sigma2=xp->sf_data.sigma2; + } + /* Compute the temperature */ + double const T=get_temperature(phys_const,hydro_props,us,cosmo,cooling,p,xp); + /* Other useful values */ + const int N=starform->Njeans; + const double h=p->h; + /* We suppose that the gas is neutral */ + const double mu=hydro_props->mu_neutral; + /* Maximum temperature allowed (temperature criterion) */ + const double T0=starform->Max_temperature; + /* Compute density */ + const double physical_density = hydro_get_physical_density(p, cosmo); + /* We compute the minimal density for star formation (see Revaz & Jablonka, 2018 eq (3)) */ + const double rho_sfr=M_PI*(hydro_gamma*kb*T/mu/mH+sigma2)/h/h/4./G/pow(N,2./3.); + /* Temperature criterion for star formation eligibility */ + if(T>T0) + { + return 0; + } + /* Density criterion */ + else + { + if(physical_density>rho_sfr) + { + /* The particle is eligible (satisfy both conditions) */ + return 1; + } + else + { + return 0; + } + } } /** * @brief Compute the star-formation rate of a given particle and store * it into the #xpart. * - * Nothing to do here. - * * @param p #part. * @param xp the #xpart. * @param starform the star formation law properties to use @@ -71,36 +155,65 @@ INLINE static int star_formation_is_star_forming( * @param dt_star The time-step of this particle. */ INLINE static void star_formation_compute_SFR( - const struct part* restrict p, struct xpart* restrict xp, + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* starform, const struct phys_const* phys_const, - const struct cosmology* cosmo, const double dt_star) {} + const struct cosmology* cosmo, const double dt_star) + { + if (dt_star == 0.) { + xp->sf_data.SFR = 0.; + } + else + { + const double G = phys_const->const_newton_G; + const double c_star=starform->star_formation_rate; + const double physical_density = hydro_get_physical_density(p, cosmo); + if(physical_density!=0) + { + /* We compute the star formation rate and store it (see Revaz & Jablonka, 2012, eq. (5)) */ + /* Units are mass/time/distance³ */ + xp->sf_data.SFR=c_star*physical_density*sqrt(physical_density*32.f*G)/sqrt(3*M_PI); + } + else + { + xp->sf_data.SFR=0.; + } + } + return; + } /** * @brief Decides whether a particle should be converted into a * star or not. * - * No SF should occur, so return 0. - * * @param p The #part. * @param xp The #xpart. * @param starform The properties of the star formation model. * @param e The #engine (for random numbers). * @param dt_star The time-step of this particle * @return 1 if a conversion should be done, 0 otherwise. - */ + */ INLINE static int star_formation_should_convert_to_star( - const struct part* p, const struct xpart* xp, + struct part* p, struct xpart* xp, const struct star_formation* starform, const struct engine* e, const double dt_star) { - - return 0; + /* Calculate the propability of forming a star, see Revaz & Jablonka (2012), eq. (4) */ + const double prob = 1.- exp(xp->sf_data.SFR * dt_star * (-1.) / hydro_get_physical_density(p,e->cosmology)); + /* Get a unique random number between 0 and 1 for star formation */ + const double random_number = + random_unit_interval(p->id, e->ti_current, random_number_star_formation); + if(random_number>prob) + { + return 0; + } + else + { + return 1; + } } /** * @brief Update the SF properties of a particle that is not star forming. * - * Nothing to do here. - * * @param p The #part. * @param xp The #xpart. * @param e The #engine. @@ -109,14 +222,24 @@ INLINE static int star_formation_should_convert_to_star( */ INLINE static void star_formation_update_part_not_SFR( struct part* p, struct xpart* xp, const struct engine* e, - const struct star_formation* starform, const int with_cosmology) {} + const struct star_formation* starform, const int with_cosmology) { + /* Check if it is the first time steps after star formation */ + if (xp->sf_data.SFR > 0.) { + + /* Record the current time as an indicator of when this particle was last + star-forming. */ + if (with_cosmology) { + xp->sf_data.SFR = -(e->cosmology->a); + } else { + xp->sf_data.SFR = -(e->time); + } + } +} /** * @brief Copies the properties of the gas particle over to the * star particle. * - * Nothing to do here. - * * @param e The #engine * @param p the gas particles. * @param xp the additional properties of the gas particles. @@ -133,7 +256,29 @@ INLINE static void star_formation_copy_properties( const struct phys_const* phys_const, const struct hydro_props* restrict hydro_props, const struct unit_system* restrict us, - const struct cooling_function_data* restrict cooling) {} + const struct cooling_function_data* restrict cooling) { + + /* Store the current mass */ + sp->mass = hydro_get_mass(p); + + /* Store either the birth_scale_factor or birth_time depending */ + if (with_cosmology) { + sp->birth_scale_factor = cosmo->a; + } else { + sp->birth_time = e->time; + } + /* Store the chemistry struct in the star particle */ + sp->chemistry_data = p->chemistry_data; + + /* Store the tracers data */ + sp->tracers_data = xp->tracers_data; + + /* Store the birth density in the star particle */ + sp->birth_density = hydro_get_physical_density(p, cosmo); + /* Store the birth temperature*/ + sp->birth_temperature = get_temperature(starform->phys_const,starform->hydro_props,starform->us,cosmo,e->cooling_func,p,xp); + +} /** * @brief initialization of the star formation law @@ -147,7 +292,22 @@ INLINE static void star_formation_copy_properties( INLINE static void starformation_init_backend( struct swift_params* parameter_file, const struct phys_const* phys_const, const struct unit_system* us, const struct hydro_props* hydro_props, - const struct star_formation* starform) {} + struct star_formation* starform) { + /* Jeans Number used in starformation elligibility criterion */ + starform->Njeans = parser_get_param_int( + parameter_file, "GEARStarFormation:jeans_number"); + /* Starformation efficiency (used in SFR calculation) */ + starform->star_formation_rate = parser_get_param_double( + parameter_file, "GEARStarFormation:star_formation_efficiency"); + /* Wheter we take into account local turbulence */ + starform->with_sigma = parser_get_param_int( + parameter_file, "GEARStarFormation:with_turbulence_estimation"); + /* Maximum temperature for starformation */ + starform->Max_temperature=parser_get_param_double(parameter_file, "GEARStarFormation:Max_temperature")*units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE);; + starform->hydro_props=hydro_props; + starform->us=us; + starform->phys_const=phys_const; + } /** * @brief Prints the used parameters of the star formation law @@ -156,7 +316,6 @@ INLINE static void starformation_init_backend( */ INLINE static void starformation_print_backend( const struct star_formation* starform) { - message("Star formation law is 'GEAR'"); } @@ -164,13 +323,16 @@ INLINE static void starformation_print_backend( * @brief Finishes the density calculation. * * @param p The particle to act upon + * @param xp The extended particle data to act upon * @param cd The global star_formation information. * @param cosmo The current cosmological model. */ __attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, const struct star_formation* cd, - const struct cosmology* cosmo) {} - + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, + const struct cosmology* cosmo) { + /* To finish the turbulence estimation we devide by the density */ + xp->sf_data.sigma2/=hydro_get_physical_density(p,cosmo); +} /** * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. * @@ -183,14 +345,15 @@ __attribute__((always_inline)) INLINE static void star_formation_part_has_no_neighbours(struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, - const struct cosmology* cosmo) {} + const struct cosmology* cosmo) { + /* If part has 0 neighbours, the estimation of turbulence is 0 */ + xp->sf_data.sigma2=0.f; + + } /** * @brief Sets the star_formation properties of the (x-)particles to a valid * start state. - * - * Nothing to do here. - * * @param phys_const The physical constant in internal units. * @param us The unit system. * @param cosmo The current cosmological model. @@ -203,19 +366,25 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct unit_system* restrict us, const struct cosmology* restrict cosmo, const struct star_formation* data, - const struct part* restrict p, - struct xpart* restrict xp) {} + struct part* restrict p, + struct xpart* restrict xp) { + + xp->sf_data.sigma2=0.f; + + } /** * @brief Sets the star_formation properties of the (x-)particles to a valid * start state. * - * Nothing to do here. - * * @param p Pointer to the particle data. + * @param xp Pointer to extended particle data * @param data The global star_formation information. */ __attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, const struct star_formation* data) {} + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) { + xp->sf_data.sigma2=0.f; + + } #endif /* SWIFT_GEAR_STAR_FORMATION_H */ diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index 749b60806..2f6307c7d 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -1,6 +1,4 @@ /******************************************************************************* - * This file is part of SWIFT. - * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -39,7 +37,22 @@ */ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( float r2, const float *dx, float hi, float hj, struct part *restrict pi, - struct part *restrict pj, float a, float H) {} + struct part *restrict pj, struct xpart *restrict xpi, struct xpart *restrict xpj, float a, float H) + { + /* The goal here is to estimate the local turbulence */ + /* Value used to evaluate the SPH kernel */ + float wi; + float wj; + /* Evaluation of the SPH kernel */ + kernel_eval(sqrt(r2)/hi,&wi); + kernel_eval(sqrt(r2)/hj,&wj); + /* Square of the velocity norm between particles i and j */ + float norm_v2=pow(pi->v[0]-pj->v[0],2)+pow(pi->v[1]-pj->v[1],2)+pow(pi->v[2]-pj->v[2],2); + + /* Estimation of local turbulence for pi and pj, see Revaz & Jablonka, eq (2) */ + xpi->sf_data.sigma2+=pow(hi,-3)*norm_v2*wi*hydro_get_mass(pj); + xpj->sf_data.sigma2+=pow(hj,-3)*norm_v2*wj*hydro_get_mass(pi); + } /** * @brief do star_formation computation after the runner_iact_density (non @@ -56,8 +69,18 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( */ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, - struct part *restrict pi, - const struct part *restrict pj, float a, - float H) {} - + struct part *restrict pi, + const struct part *restrict pj, struct xpart *restrict xpi, const struct xpart *restrict xpj,float a, + float H) + /* The goal here is to estimate the local turbulence */ + /* Value used to evaluate the SPH kernel */ + { + float wi; + /* Evaluation of the SPH kernel */ + kernel_eval(sqrt(r2)/hi,&wi); + /* Square of the velocity norm */ + float norm_v2=pow(pi->v[0]-pj->v[0],2)+pow(pi->v[1]-pj->v[1],2)+pow(pi->v[2]-pj->v[2],2); + /* Estimation of local turbulence for pi */ + xpi->sf_data.sigma2+=pow(hi,-3)*norm_v2*wi*hydro_get_mass(pj); +} #endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index 6ef04c49c..09972e54d 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -37,7 +37,7 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( const struct part* parts, const struct xpart* xparts, struct io_props* list) { - + /* Nothing to write here */ return 0; } diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 5b9e033d2..1cdd6153e 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -16,8 +16,8 @@ * along with this program. If not, see . * *******************************************************************************/ -#ifndef SWIFT_GEAR_STARFORMATION_LOGGER_H -#define SWIFT_GEAR_STARFORMATION_LOGGER_H +#ifndef SWIFT_EAGLE_STARFORMATION_LOGGER_H +#define SWIFT_EAGLE_STARFORMATION_LOGGER_H /* Some standard headers */ #include @@ -27,16 +27,26 @@ #include "hydro.h" #include "part.h" #include "star_formation_logger_struct.h" - +#include "units.h" /** * @brief Update the stellar mass in the current cell after creating * the new star particle spart sp - * + * @param time_step, the current time step of the simulation * @param sp new created star particle * @param sf the star_formation_history struct of the current cell */ INLINE static void star_formation_logger_log_new_spart( - struct spart *sp, struct star_formation_history *sf) {} + const struct spart *sp, struct star_formation_history *sf, const double time_step) { + + /* Add mass of created sparticle to the total stellar mass in this cell*/ + sf->stellar_mass += sp->mass; + sf->total_stellar_mass += sp->mass; + /* Increase the number of stars */ + sf->number_of_stars+=1; + sf->total_number_of_stars+=1; + /* Approximation of the SFR */ + sf->new_sfr += sp->mass/time_step; +} /** * @brief Initialize the star formation history struct in the case the cell is @@ -45,8 +55,43 @@ INLINE static void star_formation_logger_log_new_spart( * @param sf the star_formation_history struct we want to initialize */ INLINE static void star_formation_logger_log_inactive_cell( - struct star_formation_history *sf) {} - + struct star_formation_history *sf) { + /* Initialize the stellar mass to zero */ + sf->stellar_mass=0.f; + /*!initialize number of stars to zero*/ + sf->number_of_stars=0; + /* Initialize the active SFR */ + sf->new_sfr = 0.f; +} +/** + * @brief Initialize the star formation history structure in the #engine + * + * @param sfh The pointer to the star formation history structure + */ +INLINE static void star_formation_logger_init( + struct star_formation_history *sfh) { + /* Initialize the collecting SFH structure to zero */ + sfh->new_sfr = 0.f; + sfh->number_of_stars=0; + sfh->stellar_mass=0.f; + /* to be removed when the total quantities will be implemented */ + sfh->total_number_of_stars=0; + sfh->total_stellar_mass=0.f; +} +/** + * @brief Initialize the star formation history struct in the #engine (once only) + * + * @param sfh the star_formation_history struct we want to initialize + */ +INLINE static void star_formation_logger_first_init( + struct star_formation_history *sfh) { + /* Initialize all values to zero */ + sfh->new_sfr = 0.f; + sfh->stellar_mass=0.f; + sfh->number_of_stars=0; + sfh->total_number_of_stars=0; + sfh->total_stellar_mass=0.f; +} /** * @brief add a star formation history struct to an other star formation history * struct @@ -57,15 +102,16 @@ INLINE static void star_formation_logger_log_inactive_cell( */ INLINE static void star_formation_logger_add( struct star_formation_history *sf_update, - const struct star_formation_history *sf_add) {} + const struct star_formation_history *sf_add) { + + /* Update the SFH structure */ + sf_update->new_sfr += sf_add->new_sfr; + sf_update->number_of_stars += sf_add->number_of_stars; + sf_update->stellar_mass += sf_add->stellar_mass; + sf_update->total_number_of_stars+=sf_add->total_number_of_stars; + sf_update->total_stellar_mass+=sf_add->total_stellar_mass; +} -/** - * @brief Initialize the star formation history structure in the #engine - * - * @param sfh The pointer to the star formation history structure - */ -INLINE static void star_formation_logger_init( - struct star_formation_history *sfh) {} /** * @brief Write the final SFH to a file @@ -79,8 +125,11 @@ INLINE static void star_formation_logger_init( */ INLINE static void star_formation_logger_write_to_log_file( FILE *fp, const double time, const double a, const double z, - const struct star_formation_history sf, const int step) {} + struct star_formation_history sf, const int step) { + fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14e\n", step, time, a, z, sf.number_of_stars, + sf.stellar_mass, sf.new_sfr); +} /** * @brief Initialize the SFH logger file * @@ -90,30 +139,68 @@ INLINE static void star_formation_logger_write_to_log_file( */ INLINE static void star_formation_logger_init_log_file( FILE *fp, const struct unit_system *restrict us, - const struct phys_const *phys_const) {} + const struct phys_const *phys_const) { + + /* Write some general text to the logger file */ + fprintf(fp, "# Star Formation History Logger file\n"); + fprintf(fp, "######################################################\n"); + fprintf(fp, "# The quantities are all given in internal physical units!\n"); + fprintf(fp, "#\n"); + fprintf(fp, "# (0) Simulation step\n"); + fprintf(fp, + "# (1) Time since Big Bang (cosmological run), Time since start of " + "the simulation (non-cosmological run).\n"); + fprintf(fp, "# Unit = %e seconds\n", us->UnitTime_in_cgs); + fprintf(fp, "# Unit = %e yr or %e Myr\n", 1.f / phys_const->const_year, + 1.f / phys_const->const_year / 1e6); + fprintf(fp, "# (2) Scale factor (no unit)\n"); + fprintf(fp, "# (3) Redshift (no unit)\n"); + fprintf(fp, "# (4) Number of stars formed in the current time step (no unit)\n"); + fprintf(fp, "# (5) Stellar mass formed in the current time step.\n"); + fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); + fprintf(fp, "# Unit = %e solar mass\n", + 1.f / phys_const->const_solar_mass); + fprintf(fp, "# (6) Star formation rate in the current time step.\n"); + fprintf(fp, "# Unit = %e gram/s\n", + us->UnitMass_in_cgs / us->UnitTime_in_cgs); + fprintf(fp, "# Unit = %e Msol/yr\n", + phys_const->const_year / phys_const->const_solar_mass); + fprintf( + fp, + "# (0) (1) (2) (3) (4) (5) (6)\n"); + +} /** * @brief Add the SFR tracer to the total active SFR of this cell * * @param p the #part * @param xp the #xpart + * + * Nothing to do here + * * @param sf the SFH logger struct * @param dt_star The length of the time-step in physical internal units. */ INLINE static void star_formation_logger_log_active_part( const struct part *p, const struct xpart *xp, - struct star_formation_history *sf, const double dt_star) {} + struct star_formation_history *sf, const double dt_star) { + +} /** * @brief Add the SFR tracer to the total inactive SFR of this cell as long as * the SFR tracer is larger than 0 * + * Nothing to do here + * * @param p the #part * @param xp the #xpart * @param sf the SFH logger struct */ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, - struct star_formation_history *sf) {} + struct star_formation_history *sf) { +} -#endif /* SWIFT_GEAR_STARFORMATION_LOGGER_H */ +#endif /* SWIFT_EAGLE_STARFORMATION_LOGGER_H */ diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 04b5dfdc0..4cff5a2cb 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -16,10 +16,21 @@ * along with this program. If not, see . * ******************************************************************************/ -#ifndef SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H -#define SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H +#ifndef SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H +#define SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H /* Starformation history struct */ -struct star_formation_history {}; +struct star_formation_history { + /*! Total current star formation rate (new mass divided by timestep) */ + float new_sfr; + /*! Total stellar mass (no reset) */ + float total_stellar_mass; + /*! Stellar mass created in the current timestep */ + float stellar_mass; + /*! Number of stars created in this timestep */ + long int number_of_stars; + /*! Total number of stars */ + long int total_number_of_stars; +}; -#endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */ +#endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */ diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 9b4e216fd..7f8270f59 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -23,9 +23,29 @@ * @brief Star-formation-related properties stored in the extended particle * data. */ -struct star_formation_xpart_data {}; +struct star_formation_xpart_data { + /*!star formation rate (mass/(time*volume))*/ + double SFR; + /*! Estimation of local turbulence (squared) */ + float sigma2; + }; /* Starformation struct */ -struct star_formation {}; +struct star_formation { + /*! Njeans number. We request that the SPH mass resolution is Njeans times smaller than the Jeans mass*/ + int Njeans; + /*!star formation efficency. If the particle can create a star, it happens with this probablity*/ + double star_formation_rate; + /*!do we include local turbulence*/ + int with_sigma; + /*!Maximum temperature to allow star formation* (should be about 10'000 or 30'000 K*/ + double Max_temperature; + /*!some other useful elements*/ + const struct hydro_props* restrict hydro_props; + /*!units*/ + const struct unit_system* restrict us; + /*! physical constants*/ + const struct phys_const* phys_const; + }; #endif /* SWIFT_GEAR_STAR_FORMATION_STRUCT_H */ diff --git a/src/stars/GEAR/stars.h b/src/stars/GEAR/stars.h new file mode 100644 index 000000000..e29602c12 --- /dev/null +++ b/src/stars/GEAR/stars.h @@ -0,0 +1,173 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +#ifndef SWIFT_GEAR_STARS_H +#define SWIFT_GEAR_STARS_H + +#include +#include "minmax.h" + +/** + * @brief Computes the gravity time-step of a given star particle. + * + * @param sp Pointer to the s-particle data. + */ +__attribute__((always_inline)) INLINE static float stars_compute_timestep( + const struct spart* const sp) { + + return FLT_MAX; +} + +/** + * @brief Initialises the s-particles for the first time + * + * This function is called only once just after the ICs have been + * read in to do some conversions. + * + * @param sp The particle to act upon + * @param stars_properties The properties of the stellar model. + */ +__attribute__((always_inline)) INLINE static void stars_first_init_spart( + struct spart* sp, const struct stars_props* stars_properties) { + + sp->time_bin = 0; +} + +/** + * @brief Prepares a s-particle for its interactions + * + * @param sp The particle to act upon + */ +__attribute__((always_inline)) INLINE static void stars_init_spart( + struct spart* sp) { + +#ifdef DEBUG_INTERACTIONS_STARS + for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS_STARS; ++i) + sp->ids_ngbs_density[i] = -1; + sp->num_ngb_density = 0; +#endif + + sp->density.wcount = 0.f; + sp->density.wcount_dh = 0.f; +} + +/** + * @brief Predict additional particle fields forward in time when drifting + * + * @param sp The particle + * @param dt_drift The drift time-step for positions. + */ +__attribute__((always_inline)) INLINE static void stars_predict_extra( + struct spart* restrict sp, float dt_drift) {} + +/** + * @brief Sets the values to be predicted in the drifts to their values at a + * kick time + * + * @param sp The particle. + */ +__attribute__((always_inline)) INLINE static void stars_reset_predicted_values( + struct spart* restrict sp) {} + +/** + * @brief Finishes the calculation of (non-gravity) forces acting on stars + * + * @param sp The particle to act upon + */ +__attribute__((always_inline)) INLINE static void stars_end_feedback( + struct spart* sp) {} + +/** + * @brief Kick the additional variables + * + * @param sp The particle to act upon + * @param dt The time-step for this kick + */ +__attribute__((always_inline)) INLINE static void stars_kick_extra( + struct spart* sp, float dt) {} + +/** + * @brief Finishes the calculation of density on stars + * + * @param sp The particle to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void stars_end_density( + struct spart* sp, const struct cosmology* cosmo) { + + /* Some smoothing length multiples. */ + const float h = sp->h; + const float h_inv = 1.0f / h; /* 1/h */ + const float h_inv_dim = pow_dimension(h_inv); /* 1/h^d */ + const float h_inv_dim_plus_one = h_inv_dim * h_inv; /* 1/h^(d+1) */ + + /* Finish the calculation by inserting the missing h-factors */ + sp->density.wcount *= h_inv_dim; + sp->density.wcount_dh *= h_inv_dim_plus_one; +} + +/** + * @brief Sets all particle fields to sensible values when the #spart has 0 + * ngbs. + * + * @param sp The particle to act upon + * @param cosmo The current cosmological model. + */ +__attribute__((always_inline)) INLINE static void stars_spart_has_no_neighbours( + struct spart* restrict sp, const struct cosmology* cosmo) { + + /* Some smoothing length multiples. */ + const float h = sp->h; + const float h_inv = 1.0f / h; /* 1/h */ + const float h_inv_dim = pow_dimension(h_inv); /* 1/h^d */ + + /* Re-set problematic values */ + sp->density.wcount = kernel_root * h_inv_dim; + sp->density.wcount_dh = 0.f; +} + +/** + * @brief Reset acceleration fields of a particle + * + * This is the equivalent of hydro_reset_acceleration. + * We do not compute the acceleration on star, therefore no need to use it. + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void stars_reset_feedback( + struct spart* restrict p) { + +#ifdef DEBUG_INTERACTIONS_STARS + for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS_STARS; ++i) + p->ids_ngbs_force[i] = -1; + p->num_ngb_force = 0; +#endif +} + +/** + * @brief Initializes constants related to stellar evolution, initializes imf, + * reads and processes yield tables + * + * @param params swift_params parameters structure + * @param stars stars_props data structure + */ +inline static void stars_evolve_init(struct swift_params* params, + struct stars_props* restrict stars) {} + +#endif /* SWIFT_GEAR_STARS_H */ diff --git a/src/stars/GEAR/stars_debug.h b/src/stars/GEAR/stars_debug.h new file mode 100644 index 000000000..8fc917f30 --- /dev/null +++ b/src/stars/GEAR/stars_debug.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +#ifndef SWIFT_GEAR_STARS_DEBUG_H +#define SWIFT_GEAR_STARS_DEBUG_H + +__attribute__((always_inline)) INLINE static void stars_debug_particle( + const struct spart* p) { + printf( + "x=[%.3e,%.3e,%.3e], " + "v_full=[%.3e,%.3e,%.3e] p->mass=%.3e \n t_begin=%d, t_end=%d\n", + p->x[0], p->x[1], p->x[2], p->v_full[0], p->v_full[1], p->v_full[2], + p->mass, p->ti_begin, p->ti_end); +} + +#endif /* SWIFT_GEAR_STARS_DEBUG_H */ diff --git a/src/stars/GEAR/stars_iact.h b/src/stars/GEAR/stars_iact.h new file mode 100644 index 000000000..c1f0904e5 --- /dev/null +++ b/src/stars/GEAR/stars_iact.h @@ -0,0 +1,95 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +#ifndef SWIFT_GEAR_STARS_IACT_H +#define SWIFT_GEAR_STARS_IACT_H + +/** + * @brief Density interaction between two particles (non-symmetric). + * + * @param r2 Comoving square distance between the two particles. + * @param dx Comoving vector separating both particles (pi - pj). + * @param hi Comoving smoothing-length of particle i. + * @param hj Comoving smoothing-length of particle j. + * @param si First sparticle. + * @param pj Second particle (not updated). + * @param a Current scale factor. + * @param H Current Hubble parameter. + */ +__attribute__((always_inline)) INLINE static void +runner_iact_nonsym_stars_density(const float r2, const float *dx, + const float hi, const float hj, + struct spart *restrict si, + const struct part *restrict pj, const float a, + const float H) { + + float wi, wi_dx; + + /* Get r and 1/r. */ + const float r_inv = 1.0f / sqrtf(r2); + const float r = r2 * r_inv; + + /* Compute the kernel function */ + const float hi_inv = 1.0f / hi; + const float ui = r * hi_inv; + kernel_deval(ui, &wi, &wi_dx); + + /* Compute contribution to the number of neighbours */ + si->density.wcount += wi; + si->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx); + +#ifdef DEBUG_INTERACTIONS_STARS + /* Update ngb counters */ + if (si->num_ngb_density < MAX_NUM_OF_NEIGHBOURS_STARS) + si->ids_ngbs_density[si->num_ngb_density] = pj->id; + + /* Update ngb counters */ + ++si->num_ngb_density; +#endif +} + +/** + * @brief Feedback interaction between two particles (non-symmetric). + * + * @param r2 Comoving square distance between the two particles. + * @param dx Comoving vector separating both particles (pi - pj). + * @param hi Comoving smoothing-length of particle i. + * @param hj Comoving smoothing-length of particle j. + * @param si First sparticle. + * @param pj Second particle (not updated). + * @param a Current scale factor. + * @param H Current Hubble parameter. + */ +__attribute__((always_inline)) INLINE static void +runner_iact_nonsym_stars_feedback(const float r2, const float *dx, + const float hi, const float hj, + struct spart *restrict si, + struct part *restrict pj, const float a, + const float H) { +#ifdef DEBUG_INTERACTIONS_STARS + /* Update ngb counters */ + if (si->num_ngb_force < MAX_NUM_OF_NEIGHBOURS_STARS) + si->ids_ngbs_force[si->num_ngb_force] = pj->id; + + /* Update ngb counters */ + ++si->num_ngb_force; +#endif +} + +#endif diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h new file mode 100644 index 000000000..af4f24eab --- /dev/null +++ b/src/stars/GEAR/stars_io.h @@ -0,0 +1,215 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +#ifndef SWIFT_GEAR_STARS_IO_H +#define SWIFT_GEAR_STARS_IO_H + +#include "io_properties.h" +#include "stars_part.h" + +/** + * @brief Specifies which s-particle fields to read from a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to read. + * @param num_fields The number of i/o fields to read. + */ +INLINE static void stars_read_particles(struct spart *sparts, + struct io_props *list, + int *num_fields) { + + /* Say how much we want to read */ + *num_fields = 5; + + /* List what we want to read */ + list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, + UNIT_CONV_LENGTH, sparts, x); + list[1] = io_make_input_field("Velocities", FLOAT, 3, COMPULSORY, + UNIT_CONV_SPEED, sparts, v); + list[2] = io_make_input_field("Masses", FLOAT, 1, COMPULSORY, UNIT_CONV_MASS, + sparts, mass); + list[3] = io_make_input_field("ParticleIDs", LONGLONG, 1, COMPULSORY, + UNIT_CONV_NO_UNITS, sparts, id); + list[4] = io_make_input_field("SmoothingLength", FLOAT, 1, OPTIONAL, + UNIT_CONV_LENGTH, sparts, h); +} + +/** + * @brief Specifies which s-particle fields to write to a dataset + * + * @param sparts The s-particle array. + * @param list The list of i/o properties to write. + * @param num_fields The number of i/o fields to write. + */ +INLINE static void stars_write_particles(const struct spart *sparts, + struct io_props *list, + int *num_fields) { + + /* Say how much we want to write */ + *num_fields = 6; + + /* List what we want to write */ + list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, + sparts, x); + list[1] = + io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); + list[2] = + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass); + list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, + sparts, id); + list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, + sparts, h); + list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, + birth_time); + + +#ifdef DEBUG_INTERACTIONS_STARS + + list += *num_fields; + *num_fields += 4; + + list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS, + sparts, num_ngb_density); + list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS, + sparts, num_ngb_force); + list[2] = io_make_output_field("Ids_ngb_density", LONGLONG, + MAX_NUM_OF_NEIGHBOURS_STARS, + UNIT_CONV_NO_UNITS, sparts, ids_ngbs_density); + list[3] = io_make_output_field("Ids_ngb_force", LONGLONG, + MAX_NUM_OF_NEIGHBOURS_STARS, + UNIT_CONV_NO_UNITS, sparts, ids_ngbs_force); +#endif +} + +/** + * @brief Initialize the global properties of the stars scheme. + * + * By default, takes the values provided by the hydro. + * + * @param sp The #stars_props. + * @param phys_const The physical constants in the internal unit system. + * @param us The internal unit system. + * @param params The parsed parameters. + * @param p The already read-in properties of the hydro scheme. + * @param cosmo The cosmological model. + */ +INLINE static void stars_props_init(struct stars_props *sp, + const struct phys_const *phys_const, + const struct unit_system *us, + struct swift_params *params, + const struct hydro_props *p, + const struct cosmology *cosmo) { + + /* Kernel properties */ + sp->eta_neighbours = parser_get_opt_param_float( + params, "Stars:resolution_eta", p->eta_neighbours); + + /* Tolerance for the smoothing length Newton-Raphson scheme */ + sp->h_tolerance = + parser_get_opt_param_float(params, "Stars:h_tolerance", p->h_tolerance); + + /* Get derived properties */ + sp->target_neighbours = pow_dimension(sp->eta_neighbours) * kernel_norm; + const float delta_eta = sp->eta_neighbours * (1.f + sp->h_tolerance); + sp->delta_neighbours = + (pow_dimension(delta_eta) - pow_dimension(sp->eta_neighbours)) * + kernel_norm; + + /* Number of iterations to converge h */ + sp->max_smoothing_iterations = parser_get_opt_param_int( + params, "Stars:max_ghost_iterations", p->max_smoothing_iterations); + + /* Time integration properties */ + const float max_volume_change = + parser_get_opt_param_float(params, "Stars:max_volume_change", -1); + if (max_volume_change == -1) + sp->log_max_h_change = p->log_max_h_change; + else + sp->log_max_h_change = logf(powf(max_volume_change, hydro_dimension_inv)); +} + +/** + * @brief Print the global properties of the stars scheme. + * + * @param sp The #stars_props. + */ +INLINE static void stars_props_print(const struct stars_props *sp) { + + /* Now stars */ + message("Stars kernel: %s with eta=%f (%.2f neighbours).", kernel_name, + sp->eta_neighbours, sp->target_neighbours); + + message("Stars relative tolerance in h: %.5f (+/- %.4f neighbours).", + sp->h_tolerance, sp->delta_neighbours); + + message( + "Stars integration: Max change of volume: %.2f " + "(max|dlog(h)/dt|=%f).", + pow_dimension(expf(sp->log_max_h_change)), sp->log_max_h_change); + + message("Maximal iterations in ghost task set to %d", + sp->max_smoothing_iterations); +} + +#if defined(HAVE_HDF5) +INLINE static void stars_props_print_snapshot(hid_t h_grpstars, + const struct stars_props *sp) { + + io_write_attribute_s(h_grpstars, "Kernel function", kernel_name); + io_write_attribute_f(h_grpstars, "Kernel target N_ngb", + sp->target_neighbours); + io_write_attribute_f(h_grpstars, "Kernel delta N_ngb", sp->delta_neighbours); + io_write_attribute_f(h_grpstars, "Kernel eta", sp->eta_neighbours); + io_write_attribute_f(h_grpstars, "Smoothing length tolerance", + sp->h_tolerance); + io_write_attribute_f(h_grpstars, "Volume log(max(delta h))", + sp->log_max_h_change); + io_write_attribute_f(h_grpstars, "Volume max change time-step", + pow_dimension(expf(sp->log_max_h_change))); + io_write_attribute_i(h_grpstars, "Max ghost iterations", + sp->max_smoothing_iterations); +} +#endif + +/** + * @brief Write a #stars_props struct to the given FILE as a stream of bytes. + * + * @param p the struct + * @param stream the file stream + */ +INLINE static void stars_props_struct_dump(const struct stars_props *p, + FILE *stream) { + restart_write_blocks((void *)p, sizeof(struct stars_props), 1, stream, + "starsprops", "stars props"); +} + +/** + * @brief Restore a stars_props struct from the given FILE as a stream of + * bytes. + * + * @param p the struct + * @param stream the file stream + */ +INLINE static void stars_props_struct_restore(const struct stars_props *p, + FILE *stream) { + restart_read_blocks((void *)p, sizeof(struct stars_props), 1, stream, NULL, + "stars props"); +} + +#endif /* SWIFT_GEAR_STAR_IO_H */ diff --git a/src/stars/GEAR/stars_part.h b/src/stars/GEAR/stars_part.h new file mode 100644 index 000000000..1c7b573b4 --- /dev/null +++ b/src/stars/GEAR/stars_part.h @@ -0,0 +1,151 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +#ifndef SWIFT_GEAR_STAR_PART_H +#define SWIFT_GEAR_STAR_PART_H + +/* Some standard headers. */ +#include + +/* Read additional subgrid models */ +#include "chemistry_struct.h" +#include "feedback_struct.h" +#include "tracers_struct.h" + +/** + * @brief Particle fields for the star particles. + * + * All quantities related to gravity are stored in the associate #gpart. + */ +struct spart { + + /*! Particle ID. */ + long long id; + + /*! Pointer to corresponding gravity part. */ + struct gpart* gpart; + + /*! Particle position. */ + double x[3]; + + /* Offset between current position and position at last tree rebuild. */ + float x_diff[3]; + + /* Offset between current position and position at last tree rebuild. */ + float x_diff_sort[3]; + + /*! Particle velocity. */ + float v[3]; + + /*! Star mass */ + float mass; + + /* Particle cutoff radius. */ + float h; + + /*! Union for the birth time and birth scale factor */ + union { + + /*! Birth time */ + float birth_time; + + /*! Birth scale factor */ + float birth_scale_factor; + }; + + /*!birth density*/ + float birth_density; + + /*!birth temperature*/ + float birth_temperature; + + /*! Particle time bin */ + timebin_t time_bin; + + struct { + + /* Number of neighbours. */ + float wcount; + + /* Number of neighbours spatial derivative. */ + float wcount_dh; + + } density; + + /*! Feedback structure */ + struct feedback_spart_data feedback_data; + + /*! Tracer structure */ + struct tracers_xpart_data tracers_data; + + /*! Chemistry structure */ + struct chemistry_part_data chemistry_data; + + +#ifdef SWIFT_DEBUG_CHECKS + + /* Time of the last drift */ + integertime_t ti_drift; + + /* Time of the last kick */ + integertime_t ti_kick; + +#endif + +#ifdef DEBUG_INTERACTIONS_STARS + /*! Number of interactions in the density SELF and PAIR */ + int num_ngb_density; + + /*! List of interacting particles in the density SELF and PAIR */ + long long ids_ngbs_density[MAX_NUM_OF_NEIGHBOURS_STARS]; + + /*! Number of interactions in the force SELF and PAIR */ + int num_ngb_force; + + /*! List of interacting particles in the force SELF and PAIR */ + long long ids_ngbs_force[MAX_NUM_OF_NEIGHBOURS_STARS]; +#endif + +} SWIFT_STRUCT_ALIGN; + +/** + * @brief Contains all the constants and parameters of the stars scheme + */ +struct stars_props { + + /*! Resolution parameter */ + float eta_neighbours; + + /*! Target weightd number of neighbours (for info only)*/ + float target_neighbours; + + /*! Smoothing length tolerance */ + float h_tolerance; + + /*! Tolerance on neighbour number (for info only)*/ + float delta_neighbours; + + /*! Maximal number of iterations to converge h */ + int max_smoothing_iterations; + + /*! Maximal change of h over one time-step */ + float log_max_h_change; +}; + +#endif /* SWIFT_GEAR_STAR_PART_H */ diff --git a/src/tools.c b/src/tools.c index bd467e184..7b56ac820 100644 --- a/src/tools.c +++ b/src/tools.c @@ -190,6 +190,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { float r2, hi, hj, hig2, hjg2, dx[3]; struct part *pi, *pj; + struct xpart *xpi, *xpj; const double dim[3] = {r->e->s->dim[0], r->e->s->dim[1], r->e->s->dim[2]}; const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -200,6 +201,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; + xpi = &ci->hydro.xparts[i]; hi = pi->h; hig2 = hi * hi * kernel_gamma2; @@ -209,6 +211,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int j = 0; j < cj->hydro.count; ++j) { pj = &cj->hydro.parts[j]; + xpj = &cj->hydro.xparts[j]; /* Pairwise distance */ r2 = 0.0f; @@ -222,9 +225,9 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { if (r2 < hig2 && !part_is_inhibited(pj, e)) { /* Interact */ - runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, a, H); } } } @@ -233,6 +236,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int j = 0; j < cj->hydro.count; ++j) { pj = &cj->hydro.parts[j]; + xpj = &cj->hydro.xparts[j]; hj = pj->h; hjg2 = hj * hj * kernel_gamma2; @@ -242,6 +246,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; + xpi = &ci->hydro.xparts[i]; /* Pairwise distance */ r2 = 0.0f; @@ -257,7 +262,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hj, pi->h, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dx, hj, pi->h, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, xpj, xpi, a, H); } } } @@ -502,6 +507,7 @@ void pairs_all_stars_density(struct runner *r, struct cell *ci, void self_all_density(struct runner *r, struct cell *ci) { float r2, hi, hj, hig2, hjg2, dxi[3]; //, dxj[3]; struct part *pi, *pj; + struct xpart *xpi, *xpj; const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; const float a = cosmo->a; @@ -511,12 +517,14 @@ void self_all_density(struct runner *r, struct cell *ci) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; + xpi = &ci->hydro.xparts[i]; hi = pi->h; hig2 = hi * hi * kernel_gamma2; for (int j = i + 1; j < ci->hydro.count; ++j) { pj = &ci->hydro.parts[j]; + xpj = &ci->hydro.xparts[j]; hj = pj->h; hjg2 = hj * hj * kernel_gamma2; @@ -535,7 +543,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hi, hj, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dxi, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, xpi, xpj, a, H); } /* Hit or miss? */ @@ -548,7 +556,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hj, hi, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dxi, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, a, H); + runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, xpj, xpi, a, H); } } } -- GitLab From c9e5191fc420bf2c4e4f4a7e899e4911bbf03828 Mon Sep 17 00:00:00 2001 From: loikki Date: Thu, 13 Jun 2019 07:52:25 +0200 Subject: [PATCH 02/16] Add GEAR stars --- src/stars.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stars.h b/src/stars.h index dd8390e02..dea6e07a8 100644 --- a/src/stars.h +++ b/src/stars.h @@ -29,6 +29,9 @@ #elif defined(STARS_EAGLE) #include "./stars/EAGLE/stars.h" #include "./stars/EAGLE/stars_iact.h" +#elif defined(STARS_GEAR) +#include "./stars/GEAR/stars.h" +#include "./stars/GEAR/stars_iact.h" #else #error "Invalid choice of star model" #endif -- GitLab From 47bd54aa7f249934d46bbc33616300c9766151ab Mon Sep 17 00:00:00 2001 From: loikki Date: Thu, 13 Jun 2019 08:50:24 +0200 Subject: [PATCH 03/16] format --- src/runner.c | 26 +- src/runner_doiact.h | 204 ++++++++------- src/star_formation/GEAR/star_formation.h | 236 +++++++++--------- src/star_formation/GEAR/star_formation_iact.h | 61 ++--- src/star_formation/GEAR/star_formation_io.h | 2 +- .../GEAR/star_formation_logger.h | 58 +++-- .../GEAR/star_formation_logger_struct.h | 2 +- .../GEAR/star_formation_struct.h | 43 ++-- src/stars/GEAR/stars_io.h | 1 - src/stars/GEAR/stars_part.h | 9 +- src/tools.c | 16 +- 11 files changed, 345 insertions(+), 313 deletions(-) diff --git a/src/runner.c b/src/runner.c index 0977d9e2e..5fc9d46c1 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1185,7 +1185,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { hydro_props, us, cooling); /* Update the Star formation history */ - star_formation_logger_log_new_spart(sp, &c->stars.sfh,e->time_step); + star_formation_logger_log_new_spart(sp, &c->stars.sfh, + e->time_step); } } @@ -2379,35 +2380,36 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Self-interaction? */ if (l->t->type == task_type_self) - runner_doself_subset_branch_density(r, finger, parts, xparts, pid, count); + runner_doself_subset_branch_density(r, finger, parts, xparts, pid, + count); /* Otherwise, pair interaction? */ else if (l->t->type == task_type_pair) { /* Left or right? */ if (l->t->ci == finger) - runner_dopair_subset_branch_density(r, finger, parts, xparts, pid, - count, l->t->cj); + runner_dopair_subset_branch_density(r, finger, parts, xparts, + pid, count, l->t->cj); else - runner_dopair_subset_branch_density(r, finger, parts, xparts, pid, - count, l->t->ci); + runner_dopair_subset_branch_density(r, finger, parts, xparts, + pid, count, l->t->ci); } /* Otherwise, sub-self interaction? */ else if (l->t->type == task_type_sub_self) - runner_dosub_subset_density(r, finger, parts, xparts, pid, count, NULL, - 1); + runner_dosub_subset_density(r, finger, parts, xparts, pid, count, + NULL, 1); /* Otherwise, sub-pair interaction? */ else if (l->t->type == task_type_sub_pair) { /* Left or right? */ if (l->t->ci == finger) - runner_dosub_subset_density(r, finger, parts, xparts, pid, count, - l->t->cj, 1); + runner_dosub_subset_density(r, finger, parts, xparts, pid, + count, l->t->cj, 1); else - runner_dosub_subset_density(r, finger, parts, xparts, pid, count, - l->t->ci, 1); + runner_dosub_subset_density(r, finger, parts, xparts, pid, + count, l->t->ci, 1); } } } diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 0505efbf8..b1dbd4733 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -149,11 +149,11 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; + struct xpart *restrict xparts_i = ci->hydro.xparts; #endif struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif /* Cosmological terms */ @@ -173,9 +173,9 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, for (int pid = 0; pid < count_i; pid++) { /* Get a hold of the ith part in ci. */ -struct part *restrict pi = &parts_i[pid]; + struct part *restrict pi = &parts_i[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[pid]; + struct xpart *xpi = &xparts_i[pid]; #endif /* Skip inhibited particles. */ @@ -194,7 +194,7 @@ struct part *restrict pi = &parts_i[pid]; /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; + struct xpart *xpj = &xparts_j[pjd]; #endif /* Skip inhibited particles. */ @@ -225,7 +225,8 @@ struct part *restrict pi = &parts_i[pid]; IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } if (r2 < hjg2 && pj_active) { @@ -237,7 +238,8 @@ struct part *restrict pi = &parts_i[pid]; IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } @@ -271,11 +273,11 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; + struct xpart *restrict xparts_i = ci->hydro.xparts; #endif struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif /* Cosmological terms */ @@ -295,9 +297,9 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, for (int pid = 0; pid < count_i; pid++) { /* Get a hold of the ith part in ci. */ -struct part *restrict pi = &parts_i[pid]; + struct part *restrict pi = &parts_i[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[pid]; + struct xpart *xpi = &xparts_i[pid]; #endif /* Skip inhibited particles. */ @@ -316,7 +318,7 @@ struct part *restrict pi = &parts_i[pid]; /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; + struct xpart *xpj = &xparts_j[pjd]; #endif /* Skip inhibited particles. */ @@ -356,7 +358,8 @@ struct part *restrict pi = &parts_i[pid]; IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } else if (pj_active) { @@ -367,7 +370,8 @@ struct part *restrict pi = &parts_i[pid]; IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } @@ -402,7 +406,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; + struct xpart *restrict xparts = c->hydro.xparts; #endif /* Loop over the parts in ci. */ @@ -411,7 +415,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; + struct xpart *xpi = &xparts[pid]; #endif /* Skip inhibited particles. */ @@ -430,7 +434,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; + struct xpart *xpj = &xparts[pjd]; #endif /* Skip inhibited particles. */ @@ -471,7 +475,8 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } else if (doj) { @@ -482,7 +487,8 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over the parts in cj. */ @@ -516,7 +522,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; + struct xpart *restrict xparts = c->hydro.xparts; #endif /* Loop over the parts in ci. */ @@ -525,7 +531,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; + struct xpart *xpi = &xparts[pid]; #endif /* Skip inhibited particles. */ @@ -544,7 +550,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; + struct xpart *xpj = &xparts[pjd]; #endif /* Skip inhibited particles. */ @@ -585,7 +591,8 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } else if (doj) { @@ -596,7 +603,8 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over the parts in cj. */ @@ -620,7 +628,8 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, + struct part *restrict parts_i, + struct xpart *restrict xparts_i, int *restrict ind, int count, struct cell *restrict cj, const double *shift) { @@ -632,7 +641,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif /* Cosmological terms */ @@ -645,7 +654,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; + struct xpart *restrict xpi = &xparts_i[ind[pid]]; #endif double pix[3]; for (int k = 0; k < 3; k++) pix[k] = pi->x[k] - shift[k]; @@ -663,7 +672,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; + struct xpart *xpj = &xparts_j[pjd]; #endif /* Skip inhibited particles. */ @@ -691,7 +700,8 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, pj->h, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, + a, H); #endif } } /* loop over the parts in cj. */ @@ -715,9 +725,10 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, int count, - struct cell *restrict cj, const int sid, const int flipped, - const double *shift) { + struct part *restrict parts_i, + struct xpart *restrict xparts_i, int *restrict ind, + int count, struct cell *restrict cj, const int sid, + const int flipped, const double *shift) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -727,7 +738,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif /* Cosmological terms */ @@ -747,7 +758,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; + struct xpart *restrict xpi = &xparts_i[ind[pid]]; #endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); @@ -763,7 +774,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; #endif /* Skip inhibited particles. */ @@ -793,7 +804,8 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } } /* loop over the parts in cj. */ @@ -809,7 +821,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; + struct xpart *restrict xpi = &xparts_i[ind[pid]]; #endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); @@ -825,7 +837,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; #endif /* Skip inhibited particles. */ @@ -855,7 +867,8 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } } /* loop over the parts in cj. */ @@ -878,7 +891,8 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, * @param cj The second #cell. */ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, struct xpart *restrict xparts_i, int *restrict ind, + struct part *restrict parts_i, + struct xpart *restrict xparts_i, int *restrict ind, int count, struct cell *restrict cj) { const struct engine *e = r->e; @@ -920,7 +934,8 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, runner_dopair_subset_density_vec(r, ci, parts_i, ind, count, cj, sid, flipped, shift); else - DOPAIR_SUBSET(r, ci, parts_i, xparts_i,ind, count, cj, sid, flipped, shift); + DOPAIR_SUBSET(r, ci, parts_i, xparts_i, ind, count, cj, sid, flipped, + shift); #else DOPAIR_SUBSET(r, ci, parts_i, xparts_i, ind, count, cj, sid, flipped, shift); #endif @@ -937,7 +952,8 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, struct xpart *restrict xparts, int *restrict ind, int count) { + struct part *restrict parts, struct xpart *restrict xparts, + int *restrict ind, int count) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -950,17 +966,17 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; struct part *restrict parts_j = ci->hydro.parts; - #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) struct xpart *restrict xparts_j = ci->hydro.xparts; - #endif +#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *pi = &parts[ind[pid]]; - #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) struct xpart *xpi = &xparts[ind[pid]]; - #endif +#endif const float pix[3] = {(float)(pi->x[0] - ci->loc[0]), (float)(pi->x[1] - ci->loc[1]), (float)(pi->x[2] - ci->loc[2])}; @@ -977,7 +993,7 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; + struct xpart *xpj = &xparts_j[pjd]; #endif /* Skip inhibited particles. */ @@ -1006,7 +1022,8 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } } /* loop over the parts in cj. */ @@ -1026,7 +1043,8 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, struct xpart *restrict xparts, int *restrict ind, + struct part *restrict parts, + struct xpart *restrict xparts, int *restrict ind, int count) { #if defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) @@ -1081,11 +1099,11 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; + struct xpart *restrict xparts_i = ci->hydro.xparts; #endif struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif const double di_max = sort_i[count_i - 1].d - rshift; const double dj_min = sort_j[0].d; @@ -1103,7 +1121,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[sort_i[pid].i]; - #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) struct xpart *restrict xpi = &xparts_i[sort_i[pid].i]; #endif const float hi = pi->h; @@ -1127,7 +1145,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; #endif /* Skip inhibited particles. */ @@ -1182,7 +1200,8 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } } /* loop over the parts in cj. */ @@ -1198,7 +1217,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; #endif const float hj = pj->h; @@ -1221,7 +1240,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; + struct xpart *xpi = &xparts_i[sort_i[pid].i]; #endif /* Skip inhibited particles. */ @@ -1276,7 +1295,8 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over the parts in ci. */ @@ -1424,11 +1444,11 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; + struct xpart *restrict xparts_i = ci->hydro.xparts; #endif struct part *restrict parts_j = cj->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; + struct xpart *restrict xparts_j = cj->hydro.xparts; #endif /* Cosmological terms */ @@ -1497,7 +1517,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *pi = &parts_i[sort_i[pid].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; + struct xpart *xpi = &xparts_i[sort_i[pid].i]; #endif /* Skip inhibited particles. */ @@ -1585,7 +1605,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over the active parts in cj. */ @@ -1599,7 +1620,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; #endif /* Skip inhibited particles. */ @@ -1665,7 +1686,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, + a, H); #endif } } @@ -1683,7 +1705,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; + struct xpart *xpj = &xparts_j[sort_j[pjd].i]; #endif /* Skip inhibited particles. */ @@ -1771,7 +1793,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, + H); #endif } } /* loop over the active parts in ci. */ @@ -1786,7 +1809,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; + struct xpart *xpi = &xparts_i[sort_i[pid].i]; #endif /* Skip inhibited particles. */ @@ -1853,7 +1876,8 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, + a, H); #endif } } @@ -1978,7 +2002,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { struct part *restrict parts = c->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; + struct xpart *restrict xparts = c->hydro.xparts; #endif const int count = c->hydro.count; @@ -2004,7 +2028,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; + struct xpart *xpi = &xparts[pid]; #endif /* Skip inhibited particles. */ @@ -2024,8 +2048,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; - #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[indt[pjd]]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[indt[pjd]]; #endif const float hj = pj->h; @@ -2051,7 +2075,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over all other particles. */ @@ -2069,7 +2094,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; + struct xpart *xpj = &xparts[pjd]; #endif /* Skip inhibited particles. */ @@ -2113,7 +2138,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, + a, H); #endif } else if (doj) { @@ -2123,7 +2149,8 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, + a, H); #endif } } @@ -2186,7 +2213,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { struct part *restrict parts = c->hydro.parts; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; + struct xpart *restrict xparts = c->hydro.xparts; #endif const int count = c->hydro.count; @@ -2212,7 +2239,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; + struct xpart *xpi = &xparts[pid]; #endif /* Skip inhibited particles. */ @@ -2232,8 +2259,8 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; - #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[indt[pjd]]; +#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) + struct xpart *xpj = &xparts[indt[pjd]]; #endif const float hj = pj->h; @@ -2259,7 +2286,8 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, + H); #endif } } /* loop over all other particles. */ @@ -2277,7 +2305,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; + struct xpart *xpj = &xparts[pjd]; #endif /* Skip inhibited particles. */ @@ -2315,7 +2343,8 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, + a, H); #endif } } @@ -2572,7 +2601,8 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) { } void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, - struct xpart *xparts, int *ind, int count, struct cell *cj, int gettimer) { + struct xpart *xparts, int *ind, int count, struct cell *cj, + int gettimer) { const struct engine *e = r->e; struct space *s = e->s; @@ -2635,11 +2665,11 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, const int pid = csp->pairs[k].pid; const int pjd = csp->pairs[k].pjd; if (ci->progeny[pid] == sub && cj->progeny[pjd] != NULL) - DOSUB_SUBSET(r, ci->progeny[pid], parts, xparts, ind, count, cj->progeny[pjd], - 0); + DOSUB_SUBSET(r, ci->progeny[pid], parts, xparts, ind, count, + cj->progeny[pjd], 0); if (ci->progeny[pid] != NULL && cj->progeny[pjd] == sub) - DOSUB_SUBSET(r, cj->progeny[pjd], parts, xparts, ind, count, ci->progeny[pid], - 0); + DOSUB_SUBSET(r, cj->progeny[pjd], parts, xparts, ind, count, + ci->progeny[pid], 0); } } diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index 3215b0aea..c740b949d 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -20,19 +20,18 @@ #define SWIFT_GEAR_STAR_FORMATION_H /* Local includes */ +#include "cooling.h" #include "cosmology.h" +#include "engine.h" #include "entropy_floor.h" #include "error.h" #include "hydro_properties.h" #include "parser.h" #include "part.h" #include "physical_constants.h" -#include "units.h" -#include "star_formation_struct.h" #include "random.h" -#include "cooling.h" -#include "engine.h" - +#include "star_formation_struct.h" +#include "units.h" /** * @brief Compute the temperature of a #part based on the cooling function. @@ -63,7 +62,7 @@ INLINE static float get_temperature( const double mu_ionised = hydro_props->mu_ionised; /* Particle temperature */ - const double u = hydro_get_physical_internal_energy(p, xp, cosmo); + const double u = hydro_get_physical_internal_energy(p, xp, cosmo); /* Temperature over mean molecular weight */ const double T_over_mu = hydro_gamma_minus_one * u * m_H / k_B; @@ -90,57 +89,53 @@ INLINE static float get_temperature( * @param cooling The cooling data struct. * */ -INLINE static int star_formation_is_star_forming( +INLINE static int star_formation_is_star_forming( struct part* restrict p, struct xpart* restrict xp, const struct star_formation* starform, const struct phys_const* phys_const, const struct cosmology* cosmo, const struct hydro_props* restrict hydro_props, const struct unit_system* restrict us, const struct cooling_function_data* restrict cooling, - const struct entropy_floor_properties* restrict entropy_floor) - { - /* Some useful constants */ - const double G = phys_const->const_newton_G; - const double kb = phys_const->const_boltzmann_k; - const double mH = phys_const->const_proton_mass; - /* We first check if we are supposed to include turbulence estimation - * otherewise we keep 0 */ - float sigma2=0.f; - if(starform->with_sigma>0) - { - sigma2=xp->sf_data.sigma2; - } - /* Compute the temperature */ - double const T=get_temperature(phys_const,hydro_props,us,cosmo,cooling,p,xp); - /* Other useful values */ - const int N=starform->Njeans; - const double h=p->h; - /* We suppose that the gas is neutral */ - const double mu=hydro_props->mu_neutral; - /* Maximum temperature allowed (temperature criterion) */ - const double T0=starform->Max_temperature; - /* Compute density */ - const double physical_density = hydro_get_physical_density(p, cosmo); - /* We compute the minimal density for star formation (see Revaz & Jablonka, 2018 eq (3)) */ - const double rho_sfr=M_PI*(hydro_gamma*kb*T/mu/mH+sigma2)/h/h/4./G/pow(N,2./3.); - /* Temperature criterion for star formation eligibility */ - if(T>T0) - { - return 0; - } - /* Density criterion */ - else - { - if(physical_density>rho_sfr) - { - /* The particle is eligible (satisfy both conditions) */ - return 1; - } - else - { - return 0; - } - } + const struct entropy_floor_properties* restrict entropy_floor) { + /* Some useful constants */ + const double G = phys_const->const_newton_G; + const double kb = phys_const->const_boltzmann_k; + const double mH = phys_const->const_proton_mass; + /* We first check if we are supposed to include turbulence estimation + * otherewise we keep 0 */ + float sigma2 = 0.f; + if (starform->with_sigma > 0) { + sigma2 = xp->sf_data.sigma2; + } + /* Compute the temperature */ + double const T = + get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); + /* Other useful values */ + const int N = starform->Njeans; + const double h = p->h; + /* We suppose that the gas is neutral */ + const double mu = hydro_props->mu_neutral; + /* Maximum temperature allowed (temperature criterion) */ + const double T0 = starform->Max_temperature; + /* Compute density */ + const double physical_density = hydro_get_physical_density(p, cosmo); + /* We compute the minimal density for star formation (see Revaz & Jablonka, + * 2018 eq (3)) */ + const double rho_sfr = M_PI * (hydro_gamma * kb * T / mu / mH + sigma2) / h / + h / 4. / G / pow(N, 2. / 3.); + /* Temperature criterion for star formation eligibility */ + if (T > T0) { + return 0; + } + /* Density criterion */ + else { + if (physical_density > rho_sfr) { + /* The particle is eligible (satisfy both conditions) */ + return 1; + } else { + return 0; + } + } } /** @@ -157,29 +152,25 @@ INLINE static int star_formation_is_star_forming( INLINE static void star_formation_compute_SFR( struct part* restrict p, struct xpart* restrict xp, const struct star_formation* starform, const struct phys_const* phys_const, - const struct cosmology* cosmo, const double dt_star) - { - if (dt_star == 0.) { - xp->sf_data.SFR = 0.; - } - else - { - const double G = phys_const->const_newton_G; - const double c_star=starform->star_formation_rate; - const double physical_density = hydro_get_physical_density(p, cosmo); - if(physical_density!=0) - { - /* We compute the star formation rate and store it (see Revaz & Jablonka, 2012, eq. (5)) */ - /* Units are mass/time/distance³ */ - xp->sf_data.SFR=c_star*physical_density*sqrt(physical_density*32.f*G)/sqrt(3*M_PI); - } - else - { - xp->sf_data.SFR=0.; - } - } - return; - } + const struct cosmology* cosmo, const double dt_star) { + if (dt_star == 0.) { + xp->sf_data.SFR = 0.; + } else { + const double G = phys_const->const_newton_G; + const double c_star = starform->star_formation_rate; + const double physical_density = hydro_get_physical_density(p, cosmo); + if (physical_density != 0) { + /* We compute the star formation rate and store it (see Revaz & Jablonka, + * 2012, eq. (5)) */ + /* Units are mass/time/distance³ */ + xp->sf_data.SFR = c_star * physical_density * + sqrt(physical_density * 32.f * G) / sqrt(3 * M_PI); + } else { + xp->sf_data.SFR = 0.; + } + } + return; +} /** * @brief Decides whether a particle should be converted into a @@ -191,24 +182,22 @@ INLINE static void star_formation_compute_SFR( * @param e The #engine (for random numbers). * @param dt_star The time-step of this particle * @return 1 if a conversion should be done, 0 otherwise. - */ + */ INLINE static int star_formation_should_convert_to_star( - struct part* p, struct xpart* xp, - const struct star_formation* starform, const struct engine* e, - const double dt_star) { - /* Calculate the propability of forming a star, see Revaz & Jablonka (2012), eq. (4) */ - const double prob = 1.- exp(xp->sf_data.SFR * dt_star * (-1.) / hydro_get_physical_density(p,e->cosmology)); - /* Get a unique random number between 0 and 1 for star formation */ - const double random_number = - random_unit_interval(p->id, e->ti_current, random_number_star_formation); - if(random_number>prob) - { - return 0; - } - else - { - return 1; - } + struct part* p, struct xpart* xp, const struct star_formation* starform, + const struct engine* e, const double dt_star) { + /* Calculate the propability of forming a star, see Revaz & Jablonka (2012), + * eq. (4) */ + const double prob = 1. - exp(xp->sf_data.SFR * dt_star * (-1.) / + hydro_get_physical_density(p, e->cosmology)); + /* Get a unique random number between 0 and 1 for star formation */ + const double random_number = + random_unit_interval(p->id, e->ti_current, random_number_star_formation); + if (random_number > prob) { + return 0; + } else { + return 1; + } } /** @@ -257,7 +246,7 @@ INLINE static void star_formation_copy_properties( const struct hydro_props* restrict hydro_props, const struct unit_system* restrict us, const struct cooling_function_data* restrict cooling) { - + /* Store the current mass */ sp->mass = hydro_get_mass(p); @@ -276,8 +265,9 @@ INLINE static void star_formation_copy_properties( /* Store the birth density in the star particle */ sp->birth_density = hydro_get_physical_density(p, cosmo); /* Store the birth temperature*/ - sp->birth_temperature = get_temperature(starform->phys_const,starform->hydro_props,starform->us,cosmo,e->cooling_func,p,xp); - + sp->birth_temperature = + get_temperature(starform->phys_const, starform->hydro_props, starform->us, + cosmo, e->cooling_func, p, xp); } /** @@ -293,21 +283,25 @@ INLINE static void starformation_init_backend( struct swift_params* parameter_file, const struct phys_const* phys_const, const struct unit_system* us, const struct hydro_props* hydro_props, struct star_formation* starform) { - /* Jeans Number used in starformation elligibility criterion */ - starform->Njeans = parser_get_param_int( - parameter_file, "GEARStarFormation:jeans_number"); - /* Starformation efficiency (used in SFR calculation) */ - starform->star_formation_rate = parser_get_param_double( + /* Jeans Number used in starformation elligibility criterion */ + starform->Njeans = + parser_get_param_int(parameter_file, "GEARStarFormation:jeans_number"); + /* Starformation efficiency (used in SFR calculation) */ + starform->star_formation_rate = parser_get_param_double( parameter_file, "GEARStarFormation:star_formation_efficiency"); - /* Wheter we take into account local turbulence */ - starform->with_sigma = parser_get_param_int( + /* Wheter we take into account local turbulence */ + starform->with_sigma = parser_get_param_int( parameter_file, "GEARStarFormation:with_turbulence_estimation"); - /* Maximum temperature for starformation */ - starform->Max_temperature=parser_get_param_double(parameter_file, "GEARStarFormation:Max_temperature")*units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE);; - starform->hydro_props=hydro_props; - starform->us=us; - starform->phys_const=phys_const; - } + /* Maximum temperature for starformation */ + starform->Max_temperature = + parser_get_param_double(parameter_file, + "GEARStarFormation:Max_temperature") * + units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); + ; + starform->hydro_props = hydro_props; + starform->us = us; + starform->phys_const = phys_const; +} /** * @brief Prints the used parameters of the star formation law @@ -328,10 +322,10 @@ INLINE static void starformation_print_backend( * @param cosmo The current cosmological model. */ __attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, - const struct cosmology* cosmo) { - /* To finish the turbulence estimation we devide by the density */ - xp->sf_data.sigma2/=hydro_get_physical_density(p,cosmo); + struct part* restrict p, struct xpart* restrict xp, + const struct star_formation* cd, const struct cosmology* cosmo) { + /* To finish the turbulence estimation we devide by the density */ + xp->sf_data.sigma2 /= hydro_get_physical_density(p, cosmo); } /** * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. @@ -346,10 +340,9 @@ star_formation_part_has_no_neighbours(struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, const struct cosmology* cosmo) { - /* If part has 0 neighbours, the estimation of turbulence is 0 */ - xp->sf_data.sigma2=0.f; - - } + /* If part has 0 neighbours, the estimation of turbulence is 0 */ + xp->sf_data.sigma2 = 0.f; +} /** * @brief Sets the star_formation properties of the (x-)particles to a valid @@ -368,10 +361,9 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct star_formation* data, struct part* restrict p, struct xpart* restrict xp) { - - xp->sf_data.sigma2=0.f; - } + xp->sf_data.sigma2 = 0.f; +} /** * @brief Sets the star_formation properties of the (x-)particles to a valid @@ -382,9 +374,9 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, * @param data The global star_formation information. */ __attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) { - xp->sf_data.sigma2=0.f; - - } + struct part* restrict p, struct xpart* restrict xp, + const struct star_formation* data) { + xp->sf_data.sigma2 = 0.f; +} #endif /* SWIFT_GEAR_STAR_FORMATION_H */ diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index 2f6307c7d..e1310a41f 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -37,22 +37,24 @@ */ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( float r2, const float *dx, float hi, float hj, struct part *restrict pi, - struct part *restrict pj, struct xpart *restrict xpi, struct xpart *restrict xpj, float a, float H) - { - /* The goal here is to estimate the local turbulence */ - /* Value used to evaluate the SPH kernel */ - float wi; - float wj; - /* Evaluation of the SPH kernel */ - kernel_eval(sqrt(r2)/hi,&wi); - kernel_eval(sqrt(r2)/hj,&wj); - /* Square of the velocity norm between particles i and j */ - float norm_v2=pow(pi->v[0]-pj->v[0],2)+pow(pi->v[1]-pj->v[1],2)+pow(pi->v[2]-pj->v[2],2); + struct part *restrict pj, struct xpart *restrict xpi, + struct xpart *restrict xpj, float a, float H) { + /* The goal here is to estimate the local turbulence */ + /* Value used to evaluate the SPH kernel */ + float wi; + float wj; + /* Evaluation of the SPH kernel */ + kernel_eval(sqrt(r2) / hi, &wi); + kernel_eval(sqrt(r2) / hj, &wj); + /* Square of the velocity norm between particles i and j */ + float norm_v2 = pow(pi->v[0] - pj->v[0], 2) + pow(pi->v[1] - pj->v[1], 2) + + pow(pi->v[2] - pj->v[2], 2); - /* Estimation of local turbulence for pi and pj, see Revaz & Jablonka, eq (2) */ - xpi->sf_data.sigma2+=pow(hi,-3)*norm_v2*wi*hydro_get_mass(pj); - xpj->sf_data.sigma2+=pow(hj,-3)*norm_v2*wj*hydro_get_mass(pi); - } + /* Estimation of local turbulence for pi and pj, see Revaz & Jablonka, eq (2) + */ + xpi->sf_data.sigma2 += pow(hi, -3) * norm_v2 * wi * hydro_get_mass(pj); + xpj->sf_data.sigma2 += pow(hj, -3) * norm_v2 * wj * hydro_get_mass(pi); +} /** * @brief do star_formation computation after the runner_iact_density (non @@ -69,18 +71,21 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( */ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, - struct part *restrict pi, - const struct part *restrict pj, struct xpart *restrict xpi, const struct xpart *restrict xpj,float a, - float H) - /* The goal here is to estimate the local turbulence */ - /* Value used to evaluate the SPH kernel */ - { - float wi; - /* Evaluation of the SPH kernel */ - kernel_eval(sqrt(r2)/hi,&wi); - /* Square of the velocity norm */ - float norm_v2=pow(pi->v[0]-pj->v[0],2)+pow(pi->v[1]-pj->v[1],2)+pow(pi->v[2]-pj->v[2],2); - /* Estimation of local turbulence for pi */ - xpi->sf_data.sigma2+=pow(hi,-3)*norm_v2*wi*hydro_get_mass(pj); + struct part *restrict pi, + const struct part *restrict pj, + struct xpart *restrict xpi, + const struct xpart *restrict xpj, float a, + float H) +/* The goal here is to estimate the local turbulence */ +/* Value used to evaluate the SPH kernel */ +{ + float wi; + /* Evaluation of the SPH kernel */ + kernel_eval(sqrt(r2) / hi, &wi); + /* Square of the velocity norm */ + float norm_v2 = pow(pi->v[0] - pj->v[0], 2) + pow(pi->v[1] - pj->v[1], 2) + + pow(pi->v[2] - pj->v[2], 2); + /* Estimation of local turbulence for pi */ + xpi->sf_data.sigma2 += pow(hi, -3) * norm_v2 * wi * hydro_get_mass(pj); } #endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index 09972e54d..788b60273 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -37,7 +37,7 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( const struct part* parts, const struct xpart* xparts, struct io_props* list) { - /* Nothing to write here */ + /* Nothing to write here */ return 0; } diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 1cdd6153e..3ab808c93 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -36,16 +36,17 @@ * @param sf the star_formation_history struct of the current cell */ INLINE static void star_formation_logger_log_new_spart( - const struct spart *sp, struct star_formation_history *sf, const double time_step) { + const struct spart *sp, struct star_formation_history *sf, + const double time_step) { /* Add mass of created sparticle to the total stellar mass in this cell*/ sf->stellar_mass += sp->mass; sf->total_stellar_mass += sp->mass; /* Increase the number of stars */ - sf->number_of_stars+=1; - sf->total_number_of_stars+=1; + sf->number_of_stars += 1; + sf->total_number_of_stars += 1; /* Approximation of the SFR */ - sf->new_sfr += sp->mass/time_step; + sf->new_sfr += sp->mass / time_step; } /** @@ -57,9 +58,9 @@ INLINE static void star_formation_logger_log_new_spart( INLINE static void star_formation_logger_log_inactive_cell( struct star_formation_history *sf) { /* Initialize the stellar mass to zero */ - sf->stellar_mass=0.f; + sf->stellar_mass = 0.f; /*!initialize number of stars to zero*/ - sf->number_of_stars=0; + sf->number_of_stars = 0; /* Initialize the active SFR */ sf->new_sfr = 0.f; } @@ -72,14 +73,15 @@ INLINE static void star_formation_logger_init( struct star_formation_history *sfh) { /* Initialize the collecting SFH structure to zero */ sfh->new_sfr = 0.f; - sfh->number_of_stars=0; - sfh->stellar_mass=0.f; + sfh->number_of_stars = 0; + sfh->stellar_mass = 0.f; /* to be removed when the total quantities will be implemented */ - sfh->total_number_of_stars=0; - sfh->total_stellar_mass=0.f; + sfh->total_number_of_stars = 0; + sfh->total_stellar_mass = 0.f; } /** - * @brief Initialize the star formation history struct in the #engine (once only) + * @brief Initialize the star formation history struct in the #engine (once + * only) * * @param sfh the star_formation_history struct we want to initialize */ @@ -87,10 +89,10 @@ INLINE static void star_formation_logger_first_init( struct star_formation_history *sfh) { /* Initialize all values to zero */ sfh->new_sfr = 0.f; - sfh->stellar_mass=0.f; - sfh->number_of_stars=0; - sfh->total_number_of_stars=0; - sfh->total_stellar_mass=0.f; + sfh->stellar_mass = 0.f; + sfh->number_of_stars = 0; + sfh->total_number_of_stars = 0; + sfh->total_stellar_mass = 0.f; } /** * @brief add a star formation history struct to an other star formation history @@ -108,11 +110,10 @@ INLINE static void star_formation_logger_add( sf_update->new_sfr += sf_add->new_sfr; sf_update->number_of_stars += sf_add->number_of_stars; sf_update->stellar_mass += sf_add->stellar_mass; - sf_update->total_number_of_stars+=sf_add->total_number_of_stars; - sf_update->total_stellar_mass+=sf_add->total_stellar_mass; + sf_update->total_number_of_stars += sf_add->total_number_of_stars; + sf_update->total_stellar_mass += sf_add->total_stellar_mass; } - /** * @brief Write the final SFH to a file * @@ -127,8 +128,8 @@ INLINE static void star_formation_logger_write_to_log_file( FILE *fp, const double time, const double a, const double z, struct star_formation_history sf, const int step) { - fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14e\n", step, time, a, z, sf.number_of_stars, - sf.stellar_mass, sf.new_sfr); + fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14e\n", step, time, a, z, + sf.number_of_stars, sf.stellar_mass, sf.new_sfr); } /** * @brief Initialize the SFH logger file @@ -155,7 +156,8 @@ INLINE static void star_formation_logger_init_log_file( 1.f / phys_const->const_year / 1e6); fprintf(fp, "# (2) Scale factor (no unit)\n"); fprintf(fp, "# (3) Redshift (no unit)\n"); - fprintf(fp, "# (4) Number of stars formed in the current time step (no unit)\n"); + fprintf(fp, + "# (4) Number of stars formed in the current time step (no unit)\n"); fprintf(fp, "# (5) Stellar mass formed in the current time step.\n"); fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); fprintf(fp, "# Unit = %e solar mass\n", @@ -165,10 +167,9 @@ INLINE static void star_formation_logger_init_log_file( us->UnitMass_in_cgs / us->UnitTime_in_cgs); fprintf(fp, "# Unit = %e Msol/yr\n", phys_const->const_year / phys_const->const_solar_mass); - fprintf( - fp, - "# (0) (1) (2) (3) (4) (5) (6)\n"); - + fprintf(fp, + "# (0) (1) (2) (3) (4) " + " (5) (6)\n"); } /** @@ -184,9 +185,7 @@ INLINE static void star_formation_logger_init_log_file( */ INLINE static void star_formation_logger_log_active_part( const struct part *p, const struct xpart *xp, - struct star_formation_history *sf, const double dt_star) { - -} + struct star_formation_history *sf, const double dt_star) {} /** * @brief Add the SFR tracer to the total inactive SFR of this cell as long as @@ -200,7 +199,6 @@ INLINE static void star_formation_logger_log_active_part( */ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, - struct star_formation_history *sf) { -} + struct star_formation_history *sf) {} #endif /* SWIFT_EAGLE_STARFORMATION_LOGGER_H */ diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 4cff5a2cb..2dce8b6b2 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -25,7 +25,7 @@ struct star_formation_history { float new_sfr; /*! Total stellar mass (no reset) */ float total_stellar_mass; - /*! Stellar mass created in the current timestep */ + /*! Stellar mass created in the current timestep */ float stellar_mass; /*! Number of stars created in this timestep */ long int number_of_stars; diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 7f8270f59..617f60343 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -24,28 +24,31 @@ * data. */ struct star_formation_xpart_data { - /*!star formation rate (mass/(time*volume))*/ - double SFR; - /*! Estimation of local turbulence (squared) */ - float sigma2; - }; + /*!star formation rate (mass/(time*volume))*/ + double SFR; + /*! Estimation of local turbulence (squared) */ + float sigma2; +}; /* Starformation struct */ struct star_formation { - /*! Njeans number. We request that the SPH mass resolution is Njeans times smaller than the Jeans mass*/ - int Njeans; - /*!star formation efficency. If the particle can create a star, it happens with this probablity*/ - double star_formation_rate; - /*!do we include local turbulence*/ - int with_sigma; - /*!Maximum temperature to allow star formation* (should be about 10'000 or 30'000 K*/ - double Max_temperature; - /*!some other useful elements*/ - const struct hydro_props* restrict hydro_props; - /*!units*/ - const struct unit_system* restrict us; - /*! physical constants*/ - const struct phys_const* phys_const; - }; + /*! Njeans number. We request that the SPH mass resolution is Njeans times + * smaller than the Jeans mass*/ + int Njeans; + /*!star formation efficency. If the particle can create a star, it happens + * with this probablity*/ + double star_formation_rate; + /*!do we include local turbulence*/ + int with_sigma; + /*!Maximum temperature to allow star formation* (should be about 10'000 or + * 30'000 K*/ + double Max_temperature; + /*!some other useful elements*/ + const struct hydro_props* restrict hydro_props; + /*!units*/ + const struct unit_system* restrict us; + /*! physical constants*/ + const struct phys_const* phys_const; +}; #endif /* SWIFT_GEAR_STAR_FORMATION_STRUCT_H */ diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index af4f24eab..e9b9b3a06 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -78,7 +78,6 @@ INLINE static void stars_write_particles(const struct spart *sparts, list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, birth_time); - #ifdef DEBUG_INTERACTIONS_STARS list += *num_fields; diff --git a/src/stars/GEAR/stars_part.h b/src/stars/GEAR/stars_part.h index 1c7b573b4..4b133081d 100644 --- a/src/stars/GEAR/stars_part.h +++ b/src/stars/GEAR/stars_part.h @@ -55,10 +55,10 @@ struct spart { /*! Star mass */ float mass; - + /* Particle cutoff radius. */ float h; - + /*! Union for the birth time and birth scale factor */ union { @@ -68,10 +68,10 @@ struct spart { /*! Birth scale factor */ float birth_scale_factor; }; - + /*!birth density*/ float birth_density; - + /*!birth temperature*/ float birth_temperature; @@ -96,7 +96,6 @@ struct spart { /*! Chemistry structure */ struct chemistry_part_data chemistry_data; - #ifdef SWIFT_DEBUG_CHECKS diff --git a/src/tools.c b/src/tools.c index 7b56ac820..319160336 100644 --- a/src/tools.c +++ b/src/tools.c @@ -225,9 +225,10 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { if (r2 < hig2 && !part_is_inhibited(pj, e)) { /* Interact */ - runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, + a, H); } } } @@ -262,7 +263,8 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hj, pi->h, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dx, hj, pi->h, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, xpj, xpi, + a, H); } } } @@ -543,7 +545,8 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hi, hj, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dxi, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, xpi, xpj, a, + H); } /* Hit or miss? */ @@ -556,7 +559,8 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hj, hi, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dxi, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, xpj, xpi, a, + H); } } } -- GitLab From 7019623d590be6a8fa382440fb104c9445f1ccb0 Mon Sep 17 00:00:00 2001 From: loikki Date: Fri, 14 Jun 2019 17:18:54 +0200 Subject: [PATCH 04/16] GEAR:Remove xp in density --- src/runner.c | 21 +- src/runner_doiact.h | 250 ++++-------------- src/space.c | 3 +- src/star_formation/GEAR/star_formation.h | 7 +- src/star_formation/GEAR/star_formation_iact.h | 3 + src/star_formation/GEAR/star_formation_io.h | 3 +- .../GEAR/star_formation_logger.h | 19 +- .../GEAR/star_formation_logger_struct.h | 29 +- src/stars/GEAR/stars.h | 1 - src/stars/GEAR/stars_debug.h | 1 - src/stars/GEAR/stars_iact.h | 1 - src/stars/GEAR/stars_io.h | 1 - src/stars/GEAR/stars_part.h | 1 - src/tools.c | 20 +- 14 files changed, 95 insertions(+), 265 deletions(-) diff --git a/src/runner.c b/src/runner.c index 5fc9d46c1..f46c71bc4 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1185,8 +1185,7 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { hydro_props, us, cooling); /* Update the Star formation history */ - star_formation_logger_log_new_spart(sp, &c->stars.sfh, - e->time_step); + star_formation_logger_log_new_spart(sp, &c->stars.sfh); } } @@ -2126,7 +2125,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Finish the density calculation */ hydro_end_density(p, cosmo); chemistry_end_density(p, chemistry, cosmo); - star_formation_end_density(p, xp, star_formation, cosmo); + star_formation_end_density(p, star_formation, cosmo); /* Compute one step of the Newton-Raphson scheme */ const float n_sum = p->density.wcount * h_old_dim; @@ -2380,7 +2379,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Self-interaction? */ if (l->t->type == task_type_self) - runner_doself_subset_branch_density(r, finger, parts, xparts, pid, + runner_doself_subset_branch_density(r, finger, parts, pid, count); /* Otherwise, pair interaction? */ @@ -2388,16 +2387,16 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Left or right? */ if (l->t->ci == finger) - runner_dopair_subset_branch_density(r, finger, parts, xparts, - pid, count, l->t->cj); + runner_dopair_subset_branch_density(r, finger, parts, pid, + count, l->t->cj); else - runner_dopair_subset_branch_density(r, finger, parts, xparts, - pid, count, l->t->ci); + runner_dopair_subset_branch_density(r, finger, parts, pid, + count, l->t->ci); } /* Otherwise, sub-self interaction? */ else if (l->t->type == task_type_sub_self) - runner_dosub_subset_density(r, finger, parts, xparts, pid, count, + runner_dosub_subset_density(r, finger, parts, pid, count, NULL, 1); /* Otherwise, sub-pair interaction? */ @@ -2405,10 +2404,10 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Left or right? */ if (l->t->ci == finger) - runner_dosub_subset_density(r, finger, parts, xparts, pid, + runner_dosub_subset_density(r, finger, parts, pid, count, l->t->cj, 1); else - runner_dosub_subset_density(r, finger, parts, xparts, pid, + runner_dosub_subset_density(r, finger, parts, pid, count, l->t->ci, 1); } } diff --git a/src/runner_doiact.h b/src/runner_doiact.h index b1dbd4733..5f6f52db5 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -148,13 +148,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; -#endif struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif /* Cosmological terms */ const float a = cosmo->a; @@ -174,9 +168,6 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -193,9 +184,6 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -225,8 +213,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } if (r2 < hjg2 && pj_active) { @@ -238,8 +225,7 @@ void DOPAIR1_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } @@ -272,13 +258,7 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; -#endif struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif /* Cosmological terms */ const float a = cosmo->a; @@ -298,9 +278,6 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -317,9 +294,6 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -351,15 +325,14 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (pi_active) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (pj_active) { @@ -370,8 +343,7 @@ void DOPAIR2_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -405,18 +377,12 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; -#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -433,9 +399,6 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -468,15 +431,14 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -487,8 +449,7 @@ void DOSELF1_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in cj. */ @@ -521,18 +482,12 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; -#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -549,9 +504,6 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -584,15 +536,14 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -603,8 +554,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in cj. */ @@ -629,7 +579,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { */ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, struct part *restrict parts_i, - struct xpart *restrict xparts_i, int *restrict ind, + int *restrict ind, int count, struct cell *restrict cj, const double *shift) { @@ -640,9 +590,6 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif /* Cosmological terms */ const float a = cosmo->a; @@ -653,9 +600,6 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; -#endif double pix[3]; for (int k = 0; k < 3; k++) pix[k] = pi->x[k] - shift[k]; const float hi = pi->h; @@ -671,9 +615,6 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -700,8 +641,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, pj->h, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -726,7 +666,7 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, */ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, struct part *restrict parts_i, - struct xpart *restrict xparts_i, int *restrict ind, + int *restrict ind, int count, struct cell *restrict cj, const int sid, const int flipped, const double *shift) { @@ -737,9 +677,6 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, const int count_j = cj->hydro.count; struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif /* Cosmological terms */ const float a = cosmo->a; @@ -757,9 +694,6 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; -#endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); const double piz = pi->x[2] - (shift[2]); @@ -773,9 +707,6 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -804,8 +735,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -820,9 +750,6 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[ind[pid]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[ind[pid]]; -#endif const double pix = pi->x[0] - (shift[0]); const double piy = pi->x[1] - (shift[1]); const double piz = pi->x[2] - (shift[2]); @@ -836,9 +763,6 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpj = &xparts_j[sort_j[pjd].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -867,8 +791,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -892,7 +815,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, */ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, struct part *restrict parts_i, - struct xpart *restrict xparts_i, int *restrict ind, + int *restrict ind, int count, struct cell *restrict cj) { const struct engine *e = r->e; @@ -928,16 +851,16 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, #endif #if defined(SWIFT_USE_NAIVE_INTERACTIONS) - DOPAIR_SUBSET_NAIVE(r, ci, parts_i, xparts_i, ind, count, cj, shift); + DOPAIR_SUBSET_NAIVE(r, ci, parts_i, ind, count, cj, shift); #elif defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) if (sort_is_face(sid)) runner_dopair_subset_density_vec(r, ci, parts_i, ind, count, cj, sid, flipped, shift); else - DOPAIR_SUBSET(r, ci, parts_i, xparts_i, ind, count, cj, sid, flipped, + DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); #else - DOPAIR_SUBSET(r, ci, parts_i, xparts_i, ind, count, cj, sid, flipped, shift); + DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); #endif } @@ -952,7 +875,7 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, struct xpart *restrict xparts, + struct part *restrict parts, int *restrict ind, int count) { const struct engine *e = r->e; @@ -966,17 +889,11 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, const int count_i = ci->hydro.count; struct part *restrict parts_j = ci->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = ci->hydro.xparts; -#endif /* Loop over the parts in ci. */ for (int pid = 0; pid < count; pid++) { /* Get a hold of the ith part in ci. */ struct part *pi = &parts[ind[pid]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[ind[pid]]; -#endif const float pix[3] = {(float)(pi->x[0] - ci->loc[0]), (float)(pi->x[1] - ci->loc[1]), (float)(pi->x[2] - ci->loc[2])}; @@ -992,9 +909,6 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts_j[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1022,8 +936,7 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -1044,13 +957,13 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, */ void DOSELF_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, struct part *restrict parts, - struct xpart *restrict xparts, int *restrict ind, + int *restrict ind, int count) { #if defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) runner_doself_subset_density_vec(r, ci, parts, ind, count); #else - DOSELF_SUBSET(r, ci, parts, xparts, ind, count); + DOSELF_SUBSET(r, ci, parts, ind, count); #endif } @@ -1098,13 +1011,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; -#endif struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif const double di_max = sort_i[count_i - 1].d - rshift; const double dj_min = sort_j[0].d; const float dx_max = (ci->hydro.dx_max_sort + cj->hydro.dx_max_sort); @@ -1121,9 +1028,6 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *restrict pi = &parts_i[sort_i[pid].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xpi = &xparts_i[sort_i[pid].i]; -#endif const float hi = pi->h; /* Skip inactive particles */ @@ -1144,9 +1048,6 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1200,8 +1101,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the parts in cj. */ @@ -1216,9 +1116,6 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; -#endif const float hj = pj->h; /* Skip inactive particles */ @@ -1239,9 +1136,6 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1295,8 +1189,7 @@ void DOPAIR1(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the parts in ci. */ @@ -1443,13 +1336,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, const int count_i = ci->hydro.count; const int count_j = cj->hydro.count; struct part *restrict parts_i = ci->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_i = ci->hydro.xparts; -#endif struct part *restrict parts_j = cj->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts_j = cj->hydro.xparts; -#endif /* Cosmological terms */ const float a = cosmo->a; @@ -1516,9 +1403,6 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the ith part in ci. */ struct part *pi = &parts_i[sort_i[pid].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1605,8 +1489,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over the active parts in cj. */ @@ -1619,9 +1502,6 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pj */ struct part *pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1680,14 +1560,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } @@ -1704,9 +1583,6 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Get a hold of the jth part in cj. */ struct part *pj = &parts_j[sort_j[pjd].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts_j[sort_j[pjd].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -1793,8 +1669,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } /* loop over the active parts in ci. */ @@ -1808,9 +1683,6 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, /* Recover pi */ struct part *pi = &parts_i[sort_i[pid].i]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts_i[sort_i[pid].i]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -1870,14 +1742,13 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, IACT(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, H); + runner_iact_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } else { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -2001,9 +1872,6 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { TIMER_TIC; struct part *restrict parts = c->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; -#endif const int count = c->hydro.count; /* Set up indt. */ @@ -2027,9 +1895,6 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -2048,9 +1913,6 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[indt[pjd]]; -#endif const float hj = pj->h; #ifdef SWIFT_DEBUG_CHECKS @@ -2075,8 +1937,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over all other particles. */ @@ -2093,9 +1954,6 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -2131,15 +1989,14 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doi) { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else if (doj) { @@ -2149,8 +2006,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } @@ -2212,9 +2068,6 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { TIMER_TIC; struct part *restrict parts = c->hydro.parts; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *restrict xparts = c->hydro.xparts; -#endif const int count = c->hydro.count; /* Set up indt. */ @@ -2238,9 +2091,6 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the ith particle. */ struct part *restrict pi = &parts[pid]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpi = &xparts[pid]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pi, e)) continue; @@ -2259,9 +2109,6 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[indt[pjd]]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[indt[pjd]]; -#endif const float hj = pj->h; /* Compute the pairwise distance. */ @@ -2286,8 +2133,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT_NONSYM(r2, dx, hj, hi, pj, pi, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dx, hj, hi, pj, pi, a, H); #endif } } /* loop over all other particles. */ @@ -2304,9 +2150,6 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Get a pointer to the jth particle. */ struct part *restrict pj = &parts[pjd]; -#if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) - struct xpart *xpj = &xparts[pjd]; -#endif /* Skip inhibited particles. */ if (part_is_inhibited(pj, e)) continue; @@ -2337,14 +2180,13 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { IACT(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, a, H); + runner_iact_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } else { IACT_NONSYM(r2, dx, hi, hj, pi, pj, a, H); #if (FUNCTION_TASK_LOOP == TASK_LOOP_DENSITY) runner_iact_nonsym_chemistry(r2, dx, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, xpi, xpj, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, hj, pi, pj, a, H); #endif } } @@ -2601,7 +2443,7 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) { } void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, - struct xpart *xparts, int *ind, int count, struct cell *cj, + int *ind, int count, struct cell *cj, int gettimer) { const struct engine *e = r->e; @@ -2637,16 +2479,16 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, if (cell_can_recurse_in_self_hydro_task(ci)) { /* Loop over all progeny. */ - DOSUB_SUBSET(r, sub, parts, xparts, ind, count, NULL, 0); + DOSUB_SUBSET(r, sub, parts, ind, count, NULL, 0); for (int j = 0; j < 8; j++) if (ci->progeny[j] != sub && ci->progeny[j] != NULL) - DOSUB_SUBSET(r, sub, parts, xparts, ind, count, ci->progeny[j], 0); + DOSUB_SUBSET(r, sub, parts, ind, count, ci->progeny[j], 0); } /* Otherwise, compute self-interaction. */ else - DOSELF_SUBSET_BRANCH(r, ci, parts, xparts, ind, count); + DOSELF_SUBSET_BRANCH(r, ci, parts, ind, count); } /* self-interaction. */ /* Otherwise, it's a pair interaction. */ @@ -2665,10 +2507,10 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, const int pid = csp->pairs[k].pid; const int pjd = csp->pairs[k].pjd; if (ci->progeny[pid] == sub && cj->progeny[pjd] != NULL) - DOSUB_SUBSET(r, ci->progeny[pid], parts, xparts, ind, count, + DOSUB_SUBSET(r, ci->progeny[pid], parts, ind, count, cj->progeny[pjd], 0); if (ci->progeny[pid] != NULL && cj->progeny[pjd] == sub) - DOSUB_SUBSET(r, cj->progeny[pjd], parts, xparts, ind, count, + DOSUB_SUBSET(r, cj->progeny[pjd], parts, ind, count, ci->progeny[pid], 0); } } @@ -2679,7 +2521,7 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, /* Do any of the cells need to be drifted first? */ if (!cell_are_part_drifted(cj, e)) error("Cell should be drifted!"); - DOPAIR_SUBSET_BRANCH(r, ci, parts, xparts, ind, count, cj); + DOPAIR_SUBSET_BRANCH(r, ci, parts, ind, count, cj); } } /* otherwise, pair interaction. */ diff --git a/src/space.c b/src/space.c index 250af5efa..d9b6dbdb0 100644 --- a/src/space.c +++ b/src/space.c @@ -4082,8 +4082,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count, chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[k], &xp[k]); /* Also initialise the star formation */ - star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k], - &xp[k]); + star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k]); /* And the cooling */ cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[k], &xp[k]); diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index c740b949d..ab0064f06 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2018 Folkert Nobels (nobels@strw.leidenuniv.nl) + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -352,15 +353,13 @@ star_formation_part_has_no_neighbours(struct part* restrict p, * @param cosmo The current cosmological model. * @param data The global star_formation information used for this run. * @param p Pointer to the particle data. - * @param xp Pointer to the extended particle data. */ __attribute__((always_inline)) INLINE static void star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct unit_system* restrict us, const struct cosmology* restrict cosmo, const struct star_formation* data, - struct part* restrict p, - struct xpart* restrict xp) { + struct part* restrict p) { xp->sf_data.sigma2 = 0.f; } diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index e1310a41f..18da287f3 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -1,4 +1,7 @@ /******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index 788b60273..ec0713be1 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2018 Folkert Nobels (nobels@strw.leidenuniv.nl) + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 3ab808c93..4a3789517 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2019 Folkert Nobels (nobels@strw.leidenuniv.nl) + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -16,8 +17,8 @@ * along with this program. If not, see . * *******************************************************************************/ -#ifndef SWIFT_EAGLE_STARFORMATION_LOGGER_H -#define SWIFT_EAGLE_STARFORMATION_LOGGER_H +#ifndef SWIFT_GEAR_STARFORMATION_LOGGER_H +#define SWIFT_GEAR_STARFORMATION_LOGGER_H /* Some standard headers */ #include @@ -28,25 +29,23 @@ #include "part.h" #include "star_formation_logger_struct.h" #include "units.h" + + /** * @brief Update the stellar mass in the current cell after creating * the new star particle spart sp + * * @param time_step, the current time step of the simulation * @param sp new created star particle * @param sf the star_formation_history struct of the current cell */ INLINE static void star_formation_logger_log_new_spart( - const struct spart *sp, struct star_formation_history *sf, - const double time_step) { + const struct spart *sp, struct star_formation_history *sf) { /* Add mass of created sparticle to the total stellar mass in this cell*/ sf->stellar_mass += sp->mass; - sf->total_stellar_mass += sp->mass; /* Increase the number of stars */ sf->number_of_stars += 1; - sf->total_number_of_stars += 1; - /* Approximation of the SFR */ - sf->new_sfr += sp->mass / time_step; } /** @@ -201,4 +200,4 @@ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, struct star_formation_history *sf) {} -#endif /* SWIFT_EAGLE_STARFORMATION_LOGGER_H */ +#endif /* SWIFT_GEAR_STARFORMATION_LOGGER_H */ diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 2dce8b6b2..229344b4f 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. - * Copyright (c) 2019 Folkert Nobels (nobels@strw.leidenuniv.nl) + * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) + * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -16,21 +17,25 @@ * along with this program. If not, see . * ******************************************************************************/ -#ifndef SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H -#define SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H +#ifndef SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H +#define SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H -/* Starformation history struct */ +/** + * Structure containing the global star formation information. + */ struct star_formation_history { - /*! Total current star formation rate (new mass divided by timestep) */ - float new_sfr; - /*! Total stellar mass (no reset) */ + /*! Total stellar mass from the begining of the simulation */ float total_stellar_mass; - /*! Stellar mass created in the current timestep */ - float stellar_mass; - /*! Number of stars created in this timestep */ - long int number_of_stars; + /*! Total number of stars */ long int total_number_of_stars; + + /*! Stellar mass created in the current timestep */ + float new_stellar_mass; + + /*! Number of stars created in this timestep */ + long int number_new_stars; + }; -#endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */ +#endif /* SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H */ diff --git a/src/stars/GEAR/stars.h b/src/stars/GEAR/stars.h index e29602c12..467aaa164 100644 --- a/src/stars/GEAR/stars.h +++ b/src/stars/GEAR/stars.h @@ -1,7 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) - * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/stars/GEAR/stars_debug.h b/src/stars/GEAR/stars_debug.h index 8fc917f30..41953367f 100644 --- a/src/stars/GEAR/stars_debug.h +++ b/src/stars/GEAR/stars_debug.h @@ -1,7 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) - * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/stars/GEAR/stars_iact.h b/src/stars/GEAR/stars_iact.h index c1f0904e5..c7bda43fc 100644 --- a/src/stars/GEAR/stars_iact.h +++ b/src/stars/GEAR/stars_iact.h @@ -1,7 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) - * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index e9b9b3a06..fd8759351 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -1,7 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) - * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/stars/GEAR/stars_part.h b/src/stars/GEAR/stars_part.h index 4b133081d..3e9cfd020 100644 --- a/src/stars/GEAR/stars_part.h +++ b/src/stars/GEAR/stars_part.h @@ -1,7 +1,6 @@ /******************************************************************************* * This file is part of SWIFT. * Coypright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch) - * 2019 Fabien Jeanquartier (fabien.jeanquartier@epfl.ch) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published diff --git a/src/tools.c b/src/tools.c index 319160336..bd467e184 100644 --- a/src/tools.c +++ b/src/tools.c @@ -190,7 +190,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { float r2, hi, hj, hig2, hjg2, dx[3]; struct part *pi, *pj; - struct xpart *xpi, *xpj; const double dim[3] = {r->e->s->dim[0], r->e->s->dim[1], r->e->s->dim[2]}; const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -201,7 +200,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; - xpi = &ci->hydro.xparts[i]; hi = pi->h; hig2 = hi * hi * kernel_gamma2; @@ -211,7 +209,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int j = 0; j < cj->hydro.count; ++j) { pj = &cj->hydro.parts[j]; - xpj = &cj->hydro.xparts[j]; /* Pairwise distance */ r2 = 0.0f; @@ -227,8 +224,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dx, hi, pj->h, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, xpi, xpj, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hi, pj->h, pi, pj, a, H); } } } @@ -237,7 +233,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int j = 0; j < cj->hydro.count; ++j) { pj = &cj->hydro.parts[j]; - xpj = &cj->hydro.xparts[j]; hj = pj->h; hjg2 = hj * hj * kernel_gamma2; @@ -247,7 +242,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; - xpi = &ci->hydro.xparts[i]; /* Pairwise distance */ r2 = 0.0f; @@ -263,8 +257,7 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) { /* Interact */ runner_iact_nonsym_density(r2, dx, hj, pi->h, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dx, hj, pi->h, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, xpj, xpi, - a, H); + runner_iact_nonsym_star_formation(r2, dx, hj, pi->h, pj, pi, a, H); } } } @@ -509,7 +502,6 @@ void pairs_all_stars_density(struct runner *r, struct cell *ci, void self_all_density(struct runner *r, struct cell *ci) { float r2, hi, hj, hig2, hjg2, dxi[3]; //, dxj[3]; struct part *pi, *pj; - struct xpart *xpi, *xpj; const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; const float a = cosmo->a; @@ -519,14 +511,12 @@ void self_all_density(struct runner *r, struct cell *ci) { for (int i = 0; i < ci->hydro.count; ++i) { pi = &ci->hydro.parts[i]; - xpi = &ci->hydro.xparts[i]; hi = pi->h; hig2 = hi * hi * kernel_gamma2; for (int j = i + 1; j < ci->hydro.count; ++j) { pj = &ci->hydro.parts[j]; - xpj = &ci->hydro.xparts[j]; hj = pj->h; hjg2 = hj * hj * kernel_gamma2; @@ -545,8 +535,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hi, hj, pi, pj, a, H); runner_iact_nonsym_chemistry(r2, dxi, hi, hj, pi, pj, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, xpi, xpj, a, - H); + runner_iact_nonsym_star_formation(r2, dxi, hi, hj, pi, pj, a, H); } /* Hit or miss? */ @@ -559,8 +548,7 @@ void self_all_density(struct runner *r, struct cell *ci) { /* Interact */ runner_iact_nonsym_density(r2, dxi, hj, hi, pj, pi, a, H); runner_iact_nonsym_chemistry(r2, dxi, hj, hi, pj, pi, a, H); - runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, xpj, xpi, a, - H); + runner_iact_nonsym_star_formation(r2, dxi, hj, hi, pj, pi, a, H); } } } -- GitLab From 27dc998950f8f92829c976b20afee8895ee1b915 Mon Sep 17 00:00:00 2001 From: loikki Date: Fri, 14 Jun 2019 18:49:53 +0200 Subject: [PATCH 05/16] GEAR: more cleaning --- src/collectgroup.c | 3 +- src/engine.c | 5 ++ src/runner.c | 15 ++-- src/runner_doiact.h | 33 +++---- src/space.c | 4 +- .../GEAR/star_formation_logger.h | 89 ++++++++++++------- .../GEAR/star_formation_logger_struct.h | 2 +- 7 files changed, 85 insertions(+), 66 deletions(-) diff --git a/src/collectgroup.c b/src/collectgroup.c index d17608d67..e75db63f8 100644 --- a/src/collectgroup.c +++ b/src/collectgroup.c @@ -122,7 +122,8 @@ void collectgroup1_apply(const struct collectgroup1 *grp1, struct engine *e) { e->total_nr_cells = grp1->total_nr_cells; e->total_nr_tasks = grp1->total_nr_tasks; e->tasks_per_cell_max = grp1->tasks_per_cell_max; - e->sfh = grp1->sfh; + + star_formation_logger_add_to_engine(e->sfh, grp1->sfh); } /** diff --git a/src/engine.c b/src/engine.c index 8f14cfd00..d5b7d976b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5062,6 +5062,11 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, parser_get_opt_param_double(params, "FOF:delta_time", -1.); } + /* Initialize the star formation history structure */ + if (e->policy & engine_policy_star_formation) { + star_formation_logger_first_init(e->sfh); + } + engine_init_output_lists(e, params); } diff --git a/src/runner.c b/src/runner.c index f46c71bc4..6e562f1fe 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2379,8 +2379,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Self-interaction? */ if (l->t->type == task_type_self) - runner_doself_subset_branch_density(r, finger, parts, pid, - count); + runner_doself_subset_branch_density(r, finger, parts, pid, count); /* Otherwise, pair interaction? */ else if (l->t->type == task_type_pair) { @@ -2396,19 +2395,19 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Otherwise, sub-self interaction? */ else if (l->t->type == task_type_sub_self) - runner_dosub_subset_density(r, finger, parts, pid, count, - NULL, 1); + runner_dosub_subset_density(r, finger, parts, pid, count, NULL, + 1); /* Otherwise, sub-pair interaction? */ else if (l->t->type == task_type_sub_pair) { /* Left or right? */ if (l->t->ci == finger) - runner_dosub_subset_density(r, finger, parts, pid, - count, l->t->cj, 1); + runner_dosub_subset_density(r, finger, parts, pid, count, + l->t->cj, 1); else - runner_dosub_subset_density(r, finger, parts, pid, - count, l->t->ci, 1); + runner_dosub_subset_density(r, finger, parts, pid, count, + l->t->ci, 1); } } } diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 5f6f52db5..28f001fb3 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -578,8 +578,7 @@ void DOSELF2_NAIVE(struct runner *r, struct cell *restrict c) { * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, - int *restrict ind, + struct part *restrict parts_i, int *restrict ind, int count, struct cell *restrict cj, const double *shift) { @@ -665,10 +664,9 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, * @param shift The shift vector to apply to the particles in ci. */ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, - int *restrict ind, - int count, struct cell *restrict cj, const int sid, - const int flipped, const double *shift) { + struct part *restrict parts_i, int *restrict ind, int count, + struct cell *restrict cj, const int sid, const int flipped, + const double *shift) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -814,8 +812,7 @@ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, * @param cj The second #cell. */ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts_i, - int *restrict ind, + struct part *restrict parts_i, int *restrict ind, int count, struct cell *restrict cj) { const struct engine *e = r->e; @@ -857,8 +854,7 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, runner_dopair_subset_density_vec(r, ci, parts_i, ind, count, cj, sid, flipped, shift); else - DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, - shift); + DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); #else DOPAIR_SUBSET(r, ci, parts_i, ind, count, cj, sid, flipped, shift); #endif @@ -875,8 +871,7 @@ void DOPAIR_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, - int *restrict ind, int count) { + struct part *restrict parts, int *restrict ind, int count) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -956,8 +951,7 @@ void DOSELF_SUBSET(struct runner *r, struct cell *restrict ci, * @param count The number of particles in @c ind. */ void DOSELF_SUBSET_BRANCH(struct runner *r, struct cell *restrict ci, - struct part *restrict parts, - int *restrict ind, + struct part *restrict parts, int *restrict ind, int count) { #if defined(WITH_VECTORIZATION) && defined(GADGET2_SPH) @@ -2443,8 +2437,7 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) { } void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, - int *ind, int count, struct cell *cj, - int gettimer) { + int *ind, int count, struct cell *cj, int gettimer) { const struct engine *e = r->e; struct space *s = e->s; @@ -2507,11 +2500,11 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, const int pid = csp->pairs[k].pid; const int pjd = csp->pairs[k].pjd; if (ci->progeny[pid] == sub && cj->progeny[pjd] != NULL) - DOSUB_SUBSET(r, ci->progeny[pid], parts, ind, count, - cj->progeny[pjd], 0); + DOSUB_SUBSET(r, ci->progeny[pid], parts, ind, count, cj->progeny[pjd], + 0); if (ci->progeny[pid] != NULL && cj->progeny[pjd] == sub) - DOSUB_SUBSET(r, cj->progeny[pjd], parts, ind, count, - ci->progeny[pid], 0); + DOSUB_SUBSET(r, cj->progeny[pjd], parts, ind, count, ci->progeny[pid], + 0); } } diff --git a/src/space.c b/src/space.c index d9b6dbdb0..aa04571c9 100644 --- a/src/space.c +++ b/src/space.c @@ -4082,7 +4082,7 @@ void space_first_init_parts_mapper(void *restrict map_data, int count, chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[k], &xp[k]); /* Also initialise the star formation */ - star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k]); + star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k], &xp[k]); /* And the cooling */ cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[k], &xp[k]); @@ -4364,7 +4364,7 @@ void space_init_parts_mapper(void *restrict map_data, int count, for (int k = 0; k < count; k++) { hydro_init_part(&parts[k], hs); chemistry_init_part(&parts[k], e->chemistry); - star_formation_init_part(&parts[k], &xparts[k], e->star_formation); + star_formation_init_part(&parts[k], e->star_formation); tracers_after_init(&parts[k], &xparts[k], e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 4a3789517..3c699d26c 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -32,8 +32,8 @@ /** - * @brief Update the stellar mass in the current cell after creating - * the new star particle spart sp + * @brief Update the stellar quantities in the current cell after creating + * the new star particle spart sp. * * @param time_step, the current time step of the simulation * @param sp new created star particle @@ -42,10 +42,13 @@ INLINE static void star_formation_logger_log_new_spart( const struct spart *sp, struct star_formation_history *sf) { - /* Add mass of created sparticle to the total stellar mass in this cell*/ + /* Add mass of created sparticle to the total stellar mass in this cell */ sf->stellar_mass += sp->mass; + /* Increase the number of stars */ sf->number_of_stars += 1; + + /* No need to deal with the integrated quantities, only the engine's one is updated */ } /** @@ -56,12 +59,13 @@ INLINE static void star_formation_logger_log_new_spart( */ INLINE static void star_formation_logger_log_inactive_cell( struct star_formation_history *sf) { + /* Initialize the stellar mass to zero */ sf->stellar_mass = 0.f; - /*!initialize number of stars to zero*/ + + /* initialize number of stars to zero*/ sf->number_of_stars = 0; - /* Initialize the active SFR */ - sf->new_sfr = 0.f; + } /** * @brief Initialize the star formation history structure in the #engine @@ -71,28 +75,24 @@ INLINE static void star_formation_logger_log_inactive_cell( INLINE static void star_formation_logger_init( struct star_formation_history *sfh) { /* Initialize the collecting SFH structure to zero */ - sfh->new_sfr = 0.f; - sfh->number_of_stars = 0; - sfh->stellar_mass = 0.f; - /* to be removed when the total quantities will be implemented */ - sfh->total_number_of_stars = 0; - sfh->total_stellar_mass = 0.f; + sfh->new_stellar_mass = 0.f; + sfh->number_new_stars = 0; } /** - * @brief Initialize the star formation history struct in the #engine (once - * only) + * @brief Initialize the star formation history struct in the #engine when + * starting the simulation. * * @param sfh the star_formation_history struct we want to initialize */ INLINE static void star_formation_logger_first_init( struct star_formation_history *sfh) { /* Initialize all values to zero */ - sfh->new_sfr = 0.f; - sfh->stellar_mass = 0.f; - sfh->number_of_stars = 0; - sfh->total_number_of_stars = 0; + sfh->new_stellar_mass = 0.f; + sfh->number_new_stars = 0; + sfh->total_number_stars = 0; sfh->total_stellar_mass = 0.f; } + /** * @brief add a star formation history struct to an other star formation history * struct @@ -106,15 +106,36 @@ INLINE static void star_formation_logger_add( const struct star_formation_history *sf_add) { /* Update the SFH structure */ - sf_update->new_sfr += sf_add->new_sfr; - sf_update->number_of_stars += sf_add->number_of_stars; - sf_update->stellar_mass += sf_add->stellar_mass; - sf_update->total_number_of_stars += sf_add->total_number_of_stars; - sf_update->total_stellar_mass += sf_add->total_stellar_mass; + sf_update->number_new_stars += sf_add->number_new_stars; + sf_update->new_stellar_mass += sf_add->new_stellar_mass; +} + +/** + * @brief add a star formation history struct to an other star formation history + * struct + * + * @param sf_add the star formation struct which we want to add to the star + * formation history + * @param sf_update the star formation structure which we want to update + */ +INLINE static void star_formation_logger_add_to_engine( + struct star_formation_history *sf_update, + const struct star_formation_history *sf_add) { + + /* Remove self contribution */ + sf_update->total_number_stars -= sf_update->number_new_stars; + sf_update->total_stellar_mass -= sf_update->new_stellar_mass; + + /* Update the SFH structure */ + sf_update->number_new_stars += sf_add->number_new_stars; + sf_update->new_stellar_mass += sf_add->new_stellar_mass; + sf_update->total_number_stars += sf_add->number_new_stars; + sf_update->total_stellar_mass += sf_add->new_stellar_mass; + } /** - * @brief Write the final SFH to a file +za * @brief Write the final SFH to a file * * @param fp The file to write to. * @param time the simulation time (time since Big Bang) in internal units. @@ -127,8 +148,8 @@ INLINE static void star_formation_logger_write_to_log_file( FILE *fp, const double time, const double a, const double z, struct star_formation_history sf, const int step) { - fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14e\n", step, time, a, z, - sf.number_of_stars, sf.stellar_mass, sf.new_sfr); + fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, + sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, sf.new_stellar_mass); } /** * @brief Initialize the SFH logger file @@ -156,19 +177,19 @@ INLINE static void star_formation_logger_init_log_file( fprintf(fp, "# (2) Scale factor (no unit)\n"); fprintf(fp, "# (3) Redshift (no unit)\n"); fprintf(fp, - "# (4) Number of stars formed in the current time step (no unit)\n"); - fprintf(fp, "# (5) Stellar mass formed in the current time step.\n"); + "# (4) Total number of stars formed in the simulation (no unit)\n"); + fprintf(fp, "# (5) Total stellar mass formed in the simulation.\n"); + fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); + fprintf(fp, "# Unit = %e solar mass\n", + 1.f / phys_const->const_solar_mass); + fprintf(fp, "# (6) Number of stars formed in the current time step (no unit).\n"); + fprintf(fp, "# (7) Mass of stars formed in the current time step.\n"); fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); fprintf(fp, "# Unit = %e solar mass\n", 1.f / phys_const->const_solar_mass); - fprintf(fp, "# (6) Star formation rate in the current time step.\n"); - fprintf(fp, "# Unit = %e gram/s\n", - us->UnitMass_in_cgs / us->UnitTime_in_cgs); - fprintf(fp, "# Unit = %e Msol/yr\n", - phys_const->const_year / phys_const->const_solar_mass); fprintf(fp, "# (0) (1) (2) (3) (4) " - " (5) (6)\n"); + " (5) (6) (7)\n"); } /** diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 229344b4f..7939bb12e 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -28,7 +28,7 @@ struct star_formation_history { float total_stellar_mass; /*! Total number of stars */ - long int total_number_of_stars; + long int total_number_stars; /*! Stellar mass created in the current timestep */ float new_stellar_mass; -- GitLab From bae5999025d7df7b860c314909865ef101f33bb1 Mon Sep 17 00:00:00 2001 From: loikki Date: Sun, 16 Jun 2019 19:36:41 +0200 Subject: [PATCH 06/16] Format --- src/runner.c | 10 +++++----- src/runner_doiact.h | 10 +++++----- src/space.c | 3 ++- src/star_formation/GEAR/star_formation_logger.h | 12 ++++++------ .../GEAR/star_formation_logger_struct.h | 1 - 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/runner.c b/src/runner.c index 6e562f1fe..644d7f617 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2387,16 +2387,16 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Left or right? */ if (l->t->ci == finger) runner_dopair_subset_branch_density(r, finger, parts, pid, - count, l->t->cj); + count, l->t->cj); else runner_dopair_subset_branch_density(r, finger, parts, pid, - count, l->t->ci); + count, l->t->ci); } /* Otherwise, sub-self interaction? */ else if (l->t->type == task_type_sub_self) runner_dosub_subset_density(r, finger, parts, pid, count, NULL, - 1); + 1); /* Otherwise, sub-pair interaction? */ else if (l->t->type == task_type_sub_pair) { @@ -2404,10 +2404,10 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Left or right? */ if (l->t->ci == finger) runner_dosub_subset_density(r, finger, parts, pid, count, - l->t->cj, 1); + l->t->cj, 1); else runner_dosub_subset_density(r, finger, parts, pid, count, - l->t->ci, 1); + l->t->ci, 1); } } } diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 28f001fb3..1a39c8d49 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -665,8 +665,8 @@ void DOPAIR_SUBSET_NAIVE(struct runner *r, struct cell *restrict ci, */ void DOPAIR_SUBSET(struct runner *r, struct cell *restrict ci, struct part *restrict parts_i, int *restrict ind, int count, - struct cell *restrict cj, const int sid, const int flipped, - const double *shift) { + struct cell *restrict cj, const int sid, const int flipped, + const double *shift) { const struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; @@ -2437,7 +2437,7 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) { } void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, - int *ind, int count, struct cell *cj, int gettimer) { + int *ind, int count, struct cell *cj, int gettimer) { const struct engine *e = r->e; struct space *s = e->s; @@ -2501,10 +2501,10 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts, const int pjd = csp->pairs[k].pjd; if (ci->progeny[pid] == sub && cj->progeny[pjd] != NULL) DOSUB_SUBSET(r, ci->progeny[pid], parts, ind, count, cj->progeny[pjd], - 0); + 0); if (ci->progeny[pid] != NULL && cj->progeny[pjd] == sub) DOSUB_SUBSET(r, cj->progeny[pjd], parts, ind, count, ci->progeny[pid], - 0); + 0); } } diff --git a/src/space.c b/src/space.c index aa04571c9..49c714743 100644 --- a/src/space.c +++ b/src/space.c @@ -4082,7 +4082,8 @@ void space_first_init_parts_mapper(void *restrict map_data, int count, chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[k], &xp[k]); /* Also initialise the star formation */ - star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k], &xp[k]); + star_formation_first_init_part(phys_const, us, cosmo, star_formation, &p[k], + &xp[k]); /* And the cooling */ cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[k], &xp[k]); diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 3c699d26c..22a65eed8 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -30,7 +30,6 @@ #include "star_formation_logger_struct.h" #include "units.h" - /** * @brief Update the stellar quantities in the current cell after creating * the new star particle spart sp. @@ -48,7 +47,8 @@ INLINE static void star_formation_logger_log_new_spart( /* Increase the number of stars */ sf->number_of_stars += 1; - /* No need to deal with the integrated quantities, only the engine's one is updated */ + /* No need to deal with the integrated quantities, only the engine's one is + * updated */ } /** @@ -65,7 +65,6 @@ INLINE static void star_formation_logger_log_inactive_cell( /* initialize number of stars to zero*/ sf->number_of_stars = 0; - } /** * @brief Initialize the star formation history structure in the #engine @@ -131,7 +130,6 @@ INLINE static void star_formation_logger_add_to_engine( sf_update->new_stellar_mass += sf_add->new_stellar_mass; sf_update->total_number_stars += sf_add->number_new_stars; sf_update->total_stellar_mass += sf_add->new_stellar_mass; - } /** @@ -149,7 +147,8 @@ INLINE static void star_formation_logger_write_to_log_file( struct star_formation_history sf, const int step) { fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, - sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, sf.new_stellar_mass); + sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, + sf.new_stellar_mass); } /** * @brief Initialize the SFH logger file @@ -182,7 +181,8 @@ INLINE static void star_formation_logger_init_log_file( fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); fprintf(fp, "# Unit = %e solar mass\n", 1.f / phys_const->const_solar_mass); - fprintf(fp, "# (6) Number of stars formed in the current time step (no unit).\n"); + fprintf(fp, + "# (6) Number of stars formed in the current time step (no unit).\n"); fprintf(fp, "# (7) Mass of stars formed in the current time step.\n"); fprintf(fp, "# Unit = %e gram\n", us->UnitMass_in_cgs); fprintf(fp, "# Unit = %e solar mass\n", diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 7939bb12e..718066fd6 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -35,7 +35,6 @@ struct star_formation_history { /*! Number of stars created in this timestep */ long int number_new_stars; - }; #endif /* SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H */ -- GitLab From e5d6d217f179af050328461768042add319b5f66 Mon Sep 17 00:00:00 2001 From: loikki Date: Sun, 16 Jun 2019 20:31:50 +0200 Subject: [PATCH 07/16] GEAR: star formation fully implemented --- src/cooling/grackle/cooling.h | 36 ++- src/star_formation/GEAR/star_formation.h | 224 +++++++----------- src/star_formation/GEAR/star_formation_iact.h | 49 ++-- .../GEAR/star_formation_logger.h | 4 +- .../GEAR/star_formation_struct.h | 35 ++- 5 files changed, 170 insertions(+), 178 deletions(-) diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index 1abbe5d38..57f4b146c 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -697,6 +697,17 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( xp->cooling_data.radiated_energy -= hydro_get_mass(p) * cooling_du_dt * dt; } +/** + * @brief Compute the temperature of a #part based on the cooling function. + * + * @param phys_const #phys_const data structure. + * @param hydro_props The properties of the hydro scheme. + * @param us The internal system of units. + * @param cosmo #cosmology data structure. + * @param cooling #cooling_function_data struct. + * @param p #part data. + * @param xp Pointer to the #xpart data. + */ static INLINE float cooling_get_temperature( const struct phys_const* restrict phys_const, const struct hydro_props* restrict hydro_props, @@ -704,9 +715,30 @@ static INLINE float cooling_get_temperature( const struct cosmology* restrict cosmo, const struct cooling_function_data* restrict cooling, const struct part* restrict p, const struct xpart* restrict xp) { + // TODO use the grackle library + + /* Physical constants */ + const double m_H = phys_const->const_proton_mass; + const double k_B = phys_const->const_boltzmann_k; - error("This function needs implementing!!"); - return 0.; + /* Gas properties */ + const double T_transition = hydro_props->hydrogen_ionization_temperature; + const double mu_neutral = hydro_props->mu_neutral; + const double mu_ionised = hydro_props->mu_ionised; + + /* Particle temperature */ + const double u = hydro_get_physical_internal_energy(p, xp, cosmo); + + /* Temperature over mean molecular weight */ + const double T_over_mu = hydro_gamma_minus_one * u * m_H / k_B; + + /* Are we above or below the HII -> HI transition? */ + if (T_over_mu > (T_transition + 1.) / mu_ionised) + return T_over_mu * mu_ionised; + else if (T_over_mu < (T_transition - 1.) / mu_neutral) + return T_over_mu * mu_neutral; + else + return T_transition; } /** diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index ab0064f06..7d13f7403 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -34,52 +34,12 @@ #include "star_formation_struct.h" #include "units.h" -/** - * @brief Compute the temperature of a #part based on the cooling function. - * - * @param phys_const #phys_const data structure. - * @param hydro_props The properties of the hydro scheme. - * @param us The internal system of units. - * @param cosmo #cosmology data structure. - * @param cooling #cooling_function_data struct. - * @param p #part data. - * @param xp Pointer to the #xpart data. - */ -INLINE static float get_temperature( - const struct phys_const* restrict phys_const, - const struct hydro_props* restrict hydro_props, - const struct unit_system* restrict us, - const struct cosmology* restrict cosmo, - const struct cooling_function_data* restrict cooling, - const struct part* restrict p, const struct xpart* restrict xp) { - - /* Physical constants */ - const double m_H = phys_const->const_proton_mass; - const double k_B = phys_const->const_boltzmann_k; - - /* Gas properties */ - const double T_transition = hydro_props->hydrogen_ionization_temperature; - const double mu_neutral = hydro_props->mu_neutral; - const double mu_ionised = hydro_props->mu_ionised; - - /* Particle temperature */ - const double u = hydro_get_physical_internal_energy(p, xp, cosmo); - - /* Temperature over mean molecular weight */ - const double T_over_mu = hydro_gamma_minus_one * u * m_H / k_B; - - /* Are we above or below the HII -> HI transition? */ - if (T_over_mu > (T_transition + 1.) / mu_ionised) - return T_over_mu * mu_ionised; - else if (T_over_mu < (T_transition - 1.) / mu_neutral) - return T_over_mu * mu_neutral; - else - return T_transition; -} /** * @brief Calculate if the gas has the potential of becoming * a star. * + * Use the star formation criterion given by eq. 3 in Revaz & Jablonka 2018. + * * @param starform the star formation law properties to use. * @param p the gas particles. * @param xp the additional properties of the gas particles. @@ -98,50 +58,47 @@ INLINE static int star_formation_is_star_forming( const struct unit_system* restrict us, const struct cooling_function_data* restrict cooling, const struct entropy_floor_properties* restrict entropy_floor) { - /* Some useful constants */ - const double G = phys_const->const_newton_G; - const double kb = phys_const->const_boltzmann_k; - const double mH = phys_const->const_proton_mass; - /* We first check if we are supposed to include turbulence estimation - * otherewise we keep 0 */ - float sigma2 = 0.f; - if (starform->with_sigma > 0) { - sigma2 = xp->sf_data.sigma2; - } - /* Compute the temperature */ - double const T = - get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); - /* Other useful values */ - const int N = starform->Njeans; - const double h = p->h; - /* We suppose that the gas is neutral */ - const double mu = hydro_props->mu_neutral; - /* Maximum temperature allowed (temperature criterion) */ - const double T0 = starform->Max_temperature; - /* Compute density */ - const double physical_density = hydro_get_physical_density(p, cosmo); - /* We compute the minimal density for star formation (see Revaz & Jablonka, - * 2018 eq (3)) */ - const double rho_sfr = M_PI * (hydro_gamma * kb * T / mu / mH + sigma2) / h / - h / 4. / G / pow(N, 2. / 3.); - /* Temperature criterion for star formation eligibility */ + + const float temperature = + cooling_get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); + + const float temperature_max = starform->Max_temperature; + + /* Check the temperature criterion */ if (T > T0) { return 0; } - /* Density criterion */ - else { - if (physical_density > rho_sfr) { - /* The particle is eligible (satisfy both conditions) */ - return 1; - } else { - return 0; - } + + /* Get the required variables */ + const float G = phys_const->const_newton_G; + const float kb = phys_const->const_boltzmann_k; + const float mH = phys_const->const_proton_mass; + + const float sigma2 = xp->sf_data.sigma2; + const int n_jeans_2_3 = starform->n_jeans_2_3; + + const float h = p->h; + const float density = hydro_get_physical_density(p, cosmo); + + // TODO use GRACKLE */ + const float mu = hydro_props->mu_neutral; + + /* Compute the density criterion */ + const float coef = M_PI_4 / (G * n_jeans_2_3 * h * h); + const float density_criterion = coef * (hydro_gamma * kb * T / (mu * mH) + sigma2); + + /* Check the density criterion */ + if (density > density_criterion) { + return 1; + } else { + return 0; } } /** - * @brief Compute the star-formation rate of a given particle and store - * it into the #xpart. + * @brief Compute the star-formation rate of a given particle. + * + * Nothing to do here. Everything is done in #star_formation_should_convert_to_star. * * @param p #part. * @param xp the #xpart. @@ -153,29 +110,13 @@ INLINE static int star_formation_is_star_forming( INLINE static void star_formation_compute_SFR( struct part* restrict p, struct xpart* restrict xp, const struct star_formation* starform, const struct phys_const* phys_const, - const struct cosmology* cosmo, const double dt_star) { - if (dt_star == 0.) { - xp->sf_data.SFR = 0.; - } else { - const double G = phys_const->const_newton_G; - const double c_star = starform->star_formation_rate; - const double physical_density = hydro_get_physical_density(p, cosmo); - if (physical_density != 0) { - /* We compute the star formation rate and store it (see Revaz & Jablonka, - * 2012, eq. (5)) */ - /* Units are mass/time/distance³ */ - xp->sf_data.SFR = c_star * physical_density * - sqrt(physical_density * 32.f * G) / sqrt(3 * M_PI); - } else { - xp->sf_data.SFR = 0.; - } - } - return; -} + const struct cosmology* cosmo, const double dt_star) {} /** * @brief Decides whether a particle should be converted into a * star or not. + + * Compute the star formation rate from eq. 4 in Revaz & Jablonka 2012. * * @param p The #part. * @param xp The #xpart. @@ -187,16 +128,30 @@ INLINE static void star_formation_compute_SFR( INLINE static int star_formation_should_convert_to_star( struct part* p, struct xpart* xp, const struct star_formation* starform, const struct engine* e, const double dt_star) { - /* Calculate the propability of forming a star, see Revaz & Jablonka (2012), - * eq. (4) */ - const double prob = 1. - exp(xp->sf_data.SFR * dt_star * (-1.) / - hydro_get_physical_density(p, e->cosmology)); - /* Get a unique random number between 0 and 1 for star formation */ - const double random_number = - random_unit_interval(p->id, e->ti_current, random_number_star_formation); + + /* Check that we are running a full time step */ + if (dt_star == 0.) { + return 0; + } + + /* Get a few variables */ + const float G = phys_const->const_newton_G; + const float c_star = starform->star_formation_rate; + const float density = hydro_get_physical_density(p, cosmo); + + /* Compute the probability */ + const float inv_free_fall_time = sqrtf(density * 32. * G / (3. * M_PI)); + const float prob = 1. - exp(-starform->star_formation_efficency * inv_free_fall_time * dt_star); + + /* Roll the dice... */ + const float random_number = + random_unit_interval(p->id, e->ti_current, random_number_star_formation); + if (random_number > prob) { + /* No star for you */ return 0; } else { + /* You get a star, you get a star, everybody gets a star */ return 1; } } @@ -212,19 +167,7 @@ INLINE static int star_formation_should_convert_to_star( */ INLINE static void star_formation_update_part_not_SFR( struct part* p, struct xpart* xp, const struct engine* e, - const struct star_formation* starform, const int with_cosmology) { - /* Check if it is the first time steps after star formation */ - if (xp->sf_data.SFR > 0.) { - - /* Record the current time as an indicator of when this particle was last - star-forming. */ - if (with_cosmology) { - xp->sf_data.SFR = -(e->cosmology->a); - } else { - xp->sf_data.SFR = -(e->time); - } - } -} + const struct star_formation* starform, const int with_cosmology) {} /** * @brief Copies the properties of the gas particle over to the @@ -257,6 +200,8 @@ INLINE static void star_formation_copy_properties( } else { sp->birth_time = e->time; } + + // TODO copy only metals /* Store the chemistry struct in the star particle */ sp->chemistry_data = p->chemistry_data; @@ -265,6 +210,7 @@ INLINE static void star_formation_copy_properties( /* Store the birth density in the star particle */ sp->birth_density = hydro_get_physical_density(p, cosmo); + /* Store the birth temperature*/ sp->birth_temperature = get_temperature(starform->phys_const, starform->hydro_props, starform->us, @@ -284,24 +230,24 @@ INLINE static void starformation_init_backend( struct swift_params* parameter_file, const struct phys_const* phys_const, const struct unit_system* us, const struct hydro_props* hydro_props, struct star_formation* starform) { - /* Jeans Number used in starformation elligibility criterion */ - starform->Njeans = - parser_get_param_int(parameter_file, "GEARStarFormation:jeans_number"); - /* Starformation efficiency (used in SFR calculation) */ - starform->star_formation_rate = parser_get_param_double( + + // TODO move into pressure floor + starform->n_jeans_2_3 = + parser_get_param_float(parameter_file, "GEARStarFormation:NJeans"); + starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2./3.); + + /* Star formation efficiency */ + starform->star_formation_efficiency = parser_get_param_double( parameter_file, "GEARStarFormation:star_formation_efficiency"); - /* Wheter we take into account local turbulence */ - starform->with_sigma = parser_get_param_int( - parameter_file, "GEARStarFormation:with_turbulence_estimation"); - /* Maximum temperature for starformation */ - starform->Max_temperature = + + /* Maximum temperature for star formation */ + starform->maximal_temperature = parser_get_param_double(parameter_file, - "GEARStarFormation:Max_temperature") * - units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); - ; - starform->hydro_props = hydro_props; - starform->us = us; - starform->phys_const = phys_const; + "GEARStarFormation:maximal_temperature"); + + /* Apply unit change */ + starform->maximal_temperature *= + units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); } /** @@ -325,9 +271,12 @@ INLINE static void starformation_print_backend( __attribute__((always_inline)) INLINE static void star_formation_end_density( struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, const struct cosmology* cosmo) { + + // TODO move into pressure floor /* To finish the turbulence estimation we devide by the density */ - xp->sf_data.sigma2 /= hydro_get_physical_density(p, cosmo); + xp->sf_data.sigma2 /= pow_dimension(p->h) * hydro_get_physical_density(p, cosmo); } + /** * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. * @@ -341,6 +290,8 @@ star_formation_part_has_no_neighbours(struct part* restrict p, struct xpart* restrict xp, const struct star_formation* cd, const struct cosmology* cosmo) { + + // TODO move into pressure floor /* If part has 0 neighbours, the estimation of turbulence is 0 */ xp->sf_data.sigma2 = 0.f; } @@ -361,7 +312,8 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct star_formation* data, struct part* restrict p) { - xp->sf_data.sigma2 = 0.f; + /* Nothing special here */ + star_formation_init_part(p, xp, data); } /** diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index 18da287f3..8515b780b 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -29,6 +29,8 @@ * @brief do star_formation computation after the runner_iact_density (symmetric * version) * + * Compute the velocity dispersion follow eq. 2 in Revaz & Jablonka 2018. + * * @param r2 Comoving square distance between the two particles. * @param dx Comoving vector separating both particles (pi - pj). * @param hi Comoving smoothing-length of particle i. @@ -42,21 +44,26 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( float r2, const float *dx, float hi, float hj, struct part *restrict pi, struct part *restrict pj, struct xpart *restrict xpi, struct xpart *restrict xpj, float a, float H) { - /* The goal here is to estimate the local turbulence */ - /* Value used to evaluate the SPH kernel */ + float wi; float wj; /* Evaluation of the SPH kernel */ kernel_eval(sqrt(r2) / hi, &wi); kernel_eval(sqrt(r2) / hj, &wj); - /* Square of the velocity norm between particles i and j */ - float norm_v2 = pow(pi->v[0] - pj->v[0], 2) + pow(pi->v[1] - pj->v[1], 2) + - pow(pi->v[2] - pj->v[2], 2); - /* Estimation of local turbulence for pi and pj, see Revaz & Jablonka, eq (2) - */ - xpi->sf_data.sigma2 += pow(hi, -3) * norm_v2 * wi * hydro_get_mass(pj); - xpj->sf_data.sigma2 += pow(hj, -3) * norm_v2 * wj * hydro_get_mass(pi); + /* Delta v */ + float dv[3] = { + pi->v[0] - pj->v[0], + pi->v[1] - pj->v[1], + pi->v[2] - pj->v[2] + }; + + /* Square of delta v */ + float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + + /* Compute the velocity dispersion */ + xpi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); + xpj->sf_data.sigma2 += norm_v2 * wj * hydro_get_mass(pi); } /** @@ -78,17 +85,23 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, const struct part *restrict pj, struct xpart *restrict xpi, const struct xpart *restrict xpj, float a, - float H) -/* The goal here is to estimate the local turbulence */ -/* Value used to evaluate the SPH kernel */ -{ + float H) { float wi; /* Evaluation of the SPH kernel */ kernel_eval(sqrt(r2) / hi, &wi); - /* Square of the velocity norm */ - float norm_v2 = pow(pi->v[0] - pj->v[0], 2) + pow(pi->v[1] - pj->v[1], 2) + - pow(pi->v[2] - pj->v[2], 2); - /* Estimation of local turbulence for pi */ - xpi->sf_data.sigma2 += pow(hi, -3) * norm_v2 * wi * hydro_get_mass(pj); + + /* Delta v */ + float dv[3] = { + pi->v[0] - pj->v[0], + pi->v[1] - pj->v[1], + pi->v[2] - pj->v[2] + }; + + /* Square of delta v */ + float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + + /* Compute the velocity dispersion */ + xpi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); } + #endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 22a65eed8..6b43e1540 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -195,11 +195,11 @@ INLINE static void star_formation_logger_init_log_file( /** * @brief Add the SFR tracer to the total active SFR of this cell * + * Nothing to do here + * * @param p the #part * @param xp the #xpart * - * Nothing to do here - * * @param sf the SFH logger struct * @param dt_star The length of the time-step in physical internal units. */ diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 617f60343..8786ddb8d 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -24,31 +24,26 @@ * data. */ struct star_formation_xpart_data { - /*!star formation rate (mass/(time*volume))*/ - double SFR; + + // TODO move it to the pressure floor /*! Estimation of local turbulence (squared) */ float sigma2; }; -/* Starformation struct */ +/** + * @brief Global star formation properties + */ struct star_formation { - /*! Njeans number. We request that the SPH mass resolution is Njeans times - * smaller than the Jeans mass*/ - int Njeans; - /*!star formation efficency. If the particle can create a star, it happens - * with this probablity*/ - double star_formation_rate; - /*!do we include local turbulence*/ - int with_sigma; - /*!Maximum temperature to allow star formation* (should be about 10'000 or - * 30'000 K*/ - double Max_temperature; - /*!some other useful elements*/ - const struct hydro_props* restrict hydro_props; - /*!units*/ - const struct unit_system* restrict us; - /*! physical constants*/ - const struct phys_const* phys_const; + + // TODO move it to pressure floor + /*! Number of particle required to resolved the Jeans criterion (at power 2/3) */ + float n_jeans_2_3; + + /*! Maximal temperature for forming a star */ + float maximal_temperature; + + /*! Star formation efficiency */ + float star_formation_efficiency; }; #endif /* SWIFT_GEAR_STAR_FORMATION_STRUCT_H */ -- GitLab From 54936f265dd27959a964d5bb4e998b0d41c6008d Mon Sep 17 00:00:00 2001 From: loikki Date: Tue, 18 Jun 2019 09:07:40 +0200 Subject: [PATCH 08/16] GEAR: SFR working correctly --- src/collectgroup.c | 2 +- src/engine.c | 2 +- src/hydro/Gadget2/hydro_part.h | 3 + src/space.c | 2 +- src/star_formation.c | 1 + src/star_formation/GEAR/star_formation.h | 104 ++++++------------ src/star_formation/GEAR/star_formation_iact.h | 13 +-- src/star_formation/GEAR/star_formation_io.h | 36 +++++- .../GEAR/star_formation_logger.h | 16 +-- .../GEAR/star_formation_struct.h | 4 +- src/stars/GEAR/stars_io.h | 8 +- src/stars/GEAR/stars_part.h | 17 ++- 12 files changed, 110 insertions(+), 98 deletions(-) diff --git a/src/collectgroup.c b/src/collectgroup.c index e75db63f8..4be3116e3 100644 --- a/src/collectgroup.c +++ b/src/collectgroup.c @@ -123,7 +123,7 @@ void collectgroup1_apply(const struct collectgroup1 *grp1, struct engine *e) { e->total_nr_tasks = grp1->total_nr_tasks; e->tasks_per_cell_max = grp1->tasks_per_cell_max; - star_formation_logger_add_to_engine(e->sfh, grp1->sfh); + star_formation_logger_add_to_engine(&e->sfh, &grp1->sfh); } /** diff --git a/src/engine.c b/src/engine.c index d5b7d976b..085160d12 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5064,7 +5064,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, /* Initialize the star formation history structure */ if (e->policy & engine_policy_star_formation) { - star_formation_logger_first_init(e->sfh); + star_formation_logger_first_init(&e->sfh); } engine_init_output_lists(e, params); diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 7a8844d56..853d2adf1 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -155,6 +155,9 @@ struct part { /*! Black holes information (e.g. swallowing ID) */ struct black_holes_part_data black_holes_data; + /* Additional data used by the star formation */ + struct star_formation_part_data sf_data; + /* Time-step length */ timebin_t time_bin; diff --git a/src/space.c b/src/space.c index 49c714743..250af5efa 100644 --- a/src/space.c +++ b/src/space.c @@ -4365,7 +4365,7 @@ void space_init_parts_mapper(void *restrict map_data, int count, for (int k = 0; k < count; k++) { hydro_init_part(&parts[k], hs); chemistry_init_part(&parts[k], e->chemistry); - star_formation_init_part(&parts[k], e->star_formation); + star_formation_init_part(&parts[k], &xparts[k], e->star_formation); tracers_after_init(&parts[k], &xparts[k], e->internal_units, e->physical_constants, with_cosmology, e->cosmology, e->hydro_properties, e->cooling_func, e->time); diff --git a/src/star_formation.c b/src/star_formation.c index 698a64cc6..60cff1e2e 100644 --- a/src/star_formation.c +++ b/src/star_formation.c @@ -24,6 +24,7 @@ #include "part.h" #include "restart.h" #include "star_formation.h" +#include "star_formation_io.h" #include "units.h" /** diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index 7d13f7403..cfb314be4 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -62,20 +62,16 @@ INLINE static int star_formation_is_star_forming( const float temperature = cooling_get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); - const float temperature_max = starform->Max_temperature; + const float temperature_max = starform->maximal_temperature; /* Check the temperature criterion */ - if (T > T0) { + if (temperature > temperature_max) { return 0; } /* Get the required variables */ - const float G = phys_const->const_newton_G; - const float kb = phys_const->const_boltzmann_k; - const float mH = phys_const->const_proton_mass; - - const float sigma2 = xp->sf_data.sigma2; - const int n_jeans_2_3 = starform->n_jeans_2_3; + const float sigma2 = p->sf_data.sigma2; + const float n_jeans_2_3 = starform->n_jeans_2_3; const float h = p->h; const float density = hydro_get_physical_density(p, cosmo); @@ -84,8 +80,9 @@ INLINE static int star_formation_is_star_forming( const float mu = hydro_props->mu_neutral; /* Compute the density criterion */ - const float coef = M_PI_4 / (G * n_jeans_2_3 * h * h); - const float density_criterion = coef * (hydro_gamma * kb * T / (mu * mH) + sigma2); + 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) + sigma2); /* Check the density criterion */ if (density > density_criterion) { @@ -129,6 +126,9 @@ INLINE static int star_formation_should_convert_to_star( struct part* p, struct xpart* xp, const struct star_formation* starform, const struct engine* e, const double dt_star) { + const struct phys_const* phys_const = e->physical_constants; + const struct cosmology *cosmo = e->cosmology; + /* Check that we are running a full time step */ if (dt_star == 0.) { return 0; @@ -136,12 +136,11 @@ INLINE static int star_formation_should_convert_to_star( /* Get a few variables */ const float G = phys_const->const_newton_G; - const float c_star = starform->star_formation_rate; const float density = hydro_get_physical_density(p, cosmo); /* Compute the probability */ const float inv_free_fall_time = sqrtf(density * 32. * G / (3. * M_PI)); - const float prob = 1. - exp(-starform->star_formation_efficency * inv_free_fall_time * dt_star); + const float prob = 1. - exp(-starform->star_formation_efficiency * inv_free_fall_time * dt_star); /* Roll the dice... */ const float random_number = @@ -193,6 +192,7 @@ INLINE static void star_formation_copy_properties( /* Store the current mass */ sp->mass = hydro_get_mass(p); + sp->birth.mass = sp->mass; /* Store either the birth_scale_factor or birth_time depending */ if (with_cosmology) { @@ -209,45 +209,12 @@ INLINE static void star_formation_copy_properties( sp->tracers_data = xp->tracers_data; /* Store the birth density in the star particle */ - sp->birth_density = hydro_get_physical_density(p, cosmo); + sp->birth.density = hydro_get_physical_density(p, cosmo); /* Store the birth temperature*/ - sp->birth_temperature = - get_temperature(starform->phys_const, starform->hydro_props, starform->us, - cosmo, e->cooling_func, p, xp); -} - -/** - * @brief initialization of the star formation law - * - * @param parameter_file The parsed parameter file - * @param phys_const Physical constants in internal units - * @param us The current internal system of units - * @param starform the star formation law properties to initialize - * - */ -INLINE static void starformation_init_backend( - struct swift_params* parameter_file, const struct phys_const* phys_const, - const struct unit_system* us, const struct hydro_props* hydro_props, - struct star_formation* starform) { - - // TODO move into pressure floor - starform->n_jeans_2_3 = - parser_get_param_float(parameter_file, "GEARStarFormation:NJeans"); - starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2./3.); - - /* Star formation efficiency */ - starform->star_formation_efficiency = parser_get_param_double( - parameter_file, "GEARStarFormation:star_formation_efficiency"); - - /* Maximum temperature for star formation */ - starform->maximal_temperature = - parser_get_param_double(parameter_file, - "GEARStarFormation:maximal_temperature"); - - /* Apply unit change */ - starform->maximal_temperature *= - units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); + sp->birth.temperature = + cooling_get_temperature(phys_const, hydro_props, us, + cosmo, cooling, p, xp); } /** @@ -265,16 +232,15 @@ INLINE static void starformation_print_backend( * * @param p The particle to act upon * @param xp The extended particle data to act upon - * @param cd The global star_formation information. + * @param sf The global star_formation information. * @param cosmo The current cosmological model. */ __attribute__((always_inline)) INLINE static void star_formation_end_density( - struct part* restrict p, struct xpart* restrict xp, - const struct star_formation* cd, const struct cosmology* cosmo) { + struct part* restrict p, const struct star_formation* sf, const struct cosmology* cosmo) { // TODO move into pressure floor /* To finish the turbulence estimation we devide by the density */ - xp->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); } /** @@ -293,7 +259,21 @@ star_formation_part_has_no_neighbours(struct part* restrict p, // TODO move into pressure floor /* If part has 0 neighbours, the estimation of turbulence is 0 */ - xp->sf_data.sigma2 = 0.f; + p->sf_data.sigma2 = 0.f; +} + +/** + * @brief Sets the star_formation properties of the (x-)particles to a valid + * start state. + * + * @param p Pointer to the particle data. + * @param xp Pointer to extended particle data + * @param data The global star_formation information. + */ +__attribute__((always_inline)) INLINE static void star_formation_init_part( + struct part* restrict p, struct xpart* restrict xp, + const struct star_formation* data) { + p->sf_data.sigma2 = 0.f; } /** @@ -310,24 +290,12 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct unit_system* restrict us, const struct cosmology* restrict cosmo, const struct star_formation* data, - struct part* restrict p) { + struct part* restrict p, + struct xpart* restrict xp) { /* Nothing special here */ star_formation_init_part(p, xp, data); } -/** - * @brief Sets the star_formation properties of the (x-)particles to a valid - * start state. - * - * @param p Pointer to the particle data. - * @param xp Pointer to extended particle data - * @param data The global star_formation information. - */ -__attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, struct xpart* restrict xp, - const struct star_formation* data) { - xp->sf_data.sigma2 = 0.f; -} #endif /* SWIFT_GEAR_STAR_FORMATION_H */ diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index 8515b780b..ef42d264e 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -42,8 +42,7 @@ */ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( float r2, const float *dx, float hi, float hj, struct part *restrict pi, - struct part *restrict pj, struct xpart *restrict xpi, - struct xpart *restrict xpj, float a, float H) { + struct part *restrict pj, float a, float H) { float wi; float wj; @@ -62,8 +61,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; /* Compute the velocity dispersion */ - xpi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); - xpj->sf_data.sigma2 += norm_v2 * wj * hydro_get_mass(pi); + pi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); + pj->sf_data.sigma2 += norm_v2 * wj * hydro_get_mass(pi); } /** @@ -82,9 +81,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( __attribute__((always_inline)) INLINE static void runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, struct part *restrict pi, - const struct part *restrict pj, - struct xpart *restrict xpi, - const struct xpart *restrict xpj, float a, + const struct part *restrict pj, float a, float H) { float wi; /* Evaluation of the SPH kernel */ @@ -101,7 +98,7 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; /* Compute the velocity dispersion */ - xpi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); + pi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); } #endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index ec0713be1..a0fa0935c 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -38,8 +38,42 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( const struct part* parts, const struct xpart* xparts, struct io_props* list) { - /* Nothing to write here */ +/* Nothing to write here */ return 0; } + +/** + * @brief initialization of the star formation law + * + * @param parameter_file The parsed parameter file + * @param phys_const Physical constants in internal units + * @param us The current internal system of units + * @param starform the star formation law properties to initialize + * + */ +INLINE static void starformation_init_backend( + struct swift_params* parameter_file, const struct phys_const* phys_const, + const struct unit_system* us, const struct hydro_props* hydro_props, + struct star_formation* starform) { + + // TODO move into pressure floor + starform->n_jeans_2_3 = + parser_get_param_float(parameter_file, "GEARStarFormation:NJeans"); + starform->n_jeans_2_3 = pow(starform->n_jeans_2_3, 2./3.); + + /* Star formation efficiency */ + starform->star_formation_efficiency = parser_get_param_double( + parameter_file, "GEARStarFormation:star_formation_efficiency"); + + /* Maximum temperature for star formation */ + starform->maximal_temperature = + parser_get_param_double(parameter_file, + "GEARStarFormation:maximal_temperature"); + + /* Apply unit change */ + starform->maximal_temperature *= + units_cgs_conversion_factor(us, UNIT_CONV_TEMPERATURE); +} + #endif /* SWIFT_STAR_FORMATION_GEAR_IO_H */ diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 6b43e1540..2ead5c9c0 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -42,10 +42,10 @@ INLINE static void star_formation_logger_log_new_spart( const struct spart *sp, struct star_formation_history *sf) { /* Add mass of created sparticle to the total stellar mass in this cell */ - sf->stellar_mass += sp->mass; + sf->new_stellar_mass += sp->mass; /* Increase the number of stars */ - sf->number_of_stars += 1; + sf->number_new_stars += 1; /* No need to deal with the integrated quantities, only the engine's one is * updated */ @@ -61,10 +61,10 @@ INLINE static void star_formation_logger_log_inactive_cell( struct star_formation_history *sf) { /* Initialize the stellar mass to zero */ - sf->stellar_mass = 0.f; + sf->new_stellar_mass = 0.f; /* initialize number of stars to zero*/ - sf->number_of_stars = 0; + sf->number_new_stars = 0; } /** * @brief Initialize the star formation history structure in the #engine @@ -121,13 +121,9 @@ INLINE static void star_formation_logger_add_to_engine( struct star_formation_history *sf_update, const struct star_formation_history *sf_add) { - /* Remove self contribution */ - sf_update->total_number_stars -= sf_update->number_new_stars; - sf_update->total_stellar_mass -= sf_update->new_stellar_mass; - /* Update the SFH structure */ - sf_update->number_new_stars += sf_add->number_new_stars; - sf_update->new_stellar_mass += sf_add->new_stellar_mass; + sf_update->number_new_stars = sf_add->number_new_stars; + sf_update->new_stellar_mass = sf_add->new_stellar_mass; sf_update->total_number_stars += sf_add->number_new_stars; sf_update->total_stellar_mass += sf_add->new_stellar_mass; } diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 8786ddb8d..960ccda29 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -23,8 +23,10 @@ * @brief Star-formation-related properties stored in the extended particle * data. */ -struct star_formation_xpart_data { +struct star_formation_xpart_data {}; + +struct star_formation_part_data { // TODO move it to the pressure floor /*! Estimation of local turbulence (squared) */ float sigma2; diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index fd8759351..4551d8af2 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -61,7 +61,7 @@ INLINE static void stars_write_particles(const struct spart *sparts, int *num_fields) { /* Say how much we want to write */ - *num_fields = 6; + *num_fields = 9; /* List what we want to write */ list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, @@ -76,6 +76,12 @@ INLINE static void stars_write_particles(const struct spart *sparts, sparts, h); list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, birth_time); + list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY, sparts, + birth.density); + list[7] = 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, + birth.mass); #ifdef DEBUG_INTERACTIONS_STARS diff --git a/src/stars/GEAR/stars_part.h b/src/stars/GEAR/stars_part.h index 3e9cfd020..bf68a580e 100644 --- a/src/stars/GEAR/stars_part.h +++ b/src/stars/GEAR/stars_part.h @@ -68,12 +68,6 @@ struct spart { float birth_scale_factor; }; - /*!birth density*/ - float birth_density; - - /*!birth temperature*/ - float birth_temperature; - /*! Particle time bin */ timebin_t time_bin; @@ -87,6 +81,17 @@ struct spart { } density; + struct { + /*! birth density*/ + float density; + + /*! birth temperature*/ + float temperature; + + /*! birth mass */ + float mass; + } birth; + /*! Feedback structure */ struct feedback_spart_data feedback_data; -- GitLab From e5e3c94008131aa14760716f568613667b28bbcc Mon Sep 17 00:00:00 2001 From: loikki Date: Thu, 11 Jul 2019 09:10:24 +0200 Subject: [PATCH 09/16] GEAR: add star_formation_history_accumulator --- src/collectgroup.c | 2 +- src/engine.c | 2 +- src/engine.h | 2 +- .../GEAR/star_formation_logger.h | 106 +++++++++--------- .../GEAR/star_formation_logger_struct.h | 13 ++- 5 files changed, 70 insertions(+), 55 deletions(-) diff --git a/src/collectgroup.c b/src/collectgroup.c index 4be3116e3..8dd9e974f 100644 --- a/src/collectgroup.c +++ b/src/collectgroup.c @@ -123,7 +123,7 @@ void collectgroup1_apply(const struct collectgroup1 *grp1, struct engine *e) { e->total_nr_tasks = grp1->total_nr_tasks; e->tasks_per_cell_max = grp1->tasks_per_cell_max; - star_formation_logger_add_to_engine(&e->sfh, &grp1->sfh); + star_formation_logger_add_to_accumulator(&e->sfh, &grp1->sfh); } /** diff --git a/src/engine.c b/src/engine.c index 085160d12..33f94e9c1 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5064,7 +5064,7 @@ void engine_init(struct engine *e, struct space *s, struct swift_params *params, /* Initialize the star formation history structure */ if (e->policy & engine_policy_star_formation) { - star_formation_logger_first_init(&e->sfh); + star_formation_logger_accumulator_init(&e->sfh); } engine_init_output_lists(e, params); diff --git a/src/engine.h b/src/engine.h index 829693356..967a43087 100644 --- a/src/engine.h +++ b/src/engine.h @@ -237,7 +237,7 @@ struct engine { long long b_updates_since_rebuild; /* Star formation logger information */ - struct star_formation_history sfh; + struct star_formation_history_accumulator sfh; /* Properties of the previous step */ int step_props; diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 2ead5c9c0..45d39b184 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -77,20 +77,6 @@ INLINE static void star_formation_logger_init( sfh->new_stellar_mass = 0.f; sfh->number_new_stars = 0; } -/** - * @brief Initialize the star formation history struct in the #engine when - * starting the simulation. - * - * @param sfh the star_formation_history struct we want to initialize - */ -INLINE static void star_formation_logger_first_init( - struct star_formation_history *sfh) { - /* Initialize all values to zero */ - sfh->new_stellar_mass = 0.f; - sfh->number_new_stars = 0; - sfh->total_number_stars = 0; - sfh->total_stellar_mass = 0.f; -} /** * @brief add a star formation history struct to an other star formation history @@ -109,43 +95,6 @@ INLINE static void star_formation_logger_add( sf_update->new_stellar_mass += sf_add->new_stellar_mass; } -/** - * @brief add a star formation history struct to an other star formation history - * struct - * - * @param sf_add the star formation struct which we want to add to the star - * formation history - * @param sf_update the star formation structure which we want to update - */ -INLINE static void star_formation_logger_add_to_engine( - struct star_formation_history *sf_update, - const struct star_formation_history *sf_add) { - - /* Update the SFH structure */ - sf_update->number_new_stars = sf_add->number_new_stars; - sf_update->new_stellar_mass = sf_add->new_stellar_mass; - sf_update->total_number_stars += sf_add->number_new_stars; - sf_update->total_stellar_mass += sf_add->new_stellar_mass; -} - -/** -za * @brief Write the final SFH to a file - * - * @param fp The file to write to. - * @param time the simulation time (time since Big Bang) in internal units. - * @param a the scale factor. - * @param z the redshift. - * @param sf the #star_formation_history struct. - * @param step The time-step of the simulation. - */ -INLINE static void star_formation_logger_write_to_log_file( - FILE *fp, const double time, const double a, const double z, - struct star_formation_history sf, const int step) { - - fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, - sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, - sf.new_stellar_mass); -} /** * @brief Initialize the SFH logger file * @@ -217,4 +166,59 @@ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, struct star_formation_history *sf) {} + + +/** + * @brief add a star formation history struct to an other star formation history + * struct + * + * @param sf_add the star formation struct which we want to add to the star + * formation history + * @param sf_update the star formation structure which we want to update + */ +INLINE static void star_formation_logger_add_to_accumulator( + struct star_formation_history_accumulator *sf_update, + const struct star_formation_history *sf_add) { + + /* Update the SFH structure */ + sf_update->number_new_stars = sf_add->number_new_stars; + sf_update->new_stellar_mass = sf_add->new_stellar_mass; + sf_update->total_number_stars += sf_add->number_new_stars; + sf_update->total_stellar_mass += sf_add->new_stellar_mass; +} + +/** + * @brief Write the final SFH to a file + * + * @param fp The file to write to. + * @param time the simulation time (time since Big Bang) in internal units. + * @param a the scale factor. + * @param z the redshift. + * @param sf the #star_formation_history struct. + * @param step The time-step of the simulation. + */ +INLINE static void star_formation_logger_write_to_log_file( + FILE *fp, const double time, const double a, const double z, + struct star_formation_history_accumulator sf, const int step) { + + fprintf(fp, "%6d %16e %12.7f %14e %14ld %14e %14ld %14e\n", step, time, a, z, + sf.total_number_stars, sf.total_stellar_mass, sf.number_new_stars, + sf.new_stellar_mass); +} + +/** + * @brief Initialize the star formation history struct in the #engine when + * starting the simulation. + * + * @param sfh the star_formation_history struct we want to initialize + */ +INLINE static void star_formation_logger_accumulator_init( + struct star_formation_history_accumulator *sfh) { + /* Initialize all values to zero */ + sfh->new_stellar_mass = 0.f; + sfh->number_new_stars = 0; + sfh->total_number_stars = 0; + sfh->total_stellar_mass = 0.f; +} + #endif /* SWIFT_GEAR_STARFORMATION_LOGGER_H */ diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index 718066fd6..e4ae68edf 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -21,9 +21,20 @@ #define SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H /** - * Structure containing the global star formation information. + * Structure containing the local star formation information. */ struct star_formation_history { + /*! Stellar mass created in the current timestep */ + float new_stellar_mass; + + /*! Number of stars created in this timestep */ + long int number_new_stars; +}; + +/** + * Structure containing the global star formation information. + */ +struct star_formation_history_accumulator { /*! Total stellar mass from the begining of the simulation */ float total_stellar_mass; -- GitLab From 939ea33be78fc1b56c27084276233e05b046abf2 Mon Sep 17 00:00:00 2001 From: loikki Date: Thu, 11 Jul 2019 09:11:23 +0200 Subject: [PATCH 10/16] GEAR: update comment --- src/star_formation/GEAR/star_formation_logger_struct.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index e4ae68edf..f694cda64 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -21,7 +21,7 @@ #define SWIFT_GEAR_STAR_FORMATION_LOGGER_STRUCT_H /** - * Structure containing the local star formation information. + * Structure containing the star formation information from the cells. */ struct star_formation_history { /*! Stellar mass created in the current timestep */ @@ -32,7 +32,7 @@ struct star_formation_history { }; /** - * Structure containing the global star formation information. + * Structure containing the global star formation information (including time integrated variables). */ struct star_formation_history_accumulator { /*! Total stellar mass from the begining of the simulation */ -- GitLab From df8bc13863744a6b0ecabf84fd1ac27124bb3b40 Mon Sep 17 00:00:00 2001 From: loikki Date: Thu, 25 Jul 2019 10:47:50 +0200 Subject: [PATCH 11/16] GEAR: add parameters in parameter_example.yml --- examples/parameter_example.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 996e35e41..6aeeaad3e 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -338,6 +338,11 @@ EAGLEChemistry: # Parameters related to star formation models ----------------------------------------------- +# GEAR star formation model (Revaz and Jablonka 2018) +GEARStarFormation: + star_formation_efficiency: 0.01 # star formation efficiency (c_*) + maximal_temperature: 3e4 # Upper limit to the temperature of a star forming particle + # EAGLE star formation model (Schaye and Dalla Vecchia 2008) EAGLEStarFormation: EOS_density_norm_H_p_cm3: 0.1 # Physical density used for the normalisation of the EOS assumed for the star-forming gas in Hydrogen atoms per cm^3. -- GitLab From b885c0c4479de8d0b1fb451f855b95ff62365a25 Mon Sep 17 00:00:00 2001 From: loikki Date: Mon, 29 Jul 2019 13:14:50 +0200 Subject: [PATCH 12/16] GEAR: add hubble flow --- src/star_formation/GEAR/star_formation.h | 22 +++++++------------ src/star_formation/GEAR/star_formation_iact.h | 22 +++++++++++++------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index cfb314be4..a1d9dda2a 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -85,11 +85,7 @@ INLINE static int star_formation_is_star_forming( / (mu * phys_const->const_proton_mass) + sigma2); /* Check the density criterion */ - if (density > density_criterion) { - return 1; - } else { - return 0; - } + return density > density_criterion; } /** @@ -139,20 +135,15 @@ INLINE static int star_formation_should_convert_to_star( const float density = hydro_get_physical_density(p, cosmo); /* Compute the probability */ - const float inv_free_fall_time = sqrtf(density * 32. * G / (3. * M_PI)); - const float prob = 1. - exp(-starform->star_formation_efficiency * inv_free_fall_time * dt_star); + const float inv_free_fall_time = 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... */ const float random_number = random_unit_interval(p->id, e->ti_current, random_number_star_formation); - if (random_number > prob) { - /* No star for you */ - return 0; - } else { - /* You get a star, you get a star, everybody gets a star */ - return 1; - } + /* Can we form a star? */ + return random_number < prob; } /** @@ -241,6 +232,9 @@ __attribute__((always_inline)) INLINE static void star_formation_end_density( // TODO move into pressure floor /* To finish the turbulence estimation we devide by the density */ p->sf_data.sigma2 /= pow_dimension(p->h) * hydro_get_physical_density(p, cosmo); + + /* Add the cosmological factor */ + p->sf_data.sigma2 *= cosmo->a * cosmo->a; } /** diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index ef42d264e..80de64227 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -57,12 +57,16 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( pi->v[2] - pj->v[2] }; - /* Square of delta v */ - float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + /* Norms at power 2 */ + const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + const float norm_x2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; /* Compute the velocity dispersion */ - pi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); - pj->sf_data.sigma2 += norm_v2 * wj * hydro_get_mass(pi); + const float sigma2 = norm_v2 + H * norm_x2; + + /* Compute the velocity dispersion */ + pi->sf_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); + pj->sf_data.sigma2 += sigma2 * wj * hydro_get_mass(pi); } /** @@ -94,11 +98,15 @@ runner_iact_nonsym_star_formation(float r2, const float *dx, float hi, float hj, pi->v[2] - pj->v[2] }; - /* Square of delta v */ - float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + /* Norms at power 2 */ + const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; + const float norm_x2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; + + /* Compute the velocity dispersion */ + const float sigma2 = norm_v2 + H * norm_x2; /* Compute the velocity dispersion */ - pi->sf_data.sigma2 += norm_v2 * wi * hydro_get_mass(pj); + pi->sf_data.sigma2 += sigma2 * wi * hydro_get_mass(pj); } #endif /* SWIFT_GEAR_STAR_FORMATION_IACT_H */ -- GitLab From 4941f719e9ce56d554c2a74bbdb4cb6ee45da05b Mon Sep 17 00:00:00 2001 From: loikki Date: Mon, 29 Jul 2019 14:00:50 +0200 Subject: [PATCH 13/16] Apply API changes to star formation --- src/star_formation/EAGLE/star_formation.h | 2 +- .../EAGLE/star_formation_logger.h | 43 ++++++++++++++++++- .../EAGLE/star_formation_logger_struct.h | 19 ++++++++ .../EAGLE/star_formation_struct.h | 2 + src/star_formation/none/star_formation.h | 2 +- .../none/star_formation_logger.h | 25 ++++++++++- .../none/star_formation_logger_struct.h | 7 +++ .../none/star_formation_struct.h | 6 +++ 8 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/star_formation/EAGLE/star_formation.h b/src/star_formation/EAGLE/star_formation.h index 1fc653165..eb6a74cbd 100644 --- a/src/star_formation/EAGLE/star_formation.h +++ b/src/star_formation/EAGLE/star_formation.h @@ -690,6 +690,6 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, * @param data The global star_formation information. */ __attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, const struct star_formation* data) {} + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {} #endif /* SWIFT_EAGLE_STAR_FORMATION_H */ diff --git a/src/star_formation/EAGLE/star_formation_logger.h b/src/star_formation/EAGLE/star_formation_logger.h index d634c876e..e992e5d14 100644 --- a/src/star_formation/EAGLE/star_formation_logger.h +++ b/src/star_formation/EAGLE/star_formation_logger.h @@ -87,6 +87,28 @@ INLINE static void star_formation_logger_add( sf_update->SFR_inactive += sf_add->SFR_inactive; } +/** + * @brief add a star formation history struct to the engine star formation history + * accumulator struct + * + * @param sf_add the star formation accumulator struct which we want to add to the star + * formation history + * @param sf_update the star formation structure which we want to update + */ +INLINE static void star_formation_logger_add_to_accumulator( + struct star_formation_history_accumulator *sf_update, + const struct star_formation_history *sf_add) { + + /* Update the SFH structure */ + sf_update->new_stellar_mass += sf_add->new_stellar_mass; + + sf_update->SFR_active += sf_add->SFR_active; + + sf_update->SFRdt_active += sf_add->SFRdt_active; + + sf_update->SFR_inactive += sf_add->SFR_inactive; +} + /** * @brief Initialize the star formation history structure in the #engine * @@ -105,6 +127,25 @@ INLINE static void star_formation_logger_init( sfh->SFR_inactive = 0.f; } +/** + * @brief Initialize the star formation history structure in the #engine + * + * @param sfh The pointer to the star formation history structure + */ +INLINE static void star_formation_logger_accumulator_init( + struct star_formation_history_accumulator *sfh) { + + /* Initialize the collecting SFH structure to zero */ + sfh->new_stellar_mass = 0.f; + + sfh->SFR_active = 0.f; + + sfh->SFRdt_active = 0.f; + + sfh->SFR_inactive = 0.f; +} + + /** * @brief Write the final SFH to a file * @@ -117,7 +158,7 @@ INLINE static void star_formation_logger_init( */ INLINE static void star_formation_logger_write_to_log_file( FILE *fp, const double time, const double a, const double z, - const struct star_formation_history sf, const int step) { + const struct star_formation_history_accumulator sf, const int step) { /* Calculate the total SFR */ const float totalSFR = sf.SFR_active + sf.SFR_inactive; diff --git a/src/star_formation/EAGLE/star_formation_logger_struct.h b/src/star_formation/EAGLE/star_formation_logger_struct.h index 2a23659c4..b677ee6bc 100644 --- a/src/star_formation/EAGLE/star_formation_logger_struct.h +++ b/src/star_formation/EAGLE/star_formation_logger_struct.h @@ -34,4 +34,23 @@ struct star_formation_history { float SFRdt_active; }; + +/* Starformation history struct for the engine. + Allows to integrate in time some values. + Nothing to do in EAGLE => copy of star_formation_history */ +struct star_formation_history_accumulator { + /*! Total new stellar mass */ + float new_stellar_mass; + + /*! SFR of all particles */ + float SFR_inactive; + + /*! SFR of active particles */ + float SFR_active; + + /*! SFR*dt of active particles */ + float SFRdt_active; +}; + + #endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */ diff --git a/src/star_formation/EAGLE/star_formation_struct.h b/src/star_formation/EAGLE/star_formation_struct.h index 41247e160..8caac49d4 100644 --- a/src/star_formation/EAGLE/star_formation_struct.h +++ b/src/star_formation/EAGLE/star_formation_struct.h @@ -29,4 +29,6 @@ struct star_formation_xpart_data { float SFR; }; +struct star_formation_part_data {}; + #endif /* SWIFT_EAGLE_STAR_FORMATION_STRUCT_H */ diff --git a/src/star_formation/none/star_formation.h b/src/star_formation/none/star_formation.h index dfe645718..6ef1c1106 100644 --- a/src/star_formation/none/star_formation.h +++ b/src/star_formation/none/star_formation.h @@ -219,6 +219,6 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, * @param data The global star_formation information. */ __attribute__((always_inline)) INLINE static void star_formation_init_part( - struct part* restrict p, const struct star_formation* data) {} + struct part* restrict p, struct xpart* restrict xp, const struct star_formation* data) {} #endif /* SWIFT_NONE_STAR_FORMATION_H */ diff --git a/src/star_formation/none/star_formation_logger.h b/src/star_formation/none/star_formation_logger.h index b4e6987c0..0a90bd486 100644 --- a/src/star_formation/none/star_formation_logger.h +++ b/src/star_formation/none/star_formation_logger.h @@ -59,6 +59,19 @@ INLINE static void star_formation_logger_add( struct star_formation_history *sf_update, const struct star_formation_history *sf_add) {} + +/** + * @brief add a star formation history accumulator struct to an other star formation history + * struct + * + * @param sf_add the star formation accumulator struct which we want to add to the star + * formation history + * @param sf_update the star formation structure which we want to update + */ +INLINE static void star_formation_logger_add_to_accumulator( + struct star_formation_history_accumulator *sf_update, + const struct star_formation_history *sf_add) {} + /** * @brief Initialize the star formation history structure in the #engine * @@ -67,6 +80,14 @@ INLINE static void star_formation_logger_add( INLINE static void star_formation_logger_init( struct star_formation_history *sfh) {} +/** + * @brief Initialize the star formation history structure in the #engine + * + * @param sfh The pointer to the star formation history structure + */ +INLINE static void star_formation_logger_accumulator_init( + struct star_formation_history_accumulator *sfh) {} + /** * @brief Write the final SFH to a file * @@ -74,12 +95,12 @@ INLINE static void star_formation_logger_init( * @param time the simulation time (time since Big Bang) in internal units. * @param a the scale factor. * @param z the redshift. - * @param sf the #star_formation_history struct. + * @param sf the #star_formation_history_accumulator struct. * @param step The time-step of the simulation. */ INLINE static void star_formation_logger_write_to_log_file( FILE *fp, const double time, const double a, const double z, - const struct star_formation_history sf, const int step) {} + const struct star_formation_history_accumulator sf, const int step) {} /** * @brief Initialize the SFH logger file diff --git a/src/star_formation/none/star_formation_logger_struct.h b/src/star_formation/none/star_formation_logger_struct.h index 9efda271d..c80d6b6f3 100644 --- a/src/star_formation/none/star_formation_logger_struct.h +++ b/src/star_formation/none/star_formation_logger_struct.h @@ -22,4 +22,11 @@ /* Starformation history struct */ struct star_formation_history {}; + +/* Starformation history accumulator struct. + This structure is only defined in the engine and + allows the user to integrate some quantities over time. +*/ +struct star_formation_history_accumulator {}; + #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */ diff --git a/src/star_formation/none/star_formation_struct.h b/src/star_formation/none/star_formation_struct.h index 27a2adaf8..2f5241a58 100644 --- a/src/star_formation/none/star_formation_struct.h +++ b/src/star_formation/none/star_formation_struct.h @@ -25,4 +25,10 @@ */ struct star_formation_xpart_data {}; +/** + * @brief Star-formation-related properties stored in the particle + * data. + */ +struct star_formation_part_data {}; + #endif /* SWIFT_NONE_STAR_FORMATION_STRUCT_H */ -- GitLab From 8109e6ce943b53f78e9a239a54602e66a5415f8b Mon Sep 17 00:00:00 2001 From: loikki Date: Mon, 29 Jul 2019 14:03:02 +0200 Subject: [PATCH 14/16] Format --- src/star_formation/EAGLE/star_formation.h | 3 +- .../EAGLE/star_formation_logger.h | 9 ++--- .../EAGLE/star_formation_logger_struct.h | 2 - src/star_formation/GEAR/star_formation.h | 40 +++++++++++-------- src/star_formation/GEAR/star_formation_iact.h | 12 +----- src/star_formation/GEAR/star_formation_io.h | 12 +++--- .../GEAR/star_formation_logger.h | 2 - .../GEAR/star_formation_logger_struct.h | 3 +- .../GEAR/star_formation_struct.h | 4 +- src/star_formation/none/star_formation.h | 3 +- .../none/star_formation_logger.h | 9 ++--- .../none/star_formation_logger_struct.h | 1 - src/stars/GEAR/stars_io.h | 9 +++-- 13 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/star_formation/EAGLE/star_formation.h b/src/star_formation/EAGLE/star_formation.h index eb6a74cbd..55f1c8d42 100644 --- a/src/star_formation/EAGLE/star_formation.h +++ b/src/star_formation/EAGLE/star_formation.h @@ -690,6 +690,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, * @param data The global star_formation information. */ __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 */ diff --git a/src/star_formation/EAGLE/star_formation_logger.h b/src/star_formation/EAGLE/star_formation_logger.h index e992e5d14..a843f63ce 100644 --- a/src/star_formation/EAGLE/star_formation_logger.h +++ b/src/star_formation/EAGLE/star_formation_logger.h @@ -88,11 +88,11 @@ INLINE static void star_formation_logger_add( } /** - * @brief add a star formation history struct to the engine star formation history - * accumulator struct + * @brief add a star formation history struct to the engine star formation + * history accumulator struct * - * @param sf_add the star formation accumulator struct which we want to add to the star - * formation history + * @param sf_add the star formation accumulator struct which we want to add to + * the star formation history * @param sf_update the star formation structure which we want to update */ INLINE static void star_formation_logger_add_to_accumulator( @@ -145,7 +145,6 @@ INLINE static void star_formation_logger_accumulator_init( sfh->SFR_inactive = 0.f; } - /** * @brief Write the final SFH to a file * diff --git a/src/star_formation/EAGLE/star_formation_logger_struct.h b/src/star_formation/EAGLE/star_formation_logger_struct.h index b677ee6bc..c03a00c97 100644 --- a/src/star_formation/EAGLE/star_formation_logger_struct.h +++ b/src/star_formation/EAGLE/star_formation_logger_struct.h @@ -34,7 +34,6 @@ struct star_formation_history { float SFRdt_active; }; - /* Starformation history struct for the engine. Allows to integrate in time some values. Nothing to do in EAGLE => copy of star_formation_history */ @@ -52,5 +51,4 @@ struct star_formation_history_accumulator { float SFRdt_active; }; - #endif /* SWIFT_EAGLE_STAR_FORMATION_LOGGER_STRUCT_H */ diff --git a/src/star_formation/GEAR/star_formation.h b/src/star_formation/GEAR/star_formation.h index a1d9dda2a..ac423a518 100644 --- a/src/star_formation/GEAR/star_formation.h +++ b/src/star_formation/GEAR/star_formation.h @@ -59,8 +59,8 @@ INLINE static int star_formation_is_star_forming( const struct cooling_function_data* restrict cooling, const struct entropy_floor_properties* restrict entropy_floor) { - const float temperature = - cooling_get_temperature(phys_const, hydro_props, us, cosmo, cooling, p, xp); + const float temperature = cooling_get_temperature(phys_const, hydro_props, us, + cosmo, cooling, p, xp); const float temperature_max = starform->maximal_temperature; @@ -80,9 +80,12 @@ INLINE static int star_formation_is_star_forming( const float mu = hydro_props->mu_neutral; /* 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) + sigma2); + 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) + + sigma2); /* Check the density criterion */ return density > density_criterion; @@ -91,7 +94,8 @@ INLINE static int star_formation_is_star_forming( /** * @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 xp the #xpart. @@ -123,7 +127,7 @@ INLINE static int star_formation_should_convert_to_star( const struct engine* e, const double dt_star) { 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 */ if (dt_star == 0.) { @@ -135,12 +139,14 @@ INLINE static int star_formation_should_convert_to_star( const float density = hydro_get_physical_density(p, cosmo); /* Compute the probability */ - const float inv_free_fall_time = 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); + const float inv_free_fall_time = + 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... */ 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? */ return random_number < prob; @@ -203,9 +209,8 @@ INLINE static void star_formation_copy_properties( sp->birth.density = hydro_get_physical_density(p, cosmo); /* Store the birth temperature*/ - sp->birth.temperature = - cooling_get_temperature(phys_const, hydro_props, us, - cosmo, cooling, p, xp); + sp->birth.temperature = cooling_get_temperature(phys_const, hydro_props, us, + cosmo, cooling, p, xp); } /** @@ -227,11 +232,13 @@ INLINE static void starformation_print_backend( * @param cosmo The current cosmological model. */ __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 /* 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 */ p->sf_data.sigma2 *= cosmo->a * cosmo->a; @@ -285,11 +292,10 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, const struct cosmology* restrict cosmo, const struct star_formation* data, struct part* restrict p, - struct xpart* restrict xp) { + struct xpart* restrict xp) { /* Nothing special here */ star_formation_init_part(p, xp, data); } - #endif /* SWIFT_GEAR_STAR_FORMATION_H */ diff --git a/src/star_formation/GEAR/star_formation_iact.h b/src/star_formation/GEAR/star_formation_iact.h index 80de64227..7325b92af 100644 --- a/src/star_formation/GEAR/star_formation_iact.h +++ b/src/star_formation/GEAR/star_formation_iact.h @@ -51,11 +51,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_star_formation( kernel_eval(sqrt(r2) / hj, &wj); /* Delta v */ - float dv[3] = { - pi->v[0] - pj->v[0], - pi->v[1] - pj->v[1], - pi->v[2] - pj->v[2] - }; + float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]}; /* Norms at power 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, kernel_eval(sqrt(r2) / hi, &wi); /* Delta v */ - float dv[3] = { - pi->v[0] - pj->v[0], - pi->v[1] - pj->v[1], - pi->v[2] - pj->v[2] - }; + float dv[3] = {pi->v[0] - pj->v[0], pi->v[1] - pj->v[1], pi->v[2] - pj->v[2]}; /* Norms at power 2 */ const float norm_v2 = dv[0] * dv[0] + dv[1] * dv[1] + dv[2] * dv[2]; diff --git a/src/star_formation/GEAR/star_formation_io.h b/src/star_formation/GEAR/star_formation_io.h index a0fa0935c..3e021f784 100644 --- a/src/star_formation/GEAR/star_formation_io.h +++ b/src/star_formation/GEAR/star_formation_io.h @@ -38,11 +38,10 @@ __attribute__((always_inline)) INLINE static int star_formation_write_particles( const struct part* parts, const struct xpart* xparts, struct io_props* list) { -/* Nothing to write here */ + /* Nothing to write here */ return 0; } - /** * @brief initialization of the star formation law * @@ -60,20 +59,19 @@ INLINE static void starformation_init_backend( // TODO move into pressure floor starform->n_jeans_2_3 = 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 */ starform->star_formation_efficiency = parser_get_param_double( parameter_file, "GEARStarFormation:star_formation_efficiency"); /* Maximum temperature for star formation */ - starform->maximal_temperature = - parser_get_param_double(parameter_file, - "GEARStarFormation:maximal_temperature"); + starform->maximal_temperature = parser_get_param_double( + parameter_file, "GEARStarFormation:maximal_temperature"); /* Apply unit change */ 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 */ diff --git a/src/star_formation/GEAR/star_formation_logger.h b/src/star_formation/GEAR/star_formation_logger.h index 45d39b184..84475909c 100644 --- a/src/star_formation/GEAR/star_formation_logger.h +++ b/src/star_formation/GEAR/star_formation_logger.h @@ -166,8 +166,6 @@ INLINE static void star_formation_logger_log_inactive_part( const struct part *p, const struct xpart *xp, struct star_formation_history *sf) {} - - /** * @brief add a star formation history struct to an other star formation history * struct diff --git a/src/star_formation/GEAR/star_formation_logger_struct.h b/src/star_formation/GEAR/star_formation_logger_struct.h index f694cda64..63e3af06a 100644 --- a/src/star_formation/GEAR/star_formation_logger_struct.h +++ b/src/star_formation/GEAR/star_formation_logger_struct.h @@ -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 { /*! Total stellar mass from the begining of the simulation */ diff --git a/src/star_formation/GEAR/star_formation_struct.h b/src/star_formation/GEAR/star_formation_struct.h index 960ccda29..2e9a7548f 100644 --- a/src/star_formation/GEAR/star_formation_struct.h +++ b/src/star_formation/GEAR/star_formation_struct.h @@ -25,7 +25,6 @@ */ struct star_formation_xpart_data {}; - struct star_formation_part_data { // TODO move it to the pressure floor /*! Estimation of local turbulence (squared) */ @@ -38,7 +37,8 @@ struct star_formation_part_data { struct star_formation { // 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; /*! Maximal temperature for forming a star */ diff --git a/src/star_formation/none/star_formation.h b/src/star_formation/none/star_formation.h index 6ef1c1106..3275e1a4c 100644 --- a/src/star_formation/none/star_formation.h +++ b/src/star_formation/none/star_formation.h @@ -219,6 +219,7 @@ star_formation_first_init_part(const struct phys_const* restrict phys_const, * @param data The global star_formation information. */ __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 */ diff --git a/src/star_formation/none/star_formation_logger.h b/src/star_formation/none/star_formation_logger.h index 0a90bd486..552df0c6c 100644 --- a/src/star_formation/none/star_formation_logger.h +++ b/src/star_formation/none/star_formation_logger.h @@ -59,13 +59,12 @@ INLINE static void star_formation_logger_add( struct star_formation_history *sf_update, const struct star_formation_history *sf_add) {} - /** - * @brief add a star formation history accumulator struct to an other star formation history - * struct + * @brief add a star formation history accumulator struct to an other star + * formation history struct * - * @param sf_add the star formation accumulator struct which we want to add to the star - * formation history + * @param sf_add the star formation accumulator struct which we want to add to + * the star formation history * @param sf_update the star formation structure which we want to update */ INLINE static void star_formation_logger_add_to_accumulator( diff --git a/src/star_formation/none/star_formation_logger_struct.h b/src/star_formation/none/star_formation_logger_struct.h index c80d6b6f3..b60c64f2e 100644 --- a/src/star_formation/none/star_formation_logger_struct.h +++ b/src/star_formation/none/star_formation_logger_struct.h @@ -22,7 +22,6 @@ /* Starformation history struct */ struct star_formation_history {}; - /* Starformation history accumulator struct. This structure is only defined in the engine and allows the user to integrate some quantities over time. diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index 4551d8af2..a538a2ba1 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -76,10 +76,11 @@ INLINE static void stars_write_particles(const struct spart *sparts, sparts, h); list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, birth_time); - list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY, sparts, - birth.density); - list[7] = io_make_output_field("BirthTemperature", FLOAT, 1, UNIT_CONV_TEMPERATURE, sparts, - birth.temperature); + list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY, + sparts, birth.density); + list[7] = + 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, birth.mass); -- GitLab From e4680c2ab61284e73cf5bec169d148738ac1e71d Mon Sep 17 00:00:00 2001 From: loikki Date: Wed, 31 Jul 2019 09:31:44 +0200 Subject: [PATCH 15/16] GEAR: update output --- src/stars/GEAR/stars_io.h | 59 +++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index a538a2ba1..bcbd5bdbf 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -55,34 +55,63 @@ INLINE static void stars_read_particles(struct spart *sparts, * @param sparts The s-particle array. * @param list The list of i/o properties to write. * @param num_fields The number of i/o fields to write. + * @param with_cosmology Is it a cosmological run? */ INLINE static void stars_write_particles(const struct spart *sparts, struct io_props *list, - int *num_fields) { + int *num_fields, + const int with_cosmology) { /* Say how much we want to write */ *num_fields = 9; /* List what we want to write */ - list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x); + list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, 1., + sparts, x, "Co-moving positions of the particles"); + list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); + io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, sparts, v, + "Peculiar velocities of the stars. This is (a * dx/dt) where x is the " + "co-moving positions of the particles"); + list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, sparts, mass); + io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, sparts, mass, + "Masses of the particles"); + list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - sparts, id); + 0.f, sparts, id, + "Unique IDs of the particles"); + list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - sparts, h); - list[5] = io_make_output_field("BirthTime", FLOAT, 1, UNIT_CONV_TIME, sparts, - birth_time); - list[6] = io_make_output_field("BirthDensity", FLOAT, 1, UNIT_CONV_DENSITY, - sparts, birth.density); + 1.f, sparts, h, + "Co-moving smoothing lengths (FWHM of the kernel) of the particles"); + + if (with_cosmology) { + list[5] = io_make_output_field( + "BirthScaleFactors", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, sparts, + birth_scale_factor, "Scale-factors at which the stars were born"); + } else { + list[5] = io_make_output_field("BirthTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, + sparts, birth_time, + "Times at which the stars were born"); + } + + list[6] = io_make_output_field( + "BirthDensities", FLOAT, 1, UNIT_CONV_DENSITY, 0.f, sparts, birth.density, + "Physical densities at the time of birth of the gas particles that " + "turned into stars (note that " + "we store the physical density at the birth redshift, no conversion is " + "needed)"); + list[7] = - 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, - birth.mass); + io_make_output_field("BirthTemperatures", FLOAT, 1, UNIT_CONV_TEMPERATURE, + 0.f, sparts, birth.temperature, + "Temperatures at the time of birth of the gas " + "particles that turned into stars"); + + list[7] = io_make_output_field("BirthMasses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + sparts, birth.mass, + "Masses of the star particles at birth time"); #ifdef DEBUG_INTERACTIONS_STARS -- GitLab From 78186240b55c7256ad0cabc8efdb346ac128c831 Mon Sep 17 00:00:00 2001 From: loikki Date: Wed, 31 Jul 2019 09:39:57 +0200 Subject: [PATCH 16/16] Format --- src/stars/GEAR/stars_io.h | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/stars/GEAR/stars_io.h b/src/stars/GEAR/stars_io.h index bcbd5bdbf..ebd72aa50 100644 --- a/src/stars/GEAR/stars_io.h +++ b/src/stars/GEAR/stars_io.h @@ -58,33 +58,32 @@ INLINE static void stars_read_particles(struct spart *sparts, * @param with_cosmology Is it a cosmological run? */ INLINE static void stars_write_particles(const struct spart *sparts, - struct io_props *list, - int *num_fields, - const int with_cosmology) { + struct io_props *list, int *num_fields, + const int with_cosmology) { /* Say how much we want to write */ *num_fields = 9; /* List what we want to write */ - list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, 1., - sparts, x, "Co-moving positions of the particles"); + list[0] = + io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, 1., + sparts, x, "Co-moving positions of the particles"); - list[1] = - io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, sparts, v, - "Peculiar velocities of the stars. This is (a * dx/dt) where x is the " - "co-moving positions of the particles"); + list[1] = io_make_output_field( + "Velocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, sparts, v, + "Peculiar velocities of the stars. This is (a * dx/dt) where x is the " + "co-moving positions of the particles"); - list[2] = - io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, sparts, mass, - "Masses of the particles"); + list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, 0.f, + sparts, mass, "Masses of the particles"); - list[3] = io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, - 0.f, sparts, id, - "Unique IDs of the particles"); + list[3] = + io_make_output_field("ParticleIDs", LONGLONG, 1, UNIT_CONV_NO_UNITS, 0.f, + sparts, id, "Unique IDs of the particles"); - list[4] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, - 1.f, sparts, h, - "Co-moving smoothing lengths (FWHM of the kernel) of the particles"); + list[4] = io_make_output_field( + "SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, 1.f, sparts, h, + "Co-moving smoothing lengths (FWHM of the kernel) of the particles"); if (with_cosmology) { list[5] = io_make_output_field( -- GitLab