diff --git a/dumux/discretization/staggered/elementvolumevariables.hh b/dumux/discretization/staggered/elementvolumevariables.hh index fbce3036e97979e50fcda6ba2b26d0d376ae75e5..885a47a6363adf097c36d31e94e7987844b3a717 100644 --- a/dumux/discretization/staggered/elementvolumevariables.hh +++ b/dumux/discretization/staggered/elementvolumevariables.hh @@ -34,7 +34,7 @@ namespace Dumux { * \ingroup StaggeredDiscretization * \brief Base class for the element volume variables vector for the staggered model */ -template<class FVGridGeometry, class GridVolumeVariables, bool enableGridVolVarsCache> +template<class GVV, bool cachingEnabled> class StaggeredElementVolumeVariables {}; @@ -43,43 +43,41 @@ class StaggeredElementVolumeVariables * \brief Class for the element volume variables vector for the staggered model. Specialization in case the volume variables are stored globally. */ -template<class FVGridGeometry, class GridVolumeVariables> -class StaggeredElementVolumeVariables<FVGridGeometry, GridVolumeVariables, /*enableGridVolVarsCache*/true> +template<class GVV> +class StaggeredElementVolumeVariables<GVV, /*cachingEnabled*/true> { - using GridView = typename FVGridGeometry::GridView; - using FVElementGeometry = typename FVGridGeometry::LocalView; - using VolumeVariables = typename GridVolumeVariables::VolumeVariables; - using SubControlVolume = typename FVElementGeometry::SubControlVolume; - using IndexType = typename GridView::IndexSet::IndexType; - - using Element = typename GridView::template Codim<0>::Entity; - public: + //! export type of the grid volume variables + using GridVolumeVariables = GVV; + + //! export type of the volume variables + using VolumeVariables = typename GridVolumeVariables::VolumeVariables; //! Constructor StaggeredElementVolumeVariables(const GridVolumeVariables& gridVolVars) : gridVolVarsPtr_(&gridVolVars) {} //! operator for the access with an scv + template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0> const VolumeVariables& operator [](const SubControlVolume& scv) const { return gridVolVars().volVars(scv.dofIndex()); } //! operator for the access with an index //! needed for Staggered methods for the access to the boundary volume variables - const VolumeVariables& operator [](const IndexType scvIdx) const + const VolumeVariables& operator [](const std::size_t scvIdx) const { return gridVolVars().volVars(scvIdx); } //! For compatibility reasons with the case of not storing the vol vars. //! function to be called before assembling an element, preparing the vol vars within the stencil - template<class SolutionVector> - void bind(const Element& element, + template<class FVElementGeometry, class SolutionVector> + void bind(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const SolutionVector& sol) {} //! function to prepare the vol vars within the element - template<class SolutionVector> - void bindElement(const Element& element, + template<class FVElementGeometry, class SolutionVector> + void bindElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const SolutionVector& sol) {} @@ -98,21 +96,17 @@ private: * \brief Class for the element volume variables vector for the staggered model. Specialization in case the volume variables are not stored globally. */ -template<class FVGridGeometry, class GridVolumeVariables> -class StaggeredElementVolumeVariables<FVGridGeometry, GridVolumeVariables, /*enableGridVolVarsCache*/false> +template<class GVV> +class StaggeredElementVolumeVariables<GVV, /*cachingEnabled*/false> { - using CellCenterPrimaryVariables = typename GridVolumeVariables::CellCenterPrimaryVariables; - using GridView = typename FVGridGeometry::GridView; - using FVElementGeometry = typename FVGridGeometry::LocalView; - using VolumeVariables = typename GridVolumeVariables::VolumeVariables; - using SubControlVolume = typename FVElementGeometry::SubControlVolume; - using IndexType = typename GridView::IndexSet::IndexType; - using Indices = typename GridVolumeVariables::Indices; - - using Element = typename GridView::template Codim<0>::Entity; - static constexpr auto cellCenterIdx = FVGridGeometry::cellCenterIdx(); + using Indices = typename GVV::Indices; //TODO: get them out of the volvars public: + //! export type of the grid volume variables + using GridVolumeVariables = GVV; + + //! export type of the volume variables + using VolumeVariables = typename GridVolumeVariables::VolumeVariables; //! Constructor StaggeredElementVolumeVariables(const GridVolumeVariables& gridVolVars) @@ -120,8 +114,8 @@ public: //! Binding of an element, prepares the volume variables within the element stencil //! called by the local jacobian to prepare element assembly - template<class SolutionVector> - void bind(const Element& element, + template<class FVElementGeometry, class SolutionVector> + void bind(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const SolutionVector& sol) { @@ -131,6 +125,7 @@ public: const auto& fvGridGeometry = fvGeometry.fvGridGeometry(); const auto globalI = fvGridGeometry.elementMapper().index(element); const auto map = fvGridGeometry.connectivityMap(); + constexpr auto cellCenterIdx = FVElementGeometry::FVGridGeometry::cellCenterIdx(); const auto& connectivityMapI = map(cellCenterIdx, cellCenterIdx, globalI); const auto numDofs = connectivityMapI.size(); @@ -141,6 +136,8 @@ public: volVarIndices_.resize(numDofs); int localIdx = 0; + using CellCenterPrimaryVariables = typename SolutionVector::value_type; + // Update the volume variables of the element at hand and the neighboring elements for (auto globalJ : connectivityMapI) { @@ -196,8 +193,8 @@ public: //! Binding of an element, prepares only the volume variables of the element. //! Specialization for Staggered models - template<class SolutionVector> - void bindElement(const Element& element, + template<class FVElementGeometry, class SolutionVector> + void bindElement(const typename FVElementGeometry::FVGridGeometry::GridView::template Codim<0>::Entity& element, const FVElementGeometry& fvGeometry, const SolutionVector& sol) { @@ -209,7 +206,9 @@ public: // update the volume variables of the element auto&& scv = fvGeometry.scv(eIdx); + using CellCenterPrimaryVariables = typename SolutionVector::value_type; CellCenterPrimaryVariables priVars(0.0); + constexpr auto cellCenterIdx = FVElementGeometry::FVGridGeometry::cellCenterIdx(); priVars = sol[cellCenterIdx][eIdx]; auto elemSol = elementSolution<FVElementGeometry>(std::move(priVars)); volumeVariables_[0].update(elemSol, @@ -220,19 +219,21 @@ public: } //! const operator for the access with an scv + template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0> const VolumeVariables& operator [](const SubControlVolume& scv) const { return volumeVariables_[getLocalIdx_(scv.dofIndex())]; } //! operator for the access with an scv + template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0> VolumeVariables& operator [](const SubControlVolume& scv) { return volumeVariables_[getLocalIdx_(scv.dofIndex())]; } //! const operator for the access with an index - const VolumeVariables& operator [](IndexType scvIdx) const + const VolumeVariables& operator [](std::size_t scvIdx) const { return volumeVariables_[getLocalIdx_(scvIdx)]; } //! operator for the access with an index - VolumeVariables& operator [](IndexType scvIdx) + VolumeVariables& operator [](std::size_t scvIdx) { return volumeVariables_[getLocalIdx_(scvIdx)]; } //! The global volume variables object we are a restriction of @@ -256,10 +257,10 @@ private: return std::distance(volVarIndices_.begin(), it); } - std::vector<IndexType> volVarIndices_; + std::vector<std::size_t> volVarIndices_; std::vector<VolumeVariables> volumeVariables_; }; -} // end namespace +} // end namespace Dumux #endif diff --git a/dumux/discretization/staggered/gridvariablestraits.hh b/dumux/discretization/staggered/gridvariablestraits.hh index 560759993a880a263f72f0954886909bbceaaa4d..90f1762aadf3895b67759c8e6a6e9a27f54ea158 100644 --- a/dumux/discretization/staggered/gridvariablestraits.hh +++ b/dumux/discretization/staggered/gridvariablestraits.hh @@ -50,19 +50,19 @@ struct StaggeredGridFaceVariablesTraits * \ingroup StaggeredDiscretization * \brief Traits class to be used for the StaggeredGridVolumeVariables. * - * \tparam VV The volume variables type * \tparam P The problem type + * \tparam VV The volume variables type * \tparam I The indices type */ -template<class VV, class P, class PV, class I> +template<class P, class VV, class I> struct StaggeredGridVolumeVariablesTraits { - template<class FVGridGeometry, class GridVolumeVariables, bool enableCache> - using LocalView = StaggeredElementVolumeVariables<FVGridGeometry, GridVolumeVariables, enableCache>; + template<class GridVolumeVariables, bool enableCache> + using LocalView = StaggeredElementVolumeVariables<GridVolumeVariables, enableCache>; - using Indices = I; using Problem = P; using VolumeVariables = VV; + using Indices = I; }; } // end namespace Dumux diff --git a/dumux/discretization/staggered/gridvolumevariables.hh b/dumux/discretization/staggered/gridvolumevariables.hh index 218b9997d466cd92d53369aa82093b2721c3b26f..d1f2716aed0e1a9a32368c9ba09eb3fc73abf618 100644 --- a/dumux/discretization/staggered/gridvolumevariables.hh +++ b/dumux/discretization/staggered/gridvolumevariables.hh @@ -36,7 +36,7 @@ namespace Dumux { * \ingroup StaggeredDiscretization * \brief Grid volume variables class for staggered models */ -template<class FVGridGeometry, class Traits, bool enableGridVolVarsCache> +template<class Traits, bool cachingEnabled> class StaggeredGridVolumeVariables; /*! @@ -44,29 +44,29 @@ class StaggeredGridVolumeVariables; * \brief Grid volume variables class for staggered models. Specialization in case of storing the volume variables */ -template<class FVGridGeometry, class Traits> -class StaggeredGridVolumeVariables<FVGridGeometry, Traits, /*enableGridVolVarsCache*/true> +template<class Traits> +class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/true> { - using ThisType = StaggeredGridVolumeVariables<FVGridGeometry, Traits, true>; + using ThisType = StaggeredGridVolumeVariables<Traits, true>; using Problem = typename Traits::Problem; - using FVElementGeometry = typename FVGridGeometry::LocalView; - using SubControlVolume = typename FVElementGeometry::SubControlVolume; - using Indices = typename Traits::Indices; - using IndexType = typename FVGridGeometry::GridView::IndexSet::IndexType; public: + //! export the type of the indices TODO: get them out of the volvars + using Indices = typename Traits::Indices; + //! export the type of the VolumeVariables using VolumeVariables = typename Traits::VolumeVariables; - //! 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>; + StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {} //! Update all volume variables - template<class SolutionVector> + template<class FVGridGeometry, class SolutionVector> void update(const FVGridGeometry& fvGridGeometry, const SolutionVector& sol) { using CellCenterPrimaryVariables = typename SolutionVector::value_type; @@ -82,7 +82,7 @@ public: for (auto&& scv : scvs(fvGeometry)) { CellCenterPrimaryVariables priVars = sol[scv.dofIndex()]; - auto elemSol = elementSolution<FVElementGeometry>(std::move(priVars)); + auto elemSol = elementSolution<typename FVGridGeometry::LocalView>(std::move(priVars)); volumeVariables_[scv.dofIndex()].update(elemSol, problem(), element, scv); } @@ -111,21 +111,23 @@ public: if(eqIdx == Indices::pressureIdx) DUNE_THROW(Dune::InvalidStateException, "Face at: " << scvf.center() << " has neither Dirichlet nor Neumann BC."); } - auto elemSol = elementSolution<FVElementGeometry>(std::move(boundaryPriVars)); + auto elemSol = elementSolution<typename FVGridGeometry::LocalView>(std::move(boundaryPriVars)); volumeVariables_[scvf.outsideScvIdx()].update(elemSol, problem(), element, insideScv); } } } - const VolumeVariables& volVars(const IndexType scvIdx) const + const VolumeVariables& volVars(const std::size_t scvIdx) const { return volumeVariables_[scvIdx]; } - VolumeVariables& volVars(const IndexType scvIdx) + VolumeVariables& volVars(const std::size_t scvIdx) { return volumeVariables_[scvIdx]; } + template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0> const VolumeVariables& volVars(const SubControlVolume& scv) const { return volumeVariables_[scv.dofIndex()]; } + template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0> VolumeVariables& volVars(const SubControlVolume& scv) { return volumeVariables_[scv.dofIndex()]; } @@ -143,24 +145,25 @@ private: * \brief Grid volume variables class for staggered models. Specialization in case of not storing the volume variables */ -template<class FVGridGeometry, class Traits> -class StaggeredGridVolumeVariables<FVGridGeometry, Traits, /*enableGridVolVarsCache*/false> +template<class Traits> +class StaggeredGridVolumeVariables<Traits, /*cachingEnabled*/false> { - using ThisType = StaggeredGridVolumeVariables<FVGridGeometry, Traits, false>; + using ThisType = StaggeredGridVolumeVariables<Traits, false>; using Problem = typename Traits::Problem; public: //! export the type of the VolumeVariables using VolumeVariables = typename Traits::VolumeVariables; - //! 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 = false; + //! export the type of the local view + using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; + StaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {} - template<class SolutionVector> + template<class FVGridGeometry, class SolutionVector> void update(const FVGridGeometry& fvGridGeometry, const SolutionVector& sol) {} const Problem& problem() const diff --git a/dumux/discretization/staggered/properties.hh b/dumux/discretization/staggered/properties.hh index 397fe58fb7811469a06110c6a1ae3359a982d491..a3291223bc4dd8818b4277f33e27e1f573e44a26 100644 --- a/dumux/discretization/staggered/properties.hh +++ b/dumux/discretization/staggered/properties.hh @@ -85,15 +85,15 @@ private: using CellCenterPrimaryVariables = typename GET_PROP_TYPE(TypeTag, CellCenterPrimaryVariables); using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables); using FVGridGeometry = typename GET_PROP_TYPE(TypeTag, FVGridGeometry); - using Indices = typename GET_PROP_TYPE(TypeTag, Indices); + using Indices = typename GET_PROP_TYPE(TypeTag, Indices); // TODO extract indices from volumevariables using Problem = typename GET_PROP_TYPE(TypeTag, Problem); static constexpr auto enableCache = GET_PROP_VALUE(TypeTag, EnableGridVolumeVariablesCache); - using Traits = StaggeredGridVolumeVariablesTraits<VolumeVariables, Problem, CellCenterPrimaryVariables, Indices>; + using Traits = StaggeredGridVolumeVariablesTraits<Problem, VolumeVariables, Indices>; // TODO extract indices from volumevariables public: - using type = StaggeredGridVolumeVariables<FVGridGeometry, Traits, enableCache>; + using type = StaggeredGridVolumeVariables<Traits, enableCache>; }; //! Set the global flux variables cache vector class