From d887e8f441d2ceddb6e40c3698b77495c4623deb Mon Sep 17 00:00:00 2001 From: wjr21 <wjr21@sussex.ac.uk> Date: Mon, 31 Jan 2022 15:37:13 +0000 Subject: [PATCH] initialised gravity proir to space_init and passed gravity properties through the find neighbours for calulation of the number of neighbour cells --- examples/main.c | 24 ++++++++++++------------ src/space.c | 7 ++++--- src/space.h | 7 ++++--- src/space_regrid.c | 5 +++-- src/zoom_region.c | 11 +++++------ src/zoom_region.h | 5 +++-- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/examples/main.c b/examples/main.c index dd69e09b3c..a4c3d6fb65 100644 --- a/examples/main.c +++ b/examples/main.c @@ -1269,12 +1269,20 @@ int main(int argc, char *argv[]) { neutrino_props_init(&neutrino_properties, &prog_const, &us, params, &cosmo); + /* Initialise the gravity properties */ + bzero(&gravity_properties, sizeof(struct gravity_props)); + if (with_self_gravity) + gravity_props_init( + &gravity_properties, params, &prog_const, &cosmo, with_cosmology, + with_external_gravity, with_baryon_particles, with_DM_particles, + with_neutrinos, with_DM_background_particles, periodic, dim); + /* Initialize the space with these data. */ if (myrank == 0) clocks_gettime(&tic); - space_init(&s, params, &cosmo, dim, &hydro_properties, parts, gparts, sinks, - sparts, bparts, Ngas, Ngpart, Nsink, Nspart, Nbpart, Nnupart, - periodic, replicate, remap_ids, generate_gas_in_ics, with_hydro, - with_self_gravity, with_star_formation, with_sink, + space_init(&s, params, &cosmo, dim, &hydro_properties, &gravity_properties, + parts, gparts, sinks, sparts, bparts, Ngas, Ngpart, Nsink, Nspart, + Nbpart, Nnupart, periodic, replicate, remap_ids, generate_gas_in_ics, + with_hydro, with_self_gravity, with_star_formation, with_sink, with_DM_background_particles, with_neutrinos, talking, dry_run, nr_nodes); @@ -1288,14 +1296,6 @@ int main(int argc, char *argv[]) { fflush(stdout); } - /* Initialise the gravity properties */ - bzero(&gravity_properties, sizeof(struct gravity_props)); - if (with_self_gravity) - gravity_props_init( - &gravity_properties, params, &prog_const, &cosmo, with_cosmology, - with_external_gravity, with_baryon_particles, with_DM_particles, - with_neutrinos, with_DM_background_particles, periodic, s.dim); - /* Initialise the external potential properties */ bzero(&potential, sizeof(struct external_potential)); if (with_external_gravity) diff --git a/src/space.c b/src/space.c index 4bbe95b802..a43aa89d0f 100644 --- a/src/space.c +++ b/src/space.c @@ -44,6 +44,7 @@ #include "atomic.h" #include "const.h" #include "cooling.h" +#include "gravity_properties.h" #include "engine.h" #include "error.h" #include "kernel_hydro.h" @@ -1069,8 +1070,8 @@ void space_collect_mean_masses(struct space *s, int verbose) { */ void space_init(struct space *s, struct swift_params *params, const struct cosmology *cosmo, double dim[3], - const struct hydro_props *hydro_properties, struct part *parts, - struct gpart *gparts, struct sink *sinks, struct spart *sparts, + const struct hydro_props *hydro_properties, struct gravity_props *gravity_properties, + struct part *parts, struct gpart *gparts, struct sink *sinks, struct spart *sparts, struct bpart *bparts, size_t Npart, size_t Ngpart, size_t Nsink, size_t Nspart, size_t Nbpart, size_t Nnupart, int periodic, int replicate, int remap_ids, int generate_gas_in_ics, @@ -1448,7 +1449,7 @@ void space_init(struct space *s, struct swift_params *params, } /* Build the cells recursively. */ - if (!dry_run) space_regrid(s, verbose); + if (!dry_run) space_regrid(s, gravity_properties, verbose); /* Compute the max id for the generation of unique id. */ if (create_sparts) { diff --git a/src/space.h b/src/space.h index 96430b8ebb..af995bbbce 100644 --- a/src/space.h +++ b/src/space.h @@ -30,6 +30,7 @@ #include <stddef.h> /* Includes. */ +#include "gravity_properties.h" #include "hydro_space.h" #include "lock.h" #include "parser.h" @@ -383,8 +384,8 @@ void space_sinks_sort(struct sink *sinks, int *ind, int *counts, int num_bins, void space_getcells(struct space *s, int nr_cells, struct cell **cells); void space_init(struct space *s, struct swift_params *params, const struct cosmology *cosmo, double dim[3], - const struct hydro_props *hydro_properties, struct part *parts, - struct gpart *gparts, struct sink *sinks, struct spart *sparts, + const struct hydro_props *hydro_properties, struct gravity_props *gravity_properties, + struct part *parts, struct gpart *gparts, struct sink *sinks, struct spart *sparts, struct bpart *bparts, size_t Npart, size_t Ngpart, size_t Nsink, size_t Nspart, size_t Nbpart, size_t Nnupart, int periodic, int replicate, int remap_ids, int generate_gas_in_ics, @@ -408,7 +409,7 @@ void space_recycle_list(struct space *s, struct cell *cell_list_begin, struct cell *cell_list_end, struct gravity_tensors *multipole_list_begin, struct gravity_tensors *multipole_list_end); -void space_regrid(struct space *s, int verbose); +void space_regrid(struct space *s, struct gravity_props *p, int verbose); void space_allocate_extras(struct space *s, int verbose); void space_split(struct space *s, int verbose); void space_reorder_extras(struct space *s, int verbose); diff --git a/src/space_regrid.c b/src/space_regrid.c index a6bde247f1..0543915dc7 100644 --- a/src/space_regrid.c +++ b/src/space_regrid.c @@ -27,6 +27,7 @@ /* Local headers. */ #include "cell.h" +#include "gravity_properties.h" #include "engine.h" #include "scheduler.h" #include "zoom_region.h" @@ -37,7 +38,7 @@ * @param s The #space. * @param verbose Print messages to stdout or not. */ -void space_regrid(struct space *s, int verbose) { +void space_regrid(struct space *s, struct gravity_props *gravity_properties, int verbose) { const size_t nr_parts = s->nr_parts; const size_t nr_sparts = s->nr_sparts; @@ -314,7 +315,7 @@ void space_regrid(struct space *s, int verbose) { } #ifdef WITH_ZOOM_REGION - construct_tl_cells_with_zoom_region(s, cdim, dmin, ti_current, verbose); + construct_tl_cells_with_zoom_region(s, cdim, dmin, ti_current, gravity_properties, verbose); #else /* Set the cell location and sizes. */ for (int i = 0; i < cdim[0]; i++) diff --git a/src/zoom_region.c b/src/zoom_region.c index 71144e63b1..1aa693b466 100644 --- a/src/zoom_region.c +++ b/src/zoom_region.c @@ -4,6 +4,7 @@ #include <float.h> #include "cell.h" +#include "gravity_properties.h" #include "engine.h" #include "proxy.h" #include "space.h" @@ -226,7 +227,7 @@ void construct_zoom_region(struct space *s, int verbose) { * @param verbose Are we talking? */ void construct_tl_cells_with_zoom_region(struct space *s, const int *cdim, const float dmin, - const integertime_t ti_current, int verbose) { + const integertime_t ti_current, struct gravity_props *gravity_properties, int verbose) { #ifdef WITH_ZOOM_REGION /* We are recomputing the boundary of the zoom region. */ @@ -409,7 +410,7 @@ void construct_tl_cells_with_zoom_region(struct space *s, const int *cdim, const } /* Now find what cells neighbour the zoom region. */ - if (s->with_zoom_region) find_neighbouring_cells(s, verbose); + if (s->with_zoom_region) find_neighbouring_cells(s, gravity_properties, verbose); #endif } @@ -423,7 +424,7 @@ void construct_tl_cells_with_zoom_region(struct space *s, const int *cdim, const * @param s The space. * @param verbose Are we talking? */ -void find_neighbouring_cells(struct space *s, const int verbose) { +void find_neighbouring_cells(struct space *s, struct gravity_props *gravity_properties, const int verbose) { #ifdef WITH_ZOOM_REGION const int cdim[3] = {s->cdim[0], s->cdim[1], s->cdim[2]}; const int periodic = s->periodic; @@ -432,10 +433,8 @@ void find_neighbouring_cells(struct space *s, const int verbose) { /* Some info about the zoom domain */ const int bkg_cell_offset = s->zoom_props->tl_cell_offset; - message("Got here"); - /* Get some info about the physics */ - const double theta_crit_inv = 1. / 0.7; + const double theta_crit_inv = 1. / gravity_properties->theta_crit; /* Maximal distance from shifted CoM to any corner */ const double distance = 2. * cells[bkg_cell_offset].width[0] * theta_crit_inv; diff --git a/src/zoom_region.h b/src/zoom_region.h index c0b97c9340..ede64fe41e 100644 --- a/src/zoom_region.h +++ b/src/zoom_region.h @@ -1,4 +1,5 @@ #include "cell.h" +#include "gravity_properties.h" #include "space.h" #ifndef SWIFT_ZOOM_H @@ -10,8 +11,8 @@ int cell_getid_zoom(const int cdim[3], const double x, const double y, const int i, const int j, const int k); void construct_zoom_region(struct space *s, int verbose); void construct_tl_cells_with_zoom_region(struct space *s, const int *cdim, const float dmin, - const integertime_t ti_current, int verbose); -void find_neighbouring_cells(struct space *s, const int verbose); + const integertime_t ti_current, struct gravity_props *gravity_properties, int verbose); +void find_neighbouring_cells(struct space *s, struct gravity_props *gravity_properties, const int verbose); double cell_min_dist2_diff_size(const struct cell *restrict ci, const struct cell *restrict cj, const int periodic, const double dim[3]); -- GitLab