From e3fe3b4d84a2bf690bd0b83bb3ef38d9bfe088c2 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Wed, 20 Feb 2019 11:59:12 +0100
Subject: [PATCH] [Mat/MPL] Impl. of convertStringToVariable().

---
 MaterialLib/MPL/VariableType.cpp | 55 ++++++++++++++++++++++++++++++++
 MaterialLib/MPL/VariableType.h   |  2 ++
 2 files changed, 57 insertions(+)
 create mode 100644 MaterialLib/MPL/VariableType.cpp

diff --git a/MaterialLib/MPL/VariableType.cpp b/MaterialLib/MPL/VariableType.cpp
new file mode 100644
index 00000000000..a287735de5e
--- /dev/null
+++ b/MaterialLib/MPL/VariableType.cpp
@@ -0,0 +1,55 @@
+/**
+ * \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
+ *
+ */
+
+#include "VariableType.h"
+#include <boost/algorithm/string/predicate.hpp>
+#include "BaseLib/Error.h"
+
+namespace MaterialPropertyLib
+{
+Variables convertStringToVariable(std::string const& input)
+{
+    if (boost::iequals(input, "phase_pressure"))
+    {
+        return Variables::phase_pressure;
+    }
+    if (boost::iequals(input, "capillary_pressure"))
+    {
+        return Variables::capillary_pressure;
+    }
+    if (boost::iequals(input, "gas_density"))
+    {
+        return Variables::gas_density;
+    }
+    if (boost::iequals(input, "liquid_density"))
+    {
+        return Variables::liquid_density;
+    }
+    if (boost::iequals(input, "temperature"))
+    {
+        return Variables::temperature;
+    }
+    if (boost::iequals(input, "liquid_saturation"))
+    {
+        return Variables::liquid_saturation;
+    }
+    if (boost::iequals(input, "u"))
+    {
+        return Variables::u;
+    }
+
+    OGS_FATAL(
+        "The variable name '%s' does not correspond to any known variable",
+        input.c_str());
+
+    return Variables::number_of_variables;  // to avoid the 'no return' warning
+}
+}  // namespace MaterialPropertyLib
diff --git a/MaterialLib/MPL/VariableType.h b/MaterialLib/MPL/VariableType.h
index 539a94ca036..e7a55756701 100644
--- a/MaterialLib/MPL/VariableType.h
+++ b/MaterialLib/MPL/VariableType.h
@@ -63,4 +63,6 @@ inline double getScalar(VariableType pv)
 {
     return boost::get<double>(pv);
 }
+
+Variables convertStringToVariable(std::string const& input);
 }  // namespace MaterialPropertyLib
-- 
GitLab