Skip to content

Commit

Permalink
Use Galaxy to prime random orbit's seed values
Browse files Browse the repository at this point in the history
When we introduced the thread-safe random number generation changes a
few months back we wrongly assumed that using a Halo's ID to prime the
seed number used to generate galaxy's orbit values was correct. It
actually wasn't: it has the effect that for all Galaxies in the same
Halo the same seed is generated, and therefore the same orbital values
are generated.

This commit adds a Galaxy parameter to the generate_random_orbits call
so that it can be used to prime the random number generator's seed
instead of the Halo. This should ensure results are different across
Galaxies even when they belong to the same Halo.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Jun 19, 2020
1 parent bc0d763 commit bc33e9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/dark_matter_halos.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class DarkMatterHalos {
double v2disk (double x, double m, double c, double r);
double v2bulge (double x, double m, double c, double r);

void generate_random_orbits(xyz<float> &pos, xyz<float> &v, xyz<float> &L, double total_am, const HaloPtr &halo);
void generate_random_orbits(xyz<float> &pos, xyz<float> &v, xyz<float> &L, double total_am, const HaloPtr &halo, const Galaxy &galaxy);

protected:
DarkMatterHaloParameters params;
Expand Down
4 changes: 2 additions & 2 deletions src/dark_matter_halos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ xyz<float> DarkMatterHalos::random_point_in_sphere(float r, std::default_random_
};
}

void DarkMatterHalos::generate_random_orbits(xyz<float> &pos, xyz<float> &v, xyz<float> &L, double total_am, const HaloPtr &halo)
void DarkMatterHalos::generate_random_orbits(xyz<float> &pos, xyz<float> &v, xyz<float> &L, double total_am, const HaloPtr &halo, const Galaxy &galaxy)
{

// Prime the generator with a known seed to allow for reproducible runs
std::default_random_engine generator(exec_params.get_seed(halo));
std::default_random_engine generator(exec_params.get_seed(galaxy));

double c = halo->concentration;

Expand Down
2 changes: 1 addition & 1 deletion src/galaxy_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void HDF5GalaxyWriter::write_galaxies(hdf5::Writer &file, int snapshot, const st
}
else{
// In case of type 2 galaxies assign negative positions, velocities and angular momentum.
darkmatterhalo->generate_random_orbits(pos, vel, L, galaxy.angular_momentum(), halo);
darkmatterhalo->generate_random_orbits(pos, vel, L, galaxy.angular_momentum(), halo, galaxy);
mvir_subhalo.push_back(galaxy.msubhalo_type2);
cnfw_subhalo.push_back(galaxy.concentration_type2);
lambda_subhalo.push_back(galaxy.lambda_type2);
Expand Down

0 comments on commit bc33e9c

Please sign in to comment.