From b9b4672b0467215f6d7fb40d0ee7f76aed585d33 Mon Sep 17 00:00:00 2001
From: Samuel Burbulla <samuel.burbulla@mathematik.uni-stuttgart.de>
Date: Tue, 5 Mar 2019 15:39:27 +0100
Subject: [PATCH] Some fixes for coupling moving meshes.

---
 .../facet/cellcentered/tpfa/couplingmanager.hh        |  2 ++
 dumux/multidomain/facet/couplingmapperbase.hh         |  8 ++++----
 dumux/multidomain/facet/gridmanager.hh                | 11 +++++++++--
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/dumux/multidomain/facet/cellcentered/tpfa/couplingmanager.hh b/dumux/multidomain/facet/cellcentered/tpfa/couplingmanager.hh
index 96f508b2ea..0b4f65ab61 100644
--- a/dumux/multidomain/facet/cellcentered/tpfa/couplingmanager.hh
+++ b/dumux/multidomain/facet/cellcentered/tpfa/couplingmanager.hh
@@ -181,7 +181,9 @@ public:
         ParentType::updateSolution(curSol);
 
         // determine all bulk elements/scvfs that couple to low dim elements
+        bulkElemIsCoupled_.clear();
         bulkElemIsCoupled_.resize(bulkProblem->fvGridGeometry().gridView().size(0), false);
+        bulkScvfIsCoupled_.clear();
         bulkScvfIsCoupled_.resize(bulkProblem->fvGridGeometry().numScvf(), false);
 
         const auto& bulkMap = couplingMapperPtr_->couplingMap(bulkGridId, lowDimGridId);
diff --git a/dumux/multidomain/facet/couplingmapperbase.hh b/dumux/multidomain/facet/couplingmapperbase.hh
index 93da620d23..c36de3299a 100644
--- a/dumux/multidomain/facet/couplingmapperbase.hh
+++ b/dumux/multidomain/facet/couplingmapperbase.hh
@@ -197,7 +197,7 @@ protected:
                 continue;
 
             // turn (insertion) indices into actual grid element indices ...
-            std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (auto& idx) { idx = bulkInsertionToElemIdxMap[idx]; });
+            std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (auto& idx) { idx = bulkInsertionToElemIdxMap.at(idx); });
 
             // ... and add them
             addCouplingEntryPolicy(std::move(adjoinedEntities), element, lowDimFvGridGeometry, bulkFvGridGeometry);
@@ -233,14 +233,14 @@ private:
 
     //! Creates the map from element insertion index to grid element index
     template< class Embeddings, class FVGridGeometry>
-    std::vector< typename IndexTraits<typename FVGridGeometry::GridView>::GridIndex >
+    std::map< typename IndexTraits<typename FVGridGeometry::GridView>::GridIndex, typename IndexTraits<typename FVGridGeometry::GridView>::GridIndex >
     makeInsertionToGridIndexMap_(std::shared_ptr<const Embeddings> embeddings, const FVGridGeometry& fvGridGeometry) const
     {
         using GridIndexType = typename IndexTraits<typename FVGridGeometry::GridView>::GridIndex;
 
-        std::vector< GridIndexType > map(fvGridGeometry.gridView().size(0));
+        std::map< GridIndexType, GridIndexType > map;
         for (const auto& e : elements(fvGridGeometry.gridView()))
-            map[ embeddings->template insertionIndex<bulkId>(e) ] = fvGridGeometry.elementMapper().index(e);
+            map.insert( std::make_pair( embeddings->template insertionIndex<bulkId>(e), fvGridGeometry.elementMapper().index(e) ) );
 
         return map;
     }
diff --git a/dumux/multidomain/facet/gridmanager.hh b/dumux/multidomain/facet/gridmanager.hh
index 5366ed14d4..b09a7f04e2 100644
--- a/dumux/multidomain/facet/gridmanager.hh
+++ b/dumux/multidomain/facet/gridmanager.hh
@@ -251,7 +251,6 @@ public:
         if (id > bulkGridId)
             lowDimGridVertexIndices_[id-1] = std::move(lowDimGridVertexIndices);
     }
-private:
     //! data on connectivity between the grids
     std::array<EmbedmentMap, numGrids> embeddedEntityMaps_;
     std::array<EmbedmentMap, numGrids> adjoinedEntityMaps_;
@@ -259,6 +258,7 @@ private:
     //! Contains the hierarchy insertion indices that make up a lower-dimensional grid
     std::array<std::vector<GridIndexType>, numGrids-1> lowDimGridVertexIndices_;
 
+private:
     //! tuple to store the grids
     using Indices = std::make_index_sequence<numGrids>;
     template<std::size_t id> using GridViewPtr = std::shared_ptr<GridView<id>>;
@@ -310,6 +310,11 @@ public:
     const Grid<id>& grid() const
     { return *std::get<id>(gridPtrTuple_); }
 
+    //! returns the i-th grid
+    template<std::size_t id>
+    Grid<id>& grid()
+    { return *std::get<id>(gridPtrTuple_); }
+
     //! return a pointer to the grid data object
     std::shared_ptr<const GridData> getGridData() const
     {
@@ -436,12 +441,14 @@ private:
     //! tuple to store the grids
     using Indices = std::make_index_sequence<numGrids>;
     using GridPtrTuple = typename makeFromIndexedType<std::tuple, GridPtr, Indices>::type;
+  protected:
     GridPtrTuple gridPtrTuple_;
-
+  private:
     //! grid data, i.e. parameters and markers
     bool enableEntityMarkers_;
     std::shared_ptr<GridData> gridDataPtr_;
 
+  protected:
     //! data on embeddings
     std::shared_ptr<Embeddings> embeddingsPtr_;
 };
-- 
GitLab