From be6e39cfb9501f2830fb565ff4a5cab7c58367e7 Mon Sep 17 00:00:00 2001
From: Bernd Flemisch <bernd@iws.uni-stuttgart.de>
Date: Fri, 5 Aug 2011 13:08:38 +0000
Subject: [PATCH] Now, the box 2p model can use the parameter tree for enabling
 gravity. In order to not run into serious performance penalties, the
 parameter tree is not parsed every time a FluxVariables object is
 constructed. Instead, the 2p problem has been equipped with a function const
 bool enableGravity() const which is called from the flux variables.

An example for the usage is provided in
dumux-devel/test/boxmodels/2pwithparam.


git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@6395 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 dumux/boxmodels/2p/2pfluxvariables.hh | 10 +++++++---
 dumux/boxmodels/2p/2pproblem.hh       | 16 ++++++++++++++--
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/dumux/boxmodels/2p/2pfluxvariables.hh b/dumux/boxmodels/2p/2pfluxvariables.hh
index 0bdd2be980..3fa3e5d331 100644
--- a/dumux/boxmodels/2p/2pfluxvariables.hh
+++ b/dumux/boxmodels/2p/2pfluxvariables.hh
@@ -53,6 +53,7 @@ class TwoPFluxVariables
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
 
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(Problem)) Problem;
+    typedef typename GET_PROP(TypeTag, PTAG(ParameterTree)) Params;
 
     typedef typename GridView::ctype CoordScalar;
     typedef typename GridView::template Codim<0>::Entity Element;
@@ -63,7 +64,7 @@ class TwoPFluxVariables
         dimWorld = GridView::dimensionworld,
         numPhases = GET_PROP_VALUE(TypeTag, PTAG(NumPhases)),
 
-        enableGravity = GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)),
+//        enableGravity = GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)),
     };
 
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(FVElementGeometry)) FVElementGeometry;
@@ -89,7 +90,8 @@ public:
                  const FVElementGeometry &elemGeom,
                  int faceIdx,
                  const ElementVolumeVariables &elemDat)
-        : fvElemGeom_(elemGeom)
+        : fvElemGeom_(elemGeom), enableGravity_(problem.enableGravity())
+
     {
         scvfIdx_ = faceIdx;
 
@@ -178,7 +180,7 @@ private:
         ///////////////
         // correct the pressure gradients by the gravitational acceleration
         ///////////////
-        if (enableGravity) {
+        if (enableGravity_) {
             // estimate the gravitational acceleration at a given SCV face
             // using the arithmetic mean
             Vector g(problem.boxGravity(element, fvElemGeom_, face().i));
@@ -225,6 +227,8 @@ private:
                                                                 fvElemGeom_,
                                                                 face().j));
     }
+
+    const bool enableGravity_;
 };
 
 } // end namepace
diff --git a/dumux/boxmodels/2p/2pproblem.hh b/dumux/boxmodels/2p/2pproblem.hh
index 35b0e76901..ae0e5663ab 100644
--- a/dumux/boxmodels/2p/2pproblem.hh
+++ b/dumux/boxmodels/2p/2pproblem.hh
@@ -55,6 +55,7 @@ class TwoPProblem : public BoxProblem<TypeTag>
 
     typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition;
     typedef typename GridView::template Codim<0>::Entity Element;
+    typedef typename GET_PROP(TypeTag, PTAG(ParameterTree)) Params;
 
 public:
     /*!
@@ -74,7 +75,9 @@ public:
         spatialParameters_ = new SpatialParameters(gridView);
 
         gravity_ = 0;
-        if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
+        enableGravity_ = GET_PROP_VALUE(TypeTag, PTAG(EnableGravity));
+        enableGravity_ = Params::tree().get("EnableGravity", enableGravity_);
+        if (enableGravity_)
             gravity_[dim-1]  = -9.81;
     }
 
@@ -95,7 +98,9 @@ public:
     {
         newSpatialParams_ = false;
         gravity_ = 0;
-        if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
+        enableGravity_ = GET_PROP_VALUE(TypeTag, PTAG(EnableGravity));
+        enableGravity_ = Params::tree().get("EnableGravity", enableGravity_);
+        if (enableGravity_)
             gravity_[dim-1]  = -9.81;
     }
 
@@ -179,6 +184,12 @@ public:
     const GlobalPosition &gravity() const
     { return gravity_; }
 
+    /*!
+     * \brief Check whether gravity is enabled.
+     */
+    const bool enableGravity() const
+    { return enableGravity_; }
+
     /*!
      * \brief Returns the spatial parameters object.
      */
@@ -206,6 +217,7 @@ private:
     // fluids and material properties
     SpatialParameters*  spatialParameters_;
     bool newSpatialParams_;
+    bool enableGravity_;
 };
 
 }
-- 
GitLab