From 29e612398bcbaae0e0af6de8de769d9594475f5a Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 4 Apr 2018 11:08:41 +0200 Subject: [PATCH] [disc][tpfa] Free grid/element flux variables cache from TypeTag --- .../tpfa/elementfluxvariablescache.hh | 89 ++++++++++--------- .../tpfa/fluxvariablescachefiller.hh | 3 +- .../tpfa/gridfluxvariablescache.hh | 89 +++++++++++-------- .../cellcentered/tpfa/properties.hh | 19 ++-- 4 files changed, 115 insertions(+), 85 deletions(-) diff --git a/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh b/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh index 83a823e008..444a8e5ae8 100644 --- a/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh +++ b/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh @@ -25,11 +25,8 @@ #define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH #include <dune/common/exceptions.hh> -#include <dumux/common/properties.hh> -#include <dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh> -namespace Dumux -{ +namespace Dumux { /*! * \ingroup CCTpfaDiscretization @@ -39,48 +36,51 @@ namespace Dumux * GridFluxVariablesCache which is memory intensive but faster. For caching disabled the * flux caches are locally computed for each element whenever needed. */ -template<class TypeTag, bool EnableGridFluxVariablesCache> +template<class GFVC, bool cachingEnabled> class CCTpfaElementFluxVariablesCache; /*! * \ingroup CCTpfaDiscretization * \brief The flux variables caches for an element with caching enabled */ -template<class TypeTag> -class CCTpfaElementFluxVariablesCache<TypeTag, true> +template<class GFVC> +class CCTpfaElementFluxVariablesCache<GFVC, true> { - using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using IndexType = typename GridView::IndexSet::IndexType; - using Element = typename GridView::template Codim<0>::Entity; - using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView; - using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; - using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); - using GridFluxVariablesCache = typename GET_PROP_TYPE(TypeTag, GridFluxVariablesCache); - using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; - public: + //! export the type of the grid flux variables cache + using GridFluxVariablesCache = GFVC; + + //! export the type of the flux variables cache + using FluxVariablesCache = typename GFVC::FluxVariablesCache; + + //! export the type of the flux variables cache filler + using FluxVariablesCacheFiller = typename GFVC::FluxVariablesCacheFiller; + CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache& global) : gridFluxVarsCachePtr_(&global) {} //! Specialization for the global caching being enabled - do nothing here - void bindElement(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bindElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) {} //! Specialization for the global caching being enabled - do nothing here - void bind(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bind(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) {} //! Specialization for the global caching being enabled - do nothing here - void bindScvf(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bindScvf(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars, - const SubControlVolumeFace& scvf) {} + const typename FVElementGeometry::SubControlVolumeFace& scvf) {} //! Specialization for the global caching being enabled - do nothing here - void update(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void update(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) { @@ -88,6 +88,7 @@ public: } //! access operators in the case of caching + template<class SubControlVolumeFace> const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const { return gridFluxVarsCache()[scvf]; } @@ -103,21 +104,19 @@ private: * \ingroup CCTpfaDiscretization * \brief The flux variables caches for an element with caching disabled */ -template<class TypeTag> -class CCTpfaElementFluxVariablesCache<TypeTag, false> +template<class GFVC> +class CCTpfaElementFluxVariablesCache<GFVC, false> { - using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using IndexType = typename GridView::IndexSet::IndexType; - using Element = typename GridView::template Codim<0>::Entity; - using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView; - using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; - using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); - using GridFluxVariablesCache = typename GET_PROP_TYPE(TypeTag, GridFluxVariablesCache); - using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; - using FluxVariablesCacheFiller = CCTpfaFluxVariablesCacheFiller<TypeTag>; - public: + //! export the type of the grid flux variables cache + using GridFluxVariablesCache = GFVC; + + //! export the type of the flux variables cache + using FluxVariablesCache = typename GFVC::FluxVariablesCache; + + //! export the type of the flux variables cache filler + using FluxVariablesCacheFiller = typename GFVC::FluxVariablesCacheFiller; + CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache& global) : gridFluxVarsCachePtr_(&global) {} @@ -126,7 +125,8 @@ public: * \note the fvGeometry is assumed to be bound to the same element * \note this function has to be called prior to flux calculations on the element. */ - void bindElement(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bindElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) { @@ -138,7 +138,7 @@ public: // instantiate helper class to fill the caches FluxVariablesCacheFiller filler(gridFluxVarsCache().problem()); - IndexType localScvfIdx = 0; + std::size_t localScvfIdx = 0; // fill the containers for (auto&& scvf : scvfs(fvGeometry)) { @@ -153,7 +153,8 @@ public: * \note the fvGeometry is assumed to be bound to the same element * \note this function has to be called prior to flux calculations on the element. */ - void bind(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bind(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) { @@ -201,10 +202,11 @@ public: * \note the fvGeometry is assumed to be bound to the same element * \note this function has to be called prior to flux calculations on the element. */ - void bindScvf(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void bindScvf(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars, - const SubControlVolumeFace& scvf) + const typename FVElementGeometry::SubControlVolumeFace& scvf) { fluxVarsCache_.resize(1); globalScvfIndices_.resize(1); @@ -220,7 +222,8 @@ public: * \brief Update the transmissibilities if the volume variables have changed * \note Results in undefined behaviour if called before bind() or with a different element */ - void update(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void update(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) { @@ -248,10 +251,12 @@ public: } //! access operators in the case of no caching + template<class SubControlVolumeFace> const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } //! access operators in the case of no caching + template<class SubControlVolumeFace> FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } @@ -271,7 +276,7 @@ private: } std::vector<FluxVariablesCache> fluxVarsCache_; - std::vector<IndexType> globalScvfIndices_; + std::vector<std::size_t> globalScvfIndices_; }; } // end namespace Dumux diff --git a/dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh b/dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh index c78114d0ba..69b5b024ff 100644 --- a/dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh +++ b/dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh @@ -27,8 +27,7 @@ #include <dumux/common/properties.hh> #include <dumux/discretization/methods.hh> -namespace Dumux -{ +namespace Dumux { /*! * \ingroup CCTpfaDiscretization diff --git a/dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh b/dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh index 317a2e8e01..6eef4a02c0 100644 --- a/dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh +++ b/dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh @@ -24,20 +24,37 @@ #ifndef DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH #define DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH -#include <dumux/common/properties.hh> -#include <dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh> - //! make the local view function available whenever we use this class #include <dumux/discretization/localview.hh> +#include <dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh> namespace Dumux { +/*! + * \ingroup CCTpfaDiscretization + * \brief Flux variable caches traits + */ +template<class P, class FVC, class FVCF> +struct CCTpfaDefaultGridFVCTraits +{ + using Problem = P; + using FluxVariablesCache = FVC; + using FluxVariablesCacheFiller = FVCF; + + template<class GridFluxVariablesCache, bool cachingEnabled> + using LocalView = CCTpfaElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>; +}; + /*! * \ingroup CCTpfaDiscretization * \brief Flux variable caches on a gridview * \note The class is specialized for a version with and without grid caching */ -template<class TypeTag, bool EnableGridFluxVariablesCache> +template<class Problem, + class FluxVariablesCache, + class FluxVariablesCacheFiller, + bool EnableGridFluxVariablesCache = false, + class Traits = CCTpfaDefaultGridFVCTraits<Problem, FluxVariablesCache, FluxVariablesCacheFiller> > class CCTpfaGridFluxVariablesCache; /*! @@ -45,33 +62,30 @@ class CCTpfaGridFluxVariablesCache; * \brief Flux variable caches on a gridview with grid caching enabled * \note The flux caches of the gridview are stored which is memory intensive but faster */ -template<class TypeTag> -class CCTpfaGridFluxVariablesCache<TypeTag, true> +template<class P, class FVC, class FVCF, class Traits> +class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, Traits> { - using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); - using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView; - using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector); - using GridVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables); - using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; - using IndexType = typename GridView::IndexSet::IndexType; - using Element = typename GridView::template Codim<0>::Entity; - using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); - using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; - using FluxVariablesCacheFiller = CCTpfaFluxVariablesCacheFiller<TypeTag>; + using Problem = typename Traits::Problem; + using ThisType = CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, Traits>; public: - //! export the type of the local view - using LocalView = typename GET_PROP_TYPE(TypeTag, ElementFluxVariablesCache); + //! export the flux variable cache type + using FluxVariablesCache = typename Traits::FluxVariablesCache; + + //! export the flux variable cache filler type + using FluxVariablesCacheFiller = typename Traits::FluxVariablesCacheFiller; //! make it possible to query if caching is enabled static constexpr bool cachingEnabled = true; + //! export the type of the local view + using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; + // The constructor CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {} // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces + template<class FVGridGeometry, class GridVolumeVariables, class SolutionVector> void update(const FVGridGeometry& fvGridGeometry, const GridVolumeVariables& gridVolVars, const SolutionVector& sol, @@ -101,7 +115,8 @@ public: } } - void updateElement(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void updateElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) { @@ -130,9 +145,11 @@ public: } // access operators in the case of caching + template<class SubControlVolumeFace> const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const { return fluxVarsCache_[scvf.index()]; } + template<class SubControlVolumeFace> FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) { return fluxVarsCache_[scvf.index()]; } @@ -143,43 +160,45 @@ private: const Problem* problemPtr_; std::vector<FluxVariablesCache> fluxVarsCache_; - std::vector<IndexType> globalScvfIndices_; + std::vector<std::size_t> globalScvfIndices_; }; /*! * \ingroup CCTpfaDiscretization * \brief Flux variable caches on a gridview with grid caching disabled */ -template<class TypeTag> -class CCTpfaGridFluxVariablesCache<TypeTag, false> +template<class P, class FVC, class FVCF, class Traits> +class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, Traits> { - using GridView = typename GET_PROP_TYPE(TypeTag, GridView); - using Element = typename GridView::template Codim<0>::Entity; - using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); - using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry)::LocalView; - using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector); - using GridVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables); - using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, GridVolumeVariables)::LocalView; + using Problem = typename Traits::Problem; + using ThisType = CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, Traits>; public: - //! export the type of the local view - using LocalView = typename GET_PROP_TYPE(TypeTag, ElementFluxVariablesCache); + //! export the flux variable cache type + using FluxVariablesCache = typename Traits::FluxVariablesCache; + + //! export the flux variable cache filler type + using FluxVariablesCacheFiller = typename Traits::FluxVariablesCacheFiller; //! make it possible to query if caching is enabled static constexpr bool cachingEnabled = false; + //! export the type of the local view + using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; + // The constructor CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {} //! When global flux variables caching is disabled, we don't need to update the cache + template<class FVGridGeometry, class GridVolumeVariables, class SolutionVector> void update(const FVGridGeometry& fvGridGeometry, const GridVolumeVariables& gridVolVars, const SolutionVector& sol, bool forceUpdate = false) {} //! When global flux variables caching is disabled, we don't need to update the cache - void updateElement(const Element& element, + template<class FVElementGeometry, class ElementVolumeVariables> + void updateElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const ElementVolumeVariables& elemVolVars) {} diff --git a/dumux/discretization/cellcentered/tpfa/properties.hh b/dumux/discretization/cellcentered/tpfa/properties.hh index 3680e2f8c8..a1dddbd8f9 100644 --- a/dumux/discretization/cellcentered/tpfa/properties.hh +++ b/dumux/discretization/cellcentered/tpfa/properties.hh @@ -35,13 +35,11 @@ #include <dumux/discretization/fvproperties.hh> #include <dumux/discretization/cellcentered/subcontrolvolume.hh> - #include <dumux/discretization/cellcentered/elementboundarytypes.hh> -#include <dumux/discretization/cellcentered/elementsolution.hh> #include <dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh> #include <dumux/discretization/cellcentered/tpfa/gridvolumevariables.hh> #include <dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh> -#include <dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh> +#include <dumux/discretization/cellcentered/tpfa/fluxvariablescachefiller.hh> #include <dumux/discretization/cellcentered/tpfa/subcontrolvolumeface.hh> namespace Dumux { @@ -71,11 +69,20 @@ public: using type = CCTpfaGridVolumeVariables<Problem, VolumeVariables, enableCache>; }; -//! The global flux variables cache vector class -SET_TYPE_PROP(CCTpfaModel, GridFluxVariablesCache, CCTpfaGridFluxVariablesCache<TypeTag, GET_PROP_VALUE(TypeTag, EnableGridFluxVariablesCache)>); +//! The grid flux variables cache vector class +SET_PROP(CCTpfaModel, GridFluxVariablesCache) +{ +private: + static constexpr bool enableCache = GET_PROP_VALUE(TypeTag, EnableGridFluxVariablesCache); + using Problem = typename GET_PROP_TYPE(TypeTag, Problem); + using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); + using FluxVariablesCacheFiller = CCTpfaFluxVariablesCacheFiller<TypeTag>; +public: + using type = CCTpfaGridFluxVariablesCache<Problem, FluxVariablesCache, FluxVariablesCacheFiller, enableCache>; +}; //! The local flux variables cache vector class -SET_TYPE_PROP(CCTpfaModel, ElementFluxVariablesCache, CCTpfaElementFluxVariablesCache<TypeTag, GET_PROP_VALUE(TypeTag, EnableGridFluxVariablesCache)>); +SET_TYPE_PROP(CCTpfaModel, ElementFluxVariablesCache, typename GET_PROP_TYPE(TypeTag, GridFluxVariablesCache)::LocalView); //! Set the default for the ElementBoundaryTypes SET_TYPE_PROP(CCTpfaModel, ElementBoundaryTypes, CCElementBoundaryTypes); -- GitLab