From 37c67270494128500a3b222eebeac5e0e0da9d54 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 22 Apr 2020 16:53:13 +0200 Subject: [PATCH 1/4] Added the gas relative peculiar velocities to the EAGLE BH output --- src/black_holes/EAGLE/black_holes_io.h | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/black_holes/EAGLE/black_holes_io.h b/src/black_holes/EAGLE/black_holes_io.h index 690c76d38..8bdf54db5 100644 --- a/src/black_holes/EAGLE/black_holes_io.h +++ b/src/black_holes/EAGLE/black_holes_io.h @@ -100,6 +100,26 @@ INLINE static void convert_bpart_vel(const struct engine* e, ret[2] *= cosmo->a_inv; } +INLINE static void convert_bpart_gas_vel(const struct engine* e, + const struct bpart* bp, float* ret) { + + const struct cosmology* cosmo = e->cosmology; + + /* Convert velocities to peculiar velocities */ + const double gas_v_peculiar[3] = {bp->velocity_gas[0] * cosmo->a_inv, + bp->velocity_gas[1] * cosmo->a_inv, + bp->velocity_gas[2] * cosmo->a_inv}; + + const double bh_v_peculiar[3] = {bp->v[0] * cosmo->a_inv, + bp->v[1] * cosmo->a_inv, + bp->v[2] * cosmo->a_inv}; + + /* Conversion from internal units to peculiar velocities */ + ret[0] = gas_v_peculiar[0] - bh_v_peculiar[0]; + ret[1] = gas_v_peculiar[1] - bh_v_peculiar[1]; + ret[2] = gas_v_peculiar[2] - bh_v_peculiar[2]; +} + /** * @brief Specifies which b-particle fields to write to a dataset * @@ -114,7 +134,7 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts, int with_cosmology) { /* Say how much we want to write */ - *num_fields = 18; + *num_fields = 19; /* List what we want to write */ list[0] = io_make_output_field_convert_bpart( @@ -232,6 +252,13 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts, "Physical angular momenta that the black holes have accumulated by " "swallowing gas particles."); + list[18] = io_make_output_field_convert_bpart( + "GasRelativeVelocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, bparts, + convert_bpart_gas_vel, + "Peculiar relative velocities of the gas particles around the black " + "holes. This is a * dx/dt where x is the co-moving position of the " + "particles."); + #ifdef DEBUG_INTERACTIONS_BLACK_HOLES list += *num_fields; -- GitLab From 167381e6d94dd3d0cfb29d71207b139b15930f2f Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 22 Apr 2020 17:04:22 +0200 Subject: [PATCH 2/4] Added the gas circular peculiar velocities to the EAGLE BH output --- src/black_holes/EAGLE/black_holes_io.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/black_holes/EAGLE/black_holes_io.h b/src/black_holes/EAGLE/black_holes_io.h index 8bdf54db5..0b9dc45eb 100644 --- a/src/black_holes/EAGLE/black_holes_io.h +++ b/src/black_holes/EAGLE/black_holes_io.h @@ -114,12 +114,23 @@ INLINE static void convert_bpart_gas_vel(const struct engine* e, bp->v[1] * cosmo->a_inv, bp->v[2] * cosmo->a_inv}; - /* Conversion from internal units to peculiar velocities */ ret[0] = gas_v_peculiar[0] - bh_v_peculiar[0]; ret[1] = gas_v_peculiar[1] - bh_v_peculiar[1]; ret[2] = gas_v_peculiar[2] - bh_v_peculiar[2]; } +INLINE static void convert_bpart_gas_circular_vel(const struct engine* e, + const struct bpart* bp, + float* ret) { + + const struct cosmology* cosmo = e->cosmology; + + /* Conversion from internal units to peculiar velocities */ + ret[0] = bp->circular_velocity_gas[0] * cosmo->a_inv; + ret[1] = bp->circular_velocity_gas[1] * cosmo->a_inv; + ret[2] = bp->circular_velocity_gas[2] * cosmo->a_inv; +} + /** * @brief Specifies which b-particle fields to write to a dataset * @@ -134,7 +145,7 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts, int with_cosmology) { /* Say how much we want to write */ - *num_fields = 19; + *num_fields = 20; /* List what we want to write */ list[0] = io_make_output_field_convert_bpart( @@ -259,6 +270,13 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts, "holes. This is a * dx/dt where x is the co-moving position of the " "particles."); + list[19] = io_make_output_field_convert_bpart( + "GasCircularVelocities", FLOAT, 3, UNIT_CONV_SPEED, 0.f, bparts, + convert_bpart_gas_circular_vel, + "Peculiar circular velocities of the gas particles around the black " + "holes. This is the curl of a * dx/dt where x is the co-moving position " + "of the particles."); + #ifdef DEBUG_INTERACTIONS_BLACK_HOLES list += *num_fields; -- GitLab From f745b275ea6a6b7eb5eebae41f8d8d4240fa770e Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 22 Apr 2020 17:05:58 +0200 Subject: [PATCH 3/4] Set the gas velocities to the BH velocities if a BH has no neighbours --- src/black_holes/EAGLE/black_holes.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/black_holes/EAGLE/black_holes.h b/src/black_holes/EAGLE/black_holes.h index e493e89f0..abb158885 100644 --- a/src/black_holes/EAGLE/black_holes.h +++ b/src/black_holes/EAGLE/black_holes.h @@ -234,6 +234,10 @@ black_holes_bpart_has_no_neighbours(struct bpart* bp, /* Re-set problematic values */ bp->density.wcount = kernel_root * h_inv_dim; bp->density.wcount_dh = 0.f; + + bp->velocity_gas[0] = bp->v[0]; + bp->velocity_gas[1] = bp->v[1]; + bp->velocity_gas[2] = bp->v[2]; } /** -- GitLab From 66e43cf4a6f51e029df523abf21f5765d1931c2d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 22 Apr 2020 17:56:25 +0200 Subject: [PATCH 4/4] More sensible way to abort BH calculations when no neighbours are found --- src/black_holes/EAGLE/black_holes.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/black_holes/EAGLE/black_holes.h b/src/black_holes/EAGLE/black_holes.h index abb158885..017eb14c2 100644 --- a/src/black_holes/EAGLE/black_holes.h +++ b/src/black_holes/EAGLE/black_holes.h @@ -235,9 +235,9 @@ black_holes_bpart_has_no_neighbours(struct bpart* bp, bp->density.wcount = kernel_root * h_inv_dim; bp->density.wcount_dh = 0.f; - bp->velocity_gas[0] = bp->v[0]; - bp->velocity_gas[1] = bp->v[1]; - bp->velocity_gas[2] = bp->v[2]; + bp->velocity_gas[0] = FLT_MAX; + bp->velocity_gas[1] = FLT_MAX; + bp->velocity_gas[2] = FLT_MAX; } /** @@ -391,7 +391,7 @@ __attribute__((always_inline)) INLINE static void black_holes_prepare_feedback( const struct phys_const* constants, const struct cosmology* cosmo, const double time, const int with_cosmology, const double dt) { - if (dt == 0.) return; + if (dt == 0. || bp->rho_gas == 0.) return; /* Gather some physical constants (all in internal units) */ const double G = constants->const_newton_G; -- GitLab