From 2009d5dfb8116e98f087d068aab5c47572324b90 Mon Sep 17 00:00:00 2001
From: Mathis Kelm <mathis.kelm@iws.uni-stuttgart.de>
Date: Wed, 29 Sep 2021 13:48:30 +0200
Subject: [PATCH] [test] Check if grid can communicate in tests

---
 test/io/gridmanager/gridmanagertests.hh | 10 +++++++---
 test/porousmediumflow/co2/problem.hh    | 10 +++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/test/io/gridmanager/gridmanagertests.hh b/test/io/gridmanager/gridmanagertests.hh
index 9ba89f6aa4..58f61d7bf5 100644
--- a/test/io/gridmanager/gridmanagertests.hh
+++ b/test/io/gridmanager/gridmanagertests.hh
@@ -31,6 +31,7 @@
 
 #include <dumux/io/grid/gridmanager.hh>
 #include <dumux/discretization/method.hh>
+#include <dumux/common/gridcapabilities.hh>
 
 namespace Dumux {
 
@@ -287,9 +288,12 @@ private:
         if (gridView.comm().size() > 1)
         {
             VertexHandleNonZeroMin<GridView> dataHandle(boundaryMarker, gridView);
-            gridView.communicate(dataHandle,
-                                 Dune::InteriorBorder_All_Interface,
-                                 Dune::ForwardCommunication);
+            if constexpr (Detail::canCommunicate<typename GridView::Traits::Grid, GridView::dimension>)
+                gridView.communicate(dataHandle,
+                                     Dune::InteriorBorder_All_Interface,
+                                     Dune::ForwardCommunication);
+            else
+                DUNE_THROW(Dune::InvalidStateException, "Cannot call getBoundaryMarkers_ on multiple processes for a grid that cannot communicate codim-" << GridView::dimension << "-entities");
         }
     }
 };
diff --git a/test/porousmediumflow/co2/problem.hh b/test/porousmediumflow/co2/problem.hh
index 6ab508f783..3e6db0df59 100644
--- a/test/porousmediumflow/co2/problem.hh
+++ b/test/porousmediumflow/co2/problem.hh
@@ -37,6 +37,7 @@
 #include <dumux/porousmediumflow/problem.hh>
 #include <dumux/discretization/box/scvftoscvboundarytypes.hh>
 #include <dumux/material/components/co2.hh>
+#include <dumux/common/gridcapabilities.hh>
 
 #include "co2tables.hh"
 
@@ -235,9 +236,12 @@ public:
             {
                 VectorCommDataHandleSum<typename GridGeometry::VertexMapper, std::vector<Scalar>, GridView::dimension>
                 sumVolumeHandle(this->gridGeometry().vertexMapper(), vtkBoxVolume_);
-                gridView.communicate(sumVolumeHandle,
-                                     Dune::InteriorBorder_InteriorBorder_Interface,
-                                     Dune::ForwardCommunication);
+                if constexpr (Detail::canCommunicate<typename GridView::Traits::Grid, GridView::dimension>)
+                    gridView.communicate(sumVolumeHandle,
+                                         Dune::InteriorBorder_InteriorBorder_Interface,
+                                         Dune::ForwardCommunication);
+                else
+                    DUNE_THROW(Dune::InvalidStateException, "Cannot call addFieldsToWriter on multiple processes for a grid that cannot communicate codim-" << GridView::dimension << "-entities.");
             }
         }
     }
-- 
GitLab