3#ifndef DUNE_MMESH_INTERFACE_ENTITY_HH
4#define DUNE_MMESH_INTERFACE_ENTITY_HH
11#include <dune/grid/common/grid.hh>
28template <
int codim,
int dim,
class Gr
idImp>
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31 :
public EntityDefaultImplementation<codim, dim, GridImp,
32 MMeshInterfaceGridEntity>
35 template <
class Gr
idImp_>
36 friend class MMeshInterfaceGridLeafIndexSet;
38 template <
class Gr
idImp_>
39 friend class MMeshInterfaceGridLocalIdSet;
41 template <
class Gr
idImp_>
42 friend class MMeshInterfaceGridGlobalIdSet;
44 friend struct HostGridAccess<typename
std::remove_const<GridImp>
::type>;
47 typedef typename GridImp::ctype ctype;
50 typedef typename GridImp::template MMeshInterfaceEntity<codim>
54 using IdType = MMeshImpl::MultiId;
57 typedef typename GridImp::template Codim<codim>::Geometry Geometry;
68 MMeshInterfaceGridEntity(
const GridImp*
grid,
72 MMeshInterfaceGridEntity(
const MMeshInterfaceGridEntity& original)
73 : hostEntity_(original.hostEntity_), grid_(original.grid_) {}
75 MMeshInterfaceGridEntity(MMeshInterfaceGridEntity&& original)
76 : hostEntity_(
std::move(original.hostEntity_)), grid_(original.grid_) {}
78 MMeshInterfaceGridEntity& operator=(
79 const MMeshInterfaceGridEntity& original) {
80 if (
this != &original) {
81 grid_ = original.grid_;
82 hostEntity_ = original.hostEntity_;
87 MMeshInterfaceGridEntity& operator=(MMeshInterfaceGridEntity&& original) {
88 if (
this != &original) {
89 grid_ = original.grid_;
90 hostEntity_ = std::move(original.hostEntity_);
96 template <
int cc = codim>
97 std::enable_if_t<cc == dim, bool> equals(
98 const MMeshInterfaceGridEntity& other)
const {
99 return hostEntity_ == other.hostEntity_;
103 template <
int cc = codim>
104 std::enable_if_t<cc == 1 && dim == 2, bool> equals(
105 const MMeshInterfaceGridEntity& other)
const {
106 const auto& vh1 = hostEntity_.first->vertex(hostEntity_.second);
107 const auto& vh2 = hostEntity_.first->vertex(hostEntity_.third);
108 const auto& hostOther_ = other.hostEntity_;
109 const auto& vo1 = hostOther_.first->vertex(hostOther_.second);
110 const auto& vo2 = hostOther_.first->vertex(hostOther_.third);
112 return ((vh1 == vo1) && (vh2 == vo2)) || ((vh1 == vo2) && (vh2 == vo1));
129 return grid().getMMesh().partitionHelper().partitionType(
130 grid().entity(hostEntity_));
135 if (dim == 1)
return (cc == 0) ? 0 : 2;
137 if (dim == 2)
return (cc == 0) ? 0 : 3;
143 std::enable_if_t<cc == codim, typename GridImp::template Codim<cc>::Entity>
151 std::enable_if_t<cc == codim + 1,
152 typename GridImp::template Codim<cc>::Entity>
154 DUNE_THROW(NotImplemented,
"subEntity<1> for codim 1 entity");
155 return typename GridImp::template Codim<cc>::Entity();
159 Geometry
geometry()
const {
return Geometry(hostEntity_); }
162 GeometryType
type()
const {
return GeometryTypes::simplex(dim - codim); }
169 if constexpr (codim == dim) {
170 if constexpr (dim == 2)
173 const auto& hostgrid =
grid().getHostGrid();
176 auto circulator = hostgrid.incident_edges(hostEntity_);
177 for (std::size_t i = 0; i < CGAL::circulator_size(circulator);
180 if (hostgrid.is_infinite(circulator))
return false;
182 if (
grid().isInterface(*circulator)) count++;
188 DUNE_THROW(NotImplemented,
"isTip() for codim != dim");
194 if constexpr (codim == dim)
195 return hostEntity_->info().boundaryFlag;
197 DUNE_THROW(NotImplemented,
"boundaryFlag() for codim != dim");
202 if constexpr (codim == dim)
203 return hostEntity_->info().insertionLevel;
205 DUNE_THROW(NotImplemented,
"boundaryFlag() for codim != dim");
210 if constexpr (codim == dim) {
214 Impl(grid_, hostEntity_, includeInfinite));
216 DUNE_THROW(NotImplemented,
"incidentVerticesBegin() for codim != dim");
221 if constexpr (codim == dim) {
225 Impl(grid_, hostEntity_, includeInfinite,
true));
227 DUNE_THROW(NotImplemented,
"incidentVerticesEnd() for codim != dim");
232 if constexpr (codim == dim) {
234 GridImp>::Implementation;
236 Impl(grid_, hostEntity_));
238 DUNE_THROW(NotImplemented,
239 "incidentInterfaceVerticesBegin() for codim != dim");
244 if constexpr (codim == dim) {
246 GridImp>::Implementation;
248 Impl(grid_, hostEntity_,
true));
250 DUNE_THROW(NotImplemented,
251 "incidentInterfaceVerticesEnd() for codim != dim");
256 if constexpr (codim == dim) {
258 GridImp>::Implementation;
260 Impl(grid_, hostEntity_));
261 }
else if constexpr (codim == dim - 1) {
263 GridImp>::Implementation;
265 Impl(grid_, hostEntity_));
267 DUNE_THROW(NotImplemented,
268 "incidentInterfaceElementsBegin() for codim <= dim-1");
273 if constexpr (codim == dim) {
275 GridImp>::Implementation;
277 Impl(grid_, hostEntity_,
true));
278 }
else if constexpr (codim == dim - 1) {
280 GridImp>::Implementation;
282 Impl(grid_, hostEntity_,
true));
284 DUNE_THROW(NotImplemented,
285 "incidentInterfaceElementsEnd() for codim != dim");
289 const MMeshInterfaceEntity&
hostEntity()
const {
return hostEntity_; }
293 if constexpr (codim == dim)
294 return hostEntity_->info().id;
296 return grid().globalIdSet().id(*
this);
300 const GridImp&
grid()
const {
return *grid_; }
304 MMeshInterfaceEntity hostEntity_;
307 const GridImp* grid_;
322template <
int dim,
class Gr
idImp>
324#ifndef DOXYGEN_SHOULD_SKIP_THIS
325 :
public EntityDefaultImplementation<0, dim, GridImp,
326 MMeshInterfaceGridEntity>
329 friend struct HostGridAccess<typename
std::remove_const<GridImp>
::type>;
331 typedef Entity<0, dim, GridImp, MMeshInterfaceGridEntity> EntityType;
335 typedef typename GridImp::template MMeshInterfaceEntity<0>
336 MMeshInterfaceEntity;
338 typedef typename GridImp::template MMeshInterfaceEntity<dim>
339 MMeshInterfaceVertex;
341 typedef typename GridImp::template Codim<0>::Geometry Geometry;
343 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
362 typedef typename Geometry::GlobalCoordinate GlobalCoordinate;
365 typedef typename Geometry::LocalCoordinate LocalCoordinate;
375 if (
grid->canBeMirrored(hostEntity_)) {
376 const auto mirrored = grid_->mirrorHostEntity(hostEntity_);
377 if (hostEntity_.first->info().insertionIndex >
378 mirrored.first->info().insertionIndex)
379 hostEntity_ = mirrored;
383 MMeshInterfaceGridEntity(
const GridImp*
grid,
386 if (
grid->canBeMirrored(hostEntity_)) {
387 const auto mirrored = grid_->mirrorHostEntity(hostEntity_);
388 if (hostEntity_.first->info().insertionIndex >
389 mirrored.first->info().insertionIndex)
390 hostEntity_ = mirrored;
394 MMeshInterfaceGridEntity(
const GridImp*
grid,
399 MMeshInterfaceGridEntity(
const GridImp*
grid,
const VertexStorage& vertex)
400 : id_( IdType({std::size_t(-3), std::size_t(-2)})),
405 MMeshInterfaceGridEntity(
const MMeshInterfaceGridEntity& original)
406 : hostEntity_(original.hostEntity_),
408 grid_(original.grid_),
409 isLeaf_(original.isLeaf_),
410 vertex_(original.vertex_) {}
412 MMeshInterfaceGridEntity(MMeshInterfaceGridEntity&& original)
413 : hostEntity_(
std::move(original.hostEntity_)),
415 grid_(original.grid_),
416 isLeaf_(original.isLeaf_),
417 vertex_(original.vertex_) {}
419 MMeshInterfaceGridEntity& operator=(
420 const MMeshInterfaceGridEntity& original) {
421 if (
this != &original) {
422 grid_ = original.grid_;
423 hostEntity_ = original.hostEntity_;
424 isLeaf_ = original.isLeaf_;
426 vertex_ = original.vertex_;
431 MMeshInterfaceGridEntity& operator=(MMeshInterfaceGridEntity&& original) {
432 if (
this != &original) {
433 grid_ = original.grid_;
434 hostEntity_ = std::move(original.hostEntity_);
435 isLeaf_ = original.isLeaf_;
437 vertex_ = original.vertex_;
443 template <
int d = dim>
444 std::enable_if_t<d == 1, bool> equals(
445 const MMeshInterfaceGridEntity& other)
const {
446 return hostEntity_ == other.hostEntity_;
450 template <
int d = dim>
451 std::enable_if_t<d == 2, bool> equals(
452 const MMeshInterfaceGridEntity& other)
const {
453 return hostEntity_ == other.hostEntity_;
458 return this->equals(other);
463 return hostEntity_ < other.hostEntity_;
468 return grid_->getConnectedComponent(*
this);
473 return grid_->hasConnectedComponent(*
this);
478 DUNE_THROW(InvalidStateException,
479 "MMesh entities do no have a father, but a connectedComponent "
487 void bindFather(
const EntityType& father)
const { father_ = &father; }
492 if constexpr (dim != 1)
493 DUNE_THROW(NotImplemented,
"geometryInFather() for dim != 1");
495 assert(father_ !=
nullptr);
497 auto thisPoints = this->vertex_;
500 for (
int i = 0; i < 2; ++i) thisPoints[i] =
geometry().corner(i);
502 std::array<LocalCoordinate, 2> local;
503 for (
int i = 0; i < 2; ++i)
504 local[i] = father_->impl().geometry().local(thisPoints[i]);
506 return LocalGeometry(local);
518 return hostEntity_.first->info().mightVanish;
523 hostEntity_.first->info().mightVanish = mightVanish;
527 void mark(
int refCount)
const { hostEntity_.first->info().mark = refCount; }
530 int getMark()
const {
return hostEntity_.first->info().mark; }
543 return grid().getMMesh().partitionHelper().partitionType(
544 grid().entity(hostEntity_));
550 return Geometry(hostEntity_);
552 return Geometry(this->vertex_);
557 if (dim == 1)
return (cc == 0) ? 1 : 2;
559 if (dim == 2)
return (cc == 0) ? 1 : 3;
566 std::enable_if_t<cc == 0, typename GridImp::template Codim<cc>::Entity>
575 std::enable_if_t<cc == dim, typename GridImp::template Codim<cc>::Entity>
580 MMeshInterfaceImpl::computeCGALIndices<MMeshInterfaceEntity, dim>(
583 grid_, hostEntity_.first->vertex(cgalIndex[i]));
590 std::enable_if_t<cc == 1 && dim == 2,
591 typename GridImp::template Codim<cc>::Entity>
596 MMeshInterfaceImpl::computeCGALIndices<MMeshInterfaceEntity, dim>(
598 auto cell = hostEntity_.first;
600 int v1 = cgalIndex[i == 2 ? 1 : 0];
601 int v2 = cgalIndex[i == 0 ? 1 : 2];
604 grid_, CGAL::Triple<
decltype(cell),
int,
int>(cell, v1, v2));
616 grid_, hostEntity_,
true);
641 bool isLeaf()
const {
return isLeaf_ && !isNew(); }
650 GeometryType
type()
const {
return GeometryTypes::simplex(dim); }
653 const MMeshInterfaceEntity&
hostEntity()
const {
return hostEntity_; }
656 const GridImp&
grid()
const {
return *grid_; }
662 typename IdType::VT idlist(dim + 1);
663 for (std::size_t i = 0; i < this->
subEntities(dim); ++i)
664 if (grid_->canBeMirrored(hostEntity_))
665 idlist[i] = this->subEntity<dim>(i).impl().hostEntity()->info().id;
668 std::sort(idlist.begin(), idlist.end());
677 MMeshInterfaceEntity hostEntity_;
683 const GridImp* grid_;
692 mutable const EntityType* father_;
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: hierarchiciterator.hh:22
std::array< GlobalCoordinate, dim+1 > VertexStorage
define the type used for storage the vertices of a caching entity
Definition: entity.hh:368
const GridImp & grid() const
returns the host entity
Definition: entity.hh:656
bool isLeaf() const
returns true if Entity has no children
Definition: entity.hh:641
const bool isNew() const
returns true if this entity is new after adaptation
Definition: entity.hh:511
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The type of the EntitySeed interface class.
Definition: entity.hh:353
MMeshInterfaceGridHierarchicIterator< GridImp > hend(int maxlevel) const
Reference to one past the last hierarchic entity.
Definition: entity.hh:635
GridImp::ConnectedComponent ConnectedComponent
The type of the connected component.
Definition: entity.hh:356
std::enable_if_t< cc==dim, typename GridImp::template Codim< cc >::Entity > subEntity(std::size_t i) const
Provide access to sub entity i of given codimension. Entities are numbered 0 ... subEntities(cc)-1.
Definition: entity.hh:576
LocalGeometry geometryInFather() const
Definition: entity.hh:491
std::size_t subEntities(std::size_t cc) const
Return the number of subEntities of codimension cc.
Definition: entity.hh:556
MMeshInterfaceGridLeafIntersectionIterator< GridImp > ileafbegin() const
First leaf intersection.
Definition: entity.hh:608
const ConnectedComponent & connectedComponent() const
returns the connected component
Definition: entity.hh:467
void setIsNew(bool isNew) const
set if this entity is new after adaptation
Definition: entity.hh:514
bool wasRefined() const
returns if grid was refined
Definition: entity.hh:644
int level() const
Level of this element.
Definition: entity.hh:536
EntitySeed seed() const
Create EntitySeed.
Definition: entity.hh:533
bool operator<(const MMeshInterfaceGridEntity &other) const
returns true if host entities are equal
Definition: entity.hh:462
MMeshInterfaceGridLeafIntersectionIterator< GridImp > ilevelbegin() const
We only have one level.
Definition: entity.hh:620
bool operator==(const MMeshInterfaceGridEntity &other) const
returns true if host entities are equal
Definition: entity.hh:457
std::enable_if_t< cc==1 &&dim==2, typename GridImp::template Codim< cc >::Entity > subEntity(std::size_t i) const
Provide access to sub entity i of given codimension. Entities are numbered 0 ... subEntities(cc)-1.
Definition: entity.hh:592
bool mightBeCoarsened() const
returns if grid might be coarsened
Definition: entity.hh:647
MMeshInterfaceGridLeafIntersectionIterator< GridImp > ileafend() const
Reference to one past the last leaf intersection.
Definition: entity.hh:614
MMeshInterfaceGridHierarchicIterator< GridImp > hbegin(int maxlevel) const
First hierarchic entity, i.e. this entity, because we only have one level.
Definition: entity.hh:629
bool hasFather() const
returns true if father entity exists
Definition: entity.hh:485
Geometry geometry() const
Geometry of this entity.
Definition: entity.hh:548
bool hasConnectedComponent() const
returns true if a connected component exists
Definition: entity.hh:472
const MMeshInterfaceEntity & hostEntity() const
returns the host entity
Definition: entity.hh:653
void mark(int refCount) const
mark entity for refine or coarse
Definition: entity.hh:527
MMeshImpl::MultiId IdType
define the type used for persistent indices
Definition: entity.hh:359
const bool mightVanish() const
returns true if this entity will vanish after adaptation
Definition: entity.hh:517
void setWillVanish(bool mightVanish) const
set if this entity will vanish after adaptation
Definition: entity.hh:522
int getMark() const
get mark of entity
Definition: entity.hh:530
GeometryType type() const
returns the geometry type
Definition: entity.hh:650
IdType id() const
return cached id
Definition: entity.hh:659
auto father() const
returns the father entity
Definition: entity.hh:477
PartitionType partitionType() const
The partition type for parallel computing.
Definition: entity.hh:542
std::enable_if_t< cc==0, typename GridImp::template Codim< cc >::Entity > subEntity(std::size_t i) const
Provide access to sub entity i of given codimension. Entities are numbered 0 ... subEntities(cc)-1.
Definition: entity.hh:567
VertexStorage vertex_
the vertices of the host entity object of this entity (for caching entity)
Definition: entity.hh:690
The implementation of entities in a MMesh interface grid.
Definition: entity.hh:34
int level() const
level of this element
Definition: entity.hh:122
GridImp::template Codim< codim >::EntitySeed EntitySeed
The type of the EntitySeed interface class.
Definition: entity.hh:60
std::enable_if_t< cc==codim, typename GridImp::template Codim< cc >::Entity > subEntity(std::size_t i) const
Provide access to sub entity i for cc == dim.
Definition: entity.hh:144
GeometryType type() const
returns the geometry type
Definition: entity.hh:162
unsigned int subEntities(unsigned int cc) const
Return the number of subEntities of codimension codim.
Definition: entity.hh:134
bool hasConnectedComponent() const
returns true if connected component entity exists
Definition: entity.hh:116
auto incidentInterfaceVerticesBegin() const
First incident vertex.
Definition: entity.hh:231
auto incidentInterfaceVerticesEnd() const
Last incident vertex.
Definition: entity.hh:243
auto incidentInterfaceElementsEnd() const
Last incident element.
Definition: entity.hh:272
const GridImp & grid() const
returns the grid
Definition: entity.hh:300
std::enable_if_t< cc==codim+1, typename GridImp::template Codim< cc >::Entity > subEntity(std::size_t i) const
Provide access to sub entity i for cc == dim-1.
Definition: entity.hh:153
EntitySeed seed() const
Return entity seed.
Definition: entity.hh:119
bool isTip() const
Return if this vertex is a tip.
Definition: entity.hh:168
IdType id() const
Return id.
Definition: entity.hh:292
const MMeshInterfaceEntity & hostEntity() const
Return reference to the host entity.
Definition: entity.hh:289
bool isInterface() const
returns that entity is part of the interface
Definition: entity.hh:165
std::size_t insertionLevel() const
Return the insertion level of the vertex.
Definition: entity.hh:201
int boundaryFlag() const
Definition: entity.hh:193
auto incidentVerticesBegin(bool includeInfinite) const
First incident vertex.
Definition: entity.hh:209
PartitionType partitionType() const
The partition type for parallel computing.
Definition: entity.hh:128
auto incidentInterfaceElementsBegin() const
First incident element.
Definition: entity.hh:255
Geometry geometry() const
geometry of this entity
Definition: entity.hh:159
auto incidentVerticesEnd(bool includeInfinite) const
Last incident vertex.
Definition: entity.hh:220
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: hierarchiciterator.hh:22
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: intersectioniterator.hh:28
EntityIterator< Grid::dimension, Grid, MMeshIncidentVerticesIteratorImp< Grid, Grid::dimensionworld > > MMeshIncidentVerticesIterator
The Incident Facets Iterator alias.
Definition: incidentiterator.hh:51
Some common helper methods.
The MMeshIncidentIterator class.
EntityIterator< Grid::dimension, Grid, MMeshIncidentInterfaceVerticesIteratorImp< Grid, Grid::dimension > > MMeshIncidentInterfaceVerticesIterator
The Incident Interface Vertices Iterator alias.
Definition: incidentiterator.hh:27
EntityIterator< 0, Grid, MMeshIncidentInterfaceElementsIteratorImp< Grid, Grid::dimension > > MMeshIncidentInterfaceElementsIterator
The Incident Interface Elements Iterator alias.
Definition: incidentiterator.hh:163
EntityIterator< 0, Grid, MMeshEdgeIncidentInterfaceElementsIteratorImp< Grid, Grid::dimension > > MMeshEdgeIncidentInterfaceElementsIterator
The Incident Interface Elements Iterator alias.
Definition: incidentiterator.hh:307