From 4228c1f427a12237e6bff0a4bf4857789de41ac1 Mon Sep 17 00:00:00 2001
From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Wed, 30 Sep 2020 09:15:07 +0200
Subject: [PATCH] [fvassembler] Correct enforcement of periodic constraints

* make sure the second dof has the same value as the first one
---
 dumux/assembly/fvassembler.hh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/dumux/assembly/fvassembler.hh b/dumux/assembly/fvassembler.hh
index 962e83a533..ff95993c52 100644
--- a/dumux/assembly/fvassembler.hh
+++ b/dumux/assembly/fvassembler.hh
@@ -124,7 +124,7 @@ public:
             localAssembler.assembleJacobianAndResidual(*jacobian_, *residual_, *gridVariables_, partialReassembler);
         });
 
-        enforcePeriodicConstraints_(*jacobian_, *residual_, *gridGeometry_);
+        enforcePeriodicConstraints_(*jacobian_, *residual_, curSol, *gridGeometry_);
     }
 
     /*!
@@ -397,7 +397,7 @@ private:
     }
 
     template<class GG> std::enable_if_t<GG::discMethod == DiscretizationMethod::box, void>
-    enforcePeriodicConstraints_(JacobianMatrix& jac, SolutionVector& res, const GG& gridGeometry)
+    enforcePeriodicConstraints_(JacobianMatrix& jac, SolutionVector& res, const SolutionVector& curSol, const GG& gridGeometry)
     {
         for (const auto& m : gridGeometry.periodicVertexMap())
         {
@@ -410,6 +410,7 @@ private:
                     jac[m.first][it.index()] += (*it);
 
                 // enforce constraint in second row
+                res[m.second] = curSol[m.second] - curSol[m.first];
                 for (auto it = jac[m.second].begin(); it != end; ++it)
                     (*it) = it.index() == m.second ? 1.0 : it.index() == m.first ? -1.0 : 0.0;
             }
@@ -417,7 +418,7 @@ private:
     }
 
     template<class GG> std::enable_if_t<GG::discMethod != DiscretizationMethod::box, void>
-    enforcePeriodicConstraints_(JacobianMatrix& jac, SolutionVector& res, const GG& gridGeometry) {}
+    enforcePeriodicConstraints_(JacobianMatrix& jac, SolutionVector& res, const SolutionVector& curSol, const GG& gridGeometry) {}
 
     //! pointer to the problem to be solved
     std::shared_ptr<const Problem> problem_;
-- 
GitLab