From 7bde74182a76e6438362a59952b9a3f622243b4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de>
Date: Tue, 3 Apr 2018 09:25:41 +0200
Subject: [PATCH] [fluxvars] hand in upwind scheme as template parameter

this also has the benefit that the base class is getting smaller with
the upwind scheme not being in it. Staggered, for example, does not use
an upwind scheme and thus always carried an invalid upwind scheme implementation
with it...
---
 dumux/discretization/fluxvariablesbase.hh     | 37 +------------------
 .../navierstokes/staggered/fluxvariables.hh   |  2 +-
 dumux/porousmediumflow/fluxvariables.hh       | 15 +++++---
 3 files changed, 12 insertions(+), 42 deletions(-)

diff --git a/dumux/discretization/fluxvariablesbase.hh b/dumux/discretization/fluxvariablesbase.hh
index 39fb993a4f..12ffb50a7b 100644
--- a/dumux/discretization/fluxvariablesbase.hh
+++ b/dumux/discretization/fluxvariablesbase.hh
@@ -24,33 +24,16 @@
 #ifndef DUMUX_DISCRETIZATION_FLUXVARIABLESBASE_HH
 #define DUMUX_DISCRETIZATION_FLUXVARIABLESBASE_HH
 
-#include <dumux/common/properties.hh>
-#include <dumux/discretization/upwindscheme.hh>
-
 namespace Dumux {
 
-// forward declaration
-template<class TypeTag, class Impl, class UpwindScheme>
-class FluxVariablesBaseImplementation;
-
-/*!
- * \ingroup Discretization
- * \brief Base class for the flux variables living on a sub control volume face
- * \note The upwind scheme is chosen depending on the discretization method
- */
-template<class TypeTag, class Impl>
-using FluxVariablesBase = FluxVariablesBaseImplementation<TypeTag, Impl, UpwindScheme<typename GET_PROP_TYPE(TypeTag, FVGridGeometry)>>;
-
 /*!
  * \ingroup Discretization
  * \brief Base class for the flux variables living on a sub control volume face
  *
  * \tparam TypeTag The type tag
- * \tparam Implementation The implementation that uses this class as base (CRTP)
- * \tparam UpwindScheme The type of the upwind scheme used for upwinding of advective fluxes
  */
-template<class TypeTag, class Implementation, class UpwindScheme>
-class FluxVariablesBaseImplementation
+template<class TypeTag>
+class FluxVariablesBase
 {
     using Problem = typename GET_PROP_TYPE(TypeTag, Problem);
     using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
@@ -99,23 +82,7 @@ public:
     const ElementFluxVariablesCache& elemFluxVarsCache() const
     { return *elemFluxVarsCachePtr_; }
 
-    //! Applies the upwind scheme to precalculated fluxes
-    template<class UpwindTermFunction>
-    Scalar applyUpwindScheme(const UpwindTermFunction& upwindTerm, Scalar flux, int phaseIdx) const
-    {
-        //! Give the upwind scheme access to the cached variables
-        return UpwindScheme::apply(asImp_(), upwindTerm, flux, phaseIdx);
-    }
-
 private:
-    //! Returns the implementation of the problem (i.e. static polymorphism)
-    Implementation &asImp_()
-    { return *static_cast<Implementation *>(this); }
-
-    //! \copydoc asImp_()
-    const Implementation &asImp_() const
-    { return *static_cast<const Implementation *>(this); }
-
     const Problem* problemPtr_;                             //!< Pointer to the problem
     const Element* elementPtr_;                             //!< Pointer to the element at hand
     const FVElementGeometry* fvGeometryPtr_;                //!< Pointer to the current FVElementGeometry
diff --git a/dumux/freeflow/navierstokes/staggered/fluxvariables.hh b/dumux/freeflow/navierstokes/staggered/fluxvariables.hh
index 88e07cb50d..835674a14c 100644
--- a/dumux/freeflow/navierstokes/staggered/fluxvariables.hh
+++ b/dumux/freeflow/navierstokes/staggered/fluxvariables.hh
@@ -43,7 +43,7 @@ class NavierStokesFluxVariablesImpl;
  */
 template<class TypeTag>
 class NavierStokesFluxVariablesImpl<TypeTag, DiscretizationMethod::staggered>
-: public FluxVariablesBase<TypeTag, NavierStokesFluxVariablesImpl<TypeTag, DiscretizationMethod::staggered>>
+: public FluxVariablesBase<TypeTag>
 {
     using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
     using Problem = typename GET_PROP_TYPE(TypeTag, Problem);
diff --git a/dumux/porousmediumflow/fluxvariables.hh b/dumux/porousmediumflow/fluxvariables.hh
index 40af4a14f1..654b681c05 100644
--- a/dumux/porousmediumflow/fluxvariables.hh
+++ b/dumux/porousmediumflow/fluxvariables.hh
@@ -28,6 +28,7 @@
 
 #include <dumux/common/properties.hh>
 #include <dumux/discretization/fluxvariablesbase.hh>
+#include <dumux/discretization/upwindscheme.hh>
 
 namespace Dumux {
 
@@ -35,14 +36,15 @@ namespace Dumux {
  * \ingroup ImplicitModel
  * \brief The porous medium flux variables class that computes advective / convective,
  *        molecular diffusive and heat conduction fluxes.
+ *
+ * \param TypeTag The type tag for access to type traits
+ * \param UpwindScheme The upwind scheme to be applied to advective fluxes
  * \note  Not all specializations are currently implemented
  */
-template<class TypeTag>
-class PorousMediumFluxVariables : public FluxVariablesBase<TypeTag, PorousMediumFluxVariables<TypeTag>>
+template<class TypeTag,
+         class UpwindScheme = UpwindScheme<typename GET_PROP_TYPE(TypeTag, FVGridGeometry)> >
+class PorousMediumFluxVariables : public FluxVariablesBase<TypeTag>
 {
-    using ThisType = PorousMediumFluxVariables<TypeTag>;
-    using ParentType = FluxVariablesBase<TypeTag, ThisType>;
-
     using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
     using ModelTraits = typename GET_PROP_TYPE(TypeTag, ModelTraits);
     using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry);
@@ -99,7 +101,8 @@ public:
             advFluxIsCached_.set(phaseIdx, true);
         }
 
-        return this->applyUpwindScheme(upwindTerm, advFluxBeforeUpwinding_[phaseIdx], phaseIdx);
+        //! Give the upwind scheme access to the cached variables
+        return UpwindScheme::apply(*this, upwindTerm, advFluxBeforeUpwinding_[phaseIdx], phaseIdx);
     }
 
     /*!
-- 
GitLab