// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #ifndef DUNE_MULTIMESH_GRIDVIEW_HH #define DUNE_MULTIMESH_GRIDVIEW_HH #include #include #include #include namespace Dune { // forward declaration template class MultiMeshLevelGridView; template struct MultiMeshLevelGridViewTraits { using GridViewImp = MultiMeshLevelGridView; using Grid = typename std::remove_const::type; using IndexSet = typename Grid::Traits::LevelIndexSet; using Intersection = typename Grid::Traits::LevelIntersection; using IntersectionIterator = typename Grid::Traits::LevelIntersectionIterator; using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication; template struct Codim { using Iterator = typename Grid::Traits::template Codim::template Partition::LevelIterator; using Entity = typename Grid::Traits::template Codim::Entity; using Geometry = typename Grid::template Codim::Geometry; using LocalGeometry = typename Grid::template Codim::LocalGeometry; template struct Partition { using Iterator = typename Grid::template Codim::template Partition::LevelIterator; }; }; enum { conforming = Capabilities::isLevelwiseConforming::v }; }; template class MultiMeshLevelGridView { public: using Traits = MultiMeshLevelGridViewTraits; /// The MultiMesh GridType using Grid = typename Traits::Grid; /// Type of the corresponding GridType hosted by the MultiMesh using HostGrid = typename GridImp::HostGridType; using IndexSet = typename Traits::IndexSet; using Intersection = typename Traits::Intersection; using IntersectionIterator = typename Traits::IntersectionIterator; using CollectiveCommunication = typename Traits::CollectiveCommunication; template struct Codim : public Traits::template Codim {}; enum { conforming = Traits::conforming }; public: /// Constructor. Stores a pointer to the grid MultiMeshLevelGridView (const Grid& multiMesh, int level) : multiMesh_(&multiMesh) , level_(level) {} /// Obtain a const reference to the underlying hierarchic grid const Grid& grid () const { assert( multiMesh_ ); return *multiMesh_; } const HostGrid& grid (std::size_t i) const { return multiMesh_->grid(i); } /// Obtain the level-indexSet const IndexSet& indexSet (std::size_t idx) const { return grid(idx).levelIndexSet(level_); } const IndexSet& indexSet () const { assert(false && "Should be called on the i'th grid: indexSet(i)"); return grid(0).levelIndexSet(level_); } /// Obtain number of entities in a given codimension int size (std::size_t idx, int codim) const { return grid(idx).size(level_, codim); } int size (int codim) const { assert(false && "Should be called on the i'th grid: size(i, codim)"); return grid(0).size(level_, codim); } /// Obtain number of entities with a given geometry type int size (std::size_t idx, const GeometryType& type) const { return grid(idx).size( level_, type ); } int size (const GeometryType& type) const { assert(false && "Should be called on the i'th grid: size(i, type)"); return grid(0).size( level_, type ); } /// Obtain begin iterator for this view template typename Codim::template Partition::Iterator begin () const { assert(cd == 0 && "Implemented for codim == 0 only"); return grid().template lbegin(level_); } /// Obtain end iterator for this view template typename Codim::template Partition::Iterator end () const { assert(cd == 0 && "Implemented for codim == 0 only"); return grid().template lend(level_); } /// Obtain begin intersection iterator with respect to this view IntersectionIterator ibegin (const typename Codim<0>::Entity& entity) const { return entity.impl().ilevelbegin(); } /// Obtain end intersection iterator with respect to this view IntersectionIterator iend (const typename Codim<0>::Entity& entity) const { return entity.impl().ilevelend(); } /// Obtain collective communication object const CollectiveCommunication& comm () const { return grid().comm(); } /// Return size of the overlap region for a given codim on the grid view. int overlapSize (int codim) const { return grid().overlapSize(level_, codim); } /// Return size of the ghost region for a given codim on the grid view. int ghostSize (int codim) const { return grid().ghostSize(level_, codim); } /// Communicate data on this view template void communicate (CommDataHandleIF& data, InterfaceType iftype, CommunicationDirection dir) const { return grid().communicate(data, iftype, dir, level_); } private: const Grid* multiMesh_; int level_; }; // forward declaration template class MultiMeshLeafGridView; template struct MultiMeshLeafGridViewTraits { using GridViewImp = MultiMeshLeafGridView; using Grid = typename std::remove_const::type; using IndexSet = typename Grid::Traits::LeafIndexSet; using Intersection = typename Grid::Traits::LeafIntersection; using IntersectionIterator = typename Grid::Traits::LeafIntersectionIterator; using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication; template struct Codim { using Iterator = typename Grid::Traits::template Codim::template Partition::LeafIterator; using Entity = typename Grid::Traits::template Codim::Entity; using Geometry = typename Grid::template Codim::Geometry; using LocalGeometry = typename Grid::template Codim::LocalGeometry; template struct Partition { using Iterator = typename Grid::template Codim::template Partition::LeafIterator; }; }; enum { conforming = Capabilities::isLeafwiseConforming::v }; }; template class MultiMeshLeafGridView { public: using Traits = MultiMeshLeafGridViewTraits; /// The MultiMesh GridType using Grid = typename Traits::Grid; /// Type of the corresponding GridType hosted by the MultiMesh using HostGrid = typename GridImp::HostGrid; using IndexSet = typename Traits::IndexSet; using Intersection = typename Traits::Intersection; using IntersectionIterator = typename Traits::IntersectionIterator; using CollectiveCommunication = typename Traits::CollectiveCommunication; template struct Codim : public Traits::template Codim {}; enum { conforming = Traits::conforming }; public: MultiMeshLeafGridView (const Grid& multiMesh) : multiMesh_(&multiMesh) {} /// Obtain a const reference to the underlying hierarchic grid const Grid& grid () const { assert( multiMesh_ ); return *multiMesh_; } const HostGrid& grid (std::size_t i) const { return multiMesh_[i]; } /// Obtain the level-indexSet const IndexSet& indexSet (std::size_t idx) const { return grid(idx).leafIndexSet(); } const IndexSet& indexSet () const { assert(false && "Should be called on the i'th grid: indexSet(i)"); return grid(0).leafIndexSet(); } /// Obtain number of entities in a given codimension int size (std::size_t idx, int codim) const { return grid(idx).size(codim); } int size (int codim) const { assert(false && "Should be called on the i'th grid: size(i, codim)"); return grid(0).size(codim); } /// Obtain number of entities with a given geometry type int size (std::size_t idx, const GeometryType& type) const { return grid(idx).size(type); } int size (const GeometryType& type) const { assert(false && "Should be called on the i'th grid: size(i, type)"); return grid(0).size(type); } /// Obtain begin iterator for this view template typename Codim::template Partition::Iterator begin () const { assert(cd == 0 && "Implemented for codim == 0 only"); return grid().template leafbegin(); } /// Obtain end iterator for this view template typename Codim::template Partition::Iterator end () const { assert(cd == 0 && "Implemented for codim == 0 only"); return grid().template leafend(); } /// Obtain begin intersection iterator with respect to this view IntersectionIterator ibegin (const typename Codim<0>::Entity& entity) const { return entity.impl().ileafbegin(); } /// Obtain end intersection iterator with respect to this view IntersectionIterator iend (const typename Codim<0>::Entity& entity) const { return entity.impl().ileaflend(); } /// Obtain collective communication object const CollectiveCommunication& comm () const { return grid().comm(); } /// Return size of the overlap region for a given codim on the grid view. int overlapSize (int codim) const { return grid().overlapSize(codim); } /// Return size of the ghost region for a given codim on the grid view. int ghostSize (int codim) const { return grid().ghostSize(codim); } /// Communicate data on this view template void communicate (CommDataHandleIF& data, InterfaceType iftype, CommunicationDirection dir) const { return grid().communicate(data, iftype, dir); } private: const Grid *multiMesh_; }; } // end namespace Dune #endif // DUNE_MULTIMESH_GRIDVIEW_HH