From eb36fc2d84702cc751f2427ff79f7a8e6734b6ec Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 4 Apr 2018 14:53:47 +0200 Subject: [PATCH] [staggered] Adapt grid/element fluxvariables cache to cc and box --- .../mpfa/elementfluxvariablescache.hh | 2 +- .../tpfa/elementfluxvariablescache.hh | 1 + .../staggered/elementfluxvariablescache.hh | 82 +++++++++---------- .../staggered/freeflow/properties.hh | 1 + .../staggered/gridfluxvariablescache.hh | 60 +++++++++----- .../staggered/gridvariablestraits.hh | 19 +---- dumux/discretization/staggered/properties.hh | 11 +-- 7 files changed, 89 insertions(+), 87 deletions(-) diff --git a/dumux/discretization/cellcentered/mpfa/elementfluxvariablescache.hh b/dumux/discretization/cellcentered/mpfa/elementfluxvariablescache.hh index 37fa64a95d..6835c183e1 100644 --- a/dumux/discretization/cellcentered/mpfa/elementfluxvariablescache.hh +++ b/dumux/discretization/cellcentered/mpfa/elementfluxvariablescache.hh @@ -24,8 +24,8 @@ #ifndef DUMUX_DISCRETIZATION_CCMPFA_ELEMENT_FLUXVARSCACHE_HH #define DUMUX_DISCRETIZATION_CCMPFA_ELEMENT_FLUXVARSCACHE_HH +#include <algorithm> #include <type_traits> - #include <dune/common/exceptions.hh> namespace Dumux { diff --git a/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh b/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh index 444a8e5ae8..b93bb79ad5 100644 --- a/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh +++ b/dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh @@ -24,6 +24,7 @@ #ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH #define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH +#include <algorithm> #include <dune/common/exceptions.hh> namespace Dumux { diff --git a/dumux/discretization/staggered/elementfluxvariablescache.hh b/dumux/discretization/staggered/elementfluxvariablescache.hh index 84c5907877..e0a5274ad4 100644 --- a/dumux/discretization/staggered/elementfluxvariablescache.hh +++ b/dumux/discretization/staggered/elementfluxvariablescache.hh @@ -27,14 +27,13 @@ #include <algorithm> #include <iterator> -namespace Dumux -{ +namespace Dumux { /*! * \ingroup StaggeredDiscretization * \brief Base class for the stencil local flux variables cache for the staggered model */ -template<class FVGridGeometry, class GridFluxVariablesCache, bool EnableGridFluxVariablesCache> +template<class GridFluxVariablesCache, bool cachingEnabled> class StaggeredElementFluxVariablesCache; /*! @@ -42,40 +41,40 @@ class StaggeredElementFluxVariablesCache; * \brief Class for the stencil local flux variables cache for the staggered model. Specialization for the case of storing the fluxvars cache globally. */ -template<class FVGridGeometry, class GridFluxVariablesCache> -class StaggeredElementFluxVariablesCache<FVGridGeometry, GridFluxVariablesCache, true> +template<class GFVC> +class StaggeredElementFluxVariablesCache<GFVC, true> { - using GridView =typename FVGridGeometry::GridView; - using IndexType = typename GridView::IndexSet::IndexType; - using Element = typename GridView::template Codim<0>::Entity; - using FVElementGeometry = typename FVGridGeometry::LocalView; - using FluxVariablesCache = typename GridFluxVariablesCache::FluxVariablesCache; - 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; + StaggeredElementFluxVariablesCache(const GridFluxVariablesCache& global) : gridFluxVarsCachePtr_(&global) {} //! Specialization for the global caching being enabled - do nothing here - template<class ElementVolumeVariables> - 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 - template<class ElementVolumeVariables> - 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 - template<class ElementVolumeVariables> - 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) {} //! operators in the case of caching + template<class SubControlVolumeFace> const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const { return (*gridFluxVarsCachePtr_)[scvf.index()]; } @@ -92,24 +91,23 @@ private: * \brief Class for the stencil local flux variables cache for the staggered model. Specialization for the case of not storing the fluxvars cache globally. */ -template<class FVGridGeometry, class GridFluxVariablesCache> -class StaggeredElementFluxVariablesCache<FVGridGeometry, GridFluxVariablesCache, false> +template<class GFVC> +class StaggeredElementFluxVariablesCache<GFVC, false> { - using GridView =typename FVGridGeometry::GridView; - using IndexType = typename GridView::IndexSet::IndexType; - using Element = typename GridView::template Codim<0>::Entity; - using FVElementGeometry = typename FVGridGeometry::LocalView; - using FluxVariablesCache = typename GridFluxVariablesCache::FluxVariablesCache; - 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; + StaggeredElementFluxVariablesCache(const GridFluxVariablesCache& global) : gridFluxVarsCachePtr_(&global) {} //! This function has to be called prior to flux calculations on the element. //! Prepares the transmissibilities of the scv faces in an element. The FvGeometry is assumed to be bound. - template<class ElementVolumeVariables> - 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) { @@ -117,7 +115,7 @@ public: const auto numScvf = fvGeometry.numScvf(); fluxVarsCache_.resize(numScvf); globalScvfIndices_.resize(numScvf); - IndexType localScvfIdx = 0; + std::size_t localScvfIdx = 0; // fill the containers for (auto&& scvf : scvfs(fvGeometry)) @@ -130,8 +128,8 @@ public: //! This function is called by the StaggeredLocalResidual before flux calculations during assembly. //! Prepares the transmissibilities of the scv faces in the stencil. The FvGeometries are assumed to be bound. - template<class ElementVolumeVariables> - 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) { @@ -141,7 +139,7 @@ public: // find the number of scv faces that need to be prepared auto numScvf = fvGeometry.numScvf(); - for (IndexType localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ) + for (std::size_t localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ) { const auto& fluxVarIndicesJ = gridFluxVarsCache().problem_().model().localJacobian().assemblyMap()[globalI][localIdxJ]; numScvf += fluxVarIndicesJ.size(); @@ -150,7 +148,7 @@ public: // fill the containers with the data on the scv faces inside the actual element fluxVarsCache_.resize(numScvf); globalScvfIndices_.resize(numScvf); - IndexType localScvfIdx = 0; + std::size_t localScvfIdx = 0; for (auto&& scvf : scvfs(fvGeometry)) { fluxVarsCache_[localScvfIdx].update(gridFluxVarsCache().problem_(), element, fvGeometry, elemVolVars, scvf); @@ -159,7 +157,7 @@ public: } // add required data on the scv faces in the neighboring elements - for (IndexType localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ) + for (std::size_t localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ) { const auto& fluxVarIndicesJ = gridFluxVarsCache().problem_().model().localJacobian().assemblyMap()[globalI][localIdxJ]; const auto elementJ = fvGeometry.fvGridGeometry().element(neighborStencil[localIdxJ]); @@ -174,11 +172,11 @@ public: } } - template<class ElementVolumeVariables> - 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); @@ -188,9 +186,11 @@ public: } //! access operators in the case of no caching + template<class SubControlVolumeFace> const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } + template<class SubControlVolumeFace> FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } @@ -210,9 +210,9 @@ private: } std::vector<FluxVariablesCache> fluxVarsCache_; - std::vector<IndexType> globalScvfIndices_; + std::vector<std::size_t> globalScvfIndices_; }; -} // end namespace +} // end namespace Dumux #endif diff --git a/dumux/discretization/staggered/freeflow/properties.hh b/dumux/discretization/staggered/freeflow/properties.hh index 3916d6576c..22ba9f669d 100644 --- a/dumux/discretization/staggered/freeflow/properties.hh +++ b/dumux/discretization/staggered/freeflow/properties.hh @@ -38,6 +38,7 @@ #include <dumux/discretization/cellcentered/subcontrolvolume.hh> #include <dumux/discretization/staggered/freeflow/subcontrolvolumeface.hh> #include <dumux/discretization/staggered/fvgridgeometry.hh> +#include <dumux/discretization/staggered/fvelementgeometry.hh> #include "subcontrolvolumeface.hh" #include "connectivitymap.hh" diff --git a/dumux/discretization/staggered/gridfluxvariablescache.hh b/dumux/discretization/staggered/gridfluxvariablescache.hh index c54dc9d540..4d02b339f1 100644 --- a/dumux/discretization/staggered/gridfluxvariablescache.hh +++ b/dumux/discretization/staggered/gridfluxvariablescache.hh @@ -26,14 +26,34 @@ //! make the local view function available whenever we use this class #include <dumux/discretization/localview.hh> +#include <dumux/discretization/staggered/elementfluxvariablescache.hh> namespace Dumux { +/*! + * \ingroup StaggeredDiscretization + * \brief Traits class to be used for the StaggeredGridVFluxVariablesCache. + * \tparam P The problem type + * \tparam FVC The flux variables cache type + */ +template<class P, class FVC> +struct StaggeredDefaultGridFluxVariablesCacheTraits +{ + using Problem = P; + using FluxVariablesCache = FVC; + + template<class GridFluxVariablesCache, bool cachingEnabled> + using LocalView = StaggeredElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>; +}; + /*! * \ingroup StaggeredDiscretization * \brief Flux variables cache class for staggered models */ -template<class FVGridGeometry, class Traits, bool EnableGridFluxVariablesCache> +template<class Problem, + class FluxVariablesCache, + bool cachingEnabled = false, + class Traits = StaggeredDefaultGridFluxVariablesCacheTraits<Problem, FluxVariablesCache> > class StaggeredGridFluxVariablesCache; /*! @@ -41,26 +61,26 @@ class StaggeredGridFluxVariablesCache; * \brief Flux variables cache class for staggered models. Specialization in case of storing the flux cache. */ -template<class FVGridGeometry, class Traits> -class StaggeredGridFluxVariablesCache<FVGridGeometry, Traits, true> +template<class P, class FVC, class Traits> +class StaggeredGridFluxVariablesCache<P, FVC, true, Traits> { - using ThisType = StaggeredGridFluxVariablesCache<FVGridGeometry, Traits, true>; + using ThisType = StaggeredGridFluxVariablesCache<P, FVC, true, Traits>; using Problem = typename Traits::Problem; - using IndexType = typename FVGridGeometry::GridView::IndexSet::IndexType; public: - //! export the type of the flux variables cache + //! export the flux variable cache type using FluxVariablesCache = typename Traits::FluxVariablesCache; - //! export the type of the local view - using LocalView = typename Traits::template LocalView<FVGridGeometry, ThisType, true>; //! 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>; + StaggeredGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {} // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces - template<class GridVolumeVariables, class SolutionVector> + template<class FVGridGeometry, class GridVolumeVariables, class SolutionVector> void update(const FVGridGeometry& fvGridGeometry, const GridVolumeVariables& gridVolVars, const SolutionVector& sol, @@ -87,18 +107,17 @@ public: { return *problemPtr_; } // access operators in the case of caching - const FluxVariablesCache& operator [](IndexType scvfIdx) const + const FluxVariablesCache& operator [](std::size_t scvfIdx) const { return fluxVarsCache_[scvfIdx]; } - FluxVariablesCache& operator [](IndexType scvfIdx) + FluxVariablesCache& operator [](std::size_t scvfIdx) { return fluxVarsCache_[scvfIdx]; } private: - const Problem* problemPtr_; std::vector<FluxVariablesCache> fluxVarsCache_; - std::vector<IndexType> globalScvfIndices_; + std::vector<std::size_t> globalScvfIndices_; }; /*! @@ -106,20 +125,21 @@ private: * \brief Flux variables cache class for staggered models. Specialization in case of not storing the flux cache. */ -template<class FVGridGeometry, class Traits> -class StaggeredGridFluxVariablesCache<FVGridGeometry, Traits, false> +template<class P, class FVC, class Traits> +class StaggeredGridFluxVariablesCache<P, FVC, false, Traits> { - using ThisType = StaggeredGridFluxVariablesCache<FVGridGeometry, Traits, false>; + using ThisType = StaggeredGridFluxVariablesCache<P, FVC, false, Traits>; using Problem = typename Traits::Problem; public: - //! export the type of the flux variables cache + //! export the flux variable cache type using FluxVariablesCache = typename Traits::FluxVariablesCache; - //! export the type of the local view - using LocalView = typename Traits::template LocalView<FVGridGeometry, ThisType, false>; //! make it possible to query if caching is enabled - static constexpr bool cachingEnabled = false; + static constexpr bool cachingEnabled = true; + + //! export the type of the local view + using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; // When global flux variables caching is disabled, we don't need to update the cache void update(Problem& problem) diff --git a/dumux/discretization/staggered/gridvariablestraits.hh b/dumux/discretization/staggered/gridvariablestraits.hh index c94a3b57ed..560759993a 100644 --- a/dumux/discretization/staggered/gridvariablestraits.hh +++ b/dumux/discretization/staggered/gridvariablestraits.hh @@ -24,6 +24,8 @@ #ifndef DUMUX_DISCRETIZATION_STAGGERED_GRID_VARIABLES_TRAITS_HH #define DUMUX_DISCRETIZATION_STAGGERED_GRID_VARIABLES_TRAITS_HH +#include <dumux/discretization/staggered/elementfacevariables.hh> +#include <dumux/discretization/staggered/elementvolumevariables.hh> namespace Dumux { @@ -63,23 +65,6 @@ struct StaggeredGridVolumeVariablesTraits using VolumeVariables = VV; }; -/*! - * \ingroup StaggeredDiscretization - * \brief Traits class to be used for the StaggeredGridVFluxVariablesCache. - * - * \tparam FVC The flux variables cache type - * \tparam P The problem type - */ -template<class FVC, class P> -struct StaggeredGridFluxVariablesCacheTraits -{ - template<class FVGridGeometry, class StaggeredGridFluxVariablesCache, bool enableCache> - using LocalView = StaggeredElementFluxVariablesCache<FVGridGeometry, StaggeredGridFluxVariablesCache, enableCache>; - - using FluxVariablesCache = FVC; - using Problem = P; -}; - } // end namespace Dumux #endif diff --git a/dumux/discretization/staggered/properties.hh b/dumux/discretization/staggered/properties.hh index 1d1322c223..397fe58fb7 100644 --- a/dumux/discretization/staggered/properties.hh +++ b/dumux/discretization/staggered/properties.hh @@ -39,14 +39,10 @@ #include <dumux/discretization/cellcentered/subcontrolvolume.hh> #include <dumux/discretization/staggered/gridvariables.hh> #include <dumux/discretization/staggered/gridfluxvariablescache.hh> -#include <dumux/discretization/staggered/elementfluxvariablescache.hh> #include <dumux/discretization/staggered/gridvolumevariables.hh> -#include <dumux/discretization/staggered/elementvolumevariables.hh> #include <dumux/discretization/staggered/fvgridgeometry.hh> -#include <dumux/discretization/staggered/fvelementgeometry.hh> #include <dumux/discretization/staggered/gridfacevariables.hh> #include <dumux/discretization/staggered/facesolution.hh> -#include <dumux/discretization/staggered/elementfacevariables.hh> #include <dumux/discretization/staggered/subcontrolvolumeface.hh> #include <dune/istl/multitypeblockvector.hh> @@ -104,12 +100,11 @@ public: SET_PROP(StaggeredModel, GridFluxVariablesCache) { private: - using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); - using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); + static constexpr auto enableCache = GET_PROP_VALUE(TypeTag, EnableGridFluxVariablesCache); using Problem = typename GET_PROP_TYPE(TypeTag, Problem); - using Traits = StaggeredGridFluxVariablesCacheTraits<FluxVariablesCache, Problem>; + using FluxVariablesCache = typename GET_PROP_TYPE(TypeTag, FluxVariablesCache); public: - using type = StaggeredGridFluxVariablesCache<FVGridGeometry, Traits, GET_PROP_VALUE(TypeTag, EnableGridFluxVariablesCache)>; + using type = StaggeredGridFluxVariablesCache<Problem, FluxVariablesCache, enableCache>; }; //! Set the face solution type -- GitLab