From c355ef62cc7c80e13bbe9a0556c946c2d1965ed8 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Thu, 23 Apr 2020 13:59:57 +0200
Subject: [PATCH] Removed usage of the theta_crit2 and theta_crit_inv constants

---
 src/cell.c               |  7 +++++--
 src/engine.c             |  5 +++--
 src/runner_doiact_grav.c | 12 ++++++++----
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 7d72019da6..4d9f25a4e2 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -6389,7 +6389,9 @@ void cell_reorder_extra_gparts(struct cell *c, struct part *parts,
  */
 int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj,
                          const struct engine *e, const struct space *s) {
-  const double theta_crit2 = e->gravity_properties->theta_crit2;
+
+  const double theta_crit = e->gravity_properties->theta_crit;
+  const double theta_crit2 = theta_crit * theta_crit;
   const int periodic = s->periodic;
   const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]};
 
@@ -6431,7 +6433,8 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj,
 int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj,
                                  const struct engine *e,
                                  const struct space *s) {
-  const double theta_crit2 = e->gravity_properties->theta_crit2;
+  const double theta_crit = e->gravity_properties->theta_crit;
+  const double theta_crit2 = theta_crit * theta_crit;
   const int periodic = s->periodic;
   const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]};
 
diff --git a/src/engine.c b/src/engine.c
index 23222740ec..d1760d0b3f 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -3099,8 +3099,9 @@ void engine_makeproxies(struct engine *e) {
   /* Get some info about the physics */
   const int with_hydro = (e->policy & engine_policy_hydro);
   const int with_gravity = (e->policy & engine_policy_self_gravity);
-  const double theta_crit_inv = e->gravity_properties->theta_crit_inv;
-  const double theta_crit2 = e->gravity_properties->theta_crit2;
+  const double theta_crit_inv = 1. / e->gravity_properties->theta_crit;
+  const double theta_crit2 =
+      e->gravity_properties->theta_crit * e->gravity_properties->theta_crit;
   const double max_mesh_dist = e->mesh->r_cut_max;
   const double max_mesh_dist2 = max_mesh_dist * max_mesh_dist;
 
diff --git a/src/runner_doiact_grav.c b/src/runner_doiact_grav.c
index 81c091a894..b36bedd090 100644
--- a/src/runner_doiact_grav.c
+++ b/src/runner_doiact_grav.c
@@ -541,7 +541,8 @@ static INLINE void runner_dopair_grav_pm_full(
 #ifdef SWIFT_DEBUG_CHECKS
     const float r_max_j = cj->grav.multipole->r_max;
     const float r_max2 = r_max_j * r_max_j;
-    const float theta_crit2 = e->gravity_properties->theta_crit2;
+    const double theta_crit = e->gravity_properties->theta_crit;
+    const double theta_crit2 = theta_crit * theta_crit;
 
     /* Note: 0.99 and 1.1 to avoid FP rounding false-positives */
     if (!gravity_M2P_accept(r_max2, theta_crit2 * 1.1, r2, 0.99 * h_i))
@@ -684,7 +685,8 @@ static INLINE void runner_dopair_grav_pm_truncated(
 #ifdef SWIFT_DEBUG_CHECKS
     const float r_max_j = cj->grav.multipole->r_max;
     const float r_max2 = r_max_j * r_max_j;
-    const float theta_crit2 = e->gravity_properties->theta_crit2;
+    const double theta_crit = e->gravity_properties->theta_crit;
+    const double theta_crit2 = theta_crit * theta_crit;
 
     /* 0.99 and 1.1 to avoid FP rounding false-positives */
     if (!gravity_M2P_accept(r_max2, theta_crit2 * 1.1, r2, 0.99 * h_i))
@@ -1623,7 +1625,8 @@ void runner_dopair_recursive_grav(struct runner *r, struct cell *ci,
   const int nodeID = e->nodeID;
   const int periodic = e->mesh->periodic;
   const double dim[3] = {e->mesh->dim[0], e->mesh->dim[1], e->mesh->dim[2]};
-  const double theta_crit2 = e->gravity_properties->theta_crit2;
+  const double theta_crit = e->gravity_properties->theta_crit;
+  const double theta_crit2 = theta_crit * theta_crit;
   const double max_distance = e->mesh->r_cut_max;
 
   /* Anything to do here? */
@@ -1840,7 +1843,8 @@ void runner_do_grav_long_range(struct runner *r, struct cell *ci, int timer) {
   const struct engine *e = r->e;
   const int periodic = e->mesh->periodic;
   const double dim[3] = {e->mesh->dim[0], e->mesh->dim[1], e->mesh->dim[2]};
-  const double theta_crit2 = e->gravity_properties->theta_crit2;
+  const double theta_crit = e->gravity_properties->theta_crit;
+  const double theta_crit2 = theta_crit * theta_crit;
   const double max_distance2 = e->mesh->r_cut_max * e->mesh->r_cut_max;
 
   TIMER_TIC;
-- 
GitLab