Commit 359fc87d authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Star density works, still need cleaning/testing

parent 5cfd39f0
......@@ -2696,7 +2696,7 @@ void engine_make_starloop_tasks_mapper(void *map_data, int num_elements,
/* Skip cells without star particles */
if (ci->scount == 0) continue;
/* If the cells is local build a self-interaction */
if (ci->nodeID == nodeID)
scheduler_addtask(sched, task_type_self, task_subtype_star_density, 0, 0, ci,
......@@ -2721,13 +2721,13 @@ void engine_make_starloop_tasks_mapper(void *map_data, int num_elements,
struct cell *cj = &cells[cjd];
/* Is that neighbour local and does it have particles ? */
if (cid >= cjd || cj->scount == 0 ||
if (cid >= cjd || cj->count == 0 ||
(ci->nodeID != nodeID && cj->nodeID != nodeID))
continue;
/* Construct the pair task */
const int sid = sortlistID[(kk + 1) + 3 * ((jj + 1) + 3 * (ii + 1))];
scheduler_addtask(sched, task_type_pair, task_subtype_star_density, sid, 0,
scheduler_addtask(sched, task_type_pair, task_subtype_star_density, sid, 0,
ci, cj);
}
}
......@@ -3362,8 +3362,6 @@ void engine_link_star_tasks_mapper(void *map_data, int num_elements,
if (t->cj->nodeID == nodeID) {
if (t->ci->super_hydro != t->cj->super)
engine_make_star_loops_dependencies(sched, t, t->cj);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t, t->cj->super->end_force);
}
}
......@@ -3380,7 +3378,6 @@ void engine_link_star_tasks_mapper(void *map_data, int num_elements,
/* that are local and are not descendant of the same super_hydro-cells */
if (t->ci->nodeID == nodeID) {
engine_make_star_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t, t->ci->super->end_force);
} else
error("oo");
}
......@@ -3403,13 +3400,10 @@ void engine_link_star_tasks_mapper(void *map_data, int num_elements,
/* that are local and are not descendant of the same super_hydro-cells */
if (t->ci->nodeID == nodeID) {
engine_make_star_loops_dependencies(sched, t, t->ci);
scheduler_addunlock(sched, t, t->ci->super->end_force);
}
if (t->cj->nodeID == nodeID) {
if (t->ci->super != t->cj->super)
engine_make_star_loops_dependencies(sched, t, t->cj);
if (t->ci->super != t->cj->super)
scheduler_addunlock(sched, t, t->cj->super->end_force);
}
}
}
......@@ -4922,6 +4916,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
/* Init the particle data (by hand). */
space_init_parts(s, e->verbose);
space_init_gparts(s, e->verbose);
space_init_sparts(s, e->verbose);
/* Now, launch the calculation */
TIMER_TIC;
......@@ -4970,6 +4965,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
/* Init the particle data (by hand). */
space_init_parts(e->s, e->verbose);
space_init_gparts(e->s, e->verbose);
space_init_sparts(e->s, e->verbose);
/* Print the number of active tasks ? */
if (e->verbose) engine_print_task_counts(e);
......
......@@ -149,12 +149,12 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
const struct engine *e = r->e;
const struct cosmology *cosmo = e->cosmology;
const struct stars_props *stars_properties = e->stars_properties;
const float star_h_max = e->stars_properties->h_max;
const float eps = e->stars_properties->h_tolerance;
const float star_h_max = stars_properties->h_max;
const float eps = stars_properties->h_tolerance;
const float star_eta_dim =
pow_dimension(e->stars_properties->eta_neighbours);
const int max_smoothing_iter = e->stars_properties->max_smoothing_iterations;
int redo = 0, count = 0;
pow_dimension(stars_properties->eta_neighbours);
const int max_smoothing_iter = stars_properties->max_smoothing_iterations;
int redo = 0, scount = 0;
TIMER_TIC;
......@@ -173,19 +173,19 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
error("Can't allocate memory for sid.");
for (int k = 0; k < c->scount; k++)
if (spart_is_active(&sparts[k], e)) {
sid[count] = k;
++count;
sid[scount] = k;
++scount;
}
/* While there are particles that need to be updated... */
for (int num_reruns = 0; count > 0 && num_reruns < max_smoothing_iter;
for (int num_reruns = 0; scount > 0 && num_reruns < max_smoothing_iter;
num_reruns++) {
/* Reset the redo-count. */
redo = 0;
/* Loop over the remaining active parts in this cell. */
for (int i = 0; i < count; i++) {
for (int i = 0; i < scount; i++) {
/* Get a direct pointer on the part. */
struct spart *sp = &sparts[sid[i]];
......@@ -249,7 +249,7 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
redo += 1;
/* Re-initialise everything */
star_init_spart(sp, stars_properties);
star_init_spart(sp);
/* Off we go ! */
continue;
......@@ -266,7 +266,7 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
}
}
/* We now have a particle whose smoothing length has converged */
/* We now have a particle whose smoothing length has converged */
/* As of here, particle force variables will be set. */
......@@ -285,8 +285,8 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
* converged again */
/* Re-set the counter for the next loop (potentially). */
count = redo;
if (count > 0) {
scount = redo;
if (scount > 0) {
/* Climb up the cell hierarchy. */
for (struct cell *finger = c; finger != NULL; finger = finger->parent) {
......@@ -301,7 +301,7 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Self-interaction? */
if (l->t->type == task_type_self)
runner_doself_subset_branch_star_density(r, finger, sparts, sid, count);
runner_doself_subset_branch_star_density(r, finger, sparts, sid, scount);
/* Otherwise, pair interaction? */
else if (l->t->type == task_type_pair) {
......@@ -309,15 +309,15 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Left or right? */
if (l->t->ci == finger)
runner_dopair_subset_branch_star_density(r, finger, sparts, sid,
count, l->t->cj);
scount, l->t->cj);
else
runner_dopair_subset_branch_star_density(r, finger, sparts, sid,
count, l->t->ci);
scount, l->t->ci);
}
/* Otherwise, sub-self interaction? */
else if (l->t->type == task_type_sub_self)
runner_dosub_subset_star_density(r, finger, sparts, sid, count, NULL,
runner_dosub_subset_star_density(r, finger, sparts, sid, scount, NULL,
-1, 1);
/* Otherwise, sub-pair interaction? */
......@@ -325,10 +325,10 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
/* Left or right? */
if (l->t->ci == finger)
runner_dosub_subset_star_density(r, finger, sparts, sid, count,
runner_dosub_subset_star_density(r, finger, sparts, sid, scount,
l->t->cj, -1, 1);
else
runner_dosub_subset_star_density(r, finger, sparts, sid, count,
runner_dosub_subset_star_density(r, finger, sparts, sid, scount,
l->t->ci, -1, 1);
}
}
......@@ -336,14 +336,20 @@ void runner_do_star_ghost(struct runner *r, struct cell *c, int timer) {
}
}
if (count) {
error("Smoothing length failed to converge on %i particles.", count);
if (scount) {
error("Smoothing length failed to converge on %i particles.", scount);
}
/* Be clean */
free(sid);
}
/* Reset the data for next loop */
for (int k = 0; k < c->scount; k++)
if (spart_is_active(&sparts[k], e)) {
star_init_spart(&sparts[k]);
}
if (timer) TIMER_TOC(timer_do_star_ghost);
}
......
......@@ -78,8 +78,9 @@ void runner_doself_star_density(struct runner *r, struct cell *c, int timer) {
error("Particle pj not drifted to current time");
#endif
if (r2 < hig2)
if (r2 < hig2) {
runner_iact_nonsym_star_density(r2, dx, hi, hj, si, pj, a, H);
}
} /* loop over the parts in ci. */
} /* loop over the sparts in ci. */
......
......@@ -315,7 +315,7 @@ void scheduler_write_dependencies(struct scheduler *s, int verbose) {
fprintf(f, "\t};\n");
/* Make a cluster for the density tasks */
fprintf(f, "\t subgraph cluster0{\n");
fprintf(f, "\t subgraph cluster4{\n");
fprintf(f, "\t\t label=\"\";\n");
for (int k = 0; k < 4; ++k)
if (star_density_cluster[k])
......
......@@ -2669,6 +2669,32 @@ void space_init_gparts(struct space *s, int verbose) {
clocks_getunit());
}
void space_init_sparts_mapper(void *restrict map_data, int scount,
void *restrict extra_data) {
struct spart *restrict sparts = (struct spart *)map_data;
for (int k = 0; k < scount; k++) star_init_spart(&sparts[k]);
}
/**
* @brief Calls the #spart initialisation function on all particles in the space.
*
* @param s The #space.
* @param verbose Are we talkative?
*/
void space_init_sparts(struct space *s, int verbose) {
const ticks tic = getticks();
if (s->nr_sparts > 0)
threadpool_map(&s->e->threadpool, space_init_sparts_mapper, s->sparts,
s->nr_sparts, sizeof(struct spart), 0, NULL);
if (verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
}
void space_convert_quantities_mapper(void *restrict map_data, int count,
void *restrict extra_data) {
struct space *s = (struct space *)extra_data;
......
......@@ -244,6 +244,7 @@ void space_first_init_gparts(struct space *s, int verbose);
void space_first_init_sparts(struct space *s, int verbose);
void space_init_parts(struct space *s, int verbose);
void space_init_gparts(struct space *s, int verbose);
void space_init_sparts(struct space *s, int verbose);
void space_convert_quantities(struct space *s, int verbose);
void space_link_cleanup(struct space *s);
void space_check_drift_point(struct space *s, integertime_t ti_drift,
......
......@@ -53,7 +53,7 @@ __attribute__((always_inline)) INLINE static void star_first_init_spart(
* @param sp The particle to act upon
*/
__attribute__((always_inline)) INLINE static void star_init_spart(
struct spart* sp, const struct stars_props *stars_properties) {
struct spart* sp) {
#ifdef DEBUG_INTERACTIONS_SPH
for (int i = 0; i < MAX_NUM_OF_NEIGHBOURS; ++i) sp->ids_ngbs_density[i] = -1;
......
......@@ -105,7 +105,7 @@ INLINE static void stars_props_init(struct stars_props *sp,
/* Maximal smoothing length */
sp->h_max = parser_get_opt_param_float(params, "Stars:h_max",
sp->h_max);
p->h_max);
/* Number of iterations to converge h */
sp->max_smoothing_iterations = parser_get_opt_param_int(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment