From 6b6baa5d89fed142e0d0760366a7a5760a63208c Mon Sep 17 00:00:00 2001
From: Wenqing Wang <wenqing.wang@ufz.de>
Date: Mon, 29 Jul 2019 18:04:21 +0200
Subject: [PATCH] [MPL] Added a new common functions.

Conversion to Eigen matrices.
---
 MaterialLib/CMakeLists.txt                    |  1 +
 .../FormEffectiveThermalConductivity.cpp      | 39 ++++++++
 .../Utils/FormEffectiveThermalConductivity.h  | 24 +++++
 MaterialLib/MPL/Utils/FormEigenTensor.cpp     | 89 +++++++++++++++++++
 MaterialLib/MPL/Utils/FormEigenTensor.h       | 23 +++++
 5 files changed, 176 insertions(+)
 create mode 100644 MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.cpp
 create mode 100644 MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.h
 create mode 100644 MaterialLib/MPL/Utils/FormEigenTensor.cpp
 create mode 100644 MaterialLib/MPL/Utils/FormEigenTensor.h

diff --git a/MaterialLib/CMakeLists.txt b/MaterialLib/CMakeLists.txt
index 92a8bd4cfa2..6af23f988eb 100644
--- a/MaterialLib/CMakeLists.txt
+++ b/MaterialLib/CMakeLists.txt
@@ -17,6 +17,7 @@ append_source_files(SOURCES Fluid/WaterVaporProperties)
 append_source_files(SOURCES MPL)
 append_source_files(SOURCES MPL/Properties)
 append_source_files(SOURCES MPL/Components)
+append_source_files(SOURCES MPL/Utils)
 
 append_source_files(SOURCES PorousMedium)
 append_source_files(SOURCES PorousMedium/Porosity)
diff --git a/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.cpp b/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.cpp
new file mode 100644
index 00000000000..8b0f1bb55aa
--- /dev/null
+++ b/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.cpp
@@ -0,0 +1,39 @@
+/*
+ * \file
+ * \copyright
+ * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ * Created on July 31, 2019, 12:10 PM
+ */
+
+#include "FormEffectiveThermalConductivity.h"
+
+#include "FormEigenTensor.h"
+
+namespace MaterialPropertyLib
+{
+template <int GlobalDim>
+Eigen::Matrix<double, GlobalDim, GlobalDim> formEffectiveThermalConductivity(
+    MaterialPropertyLib::PropertyDataType const& solid_thermal_conductivity,
+    const double fluid_thermal_conductivity, const double porosity)
+{
+    return (1.0 - porosity) *
+               formEigenTensor<GlobalDim>(solid_thermal_conductivity) +
+           porosity * fluid_thermal_conductivity *
+               Eigen::Matrix<double, GlobalDim, GlobalDim>::Identity();
+}
+
+template Eigen::Matrix<double, 1, 1> formEffectiveThermalConductivity<1>(
+    MaterialPropertyLib::PropertyDataType const& solid_thermal_conductivity,
+    const double fluid_thermal_conductivity, const double porosity);
+template Eigen::Matrix<double, 2, 2> formEffectiveThermalConductivity<2>(
+    MaterialPropertyLib::PropertyDataType const& solid_thermal_conductivity,
+    const double fluid_thermal_conductivity, const double porosity);
+template Eigen::Matrix<double, 3, 3> formEffectiveThermalConductivity<3>(
+    MaterialPropertyLib::PropertyDataType const& solid_thermal_conductivity,
+    const double fluid_thermal_conductivity, const double porosity);
+
+}  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.h b/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.h
new file mode 100644
index 00000000000..52942f6ec65
--- /dev/null
+++ b/MaterialLib/MPL/Utils/FormEffectiveThermalConductivity.h
@@ -0,0 +1,24 @@
+/*
+ * \file
+ * \copyright
+ * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ * Created on July 31, 2019, 12:10 PM
+ */
+
+#pragma once
+
+#include <Eigen/Dense>
+
+#include "MaterialLib/MPL/Property.h"
+
+namespace MaterialPropertyLib
+{
+template <int GlobalDim>
+Eigen::Matrix<double, GlobalDim, GlobalDim> formEffectiveThermalConductivity(
+    MaterialPropertyLib::PropertyDataType const& solid_thermal_conductivity,
+    const double fluid_thermal_conductivity, const double porosity);
+}  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/Utils/FormEigenTensor.cpp b/MaterialLib/MPL/Utils/FormEigenTensor.cpp
new file mode 100644
index 00000000000..6479e24fdbf
--- /dev/null
+++ b/MaterialLib/MPL/Utils/FormEigenTensor.cpp
@@ -0,0 +1,89 @@
+/*
+ * \file
+ * \copyright
+ * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ * Created on July 31, 2019, 11:28 AM
+ */
+
+#include "FormEigenTensor.h"
+
+#include <boost/variant/static_visitor.hpp>
+
+#include "MaterialLib/MPL/PropertyType.h"
+
+namespace MaterialPropertyLib
+{
+template <int GlobalDim>
+struct FormEigenTensor
+    : boost::static_visitor<Eigen::Matrix<double, GlobalDim, GlobalDim>>
+{
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        double const& value) const
+    {
+        return Eigen::Matrix<double, GlobalDim, GlobalDim>::Identity() * value;
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        MaterialPropertyLib::Vector const& values) const
+    {
+        return Eigen::Map<Eigen::Matrix<double, GlobalDim, 1> const>(
+                   values.data(), GlobalDim, 1)
+            .asDiagonal();
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        MaterialPropertyLib::Tensor2d const& values) const
+    {
+        return Eigen::Map<Eigen::Matrix<double, GlobalDim, GlobalDim> const>(
+            values.data(), GlobalDim, GlobalDim);
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        MaterialPropertyLib::Tensor const& values) const
+    {
+        return Eigen::Map<Eigen::Matrix<double, GlobalDim, GlobalDim> const>(
+            values.data(), GlobalDim, GlobalDim);
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        MaterialPropertyLib::SymmTensor const& /*values*/) const
+    {
+        OGS_FATAL(
+            "The value of MaterialPropertyLib::SymmTensor is inapplicable");
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        std::string const& /*values*/) const
+    {
+        OGS_FATAL("The value of std::string is inapplicable");
+    }
+
+    Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
+        MaterialPropertyLib::Pair const& /*values*/) const
+    {
+        OGS_FATAL("The size of tensor is neither one nor %d nor %d squared.",
+                  GlobalDim, GlobalDim);
+    }
+};
+
+template <int GlobalDim>
+Eigen::Matrix<double, GlobalDim, GlobalDim> formEigenTensor(
+    MaterialPropertyLib::PropertyDataType const& values)
+{
+    return boost::apply_visitor(FormEigenTensor<GlobalDim>(), values);
+}
+
+template Eigen::Matrix<double, 1, 1> formEigenTensor<1>(
+    MaterialPropertyLib::PropertyDataType const& values);
+
+template Eigen::Matrix<double, 2, 2> formEigenTensor<2>(
+    MaterialPropertyLib::PropertyDataType const& values);
+
+template Eigen::Matrix<double, 3, 3> formEigenTensor<3>(
+    MaterialPropertyLib::PropertyDataType const& values);
+
+}  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/Utils/FormEigenTensor.h b/MaterialLib/MPL/Utils/FormEigenTensor.h
new file mode 100644
index 00000000000..9c72b96de0f
--- /dev/null
+++ b/MaterialLib/MPL/Utils/FormEigenTensor.h
@@ -0,0 +1,23 @@
+/*
+ * \file
+ * \copyright
+ * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ * Created on July 29, 2019, 2:48 PM
+ */
+
+#pragma once
+
+#include <Eigen/Dense>
+
+#include "MaterialLib/MPL/Property.h"
+
+namespace MaterialPropertyLib
+{
+template <int GlobalDim>
+Eigen::Matrix<double, GlobalDim, GlobalDim> formEigenTensor(
+    MaterialPropertyLib::PropertyDataType const& values);
+}  // namespace MaterialPropertyLib
-- 
GitLab