diff --git a/dumux/common/defaultmappertraits.hh b/dumux/common/defaultmappertraits.hh index 5c485118a4ed16db45d72492b3254f2aa2f069c5..944ff031a310a6a790aef950e603bfb08423cf25 100644 --- a/dumux/common/defaultmappertraits.hh +++ b/dumux/common/defaultmappertraits.hh @@ -28,11 +28,13 @@ namespace Dumux { -template <class GridView> +template <class GridView, + class EM = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>, + class VM = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>> struct DefaultMapperTraits { - using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; - using VertexMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + using ElementMapper = EM; + using VertexMapper = VM; }; } // namespace Dumux diff --git a/dumux/common/geometry/geometricentityset.hh b/dumux/common/geometry/geometricentityset.hh index 9adfa846962c6a62864ce0bd0c9fb67fb054ae05..fbcedf3e46b353e1a57ad0358714eea775208542 100644 --- a/dumux/common/geometry/geometricentityset.hh +++ b/dumux/common/geometry/geometricentityset.hh @@ -36,11 +36,9 @@ namespace Dumux { * \note This can be used e.g. to contruct a bounding box volume hierarchy of a grid * It defines the minimum requirement for such a set */ -template <class GridView, int codim = 0> +template <class GridView, int codim = 0, class Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>> class GridViewGeometricEntitySet { - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; - public: using Entity = typename GridView::template Codim<codim>::Entity; diff --git a/dumux/common/reorderingdofmapper.hh b/dumux/common/reorderingdofmapper.hh index 56ed39360e811a042390def6d3916d8f67891f8f..64b290fab55785bb3d98c1b0d7853c7bcb0e49d1 100644 --- a/dumux/common/reorderingdofmapper.hh +++ b/dumux/common/reorderingdofmapper.hh @@ -23,41 +23,43 @@ * \brief An SCSG element mapper that sorts the indices in order to optimize the matrix sparsity pattern * \note The reordering needs the SCOTCH library */ -#ifndef DUMUX_REORDERING_DOF_MAPPER_HH -#define DUMUX_REORDERING_DOF_MAPPER_HH +#ifndef DUMUX_COMMON_REORDERING_DOF_MAPPER_HH +#define DUMUX_COMMON_REORDERING_DOF_MAPPER_HH + +#if HAVE_PTSCOTCH #include <dune/common/timer.hh> #include <dune/grid/common/mapper.hh> #include <dumux/linear/scotchbackend.hh> -namespace Dumux -{ +namespace Dumux { /*! * \ingroup Common * \brief An SCSG element mapper that sorts the indices in order to optimize the matrix sparsity pattern * \note The reordering needs the SCOTCH library */ -template<class GridView, int codimension> +template<class GridView> class ReorderingDofMapper -: public Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView, codimension>, typename GridView::IndexSet::IndexType> +: public Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView>, typename GridView::IndexSet::IndexType> { using Index = typename GridView::IndexSet::IndexType; - using ParentType = typename Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView, codimension>, Index>; + using ParentType = typename Dune::Mapper<typename GridView::Grid, ReorderingDofMapper<GridView>, Index>; using Element = typename GridView::template Codim<0>::Entity; - public: /*! * \brief Construct mapper from grid and one of its index sets. * \param gridView A Dune GridView object. + * \param layout a layout object (we just check whether it contains elements -> element mapper, else it's a vertex mapper) */ - ReorderingDofMapper (const GridView& gridView) - : gridView_(gridView), - indexSet_(gridView.indexSet()) + template<class Layout> + ReorderingDofMapper (const GridView& gridView, Layout&& layout) + : gridView_(gridView) + , indexSet_(gridView.indexSet()) + , codimension_(layout(indexSet_.types(0)[0], GridView::dimension) ? 0 : GridView::dimension) { - static_assert(codimension == 0 || codimension == GridView::dimension, "The reordering dofMapper is only implemented for element or vertex dofs"); update(); } @@ -97,7 +99,7 @@ public: */ std::size_t size () const { - return indexSet_.size(codimension); + return indexSet_.size(codimension_); } /** @brief Returns true if the entity is contained in the index set @@ -138,7 +140,7 @@ public: std::vector<std::vector<Index>> graph(size()); // dofs on element centers (cell-centered methods) - if (codimension == 0) + if (codimension_ == 0) { for (const auto& element : elements(gridView_)) { @@ -156,9 +158,9 @@ public: for (const auto& element : elements(gridView_)) { auto eIdx = indexSet_.index(element); - for (int vIdxLocal = 0; vIdxLocal < element.subEntities(codimension); ++vIdxLocal) + for (int vIdxLocal = 0; vIdxLocal < element.subEntities(codimension_); ++vIdxLocal) { - auto vIdxGlobal = indexSet_.subIndex(element, vIdxLocal, codimension); + auto vIdxGlobal = indexSet_.subIndex(element, vIdxLocal, codimension_); graph[vIdxGlobal].push_back(eIdx); } } @@ -173,18 +175,21 @@ private: // GridView is needed to keep the IndexSet valid const GridView gridView_; const typename GridView::IndexSet& indexSet_; + const int codimension_; // the map resulting from the reordering std::vector<int> permutation_; }; -//! Redordering dof mapper for vertex-centered methods, box method -template<class GridView> -using BoxReorderingDofMapper = ReorderingDofMapper<GridView, GridView::dimension>; +} // end namespace Dumux -//! Reordering dof mapper for the cell-centered methods -template<class GridView> -using CCReorderingDofMapper = ReorderingDofMapper<GridView, 0>; +#else +#warning "PTSCOTCH was not found on your system. Dumux::ReorderingDofMapper needs it to work -> fallback to MCMGMapper without reordering!" +#include <dune/grid/common/mcmgmapper.hh> +namespace Dumux { +template<class GridView> +using ReorderingDofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; } // end namespace Dumux -#endif +#endif // HAVE_PTSCOTCH +#endif // DUMUX_COMMON_REORDERING_DOF_MAPPER_HH diff --git a/dumux/discretization/basefvgridgeometry.hh b/dumux/discretization/basefvgridgeometry.hh index 7d50774734d35794fc234c09988eed790f7fe57b..4a6a378a5f71950926e46803f9b245295f427427 100644 --- a/dumux/discretization/basefvgridgeometry.hh +++ b/dumux/discretization/basefvgridgeometry.hh @@ -46,7 +46,7 @@ template<class Impl, class GV, class Traits> class BaseFVGridGeometry { using ElementMap = EntityMap<GV, 0>; - using ElementSet = GridViewGeometricEntitySet<GV, 0>; + using ElementSet = GridViewGeometricEntitySet<GV, 0, typename Traits::ElementMapper>; using BoundingBoxTree = Dumux::BoundingBoxTree<ElementSet>; static const int dim = GV::dimension; diff --git a/dumux/discretization/box/fvgridgeometry.hh b/dumux/discretization/box/fvgridgeometry.hh index 3736f7781dd46d03106913b1541766481deec3a5..1df7688e820701b2670a5cd5546782df42604edd 100644 --- a/dumux/discretization/box/fvgridgeometry.hh +++ b/dumux/discretization/box/fvgridgeometry.hh @@ -45,9 +45,9 @@ namespace Dumux { * Defines the scv and scvf types and the mapper types * \tparam the grid view type */ -template<class GridView> +template<class GridView, class MapperTraits = DefaultMapperTraits<GridView>> struct BoxDefaultGridGeometryTraits -: public DefaultMapperTraits<GridView> +: public MapperTraits { using SubControlVolume = BoxSubControlVolume<GridView>; using SubControlVolumeFace = BoxSubControlVolumeFace<GridView>; diff --git a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh index bd874db720f736153ee6d386cab5af937ebe0db7..9cbf47d78debdff59d75885e42885efafe066730 100644 --- a/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh +++ b/dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh @@ -44,9 +44,9 @@ namespace Dumux { * Defines the scv and scvf types and the mapper types * \tparam the grid view type */ -template<class GridView> +template<class GridView, class MapperTraits = DefaultMapperTraits<GridView>> struct CCTpfaDefaultGridGeometryTraits -: public DefaultMapperTraits<GridView> +: public MapperTraits { using SubControlVolume = CCSubControlVolume<GridView>; using SubControlVolumeFace = CCTpfaSubControlVolumeFace<GridView>; diff --git a/dumux/discretization/staggered/freeflow/fvgridgeometrytraits.hh b/dumux/discretization/staggered/freeflow/fvgridgeometrytraits.hh index 942a2d5fd16a720bedc4495c25e5ae5405058ddc..6499c59498870b930658154db262bd7c9017633d 100644 --- a/dumux/discretization/staggered/freeflow/fvgridgeometrytraits.hh +++ b/dumux/discretization/staggered/freeflow/fvgridgeometrytraits.hh @@ -40,8 +40,9 @@ namespace Dumux { * \ingroup StaggeredDiscretization * \brief Default traits for the finite volume grid geometry. */ -template<class GridView> -struct StaggeredFreeFlowDefaultFVGridGeometryTraits : public DefaultMapperTraits<GridView> +template<class GridView, class MapperTraits = DefaultMapperTraits<GridView>> +struct StaggeredFreeFlowDefaultFVGridGeometryTraits +: public MapperTraits { using SubControlVolume = CCSubControlVolume<GridView>; using SubControlVolumeFace = FreeFlowStaggeredSubControlVolumeFace<GridView>; diff --git a/dumux/io/vtkfunction.hh b/dumux/io/vtkfunction.hh index 1cc3e563ca6d0bd637baaee4a40d84eaf788d7d2..f8272b6423aaba368753b518357d8e0aef5b9b57 100644 --- a/dumux/io/vtkfunction.hh +++ b/dumux/io/vtkfunction.hh @@ -41,14 +41,13 @@ namespace Vtk { * \tparam GridView The Dune grid view type * \tparam F The field type (either vector of scalars or vectors) */ -template <typename GridView, typename F> +template <typename GridView, typename Mapper, typename F> struct VectorP0VTKFunction : Dune::VTKFunction<GridView> { enum { dim = GridView::dimension }; using ctype = typename GridView::ctype; using Element = typename GridView::template Codim<0>::Entity; - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; public: //! return number of components @@ -95,14 +94,13 @@ private: * \tparam GridView The Dune grid view type * \tparam F The field type (either vector of scalars or vectors) */ -template <typename GridView, typename F> +template <typename GridView, typename Mapper, typename F> struct VectorP1VTKFunction : Dune::VTKFunction<GridView> { enum { dim = GridView::dimension }; using ctype = typename GridView::ctype; using Element = typename GridView::template Codim<0>::Entity; - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; public: //! return number of components @@ -159,14 +157,13 @@ private: * \tparam GridView The Dune grid view type * \tparam F The field type (either vector of scalars or vectors) */ -template <typename GridView, typename F> +template <typename GridView, typename Mapper, typename F> struct VectorP1NonConformingVTKFunction : Dune::VTKFunction<GridView> { enum { dim = GridView::dimension }; using ctype = typename GridView::ctype; using Element = typename GridView::template Codim<0>::Entity; - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; public: //! return number of components @@ -243,12 +240,12 @@ public: if (codim == GridView::dimension) { if (dm == Dune::VTK::conforming) - field_ = std::make_shared< VectorP1VTKFunction<GridView, F> >(gridView, mapper, f, name, numComp); + field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f, name, numComp); else - field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, F> >(gridView, mapper, f, name, numComp); + field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f, name, numComp); } else if (codim == 0) - field_ = std::make_shared< VectorP0VTKFunction<GridView, F> >(gridView, mapper, f, name, numComp); + field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f, name, numComp); else DUNE_THROW(Dune::NotImplemented, "Only element or vertex quantities allowed."); } diff --git a/dumux/io/vtkoutputmodule.hh b/dumux/io/vtkoutputmodule.hh index da5cb25c25e4050995c44f9c03f81e6c6bf683a2..403cf72fe53eae4b6ef9c0ecbcaf09271ae24a56 100644 --- a/dumux/io/vtkoutputmodule.hh +++ b/dumux/io/vtkoutputmodule.hh @@ -358,7 +358,8 @@ private: if (isBox) { for (std::size_t i = 0; i < volVarScalarDataInfo_.size(); ++i) - sequenceWriter_.addVertexData( volVarScalarData[i], volVarScalarDataInfo_[i].name ); + sequenceWriter_.addVertexData( Field(gridGeom_.gridView(), gridGeom_.vertexMapper(), volVarScalarData[i], + volVarScalarDataInfo_[i].name, /*numComp*/1, /*codim*/dim).get() ); for (std::size_t i = 0; i < volVarVectorDataInfo_.size(); ++i) sequenceWriter_.addVertexData( Field(gridGeom_.gridView(), gridGeom_.vertexMapper(), volVarVectorData[i], volVarVectorDataInfo_[i].name, /*numComp*/dimWorld, /*codim*/dim).get() ); @@ -366,7 +367,8 @@ private: else { for (std::size_t i = 0; i < volVarScalarDataInfo_.size(); ++i) - sequenceWriter_.addCellData( volVarScalarData[i], volVarScalarDataInfo_[i].name ); + sequenceWriter_.addCellData( Field(gridGeom_.gridView(), gridGeom_.elementMapper(), volVarScalarData[i], + volVarScalarDataInfo_[i].name, /*numComp*/1, /*codim*/0).get() ); for (std::size_t i = 0; i < volVarVectorDataInfo_.size(); ++i) sequenceWriter_.addCellData( Field(gridGeom_.gridView(), gridGeom_.elementMapper(), volVarVectorData[i], volVarVectorDataInfo_[i].name, /*numComp*/dimWorld, /*codim*/0).get() ); diff --git a/dumux/porousmediumflow/boxdfm/fvgridgeometry.hh b/dumux/porousmediumflow/boxdfm/fvgridgeometry.hh index 908f720e08057fa8c4d719c571019c31eaf2ac00..a218adac3998a13e2182b9aef9821e5ffaf2fe05 100644 --- a/dumux/porousmediumflow/boxdfm/fvgridgeometry.hh +++ b/dumux/porousmediumflow/boxdfm/fvgridgeometry.hh @@ -49,9 +49,9 @@ namespace Dumux { * Defines the scv and scvf types and the mapper types * \tparam the grid view type */ -template<class GridView> +template<class GridView, class MapperTraits = DefaultMapperTraits<GridView>> struct BoxDfmDefaultGridGeometryTraits -: public DefaultMapperTraits<GridView> +: public MapperTraits { using SubControlVolume = BoxDfmSubControlVolume<GridView>; using SubControlVolumeFace = BoxDfmSubControlVolumeFace<GridView>; diff --git a/test/porousmediumflow/1p/implicit/tubesproblem.hh b/test/porousmediumflow/1p/implicit/tubesproblem.hh index 7a25c350d0bf6b7e9d44d938568e384bb2d48afb..b3832cdf294488f3728c76016144f603d2ef6025 100644 --- a/test/porousmediumflow/1p/implicit/tubesproblem.hh +++ b/test/porousmediumflow/1p/implicit/tubesproblem.hh @@ -32,6 +32,7 @@ #include <dune/foamgrid/foamgrid.hh> #endif +#include <dumux/common/reorderingdofmapper.hh> #include <dumux/discretization/cellcentered/tpfa/properties.hh> #include <dumux/discretization/box/properties.hh> #include <dumux/discretization/methods.hh> @@ -59,6 +60,35 @@ NEW_TYPE_TAG(TubesTestBoxTypeTag, INHERITS_FROM(BoxModel, TubesTestTypeTag)); SET_TYPE_PROP(TubesTestTypeTag, Grid, Dune::FoamGrid<1, 3>); #endif +// if we have pt scotch use the reordering dof mapper to optimally sort the dofs (cc) +SET_PROP(TubesTestCCTpfaTypeTag, FVGridGeometry) +{ +private: + static constexpr bool enableCache = GET_PROP_VALUE(TypeTag, EnableFVGridGeometryCache); + using GridView = typename GET_PROP_TYPE(TypeTag, GridView); + + using ElementMapper = ReorderingDofMapper<GridView>; + using VertexMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + using MapperTraits = DefaultMapperTraits<GridView, ElementMapper, VertexMapper>; +public: + using type = CCTpfaFVGridGeometry<GridView, enableCache, CCTpfaDefaultGridGeometryTraits<GridView, MapperTraits>>; +}; + +// if we have pt scotch use the reordering dof mapper to optimally sort the dofs (box) +SET_PROP(TubesTestBoxTypeTag, FVGridGeometry) +{ +private: + static constexpr bool enableCache = GET_PROP_VALUE(TypeTag, EnableFVGridGeometryCache); + using GridView = typename GET_PROP_TYPE(TypeTag, GridView); + using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); + + using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + using VertexMapper = ReorderingDofMapper<GridView>; + using MapperTraits = DefaultMapperTraits<GridView, ElementMapper, VertexMapper>; +public: + using type = BoxFVGridGeometry<Scalar, GridView, enableCache, BoxDefaultGridGeometryTraits<GridView, MapperTraits>>; +}; + // Set the problem property SET_TYPE_PROP(TubesTestTypeTag, Problem, TubesTestProblem<TypeTag>);