From b82c76b4eaaccc96231d4d9b8e5a39e9fb80601d Mon Sep 17 00:00:00 2001
From: Johannes Hommel <johannes.hommel@iws.uni-stuttgart.de>
Date: Fri, 22 Jan 2016 14:00:41 +0100
Subject: [PATCH] Adapted 2pnc and 2pncmin according to FS211

2pnc and 2pncmin are now using only convenience functions as required in FS211
instead of directly calling the fluidstate.
The necessary convenienience functions (mass and moleFraction, molarity) were implemented.
---
 dumux/implicit/2pnc/2pncfluxvariables.hh      |  4 +--
 dumux/implicit/2pnc/2pncmodel.hh              | 20 ++++++------
 dumux/implicit/2pnc/2pncvolumevariables.hh    | 31 +++++++++++++++++++
 dumux/implicit/2pncmin/2pncminmodel.hh        | 16 +++++-----
 .../2pncmin/2pncminvolumevariables.hh         | 29 ++++++++++-------
 5 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/dumux/implicit/2pnc/2pncfluxvariables.hh b/dumux/implicit/2pnc/2pncfluxvariables.hh
index 4a31de4963..541db7b224 100644
--- a/dumux/implicit/2pnc/2pncfluxvariables.hh
+++ b/dumux/implicit/2pnc/2pncfluxvariables.hh
@@ -147,11 +147,11 @@ protected:
                     if(compIdx != phaseIdx) //No grad is needed for this case
                     {
                         tmp = feGrad;
-                        tmp *= elemVolVars[idx].fluidState().massFraction(phaseIdx, compIdx);
+                        tmp *= elemVolVars[idx].massFraction(phaseIdx, compIdx);
                         massFractionGrad_[phaseIdx][compIdx] += tmp;
 
                         tmp = feGrad;
-                        tmp *= elemVolVars[idx].fluidState().moleFraction(phaseIdx, compIdx);
+                        tmp *= elemVolVars[idx].moleFraction(phaseIdx, compIdx);
                         moleFractionGrad_[phaseIdx][compIdx] += tmp;
                     }
                 }
diff --git a/dumux/implicit/2pnc/2pncmodel.hh b/dumux/implicit/2pnc/2pncmodel.hh
index b9242d17e6..1b91cadddb 100644
--- a/dumux/implicit/2pnc/2pncmodel.hh
+++ b/dumux/implicit/2pnc/2pncmodel.hh
@@ -371,8 +371,8 @@ public:
                 (*pg)[dofIdxGlobal]             = elemVolVars[scvIdx].pressure(nPhaseIdx);
                 (*pl)[dofIdxGlobal]             = elemVolVars[scvIdx].pressure(wPhaseIdx);
                 (*pc)[dofIdxGlobal]             = elemVolVars[scvIdx].capillaryPressure();
-                (*rhoL)[dofIdxGlobal]           = elemVolVars[scvIdx].fluidState().density(wPhaseIdx);
-                (*rhoG)[dofIdxGlobal]           = elemVolVars[scvIdx].fluidState().density(nPhaseIdx);
+                (*rhoL)[dofIdxGlobal]           = elemVolVars[scvIdx].density(wPhaseIdx);
+                (*rhoG)[dofIdxGlobal]           = elemVolVars[scvIdx].density(nPhaseIdx);
                 (*mobL)[dofIdxGlobal]           = elemVolVars[scvIdx].mobility(wPhaseIdx);
                 (*mobG)[dofIdxGlobal]           = elemVolVars[scvIdx].mobility(nPhaseIdx);
                 (*boxVolume)[dofIdxGlobal]     += fvGeometry.subContVol[scvIdx].volume;
@@ -383,12 +383,12 @@ public:
                 {
                     for (int compIdx = 0; compIdx < numComponents; ++compIdx)
                     {
-                        (*moleFraction[phaseIdx][compIdx])[dofIdxGlobal]= volVars.fluidState().moleFraction(phaseIdx,compIdx);
+                        (*moleFraction[phaseIdx][compIdx])[dofIdxGlobal]= volVars.moleFraction(phaseIdx,compIdx);
                         Valgrind::CheckDefined((*moleFraction[phaseIdx][compIdx])[dofIdxGlobal]);
                     }
                 }
                 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
-                    (*molarity[compIdx])[dofIdxGlobal] = (volVars.fluidState().molarity(wPhaseIdx, compIdx));
+                    (*molarity[compIdx])[dofIdxGlobal] = (volVars.molarity(wPhaseIdx, compIdx));
 
                 Tensor K = perm_(this->problem_().spatialParams().intrinsicPermeability(element, fvGeometry, scvIdx));
 
@@ -641,11 +641,11 @@ protected:
                     //switch not depending on formulation
                     //switch "Sl" to "xgH20"
                     globalSol[dofIdxGlobal][switchIdx]
-                            = volVars.fluidState().moleFraction(nPhaseIdx, wCompIdx /*H2O*/);
+                            = volVars.moleFraction(nPhaseIdx, wCompIdx /*H2O*/);
 
                     //switch all secondary components to mole fraction in gas phase
                     for (int compIdx=numMajorComponents; compIdx<numComponents; ++compIdx)
-                        globalSol[dofIdxGlobal][compIdx] = volVars.fluidState().moleFraction(nPhaseIdx,compIdx);
+                        globalSol[dofIdxGlobal][compIdx] = volVars.moleFraction(nPhaseIdx,compIdx);
                 }
                 //if saturation of gas phase is smaller than 0 switch
                 else if (volVars.saturation(nPhaseIdx) <= Smin)
@@ -659,7 +659,7 @@ protected:
 
                     //switch "Sl" to "xlN2"
                     globalSol[dofIdxGlobal][switchIdx]
-                            = volVars.fluidState().moleFraction(wPhaseIdx, nCompIdx /*N2*/);
+                            = volVars.moleFraction(wPhaseIdx, nCompIdx /*N2*/);
                 }
             }
             else if (phasePresence == nPhaseOnly)
@@ -669,7 +669,7 @@ protected:
                 //Calculate sum of mole fractions in the hypothetical liquid phase
                 for (int compIdx = 0; compIdx < numComponents; compIdx++)
                 {
-                    sumxl += volVars.fluidState().moleFraction(wPhaseIdx, compIdx);
+                    sumxl += volVars.moleFraction(wPhaseIdx, compIdx);
                 }
                 if (sumxl > xlmax)
                     wouldSwitch = true;
@@ -691,7 +691,7 @@ protected:
 
                     //switch all secondary components back to liquid mole fraction
                     for (int compIdx=numMajorComponents; compIdx<numComponents; ++compIdx)
-                        globalSol[dofIdxGlobal][compIdx] = volVars.fluidState().moleFraction(wPhaseIdx,compIdx);
+                        globalSol[dofIdxGlobal][compIdx] = volVars.moleFraction(wPhaseIdx,compIdx);
                 }
             }
             else if (phasePresence == wPhaseOnly)
@@ -701,7 +701,7 @@ protected:
                 //Calculate sum of mole fractions in the hypothetical liquid phase
                 for (int compIdx = 0; compIdx < numComponents; compIdx++)
                 {
-                    sumxg += volVars.fluidState().moleFraction(nPhaseIdx, compIdx);
+                    sumxg += volVars.moleFraction(nPhaseIdx, compIdx);
                 }
                 if (sumxg > xgmax)
                     wouldSwitch = true;
diff --git a/dumux/implicit/2pnc/2pncvolumevariables.hh b/dumux/implicit/2pnc/2pncvolumevariables.hh
index 7bf1c928eb..2b8e3980a6 100644
--- a/dumux/implicit/2pnc/2pncvolumevariables.hh
+++ b/dumux/implicit/2pnc/2pncvolumevariables.hh
@@ -445,6 +445,37 @@ public:
     Scalar diffCoeff(int phaseIdx, int compIdx) const
     { return diffCoeff_[phaseIdx][compIdx]; }
 
+    /*!
+     * \brief Returns the molarity of a component in the phase
+     *
+     * \param phaseIdx the index of the fluid phase
+     * \param compIdx the index of the component
+     */
+     Scalar molarity(int phaseIdx, int compIdx) const // [moles/m^3]
+    { return this->fluidState_.molarity(phaseIdx, compIdx);}
+
+     /*!
+      * \brief Returns the mass fraction of a component in the phase
+      *
+      * \param phaseIdx the index of the fluid phase
+      * \param compIdx the index of the component
+      */
+     Scalar massFraction(int phaseIdx, int compIdx) const
+     {
+        return this->fluidState_.massFraction(phaseIdx, compIdx);
+     }
+
+     /*!
+      * \brief Returns the mole fraction of a component in the phase
+      *
+      * \param phaseIdx the index of the fluid phase
+      * \param compIdx the index of the component
+      */
+     Scalar moleFraction(int phaseIdx, int compIdx) const
+     {
+        return this->fluidState_.moleFraction(phaseIdx, compIdx);
+     }
+
 protected:
 
     static Scalar temperature_(const PrimaryVariables &priVars,
diff --git a/dumux/implicit/2pncmin/2pncminmodel.hh b/dumux/implicit/2pncmin/2pncminmodel.hh
index 573fab9d76..808e387e4a 100644
--- a/dumux/implicit/2pncmin/2pncminmodel.hh
+++ b/dumux/implicit/2pncmin/2pncminmodel.hh
@@ -265,8 +265,8 @@ public:
                 (*pg)[globalIdx]                = volVars.pressure(nPhaseIdx);
                 (*pl)[globalIdx]                 = volVars.pressure(wPhaseIdx);
                 (*pc)[globalIdx]              = volVars.capillaryPressure();
-                (*rhoL)[globalIdx]               = volVars.fluidState().density(wPhaseIdx);
-                (*rhoG)[globalIdx]               = volVars.fluidState().density(nPhaseIdx);
+                (*rhoL)[globalIdx]               = volVars.density(wPhaseIdx);
+                (*rhoG)[globalIdx]               = volVars.density(nPhaseIdx);
                 (*mobL)[globalIdx]               = volVars.mobility(wPhaseIdx);
                 (*mobG)[globalIdx]               = volVars.mobility(nPhaseIdx);
                 (*boxVolume)[globalIdx]        += fvGeometry.subContVol[i].volume;
@@ -283,13 +283,13 @@ public:
                 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
                     for (int compIdx = 0; compIdx < numComponents; ++compIdx)
                     {
-                        (*massFraction[phaseIdx][compIdx])[globalIdx]= volVars.fluidState().massFraction(phaseIdx,compIdx);
+                        (*massFraction[phaseIdx][compIdx])[globalIdx]= volVars.massFraction(phaseIdx,compIdx);
 
                         Valgrind::CheckDefined((*massFraction[phaseIdx][compIdx])[globalIdx]);
 
                     }
                 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
-                    (*molarity[compIdx])[globalIdx] = (volVars.fluidState().molarity(wPhaseIdx, compIdx));
+                    (*molarity[compIdx])[globalIdx] = (volVars.molarity(wPhaseIdx, compIdx));
 
                 Tensor K = this->perm_(this->problem_().spatialParams().intrinsicPermeability(element, fvGeometry, i));
 
@@ -458,7 +458,7 @@ protected:
                     //switch not depending on formulation
                     //switch "Sl" to "xgH20"
                     globalSol[globalIdx][switchIdx]
-                            = volVars.fluidState().moleFraction(nPhaseIdx, wCompIdx /*H2O*/);
+                            = volVars.moleFraction(nPhaseIdx, wCompIdx /*H2O*/);
                     //Here unlike 2pnc model we do not switch all components to to mole fraction in gas phase
                 }
                 //if saturation of gas phase is smaller than 0 switch
@@ -473,7 +473,7 @@ protected:
 
                     //switch "Sl" to "xlN2"
                     globalSol[globalIdx][switchIdx]
-                            = volVars.fluidState().moleFraction(wPhaseIdx, nCompIdx /*N2*/);
+                            = volVars.moleFraction(wPhaseIdx, nCompIdx /*N2*/);
                 }
             }
             else if (phasePresence == nPhaseOnly)
@@ -484,7 +484,7 @@ protected:
             //are only present in the liquid phase and cannot condense as the liquid (water).
             for (int compIdx = 0; compIdx < numComponents; compIdx++)
                 {
-                    sumxl += volVars.fluidState().moleFraction(wPhaseIdx, compIdx);
+                    sumxl += volVars.moleFraction(wPhaseIdx, compIdx);
                 }
                     Scalar xlmax = 1.0;
                     if (sumxl > xlmax)
@@ -515,7 +515,7 @@ protected:
                 //Calculate sum of mole fractions in the hypothetical gas phase
                 for (int compIdx = 0; compIdx < numComponents; compIdx++)
                 {
-                    sumxg += volVars.fluidState().moleFraction(nPhaseIdx, compIdx);
+                    sumxg += volVars.moleFraction(nPhaseIdx, compIdx);
                 }
                 if (sumxg > xgmax)
                     wouldSwitch = true;
diff --git a/dumux/implicit/2pncmin/2pncminvolumevariables.hh b/dumux/implicit/2pncmin/2pncminvolumevariables.hh
index 9ac0798774..12e9e6e063 100644
--- a/dumux/implicit/2pncmin/2pncminvolumevariables.hh
+++ b/dumux/implicit/2pncmin/2pncminvolumevariables.hh
@@ -416,16 +416,16 @@ public:
     Scalar permeabilityFactor() const
     { return permeabilityFactor_; }
 
-    /*!
-     * \brief Returns the mole fraction of a component in the phase
-     *
-     * \param phaseIdx the index of the fluid phase
-     * \param compIdx the index of the component
-     */
-    Scalar moleFraction(int phaseIdx, int compIdx) const
-    {
-       return this->fluidState_.moleFraction(phaseIdx, compIdx);
-    }
+//    /*!
+//     * \brief Returns the mole fraction of a component in the phase
+//     *
+//     * \param phaseIdx the index of the fluid phase
+//     * \param compIdx the index of the component
+//     */
+//    Scalar moleFraction(int phaseIdx, int compIdx) const
+//    {
+//       return this->fluidState_.moleFraction(phaseIdx, compIdx);
+//    }
 
     /*!
      * \brief Returns the mole fraction of the salinity in the liquid phase
@@ -478,9 +478,15 @@ public:
      *
      * \param phaseIdx the index of the fluid phase
      * \param compIdx the index of the component
+     * molality=\frac{n_{component}}{m_{solvent}}
+     * =\frac{n_{component}}{n_{solvent}*M_{solvent}}
+     * compIdx of the main component (solvent) in the
+     * phase is equal to the phaseIdx
      */
      Scalar molality(int phaseIdx, int compIdx) const // [moles/Kg]
-    { return this->fluidState_.moleFraction(phaseIdx, compIdx)/FluidSystem::molarMass(compIdx);}
+    { return this->fluidState_.moleFraction(phaseIdx, compIdx)
+                  /(fluidState_.moleFraction(phaseIdx, phaseIdx)
+                  * FluidSystem::molarMass(phaseIdx));}
 
 protected:
     friend class TwoPNCVolumeVariables<TypeTag>;
@@ -528,6 +534,7 @@ protected:
     Scalar sumPrecipitates_;
     Scalar salinity_;
     Scalar moleFractionSalinity_;
+    FluidState fluidState_;
 
 private:
     Implementation &asImp_()
-- 
GitLab