From 9c58874e8af7c0dfb0ffc60fe2a8706d0afd5871 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Tue, 11 Feb 2020 00:59:02 +0100
Subject: [PATCH] [MPL] Pass ParameterLib::CoordinateSystem.

---
 Applications/ApplicationsLib/ProjectData.cpp | 13 ++++++++-----
 MaterialLib/MPL/CreateComponent.cpp          | 11 +++++++----
 MaterialLib/MPL/CreateComponent.h            |  5 +++--
 MaterialLib/MPL/CreateMedium.cpp             |  9 ++++++---
 MaterialLib/MPL/CreateMedium.h               |  5 +++--
 MaterialLib/MPL/CreatePhase.cpp              | 13 ++++++++-----
 MaterialLib/MPL/CreatePhase.h                |  5 +++--
 MaterialLib/MPL/CreateProperty.cpp           |  9 ++++++---
 MaterialLib/MPL/CreateProperty.h             |  5 +++--
 Tests/MaterialLib/TestMPL.cpp                |  2 +-
 10 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index a21b5af26b3..66691e128ec 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -428,7 +428,7 @@ std::vector<std::string> ProjectData::parseParameters(
 }
 
 void ProjectData::parseMedia(
-        boost::optional<BaseLib::ConfigTree> const& media_config)
+    boost::optional<BaseLib::ConfigTree> const& media_config)
 {
     if (!media_config)
     {
@@ -488,10 +488,13 @@ void ProjectData::parseMedia(
                     id);
             }
 
-            _media[id] = (id == material_ids[0])
-                             ? MaterialPropertyLib::createMedium(medium_config,
-                                                                 _parameters)
-                             : _media[material_ids[0]];
+            _media[id] =
+                (id == material_ids[0])
+                    ? MaterialPropertyLib::createMedium(
+                          medium_config, _parameters,
+                          _local_coordinate_system ? &*_local_coordinate_system
+                                                   : nullptr)
+                    : _media[material_ids[0]];
         }
     }
 
diff --git a/MaterialLib/MPL/CreateComponent.cpp b/MaterialLib/MPL/CreateComponent.cpp
index 6992dbcfe3f..34d213f4a90 100644
--- a/MaterialLib/MPL/CreateComponent.cpp
+++ b/MaterialLib/MPL/CreateComponent.cpp
@@ -22,7 +22,8 @@ namespace
 {
 std::unique_ptr<MaterialPropertyLib::Component> createComponent(
     BaseLib::ConfigTree const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     using namespace MaterialPropertyLib;
     // Parsing the component name
@@ -42,7 +43,7 @@ std::unique_ptr<MaterialPropertyLib::Component> createComponent(
     std::unique_ptr<PropertyArray> properties =
         //! \ogs_file_param{prj__media__medium__phases__phase__components__component__properties}
         createProperties(config.getConfigSubtreeOptional("properties"),
-                         parameters);
+                         parameters, local_coordinate_system);
 
     // If a name is given, it must conform with one of the derived component
     // names in the following list:
@@ -67,7 +68,8 @@ namespace MaterialPropertyLib
 {
 std::vector<std::unique_ptr<Component>> createComponents(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     if (!config)
     {
@@ -80,7 +82,8 @@ std::vector<std::unique_ptr<Component>> createComponents(
         //! \ogs_file_param{prj__media__medium__phases__phase__components__component}
         config->getConfigSubtreeList("component"))
     {
-        auto component = createComponent(component_config, parameters);
+        auto component = createComponent(component_config, parameters,
+                                         local_coordinate_system);
 
         if (std::find_if(components.begin(),
                          components.end(),
diff --git a/MaterialLib/MPL/CreateComponent.h b/MaterialLib/MPL/CreateComponent.h
index baba5f96fb4..6141aac70fe 100644
--- a/MaterialLib/MPL/CreateComponent.h
+++ b/MaterialLib/MPL/CreateComponent.h
@@ -22,6 +22,7 @@ class ConfigTree;
 namespace ParameterLib
 {
 struct ParameterBase;
+struct CoordinateSystem;
 }
 
 namespace MaterialPropertyLib
@@ -36,7 +37,7 @@ namespace MaterialPropertyLib
 /// without predefined properties is created.
 std::vector<std::unique_ptr<Component>> createComponents(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
-        parameters);
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system);
 
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreateMedium.cpp b/MaterialLib/MPL/CreateMedium.cpp
index d477ef162be..685741dc79a 100644
--- a/MaterialLib/MPL/CreateMedium.cpp
+++ b/MaterialLib/MPL/CreateMedium.cpp
@@ -25,19 +25,22 @@ namespace MaterialPropertyLib
 {
 std::unique_ptr<Medium> createMedium(
     BaseLib::ConfigTree const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     // Parsing the phases
     // Properties of phases may be not required in all the cases.
     auto&& phases =
         //! \ogs_file_param{prj__media__medium__phases}
-        createPhases(config.getConfigSubtreeOptional("phases"), parameters);
+        createPhases(config.getConfigSubtreeOptional("phases"),
+                     parameters,
+                     local_coordinate_system);
 
     // Parsing medium properties, overwriting the defaults.
     auto&& properties =
         //! \ogs_file_param{prj__media__medium__properties}
         createProperties(config.getConfigSubtreeOptional("properties"),
-                         parameters);
+                         parameters, local_coordinate_system);
 
     if (phases.empty() && !properties)
     {
diff --git a/MaterialLib/MPL/CreateMedium.h b/MaterialLib/MPL/CreateMedium.h
index 5e5aaf4c8fc..51e1c65b07a 100644
--- a/MaterialLib/MPL/CreateMedium.h
+++ b/MaterialLib/MPL/CreateMedium.h
@@ -24,6 +24,7 @@ class Medium;
 namespace ParameterLib
 {
 struct ParameterBase;
+struct CoordinateSystem;
 }
 
 namespace MaterialPropertyLib
@@ -34,6 +35,6 @@ namespace MaterialPropertyLib
 /// assigned.
 std::unique_ptr<Medium> createMedium(
     BaseLib::ConfigTree const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
-        parameters);
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system);
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreatePhase.cpp b/MaterialLib/MPL/CreatePhase.cpp
index 86b7d5044b7..34cd803b7d0 100644
--- a/MaterialLib/MPL/CreatePhase.cpp
+++ b/MaterialLib/MPL/CreatePhase.cpp
@@ -26,7 +26,8 @@ namespace
 {
 std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
     BaseLib::ConfigTree const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     using namespace MaterialPropertyLib;
 
@@ -59,13 +60,13 @@ std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
     auto components =
         //! \ogs_file_param{prj__media__medium__phases__phase__components}
         createComponents(config.getConfigSubtreeOptional("components"),
-                         parameters);
+                         parameters, local_coordinate_system);
 
     // Properties of optional properties.
     auto properties =
         //! \ogs_file_param{prj__media__medium__phases__phase__properties}
         createProperties(config.getConfigSubtreeOptional("properties"),
-                         parameters);
+                         parameters, local_coordinate_system);
 
     if (components.empty() && !properties)
     {
@@ -84,7 +85,8 @@ namespace MaterialPropertyLib
 {
 std::vector<std::unique_ptr<Phase>> createPhases(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     if (!config)
     {
@@ -97,7 +99,8 @@ std::vector<std::unique_ptr<Phase>> createPhases(
          //! \ogs_file_param{prj__media__medium__phases__phase}
          config->getConfigSubtreeList("phase"))
     {
-        auto phase = createPhase(phase_config, parameters);
+        auto phase =
+            createPhase(phase_config, parameters, local_coordinate_system);
 
         if (std::find_if(phases.begin(),
                          phases.end(),
diff --git a/MaterialLib/MPL/CreatePhase.h b/MaterialLib/MPL/CreatePhase.h
index dce10756fd7..b91b35e5c66 100644
--- a/MaterialLib/MPL/CreatePhase.h
+++ b/MaterialLib/MPL/CreatePhase.h
@@ -21,6 +21,7 @@ class ConfigTree;
 namespace ParameterLib
 {
 struct ParameterBase;
+struct CoordinateSystem;
 }
 namespace MaterialPropertyLib
 {
@@ -41,6 +42,6 @@ namespace MaterialPropertyLib
 /// weighted by mole fraction.
 std::vector<std::unique_ptr<Phase>> createPhases(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
-        parameters);
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system);
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreateProperty.cpp b/MaterialLib/MPL/CreateProperty.cpp
index 57918da8e19..8455f1822bd 100644
--- a/MaterialLib/MPL/CreateProperty.cpp
+++ b/MaterialLib/MPL/CreateProperty.cpp
@@ -28,7 +28,8 @@ namespace
 {
 std::unique_ptr<MaterialPropertyLib::Property> createProperty(
     BaseLib::ConfigTree const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     using namespace MaterialPropertyLib;
     // Parsing the property type:
@@ -109,7 +110,8 @@ namespace MaterialPropertyLib
 {
 std::unique_ptr<PropertyArray> createProperties(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system)
 {
     if (!config)
     {
@@ -132,7 +134,8 @@ std::unique_ptr<PropertyArray> createProperties(
             //! \ogs_file_param{properties__property__name}
             property_config.getConfigParameter<std::string>("name");
         // Create a new property based on the configuration subtree:
-        auto property = createProperty(property_config, parameters);
+        auto property = createProperty(
+            property_config, parameters, local_coordinate_system);
 
         // Insert the new property at the right position into the components
         // private PropertyArray:
diff --git a/MaterialLib/MPL/CreateProperty.h b/MaterialLib/MPL/CreateProperty.h
index 68bf8e24f22..c9c252ea532 100644
--- a/MaterialLib/MPL/CreateProperty.h
+++ b/MaterialLib/MPL/CreateProperty.h
@@ -22,6 +22,7 @@ class ConfigTree;
 namespace ParameterLib
 {
 struct ParameterBase;
+struct CoordinateSystem;
 }
 
 namespace MaterialPropertyLib
@@ -42,7 +43,7 @@ using PropertyArray =
 /// properties array.
 std::unique_ptr<PropertyArray> createProperties(
     boost::optional<BaseLib::ConfigTree> const& config,
-    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
-        parameters);
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
+    ParameterLib::CoordinateSystem const* const local_coordinate_system);
 
 }  // namespace MaterialPropertyLib
diff --git a/Tests/MaterialLib/TestMPL.cpp b/Tests/MaterialLib/TestMPL.cpp
index da0429ca456..c27f367a889 100644
--- a/Tests/MaterialLib/TestMPL.cpp
+++ b/Tests/MaterialLib/TestMPL.cpp
@@ -26,5 +26,5 @@ std::unique_ptr<MPL::Medium> createTestMaterial(std::string const& xml)
     auto const& config = conf.getConfigSubtree("medium");
     std::vector<std::unique_ptr<ParameterLib::ParameterBase>> parameters;
 
-    return MPL::createMedium(config, parameters);
+    return MPL::createMedium(config, parameters, nullptr);
 }
-- 
GitLab