From 667958e07f00b522075abb22a99e1fe0debf7822 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Mon, 30 Jan 2017 14:45:48 +0100
Subject: [PATCH] [fluxvarcache] Implement and use empty cache for less code
 duplication

---
 .../cellcentered/tpfa/darcyslaw.hh            |  6 +-
 .../cellcentered/tpfa/fickslaw.hh             | 30 ++-----
 .../cellcentered/tpfa/fourierslaw.hh          | 29 ++-----
 dumux/discretization/fluxvariablescaching.hh  | 83 +++++++++++++++++++
 4 files changed, 94 insertions(+), 54 deletions(-)
 create mode 100644 dumux/discretization/fluxvariablescaching.hh

diff --git a/dumux/discretization/cellcentered/tpfa/darcyslaw.hh b/dumux/discretization/cellcentered/tpfa/darcyslaw.hh
index a87ed76103..73e086080c 100644
--- a/dumux/discretization/cellcentered/tpfa/darcyslaw.hh
+++ b/dumux/discretization/cellcentered/tpfa/darcyslaw.hh
@@ -106,11 +106,7 @@ class DarcysLawImplementation<TypeTag, DiscretizationMethods::CCTpfa>
                          const SubControlVolumeFace& scvf,
                          const FluxVariablesCacheFiller& fluxVarsCacheFiller)
         {
-            scvfFluxVarsCache.updateAdvection(problem,
-                                              element,
-                                              fvGeometry,
-                                              elemVolVars,
-                                              scvf);
+            scvfFluxVarsCache.updateAdvection(problem, element, fvGeometry, elemVolVars, scvf);
         }
     };
 
diff --git a/dumux/discretization/cellcentered/tpfa/fickslaw.hh b/dumux/discretization/cellcentered/tpfa/fickslaw.hh
index 4634f67847..a6edbd6a9c 100644
--- a/dumux/discretization/cellcentered/tpfa/fickslaw.hh
+++ b/dumux/discretization/cellcentered/tpfa/fickslaw.hh
@@ -31,6 +31,7 @@
 
 #include <dumux/implicit/properties.hh>
 #include <dumux/discretization/methods.hh>
+#include <dumux/discretization/fluxvariablescaching.hh>
 
 namespace Dumux
 {
@@ -70,35 +71,14 @@ class FicksLawImplementation<TypeTag, DiscretizationMethods::CCTpfa >
     using DimWorldMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
     using GlobalPosition = Dune::FieldVector<Scalar, dimWorld>;
 
-    //! We don't store anything for this law
-    class TpfaFicksLawCache
-    {};
-
-    //! The corresponding filler class
-    class TpfaFicksLawCacheFiller
-    {
-    public:
-      //! Function to fill a TpfaFicksLawCache (empty cache) of a given scvf
-      //! We have to fulfill the interface of a diffusion-related cache filler class
-      template<class FluxVariablesCacheFiller>
-      static void fill(FluxVariablesCache& scvfFluxVarsCache,
-                       unsigned int phaseIdx, unsigned int compIdx,
-                       const Problem& problem,
-                       const Element& element,
-                       const FVElementGeometry& fvGeometry,
-                       const ElementVolumeVariables& elemVolVars,
-                       const SubControlVolumeFace& scvf,
-                       const FluxVariablesCacheFiller& fluxVarsCacheFiller)
-      {}
-    };
-
 public:
     // state the discretization method this implementation belongs to
     static const DiscretizationMethods myDiscretizationMethod = DiscretizationMethods::CCTpfa;
 
-    // state the type for the corresponding cache and its filler
-    using Cache = TpfaFicksLawCache;
-    using CacheFiller = TpfaFicksLawCacheFiller;
+    //! state the type for the corresponding cache and its filler
+    //! We don't cache anything for this law
+    using Cache = FluxVariablesCaching::EmptyDiffusionCache;
+    using CacheFiller = FluxVariablesCaching::EmptyCacheFiller<TypeTag>;
 
     static Scalar flux(const Problem& problem,
                        const Element& element,
diff --git a/dumux/discretization/cellcentered/tpfa/fourierslaw.hh b/dumux/discretization/cellcentered/tpfa/fourierslaw.hh
index a7aba69b28..016627964c 100644
--- a/dumux/discretization/cellcentered/tpfa/fourierslaw.hh
+++ b/dumux/discretization/cellcentered/tpfa/fourierslaw.hh
@@ -30,6 +30,7 @@
 #include <dumux/common/parameters.hh>
 #include <dumux/implicit/properties.hh>
 #include <dumux/discretization/methods.hh>
+#include <dumux/discretization/fluxvariablescaching.hh>
 
 namespace Dumux
 {
@@ -67,34 +68,14 @@ class FouriersLawImplementation<TypeTag, DiscretizationMethods::CCTpfa>
 
     using ThermalConductivityModel = typename GET_PROP_TYPE(TypeTag, ThermalConductivityModel);
 
-    //! We don't store anything for this law
-    class TpfaFouriersLawCache
-    {};
-
-    //! The corresponding filler class
-    class TpfaFouriersLawCacheFiller
-    {
-    public:
-      //! Function to fill a TpfaFicksLawCache (empty cache) of a given scvf
-      //! We have to fulfill the interface of a heat conduction related cache filler class
-      template<class FluxVariablesCacheFiller>
-      static void fill(FluxVariablesCache& scvfFluxVarsCache,
-                       const Problem& problem,
-                       const Element& element,
-                       const FVElementGeometry& fvGeometry,
-                       const ElementVolumeVariables& elemVolVars,
-                       const SubControlVolumeFace& scvf,
-                       const FluxVariablesCacheFiller& fluxVarsCacheFiller)
-      {}
-    };
-
 public:
     // state the discretization method this implementation belongs to
     static const DiscretizationMethods myDiscretizationMethod = DiscretizationMethods::CCTpfa;
 
-    // state the type for the corresponding cache and its filler
-    using Cache = TpfaFouriersLawCache;
-    using CacheFiller = TpfaFouriersLawCacheFiller;
+    //! state the type for the corresponding cache and its filler
+    //! We don't cache anything for this law
+    using Cache = FluxVariablesCaching::EmptyHeatConductionCache;
+    using CacheFiller = FluxVariablesCaching::EmptyCacheFiller<TypeTag>;
 
     static Scalar flux(const Problem& problem,
                        const Element& element,
diff --git a/dumux/discretization/fluxvariablescaching.hh b/dumux/discretization/fluxvariablescaching.hh
new file mode 100644
index 0000000000..07e762fac0
--- /dev/null
+++ b/dumux/discretization/fluxvariablescaching.hh
@@ -0,0 +1,83 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   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 Classes related to flux variables caching
+ */
+#ifndef DUMUX_DISCRETIZATION_FLUXVAR_CACHING_HH
+#define DUMUX_DISCRETIZATION_FLUXVAR_CACHING_HH
+
+namespace Dumux
+{
+
+namespace FluxVariablesCaching
+{
+
+class _EmptyCache {};
+
+/*!
+ * \ingroup ImplicitModel
+ * \brief Empty caches to use in a law/process, e.g. Darcy's law
+ * \note Never use the _EmptyCache directly as it lead to ambiguous definitions
+ */
+class EmptyAdvectionCache : public _EmptyCache {};
+class EmptyDiffusionCache : public _EmptyCache {};
+class EmptyHeatConductionCache : public _EmptyCache {};
+
+//! The empty filler class corresponding to EmptyCache
+template<class TypeTag>
+class EmptyCacheFiller
+{
+    using Problem = typename GET_PROP_TYPE(TypeTag, Problem);
+    using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
+    using Element = typename GridView::template Codim<0>::Entity;
+    using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry);
+    using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables);
+    using SubControlVolumeFace = typename GET_PROP_TYPE(TypeTag, SubControlVolumeFace);
+    using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache);
+public:
+    //! For advection filler
+    template<class FluxVariablesCacheFiller>
+    static void fill(FluxVariablesCache& scvfFluxVarsCache,
+                     const Problem& problem,
+                     const Element& element,
+                     const FVElementGeometry& fvGeometry,
+                     const ElementVolumeVariables& elemVolVars,
+                     const SubControlVolumeFace& scvf,
+                     const FluxVariablesCacheFiller& fluxVarsCacheFiller)
+    {}
+
+    //! For diffusion filler
+    template<class FluxVariablesCacheFiller>
+    static void fill(FluxVariablesCache& scvfFluxVarsCache,
+                     unsigned int phaseIdx, unsigned int compIdx,
+                     const Problem& problem,
+                     const Element& element,
+                     const FVElementGeometry& fvGeometry,
+                     const ElementVolumeVariables& elemVolVars,
+                     const SubControlVolumeFace& scvf,
+                     const FluxVariablesCacheFiller& fluxVarsCacheFiller)
+    {}
+};
+
+} // end namespace FluxVariablesCaching
+
+} // end namespace Dumux
+
+#endif
-- 
GitLab