From ce14635c21541df843c59adb0fb7d39c4edfe6de Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Thu, 15 Aug 2019 12:17:09 +0200
Subject: [PATCH] [MPL] Pass through the Parameters needed by
 ParameterProperty.

---
 Applications/ApplicationsLib/ProjectData.cpp  |  3 ++-
 .../MPL/Components/GetThermalExpansivity.cpp  | 10 +++++----
 .../MPL/Components/GetThermalExpansivity.h    |  8 ++++---
 MaterialLib/MPL/CreateComponent.cpp           | 12 +++++++----
 MaterialLib/MPL/CreateComponent.h             |  9 +++++++-
 MaterialLib/MPL/CreateMedium.cpp              | 11 +++++++---
 MaterialLib/MPL/CreateMedium.h                |  8 ++++++-
 MaterialLib/MPL/CreatePhase.cpp               | 15 ++++++++-----
 MaterialLib/MPL/CreatePhase.h                 |  8 ++++++-
 MaterialLib/MPL/CreateProperty.cpp            | 21 ++++++++++++++++---
 MaterialLib/MPL/CreateProperty.h              |  9 +++++++-
 11 files changed, 87 insertions(+), 27 deletions(-)

diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index d5349c55aca..41d92566837 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -459,7 +459,8 @@ void ProjectData::parseMedia(
                 material_id);
         }
 
-        _media[material_id] = MaterialPropertyLib::createMedium(medium_config);
+        _media[material_id] =
+            MaterialPropertyLib::createMedium(medium_config, _parameters);
     }
 
     if (_media.empty())
diff --git a/MaterialLib/MPL/Components/GetThermalExpansivity.cpp b/MaterialLib/MPL/Components/GetThermalExpansivity.cpp
index 38aa9ddb5a4..55a20255a44 100644
--- a/MaterialLib/MPL/Components/GetThermalExpansivity.cpp
+++ b/MaterialLib/MPL/Components/GetThermalExpansivity.cpp
@@ -13,15 +13,17 @@
 
 #include "GetThermalExpansivity.h"
 
+#include "MaterialLib/MPL/Phase.h"
 #include "MaterialLib/MPL/Phase.h"
 
 namespace MaterialPropertyLib
 {
 class Phase;
 
-double getThermalExpansivity(Phase const& phase,
-                             VariableArray const& vars,
-                             const double density)
+double getThermalExpansivity(Phase const& phase, VariableArray const& vars,
+                             const double density,
+                             ParameterLib::SpatialPosition const& pos,
+                             double const t)
 {
     auto const thermal_expansivity_ptr =
         &phase.property(MaterialPropertyLib::PropertyType::thermal_expansivity);
@@ -29,7 +31,7 @@ double getThermalExpansivity(Phase const& phase,
     // The thermal expansivity is explicitly given in the project file.
     if (thermal_expansivity_ptr)
     {
-        return (*thermal_expansivity_ptr).template value<double>(vars);
+        return (*thermal_expansivity_ptr).template value<double>(vars, pos, t);
     }
 
     // The thermal expansivity calculated by the density model directly.
diff --git a/MaterialLib/MPL/Components/GetThermalExpansivity.h b/MaterialLib/MPL/Components/GetThermalExpansivity.h
index 45ce3c11ae9..6f39abb5ede 100644
--- a/MaterialLib/MPL/Components/GetThermalExpansivity.h
+++ b/MaterialLib/MPL/Components/GetThermalExpansivity.h
@@ -14,6 +14,7 @@
 #pragma once
 
 #include "MaterialLib/MPL/VariableType.h"  // for VariableArray
+#include "ParameterLib/SpatialPosition.h"
 
 namespace MaterialPropertyLib
 {
@@ -38,7 +39,8 @@ class Phase;
  * \f]
  * where \f$\rho\f$ is the density, \f$T\f$ is the temperature.
  */
-double getThermalExpansivity(Phase const& phase,
-                             VariableArray const& vars,
-                             const double density);
+double getThermalExpansivity(Phase const& phase, VariableArray const& vars,
+                             const double density,
+                             ParameterLib::SpatialPosition const& pos,
+                             double const t);
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreateComponent.cpp b/MaterialLib/MPL/CreateComponent.cpp
index d5d3026f246..9f4b3a80fcc 100644
--- a/MaterialLib/MPL/CreateComponent.cpp
+++ b/MaterialLib/MPL/CreateComponent.cpp
@@ -14,6 +14,7 @@
 #include "CreateComponent.h"
 
 #include "BaseLib/ConfigTree.h"
+#include "ParameterLib/Parameter.h"
 
 #include "Components/Components.h"
 #include "CreateProperty.h"
@@ -21,7 +22,8 @@
 namespace
 {
 std::unique_ptr<MaterialPropertyLib::Component> createComponent(
-    BaseLib::ConfigTree const& config)
+    BaseLib::ConfigTree const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     using namespace MaterialPropertyLib;
     // Parsing the component name
@@ -40,7 +42,8 @@ std::unique_ptr<MaterialPropertyLib::Component> createComponent(
     // if specified.
     std::unique_ptr<PropertyArray> properties =
         //! \ogs_file_param{prj__media__medium__phases__phase__components__component__properties}
-        createProperties(config.getConfigSubtreeOptional("properties"));
+        createProperties(config.getConfigSubtreeOptional("properties"),
+                         parameters);
 
     // If a name is given, it must conform with one of the derived component
     // names in the following list:
@@ -64,7 +67,8 @@ std::unique_ptr<MaterialPropertyLib::Component> createComponent(
 namespace MaterialPropertyLib
 {
 std::vector<std::unique_ptr<Component>> createComponents(
-    boost::optional<BaseLib::ConfigTree> const& config)
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     if (!config)
     {
@@ -77,7 +81,7 @@ 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);
+        auto component = createComponent(component_config, parameters);
 
         if (std::find_if(components.begin(),
                          components.end(),
diff --git a/MaterialLib/MPL/CreateComponent.h b/MaterialLib/MPL/CreateComponent.h
index 1109c58e69b..ab092b8dc20 100644
--- a/MaterialLib/MPL/CreateComponent.h
+++ b/MaterialLib/MPL/CreateComponent.h
@@ -20,6 +20,11 @@ namespace BaseLib
 {
 class ConfigTree;
 }
+namespace ParameterLib
+{
+struct ParameterBase;
+}
+
 
 namespace MaterialPropertyLib
 {
@@ -32,6 +37,8 @@ namespace MaterialPropertyLib
 /// Assigning a name is optional; If no name is given, a custom component
 /// without predefined properties is created.
 std::vector<std::unique_ptr<Component>> createComponents(
-    boost::optional<BaseLib::ConfigTree> const& config);
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
+        parameters);
 
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreateMedium.cpp b/MaterialLib/MPL/CreateMedium.cpp
index b6c8507b38c..e4da5a500c5 100644
--- a/MaterialLib/MPL/CreateMedium.cpp
+++ b/MaterialLib/MPL/CreateMedium.cpp
@@ -15,6 +15,7 @@
 
 #include <string>
 #include "BaseLib/ConfigTree.h"
+#include "ParameterLib/Parameter.h"
 
 #include "Properties/Properties.h"
 
@@ -23,17 +24,21 @@
 
 namespace MaterialPropertyLib
 {
-std::unique_ptr<Medium> createMedium(BaseLib::ConfigTree const& config)
+std::unique_ptr<Medium> createMedium(
+    BaseLib::ConfigTree const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     // Parsing the phases
     // Properties of phases may be not required in all the cases.
     //! \ogs_file_param{prj__media__medium__phases}
-    auto&& phases = createPhases(config.getConfigSubtreeOptional("phases"));
+    auto&& phases =
+        createPhases(config.getConfigSubtreeOptional("phases"), parameters);
 
     // Parsing medium properties, overwriting the defaults.
     auto&& properties =
         //! \ogs_file_param{prj__media__medium__properties}
-        createProperties(config.getConfigSubtreeOptional("properties"));
+        createProperties(config.getConfigSubtreeOptional("properties"),
+                         parameters);
 
     if (phases.empty() && !properties)
     {
diff --git a/MaterialLib/MPL/CreateMedium.h b/MaterialLib/MPL/CreateMedium.h
index 6b5c7b94c0c..6be67697fb6 100644
--- a/MaterialLib/MPL/CreateMedium.h
+++ b/MaterialLib/MPL/CreateMedium.h
@@ -21,6 +21,10 @@ namespace MaterialPropertyLib
 {
 class Medium;
 }
+namespace ParameterLib
+{
+struct ParameterBase;
+}
 
 namespace MaterialPropertyLib
 {
@@ -28,5 +32,7 @@ namespace MaterialPropertyLib
 /// tree and calls create methods for the phase vector and the properties array.
 /// Medium properties are optional. If not defined, default properties are
 /// assigned.
-std::unique_ptr<Medium> createMedium(BaseLib::ConfigTree const& config);
+std::unique_ptr<Medium> createMedium(
+    BaseLib::ConfigTree const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters);
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreatePhase.cpp b/MaterialLib/MPL/CreatePhase.cpp
index f1c9757de0f..5c6d1d2b5b6 100644
--- a/MaterialLib/MPL/CreatePhase.cpp
+++ b/MaterialLib/MPL/CreatePhase.cpp
@@ -17,6 +17,7 @@
 #include <string>
 
 #include "BaseLib/ConfigTree.h"
+#include "ParameterLib/Parameter.h"
 
 #include "CreateComponent.h"
 #include "CreateProperty.h"
@@ -25,7 +26,8 @@
 namespace
 {
 std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
-    BaseLib::ConfigTree const& config)
+    BaseLib::ConfigTree const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     using namespace MaterialPropertyLib;
 
@@ -57,12 +59,14 @@ std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
     // Parsing of optional components.
     auto components =
         //! \ogs_file_param{prj__media__medium__phases__phase__components}
-        createComponents(config.getConfigSubtreeOptional("components"));
+        createComponents(config.getConfigSubtreeOptional("components"),
+                         parameters);
 
     // Properties of optional properties.
     auto properties =
         //! \ogs_file_param{prj__media__medium__phases__phase__properties}
-        createProperties(config.getConfigSubtreeOptional("properties"));
+        createProperties(config.getConfigSubtreeOptional("properties"),
+                         parameters);
 
     if (components.empty() && !properties)
     {
@@ -80,7 +84,8 @@ std::unique_ptr<MaterialPropertyLib::Phase> createPhase(
 namespace MaterialPropertyLib
 {
 std::vector<std::unique_ptr<Phase>> createPhases(
-    boost::optional<BaseLib::ConfigTree> const& config)
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     if (!config)
     {
@@ -93,7 +98,7 @@ std::vector<std::unique_ptr<Phase>> createPhases(
          //! \ogs_file_param{prj__media__medium__phases__phase}
          config->getConfigSubtreeList("phase"))
     {
-        auto phase = createPhase(phase_config);
+        auto phase = createPhase(phase_config, parameters);
 
         if (std::find_if(phases.begin(),
                          phases.end(),
diff --git a/MaterialLib/MPL/CreatePhase.h b/MaterialLib/MPL/CreatePhase.h
index 4ea426ef6ce..22a519de1e1 100644
--- a/MaterialLib/MPL/CreatePhase.h
+++ b/MaterialLib/MPL/CreatePhase.h
@@ -19,6 +19,10 @@ namespace BaseLib
 {
 class ConfigTree;
 }
+namespace ParameterLib
+{
+struct ParameterBase;
+}
 namespace MaterialPropertyLib
 {
 class Phase;
@@ -37,5 +41,7 @@ namespace MaterialPropertyLib
 /// assigned. These default properties average the component properties,
 /// weighted by mole fraction.
 std::vector<std::unique_ptr<Phase>> createPhases(
-    boost::optional<BaseLib::ConfigTree> const& config);
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
+        parameters);
 }  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/CreateProperty.cpp b/MaterialLib/MPL/CreateProperty.cpp
index d2521df40de..3def3fe929d 100644
--- a/MaterialLib/MPL/CreateProperty.cpp
+++ b/MaterialLib/MPL/CreateProperty.cpp
@@ -16,6 +16,8 @@
 #include <string>
 #include <vector>
 #include "BaseLib/ConfigTree.h"
+#include "ParameterLib/Parameter.h"
+#include "ParameterLib/Utils.h"
 
 #include "Properties/Properties.h"
 
@@ -26,7 +28,8 @@
 namespace
 {
 std::unique_ptr<MaterialPropertyLib::Property> createProperty(
-    BaseLib::ConfigTree const& config)
+    BaseLib::ConfigTree const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     using namespace MaterialPropertyLib;
     // Parsing the property type:
@@ -170,6 +173,17 @@ std::unique_ptr<MaterialPropertyLib::Property> createProperty(
             reference_value, exp_data);
     }
 
+    if (property_type == "Parameter")
+    {
+        std::string const& parameter_name =
+            //! \ogs_file_param{properties__property__Parameter__parameter_name}
+            config.getConfigParameter<std::string>("parameter_name");
+        auto const& parameter = ParameterLib::findParameter<double>(
+            parameter_name, parameters, 1, nullptr);
+        return std::make_unique<MaterialPropertyLib::ParameterProperty>(
+            parameter);
+    }
+
     /* TODO Additional properties go here, for example:
     if (boost::iequals(property_type, "BilinearTemperaturePressure"))
     {
@@ -186,7 +200,8 @@ std::unique_ptr<MaterialPropertyLib::Property> createProperty(
 namespace MaterialPropertyLib
 {
 std::unique_ptr<PropertyArray> createProperties(
-    boost::optional<BaseLib::ConfigTree> const& config)
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
 {
     if (!config)
     {
@@ -209,7 +224,7 @@ 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);
+        auto property = createProperty(property_config, parameters);
 
         // 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 777e9181c67..8db96040da8 100644
--- a/MaterialLib/MPL/CreateProperty.h
+++ b/MaterialLib/MPL/CreateProperty.h
@@ -20,6 +20,11 @@ namespace BaseLib
 {
 class ConfigTree;
 }
+namespace ParameterLib
+{
+struct ParameterBase;
+}
+
 
 namespace MaterialPropertyLib
 {
@@ -38,6 +43,8 @@ using PropertyArray =
 /// Then, the property name is evaluated and the property is copied into the
 /// properties array.
 std::unique_ptr<PropertyArray> createProperties(
-    boost::optional<BaseLib::ConfigTree> const& config);
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const&
+        parameters);
 
 }  // namespace MaterialPropertyLib
-- 
GitLab