Commit da8b4cc2 authored by Stuart McAlpine's avatar Stuart McAlpine Committed by Matthieu Schaller

Don't load ParticleIDs when using remap_ids

parent c32a558f
......@@ -152,6 +152,8 @@ individual particle type (e.g. ``/PartType0/``) that have the following *dataset
each particle. Note that these have to be unique to a particle, and cannot be
the same even between particle types. The **IDs must be >= 0**. Negative
IDs will be rejected by the code.
Note, however, that if the parameters to remap the IDs upon startup is switched
on (see :ref:`Parameters_ICs`), the IDs can be omitted entirely from the ICs.
+ ``Masses``, an array of length N that gives the masses of the particles.
For ``PartType0`` (i.e. particles that interact through hydro-dynamics), you will
......
......@@ -596,7 +596,8 @@ copies of the simulation volume.
The remapping of IDs is especially useful in combination with the option to
generate increasing IDs when splitting gas particles as it allows for the
creation of a compact range of IDs beyond which the new IDs generated by
splitting can be safely drawn from.
splitting can be safely drawn from. Note that, when ``remap_ids`` is
switched on the ICs do not need to contain a ``ParticleIDs`` field.
The full section to start a DM+hydro run from Gadget DM-only ICs would
be:
......
......@@ -1032,15 +1032,15 @@ int main(int argc, char *argv[]) {
with_gravity, with_sink, with_stars, with_black_holes,
with_cosmology, cleanup_h, cleanup_sqrt_a, cosmo.h,
cosmo.a, myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL,
nr_threads, dry_run);
nr_threads, dry_run, remap_ids);
#else
read_ic_serial(ICfileName, &us, dim, &parts, &gparts, &sinks, &sparts,
&bparts, &Ngas, &Ngpart, &Ngpart_background, &Nsink, &Nspart,
&Nbpart, &flag_entropy_ICs, with_hydro, with_gravity,
with_sink, with_stars, with_black_holes, with_cosmology,
cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a, myrank,
nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads,
dry_run);
nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads, dry_run,
remap_ids);
#endif
#else
read_ic_single(ICfileName, &us, dim, &parts, &gparts, &sinks, &sparts,
......@@ -1048,7 +1048,7 @@ int main(int argc, char *argv[]) {
&Nbpart, &flag_entropy_ICs, with_hydro, with_gravity,
with_sink, with_stars, with_black_holes, with_cosmology,
cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a, nr_threads,
dry_run);
dry_run, remap_ids);
#endif
#endif
......
......@@ -466,7 +466,7 @@ int main(int argc, char *argv[]) {
/*with_grav=*/1, with_sinks, with_stars, with_black_holes,
with_cosmology, cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a,
myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads,
/*dry_run=*/0);
/*dry_run=*/0, /*remap_ids=*/0);
#else
read_ic_serial(ICfileName, &us, dim, &parts, &gparts, &sinks, &sparts,
&bparts, &Ngas, &Ngpart, &Ngpart_background, &Nsink, &Nspart,
......@@ -474,7 +474,7 @@ int main(int argc, char *argv[]) {
/*with_grav=*/1, with_sinks, with_stars, with_black_holes,
with_cosmology, cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a,
myrank, nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL, nr_threads,
/*dry_run=*/0);
/*dry_run=*/0, /*remap_ids=*/0);
#endif
#else
read_ic_single(ICfileName, &us, dim, &parts, &gparts, &sinks, &sparts,
......@@ -482,7 +482,7 @@ int main(int argc, char *argv[]) {
&Nbpart, &flag_entropy_ICs, with_hydro,
/*with_grav=*/1, with_sinks, with_stars, with_black_holes,
with_cosmology, cleanup_h, cleanup_sqrt_a, cosmo.h, cosmo.a,
nr_threads, /*dry_run=*/0);
nr_threads, /*dry_run=*/0, /*remap_ids=*/0);
#endif
#endif
if (myrank == 0) {
......
......@@ -2930,3 +2930,18 @@ int get_param_ptype(const char* name) {
* an int after promising to do so... */
return -1;
}
/**
* @brief Set all ParticleIDs for each gpart to 1.
*
* Function is called when remap_ids is 1.
*
* Note only the gparts IDs have to be set to 1, as other parttypes can survive
* as ParticleIDs=0 until the remapping routine.
*
* @param gparts The array of loaded gparts.
* @param Ngparts Number of loaded gparts.
*/
void set_ids_to_one(struct gpart* gparts, const size_t Ngparts) {
for (size_t i = 0; i < Ngparts; i++) gparts[i].id_or_neg_offset = 1;
}
......@@ -198,5 +198,6 @@ int get_ptype_fields(const int ptype, struct io_props* list,
const int with_cosmology, const int with_fof,
const int with_stf);
int get_param_ptype(const char* name);
void set_ids_to_one(struct gpart* gparts, const size_t Ngparts);
#endif /* SWIFT_COMMON_IO_H */
......@@ -733,7 +733,7 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
int with_stars, int with_black_holes, int with_cosmology,
int cleanup_h, int cleanup_sqrt_a, double h, double a,
int mpi_rank, int mpi_size, MPI_Comm comm, MPI_Info info,
int n_threads, int dry_run) {
int n_threads, int dry_run, int remap_ids) {
hid_t h_file = 0, h_grp = 0;
/* GADGET has only cubic boxes (in cosmological mode) */
......@@ -1010,15 +1010,23 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
/* Read everything */
if (!dry_run)
for (int i = 0; i < num_fields; ++i)
for (int i = 0; i < num_fields; ++i) {
/* If we are remapping ParticleIDs later, don't need to read them. */
if (remap_ids && strcmp(list[i].name, "ParticleIDs") == 0) continue;
/* Read array. */
read_array_parallel(h_grp, list[i], Nparticles, N_total[ptype],
mpi_rank, offset[ptype], internal_units, ic_units,
cleanup_h, cleanup_sqrt_a, h, a);
}
/* Close particle group */
H5Gclose(h_grp);
}
/* If we are remapping ParticleIDs later, start by setting them to 1. */
if (remap_ids) set_ids_to_one(*gparts, *Ngparts);
if (!dry_run && with_gravity) {
/* Let's initialise a bit of thread parallelism here */
......
......@@ -43,7 +43,7 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
int with_stars, int with_black_holes, int with_cosmology,
int cleanup_h, int cleanup_sqrt_a, double h, double a,
int mpi_rank, int mpi_size, MPI_Comm comm, MPI_Info info,
int nr_threads, int dry_run);
int nr_threads, int dry_run, int remap_ids);
void write_output_parallel(struct engine* e,
const struct unit_system* internal_units,
......
......@@ -510,7 +510,7 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
int with_black_holes, int with_cosmology, int cleanup_h,
int cleanup_sqrt_a, double h, double a, int mpi_rank,
int mpi_size, MPI_Comm comm, MPI_Info info, int n_threads,
int dry_run) {
int dry_run, int remap_ids) {
hid_t h_file = 0, h_grp = 0;
/* GADGET has only cubic boxes (in cosmological mode) */
......@@ -811,10 +811,16 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
/* Read everything */
if (!dry_run)
for (int i = 0; i < num_fields; ++i)
for (int i = 0; i < num_fields; ++i) {
/* If we are remapping ParticleIDs later, don't need to read them.
*/
if (remap_ids && strcmp(list[i].name, "ParticleIDs") == 0) continue;
/* Read array. */
read_array_serial(h_grp, list[i], Nparticles, N_total[ptype],
offset[ptype], internal_units, ic_units,
cleanup_h, cleanup_sqrt_a, h, a);
}
/* Close particle group */
H5Gclose(h_grp);
......@@ -828,6 +834,9 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
MPI_Barrier(comm);
}
/* If we are remapping ParticleIDs later, start by setting them to 1. */
if (remap_ids) set_ids_to_one(*gparts, *Ngparts);
/* Duplicate the parts for gravity */
if (!dry_run && with_gravity) {
......
......@@ -45,7 +45,7 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
int with_black_holes, int with_cosmology, int cleanup_h,
int cleanup_sqrt_a, double h, double a, int mpi_rank,
int mpi_size, MPI_Comm comm, MPI_Info info, int n_threads,
int dry_run);
int dry_run, int remap_ids);
void write_output_serial(struct engine* e,
const struct unit_system* internal_units,
......
......@@ -418,7 +418,7 @@ void read_ic_single(const char* fileName,
int with_gravity, int with_sink, int with_stars,
int with_black_holes, int with_cosmology, int cleanup_h,
int cleanup_sqrt_a, double h, double a, int n_threads,
int dry_run) {
int dry_run, int remap_ids) {
hid_t h_file = 0, h_grp = 0;
/* GADGET has only cubic boxes (in cosmological mode) */
......@@ -681,14 +681,22 @@ void read_ic_single(const char* fileName,
/* Read everything */
if (!dry_run)
for (int i = 0; i < num_fields; ++i)
for (int i = 0; i < num_fields; ++i) {
/* If we are remapping ParticleIDs later, don't need to read them. */
if (remap_ids && strcmp(list[i].name, "ParticleIDs") == 0) continue;
/* Read array. */
read_array_single(h_grp, list[i], Nparticles, internal_units, ic_units,
cleanup_h, cleanup_sqrt_a, h, a);
}
/* Close particle group */
H5Gclose(h_grp);
}
/* If we are remapping ParticleIDs later, start by setting them to 1. */
if (remap_ids) set_ids_to_one(*gparts, *Ngparts);
/* Duplicate the parts for gravity */
if (!dry_run && with_gravity) {
......
......@@ -40,7 +40,7 @@ void read_ic_single(const char* fileName,
int with_gravity, int with_sinks, int with_stars,
int with_black_holes, int with_cosmology, int cleanup_h,
int cleanup_sqrt_a, double h, double a, int nr_threads,
int dry_run);
int dry_run, int remap_ids);
void write_output_single(struct engine* e,
const struct unit_system* internal_units,
......
......@@ -5954,7 +5954,8 @@ void space_remap_ids(struct space *s, int nr_nodes, int verbose) {
const size_t local_nr_bparts = s->nr_bparts;
const size_t local_nr_baryons =
local_nr_parts + local_nr_sinks + local_nr_sparts + local_nr_bparts;
const size_t local_nr_dm = local_nr_gparts - local_nr_baryons;
const size_t local_nr_dm =
local_nr_gparts > 0 ? local_nr_gparts - local_nr_baryons : 0;
/* Get the global offsets */
long long offset_parts = 0;
......
Markdown is supported
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