From 1561b365b6967429b9d7b251f96c54b10339d63d Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Fri, 16 Jul 2021 23:34:04 +0200
Subject: [PATCH] [disc] Add toString function for discretization method

---
 dumux/discretization/method.hh | 47 ++++++++++++++++++++++++++--------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/dumux/discretization/method.hh b/dumux/discretization/method.hh
index 15478a56bd..be7922b7cc 100644
--- a/dumux/discretization/method.hh
+++ b/dumux/discretization/method.hh
@@ -24,19 +24,46 @@
 #ifndef DUMUX_DISCRETIZARION_METHOD_HH
 #define DUMUX_DISCRETIZARION_METHOD_HH
 
+#include <ostream>
+#include <string>
+
 namespace Dumux {
 
-    /*!
-     * \brief The available discretization methods in Dumux
-     * \ingroup Discretization
-     * \note Use none if specifying a discretization method is required but
-     *       the class in question is not specific to a a discretization method
-     *       or the classification is non-applicable
-     */
-    enum class DiscretizationMethod
+/*!
+ * \brief The available discretization methods in Dumux
+ * \ingroup Discretization
+ * \note Use none if specifying a discretization method is required but
+ *       the class in question is not specific to a a discretization method
+ *       or the classification is non-applicable
+ */
+enum class DiscretizationMethod
+{
+    none, box, cctpfa, ccmpfa, staggered, fem
+};
+
+/*!
+ * \brief Convert discretization method to string
+ * \ingroup Discretization
+ */
+inline std::string toString(DiscretizationMethod m)
+{
+    switch (m)
     {
-        none, box, cctpfa, ccmpfa, staggered, fem
-    };
+        case DiscretizationMethod::box: return "box";
+        case DiscretizationMethod::cctpfa: return "cctpfa";
+        case DiscretizationMethod::ccmpfa: return "ccmpfa";
+        case DiscretizationMethod::staggered: return "staggered";
+        case DiscretizationMethod::fem: return "fem";
+        default: return "none";
+    }
+}
+
+/*!
+ * \brief Write discretization method to stream
+ * \ingroup Discretization
+ */
+inline std::ostream& operator<<(std::ostream& stream, DiscretizationMethod m)
+{ stream << toString(m); return stream; }
 
 } // end namespace Dumux
 
-- 
GitLab