From ad289835172dd8609e6013ae00bd6c11dd402eef Mon Sep 17 00:00:00 2001
From: Katharina Heck <katharina.heck@iws.uni-stuttgart.de>
Date: Mon, 2 Dec 2019 16:21:34 +0100
Subject: [PATCH] [3pwateroil][localresidual] change sum of diffusive fluxes.
 The diffusive fluxes add up to 0 only in the mass averaged system and then
 need to be devided by the molar mass of each component

---
 .../porousmediumflow/3pwateroil/localresidual.hh  | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/dumux/porousmediumflow/3pwateroil/localresidual.hh b/dumux/porousmediumflow/3pwateroil/localresidual.hh
index 1191ea582c..9649a2541d 100644
--- a/dumux/porousmediumflow/3pwateroil/localresidual.hh
+++ b/dumux/porousmediumflow/3pwateroil/localresidual.hh
@@ -175,24 +175,33 @@ public:
         static constexpr auto referenceSystemFormulation = FluxVariables::MolecularDiffusionType::referenceSystemFormulation();
         const auto diffusionFluxesWPhase = fluxVars.molecularDiffusionFlux(wPhaseIdx);
         Scalar jNW = diffusionFluxesWPhase[nCompIdx];
+        Scalar jWW = -jNW;
         // check for the reference system and adapt units of the diffusive flux accordingly.
         if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
+        {
             jNW /=  FluidSystem::molarMass(nCompIdx);
-        const Scalar jWW = -jNW;
+            jWW /=  FluidSystem::molarMass(wCompIdx);
+        }
 
         const auto diffusionFluxesGPhase = fluxVars.molecularDiffusionFlux(gPhaseIdx);
         Scalar jWG = diffusionFluxesGPhase[wCompIdx];
+        Scalar jNG = -jWG;
         // check for the reference system and adapt units of the diffusive flux accordingly.
         if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
+        {
             jWG /= FluidSystem::molarMass(wCompIdx);
-        const Scalar jNG = -jWG;
+            jNG /= FluidSystem::molarMass(nCompIdx);
+        }
 
         const auto diffusionFluxesNPhase = fluxVars.molecularDiffusionFlux(nPhaseIdx);
         Scalar jWN = diffusionFluxesNPhase[wCompIdx];
+        Scalar jNN = -jWN;
         // check for the reference system and adapt units of the diffusive flux accordingly.
         if (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
+        {
             jWN /= FluidSystem::molarMass(wCompIdx);
-        const Scalar jNN = -jWN;
+            jNN /= FluidSystem::molarMass(nCompIdx);
+        }
 
         flux[conti0EqIdx] += jWW+jWG+jWN;
         flux[conti1EqIdx] += jNW+jNG+jNN;
-- 
GitLab