From 84018c3bd1f20166d99a328fb09ae3ce591688fd Mon Sep 17 00:00:00 2001
From: DennisGlaeser <dennis.glaeser@iws.uni-stuttgart.de>
Date: Thu, 1 Feb 2018 19:22:17 +0100
Subject: [PATCH] [cc] allow for customizable upper limit for admissible
 element stencils

The default also assumes one hanging node per scvf such that the adaptive
test work again.
---
 .../cellcentered/connectivitymap.hh               |  9 ++++++++-
 .../cellcentered/mpfa/fvgridgeometry.hh           |  8 ++++----
 .../cellcentered/mpfa/properties.hh               |  6 ++++++
 .../cellcentered/tpfa/fvgridgeometry.hh           | 15 +++++++++------
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/dumux/discretization/cellcentered/connectivitymap.hh b/dumux/discretization/cellcentered/connectivitymap.hh
index b4297fa1c3..07a0ea6df0 100644
--- a/dumux/discretization/cellcentered/connectivitymap.hh
+++ b/dumux/discretization/cellcentered/connectivitymap.hh
@@ -52,6 +52,7 @@ class CCSimpleConnectivityMap
     using GridView = typename FVGridGeometry::GridView;
     using IndexType = typename GridView::IndexSet::IndexType;
     using FluxStencil = Dumux::FluxStencil<FVElementGeometry>;
+    static constexpr int maxElemStencilSize = FVGridGeometry::maxElementStencilSize;
 
     struct DataJ
     {
@@ -77,7 +78,7 @@ public:
         map_.resize(fvGridGeometry.gridView().size(0));
 
         // container to store for each element J the elements I which have J in their flux stencil
-        Dune::ReservedVector<std::pair<IndexType, DataJ>, FVGridGeometry::maxElementStencilSize> dataJForI;
+        Dune::ReservedVector<std::pair<IndexType, DataJ>, maxElemStencilSize> dataJForI;
 
         for (const auto& element : elements(fvGridGeometry.gridView()))
         {
@@ -107,7 +108,13 @@ public:
                     if (it != dataJForI.end())
                         it->second.scvfsJ.push_back(scvf.index());
                     else
+                    {
+                        if (dataJForI.size() > maxElemStencilSize - 1)
+                            DUNE_THROW(Dune::InvalidStateException, "Maximum admissible stencil size is surpassed. "
+                                                                    "Please adjust the FVGridGeometry traits accordingly!");
+
                         dataJForI.push_back(std::make_pair(globalI, DataJ({globalJ, {scvf.index()}, {}})));
+                    }
                 }
             }
 
diff --git a/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh b/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh
index 6a6d7f40b5..d429170b2c 100644
--- a/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh
+++ b/dumux/discretization/cellcentered/mpfa/fvgridgeometry.hh
@@ -98,9 +98,9 @@ public:
 
     //! export the discretization method this geometry belongs to
     static constexpr DiscretizationMethods discretizationMethod = DiscretizationMethods::CCMpfa;
+
     //! The maximum admissible stencil size (used for static memory allocation during assembly)
-    // TODO: Re-implement and obtain from nodal index set (for now we use a high value)
-    static constexpr int maxElementStencilSize = (dim < dimWorld || dim == 3) ? 45 : 15;
+    static constexpr int maxElementStencilSize = Traits::maxElementStencilSize;
 
     //! Constructor without indicator function for secondary interaction volumes
     //! Per default, we use the secondary IVs at branching points & boundaries
@@ -447,9 +447,9 @@ public:
 
     //! export the discretization method this geometry belongs to
     static constexpr DiscretizationMethods discretizationMethod = DiscretizationMethods::CCMpfa;
+
     //! The maximum admissible stencil size (used for static memory allocation during assembly)
-    // TODO: Re-implement and obtain from nodal index set (for now we use a high value)
-    static constexpr int maxElementStencilSize = (dim < dimWorld || dim == 3) ? 45 : 15;
+    static constexpr int maxElementStencilSize = Traits::maxElementStencilSize;
 
     //! Constructor without indicator function for secondary interaction volumes
     //! Per default, we use the secondary IVs at branching points & boundaries
diff --git a/dumux/discretization/cellcentered/mpfa/properties.hh b/dumux/discretization/cellcentered/mpfa/properties.hh
index 3f9cba7bc4..db0cbcae33 100644
--- a/dumux/discretization/cellcentered/mpfa/properties.hh
+++ b/dumux/discretization/cellcentered/mpfa/properties.hh
@@ -127,6 +127,12 @@ private:
         using SubControlVolumeFace = CCMpfaSubControlVolumeFace<GridView>;
         using NodalIndexSet = typename GET_PROP_TYPE(TypeTag, DualGridNodalIndexSet);
 
+        //! State the maximum admissible element stencil size
+        //! Per default, we use high values that are hopefully enough for all cases
+        //! We assume simplex grids where stencils can get quite large but the size is unknown
+        static constexpr int maxElementStencilSize = int(GridView::dimension) == 3 ? 150 :
+                                                     (int(GridView::dimension)<int(GridView::dimensionworld) ? 45 : 15);
+
         //! type definitions depending on the FVGridGeometry itself
         template< class FVGridGeom >
         using MpfaHelper = CCMpfaHelper< FVGridGeom >;
diff --git a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh
index 536027447f..a29c82d1db 100644
--- a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh
+++ b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh
@@ -56,6 +56,12 @@ struct CCTpfaDefaultGridGeometryTraits
 
     template<class FVGridGeometry, bool enableCache>
     using LocalView = CCTpfaFVElementGeometry<FVGridGeometry, enableCache>;
+
+    //! State the maximum admissible number of neighbors per scvf
+    //! Per default, we allow for 8 branches on network/surface grids, where
+    //! conformity is assumed. For normal grids, we allow a maximum of one
+    //! hanging node per scvf. Use different traits if you need more.
+    static constexpr int maxNumScvfNeighbors = int(GridView::dimension)<int(GridView::dimensionworld) ? 8 : 2;
 };
 
 /*!
@@ -104,9 +110,8 @@ public:
     static constexpr DiscretizationMethods discretizationMethod = DiscretizationMethods::CCTpfa;
 
     //! The maximum admissible stencil size (used for static memory allocation during assembly)
-    //! Per default, we allow for 9 branches per scvf on network/surface grids
-    static constexpr int maxElementStencilSize = (dim < dimWorld) ? LocalView::maxNumElementScvfs*8 + 1
-                                                                  : LocalView::maxNumElementScvfs + 1;
+    static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
+
     //! export the grid view type
     using GridView = GV;
 
@@ -381,9 +386,7 @@ public:
     static constexpr DiscretizationMethods discretizationMethod = DiscretizationMethods::CCTpfa;
 
     //! The maximum admissible stencil size (used for static memory allocation during assembly)
-    //! Per default, we allow for 9 branches per scvf on network/surface grids
-    static constexpr int maxElementStencilSize = (dim < dimWorld) ? LocalView::maxNumElementScvfs*8 + 1
-                                                                  : LocalView::maxNumElementScvfs + 1;
+    static constexpr int maxElementStencilSize = LocalView::maxNumElementScvfs*Traits::maxNumScvfNeighbors + 1;
 
     //! Export the type of the grid view
     using GridView = GV;
-- 
GitLab