From 90b09a4c4e66d78df444ecc0f7a5572969f18eb5 Mon Sep 17 00:00:00 2001
From: Folkert Nobels <nobels@strw.leidenuniv.nl>
Date: Thu, 6 Dec 2018 14:18:01 +0100
Subject: [PATCH] Remove a few bugs

---
 src/runner.c                               | 24 ++++++++++++----------
 src/starformation.c                        |  6 ++++--
 src/starformation.h                        | 14 +++++++++++++
 src/starformation/none/starformation.h     |  2 ++
 src/starformation/schaye08/starformation.h |  1 +
 5 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/runner.c b/src/runner.c
index 7dea47aa08..72b7e8d157 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -64,7 +64,11 @@
 #include "task.h"
 #include "timers.h"
 #include "timestep.h"
+<<<<<<< HEAD
 #include "tracers.h"
+=======
+#include "starformation.h"
+>>>>>>> Remove a few bugs
 
 #define TASK_LOOP_DENSITY 0
 #define TASK_LOOP_GRADIENT 1
@@ -465,6 +469,8 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
 
   struct engine *e = r->e;
   const struct cosmology *cosmo = e->cosmology;
+  const struct star_formation starform = e->star_formation;
+  const struct phys_const *constants = e->physical_constants;
   const int count = c->hydro.count;
   struct part *restrict parts = c->hydro.parts;
   struct xpart *restrict xparts = c->hydro.xparts;
@@ -491,19 +497,15 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
 
         const float rho = hydro_get_physical_density(p, cosmo);
 
+        if (starformation_potential_to_become_star(starform, p, xp, constants, cosmo) ) {
+          starformation_convert_to_gas(starform, p, xp, cosmo);
+        }
         // MATTHIEU: Temporary star-formation law
         // Do not use this at home.
-        if (rho > 1.7e7 && e->step > 2) {
-          message("Removing particle id=%lld rho=%e", p->id, rho);
-
-          struct spart *sp = cell_convert_part_to_spart(e, c, p, xp);
-
-          /* Did we run out of fresh particles? */
-          if (sp == NULL) continue;
-
-          /* Set everything to a valid state */
-          stars_init_spart(sp);
-        }
+        //if (rho > 1.5e7 && e->step > 2) {
+        //  message("Removing particle id=%lld rho=%e", p->id, rho);
+        //  cell_convert_part_to_gpart(e, c, p, xp);
+        //}
       }
     }
   }
diff --git a/src/starformation.c b/src/starformation.c
index a11220ec09..c9dd394beb 100644
--- a/src/starformation.c
+++ b/src/starformation.c
@@ -23,6 +23,8 @@
 /* This object's header. */
 #include "starformation.h"
 #include "restart.h"
+#include "part.h"
+#include "units.h"
 
 /**
  * @brief  Initialises the star formation law properties in the internal 
@@ -59,7 +61,7 @@ void starformation_print(const struct star_formation* starform) {
  * @param starform the star formation struct
  * @param stream the file stream
  */
-void potential_struct_dump(const struct star_formation* starform,
+void starformation_struct_dump(const struct star_formation* starform,
                            FILE* stream) {
   restart_write_blocks((void*)starform, sizeof(struct star_formation), 1,
                        stream, "starformation", "star formation");
@@ -72,7 +74,7 @@ void potential_struct_dump(const struct star_formation* starform,
  * @param starform the star formation struct
  * @param streeam the file stream
  */
-void potential_struct_restore(const struct star_formation* starform,
+void starformation_struct_restore(const struct star_formation* starform,
                               FILE* stream) {
   restart_read_blocks((void*)starform, sizeof(struct star_formation), 1,
                       stream, NULL, "star formation");
diff --git a/src/starformation.h b/src/starformation.h
index 02287e4ae6..a785135a30 100644
--- a/src/starformation.h
+++ b/src/starformation.h
@@ -36,5 +36,19 @@
 #error "Invalid choice of star formation law"
 #endif
 
+/* General functions defined in the source file */
+void starformation_init(struct swift_params* parameter_file,
+                        const struct phys_const* phys_const,
+                        const struct unit_system* us,
+                        struct star_formation* starform);
+
+void starformation_print(const struct star_formation* starform);
+
+/* Dump store */
+void starformation_struct_dump(const struct star_formation* starform,
+                           FILE* stream);
+
+void starformation_struct_restore(const struct star_formation* starform,
+                              FILE* stream);
 
 #endif /* SWIFT_STARFORMATION_H */
diff --git a/src/starformation/none/starformation.h b/src/starformation/none/starformation.h
index 2edccc0798..953b1f038a 100644
--- a/src/starformation/none/starformation.h
+++ b/src/starformation/none/starformation.h
@@ -26,9 +26,11 @@
 /* Local includes */
 #include "cosmology.h"
 #include "physical_constants.h"
+#include "part.h"
 #include "units.h"
 #include "parser.h"
 #include "equation_of_state.h"
+#include "error.h" 
 
 /* Starformation struct */
 struct star_formation {};
diff --git a/src/starformation/schaye08/starformation.h b/src/starformation/schaye08/starformation.h
index 0f7ae4c414..aeb25d0e51 100644
--- a/src/starformation/schaye08/starformation.h
+++ b/src/starformation/schaye08/starformation.h
@@ -29,6 +29,7 @@
 #include "units.h"
 #include "parser.h"
 #include "equation_of_state.h"
+#include "part.h"
 
 /* Starformation struct */
 struct star_formation {
-- 
GitLab