From a8d6de9e219f2699d9ff3dc5b556a9da36d5952a Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Sat, 19 Jun 2021 10:56:01 +0200
Subject: [PATCH] workaround for minor backwards tracks

---
 corsika/detail/modules/tracking/Intersect.inl | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/corsika/detail/modules/tracking/Intersect.inl b/corsika/detail/modules/tracking/Intersect.inl
index e62721351..6888f09a0 100644
--- a/corsika/detail/modules/tracking/Intersect.inl
+++ b/corsika/detail/modules/tracking/Intersect.inl
@@ -60,15 +60,11 @@ namespace corsika {
     for (auto const& node : volumeNode.getChildNodes()) {
 
       Intersections const time_intersections = TDerived::intersect(particle, *node);
-      CORSIKA_LOG_TRACE("intersection times with child volume {}", fmt::ptr(node));
+      CORSIKA_LOG_DEBUG("intersection times with child volume {}", fmt::ptr(node));
       if (!time_intersections.hasIntersections()) { continue; }
-      CORSIKA_LOG_TRACE("                                        : enter {} s, exit {} s",
-                        time_intersections.getEntry() / 1_s,
-                        time_intersections.getExit() / 1_s);
-
       auto const t_entry = time_intersections.getEntry();
       auto const t_exit = time_intersections.getExit();
-      CORSIKA_LOG_TRACE("children t-entry: {}, t-exit: {}, smaller? {} ", t_entry, t_exit,
+      CORSIKA_LOG_DEBUG("children t-entry: {}, t-exit: {}, smaller? {} ", t_entry, t_exit,
                         t_entry <= minTime);
       // note, theoretically t can even be smaller than 0 since we
       // KNOW we can't yet be in this volume yet, so we HAVE TO
@@ -96,7 +92,7 @@ namespace corsika {
           time_intersections.getExit() / 1_s);
       auto const t_entry = time_intersections.getEntry();
       auto const t_exit = time_intersections.getExit();
-      CORSIKA_LOG_TRACE("children t-entry: {}, t-exit: {}, smaller? {} ", t_entry, t_exit,
+      CORSIKA_LOG_DEBUG("children t-entry: {}, t-exit: {}, smaller? {} ", t_entry, t_exit,
                         t_entry <= minTime);
       // note, theoretically t can even be smaller than 0 since we
       // KNOW we can't yet be in this volume yet, so we HAVE TO
@@ -106,7 +102,18 @@ namespace corsika {
         minNode = node;
       }
     }
-    CORSIKA_LOG_TRACE("t-intersect: {}, node {} ", minTime, fmt::ptr(minNode));
+    CORSIKA_LOG_DEBUG("next time-intersect: {}, node {} ", minTime, fmt::ptr(minNode));
+    // this branch cannot be unit-testes. This is malfunction: LCOV_EXCL_START
+    if (minTime < 0_s) {
+      if (minTime < 1e-8_s) {
+        CORSIKA_LOG_ERROR(
+            "There is a very negative time step detected: {}. This is not physical and "
+            "may "
+            "easily crash subsequent modules. Set to 0_s, but CHECK AND FIX.",
+            minTime);
+      }
+      minTime = 0_s; // LCOV_EXCL_STOP
+    }
     return std::make_tuple(minTime, minNode);
   }
 
-- 
GitLab