From 956e14f24013064b68a20235f993237457e1da9c Mon Sep 17 00:00:00 2001
From: Andreas Lauser <and@poware.org>
Date: Tue, 2 Aug 2011 09:46:09 +0000
Subject: [PATCH] introduce the ParameterTree property

As a test, the mobilityUpwindAlpha of the 2p box model is
converted. so far no keys are loaded, though...

git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@6350 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 dumux/boxmodels/2p/2plocalresidual.hh | 20 +++++++++----
 dumux/common/basicproperties.hh       | 42 +++++++++++++++++++++++++++
 dumux/common/propertysystem.hh        |  1 -
 3 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/dumux/boxmodels/2p/2plocalresidual.hh b/dumux/boxmodels/2p/2plocalresidual.hh
index f3f01ef4c5..85ad39212d 100644
--- a/dumux/boxmodels/2p/2plocalresidual.hh
+++ b/dumux/boxmodels/2p/2plocalresidual.hh
@@ -46,7 +46,7 @@ namespace Dumux
  * that it uses static polymorphism.
  */
 template<class TypeTag>
-class TwoPLocalResidual: public BoxLocalResidual<TypeTag>
+class TwoPLocalResidual : public BoxLocalResidual<TypeTag>
 {
 protected:
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(LocalResidual)) Implementation;
@@ -83,14 +83,24 @@ protected:
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(VolumeVariables)) VolumeVariables;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluxVariables)) FluxVariables;
     typedef typename GET_PROP_TYPE(TypeTag, PTAG(ElementVolumeVariables)) ElementVolumeVariables;
+    typedef typename GET_PROP(TypeTag, PTAG(ParameterTree)) Params;
 
     typedef Dune::FieldVector<Scalar, dimWorld> Vector;
     typedef Dune::FieldMatrix<Scalar, dim, dim> Tensor;
 
-    static constexpr Scalar mobilityUpwindAlpha =
-            GET_PROP_VALUE(TypeTag, PTAG(MobilityUpwindAlpha));
+    Scalar mobilityUpwindAlpha_;
+        
 
 public:
+    TwoPLocalResidual()
+    {
+        // retrieve the upwind weight for the mobility. Use the value
+        // specified via the property system as default, and overwrite
+        // it by the run-time parameter from the Dune::ParameterTree
+        mobilityUpwindAlpha_ = GET_PROP_VALUE(TypeTag, PTAG(MobilityUpwindAlpha));
+        mobilityUpwindAlpha_ = Params::tree().get("MobilityUpwindAlpha", mobilityUpwindAlpha_);
+    };
+
     /*!
      * \brief Evaluate the amount all conservation quantities
      *        (e.g. phase mass) within a finite sub-control volume.
@@ -176,9 +186,9 @@ public:
             flux[eqIdx] +=
                 normalFlux
                 *
-                ((    mobilityUpwindAlpha)*up.density(phaseIdx)*up.mobility(phaseIdx)
+                ((    mobilityUpwindAlpha_)*up.density(phaseIdx)*up.mobility(phaseIdx)
                  +
-                 (1 - mobilityUpwindAlpha)*dn.density(phaseIdx)*dn.mobility(phaseIdx));
+                 (1 - mobilityUpwindAlpha_)*dn.density(phaseIdx)*dn.mobility(phaseIdx));
         }
     }
 
diff --git a/dumux/common/basicproperties.hh b/dumux/common/basicproperties.hh
index ef2cd2447f..898f44be07 100644
--- a/dumux/common/basicproperties.hh
+++ b/dumux/common/basicproperties.hh
@@ -28,6 +28,8 @@
 
 #include <dumux/common/propertysystem.hh>
 
+#include <dune/common/parametertree.hh>
+
 namespace Dumux
 {
 namespace Properties
@@ -61,6 +63,9 @@ NEW_TYPE_TAG(ExplicitModel, INHERITS_FROM(NumericModel));
 //! Property to specify the type of scalar values.
 NEW_PROP_TAG(Scalar);
 
+//! Property which provides a Dune::ParameterTree.
+NEW_PROP_TAG(ParameterTree);
+
 ///////////////////////////////////
 // Default values for properties:
 //
@@ -70,6 +75,43 @@ NEW_PROP_TAG(Scalar);
 //! Set the default type of scalar values to double
 SET_TYPE_PROP(NumericModel, Scalar, double);
 
+//! Set the ParameterTree property
+SET_PROP(NumericModel, ParameterTree)
+{
+    typedef Dune::ParameterTree type;
+    
+    static Dune::ParameterTree &tree()
+    { 
+        if (initFinished_) {
+            DUNE_THROW(Dune::InvalidStateException,
+                       "The ParameterTree cannot be accessed after "
+                       "the initialization phase of the simulation!");
+        }
+        
+        return parameterTree_;
+    };
+
+    static void initFinished()
+    { initFinished_ = true; }
+
+
+private:
+    static Dune::ParameterTree parameterTree_;
+    static bool initFinished_;
+};
+
+// allocate space for the static parameter tree object
+template<class TypeTag>
+Dune::ParameterTree 
+    Property<TypeTag,
+             TTAG(NumericModel), 
+             PTAG(ParameterTree)>::parameterTree_;
+
+template<class TypeTag>
+bool Property<TypeTag,
+              TTAG(NumericModel), 
+              PTAG(ParameterTree)>::initFinished_ = false;
+
 } // namespace Properties
 } // namespace Dumux
 
diff --git a/dumux/common/propertysystem.hh b/dumux/common/propertysystem.hh
index f8a2977ed0..ef74c736b2 100644
--- a/dumux/common/propertysystem.hh
+++ b/dumux/common/propertysystem.hh
@@ -17,7 +17,6 @@
  *   You should have received a copy of the GNU General Public License       *
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
  *****************************************************************************/
-
 /*!
  * \file
  * \brief Provides the magic behind the DuMuX property system.
-- 
GitLab