11#ifndef OPM_SUBGRIDPART_HEADER
12#define OPM_SUBGRIDPART_HEADER
14#include <dune/common/exceptions.hh>
15#include <dune/common/typetraits.hh>
17#include <dune/grid/common/capabilities.hh>
18#include <dune/grid/common/gridview.hh>
26#include <unordered_map>
27#include <unordered_set>
33template <
class Gr
idImp>
36template <
class Gr
idImp>
41 using Grid =
typename std::remove_const<GridImp>::type;
44 using IndexSet =
typename Grid ::Traits ::LeafIndexSet;
56 template <
class BaseEntityType>
65 SubEntity(
const BaseEntityType& base,
const bool owned)
66 : BaseEntityType(base)
70 auto partitionType()
const
73 return Dune::InteriorEntity;
75 return Dune::OverlapEntity;
86 using EntitySeed =
typename Grid ::Traits ::template Codim<cd>::EntitySeed;
88 using Geometry =
typename Grid ::template Codim<cd>::Geometry;
89 using LocalGeometry =
typename Grid ::template Codim<cd>::LocalGeometry;
92 template <PartitionIteratorType pit>
99 enum { conforming = Capabilities ::isLeafwiseConforming<Grid>::v };
113template <
class Gr
idImp>
140 using Entity =
typename Traits::template Codim<cd>::Entity;
149 const Entity& operator*()
const
151 entity_ = this->view_->get(index_);
154 const Entity* operator->()
const
156 entity_ = this->view_->get(index_);
172 assert(view_ == other.view_);
173 return index_ == other.index_;
177 assert(view_ == other.view_);
178 return index_ != other.index_;
183 mutable Entity entity_;
188 template <PartitionIteratorType pit>
196 enum { conforming = Traits::conforming };
197 enum { dimension = GridImp::dimension };
206 const bool overlap =
true)
208 , subset_(std::move(seeds))
209 , num_owned_(subset_.
size())
218 std::unordered_set<int> owned;
219 std::unordered_map<int, Seed> neighbors;
220 const auto& iset = grid_->leafIndexSet();
221 const auto& leaf_view = grid_->leafGridView();
222 for (
const auto& seed : subset_) {
224 const auto& entity = grid_->entity(seed);
225 owned.insert(iset.index(entity));
227 const auto end = leaf_view.iend(entity);
228 for (
auto it = leaf_view.ibegin(entity); it !=
end; ++it) {
229 if (it->boundary()) {
232 if (it->neighbor()) {
233 const auto outside_entity = it->outside();
235 neighbors.try_emplace(iset.index(outside_entity), outside_entity.seed());
240 std::map<int, Seed> unowned_neighbors;
241 for (
const auto& nb : neighbors) {
242 if (owned.count(nb.first) == 0) {
243 unowned_neighbors.insert(nb);
246 subset_.resize(subset_.size() + unowned_neighbors.size());
247 std::size_t count = num_owned_;
248 for (
const auto& neighbor : unowned_neighbors) {
249 subset_[count] = neighbor.second;
252 assert(count == subset_.size());
269 return subset_.size();
282 static_assert(cd == 0,
"Only codimension 0 iterators for SubGridPart.");
284 return Iterator(*
this, 0);
291 static_assert(cd == 0,
"Only codimension 0 iterators for SubGridPart.");
293 return Iterator(*
this, subset_.size());
299 template <
int cd, PartitionIteratorType pit>
302 static_assert(cd == 0,
"Only codimension 0 iterators for SubGridPart.");
303 static_assert(pit == Interior_Partition || pit == Overlap_Partition || pit == All_Partition);
304 if constexpr (pit == Interior_Partition || pit == All_Partition) {
314 template <
int cd, PartitionIteratorType pit>
317 static_assert(cd == 0,
"Only codimension 0 iterators for SubGridPart.");
318 static_assert(pit == Interior_Partition || pit == Overlap_Partition || pit == All_Partition);
319 if constexpr (pit == Overlap_Partition || pit == All_Partition) {
330 return entity.impl().ileafbegin();
336 return entity.impl().ileafend();
342 return grid().comm();
349 return subset_.size() - num_owned_;
368 using Entity0 =
typename Codim<0>::Entity;
369 Entity0 get(std::size_t ii)
const
371 const bool owned = ii < num_owned_;
372 return Entity0(grid_->entity(subset_[ii]), owned);
375 std::vector<typename Entity0::EntitySeed> subset_;
376 const std::size_t num_owned_;
Definition SubGridPart.hpp:58
Definition SubGridPart.hpp:142
A class to represent a part of a grid, similar to a GridView.
Definition SubGridPart.hpp:115
int overlapSize(int codim) const
Return size of the overlap region for a given codim on the grid view.
Definition SubGridPart.hpp:346
typename Traits ::CollectiveCommunication CollectiveCommunication
type of the collective communication
Definition SubGridPart.hpp:134
IntersectionIterator ibegin(const typename Codim< 0 >::Entity &entity) const
obtain begin intersection iterator with respect to this view
Definition SubGridPart.hpp:328
Codim< cd >::Iterator begin() const
obtain number of entities with a given geometry type
Definition SubGridPart.hpp:280
Codim< cd >::Iterator end() const
obtain end iterator for this view
Definition SubGridPart.hpp:289
int size(int codim) const
obtain the index set
Definition SubGridPart.hpp:266
Codim< cd >::template Partition< pit >::Iterator end() const
obtain end iterator for this view
Definition SubGridPart.hpp:315
typename Traits ::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition SubGridPart.hpp:131
IntersectionIterator iend(const typename Codim< 0 >::Entity &entity) const
obtain end intersection iterator with respect to this view
Definition SubGridPart.hpp:334
typename Traits ::Intersection Intersection
type of the intersection
Definition SubGridPart.hpp:128
SubGridPart(const Grid &grid, std::vector< typename Codim< 0 >::Entity::EntitySeed > &&seeds, const bool overlap=true)
Construct a view of the codim 0 entities that can be constructed from the seeds input.
Definition SubGridPart.hpp:204
const CollectiveCommunication & comm() const
obtain collective communication object
Definition SubGridPart.hpp:340
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition SubGridPart.hpp:256
typename Traits::Grid Grid
type of the grid
Definition SubGridPart.hpp:122
typename Traits ::IndexSet IndexSet
type of the index set
Definition SubGridPart.hpp:125
int ghostSize(int codim) const
Return size of the ghost region for a given codim on the grid view.
Definition SubGridPart.hpp:356
Codim< cd >::template Partition< pit >::Iterator begin() const
obtain begin iterator for this view
Definition SubGridPart.hpp:300
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10
Define types needed to iterate over entities of a given partition type.
Definition SubGridPart.hpp:93
typename Grid ::template Codim< cd >::template Partition< pit >::LeafIterator BaseIterator
iterator over a given codim and partition type
Definition SubGridPart.hpp:95
Definition SubGridPart.hpp:83
Definition SubGridPart.hpp:37
typename Grid ::Traits ::LeafIntersection Intersection
type of the intersection
Definition SubGridPart.hpp:47
typename Grid ::Traits ::LeafIndexSet IndexSet
type of the index set
Definition SubGridPart.hpp:44
typename Grid ::Traits ::Communication CollectiveCommunication
type of the collective communication
Definition SubGridPart.hpp:53
typename std::remove_const< GridImp >::type Grid
type of the grid
Definition SubGridPart.hpp:41
typename Grid ::Traits ::LeafIntersectionIterator IntersectionIterator
type of the intersection iterator
Definition SubGridPart.hpp:50
Define types needed to iterate over entities of a given partition type.
Definition SubGridPart.hpp:189
Codim Structure.
Definition SubGridPart.hpp:139