From e0b2eceeb0bc27cf85d35717eb995ca13cce7ff3 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sun, 11 Mar 2018 16:54:39 +0900
Subject: [PATCH] Add cosmological conversion from internal velocity units to
 peculiar velocities.

---
 src/gravity/Default/gravity_io.h | 6 ++++++
 src/hydro/Gadget2/hydro_io.h     | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/src/gravity/Default/gravity_io.h b/src/gravity/Default/gravity_io.h
index 06d8099a88..2508f69a63 100644
--- a/src/gravity/Default/gravity_io.h
+++ b/src/gravity/Default/gravity_io.h
@@ -56,9 +56,15 @@ void convert_gpart_vel(const struct engine* e, const struct gpart* gp,
     dt_kick_grav = (ti_current - ((ti_beg + ti_end) / 2)) * time_base;
   }
 
+  /* Extrapolate the velocites to the current time */
   ret[0] = gp->v_full[0] + gp->a_grav[0] * dt_kick_grav;
   ret[1] = gp->v_full[1] + gp->a_grav[1] * dt_kick_grav;
   ret[2] = gp->v_full[2] + gp->a_grav[2] * dt_kick_grav;
+
+  /* Conversion from internal units to peculiar velocities */
+  ret[0] *= cosmo->a2_inv;
+  ret[1] *= cosmo->a2_inv;
+  ret[2] *= cosmo->a2_inv;
 }
 
 /**
diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h
index ef1402a32a..3592b0bde9 100644
--- a/src/hydro/Gadget2/hydro_io.h
+++ b/src/hydro/Gadget2/hydro_io.h
@@ -106,7 +106,13 @@ void convert_part_vel(const struct engine* e, const struct part* p,
     dt_kick_hydro = (ti_current - ((ti_beg + ti_end) / 2)) * time_base;
   }
 
+  /* Extrapolate the velocites to the current time */
   hydro_get_drifted_velocities(p, xp, dt_kick_hydro, dt_kick_grav, ret);
+
+  /* Conversion from internal units to peculiar velocities */
+  ret[0] *= cosmo->a2_inv;
+  ret[1] *= cosmo->a2_inv;
+  ret[2] *= cosmo->a2_inv;
 }
 
 /**
-- 
GitLab