diff --git a/examples/test.c b/examples/test.c index 188b20c4118bf6aec607566ff9859803892b9d9a..f6c6423a75c37b11ac619c333114bcc47a248ef8 100644 --- a/examples/test.c +++ b/examples/test.c @@ -447,6 +447,23 @@ void kernel_dump ( int N ) { } +float gadget ( float r ) { + float fac, h_inv, u, r2 = r*r; + if ( r >= const_epsilon ) + fac = 1.0f / (r2 * r); + else { + h_inv = 1. / const_epsilon; + u = r * h_inv; + if ( u < 0.5 ) + fac = const_iepsilon3 * (10.666666666667 + u * u * (32.0 * u - 38.4)); + else + fac = const_iepsilon3 * (21.333333333333 - 48.0 * u + + 38.4 * u * u - 10.666666666667 * u * u * u - 0.066666666667 / (u * u * u)); + } + return const_G * fac; +} + + void gravity_dump ( float r_max , int N ) { int k; @@ -455,22 +472,6 @@ void gravity_dump ( float r_max , int N ) { float w4[4] = {0.0f,0.0f,0.0f,0.0f}; // float dw_dx4[4] __attribute__ ((aligned (16))); - float gadget ( float r ) { - float fac, h_inv, u, r2 = r*r; - if ( r >= const_epsilon ) - fac = 1.0f / (r2 * r); - else { - h_inv = 1. / const_epsilon; - u = r * h_inv; - if ( u < 0.5 ) - fac = const_iepsilon3 * (10.666666666667 + u * u * (32.0 * u - 38.4)); - else - fac = const_iepsilon3 * (21.333333333333 - 48.0 * u + - 38.4 * u * u - 10.666666666667 * u * u * u - 0.066666666667 / (u * u * u)); - } - return const_G * fac; - } - for ( k = 1 ; k <= N ; k++ ) { x = (r_max * k) / N; x4[3] = x4[2]; x4[2] = x4[1]; x4[1] = x4[0]; x4[0] = x; diff --git a/src/space.c b/src/space.c index fcdbfa24906153252f3b8a8855ca63703c648da6..2e6df8d2fadf0674f9332afa2b86d1b37fdd8232 100644 --- a/src/space.c +++ b/src/space.c @@ -777,8 +777,34 @@ void space_map_clearsort(struct cell *c, void *data) { } } + +/** + * @brief Map a function to all particles in a cell recursively. + * + * @param s The #space we are working in. + * @param fun Function pointer to apply on the cells. + * @param data Data passed to the function fun. + */ + +static void rec_map_parts(struct cell * c, + void (*fun)(struct part *p, struct cell *c, void *data), + void *data) { + + int k; + + /* No progeny? */ + if (!c->split) + for (k = 0; k < c->count; k++) fun(&c->parts[k], c, data); + + /* Otherwise, recurse. */ + else + for (k = 0; k < 8; k++) + if (c->progeny[k] != NULL) rec_map_parts(c->progeny[k], fun, data); +} + + /** - * @brief Map a function to all particles in a aspace. + * @brief Map a function to all particles in a space. * * @param s The #space we are working in. * @param fun Function pointer to apply on the cells. @@ -791,26 +817,38 @@ void space_map_parts(struct space *s, int cid = 0; - void rec_map(struct cell * c) { + /* Call the recursive function on all higher-level cells. */ + for (cid = 0; cid < s->nr_cells; cid++) rec_map_parts(&s->cells[cid], fun, data); +} - int k; - /* No progeny? */ - if (!c->split) - for (k = 0; k < c->count; k++) fun(&c->parts[k], c, data); +/** + * @brief Map a function to all particles in a cell recursively. + * + * @param s The #space we are working in. + * @param full Map to all cells, including cells with sub-cells. + * @param fun Function pointer to apply on the cells. + * @param data Data passed to the function fun. + */ - /* Otherwise, recurse. */ - else - for (k = 0; k < 8; k++) - if (c->progeny[k] != NULL) rec_map(c->progeny[k]); - } +static void rec_map_cells_post(struct cell * c, int full, + void (*fun)(struct cell *c, void *data), + void *data) { - /* Call the recursive function on all higher-level cells. */ - for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]); + int k; + + /* Recurse. */ + if (c->split) + for (k = 0; k < 8; k++) + if (c->progeny[k] != NULL) rec_map_cells_post(c->progeny[k], full, fun, data); + + /* No progeny? */ + if (full || !c->split) fun(c, data); } + /** - * @brief Map a function to all particles in a aspace. + * @brief Map a function to all particles in a space. * * @param s The #space we are working in. * @param full Map to all cells, including cells with sub-cells. @@ -819,49 +857,45 @@ void space_map_parts(struct space *s, */ void space_map_cells_post(struct space *s, int full, - void (*fun)(struct cell *c, void *data), void *data) { + void (*fun)(struct cell *c, void *data), + void *data) { int cid = 0; - void rec_map(struct cell * c) { + /* Call the recursive function on all higher-level cells. */ + for (cid = 0; cid < s->nr_cells; cid++) rec_map_cells_post(&s->cells[cid], full, fun, data); +} - int k; - /* Recurse. */ - if (c->split) - for (k = 0; k < 8; k++) - if (c->progeny[k] != NULL) rec_map(c->progeny[k]); - /* No progeny? */ - if (full || !c->split) fun(c, data); - } +static void rec_map_cells_pre(struct cell * c, int full, + void (*fun)(struct cell *c, void *data), + void *data) { - /* Call the recursive function on all higher-level cells. */ - for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]); + int k; + + /* No progeny? */ + if (full || !c->split) fun(c, data); + + /* Recurse. */ + if (c->split) + for (k = 0; k < 8; k++) + if (c->progeny[k] != NULL) rec_map_cells_pre(c->progeny[k], full, fun, data); } -void space_map_cells_pre(struct space *s, int full, - void (*fun)(struct cell *c, void *data), void *data) { - - int cid = 0; - void rec_map(struct cell * c) { - int k; - - /* No progeny? */ - if (full || !c->split) fun(c, data); +void space_map_cells_pre(struct space *s, int full, + void (*fun)(struct cell *c, void *data), + void *data) { - /* Recurse. */ - if (c->split) - for (k = 0; k < 8; k++) - if (c->progeny[k] != NULL) rec_map(c->progeny[k]); - } + int cid = 0; /* Call the recursive function on all higher-level cells. */ - for (cid = 0; cid < s->nr_cells; cid++) rec_map(&s->cells[cid]); + for (cid = 0; cid < s->nr_cells; cid++) rec_map_cells_pre(&s->cells[cid], full, fun, data); } + /** * @brief Split cells that contain too many particles. *