From cbe01097ead6eafc74926e01eaf09bf5c37ed916 Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Fri, 17 Jan 2020 14:24:47 +0000
Subject: [PATCH] created file that will contain examples of logging
 lines/custom logging snippets for people to use as an inspiration

---
 .../example_run_binary_with_custom_logging.py |  40 ------
 examples/examples_custom_logging.py           | 123 ++++++++++++++++++
 2 files changed, 123 insertions(+), 40 deletions(-)
 delete mode 100644 examples/example_run_binary_with_custom_logging.py
 create mode 100644 examples/examples_custom_logging.py

diff --git a/examples/example_run_binary_with_custom_logging.py b/examples/example_run_binary_with_custom_logging.py
deleted file mode 100644
index ac6cfc7b9..000000000
--- a/examples/example_run_binary_with_custom_logging.py
+++ /dev/null
@@ -1,40 +0,0 @@
-import ctypes
-import tempfile
-import os
-
-from binarycpython.utils.custom_logging_functions import (
-    autogen_C_logging_code,
-    binary_c_log_code,
-    compile_shared_lib,
-    temp_custom_logging_dir,
-    create_and_load_logging_function,
-)
-import binary_c_python_api
-
-# generate logging lines
-logging_line = autogen_C_logging_code(
-    {
-        "MY_STELLAR_DATA": ["model.time", "star[0].mass"],
-        "my_sss2": ["model.time", "star[1].mass"],
-    }
-)
-
-# Generate code around logging lines
-custom_logging_code = binary_c_log_code(logging_line)
-
-# Generate library and get memaddr
-func_memaddr = create_and_load_logging_function(custom_logging_code)
-
-#
-m1 = 15.0  # Msun
-m2 = 14.0  # Msun
-separation = 0  # 0 = ignored, use period
-orbital_period = 4530.0  # days
-eccentricity = 0.0
-metallicity = 0.02
-max_evolution_time = 15000
-argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g}".format(
-    m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time
-)
-output = binary_c_python_api.run_binary_custom_logging(argstring, func_memaddr)
-print(output)
diff --git a/examples/examples_custom_logging.py b/examples/examples_custom_logging.py
new file mode 100644
index 000000000..b7e267e5b
--- /dev/null
+++ b/examples/examples_custom_logging.py
@@ -0,0 +1,123 @@
+import binary_c_python_api
+
+from binarycpython.utils.custom_logging_functions import (
+    autogen_C_logging_code,
+    binary_c_log_code,
+    create_and_load_logging_function,
+)
+
+from binarycpython.utils.grid import Population
+
+# no logging set.
+pop = Population()
+pop.set(M_1=10, M_2=10, separation=0, orbital_period=4530, eccentricity=0, metallicity=0.02, max_evolution_time=15000)
+out = pop.evolve_single()
+print(out)
+
+
+
+###########################################
+pop.set(C_logging_code="""
+    if(stardata->star[0].stellar_type>=MS)
+    {
+        if (stardata->model.time < stardata->model.max_evolution_time)
+        {
+            Printf("EXAMPLE_ABOVE_MS %30.12e %g %g %g %g %d %d\\n",
+                // 
+                stardata->model.time, // 1
+
+                stardata->star[0].mass, //2
+                stardata->previous_stardata->star[0].mass, //3
+
+                stardata->star[0].radius, //4
+                stardata->previous_stardata->star[0].radius, //5
+
+                stardata->star[0].stellar_type, //6
+                stardata->previous_stardata->star[0].stellar_type //7
+
+
+          );
+        };
+        /* Kill the simulation to save time */
+        //stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
+    };
+""")
+out = pop.evolve_single()
+print(out)
+
+
+#################################################
+pop.set(M_1=100, M_2=10, separation=0, orbital_period=400530, eccentricity=0, metallicity=0.002, max_evolution_time=15000)
+pop.set(C_logging_code="""
+    if(stardata->star[0].stellar_type>=NS)
+    {
+        if (stardata->model.time < stardata->model.max_evolution_time)
+        {
+            Printf("EXAMPLE_LOG_CO %30.12e %g %g %g %g %d %d\\n",
+                // 
+                stardata->model.time, // 1
+
+                stardata->star[0].mass, //2
+                stardata->previous_stardata->star[0].mass, //3
+
+                stardata->star[0].radius, //4
+                stardata->previous_stardata->star[0].radius, //5
+
+                stardata->star[0].stellar_type, //6
+                stardata->previous_stardata->star[0].stellar_type //7
+          );
+        };
+        /* Kill the simulation to save time */
+        stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm;
+    };
+""") 
+out = pop.evolve_single()
+print(out)
+
+
+
+
+
+
+
+
+
+
+
+quit()
+
+
+
+def custom_logging_autogenerated():
+    """
+    This is an example function for the autogeneration of logging codes that binary_c uses.
+    """
+
+    # generate logging lines
+    logging_line = autogen_C_logging_code(
+        {
+            "MY_STELLAR_DATA": ["model.time", "star[0].mass"],
+            "my_sss2": ["model.time", "star[1].mass"],
+        }
+    )
+
+
+    # Generate code around logging lines
+    custom_logging_code = binary_c_log_code(logging_line)
+
+    # Generate library and get memaddr
+    func_memaddr = create_and_load_logging_function(custom_logging_code)
+
+    #
+    m1 = 15.0  # Msun
+    m2 = 14.0  # Msun
+    separation = 0  # 0 = ignored, use period
+    orbital_period = 4530.0  # days
+    eccentricity = 0.0
+    metallicity = 0.02
+    max_evolution_time = 15000
+    argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g}".format(
+        m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time
+    )
+    output = binary_c_python_api.run_binary_custom_logging(argstring, func_memaddr)
+    print(output)
\ No newline at end of file
-- 
GitLab