From 49b85a46df1377c4ec40a5d3c7ef932f66ed0d1b Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Fri, 24 Feb 2017 17:40:18 +0100
Subject: [PATCH] [next] Clear local data before updating objects when grid
 changed

---
 dumux/discretization/cellcentered/subcontrolvolume.hh  |  3 ++-
 .../cellcentered/tpfa/elementvolumevariables.hh        | 10 ++++++++++
 .../cellcentered/tpfa/fvelementgeometry.hh             |  3 +++
 .../cellcentered/tpfa/globalfvgeometry.hh              |  5 +++++
 dumux/implicit/cellcentered/assemblymap.hh             |  5 ++++-
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/dumux/discretization/cellcentered/subcontrolvolume.hh b/dumux/discretization/cellcentered/subcontrolvolume.hh
index 6a7c2e3e76..01957c3483 100644
--- a/dumux/discretization/cellcentered/subcontrolvolume.hh
+++ b/dumux/discretization/cellcentered/subcontrolvolume.hh
@@ -47,7 +47,7 @@ public:
     // the contructor in the cc case
     CCSubControlVolume(Geometry&& geometry,
                        IndexType elementIndex)
-    : ParentType(), geometry_(std::move(geometry)), elementIndex_(elementIndex) {}
+    : ParentType(), geometry_(std::forward<Geometry>(geometry)), elementIndex_(elementIndex) {}
 
     //! The copy constrcutor
     CCSubControlVolume(const CCSubControlVolume& other) = default;
@@ -95,6 +95,7 @@ public:
     // e.g. for integration
     const Geometry& geometry() const
     {
+        assert((geometry_));
         return geometry_.value();
     }
 
diff --git a/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh b/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh
index 1bc826d074..8a6c442dc8 100644
--- a/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh
+++ b/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh
@@ -117,6 +117,8 @@ public:
               const FVElementGeometry& fvGeometry,
               const SolutionVector& sol)
     {
+        clear();
+
         const auto& problem = globalVolVars().problem_();
         const auto globalI = problem.elementMapper().index(element);
         const auto& assemblyMapI = problem.model().localJacobian().assemblyMap()[globalI];
@@ -201,6 +203,8 @@ public:
                      const FVElementGeometry& fvGeometry,
                      const SolutionVector& sol)
     {
+        clear();
+
         auto eIdx = globalVolVars().problem_().elementMapper().index(element);
         volumeVariables_.resize(1);
         volVarIndices_.resize(1);
@@ -230,6 +234,12 @@ public:
     const GlobalVolumeVariables& globalVolVars() const
     { return *globalVolVarsPtr_; }
 
+    //! Clear all local storage
+    void clear()
+    {
+        volVarIndices_.clear();
+        volumeVariables_.clear();
+    }
 private:
     const GlobalVolumeVariables* globalVolVarsPtr_;
 
diff --git a/dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh b/dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh
index 7d2981bfe7..26a361cabd 100644
--- a/dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh
+++ b/dumux/discretization/cellcentered/tpfa/fvelementgeometry.hh
@@ -499,17 +499,20 @@ private:
 
     }
 
+    //! Clear all local data
     void clear()
     {
         scvIndices_.clear();
         scvfIndices_.clear();
         scvs_.clear();
         scvfs_.clear();
+        flippedScvfIndices_.clear();
 
         neighborScvIndices_.clear();
         neighborScvfIndices_.clear();
         neighborScvs_.clear();
         neighborScvfs_.clear();
+        flippedNeighborScvfIndices_.clear();
     }
 
     // the bound element
diff --git a/dumux/discretization/cellcentered/tpfa/globalfvgeometry.hh b/dumux/discretization/cellcentered/tpfa/globalfvgeometry.hh
index 7e48089aea..4175c9c977 100644
--- a/dumux/discretization/cellcentered/tpfa/globalfvgeometry.hh
+++ b/dumux/discretization/cellcentered/tpfa/globalfvgeometry.hh
@@ -107,6 +107,7 @@ public:
         scvs_.clear();
         scvfs_.clear();
         scvfIndicesOfScv_.clear();
+        flipScvfIndices_.clear();
         elementMap_.clear();
 
         // determine size of containers
@@ -351,7 +352,11 @@ public:
     void update(const Problem& problem)
     {
         problemPtr_ = &problem;
+
+        // clear local data
         elementMap_.clear();
+        scvfIndicesOfScv_.clear();
+        neighborVolVarIndices_.clear();
 
         // reserve memory or resize the containers
         numScvs_ = gridView_.size(0);
diff --git a/dumux/implicit/cellcentered/assemblymap.hh b/dumux/implicit/cellcentered/assemblymap.hh
index eaf1ee205d..606a61d8a7 100644
--- a/dumux/implicit/cellcentered/assemblymap.hh
+++ b/dumux/implicit/cellcentered/assemblymap.hh
@@ -71,6 +71,7 @@ public:
      */
     void init(const Problem& problem)
     {
+        map_.clear();
         map_.resize(problem.gridView().size(0));
         for (const auto& element : elements(problem.gridView()))
         {
@@ -102,7 +103,9 @@ public:
                     if (it != dataJForI.end())
                         it->second.scvfsJ.push_back(scvf.index());
                     else
-                        dataJForI.emplace_back(std::make_pair(globalI, DataJ({globalJ, std::vector<IndexType>({scvf.index()})})));
+                        dataJForI.emplace_back(std::make_pair(globalI, DataJ({globalJ,
+                                                                              std::vector<IndexType>({scvf.index()}),
+                                                                              std::vector<IndexType>()})));
                 }
             }
 
-- 
GitLab