From 9ce37e09431374a6ab3614f51d3d360fcb097d12 Mon Sep 17 00:00:00 2001
From: Filip Husko <filip.husko@durham.ac.uk>
Date: Mon, 14 Apr 2025 16:46:28 +0000
Subject: [PATCH] Synch spin jet code with downstream

---
 src/black_holes/SPIN_JET/black_holes.h      |  1 +
 src/black_holes/SPIN_JET/black_holes_io.h   | 76 ++++++++++++---------
 src/black_holes/SPIN_JET/black_holes_part.h |  3 +
 3 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/src/black_holes/SPIN_JET/black_holes.h b/src/black_holes/SPIN_JET/black_holes.h
index b4894f42be..526dff6319 100644
--- a/src/black_holes/SPIN_JET/black_holes.h
+++ b/src/black_holes/SPIN_JET/black_holes.h
@@ -1494,6 +1494,7 @@ __attribute__((always_inline)) INLINE static void black_holes_end_reposition(
          * actual potential minimum. */
         if (repos_frac > 1) repos_frac = 1.;
 
+        bp->last_repos_vel = (float)repos_vel;
         bp->reposition.delta_x[0] *= repos_frac;
         bp->reposition.delta_x[1] *= repos_frac;
         bp->reposition.delta_x[2] *= repos_frac;
diff --git a/src/black_holes/SPIN_JET/black_holes_io.h b/src/black_holes/SPIN_JET/black_holes_io.h
index db6c491a07..6fc5f78964 100644
--- a/src/black_holes/SPIN_JET/black_holes_io.h
+++ b/src/black_holes/SPIN_JET/black_holes_io.h
@@ -189,7 +189,7 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
                                                const int with_cosmology) {
 
   /* Say how much we want to write */
-  *num_fields = 62;
+  *num_fields = 63;
 
   /* List what we want to write */
   list[0] = io_make_output_field_convert_bpart(
@@ -237,11 +237,10 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       -1.5f * hydro_gamma_minus_one, bparts, sound_speed_gas,
       "Co-moving sound-speeds of the gas around the particles");
 
-  list[9] = io_make_output_field(
+  list[9] = io_make_physical_output_field(
       "EnergyReservoirs", FLOAT, 1, UNIT_CONV_ENERGY, 0.f, bparts,
-      energy_reservoir,
-      "Physcial energy contained in the thermal feedback reservoir of the "
-      "particles");
+      energy_reservoir, /*can convert to comoving=*/0,
+      "Physcial energy contained in the feedback reservoir of the particles");
 
   list[10] = io_make_output_field(
       "AccretionRates", FLOAT, 1, UNIT_CONV_MASS_PER_UNIT_TIME, 0.f, bparts,
@@ -289,7 +288,7 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
         "Scale-factors at which the black holes last had a minor merger.");
   } else {
     list[15] = io_make_output_field(
-        "LastMinorMergerScaleTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, bparts,
+        "LastMinorMergerTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, bparts,
         last_minor_merger_time,
         "Times at which the black holes last had a minor merger.");
   }
@@ -301,14 +300,14 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
         "Scale-factors at which the black holes last had a major merger.");
   } else {
     list[16] = io_make_output_field(
-        "LastMajorMergerScaleTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, bparts,
+        "LastMajorMergerTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, bparts,
         last_major_merger_time,
         "Times at which the black holes last had a major merger.");
   }
 
-  list[17] = io_make_output_field(
+  list[17] = io_make_physical_output_field(
       "SwallowedAngularMomenta", FLOAT, 3, UNIT_CONV_ANGULAR_MOMENTUM, 0.f,
-      bparts, swallowed_angular_momentum,
+      bparts, swallowed_angular_momentum, /*can convert to comoving=*/0,
       "Physical angular momenta that the black holes have accumulated by "
       "swallowing gas particles.");
 
@@ -385,9 +384,9 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       convert_bpart_gas_velocity_curl,
       "Velocity curl (3D) of the gas particles around the black holes.");
 
-  list[29] = io_make_output_field(
+  list[29] = io_make_physical_output_field(
       "AccretedAngularMomenta", FLOAT, 3, UNIT_CONV_ANGULAR_MOMENTUM, 0.f,
-      bparts, accreted_angular_momentum,
+      bparts, accreted_angular_momentum, /*can convert to comoving=*/0,
       "Physical angular momenta that the black holes have accumulated through "
       "subgrid accretion.");
 
@@ -429,12 +428,11 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       "Accretion-limited time steps of black holes. The actual time step of "
       "the particles may differ due to the minimum allowed value.");
 
-  list[35] = io_make_output_field(
+  list[35] = io_make_physical_output_field(
       "AGNTotalInjectedEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 0.f, bparts,
-      AGN_cumulative_energy,
-      "Total (cumulative) physical thermal energies injected into gas "
-      "particles in thermal AGN feedback, including the effects of both "
-      "radiation and winds.");
+      AGN_cumulative_energy, /*can convert to comoving=*/0,
+      "Total (cumulative) physical energies injected into gas particles "
+      "in AGN feedback, including the effects of both radiation and winds.");
 
   list[36] = io_make_output_field_convert_bpart(
       "Potentials", FLOAT, 1, UNIT_CONV_POTENTIAL, -1.f, bparts,
@@ -442,8 +440,8 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
 
   list[37] = io_make_output_field(
       "Spins", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, bparts, spin,
-      "Dimensionless spins of the black holes. "
-      "Negative values indicate retrograde accretion.");
+      "Dimensionless spins of the black holes. Negative values indicate "
+      "retrograde accretion.");
 
   list[38] = io_make_output_field(
       "AngularMomentumDirections", FLOAT, 3, UNIT_CONV_NO_UNITS, 0.f, bparts,
@@ -456,9 +454,7 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
 
   list[40] = io_make_output_field(
       "RadiativeEfficiencies", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, bparts,
-      radiative_efficiency,
-      "The radiative efficiencies of the BHs, i.e. the "
-      "AGN luminosity divided by accretion rate.");
+      radiative_efficiency, "AGN luminosity divided by accretion rate.");
 
   list[41] = io_make_output_field("CosAccretionDiskAngle", FLOAT, 1,
                                   UNIT_CONV_NO_UNITS, 0.f, bparts,
@@ -475,9 +471,10 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       "Total jet energy waiting to be released (once it "
       "grows large enough to kick a single particle).");
 
-  list[44] = io_make_output_field(
+  list[44] = io_make_physical_output_field(
       "InjectedJetEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 0.f, bparts,
-      total_jet_energy, "Total jet energy injected into AGN surroundings.");
+      total_jet_energy, /*can convert to comoving=*/0,
+      "Total jet energy injected into AGN surroundings.");
 
   list[45] = io_make_output_field(
       "JetTimeSteps", FLOAT, 1, UNIT_CONV_TIME, 0.f, bparts, dt_jet,
@@ -524,17 +521,19 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       "The total accreted mass in each accretion mode. The components to the "
       "mass accreted in the thick, thin and slim disc modes, respectively.");
 
-  list[52] = io_make_output_field(
+  list[52] = io_make_physical_output_field(
       "AGNTotalInjectedEnergiesByMode", FLOAT, BH_accretion_modes_count,
       UNIT_CONV_ENERGY, 0.f, bparts, thermal_energy_by_mode,
+      /*can convert to comoving=*/0,
       "The total energy injected in the thermal AGN feedback mode, including "
       "the contributions of both radiation and wind feedback, split by "
       "accretion mode. The components correspond to the thermal energy dumped "
       "in the thick, thin and slim disc modes, respectively.");
 
-  list[53] = io_make_output_field(
+  list[53] = io_make_physical_output_field(
       "InjectedJetEnergiesByMode", FLOAT, BH_accretion_modes_count,
       UNIT_CONV_ENERGY, 0.f, bparts, jet_energy_by_mode,
+      /*can convert to comoving=*/0,
       "The total energy injected in the kinetic jet AGN feedback mode, split "
       "by accretion mode. The components correspond to the jet energy "
       "dumped in the thick, thin and slim disc modes, respectively.");
@@ -543,27 +542,29 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       "WindEfficiencies", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, bparts,
       wind_efficiency, "The wind efficiencies of the black holes.");
 
-  list[55] = io_make_output_field(
+  list[55] = io_make_physical_output_field(
       "TotalRadiatedEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 0.f, bparts,
-      radiated_energy,
+      radiated_energy, /*can convert to comoving=*/0,
       "The total energy launched into radiation by the black holes, "
       "in all accretion modes. ");
 
-  list[56] = io_make_output_field(
+  list[56] = io_make_physical_output_field(
       "RadiatedEnergiesByMode", FLOAT, BH_accretion_modes_count,
       UNIT_CONV_ENERGY, 0.f, bparts, radiated_energy_by_mode,
+      /*can convert to comoving=*/0,
       "The total energy launched into radiation by the black holes, split "
       "by accretion mode. The components correspond to the radiative energy "
       "dumped in the thick, thin and slim disc modes, respectively.");
 
-  list[57] = io_make_output_field(
+  list[57] = io_make_physical_output_field(
       "TotalWindEnergies", FLOAT, 1, UNIT_CONV_ENERGY, 0.f, bparts, wind_energy,
-      "The total energy launched into accretion disc winds by the black "
-      "holes, in all accretion modes. ");
+      /*can convert to comoving=*/0,
+      "The total energy launched into accretion disc winds by the black holes, "
+      "in all accretion modes. ");
 
-  list[58] = io_make_output_field(
+  list[58] = io_make_physical_output_field(
       "WindEnergiesByMode", FLOAT, BH_accretion_modes_count, UNIT_CONV_ENERGY,
-      0.f, bparts, wind_energy_by_mode,
+      0.f, bparts, wind_energy_by_mode, /*can convert to comoving=*/0,
       "The total energy launched into accretion disc winds by the black "
       "holes, split by accretion mode. The components correspond to the "
       "radiative energy dumped in the thick, thin and slim disc modes, "
@@ -581,7 +582,14 @@ INLINE static void black_holes_write_particles(const struct bpart* bparts,
       convert_bpart_gas_temperatures,
       "Temperature of the gas surrounding the black holes.");
 
-  list[61] = io_make_output_field(
+  list[61] = io_make_physical_output_field(
+      "LastRepositionVelocities", FLOAT, 1, UNIT_CONV_SPEED, 0.f, bparts,
+      last_repos_vel, /*can convert to comoving=*/0,
+      "Physical speeds at which the black holes repositioned most recently. "
+      "This is 0 for black holes that have never repositioned, or if the "
+      "simulation has been run without prescribed repositioning speed.");
+
+  list[62] = io_make_output_field(
       "AccretionEfficiencies", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f, bparts,
       accretion_efficiency,
       "The accretion efficiencies of black holes. These are used to convert "
diff --git a/src/black_holes/SPIN_JET/black_holes_part.h b/src/black_holes/SPIN_JET/black_holes_part.h
index 7e66da192b..99d147e4ea 100644
--- a/src/black_holes/SPIN_JET/black_holes_part.h
+++ b/src/black_holes/SPIN_JET/black_holes_part.h
@@ -167,6 +167,9 @@ struct bpart {
    * lower potential than all eligible neighbours) */
   int number_of_reposition_attempts;
 
+  /* Velocity of most recent reposition jump */
+  float last_repos_vel;
+
   /*! Total number of time steps in which the black hole was active. */
   int number_of_time_steps;
 
-- 
GitLab