From 11fcc94dec704f559302d0868dafe5d5e71f4bf5 Mon Sep 17 00:00:00 2001
From: Andreas Lauser <and@poware.org>
Date: Fri, 16 Dec 2011 13:23:29 +0000
Subject: [PATCH] Moved the actual implementation of completeFluidState to the
 volume variables. For the box models, this appears to be the natural place
 where it belongs to. Inserted a convenience function in the model.

git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@7064 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 dumux/boxmodels/2p/2pmodel.hh               | 73 ++------------------
 dumux/boxmodels/2p/2pvolumevariables.hh     | 76 ++++++++++++++++++++-
 dumux/boxmodels/2pni/2pnimodel.hh           | 25 +------
 dumux/boxmodels/2pni/2pnivolumevariables.hh | 18 +++++
 4 files changed, 98 insertions(+), 94 deletions(-)

diff --git a/dumux/boxmodels/2p/2pmodel.hh b/dumux/boxmodels/2p/2pmodel.hh
index 96ca672685..9401466e43 100644
--- a/dumux/boxmodels/2p/2pmodel.hh
+++ b/dumux/boxmodels/2p/2pmodel.hh
@@ -76,7 +76,6 @@ class TwoPModel : public BoxModel<TypeTag>
     typedef TwoPModel<TypeTag> ThisType;
     typedef BoxModel<TypeTag> ParentType;
 
-    typedef typename GET_PROP_TYPE(TypeTag, PTAG(Model)) Implementation;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(FVElementGeometry)) FVElementGeometry;
@@ -126,62 +125,16 @@ public:
         return 1;
     }
 
-    template <class PrimaryVariables, class Problem, class Element, class ElementGeometry, class FluidState>
+    template <class PrimaryVariables, class Problem, class Element, class FluidState>
     static void completeFluidState(const PrimaryVariables& primaryVariables,
                                    const Problem& problem,
                                    const Element& element,
-                                   const ElementGeometry& elementGeometry,
+                                   const FVElementGeometry& elementGeometry,
                                    int scvIdx,
                                    FluidState& fluidState)
     {
-        Scalar t = Implementation::temperature_(primaryVariables, problem, element,
-                                                elementGeometry, scvIdx);
-        fluidState.setTemperature(t);
-
-        // material law parameters
-        typedef typename GET_PROP_TYPE(TypeTag, PTAG(MaterialLaw)) MaterialLaw;
-        const typename MaterialLaw::Params &materialParams =
-            problem.spatialParameters().materialLawParams(element, elementGeometry, scvIdx);
-
-
-        if (int(formulation) == pwSn) {
-            Scalar Sn = primaryVariables[saturationIdx];
-            fluidState.setSaturation(nPhaseIdx, Sn);
-            fluidState.setSaturation(wPhaseIdx, 1 - Sn);
-
-            Scalar pW = primaryVariables[pressureIdx];
-            fluidState.setPressure(wPhaseIdx, pW);
-            fluidState.setPressure(nPhaseIdx,
-                                   pW + MaterialLaw::pC(materialParams, 1 - Sn));
-        }
-        else if (int(formulation) == pnSw) {
-            Scalar Sw = primaryVariables[saturationIdx];
-            fluidState.setSaturation(wPhaseIdx, Sw);
-            fluidState.setSaturation(nPhaseIdx, 1 - Sw);
-
-            Scalar pN = primaryVariables[pressureIdx];
-            fluidState.setPressure(nPhaseIdx, pN);
-            fluidState.setPressure(wPhaseIdx,
-                                   pN - MaterialLaw::pC(materialParams, Sw));
-        }
-
-        typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
-        typename FluidSystem::ParameterCache paramCache;
-        paramCache.updateAll(fluidState);
-
-        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
-            // compute and set the viscosity
-            Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
-            fluidState.setViscosity(phaseIdx, mu);
-
-            // compute and set the density
-            Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
-            fluidState.setDensity(phaseIdx, rho);
-
-            // compute and set the enthalpy
-            Scalar h = Implementation::enthalpy_(fluidState, paramCache, phaseIdx);
-            fluidState.setEnthalpy(phaseIdx, h);
-        }
+      VolumeVariables::completeFluidState(primaryVariables, problem, element, 
+					  elementGeometry, scvIdx, fluidState);
     }
 
     /*!
@@ -416,24 +369,6 @@ public:
         }
         writer.attachCellData(*rank, "process rank");
     }
-private:
-    template<class PrimaryVariables, class Problem, class Element, class FVElementGeometry>
-    static Scalar temperature_(const PrimaryVariables &priVars,
-                            const Problem& problem,
-                            const Element &element,
-                            const FVElementGeometry &elemGeom,
-                            int scvIdx)
-    {
-        return problem.boxTemperature(element, elemGeom, scvIdx);
-    }
-
-    template<class FluidState, class ParameterCache>
-    static Scalar enthalpy_(const FluidState& fluidState,
-                            const ParameterCache& paramCache,
-                            int phaseIdx)
-    {
-        return 0;
-    }
 };
 }
 
diff --git a/dumux/boxmodels/2p/2pvolumevariables.hh b/dumux/boxmodels/2p/2pvolumevariables.hh
index a321b2a500..e3b80aa2a0 100644
--- a/dumux/boxmodels/2p/2pvolumevariables.hh
+++ b/dumux/boxmodels/2p/2pvolumevariables.hh
@@ -102,7 +102,7 @@ public:
                            scvIdx,
                            isOldSol);
 
-        Model::completeFluidState(priVars, problem, element, elemGeom, scvIdx, fluidState_);
+        completeFluidState(priVars, problem, element, elemGeom, scvIdx, fluidState_);
 
         const MaterialLawParams &materialParams =
             problem.spatialParameters().materialLawParams(element, elemGeom, scvIdx);
@@ -124,6 +124,63 @@ public:
         asImp_().updateEnergy_(priVars, problem, element, elemGeom, scvIdx, isOldSol);
     }
 
+    static void completeFluidState(const PrimaryVariables& priVars,
+                                   const Problem& problem,
+                                   const Element& element,
+                                   const FVElementGeometry& elemGeom,
+                                   int scvIdx,
+                                   FluidState& fluidState)
+    {
+        Scalar t = Implementation::temperature_(priVars, problem, element,
+                                                elemGeom, scvIdx);
+        fluidState.setTemperature(t);
+
+        // material law parameters
+        typedef typename GET_PROP_TYPE(TypeTag, PTAG(MaterialLaw)) MaterialLaw;
+        const typename MaterialLaw::Params &materialParams =
+            problem.spatialParameters().materialLawParams(element, elemGeom, scvIdx);
+
+
+        if (int(formulation) == pwSn) {
+            Scalar Sn = priVars[saturationIdx];
+            fluidState.setSaturation(nPhaseIdx, Sn);
+            fluidState.setSaturation(wPhaseIdx, 1 - Sn);
+
+            Scalar pW = priVars[pressureIdx];
+            fluidState.setPressure(wPhaseIdx, pW);
+            fluidState.setPressure(nPhaseIdx,
+                                   pW + MaterialLaw::pC(materialParams, 1 - Sn));
+        }
+        else if (int(formulation) == pnSw) {
+            Scalar Sw = priVars[saturationIdx];
+            fluidState.setSaturation(wPhaseIdx, Sw);
+            fluidState.setSaturation(nPhaseIdx, 1 - Sw);
+
+            Scalar pN = priVars[pressureIdx];
+            fluidState.setPressure(nPhaseIdx, pN);
+            fluidState.setPressure(wPhaseIdx,
+                                   pN - MaterialLaw::pC(materialParams, Sw));
+        }
+
+        typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
+        typename FluidSystem::ParameterCache paramCache;
+        paramCache.updateAll(fluidState);
+
+        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
+            // compute and set the viscosity
+            Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
+            fluidState.setViscosity(phaseIdx, mu);
+
+            // compute and set the density
+            Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
+            fluidState.setDensity(phaseIdx, rho);
+
+            // compute and set the enthalpy
+            Scalar h = Implementation::enthalpy_(fluidState, paramCache, phaseIdx);
+            fluidState.setEnthalpy(phaseIdx, h);
+        }
+    }
+
     /*!
      * \brief Returns the phase state for the control-volume.
      */
@@ -189,6 +246,23 @@ public:
     { return porosity_; }
 
 protected:
+    static Scalar temperature_(const PrimaryVariables &priVars,
+                            const Problem& problem,
+                            const Element &element,
+                            const FVElementGeometry &elemGeom,
+                            int scvIdx)
+    {
+        return problem.boxTemperature(element, elemGeom, scvIdx);
+    }
+
+    template<class ParameterCache>
+    static Scalar enthalpy_(const FluidState& fluidState,
+                            const ParameterCache& paramCache,
+                            int phaseIdx)
+    {
+        return 0;
+    }
+
     /*!
      * \brief Called by update() to compute the energy related quantities
      */
diff --git a/dumux/boxmodels/2pni/2pnimodel.hh b/dumux/boxmodels/2pni/2pnimodel.hh
index 088c00b520..ef2709fb6c 100644
--- a/dumux/boxmodels/2pni/2pnimodel.hh
+++ b/dumux/boxmodels/2pni/2pnimodel.hh
@@ -68,30 +68,7 @@ namespace Dumux {
  */
 template<class TypeTag>
 class TwoPNIModel: public TwoPModel<TypeTag>
-{
-    friend class TwoPModel<TypeTag>;
-    typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
-    typedef typename GET_PROP_TYPE(TypeTag, PTAG(TwoPIndices)) Indices;
-
-    template<class PrimaryVariables, class Problem, class Element, class FVElementGeometry>
-    static Scalar temperature_(const PrimaryVariables &priVars,
-                            const Problem& problem,
-                            const Element &element,
-                            const FVElementGeometry &elemGeom,
-                            int scvIdx)
-    {
-        return priVars[Indices::temperatureIdx];
-    }
-
-    template<class FluidState, class ParameterCache>
-    static Scalar enthalpy_(const FluidState& fluidState,
-                            const ParameterCache& paramCache,
-                            int phaseIdx)
-    {
-        typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
-        return FluidSystem::enthalpy(fluidState, paramCache, phaseIdx);
-    }
-};
+{};
 
 }
 
diff --git a/dumux/boxmodels/2pni/2pnivolumevariables.hh b/dumux/boxmodels/2pni/2pnivolumevariables.hh
index c3f0f19926..df0252aab8 100644
--- a/dumux/boxmodels/2pni/2pnivolumevariables.hh
+++ b/dumux/boxmodels/2pni/2pnivolumevariables.hh
@@ -60,6 +60,7 @@ class TwoPNIVolumeVariables : public TwoPVolumeVariables<TypeTag>
     enum { temperatureIdx = Indices::temperatureIdx };
 
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
+    typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidState)) FluidState;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(PrimaryVariables)) PrimaryVariables;
     typedef Dune::FieldVector<Scalar, numPhases> PhasesVector;
 
@@ -95,6 +96,23 @@ protected:
     // is protected, we are friends with our parent..
     friend class TwoPVolumeVariables<TypeTag>;
 
+    static Scalar temperature_(const PrimaryVariables &priVars,
+                            const Problem& problem,
+                            const Element &element,
+                            const FVElementGeometry &elemGeom,
+                            int scvIdx)
+    {
+        return priVars[Indices::temperatureIdx];
+    }
+
+    template<class ParameterCache>
+    static Scalar enthalpy_(const FluidState& fluidState,
+                            const ParameterCache& paramCache,
+                            int phaseIdx)
+    {
+        return FluidSystem::enthalpy(fluidState, paramCache, phaseIdx);
+    }
+
     /*!
      * \brief Called by update() to compute the energy related quantities
      */
-- 
GitLab