From fde5359803d18fe92b7a4da85ac59482da399fce Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Wed, 17 Jun 2020 19:14:13 +0200
Subject: [PATCH] Prepare volume non negativity checking to avoid weird crashes

Work in progress [ci skip]
---
 src/mesh/MeshData.hpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp
index 5c4a6068a..099cc06aa 100644
--- a/src/mesh/MeshData.hpp
+++ b/src/mesh/MeshData.hpp
@@ -217,6 +217,24 @@ class MeshData
     static_assert((Dimension <= 3), "only 1d, 2d and 3d are implemented");
   }
 
+  void
+  _checkCellVolume() const
+  {
+    bool is_valid = [&] {
+      for (CellId j = 0; j < m_mesh.numberOfCells(); ++j) {
+        if (m_Vj[j] <= 0) {
+          return false;
+        }
+      }
+      return true;
+    }();
+
+#warning add parallel reduction
+    // if (not parallel::allReduceMin(is_valid)) {
+    //   throw NormalError("mesh contains cells of non-positive volume");
+    // }
+  }
+
  public:
   PUGS_INLINE
   const MeshType&
@@ -266,6 +284,7 @@ class MeshData
     this->_updateCjr();
     this->_updateCenter();
     this->_updateVolume();
+    this->_checkCellVolume();
   }
 
   MeshData(const MeshType& mesh) : m_mesh(mesh)
-- 
GitLab