From 6bea9b4f3593a7e12ad6fa621423b43b25eedb89 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Mon, 3 Dec 2018 19:29:16 +0100
Subject: [PATCH] wip towards tracking integration

---
 Documentation/Examples/cascade_example.cc | 19 ++++++++++----
 Environment/CMakeLists.txt                |  1 +
 Environment/Environment.h                 | 32 +++++++++++++++++++++++
 Environment/HomogeneousMedium.h           |  6 ++---
 Environment/IMediumModel.h                | 15 ++++++-----
 Environment/VolumeTreeNode.h              |  5 ++--
 Setup/SetupEnvironment.h                  |  6 ++++-
 7 files changed, 66 insertions(+), 18 deletions(-)
 create mode 100644 Environment/Environment.h

diff --git a/Documentation/Examples/cascade_example.cc b/Documentation/Examples/cascade_example.cc
index 34b55476d..5caff6b79 100644
--- a/Documentation/Examples/cascade_example.cc
+++ b/Documentation/Examples/cascade_example.cc
@@ -17,6 +17,8 @@
 #include <corsika/setup/SetupStack.h>
 #include <corsika/setup/SetupTrajectory.h>
 
+#include <corsika/environment/Environment.h>
+
 #include <corsika/random/RNGManager.h>
 
 #include <corsika/cascade/SibStack.h>
@@ -24,14 +26,18 @@
 #include <corsika/process/sibyll/ParticleConversion.h>
 
 #include <corsika/units/PhysicalUnits.h>
+
+#include <iostream>
+#include <typeinfo>
+
 using namespace corsika;
 using namespace corsika::process;
 using namespace corsika::units;
 using namespace corsika::particles;
 using namespace corsika::random;
+using namespace corsika::geometry;
+using namespace corsika::environment;
 
-#include <iostream>
-#include <typeinfo>
 using namespace std;
 
 static int fCount = 0;
@@ -236,9 +242,12 @@ double s_rndm_(int&) {
   return rmng() / (double)rmng.max();
 }
 
-int main() {
-
-  tracking_line::TrackingLine<setup::Stack> tracking;
+int main() {  
+  Environment env;
+  
+  auto theMedium = env.GetUniverse()::CreateNode<Sphere>({Point{env.GetCS(), 0_m, 0_m, 0_m}, 100_km});
+    
+  tracking_line::TrackingLine<setup::Stack> tracking(environment);
   stack_inspector::StackInspector<setup::Stack> p0(true);
   ProcessSplit p1;
   const auto sequence = p0 + p1;
diff --git a/Environment/CMakeLists.txt b/Environment/CMakeLists.txt
index c69ef3655..420fc20f0 100644
--- a/Environment/CMakeLists.txt
+++ b/Environment/CMakeLists.txt
@@ -4,6 +4,7 @@ set (
   IMediumModel.h
   NuclearComposition.h
   HomogeneousMedium.h
+  Environment.h
   )
 
 set (
diff --git a/Environment/Environment.h b/Environment/Environment.h
new file mode 100644
index 000000000..3c20ba22a
--- /dev/null
+++ b/Environment/Environment.h
@@ -0,0 +1,32 @@
+/**
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * See file AUTHORS for a list of contributors.
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
+ * the license.
+ */
+
+#ifndef _include_Environment_h
+#define _include_Environment_h
+
+#include <corsika/environment/IMediumModel.h>
+#include <corsika/environment/VolumeTreeNode.h>
+#include <corsika/geometry/RootCoordinateSystem.h>
+#include <corsika/setup/SetupEnvironment.h>
+
+namespace corsika::environment {
+
+  class Environment {
+  public:
+    auto& GetUniverse() { return universe; }
+    auto const& GetCS() const { return corsika::geometry::RootCoordinateSystem::GetInstance().GetRootCS();}
+
+  private:
+    VolumeTreeNode<corsika::setup::IEnvironmentModel>::VTNUPtr universe;
+  };
+
+} // namespace corsika::environment
+
+#endif
diff --git a/Environment/HomogeneousMedium.h b/Environment/HomogeneousMedium.h
index dcb9a4642..bea6cd618 100644
--- a/Environment/HomogeneousMedium.h
+++ b/Environment/HomogeneousMedium.h
@@ -12,11 +12,11 @@
 #define _include_HomogeneousMedium_h_
 
 #include <corsika/environment/NuclearComposition.h>
-#include <corsika/particles/ParticleProperties.h>
-#include <corsika/units/PhysicalUnits.h>
-#include <corsika/geometry/Trajectory.h>
 #include <corsika/geometry/Line.h>
 #include <corsika/geometry/Point.h>
+#include <corsika/geometry/Trajectory.h>
+#include <corsika/particles/ParticleProperties.h>
+#include <corsika/units/PhysicalUnits.h>
 
 /**
  * a homogeneous medium
diff --git a/Environment/IMediumModel.h b/Environment/IMediumModel.h
index 74fc5161f..a80950831 100644
--- a/Environment/IMediumModel.h
+++ b/Environment/IMediumModel.h
@@ -2,8 +2,8 @@
 #define _include_IMediumModel_h
 
 #include <corsika/environment/NuclearComposition.h>
-#include <corsika/geometry/Trajectory.h>
 #include <corsika/geometry/Point.h>
+#include <corsika/geometry/Trajectory.h>
 #include <corsika/units/PhysicalUnits.h>
 
 namespace corsika::environment {
@@ -14,16 +14,17 @@ namespace corsika::environment {
 
     virtual corsika::units::si::MassDensityType GetMassDensity(
         corsika::geometry::Point const&) const = 0;
-    
-    // todo: think about the mixin inheritance of the trajectory vs the BaseTrajectory approach
-    // for now, only lines are supported
+
+    // todo: think about the mixin inheritance of the trajectory vs the BaseTrajectory
+    // approach for now, only lines are supported
     virtual corsika::units::si::GrammageType IntegratedGrammage(
-        corsika::geometry::Trajectory<corsika::geometry::Line> const&, corsika::units::si::TimeType) const = 0;
-    
+        corsika::geometry::Trajectory<corsika::geometry::Line> const&,
+        corsika::units::si::TimeType) const = 0;
+
     virtual corsika::units::si::TimeType FromGrammage(
         corsika::geometry::Trajectory<corsika::geometry::Line> const&,
         corsika::units::si::GrammageType) const = 0;
-    
+
     virtual NuclearComposition const& GetNuclearComposition() const = 0;
   };
 
diff --git a/Environment/VolumeTreeNode.h b/Environment/VolumeTreeNode.h
index 7bf7b87dc..523aebcd2 100644
--- a/Environment/VolumeTreeNode.h
+++ b/Environment/VolumeTreeNode.h
@@ -88,7 +88,8 @@ namespace corsika::environment {
       static_assert(std::is_base_of_v<IModelProperties, ModelProperties>,
                     "unusable type provided");
 
-      fModelProperties = std::make_unique<ModelProperties>(std::forward<Args>(args)...);
+      fModelProperties = std::make_shared<ModelProperties>(std::forward<Args>(args)...);
+      return fModelProperties;
     }
 
     void SetModelProperties(IMPSharedPtr ptr) { fModelProperties = ptr; }
@@ -101,7 +102,7 @@ namespace corsika::environment {
       return std::make_shared<MediumType>(std::forward<Args>(args)...);
     }
 
-    // factory methods for creation of nodes
+    // factory method for creation of nodes
     template <class VolumeType, typename... Args>
     static auto CreateNode(Args&&... args) {
       static_assert(std::is_base_of_v<corsika::geometry::Volume, VolumeType>,
diff --git a/Setup/SetupEnvironment.h b/Setup/SetupEnvironment.h
index 1beb27480..e822b64ec 100644
--- a/Setup/SetupEnvironment.h
+++ b/Setup/SetupEnvironment.h
@@ -12,6 +12,10 @@
 #ifndef _include_corsika_setup_environment_h_
 #define _include_corsika_setup_environment_h_
 
-namespace corsika {}
+#include <corsika/environment/IMediumModel.h>
+
+namespace corsika::setup {
+    using IEnvironmentModel = corsika::environment::IMediumModel;
+}
 
 #endif
-- 
GitLab