diff --git a/examples/EAGLE_6/eagle_6.yml b/examples/EAGLE_6/eagle_6.yml index 9f013c15eb5a8fba6c7196f1120772b5ffc9fa0b..adf2d1a3ca0a31a8a0bd280723fbfe8dec83c7d1 100644 --- a/examples/EAGLE_6/eagle_6.yml +++ b/examples/EAGLE_6/eagle_6.yml @@ -65,10 +65,12 @@ SPH: # Parameters for the Friends-Of-Friends algorithm FOF: - min_group_size: 20 # The minimum no. of particles required for a group. - linking_length_scale: 0.2 # Scales the linking length. - #absolute_linking_length: 0.2 # Absolute linking length. Overrides default value of using the linking_length_scale parameter and the mean inter-particle separation. - basename: fof_output # Common part of the name of output files + min_group_size: 20 # The minimum no. of particles required for a group. + linking_length_scale: 0.2 # Scales the linking length. + #group_links_size_default: 20000 # Sets the initial size of the group_links array, which is used to store links across MPI domains. + #interface_cells_size_default: 4000 # Sets the initial size of the interface_cells array, which is used to store a list of local cells that touch foreign cells. + #absolute_linking_length: 0.2 # Absolute linking length. Overrides default value of using the linking_length_scale parameter and the mean inter-particle separation. + basename: fof_output # Common part of the name of output files # Parameters related to the initial conditions InitialConditions: diff --git a/src/fof.c b/src/fof.c index fec4a6f3b1dd740e8e83a8c9904496a20ad1b16c..9444dad364a44d3cde589af659bbc6db81a20839 100644 --- a/src/fof.c +++ b/src/fof.c @@ -59,7 +59,10 @@ void fof_init(struct space *s, long long Ngas, long long Ngparts) { error("Cannot write FOF outputs in directory %s (%s)", dirp, strerror(errno)); } + /* Read the minimum group size. */ s->fof_data.min_group_size = parser_get_opt_param_int(e->parameter_file, "FOF:min_group_size", 20); + + /* Read the linking length scale. */ const double l_x_scale = parser_get_opt_param_double(e->parameter_file, "FOF:linking_length_scale", 0.2); /* Calculate the particle linking length based upon the mean inter-particle @@ -71,6 +74,12 @@ void fof_init(struct space *s, long long Ngas, long long Ngparts) { s->l_x2 = l_x * l_x; + /* Read the initial group_links array size. */ + s->fof_data.group_links_size_default = parser_get_opt_param_double(e->parameter_file, "FOF:group_links_size_default", 20000); + + /* Read the initial interface cells array size. */ + s->fof_data.interface_cells_size_default = parser_get_opt_param_double(e->parameter_file, "FOF:interface_cells_size_default", 4000); + #ifdef WITH_MPI /* Check size of linking length against the top-level cell dimensions. */ if(l_x > s->width[0]) error("Linking length greater than the width of a top-level cell. Need to check more than one layer of top-level cells for links."); @@ -557,7 +566,7 @@ void fof_search_pair_cells_foreign(struct space *s, struct cell *ci, struct cell /* If the group_links array is not big enough re-allocate it. */ if(*link_count + 1 > *group_links_size) { - int new_size = *group_links_size + 0.1 * (double)(*group_links_size); + int new_size = *group_links_size + ceil(0.1 * (double)(*group_links_size)); *group_links_size = new_size; @@ -791,8 +800,8 @@ void fof_search_foreign_cells(struct space *s) { /* Make group IDs globally unique. */ for (size_t i = 0; i < nr_gparts; i++) group_index[i] += node_offset; - int group_links_size = 20000; - int interface_cell_size = 4000; + int group_links_size = s->fof_data.group_links_size_default; + int interface_cell_size = s->fof_data.interface_cells_size_default; struct fof_mpi *group_links; struct cell **interface_cells; int group_link_count = 0; @@ -839,7 +848,7 @@ void fof_search_foreign_cells(struct space *s) { /* If the interface_cells array is not big enough re-allocate it. */ if(interface_cell_count + 1 > interface_cell_size) { - int new_size = interface_cell_size + 0.1 * (double)interface_cell_size; + int new_size = interface_cell_size + ceil(0.1 * (double)interface_cell_size); interface_cell_size = new_size; interface_cells = (struct cell **)realloc(interface_cells, new_size * sizeof(struct cell *)); diff --git a/src/space.h b/src/space.h index 2c101bdb1361c8312f14b4c556a7946a3ee05517..103ca4356bef13139af673183dc3db7822794054 100644 --- a/src/space.h +++ b/src/space.h @@ -55,6 +55,8 @@ struct fof { double *group_mass; struct fof_CoM *group_CoM; int min_group_size; + int group_links_size_default; + int interface_cells_size_default; char base_name[PARSER_MAX_LINE_SIZE]; } SWIFT_STRUCT_ALIGN;