From 589ac0fc45e7127d4908e33ac4b6d418cfe00d6a Mon Sep 17 00:00:00 2001
From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Fri, 24 Mar 2017 17:08:48 +0100
Subject: [PATCH] [staggered][localResidual] Allow resizing of faceResidual
 vector

* method evalFace() has now an optional bool parameter to specify whether the face
  residual should be resized
* this is important to avoid a segfault when only calling this method without
  having called eval() before, which is done e.g. in the multidimension coupling
  localJacobian
---
 dumux/implicit/staggered/localresidual.hh | 49 +++++++++++++----------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/dumux/implicit/staggered/localresidual.hh b/dumux/implicit/staggered/localresidual.hh
index deb06209fb..a576541462 100644
--- a/dumux/implicit/staggered/localresidual.hh
+++ b/dumux/implicit/staggered/localresidual.hh
@@ -164,14 +164,11 @@ public:
               const ElementBoundaryTypes &bcTypes,
               const ElementFluxVariablesCache& elemFluxVarsCache)
     {
-        // resize and reset all terms
+        // resize and reset all face terms
         const auto numScvf = fvGeometry.numScvf();
 
-        ccResidual_ = 0.0;
-        ccStorageTerm_ = 0.0;
-
-        faceResiduals_.resize(numScvf);
-        faceStorageTerms_.resize(numScvf);
+        faceResiduals_.resize(numScvf, false /*copyOldValues*/);
+        faceStorageTerms_.resize(numScvf, false /*copyOldValues*/);
         faceResiduals_ = 0.0;
         faceStorageTerms_ = 0.0;
 
@@ -206,14 +203,14 @@ public:
      *                vertices of the element
      */
     void evalCellCenter(const Element &element,
-              const FVElementGeometry& fvGeometry,
-              const SubControlVolume& scv,
-              const ElementVolumeVariables& prevElemVolVars,
-              const ElementVolumeVariables& curElemVolVars,
-              const GlobalFaceVars& prevFaceVars,
-              const GlobalFaceVars& curFaceVars,
-              const ElementBoundaryTypes &bcTypes,
-              const ElementFluxVariablesCache& elemFluxVarsCache)
+                        const FVElementGeometry& fvGeometry,
+                        const SubControlVolume& scv,
+                        const ElementVolumeVariables& prevElemVolVars,
+                        const ElementVolumeVariables& curElemVolVars,
+                        const GlobalFaceVars& prevFaceVars,
+                        const GlobalFaceVars& curFaceVars,
+                        const ElementBoundaryTypes &bcTypes,
+                        const ElementFluxVariablesCache& elemFluxVarsCache)
     {
         // reset all terms
         ccResidual_ = 0.0;
@@ -241,15 +238,23 @@ public:
      *                vertices of the element
      */
     void evalFace(const Element &element,
-              const FVElementGeometry& fvGeometry,
-              const SubControlVolumeFace& scvf,
-              const ElementVolumeVariables& prevElemVolVars,
-              const ElementVolumeVariables& curElemVolVars,
-              const GlobalFaceVars& prevFaceVars,
-              const GlobalFaceVars& curFaceVars,
-              const ElementBoundaryTypes &bcTypes,
-              const ElementFluxVariablesCache& elemFluxVarsCache)
+                  const FVElementGeometry& fvGeometry,
+                  const SubControlVolumeFace& scvf,
+                  const ElementVolumeVariables& prevElemVolVars,
+                  const ElementVolumeVariables& curElemVolVars,
+                  const GlobalFaceVars& prevFaceVars,
+                  const GlobalFaceVars& curFaceVars,
+                  const ElementBoundaryTypes &bcTypes,
+                  const ElementFluxVariablesCache& elemFluxVarsCache,
+                  const bool resizeResidual = false)
     {
+        if(resizeResidual)
+        {
+            const auto numScvf = fvGeometry.numScvf();
+            faceResiduals_.resize(numScvf);
+            faceStorageTerms_.resize(numScvf);
+        }
+
         faceResiduals_[scvf.localFaceIdx()] = 0.0;
         faceStorageTerms_[scvf.localFaceIdx()] = 0.0;
 
-- 
GitLab