From eb00901213eba810fa78d5ac7e981a84b63bdcb6 Mon Sep 17 00:00:00 2001
From: joergbuchwald <joerg.buchwald@ufz.de>
Date: Fri, 30 Oct 2020 20:22:18 +0000
Subject: [PATCH] MPL: add debug warnings for unused parameters

---
 MaterialLib/MPL/Property.cpp | 18 ++++++++++++++++++
 MaterialLib/MPL/Property.h   | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/MaterialLib/MPL/Property.cpp b/MaterialLib/MPL/Property.cpp
index 677d2adfb30..9d73f9775ae 100644
--- a/MaterialLib/MPL/Property.cpp
+++ b/MaterialLib/MPL/Property.cpp
@@ -71,6 +71,9 @@ PropertyDataType Property::initialValue(
 
 PropertyDataType Property::value() const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return value_;
 }
 
@@ -79,6 +82,9 @@ PropertyDataType Property::value(VariableArray const& /*variable_array*/,
                                  ParameterLib::SpatialPosition const& /*pos*/,
                                  double const /*t*/, double const /*dt*/) const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return value_;
 }
 
@@ -86,6 +92,9 @@ PropertyDataType Property::value(VariableArray const& variable_array,
                                  ParameterLib::SpatialPosition const& pos,
                                  double const t, double const dt) const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return value(variable_array, VariableArray{}, pos, t, dt);
 }
 
@@ -95,6 +104,9 @@ PropertyDataType Property::dValue(VariableArray const& /*variable_array*/,
                                   ParameterLib::SpatialPosition const& /*pos*/,
                                   double const /*t*/, double const /*dt*/) const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return dvalue_;
 }
 
@@ -105,6 +117,9 @@ PropertyDataType Property::dValue(VariableArray const& variable_array,
                                   ParameterLib::SpatialPosition const& pos,
                                   double const t, double const dt) const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return dValue(variable_array, VariableArray{}, variable, pos, t, dt);
 }
 
@@ -116,6 +131,9 @@ PropertyDataType Property::d2Value(VariableArray const& /*variable_array*/,
                                    double const /*t*/,
                                    double const /*dt*/) const
 {
+#ifndef NDEBUG
+    property_used = true;
+#endif
     return 0.0;
 }
 
diff --git a/MaterialLib/MPL/Property.h b/MaterialLib/MPL/Property.h
index ff1799bd454..1f6853f97c4 100644
--- a/MaterialLib/MPL/Property.h
+++ b/MaterialLib/MPL/Property.h
@@ -44,7 +44,21 @@ PropertyDataType fromVector(std::vector<double> const& values);
 class Property
 {
 public:
+#ifndef NDEBUG
+    virtual ~Property()
+    {
+        if(property_used)
+        {
+            DBUG("Property is used: '{:s}'", description());
+        }
+        else
+        {
+            WARN("Property is not used: '{:s}'", description());
+        }
+    }
+#else
     virtual ~Property() = default;
+#endif
 
     /// Returns the initial (or reference) value of the property.
     /// The default implementation forwards to the value function.
@@ -120,6 +134,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(value());
         }
         catch (std::bad_variant_access const&)
@@ -141,6 +158,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(
                 value(variable_array, variable_array_prev, pos, t, dt));
         }
@@ -163,6 +183,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(value(variable_array, pos, t, dt));
         }
         catch (std::bad_variant_access const&)
@@ -185,6 +208,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(dValue(variable_array, variable_array_prev,
                                       variable, pos, t, dt));
         }
@@ -206,6 +232,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(dValue(variable_array, variable, pos, t, dt));
         }
         catch (std::bad_variant_access const&)
@@ -227,6 +256,9 @@ public:
     {
         try
         {
+#ifndef NDEBUG
+            property_used = true;
+#endif
             return std::get<T>(
                 d2Value(variable_array, variable1, variable2, pos, t, dt));
         }
@@ -260,6 +292,9 @@ private:
         // medium, phase or component
     }
     std::string description() const;
+#ifndef NDEBUG
+    mutable bool property_used = false;
+#endif
 
 private:
     /// Corresponds to the PropertyDataType
-- 
GitLab