From cb0db8cb5b50f9769a3acbb274680c0f9eaaf9d6 Mon Sep 17 00:00:00 2001
From: Holger Class <holger.class@iws.uni-stuttgart.de>
Date: Thu, 26 Jul 2012 10:55:45 +0000
Subject: [PATCH] useConstraintSolver option was added, to be used directly in
 the volumevariables

git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@8741 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 dumux/boxmodels/3p3c/3p3cmodel.hh            |   2 +-
 dumux/boxmodels/3p3c/3p3cpropertydefaults.hh |   1 -
 dumux/boxmodels/3p3c/3p3cvolumevariables.hh  | 218 +++++++++++++++++--
 3 files changed, 196 insertions(+), 25 deletions(-)

diff --git a/dumux/boxmodels/3p3c/3p3cmodel.hh b/dumux/boxmodels/3p3c/3p3cmodel.hh
index 75567cb65e..9df10bf629 100644
--- a/dumux/boxmodels/3p3c/3p3cmodel.hh
+++ b/dumux/boxmodels/3p3c/3p3cmodel.hh
@@ -37,7 +37,7 @@
 
 #include "3p3cproperties.hh"
 #include "3p3clocalresidual.hh"
-#include "3p3cproblem.hh"
+// #include "3p3cproblem.hh"
 
 namespace Dumux
 {
diff --git a/dumux/boxmodels/3p3c/3p3cpropertydefaults.hh b/dumux/boxmodels/3p3c/3p3cpropertydefaults.hh
index 0493d25f7a..f97b252b78 100644
--- a/dumux/boxmodels/3p3c/3p3cpropertydefaults.hh
+++ b/dumux/boxmodels/3p3c/3p3cpropertydefaults.hh
@@ -37,7 +37,6 @@
 #include "3p3cindices.hh"
 
 #include "3p3cmodel.hh"
-#include "3p3cproblem.hh"
 #include "3p3cindices.hh"
 #include "3p3cfluxvariables.hh"
 #include "3p3cvolumevariables.hh"
diff --git a/dumux/boxmodels/3p3c/3p3cvolumevariables.hh b/dumux/boxmodels/3p3c/3p3cvolumevariables.hh
index 8498cb1b4f..3fe33893a4 100644
--- a/dumux/boxmodels/3p3c/3p3cvolumevariables.hh
+++ b/dumux/boxmodels/3p3c/3p3cvolumevariables.hh
@@ -128,6 +128,8 @@ public:
                            scvIdx,
                            isOldSol);
 
+        bool useConstraintSolver = false;
+
         // capillary pressure parameters
         const MaterialLawParams &materialParams =
             problem.spatialParams().materialLawParams(element, fvGeometry, scvIdx);
@@ -205,6 +207,7 @@ public:
         // mixture, i.e. fugacity coefficients are not supposed to
         // depend on composition!
         typename FluidSystem::ParameterCache paramCache;
+        // assert(FluidSystem::isIdealGas(gPhaseIdx));
         for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
             assert(FluidSystem::isIdealMixture(phaseIdx));
 
@@ -219,11 +222,60 @@ public:
             // all phases are present, phase compositions are a
             // result of the the gas <-> liquid equilibrium. This is
             // the job of the "MiscibleMultiPhaseComposition"
-            // constraint solver
-            MiscibleMultiPhaseComposition::solve(fluidState_,
-                                                 paramCache,
-                                                 /*setViscosity=*/true,
-                                                 /*setInternalEnergy=*/false);
+            // constraint solver ...
+            if (useConstraintSolver) {
+                MiscibleMultiPhaseComposition::solve(fluidState_,
+                                                     paramCache,
+                                                     /*setViscosity=*/true,
+                                                     /*setInternalEnergy=*/false);
+            } 
+            // ... or calculated explicitly this way ...
+            else {    
+                Scalar partPressH2O = FluidSystem::fugacityCoefficient(fluidState_, 
+                                                                      wPhaseIdx, 
+                                                                      wCompIdx) * pw_;
+                Scalar partPressNAPL = FluidSystem::fugacityCoefficient(fluidState_, 
+                                                                       nPhaseIdx, 
+                                                                       nCompIdx) * pn_;
+                Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
+
+                Scalar xgn = partPressNAPL/pg_;
+                Scalar xgw = partPressH2O/pg_;
+                Scalar xgg = partPressAir/pg_;
+
+                // actually, it's nothing else than Henry coefficient
+                Scalar xwn = partPressNAPL
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 wPhaseIdx,nCompIdx) 
+                                * pw_);
+                Scalar xwg = partPressAir
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 wPhaseIdx,gCompIdx) 
+                                * pw_);
+                Scalar xww = 1.-xwg-xwn;
+
+                Scalar xnn = 1.-2.e-10;
+                Scalar xna = 1.e-10;
+                Scalar xnw = 1.e-10;
+                 
+                fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
+                fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
+                fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
+                fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
+                fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
+                fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
+                fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
+                fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
+                fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
+
+                Scalar rhoW = FluidSystem::density(fluidState_, wPhaseIdx);
+                Scalar rhoG = FluidSystem::density(fluidState_, gPhaseIdx);
+                Scalar rhoN = FluidSystem::density(fluidState_, nPhaseIdx);
+
+                fluidState_.setDensity(wPhaseIdx, rhoW);
+                fluidState_.setDensity(gPhaseIdx, rhoG);
+                fluidState_.setDensity(nPhaseIdx, rhoN);
+            }
         }
         else if (phasePresence == wPhaseOnly) {
             // only the water phase is present, water phase composition is
@@ -241,12 +293,53 @@ public:
 
             // calculate the composition of the remaining phases (as
             // well as the densities of all phases). this is the job
-            // of the "ComputeFromReferencePhase" constraint solver
-            ComputeFromReferencePhase::solve(fluidState_,
-                                             paramCache,
-                                             wPhaseIdx,
-                                             /*setViscosity=*/true,
-                                             /*setInternalEnergy=*/false);
+            // of the "ComputeFromReferencePhase" constraint solver ...
+            if (useConstraintSolver)
+            {
+                ComputeFromReferencePhase::solve(fluidState_,
+                                                 paramCache,
+                                                 wPhaseIdx,
+                                                 /*setViscosity=*/true,
+                                                 /*setInternalEnergy=*/false);
+            }
+            // ... or calculated explicitly this way ...
+            else {    
+                // note that the gas phase is actually not existing!
+                // thus, this is used as phase switch criterion
+                Scalar xgg = xwg * FluidSystem::fugacityCoefficient(fluidState_,
+                                                                    wPhaseIdx,gCompIdx)
+                                   * pw_ / pg_;
+                Scalar xgn = xwn * FluidSystem::fugacityCoefficient(fluidState_,
+                                                                    wPhaseIdx,nCompIdx)
+                                   * pw_ / pg_;
+                Scalar xgw = FluidSystem::fugacityCoefficient(fluidState_,
+                                                              wPhaseIdx,wCompIdx)
+                                   * pw_ / pg_;
+
+
+                // note that the gas phase is actually not existing!
+                // thus, this is used as phase switch criterion
+                Scalar xnn = xwn * FluidSystem::fugacityCoefficient(fluidState_,
+                                                                    wPhaseIdx,nCompIdx)
+                                   * pw_;
+                Scalar xna = 1.e-10;
+                Scalar xnw = 1.e-10;
+                 
+                fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
+                fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
+                fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
+                fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
+                fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
+                fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
+
+                Scalar rhoW = FluidSystem::density(fluidState_, wPhaseIdx);
+                Scalar rhoG = FluidSystem::density(fluidState_, gPhaseIdx);
+                Scalar rhoN = FluidSystem::density(fluidState_, nPhaseIdx);
+
+                fluidState_.setDensity(wPhaseIdx, rhoW);
+                fluidState_.setDensity(gPhaseIdx, rhoG);
+                fluidState_.setDensity(nPhaseIdx, rhoN);
+            }
         }
         else if (phasePresence == gnPhaseOnly) {
             // only gas and NAPL phases are present
@@ -315,12 +408,51 @@ public:
 
             // calculate the composition of the remaining phases (as
             // well as the densities of all phases). this is the job
-            // of the "ComputeFromReferencePhase" constraint solver
-            ComputeFromReferencePhase::solve(fluidState_,
-                                             paramCache,
-                                             gPhaseIdx,
-                                             /*setViscosity=*/true,
-                                             /*setInternalEnergy=*/false);
+            // of the "ComputeFromReferencePhase" constraint solver ...
+            if (useConstraintSolver)
+            {
+                ComputeFromReferencePhase::solve(fluidState_,
+                                                 paramCache,
+                                                 gPhaseIdx,
+                                                 /*setViscosity=*/true,
+                                                 /*setInternalEnergy=*/false);
+            }
+            // ... or calculated explicitly this way ...
+            else {    
+
+                // note that the water phase is actually not existing!
+                // thus, this is used as phase switch criterion
+                Scalar xww = xgw * pg_
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 wPhaseIdx,wCompIdx)
+                                * pw_);
+                Scalar xwn = 1.e-10;
+                Scalar xwg = 1.e-10;
+
+                // note that the NAPL phase is actually not existing!
+                // thus, this is used as phase switch criterion
+                Scalar xnn = xgn * pg_
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 nPhaseIdx,nCompIdx)
+                                * pn_);
+                Scalar xna = 1.e-10;
+                Scalar xnw = 1.e-10;
+                 
+                fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
+                fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
+                fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
+                fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
+                fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
+                fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
+
+                Scalar rhoW = FluidSystem::density(fluidState_, wPhaseIdx);
+                Scalar rhoG = FluidSystem::density(fluidState_, gPhaseIdx);
+                Scalar rhoN = FluidSystem::density(fluidState_, nPhaseIdx);
+
+                fluidState_.setDensity(wPhaseIdx, rhoW);
+                fluidState_.setDensity(gPhaseIdx, rhoG);
+                fluidState_.setDensity(nPhaseIdx, rhoN);
+            }
         }
         else if (phasePresence == wgPhaseOnly) {
             // only water and gas phases are present
@@ -337,12 +469,52 @@ public:
 
             // calculate the composition of the remaining phases (as
             // well as the densities of all phases). this is the job
-            // of the "ComputeFromReferencePhase" constraint solver
-            ComputeFromReferencePhase::solve(fluidState_,
-                                             paramCache,
-                                             gPhaseIdx,
-                                             /*setViscosity=*/true,
-                                             /*setInternalEnergy=*/false);
+            // of the "ComputeFromReferencePhase" constraint solver ...
+            if (useConstraintSolver)
+            {
+                ComputeFromReferencePhase::solve(fluidState_,
+                                                 paramCache,
+                                                 gPhaseIdx,
+                                                 /*setViscosity=*/true,
+                                                 /*setInternalEnergy=*/false);
+            }
+            // ... or calculated explicitly this way ...
+            else {    
+                // actually, it's nothing else than Henry coefficient
+                Scalar xwn = xgn * pg_
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 wPhaseIdx,nCompIdx) 
+                                * pw_);
+                Scalar xwg = xgg * pg_
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 wPhaseIdx,gCompIdx) 
+                                * pw_);
+                Scalar xww = 1.-xwg-xwn;
+
+                // note that the NAPL phase is actually not existing!
+                // thus, this is used as phase switch criterion
+                Scalar xnn = xgn * pg_
+                             / (FluidSystem::fugacityCoefficient(fluidState_,
+                                                                 nPhaseIdx,nCompIdx)
+                                * pn_);;
+                Scalar xna = 1.e-10;
+                Scalar xnw = 1.e-10;
+                 
+                fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
+                fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
+                fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
+                fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
+                fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
+                fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
+
+                Scalar rhoW = FluidSystem::density(fluidState_, wPhaseIdx);
+                Scalar rhoG = FluidSystem::density(fluidState_, gPhaseIdx);
+                Scalar rhoN = FluidSystem::density(fluidState_, nPhaseIdx);
+
+                fluidState_.setDensity(wPhaseIdx, rhoW);
+                fluidState_.setDensity(gPhaseIdx, rhoG);
+                fluidState_.setDensity(nPhaseIdx, rhoN);
+            }
         }
         else
             assert(false); // unhandled phase state
-- 
GitLab