Commit bc557dee authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Add an error message when users generate gas particles that are larger than the splitting threshold

parent 20d2d4e9
......@@ -1090,10 +1090,11 @@ int main(int argc, char *argv[]) {
/* Initialize the space with these data. */
if (myrank == 0) clocks_gettime(&tic);
space_init(&s, params, &cosmo, dim, parts, gparts, sparts, bparts, Ngas,
Ngpart, Nspart, Nbpart, periodic, replicate, generate_gas_in_ics,
with_hydro, with_self_gravity, with_star_formation,
with_DM_background_particles, talking, dry_run, nr_nodes);
space_init(&s, params, &cosmo, dim, &hydro_properties, parts, gparts,
sparts, bparts, Ngas, Ngpart, Nspart, Nbpart, periodic,
replicate, generate_gas_in_ics, with_hydro, with_self_gravity,
with_star_formation, with_DM_background_particles, talking,
dry_run, nr_nodes);
/* Initialise the line of sight properties. */
if (with_line_of_sight) los_init(s.dim, &los_properties, params);
......
......@@ -516,8 +516,8 @@ int main(int argc, char *argv[]) {
/* Initialize the space with these data. */
if (myrank == 0) clocks_gettime(&tic);
space_init(&s, params, &cosmo, dim, parts, gparts, sparts, bparts, Ngas,
Ngpart, Nspart, Nbpart, periodic, replicate,
space_init(&s, params, &cosmo, dim, /*hydro_props=*/NULL, parts, gparts,
sparts, bparts, Ngas, Ngpart, Nspart, Nbpart, periodic, replicate,
/*generate_gas_in_ics=*/0, /*hydro=*/N_total[0] > 0, /*gravity=*/1,
/*with_star_formation=*/0, with_DM_background_particles, talking,
/*dry_run=*/0, nr_nodes);
......
......@@ -4807,6 +4807,7 @@ void space_convert_quantities(struct space *s, int verbose) {
* @param params The parsed parameter file.
* @param cosmo The current cosmological model.
* @param dim Spatial dimensions of the domain.
* @param hydro_properties The properties of the hydro scheme.
* @param parts Array of Gas particles.
* @param gparts Array of Gravity particles.
* @param sparts Array of stars particles.
......@@ -4833,7 +4834,8 @@ void space_convert_quantities(struct space *s, int verbose) {
*/
void space_init(struct space *s, struct swift_params *params,
const struct cosmology *cosmo, double dim[3],
struct part *parts, struct gpart *gparts, struct spart *sparts,
const struct hydro_props *hydro_properties, struct part *parts,
struct gpart *gparts, struct spart *sparts,
struct bpart *bparts, size_t Npart, size_t Ngpart,
size_t Nspart, size_t Nbpart, int periodic, int replicate,
int generate_gas_in_ics, int hydro, int self_gravity,
......@@ -4887,7 +4889,8 @@ void space_init(struct space *s, struct swift_params *params,
/* Are we generating gas from the DM-only ICs? */
if (generate_gas_in_ics) {
space_generate_gas(s, cosmo, periodic, DM_background, dim, verbose);
space_generate_gas(s, cosmo, hydro_properties, periodic, DM_background, dim,
verbose);
parts = s->parts;
gparts = s->gparts;
Npart = s->nr_parts;
......@@ -5292,12 +5295,14 @@ void space_replicate(struct space *s, int replicate, int verbose) {
*
* @param s The #space to create the particles in.
* @param cosmo The current #cosmology model.
* @param hydro_properties The properties of the hydro scheme.
* @param periodic Are we using periodic boundary conditions?
* @param with_background Are we using background DM particles?
* @param dim The size of the box (for periodic wrapping).
* @param verbose Are we talkative?
*/
void space_generate_gas(struct space *s, const struct cosmology *cosmo,
const struct hydro_props *hydro_properties,
const int periodic, const int with_background,
const double dim[3], const int verbose) {
......@@ -5323,6 +5328,11 @@ void space_generate_gas(struct space *s, const struct cosmology *cosmo,
if (s->nr_bparts != 0)
error("Generating gas particles from DM but BHs already exists!");
/* Pull out information about particle splitting */
const int particle_splitting = hydro_properties->particle_splitting;
const float splitting_mass_threshold =
hydro_properties->particle_splitting_mass_threshold;
/* Start by counting the number of background and zoom DM particles */
size_t nr_background_gparts = 0;
if (with_background) {
......@@ -5408,6 +5418,11 @@ void space_generate_gas(struct space *s, const struct cosmology *cosmo,
gp_gas->mass *= mass_ratio;
hydro_set_mass(p, gp_gas->mass);
/* Verify that we are not generating a gas particle larger than the
threashold for particle splitting */
if (particle_splitting && gp_gas->mass > splitting_mass_threshold)
error("Generating a gas particle above the threshold for splitting");
/* Set the new positions */
gp_dm->x[0] += shift_dm;
gp_dm->x[1] += shift_dm;
......
......@@ -42,6 +42,7 @@ struct cell;
struct cosmology;
struct gravity_props;
struct star_formation;
struct hydro_props;
/* Some constants. */
#define space_cellallocchunk 1000
......@@ -316,7 +317,8 @@ void space_bparts_sort(struct bpart *bparts, int *ind, int *counts,
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],
struct part *parts, struct gpart *gparts, struct spart *sparts,
const struct hydro_props *hydro_properties, struct part *parts,
struct gpart *gparts, struct spart *sparts,
struct bpart *bparts, size_t Npart, size_t Ngpart,
size_t Nspart, size_t Nbpart, int periodic, int replicate,
int generate_gas_in_ics, int hydro, int gravity,
......@@ -376,6 +378,7 @@ void space_check_swallow(struct space *s);
void space_check_sort_flags(struct space *s);
void space_replicate(struct space *s, int replicate, int verbose);
void space_generate_gas(struct space *s, const struct cosmology *cosmo,
const struct hydro_props *hydro_properties,
const int periodic, const int with_DM_background,
const double dim[3], const int verbose);
void space_check_cosmology(struct space *s, const struct cosmology *cosmo,
......
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