diff --git a/examples/main.c b/examples/main.c index 32798b2ee4f3958f5f0e3f91f228dc6b24b5d397..7a031e6d942f21b827ce5e54c2fc3af75533caef 100644 --- a/examples/main.c +++ b/examples/main.c @@ -681,6 +681,28 @@ int main(int argc, char *argv[]) { phys_const_print(&prog_const); } + /* Read particles and space information from ICs */ + char ICfileName[200] = ""; + parser_get_param_string(params, "InitialConditions:file_name", ICfileName); + const int periodic = + parser_get_param_int(params, "InitialConditions:periodic"); + const int replicate = + parser_get_opt_param_int(params, "InitialConditions:replicate", 1); + clean_smoothing_length_values = parser_get_opt_param_int( + params, "InitialConditions:cleanup_smoothing_lengths", 0); + const int cleanup_h = parser_get_opt_param_int( + params, "InitialConditions:cleanup_h_factors", 0); + const int cleanup_sqrt_a = parser_get_opt_param_int( + params, "InitialConditions:cleanup_velocity_factors", 0); + const int generate_gas_in_ics = parser_get_opt_param_int( + params, "InitialConditions:generate_gas_in_ics", 0); + + /* Some checks that we are not doing something stupid */ + if (generate_gas_in_ics && flag_entropy_ICs) + error("Can't generate gas if the entropy flag is set in the ICs."); + if (generate_gas_in_ics && !with_cosmology) + error("Can't generate gas if the run is not cosmological."); + /* Initialise the cosmology */ if (with_cosmology) cosmology_init(params, &us, &prog_const, &cosmo); @@ -709,32 +731,11 @@ int main(int argc, char *argv[]) { /* Initialise the gravity properties */ if (with_self_gravity) - gravity_props_init(&gravity_properties, params, &cosmo, with_cosmology); + gravity_props_init(&gravity_properties, params, &cosmo, with_cosmology, + periodic); else bzero(&gravity_properties, sizeof(struct gravity_props)); - /* Read particles and space information from ICs */ - char ICfileName[200] = ""; - parser_get_param_string(params, "InitialConditions:file_name", ICfileName); - const int periodic = - parser_get_param_int(params, "InitialConditions:periodic"); - const int replicate = - parser_get_opt_param_int(params, "InitialConditions:replicate", 1); - clean_smoothing_length_values = parser_get_opt_param_int( - params, "InitialConditions:cleanup_smoothing_lengths", 0); - const int cleanup_h = parser_get_opt_param_int( - params, "InitialConditions:cleanup_h_factors", 0); - const int cleanup_sqrt_a = parser_get_opt_param_int( - params, "InitialConditions:cleanup_velocity_factors", 0); - const int generate_gas_in_ics = parser_get_opt_param_int( - params, "InitialConditions:generate_gas_in_ics", 0); - - /* Some checks that we are not doing something stupid */ - if (generate_gas_in_ics && flag_entropy_ICs) - error("Can't generate gas if the entropy flag is set in the ICs."); - if (generate_gas_in_ics && !with_cosmology) - error("Can't generate gas if the run is not cosmological."); - /* Be verbose about what happens next */ if (myrank == 0) message("Reading ICs from file '%s'", ICfileName); if (myrank == 0 && cleanup_h) diff --git a/src/gravity_properties.c b/src/gravity_properties.c index 40cd7cecb10eab7ebbe7b59d34fb15dccac8b620..fffbf22ec187f179f0e80b7121beaa3a96de0260 100644 --- a/src/gravity_properties.c +++ b/src/gravity_properties.c @@ -39,7 +39,8 @@ #define gravity_props_default_rebuild_frequency 0.01f void gravity_props_init(struct gravity_props *p, struct swift_params *params, - const struct cosmology *cosmo, int with_cosmology) { + const struct cosmology *cosmo, int with_cosmology, + int periodic) { /* Tree updates */ p->rebuild_frequency = @@ -50,24 +51,31 @@ void gravity_props_init(struct gravity_props *p, struct swift_params *params, error("Invalid tree rebuild frequency. Must be in [0., 1.]"); /* Tree-PM parameters */ - p->mesh_size = parser_get_param_int(params, "Gravity:mesh_side_length"); - p->a_smooth = parser_get_opt_param_float(params, "Gravity:a_smooth", - gravity_props_default_a_smooth); - p->r_cut_max_ratio = parser_get_opt_param_float( - params, "Gravity:r_cut_max", gravity_props_default_r_cut_max); - p->r_cut_min_ratio = parser_get_opt_param_float( - params, "Gravity:r_cut_min", gravity_props_default_r_cut_min); - - /* Some basic checks */ - if (p->mesh_size % 2 != 0) - error("The mesh side-length must be an even number."); - - if (p->a_smooth <= 0.) - error("The mesh smoothing scale 'a_smooth' must be > 0."); - - if (2. * p->a_smooth * p->r_cut_max_ratio > p->mesh_size) - error("Mesh too small given r_cut_max. Should be at least %d cells wide.", - (int)(2. * p->a_smooth * p->r_cut_max_ratio) + 1); + if (periodic) { + p->mesh_size = parser_get_param_int(params, "Gravity:mesh_side_length"); + p->a_smooth = parser_get_opt_param_float(params, "Gravity:a_smooth", + gravity_props_default_a_smooth); + p->r_cut_max_ratio = parser_get_opt_param_float( + params, "Gravity:r_cut_max", gravity_props_default_r_cut_max); + p->r_cut_min_ratio = parser_get_opt_param_float( + params, "Gravity:r_cut_min", gravity_props_default_r_cut_min); + + /* Some basic checks of what we read */ + if (p->mesh_size % 2 != 0) + error("The mesh side-length must be an even number."); + + if (p->a_smooth <= 0.) + error("The mesh smoothing scale 'a_smooth' must be > 0."); + + if (2. * p->a_smooth * p->r_cut_max_ratio > p->mesh_size) + error("Mesh too small given r_cut_max. Should be at least %d cells wide.", + (int)(2. * p->a_smooth * p->r_cut_max_ratio) + 1); + } else { + p->mesh_size = 0; + p->a_smooth = 0.f; + p->r_cut_min_ratio = 0.f; + p->r_cut_max_ratio = 0.f; + } /* Time integration */ p->eta = parser_get_param_float(params, "Gravity:eta"); diff --git a/src/gravity_properties.h b/src/gravity_properties.h index 62dbab3605fb2dcfc4ae65e54c0b5f913d714c16..0cabd9958efa2bb23524d03632f90fdd1f1c8306 100644 --- a/src/gravity_properties.h +++ b/src/gravity_properties.h @@ -88,7 +88,8 @@ struct gravity_props { void gravity_props_print(const struct gravity_props *p); void gravity_props_init(struct gravity_props *p, struct swift_params *params, - const struct cosmology *cosmo, int with_cosmology); + const struct cosmology *cosmo, int with_cosmology, + int periodic); void gravity_update(struct gravity_props *p, const struct cosmology *cosmo); #if defined(HAVE_HDF5)