3#ifndef DUNE_MMESH_GRID_MMESH_HH
4#define DUNE_MMESH_GRID_MMESH_HH
12#include <unordered_map>
13#include <unordered_set>
16#include <dune/common/deprecated.hh>
17#include <dune/common/parallel/communication.hh>
18#include <dune/common/parallel/mpihelper.hh>
19#include <dune/common/version.hh>
20#include <dune/grid/common/adaptcallback.hh>
21#include <dune/grid/common/capabilities.hh>
22#include <dune/grid/common/grid.hh>
23#include <dune/grid/io/file/vtk/vtkwriter.hh>
26#include "../interface/traits.hh"
27#include "../misc/boundaryidprovider.hh"
28#include "../misc/twistutility.hh"
29#include "../remeshing/distance.hh"
30#include "../remeshing/longestedgerefinement.hh"
31#include "../remeshing/ratioindicator.hh"
45#include "rangegenerators.hh"
49#include <dune/common/parallel/mpicommunication.hh>
51#include "../misc/communication.hh"
52#include "../misc/partitionhelper.hh"
55using Comm = Dune::No_Comm;
61template <
int dim,
class HostGr
id>
64 using Traits = GridTraits<
65 dim, dim, MMesh<HostGrid, dim>, MMeshGeometry, MMeshEntity,
67 MMeshLeafIntersection,
68 MMeshLeafIntersection,
69 MMeshLeafIntersectionIterator,
70 MMeshLeafIntersectionIterator,
71 MMeshHierarchicIterator, MMeshLeafIterator,
72 MMeshLeafIndexSet<const MMesh<HostGrid, dim>>,
73 MMeshLeafIndexSet<const MMesh<HostGrid, dim>>,
74 MMeshGlobalIdSet<const MMesh<HostGrid, dim>>, MMeshImpl::MultiId,
75 MMeshGlobalIdSet<const MMesh<HostGrid, dim>>,
76 MMeshImpl::MultiId, Communication<Comm>, DefaultLevelGridViewTraits,
77 DefaultLeafGridViewTraits, MMeshEntitySeed>;
85template <
class HostGr
id,
int dim,
int codim>
86class HostGridEntityChooser_ {
91class HostGridEntityChooser_<HG, 2, 0> {
93 using type =
typename HG::Face_handle;
96class HostGridEntityChooser_<HG, 2, 1> {
98 using type = std::pair<typename HG::Face_handle, int>;
101class HostGridEntityChooser_<HG, 2, 2> {
103 using type =
typename HG::Vertex_handle;
107class HostGridEntityChooser_<HG, 3, 0> {
109 using type =
typename HG::Cell_handle;
112class HostGridEntityChooser_<HG, 3, 1> {
114 using type = std::pair<typename HG::Cell_handle, int>;
117class HostGridEntityChooser_<HG, 3, 2> {
119 using type = CGAL::Triple<typename HG::Cell_handle, int, int>;
122class HostGridEntityChooser_<HG, 3, 3> {
124 using type =
typename HG::Vertex_handle;
128template <
class Point,
class Edge,
class IdType,
class VertexHandle,
129 class InterfaceGridConnectedComponent>
130struct RefinementInsertionPointStruct {
132 std::size_t insertionLevel = 0;
136 bool isInterface =
false;
137 InterfaceGridConnectedComponent connectedcomponent;
150template <
class HostGr
id,
int dim>
152#ifndef DOXYGEN_SHOULD_SKIP_THIS
153 :
public GridDefaultImplementation<dim, dim,
156 MMeshFamily<dim, HostGrid>>
170 using Point =
typename HostGrid::Point;
192 using Traits =
typename GridFamily::Traits;
195 using GridImp =
typename GridFamily::Traits::Grid;
209 typename HostGridEntityChooser_<HostGridType, dimension, cd>::type;
230 using Entity =
typename Traits::template Codim<0>::Entity;
233 using Facet =
typename Traits::template Codim<1>::Entity;
239 using Vertex =
typename Traits::template Codim<dimension>::Entity;
258 typename InterfaceGrid::Traits::template Codim<0>::Entity;
279 explicit MMesh(HostGrid hostgrid) :
MMesh(hostgrid, {}, {}, {}, {}) {}
285 : hostgrid_(hostgrid),
290 comm_(MPIHelper::getCommunicator()),
292 partitionHelper_(*this) {
293 leafIndexSet_ = std::make_unique<MMeshLeafIndexSet<const GridImp>>(
This());
294 globalIdSet_ = std::make_unique<MMeshGlobalIdSet<const GridImp>>(
This());
295 globalIdSet_->update(
This());
298 std::make_shared<InterfaceGrid>(
This(), interfaceBoundarySegments);
300 indicator_.
init(*
this);
312 interfaceGrid_->setIds();
313 interfaceGrid_->setIndices();
318 void setIds() { globalIdSet_->update(
This()); }
322 leafIndexSet_->update(
This());
325 localBoundarySegments_ = boundarySegments_;
327 localBoundarySegments_.clear();
328 std::size_t count = 0;
329 for (
const auto& e : elements(this->leafGridView()))
330 for (
const auto& is : intersections(this->leafGridView(), e))
332 IdType iid = globalIdSet_->template id<1>(
333 entity(is.impl().getHostIntersection()));
334 localBoundarySegments_.insert(std::make_pair(iid, count++));
348 int size(
int level,
int codim)
const {
359 return localBoundarySegments_;
367 return interfaceSegments_;
375 const std::size_t marker = 1) {
378 const auto& facet =
entity(intersection.impl().getHostIntersection());
379 std::vector<std::size_t> ids;
380 for (std::size_t i = 0; i < facet.subEntities(dim); ++i) {
381 const auto& vertex = facet.impl().template subEntity<dim>(i);
382 vertex.impl().hostEntity()->info().isInterface =
true;
385 std::sort(ids.begin(), ids.end());
386 interfaceSegments_.insert(std::make_pair(ids, marker));
392 interfaceGrid_->markAsRefined({ids}, connectedComponent);
394 interfaceGrid_->setIds();
395 interfaceGrid_->setIndices();
397 if (
comm().
size() > 0) partitionHelper_.computeInterfacePartitions();
402 void addInterface(
const I& intersection,
const std::size_t marker = 1) {
403 addInterface(intersection.impl().hostIntersection(), marker);
410 int size(
int level, GeometryType type)
const {
421 return *globalIdSet_;
426 return *globalIdSet_;
432 DUNE_THROW(GridError,
"levelIndexSet of nonexisting level "
433 << level <<
" requested!");
434 return *leafIndexSet_;
439 return *leafIndexSet_;
443 template <
class EntitySeed>
444 typename Traits::template Codim<EntitySeed::codimension>::Entity
entity(
445 const EntitySeed& seed)
const {
447 const typename Traits::Grid>;
449 auto hostEntity = seed.impl().hostEntity();
450 assert(hostEntity !=
decltype(hostEntity)());
451 return EntityImp(
This(), hostEntity);
457 typename Traits::template Codim<dimension>::EntitySeed(vertexHandle));
463 typename Traits::template Codim<0>::EntitySeed(elementHandle));
467 return entity(
typename Traits::template Codim<1>::EntitySeed(facetHandle));
470 template <
int d = dim>
471 std::enable_if_t<d == 3, Edge>
entity(
472 const HostGridEntity<2>& edgeHandle)
const {
473 return entity(
typename Traits::template Codim<2>::EntitySeed(edgeHandle));
478 typename Traits::template Codim<codim>::LevelIterator
lbegin(
485 typename Traits::template Codim<codim>::LevelIterator
lend(
int level)
const {
490 template <
int codim, PartitionIteratorType PiType>
491 typename Traits::template Codim<codim>::template Partition<
492 PiType>::LevelIterator
498 template <
int codim, PartitionIteratorType PiType>
499 typename Traits::template Codim<codim>::template Partition<
500 PiType>::LevelIterator
507 typename Traits::template Codim<codim>::LeafIterator
leafbegin()
const {
513 typename Traits::template Codim<codim>::LeafIterator
leafend()
const {
518 template <
int codim, PartitionIteratorType PiType>
519 typename Traits::template Codim<codim>::template Partition<
526 template <
int codim, PartitionIteratorType PiType>
527 typename Traits::template Codim<codim>::template Partition<
533 typename Traits::LevelIntersectionIterator ilevelbegin(
534 const typename Traits::template Codim<0>::Entity&
entity)
const {
535 return entity.impl().ilevelbegin();
538 typename Traits::LevelIntersectionIterator ilevelend(
539 const typename Traits::template Codim<0>::Entity&
entity)
const {
540 return entity.impl().ilevelend();
543 typename Traits::LeafIntersectionIterator ileafbegin(
544 const typename Traits::template Codim<0>::Entity&
entity)
const {
545 return entity.impl().ileafbegin();
548 typename Traits::LeafIntersectionIterator ileafend(
549 const typename Traits::template Codim<0>::Entity&
entity)
const {
550 return entity.impl().ileafend();
556 bool includeBoundary =
false)
const {
565 bool includeBoundary =
false)
const {
569 Impl(
this,
true, includeBoundary));
574 bool includeBoundary =
false)
const {
578 Impl(
this, includeBoundary));
583 bool includeBoundary =
false)
const {
587 Impl(
this,
true, includeBoundary));
592 return vertex.impl().hostEntity()->info().isInterface;
601 template <
class OtherIntersection>
603 return isInterface(intersection.impl().hostIntersection());
608 static std::vector<std::size_t> ids(segment.subEntities(
dimension));
609 for (std::size_t i = 0; i < segment.subEntities(
dimension); ++i) {
610 const auto& vertex = segment.impl().template subEntity<dimension>(i);
611 if (!vertex.impl().isInterface())
return false;
616 std::sort(ids.begin(), ids.end());
618 int count = interfaceSegments_.count(ids);
624 template <
int d = dim>
626 std::vector<std::size_t> ids;
627 for (std::size_t i = 0; i < edge.subEntities(
dimension); ++i) {
628 const auto& vertex = edge.impl().template subEntity<dimension>(i);
632 ids.push_back(this->
globalIdSet().
id(vertex).vt()[0]);
635 std::sort(ids.begin(), ids.end());
637 for (
const auto& iseg : interfaceSegments_) {
638 const auto& seg = iseg.first.vt();
639 if ((seg[0] == ids[0] && seg[1] == ids[1]) ||
640 (seg[1] == ids[0] && seg[2] == ids[1]) ||
641 (seg[0] == ids[0] && seg[2] == ids[1]))
650 for (std::size_t i = 0; i <
entity.subEntities(1); ++i)
658 return InterfaceEntity{{interfaceGrid_.get(), segment.impl().hostEntity()}};
664 {interfaceGrid_.get(), intersection.impl().getHostIntersection()}};
668 template <
class OtherIntersection>
670 const OtherIntersection& intersection)
const {
676 const auto& host = interfaceEntity.impl().hostEntity();
682 const auto& host = facet.impl().hostEntity();
691 if (hostgrid_.is_infinite(hostFacet.first))
700 const Entity& element = {})
const {
702 hostgrid_.inexact_locate(makePoint(p), element.impl().hostEntity()));
710 for (
int i = 0; i < steps; ++i) {
712 for (
const auto& element : elements(this->leafGridView()))
726 const typename Traits::template Codim<0>::Entity& e)
const {
727 e.impl().mark(refCount);
728 if (refCount > 0) ++refineMarked_;
729 if (refCount < 0) ++coarsenMarked_;
740 for (
const auto& element : elements(this->leafGridView())) {
741 mark(indicator_(element), element);
742 change |= indicator_(element) != 0;
745 for (
const auto& ielement : elements(interfaceGrid_->leafGridView())) {
746 interfaceGrid_->mark(indicator_(ielement), ielement);
747 change |= indicator_(ielement) != 0;
757 int getMark(
const typename Traits::template Codim<0>::Entity& e)
const {
758 return e.impl().getMark();
763 return (interfaceGrid_->preAdapt()) || (coarsenMarked_ > 0) ||
764 (remove_.size() > 0);
769 const double where = 0.5) {
771 ip.edge =
entity.template subEntity<dim - 1>(edgeIndex);
773 ip.point = makePoint(where * ip.edge.geometry().corner(0) +
774 (1 - where) * ip.edge.geometry().corner(1));
775 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
776 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
777 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
780 ip.isInterface =
true;
781 if constexpr (dim != 3) {
783 {interfaceGrid_.get(), ip.edge.impl().hostEntity()}};
788 if (inserted_.insert(ip.edgeId).second) {
789 insert_.push_back(ip);
791 std::cout <<
"Insert vertex manually: " << ip.point << std::endl;
798 ip.point = makePoint(position);
800 insert_.push_back(ip);
802 std::cout <<
"Insert vertex in cell manually: " << ip.point << std::endl;
807 const typename InterfaceGrid::Traits::template Codim<dim - 1>::Entity&
809 const Vertex& vertex =
entity(interfaceVertex.impl().hostEntity());
815 if (removed_.insert(
globalIdSet().
id(vertex)).second) {
816 remove_.push_back(vertex.impl().hostEntity());
818 std::cout <<
"Remove vertex manually: " << vertex.geometry().center()
828 for (
const auto& element : elements(this->leafGridView())) {
829 int mark = element.impl().getMark();
833 std::pair<Edge, GlobalCoordinate> pair =
837 ip.edge = pair.first;
839 ip.point = makePoint(pair.second);
840 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
841 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
842 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
845 if (inserted_.insert(ip.edgeId).second) {
846 insert_.push_back(ip);
848 std::cout <<
"Insert vertex because of marked cell: " << ip.point
854 else if (
mark == -1) {
857 if (vertex !=
decltype(vertex)())
858 if (removed_.insert(
globalIdSet().
id(vertex)).second) {
859 remove_.push_back(vertex.impl().hostEntity());
861 std::cout <<
"Remove vertex because of marked cell: "
862 << vertex.geometry().center() << std::endl;
868 for (
const auto& element : elements(this->
interfaceGrid().leafGridView())) {
876 ip.edge =
entity(pair.first.impl().hostEntity());
878 ip.point = makePoint(pair.second);
879 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
880 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
881 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
882 ip.isInterface =
true;
885 if (inserted_.insert(ip.edgeId).second) {
886 insert_.push_back(ip);
888 std::cout <<
"Insert interface vertex because of marked cell: "
889 << ip.point << std::endl;
894 else if (
mark == -1) {
896 if (ivertex !=
decltype(ivertex)()) {
897 const Vertex& vertex =
entity(ivertex.impl().hostEntity());
899 if (removed_.insert(
globalIdSet().
id(vertex)).second) {
900 remove_.push_back(vertex.impl().hostEntity());
902 std::cout <<
"Remove interface vertex because of marked cell: "
903 << vertex.geometry().center() << std::endl;
910 std::cout <<
"- insert " << insert_.size() <<
"\t remove "
911 << remove_.size() << std::endl;
921 assert(shifts.size() ==
922 this->interfaceGrid().leafIndexSet().size(
dimension - 1));
926 for (
const auto& element : elements(this->leafGridView()))
927 if (signedVolume_(element) <= 0.0)
928 DUNE_THROW(GridError,
929 "A cell has a negative volume! Maybe the interface has been "
935 for (
const auto& element : elements(this->leafGridView()))
936 if (signedVolume_(element) <= 0.0) {
938 if constexpr (dim == 3) {
939 DUNE_THROW(GridError,
940 "Interface could not be moved, because the removal of "
941 "vertices is not supported in 3D!");
943 bool allInterface =
true;
944 for (std::size_t j = 0; j < element.subEntities(
dimension); ++j) {
945 const auto& v = element.template subEntity<dimension>(j);
948 if (!v.impl().isInterface()) {
951 bool inserted = removed_.insert(
globalIdSet().
id(v)).second;
953 remove_.push_back(v.impl().hostEntity());
956 std::cout <<
"Remove vertex because of negative volume: "
957 << v.geometry().center() << std::endl;
959 allInterface =
false;
967 for (std::size_t j = 0; j < element.subEntities(1); ++j) {
968 const auto& edge = element.template subEntity<1>(j);
970 if (interfaceEdge !=
Edge())
972 DUNE_THROW(GridError,
973 "Interface could not be moved because a "
974 "constrained cell with more than one interface "
975 "edge would have negative volume!");
977 interfaceEdge = edge;
982 if (interfaceEdge ==
Edge()) {
983 bool allNonRemovable =
true;
984 for (std::size_t j = 0; j < element.subEntities(
dimension); ++j) {
985 const auto v = element.template subEntity<dimension>(j);
988 allNonRemovable =
false;
989 bool inserted = removed_.insert(
globalIdSet().
id(v)).second;
991 remove_.push_back(v.impl().hostEntity());
994 std::cout <<
"Remove interface vertex because of "
996 << v.geometry().center() << std::endl;
1000 if (allNonRemovable)
1003 "Interface could not be moved because a constrained cell "
1004 "without any interface edge would have negative volume!");
1008 for (std::size_t j = 0; j < element.subEntities(
dimension); ++j) {
1009 const auto& v = element.template subEntity<dimension>(j);
1011 interfaceEdge.impl().template subEntity<dimension>(0) &&
1012 v != interfaceEdge.impl().template subEntity<dimension>(1))
1019 const auto& iThirdVertex =
1021 for (
const auto& e : incidentInterfaceElements(iThirdVertex)) {
1023 DUNE_THROW(GridError,
1024 "Interface could not be moved because two "
1025 "interfaces cross!");
1029 if (e.impl().template subEntity<1>(0) == iThirdVertex)
1031 e.impl().template subEntity<1>(1).impl().hostEntity());
1034 e.impl().template subEntity<1>(0).impl().hostEntity());
1038 const auto iegeo = interfaceEdge.geometry();
1039 const auto& c0 = iegeo.corner(0);
1040 const auto& c1 = iegeo.corner(1);
1041 const auto cegeo = crossingEdge.geometry();
1043 Dune::PolygonCutting<double, GlobalCoordinate>::
1044 lineIntersectionPoint(c0, c1, cegeo.corner(0),
1048 if ((c0 - x) * (c1 - x) > 0.)
continue;
1051 ip.edge = interfaceEdge;
1053 ip.point = makePoint(x);
1054 ip.v0 = thirdVertex.impl().hostEntity();
1055 ip.insertionLevel = thirdVertex.impl().insertionLevel() + 1;
1056 ip.isInterface =
true;
1058 (interfaceEdge.geometry().volume() >
1059 crossingEdge.geometry()
1062 interfaceEdge.impl().hostEntity())
1066 std::cout <<
"Insert interface intersection point: " << ip.point
1069 insert_.push_back(ip);
1075 thirdVertex.impl().hostEntity()->point() =
1076 makePoint(thirdVertex.geometry().center() - shifts[idx]);
1095 assert(shifts.size() == this->leafIndexSet().size(
dimension));
1096 bool change =
false;
1101 for (
const auto& element : elements(this->leafGridView()))
1102 if (signedVolume_(element) <= 0.0) {
1104 if constexpr (dim == 3) {
1105 DUNE_THROW(GridError,
1106 "Vertices could not be moved, because the removal of "
1107 "vertices is not supported in 3D!");
1109 for (std::size_t j = 0; j < element.subEntities(
dimension); ++j) {
1110 const auto& v = element.template subEntity<dimension>(j);
1113 if (!v.impl().isInterface()) {
1116 bool inserted = removed_.insert(
globalIdSet().
id(v)).second;
1118 remove_.push_back(v.impl().hostEntity());
1121 std::cout <<
"Remove vertex because of negative volume: "
1122 << v.geometry().center() << std::endl;
1137 template <
class Gr
idImp,
class DataHandle>
1138 bool adapt(AdaptDataHandleInterface<GridImp, DataHandle>& handle) {
1143 for (
const auto& element : elements(this->leafGridView()))
1144 if (element.isNew()) {
1145 bool initialize =
true;
1147 for (
const auto& old : element.impl().connectedComponent().children()) {
1148 const Entity& father = old;
1150 MMeshImpl::CutSetTriangulation<Entity> cutSetTriangulation(old,
1152 for (
auto& middle : cutSetTriangulation.triangles()) {
1153 middle.impl().bindFather(father);
1154 handle.prolongLocal(father, middle,
true);
1155 middle.impl().bindFather(element);
1156 handle.restrictLocal(element, middle, initialize);
1168 template <
int d = dim>
1169 std::enable_if_t<d == 2, FieldType> signedVolume_(
1170 const Entity& element)
const {
1171 return hostgrid_.triangle(element.impl().hostEntity()).area();
1174 template <
int d = dim>
1175 std::enable_if_t<d == 3, FieldType> signedVolume_(
1176 const Entity& element)
const {
1177 return hostgrid_.tetrahedron(element.impl().hostEntity()).volume();
1180 bool adapt_(
bool buildComponents =
true) {
1181 if (insert_.size() == 0 && remove_.size() == 0)
return false;
1183 std::vector<std::size_t> insertComponentIds;
1184 std::vector<std::size_t> removeComponentIds;
1185 static constexpr bool writeComponents = verbose_;
1187 if (buildComponents) {
1190 connectedComponents_.size() + 1;
1194 bool markAgain =
true;
1195 std::size_t componentNumber;
1198 insertComponentIds.clear();
1199 removeComponentIds.clear();
1200 insertComponentIds.reserve(insert_.size());
1201 removeComponentIds.reserve(remove_.size());
1204 for (
const auto& ip : insert_) {
1205 if (ip.edgeId !=
IdType())
1206 markAgain |= markElementsForInsertion_(ip.edge, componentNumber);
1208 markAgain |= markElementForInsertion_(ip.point, componentNumber);
1210 insertComponentIds.push_back(componentNumber - 1);
1214 for (
const auto& vh : remove_) {
1215 markAgain |= markElementsForRemoval_(vh, componentNumber);
1216 removeComponentIds.push_back(componentNumber - 1);
1220 buildConnectedComponents_();
1223 if (writeComponents) writeComponents_();
1227 std::vector<VertexHandle> newVertices;
1228 for (
const auto& ip : insert_) {
1230 bool connect =
false;
1231 if (ip.edgeId !=
IdType()) {
1232 auto eh = ip.edge.impl().hostEntity();
1235 if (this->
globalIdSet().
id(ip.edge) != ip.edgeId) {
1238 newVertices.emplace_back();
1245 ip.edge.impl().template subEntity<dim>(0).impl().hostEntity() &&
1247 ip.edge.impl().template subEntity<dim>(1).impl().hostEntity())
1250 if (ip.isInterface ==
true)
1251 vh = insertInInterface_(ip);
1253 vh = insertInEdge_(ip.point, eh);
1255 vh->info().insertionLevel = ip.insertionLevel;
1257 vh = insertInCell_(ip.point);
1264 if constexpr (
dimension == 2) hostgrid_.remove(vh);
1267 x = makeFieldVector(ip.point);
1268 x -= makeFieldVector(ip.v0->point());
1270 x += makeFieldVector(ip.v0->point());
1271 vh = insertInCell_(makePoint(x));
1278 std::cerr <<
"Error: Edge added to interface is not part of the "
1279 "new triangulation: "
1280 << ip.v0->point() <<
" to " << vh->point() << std::endl;
1285 globalIdSet_->setNextId(vh);
1286 vh->info().insertionLevel = ip.insertionLevel;
1288 if (ip.isInterface) connect =
true;
1293 std::size_t
id = vh->info().id;
1294 vh->info().isInterface =
true;
1295 std::vector<std::size_t> ids;
1298 std::sort(ids.begin(), ids.end());
1299 interfaceSegments_.insert(std::make_pair(
1303 interfaceGrid_->markAsRefined( {ids},
1304 ip.connectedcomponent);
1307 auto v0id = interfaceGrid_->globalIdSet()
1308 .id(interfaceGrid_->entity(ip.v0))
1310 auto it = interfaceGrid_->boundarySegments().find({v0id});
1311 if (it != interfaceGrid_->boundarySegments().end())
1312 interfaceGrid_->addBoundarySegment({
id}, it->second);
1314 interfaceGrid_->addBoundarySegment({
id}, 0);
1318 newVertices.push_back(vh);
1323 for (
const auto& vh : remove_) {
1325 if (vh->info().isInterface)
1326 elements = removeFromInterface_(vh);
1328 hostgrid_.removeAndGiveNewElements(vh, elements);
1332 if (buildComponents)
1333 markElementsAfterRemoval_(elements, removeComponentIds[ci]);
1339 interfaceGrid_->setIds();
1342 if (
comm().
size() > 1) partitionHelper_.updatePartitions();
1347 if (buildComponents) {
1349 for (std::size_t i = 0; i < newVertices.size(); ++i)
1351 markElementsAfterInsertion_(newVertices[i], insertComponentIds[i]);
1355 interfaceGrid_->setIndices();
1357 if (buildComponents) {
1358 if (writeComponents) writeComponents_();
1362 return newVertices.size() > 0;
1365 template <
int d = dim>
1368 assert(hostgrid_.is_edge(ip.v0, ip.v1));
1369 hostgrid_.is_edge(ip.v0, ip.v1, eh.first, eh.second);
1372 template <
int d = dim>
1375 assert(hostgrid_.is_edge(ip.v0, ip.v1, eh.first, eh.second, eh.third));
1376 hostgrid_.is_edge(ip.v0, ip.v1, eh.first, eh.second, eh.third);
1379 template <
int d = dim>
1380 std::enable_if_t<d == 2, VertexHandle> insertInEdge_(
const Point& point,
1382 return hostgrid_.insert_in_edge(point, eh.first, eh.second);
1385 template <
int d = dim>
1386 std::enable_if_t<d == 3, VertexHandle> insertInEdge_(
const Point& point,
1388 return hostgrid_.insert_in_edge(point, eh.first, eh.second, eh.third);
1391 template <
int d = dim>
1392 std::enable_if_t<d == 2, VertexHandle> insertInCell_(
const Point& point) {
1393 auto face = hostgrid_.locate(point);
1394 return hostgrid_.insert_in_face(point, face);
1397 template <
int d = dim>
1398 std::enable_if_t<d == 3, VertexHandle> insertInCell_(
const Point& point) {
1399 auto cell = hostgrid_.locate(point);
1400 return hostgrid_.insert_in_cell(point, cell);
1409 assert(shifts.size() == iindexSet.size(
dimension - 1));
1411 for (
const auto& vertex : vertices(this->
interfaceGrid().leafGridView())) {
1413 vh->point() = makePoint(vertex.geometry().center() +
1414 shifts[iindexSet.index(vertex)]);
1423 assert(shifts.size() == indexSet.size(
dimension));
1425 for (
const auto& vertex : vertices(this->leafGridView())) {
1427 vh->point() = makePoint(vertex.geometry().center() +
1428 shifts[indexSet.index(vertex)]);
1434 template <
typename Vertex>
1438 ip.point = makePoint(p);
1439 ip.v0 = vertex.impl().hostEntity();
1440 ip.insertionLevel = vertex.impl().insertionLevel() + 1;
1441 ip.isInterface =
true;
1444 for (
const auto& elem : incidentInterfaceElements(vertex))
1445 if (!elem.isNew()) {
1450 insert_.push_back(ip);
1452 std::cout <<
"Add vertex to interface: " << ip.point << std::endl;
1457 for (
const Entity&
entity : elements(this->leafGridView())) {
1459 entity.impl().setIsNew(
false);
1460 entity.impl().setWillVanish(
false);
1461 entity.impl().hostEntity()->info().componentNumber = 0;
1466 createdEntityConnectedComponentMap_.clear();
1467 vanishingEntityConnectedComponentMap_.clear();
1468 connectedComponents_.clear();
1477 void writeComponents_()
const {
1478 static int performCount = 0;
1479 const auto& gridView = this->leafGridView();
1482 std::vector<std::size_t> component(indexSet.size(0), 0);
1483 std::vector<std::size_t> findcomponent(indexSet.size(0), 0);
1484 std::vector<bool> isnew(indexSet.size(0), 0);
1485 std::vector<bool> mightvanish(indexSet.size(0), 0);
1487 for (
const auto& e : elements(gridView)) {
1488 component[indexSet.index(e)] =
1489 e.impl().hostEntity()->info().componentNumber;
1490 isnew[indexSet.index(e)] = e.isNew();
1491 mightvanish[indexSet.index(e)] = e.mightVanish();
1494 VTKWriter<typename Traits::LeafGridView> vtkWriter(gridView);
1495 vtkWriter.addCellData(component,
"component");
1496 vtkWriter.addCellData(isnew,
"isnew");
1497 vtkWriter.addCellData(mightvanish,
"mightvanish");
1498 vtkWriter.write(
"mmesh-components-" + std::to_string(performCount));
1500 VTKWriter<typename InterfaceGrid::LeafGridView> ivtkWriter(
1501 interfaceGrid_->leafGridView());
1502 ivtkWriter.write(
"mmesh-components-interface-" +
1503 std::to_string(performCount++));
1506 void buildConnectedComponents_() {
1507 for (
const Entity&
entity : elements(this->leafGridView())) {
1508 if (
entity.mightVanish()) {
1509 const auto& hostEntity =
entity.impl().hostEntity();
1513 const std::size_t componentId = hostEntity->info().componentNumber - 1;
1517 if (componentId < connectedComponents_.size()) {
1522 if (!component.hasEntity(
entity)) component.update(
entity);
1525 vanishingEntityConnectedComponentMap_.insert(
1526 std::make_pair(
id, componentId));
1530 connectedComponents_[componentId] =
1532 vanishingEntityConnectedComponentMap_.insert(
1533 std::make_pair(
id, componentId));
1545 std::vector<std::size_t> ids;
1546 for (std::size_t i = 0; i < ip.edge.subEntities(dim); ++i)
1548 globalIdSet().
id(ip.edge.impl().template subEntity<dim>(i)).vt()[0]);
1549 std::sort(ids.begin(), ids.end());
1552 std::size_t marker = interfaceSegments_[ids];
1553 interfaceSegments_.erase(ids);
1556 auto eh = ip.edge.impl().hostEntity();
1557 const auto& vh = insertInEdge_(ip.point, eh);
1558 vh->info().isInterface =
true;
1561 std::size_t
id = globalIdSet_->setNextId(vh);
1564 std::vector<std::vector<std::size_t>> allNewIds;
1566 std::vector<std::size_t> newIds;
1567 newIds.push_back(
id);
1569 newIds.push_back(ids[(i + j) %
dimension]);
1571 std::sort(newIds.begin(), newIds.end());
1572 interfaceSegments_.insert(std::make_pair(newIds, marker));
1573 allNewIds.push_back(newIds);
1577 interfaceGrid_->markAsRefined( allNewIds,
1578 ip.connectedcomponent);
1585 template <
int d = dimension>
1586 std::enable_if_t<d == 2, ElementOutput> removeFromInterface_(
1588 std::size_t
id = vh->info().id;
1592 std::size_t marker = 1;
1593 std::vector<VertexHandle> otherVhs;
1594 for (
const auto& e :
1595 incidentInterfaceElements(interfaceGrid_->entity(vh))) {
1597 assert(!interfaceGrid_->hasConnectedComponent(e));
1598 connectedComponent.add(e);
1600 const auto v0 = e.template subEntity<1>(0).impl().hostEntity();
1601 const auto v1 = e.template subEntity<1>(1).impl().hostEntity();
1605 std::vector<std::size_t> ids(2);
1607 ids[1] = other->info().id;
1608 std::sort(ids.begin(), ids.end());
1610 auto it = interfaceSegments_.find(ids);
1611 if (it != interfaceSegments_.end()) {
1612 marker = interfaceSegments_[ids];
1613 interfaceSegments_.erase(it);
1614 otherVhs.push_back(other);
1618 if (otherVhs.size() != 2)
1621 std::list<EdgeHandle> hole;
1622 hostgrid_.make_hole(vh, hole);
1625 hostgrid_.remeshHoleConstrained(vh, hole, elements, otherVhs);
1628 std::vector<std::size_t> ids{
1629 {otherVhs[0]->info().id, otherVhs[1]->info().id}};
1630 std::sort(ids.begin(), ids.end());
1631 interfaceSegments_.insert(std::make_pair(ids, marker));
1634 interfaceGrid_->markAsRefined( {ids}, connectedComponent);
1639 template <
int d = dimension>
1640 std::enable_if_t<d == 3, ElementOutput> removeFromInterface_(
1642 DUNE_THROW(NotImplemented,
"removeFromInterface() in 3d");
1653 std::size_t
size = 0;
1656 for (
const auto& e : elements(this->leafGridView(), Partitions::ghost))
1660 for (
const auto& f : facets(this->leafGridView()))
1661 if (f.partitionType() == GhostEntity)
size++;
1664 for (
const auto& v : vertices(this->leafGridView()))
1665 if (v.partitionType() == GhostEntity)
size++;
1684 partitionHelper_.distribute();
1696 DUNE_THROW(NotImplemented,
"MMesh::loadBalance(t)");
1699 void loadBalance(
int strategy,
int minlevel,
int depth,
int maxlevel,
1701 DUNE_THROW(NotImplemented,
"MMesh::loadBalance()");
1705 const Communication<Comm>&
comm()
const {
return comm_; }
1707 template <
class Data,
class InterfaceType,
class CommunicationDirection>
1708 void communicate(Data& dataHandle, InterfaceType interface,
1709 CommunicationDirection direction,
int level = 0)
const {
1713 if ((interface == InteriorBorder_All_Interface) ||
1714 (interface == All_All_Interface)) {
1715 MMeshCommunication<GridImp, GridImp> communication(partitionHelper_);
1716 const auto& gv = this->leafGridView();
1718 switch (direction) {
1719 case ForwardCommunication:
1720 communication(gv.template begin<0, Interior_Partition>(),
1721 gv.template end<0, Interior_Partition>(),
1722 gv.template begin<0, Ghost_Partition>(),
1723 gv.template end<0, Ghost_Partition>(), dataHandle,
1724 InteriorEntity, GhostEntity,
1725 (interface == All_All_Interface));
1728 case BackwardCommunication:
1729 communication(gv.template begin<0, Ghost_Partition>(),
1730 gv.template end<0, Ghost_Partition>(),
1731 gv.template begin<0, Interior_Partition>(),
1732 gv.template end<0, Interior_Partition>(), dataHandle,
1733 GhostEntity, InteriorEntity,
1734 (interface == All_All_Interface));
1738 DUNE_THROW(NotImplemented,
"Communication on interface type "
1739 << interface <<
" not implemented.");
1741 DUNE_THROW(NotImplemented,
"MPI not found!");
1765 const auto& it = createdEntityConnectedComponentMap_.find(
1767 assert(it->second < connectedComponents_.size());
1768 assert(it != createdEntityConnectedComponentMap_.end());
1769 assert(connectedComponents_.at(it->second).size() > 0);
1770 return connectedComponents_.at(it->second);
1777 const auto& distance()
const {
return indicator_.
distance(); }
1779 int sequence()
const {
return sequence_; }
1781 const PartitionHelper<GridImp>& partitionHelper()
const {
1782 return partitionHelper_;
1787 mutable int coarsenMarked_;
1788 mutable int refineMarked_;
1789 mutable std::size_t componentCount_;
1792 std::unordered_map<IdType, ConnectedComponent> connectedComponents_;
1795 std::unordered_map<IdType, std::size_t> vanishingEntityConnectedComponentMap_;
1796 std::unordered_map<IdType, std::size_t> createdEntityConnectedComponentMap_;
1798 Communication<Comm> comm_;
1799 PartitionHelper<GridImp> partitionHelper_;
1801 std::unique_ptr<MMeshLeafIndexSet<const GridImp>> leafIndexSet_;
1802 std::unique_ptr<MMeshGlobalIdSet<const GridImp>> globalIdSet_;
1803 std::shared_ptr<InterfaceGrid> interfaceGrid_;
1805 std::vector<RefinementInsertionPoint> insert_;
1806 std::unordered_set<IdType> inserted_;
1807 std::vector<VertexHandle> remove_;
1808 std::unordered_set<IdType> removed_;
1817 static const bool verbose_ =
false;
1822 bool markElementsForInsertion_(
const Edge& edge,
1823 std::size_t& componentNumber) {
1825 getIncidentToEdge_(edge, elements);
1827 bool markAgain = getComponentNumber_(elements, componentNumber);
1830 for (
const auto& element : elements) {
1831 element->info().componentNumber = componentNumber;
1832 element->info().mightVanish =
true;
1839 template <
int d = dimension>
1840 std::enable_if_t<d == 2, void> getIncidentToEdge_(
1842 const auto& eh = edge.impl().hostEntity();
1843 elements.push_back(eh.first);
1844 elements.push_back(eh.first->neighbor(eh.second));
1847 template <
int d = dimension>
1848 std::enable_if_t<d == 3, void> getIncidentToEdge_(
1850 const auto& eh = edge.impl().hostEntity();
1851 auto cit = this->
getHostGrid().incident_cells(eh);
1852 for (std::size_t i = 0; i < CGAL::circulator_size(cit); ++i, ++cit)
1853 elements.push_back(cit);
1858 bool markElementForInsertion_(
const Point& point,
1859 std::size_t& componentNumber) {
1863 bool markAgain = getComponentNumber_(elements, componentNumber);
1866 for (
const auto& element : elements) {
1867 element->info().componentNumber = componentNumber;
1868 element->info().mightVanish =
true;
1875 void markElementsAfterInsertion_(
const HostGridEntity<dimension>& vh,
1876 const std::size_t componentId) {
1877 for (
const auto& element : incidentElements(
entity(vh))) {
1878 element.impl().hostEntity()->info().isNew =
true;
1879 element.impl().hostEntity()->info().componentNumber = componentId + 1;
1881 this->createdEntityConnectedComponentMap_.insert(
1882 std::make_pair(
id, componentId));
1887 bool markElementsForRemoval_(
const HostGridEntity<dimension>& vh,
1888 std::size_t& componentNumber) {
1890 for (
const auto& element : incidentElements(
entity(vh)))
1891 elements.push_back(element.impl().hostEntity());
1893 bool markAgain = getComponentNumber_(elements, componentNumber);
1896 for (
const auto& element : elements) {
1897 element->info().componentNumber = componentNumber;
1898 element->info().mightVanish =
true;
1906 const std::size_t componentId) {
1908 for (
const auto& element : elements) {
1909 element->info().isNew =
true;
1910 element->info().componentNumber = componentId + 1;
1913 this->createdEntityConnectedComponentMap_.insert(
1914 std::make_pair(
id, componentId));
1920 std::size_t& componentNumber)
const {
1921 bool markAgain =
false;
1922 componentNumber = 0;
1925 for (
const auto& element : elements)
1926 if (element->info().componentNumber > 0) {
1928 if (componentNumber != 0 &&
1929 element->info().componentNumber != componentNumber) {
1932 std::min(element->info().componentNumber, componentNumber);
1934 componentNumber = element->info().componentNumber;
1938 if (componentNumber == 0) componentNumber = componentCount_++;
1949namespace Capabilities {
1953template <
class HostGr
id,
int dim>
1954struct hasSingleGeometryType<MMesh<HostGrid, dim>> {
1955 static const bool v =
true;
1956 static const unsigned int topologyId = Dune::GeometryType::simplex;
1962template <
class HostGr
id,
int dim,
int codim>
1963struct canCommunicate<MMesh<HostGrid, dim>, codim> {
1964 static const bool v =
false;
1967template <
class HostGr
id,
int dim>
1968struct canCommunicate<MMesh<HostGrid, dim>, 0> {
1969 static const bool v =
true;
1975template <
class HostGr
id,
int dim,
int codim>
1976struct hasEntity<MMesh<HostGrid, dim>, codim> {
1977 static const bool v = (codim >= 0 && codim <= dim);
1980template <
class HostGr
id,
int dim,
int codim>
1981struct hasEntityIterator<MMesh<HostGrid, dim>, codim> {
1982 static const bool v = (codim >= 0 && codim <= dim);
1988template <
class HostGr
id,
int dim>
1989struct isLevelwiseConforming<MMesh<HostGrid, dim>> {
1990 static const bool v =
true;
1996template <
class HostGr
id,
int dim>
1997struct isLeafwiseConforming<MMesh<HostGrid, dim>> {
1998 static const bool v =
true;
2004template <
class HostGr
id,
int dim>
2005struct hasBackupRestoreFacilities<MMesh<HostGrid, dim>> {
2006 static const bool v =
false;
2014template <
int codim,
int dim,
class HostGr
id>
2015std::ostream& operator<<(
2016 std::ostream& stream,
2019 return stream <<
"MMeshEntity<codim=" << codim <<
", dim=" << dim
2020 <<
", center=(" << entity.geometry().center() <<
")>";
2023#include "../interface/grid.hh"
2024#include "../misc/capabilities.hh"
2025#include "../misc/persistentcontainer.hh"
2026#include "dgfparser.hh"
2027#include "gmshgridfactory.hh"
2028#include "gmshreader.hh"
2029#include "gridfactory.hh"
2030#include "structuredgridfactory.hh"
Class defining a longest edge refinement strategy.
Definition: longestedgerefinement.hh:23
static auto refinement(const Element &element)
Returns the refinement/coarsening point for each grid cell.
Definition: longestedgerefinement.hh:42
static int boundaryFlag(const Vertex &v)
return if vertex is removable at the boundary
Definition: longestedgerefinement.hh:124
static Vertex coarsening(const Element &element)
return coarsening vertex (vertex of shortest edge)
Definition: longestedgerefinement.hh:65
static bool isRemoveable(const Vertex &vertex)
return if interface vertex is neither a tip nor a junction
Definition: longestedgerefinement.hh:155
The implementation of a connected component of entities in MMeshThe connected component stores a list...
Definition: connectedcomponent.hh:33
The implementation of entities in a MMesh.
Definition: entity.hh:50
The implementation of connected components in a MMeshInterfaceGridThe connected component copies the ...
Definition: connectedcomponent.hh:31
Provides a DUNE grid interface class for the interface of a MMesh interface grid .
Definition: grid.hh:90
const MMeshInterfaceGridLeafIndexSet< const GridImp > & leafIndexSet() const
Access to the LeafIndexSet.
Definition: grid.hh:236
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: grid.hh:369
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: grid.hh:242
std::enable_if_t< d==2, const MMeshInterfaceEntity< 0 > > mirrorHostEntity(const MMeshInterfaceEntity< 0 > &other) const
Mirror a host entity (2d)
Definition: grid.hh:602
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: intersections.hh:35
Iterator over all entities of a given codimension and level of a grid (2D).
Definition: leafiterator.hh:21
The MMesh class templatized by the CGAL host grid type and the dimension. .
Definition: mmesh.hh:158
Dune::FieldVector< FieldType, dimension > GlobalCoordinate
The type used for coordinates.
Definition: mmesh.hh:204
const MMeshLeafIndexSet< const GridImp > & leafIndexSet() const
Access to the LeafIndexSet.
Definition: mmesh.hh:438
typename HostGrid::Point Point
The point type.
Definition: mmesh.hh:170
std::enable_if_t< d==3, bool > isInterface(const Edge &edge) const
Return if edge in 3d is part of an interface segment.
Definition: mmesh.hh:625
void globalRefine(int steps=1)
Global refine.
Definition: mmesh.hh:709
MMeshCachingEntity< 0, dimension, const GridImp > CachingEntity
The type of a caching entity.
Definition: mmesh.hh:242
std::list< HostGridEntity< 0 > > ElementOutput
The type of the element output.
Definition: mmesh.hh:224
Intersection asIntersection(const Facet &facet) const
Return a facet as intersection.
Definition: mmesh.hh:681
bool isInterface(const OtherIntersection &intersection) const
Return if intersection is part of the interface.
Definition: mmesh.hh:602
MMeshInterfaceVertexIterator< const GridImp > interfaceVerticesBegin(bool includeBoundary=false) const
iterator to first interface entity
Definition: mmesh.hh:573
bool preAdapt()
returns false, if at least one entity is marked for adaption
Definition: mmesh.hh:762
InterfaceEntity asInterfaceEntity(const Intersection &intersection) const
Return an intersection as a interface grid codim 0 entity.
Definition: mmesh.hh:662
std::unordered_map< IdType, std::size_t > InterfaceSegments
The interface segment set.
Definition: mmesh.hh:185
void update()
update the grid indices and ids
Definition: mmesh.hh:309
HostGridEntity< 0 > ElementHandle
The type of the underlying element handle.
Definition: mmesh.hh:212
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: mmesh.hh:513
const InterfaceGrid & interfaceGrid() const
Get reference to the interface grid.
Definition: mmesh.hh:1756
typename HostGridEntityChooser_< HostGridType, dimension, cd >::type HostGridEntity
The type of the underlying entities.
Definition: mmesh.hh:209
MMesh(HostGrid hostgrid)
Constructor that takes a CGAL triangulation.
Definition: mmesh.hh:279
void removeVertex(const Vertex &vertex)
Remove vertex manually.
Definition: mmesh.hh:814
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: mmesh.hh:348
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e) const
Mark entity for refinement.
Definition: mmesh.hh:725
const HostGrid & getHostGrid() const
Get reference to the underlying CGAL triangulation.
Definition: mmesh.hh:1750
bool loadBalance(const T &t)
Distributes this grid over the available nodes in a distributed machine.
Definition: mmesh.hh:1695
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: mmesh.hh:507
bool isOnInterface(const Entity &entity) const
Return if entity shares a facet with the interface.
Definition: mmesh.hh:649
HostGridEntity< dimension > VertexHandle
The type of the underlying vertex handle.
Definition: mmesh.hh:221
const auto & interfaceGridPtr()
Get a pointer to the interface grid.
Definition: mmesh.hh:1762
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: mmesh.hh:1649
typename Traits::template Codim< 0 >::Entity Entity
The type of a codim 0 entity.
Definition: mmesh.hh:230
const MMeshLeafIndexSet< const GridImp > & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: mmesh.hh:430
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: mmesh.hh:1652
const InterfaceSegments & interfaceSegments() const
returns the interface segment set
Definition: mmesh.hh:366
MMeshConnectedComponent< const GridImp > ConnectedComponent
The type used to store connected components of entities.
Definition: mmesh.hh:245
typename InterfaceGrid::Traits::template Codim< 0 >::Entity InterfaceEntity
The type of an interface grid entity.
Definition: mmesh.hh:258
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: mmesh.hh:417
const BoundarySegments & boundarySegments() const
returns the boundary segment to index map
Definition: mmesh.hh:358
MMeshInterfaceIterator< codim, const GridImp > interfaceEnd(bool includeBoundary=false) const
one past the end of the sequence of interface entities
Definition: mmesh.hh:564
typename GridFamily::Traits::Grid GridImp
The grid implementation.
Definition: mmesh.hh:195
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: mmesh.hh:757
typename Traits::template Codim< 1 >::Entity Facet
The type of a codim 1 entity ('facet')
Definition: mmesh.hh:233
bool adapt()
Triggers the grid adaptation process.
Definition: mmesh.hh:826
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: mmesh.hh:529
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: mmesh.hh:478
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: mmesh.hh:444
std::list< FacetHandle > BoundaryEdgesOutput
The type of the boundary edges output.
Definition: mmesh.hh:227
InterfaceSegments & interfaceSegments()
returns the interface segment set
Definition: mmesh.hh:371
InterfaceGrid & interfaceGrid()
Get a non-const reference to the interface grid.
Definition: mmesh.hh:1759
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: mmesh.hh:410
typename GridFamily::Traits Traits
The Traits.
Definition: mmesh.hh:192
static constexpr int dimension
The world dimension.
Definition: mmesh.hh:161
bool isInterface(const Intersection &intersection) const
Return if intersection is part of the interface.
Definition: mmesh.hh:596
typename Traits::template Codim< 1 >::Entity InterfaceElement
The type of an interface element.
Definition: mmesh.hh:248
HostGrid & getHostGrid()
Get non-const reference to the underlying CGAL triangulation.
Definition: mmesh.hh:1753
typename Traits::template Codim< 0 >::LeafIterator LeafIterator
The leaf iterator.
Definition: mmesh.hh:201
void addToInterface(const Vertex &vertex, const GlobalCoordinate &p)
Definition: mmesh.hh:1435
const Communication< Comm > & comm() const
Communication.
Definition: mmesh.hh:1705
void addInterface(const Intersection &intersection, const std::size_t marker=1)
Add an intersection to the interface.
Definition: mmesh.hh:374
bool adapt(AdaptDataHandleInterface< GridImp, DataHandle > &handle)
Callback for the grid adaptation process with restrict/prolong.
Definition: mmesh.hh:1138
MMeshInterfaceConnectedComponent< const InterfaceGrid > InterfaceGridConnectedComponent
The type of a connected component of interface grid entities.
Definition: mmesh.hh:262
bool isInterface(const Vertex &vertex) const
Return if vertex is part of the interface.
Definition: mmesh.hh:591
RatioIndicator< GridImp > RemeshingIndicator
The type of the employed remeshing indicator.
Definition: mmesh.hh:270
bool isInterface(const InterfaceElement &segment) const
Return if element is part of the interface.
Definition: mmesh.hh:607
bool ensureVertexMovement(std::vector< GlobalCoordinate > shifts)
Mark elements such that after movement of vertices no cell degenerates.
Definition: mmesh.hh:1094
HostGrid HostGridType
The hostgrid type.
Definition: mmesh.hh:164
void loadBalance()
Distributes this grid over the available nodes in a distributed machine.
Definition: mmesh.hh:1683
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: mmesh.hh:501
typename Traits::template Codim< dimension - 1 >::Entity Edge
The type of a codim dim-1 entity ('edge')
Definition: mmesh.hh:236
MMesh(HostGrid hostgrid, BoundarySegments boundarySegments, BoundarySegments interfaceBoundarySegments, BoundaryIds boundaryIds, InterfaceSegments interfaceSegments)
Constructor that takes additional about interface and boundary.
Definition: mmesh.hh:282
const GridImp * This() const
This pointer to derived class.
Definition: mmesh.hh:304
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: mmesh.hh:493
Intersection asIntersection(const InterfaceEntity &interfaceEntity) const
Return an interface entity as intersection of a MMesh entity.
Definition: mmesh.hh:675
bool ensureInterfaceMovement(std::vector< GlobalCoordinate > shifts)
Mark elements such that after movement of interface vertices no cell degenerates.
Definition: mmesh.hh:920
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: mmesh.hh:425
void insertVertexInCell(const GlobalCoordinate &position)
Insert vertex in cell manually.
Definition: mmesh.hh:796
void refineEdge(const Entity &entity, const std::size_t edgeIndex, const double where=0.5)
Refine edge manually.
Definition: mmesh.hh:768
typename Traits::template Codim< dimension >::Entity Vertex
The type of a codim dim entity ('vertex')
Definition: mmesh.hh:239
void removeVertex(const typename InterfaceGrid::Traits::template Codim< dim - 1 >::Entity &interfaceVertex)
Remove interface vertex manually.
Definition: mmesh.hh:806
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: mmesh.hh:355
int maxLevel() const
Return maximum level defined in this grid.
Definition: mmesh.hh:344
Vertex entity(const HostGridEntity< dimension > &vertexHandle) const
Return the entity corresponding to a vertex handle.
Definition: mmesh.hh:455
void addInterface(const I &intersection, const std::size_t marker=1)
Add wrapped intersection to the interface.
Definition: mmesh.hh:402
HostGridEntity< 1 > FacetHandle
The type of the underlying edge handle.
Definition: mmesh.hh:215
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: mmesh.hh:1676
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: mmesh.hh:420
void postAdapt()
Clean up refinement markers.
Definition: mmesh.hh:1456
MMeshInterfaceIterator< codim, const GridImp > interfaceBegin(bool includeBoundary=false) const
iterator to first interface entity
Definition: mmesh.hh:555
MMeshInterfaceVertexIterator< const GridImp > interfaceVerticesEnd(bool includeBoundary=false) const
one past the end of the sequence of interface entities
Definition: mmesh.hh:582
InterfaceEntity asInterfaceEntity(const OtherIntersection &intersection) const
Return an intersection as a interface grid codim 0 entity.
Definition: mmesh.hh:669
bool markElements()
Mark elements for adaption using the default remeshing indicator.
Definition: mmesh.hh:736
typename Point::R::RT FieldType
The field type.
Definition: mmesh.hh:173
typename Traits::LeafIntersection Intersection
The type of an intersection.
Definition: mmesh.hh:251
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: mmesh.hh:485
MMeshImpl::MultiId IdType
The type of an id.
Definition: mmesh.hh:176
HostGridEntity< dimension - 1 > EdgeHandle
The type of the underlying edge handle.
Definition: mmesh.hh:218
void moveVertices(const std::vector< GlobalCoordinate > &shifts)
Move vertices.
Definition: mmesh.hh:1421
std::unordered_map< IdType, std::size_t > BoundarySegments
The boundary segment map.
Definition: mmesh.hh:179
MMeshFamily< dim, HostGrid > GridFamily
The grid family type.
Definition: mmesh.hh:167
const BoundaryIds & boundaryIds() const
returns the boundary segment index to boundary id map
Definition: mmesh.hh:363
void moveInterface(const std::vector< GlobalCoordinate > &shifts)
Move interface vertices.
Definition: mmesh.hh:1407
const Entity locate(const GlobalCoordinate &p, const Entity &element={}) const
Locate an entity by coordinate using CGAL's locate.
Definition: mmesh.hh:699
InterfaceEntity asInterfaceEntity(const InterfaceElement &segment) const
Return a codim 1 entity as a interface grid codim 0 entity.
Definition: mmesh.hh:657
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: mmesh.hh:1671
std::unique_ptr< GridImp > GridPtrType
The unique pointer to the grid.
Definition: mmesh.hh:198
Entity entity(const HostGridEntity< 0 > &elementHandle) const
Return the entity corresponding to a element handle.
Definition: mmesh.hh:461
RefinementInsertionPointStruct< Point, Edge, IdType, VertexHandle, InterfaceGridConnectedComponent > RefinementInsertionPoint
The type of a refinement insertion point.
Definition: mmesh.hh:267
Intersection asIntersection(const FacetHandle &host) const
Return a host facet as intersection.
Definition: mmesh.hh:687
int size(int codim) const
number of leaf entities per codim in this process
Definition: mmesh.hh:407
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: mmesh.hh:521
std::unordered_map< std::size_t, std::size_t > BoundaryIds
The boundary id map.
Definition: mmesh.hh:182
void init(const Grid &grid)
Definition: ratioindicator.hh:62
void update()
Update the distances of all vertices.
Definition: ratioindicator.hh:94
const DistanceType & distance() const
Returns distance object.
Definition: ratioindicator.hh:185
The CutSetTriangulation class This class computes the overlapping polytope of to intersecting triangl...
Some common helper methods.
The MMeshInterfaceConnectedComponent class.
The MMeshInterfaceGridEntity class.
The MMeshInterfaceGridEntitySeed class.
The MMeshInterfaceGridGeometry class and its specializations Inherits from Dune::AffineGeometry.
The MMeshInterfaceGridHierarchicIterator class.
The MMeshIncidentIterator class.
The index and id sets for the MMesh class.
The intersection iterator for the MMesh class.
The MMeshInterfaceGridLeafIterator class.
The MMeshInterfaceIterator class.
EntityIterator< Grid::dimension, Grid, MMeshInterfaceVertexIteratorImp< Grid, Grid::dimension > > MMeshInterfaceVertexIterator
The Entity Iterator alias.
Definition: interfaceiterator.hh:174
EntityIterator< codim, Grid, MMeshInterfaceIteratorImp< codim, Grid, Grid::dimension > > MMeshInterfaceIterator
The Entity Iterator alias.
Definition: interfaceiterator.hh:22
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.