From 6a37ced1056e20b76413ee00f7d66549f7bb44df Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Fri, 17 Feb 2017 10:55:12 +0100
Subject: [PATCH] [liquid2c] Compute density according to composition

---
 dumux/material/fluidsystems/liquidphase2c.hh | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/dumux/material/fluidsystems/liquidphase2c.hh b/dumux/material/fluidsystems/liquidphase2c.hh
index 13485b938a..b2ecd00610 100644
--- a/dumux/material/fluidsystems/liquidphase2c.hh
+++ b/dumux/material/fluidsystems/liquidphase2c.hh
@@ -57,6 +57,8 @@ public:
     /****************************************
      * Fluid phase related static parameters
      ****************************************/
+    static constexpr int mainCompIdx = 0;
+    static constexpr int secondCompIdx = 1;
     static constexpr int wPhaseIdx = 0;
     static constexpr int numPhases = 1;
     static constexpr int numComponents = 2;
@@ -175,8 +177,18 @@ public:
     static Scalar density(const FluidState &fluidState,
                           const int phaseIdx)
     {
-        return density(fluidState.temperature(phaseIdx),
-                       fluidState.pressure(phaseIdx));
+        const Scalar T = fluidState.temperature(phaseIdx);
+        const Scalar p = fluidState.pressure(phaseIdx);
+
+        // See: Eq. (7) in Class et al. (2002a)
+        // We assume each tracer molecule replaces on main component molecule
+        // this is consistent with the assumption in Fick's law and the computation
+        // of the composition molar mass in the compositional fluid state
+        const Scalar densityMain = MainComponent::liquidDensity(T, p);
+        const Scalar molarDensity = densityMain/MainComponent::molarMass();
+
+        return molarDensity * (MainComponent::molarMass()*fluidState.moleFraction(wPhaseIdx, mainCompIdx)
+                               + SecondComponent::molarMass()*fluidState.moleFraction(wPhaseIdx, secondCompIdx));
     }
 
     /*!
@@ -322,6 +334,7 @@ public:
 };
 
 } // namespace FluidSystems
-} // namespace
+
+} // namespace Dumux
 
 #endif
-- 
GitLab