3#ifndef DUNE_MMESH_GRID_MMESH_HH
4#define DUNE_MMESH_GRID_MMESH_HH
11#include <unordered_set>
12#include <unordered_map>
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/capabilities.hh>
21#include <dune/grid/common/grid.hh>
22#include <dune/grid/common/adaptcallback.hh>
23#include <dune/grid/io/file/vtk/vtkwriter.hh>
39#include "rangegenerators.hh"
40#include "../remeshing/distance.hh"
41#include "../remeshing/longestedgerefinement.hh"
42#include "../remeshing/ratioindicator.hh"
43#include "../interface/traits.hh"
44#include "../misc/boundaryidprovider.hh"
45#include "../misc/twistutility.hh"
49 #include <dune/common/parallel/mpicommunication.hh>
50 #include "../misc/communication.hh"
51 #include "../misc/partitionhelper.hh"
52 using Comm = MPI_Comm;
54 using Comm = Dune::No_Comm;
61 template<
int dim,
class HostGr
id>
67 using Traits = GridTraits<
74 MMeshLeafIntersection,
75 MMeshLeafIntersection,
76 MMeshLeafIntersectionIterator,
77 MMeshLeafIntersectionIterator,
78 MMeshHierarchicIterator,
80 MMeshLeafIndexSet< const MMesh<HostGrid, dim> >,
81 MMeshLeafIndexSet< const MMesh<HostGrid, dim> >,
82 MMeshGlobalIdSet< const MMesh<HostGrid, dim> >,
84 MMeshGlobalIdSet< const MMesh<HostGrid, dim> >,
87 DefaultLevelGridViewTraits,
88 DefaultLeafGridViewTraits,
98 template<
class HostGr
id,
int dim,
int codim>
class HostGridEntityChooser_ {
struct type {}; };
100 template<
class HG>
class HostGridEntityChooser_<HG,2,0> {
public:
using type =
typename HG::Face_handle; };
101 template<
class HG>
class HostGridEntityChooser_<HG,2,1> {
public:
using type = std::pair<typename HG::Face_handle, int>; };
102 template<
class HG>
class HostGridEntityChooser_<HG,2,2> {
public:
using type =
typename HG::Vertex_handle; };
104 template<
class HG>
class HostGridEntityChooser_<HG,3,0> {
public:
using type =
typename HG::Cell_handle; };
105 template<
class HG>
class HostGridEntityChooser_<HG,3,1> {
public:
using type = std::pair<typename HG::Cell_handle, int>; };
106 template<
class HG>
class HostGridEntityChooser_<HG,3,2> {
public:
using type = CGAL::Triple<typename HG::Cell_handle, int, int>; };
107 template<
class HG>
class HostGridEntityChooser_<HG,3,3> {
public:
using type =
typename HG::Vertex_handle; };
110 template<
class Po
int,
class Edge,
class IdType,
class VertexHandle,
class InterfaceGr
idConnectedComponent>
111 struct RefinementInsertionPointStruct
114 std::size_t insertionLevel = 0;
118 bool isInterface =
false;
119 InterfaceGridConnectedComponent connectedcomponent;
133 template <
class HostGr
id,
int dim >
135#ifndef DOXYGEN_SHOULD_SKIP_THIS
136 :
public GridDefaultImplementation< dim, dim,
138 MMeshFamily<dim, HostGrid> >
152 using Point =
typename HostGrid::Point;
164 using BoundaryIds = std::unordered_map< std::size_t, std::size_t >;
174 using Traits =
typename GridFamily::Traits;
177 using GridImp =
typename GridFamily::Traits::Grid;
190 using HostGridEntity =
typename HostGridEntityChooser_<HostGridType, dimension, cd>::type;
211 using Entity =
typename Traits::template Codim<0>::Entity;
214 using Facet =
typename Traits::template Codim<1>::Entity;
220 using Vertex =
typename Traits::template Codim<dimension>::Entity;
244 using RefinementInsertionPoint = RefinementInsertionPointStruct<Point, Edge, IdType, VertexHandle, InterfaceGridConnectedComponent>;
257 :
MMesh(hostgrid, {}, {}, {}, {}) {}
265 : hostgrid_(hostgrid),
270 comm_( MPIHelper::getCommunicator() ),
272 partitionHelper_(*this)
274 leafIndexSet_ = std::make_unique<MMeshLeafIndexSet<const GridImp>>(
This() );
275 globalIdSet_ = std::make_unique<MMeshGlobalIdSet<const GridImp>>(
This() );
276 globalIdSet_->update(
This());
278 interfaceGrid_ = std::make_shared<InterfaceGrid>(
This(), interfaceBoundarySegments );
280 indicator_.
init(*
this);
293 interfaceGrid_->setIds();
294 interfaceGrid_->setIndices();
301 globalIdSet_->update(
This());
307 leafIndexSet_->update(
This());
310 localBoundarySegments_ = boundarySegments_;
313 localBoundarySegments_.clear();
314 std::size_t count = 0;
315 for (
const auto& e : elements(this->leafGridView()))
316 for (
const auto& is : intersections(this->leafGridView(), e))
319 IdType iid = globalIdSet_->template id<1>(
entity( is.impl().getHostIntersection() ) );
320 localBoundarySegments_.insert( std::make_pair(iid, count++) );
336 int size (
int level,
int codim)
const {
344 return localBoundarySegments_.size();
350 return localBoundarySegments_;
362 return interfaceSegments_;
368 return interfaceSegments_;
377 const auto& facet =
entity( intersection.impl().getHostIntersection() );
378 std::vector<std::size_t> ids;
379 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;
383 ids.push_back(
globalIdSet().
id( vertex ).vt()[0] );
385 std::sort(ids.begin(), ids.end());
386 interfaceSegments_.insert( std::make_pair(ids, marker) );
391 interfaceGrid_->markAsRefined( {ids}, connectedComponent );
393 interfaceGrid_->setIds();
394 interfaceGrid_->setIndices();
397 partitionHelper_.computeInterfacePartitions();
402 void addInterface(
const I& intersection,
const std::size_t marker = 1 )
404 addInterface(intersection.impl().hostIntersection(), marker);
413 int size (
int level, GeometryType type)
const {
420 int size (GeometryType type)
const
427 return *globalIdSet_;
432 return *globalIdSet_;
439 DUNE_THROW(GridError,
"levelIndexSet of nonexisting level " << level <<
" requested!");
440 return *leafIndexSet_;
446 return *leafIndexSet_;
450 template <
class EntitySeed >
451 typename Traits::template Codim<EntitySeed::codimension>::Entity
455 EntitySeed::codimension,
457 const typename Traits::Grid
460 auto hostEntity = seed.impl().hostEntity();
461 assert( hostEntity !=
decltype(hostEntity)() );
462 return EntityImp(
This(), hostEntity);
468 return entity(
typename Traits::template Codim<dimension>::EntitySeed( vertexHandle ) );
474 return entity(
typename Traits::template Codim<0>::EntitySeed( elementHandle ) );
479 return entity(
typename Traits::template Codim<1>::EntitySeed( facetHandle ) );
482 template<
int d = dim >
483 std::enable_if_t< d == 3, Edge >
484 entity(
const HostGridEntity<2>& edgeHandle)
const
486 return entity(
typename Traits::template Codim<2>::EntitySeed( edgeHandle ) );
491 typename Traits::template Codim<codim>::LevelIterator
lbegin (
int level)
const {
498 typename Traits::template Codim<codim>::LevelIterator
lend (
int level)
const {
504 template<
int codim, PartitionIteratorType PiType>
505 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
lbegin (
int level)
const {
511 template<
int codim, PartitionIteratorType PiType>
512 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator
lend (
int level)
const {
519 typename Traits::template Codim<codim>::LeafIterator
leafbegin()
const {
526 typename Traits::template Codim<codim>::LeafIterator
leafend()
const {
532 template<
int codim, PartitionIteratorType PiType>
533 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator
leafbegin()
const {
539 template<
int codim, PartitionIteratorType PiType>
540 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator
leafend()
const {
544 typename Traits::LevelIntersectionIterator ilevelbegin(
const typename Traits::template Codim< 0 >::Entity&
entity )
const
546 return entity.impl().ilevelbegin();
549 typename Traits::LevelIntersectionIterator ilevelend(
const typename Traits::template Codim< 0 >::Entity&
entity )
const
551 return entity.impl().ilevelend();
554 typename Traits::LeafIntersectionIterator ileafbegin(
const typename Traits::template Codim< 0 >::Entity&
entity )
const
556 return entity.impl().ileafbegin();
559 typename Traits::LeafIntersectionIterator ileafend(
const typename Traits::template Codim< 0 >::Entity&
entity )
const
561 return entity.impl().ileafend();
597 return vertex.impl().hostEntity()->info().isInterface;
607 template<
class OtherIntersection >
610 return isInterface( intersection.impl().hostIntersection() );
616 static std::vector<std::size_t> ids( segment.subEntities(
dimension) );
617 for( std::size_t i = 0; i < segment.subEntities(
dimension); ++i )
619 const auto& vertex = segment.impl().template subEntity<dimension>(i);
620 if ( !vertex.impl().isInterface() )
626 std::sort(ids.begin(), ids.end());
628 int count = interfaceSegments_.count( ids );
629 assert( count <= 1 );
630 return ( count > 0 );
634 template<
int d = dim >
635 std::enable_if_t< d == 3, bool >
638 std::vector<std::size_t> ids;
639 for( std::size_t i = 0; i < edge.subEntities(
dimension); ++i )
641 const auto& vertex = edge.impl().template subEntity<dimension>(i);
646 ids.push_back( this->
globalIdSet().
id( vertex ).vt()[0] );
649 std::sort(ids.begin(), ids.end());
651 for (
const auto& iseg : interfaceSegments_ )
653 const auto& seg = iseg.first.vt();
654 if ( (seg[0] == ids[0] && seg[1] == ids[1])
655 || (seg[1] == ids[0] && seg[2] == ids[1])
656 || (seg[0] == ids[0] && seg[2] == ids[1]) )
666 for( std::size_t i = 0; i <
entity.subEntities(1); ++i )
676 return InterfaceEntity {{ interfaceGrid_.get(), segment.impl().hostEntity() }};
682 return InterfaceEntity {{ interfaceGrid_.get(), intersection.impl().getHostIntersection() }};
686 template<
class OtherIntersection >
695 const auto& host = interfaceEntity.impl().hostEntity();
702 const auto& host = facet.impl().hostEntity();
712 if ( hostgrid_.is_infinite(hostFacet.first) )
721 return entity( hostgrid_.inexact_locate( makePoint( p ), element.impl().hostEntity() ) );
730 for(
int i = 0; i < steps; ++i)
733 for (
const auto& element : elements(this->leafGridView()))
746 bool mark(
int refCount,
const typename Traits::template Codim<0>::Entity & e)
const
748 e.impl().mark( refCount );
749 if(refCount > 0) ++refineMarked_;
750 if(refCount < 0) ++coarsenMarked_;
762 for (
const auto& element : elements( this->leafGridView() ))
764 mark( indicator_(element), element );
765 change |= indicator_(element) != 0;
768 for (
const auto& ielement : elements( interfaceGrid_->leafGridView() ))
770 interfaceGrid_->mark( indicator_(ielement), ielement );
771 change |= indicator_(ielement) != 0;
781 int getMark(
const typename Traits::template Codim<0>::Entity & e)
const
783 return e.impl().getMark();
789 return (interfaceGrid_->preAdapt()) || (coarsenMarked_ > 0) || (remove_.size() > 0);
796 ip.edge =
entity.template subEntity<dim-1>(edgeIndex);
798 ip.point = makePoint( where * ip.edge.geometry().corner(0) + (1 - where) * ip.edge.geometry().corner(1) );
799 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
800 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
801 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
805 ip.isInterface =
true;
806 if constexpr (dim != 3)
808 InterfaceEntity component {{ interfaceGrid_.get(), ip.edge.impl().hostEntity() }};
813 if ( inserted_.insert( ip.edgeId ).second )
815 insert_.push_back( ip );
817 std::cout <<
"Insert vertex manually: " << ip.point << std::endl;
825 ip.point = makePoint( position );
827 insert_.push_back( ip );
829 std::cout <<
"Insert vertex in cell manually: " << ip.point << std::endl;
833 void removeVertex(
const typename InterfaceGrid::Traits::template Codim<dim-1>::Entity& interfaceVertex)
835 const Vertex& vertex =
entity( interfaceVertex.impl().hostEntity() );
842 if ( removed_.insert(
globalIdSet().
id( vertex ) ).second )
844 remove_.push_back( vertex.impl().hostEntity() );
846 std::cout <<
"Remove vertex manually: " << vertex.geometry().center() << std::endl;
856 for (
const auto& element : elements( this->leafGridView() ) )
858 int mark = element.impl().getMark();
866 ip.edge = pair.first;
868 ip.point = makePoint( pair.second );
869 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
870 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
871 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
874 if ( inserted_.insert( ip.edgeId ).second )
876 insert_.push_back( ip );
878 std::cout <<
"Insert vertex because of marked cell: " << ip.point << std::endl;
887 if ( vertex !=
decltype(vertex)() )
888 if ( removed_.insert(
globalIdSet().
id( vertex ) ).second )
890 remove_.push_back( vertex.impl().hostEntity() );
892 std::cout <<
"Remove vertex because of marked cell: " << vertex.geometry().center() << std::endl;
898 for (
const auto& element : elements( this->
interfaceGrid().leafGridView() ) )
908 ip.edge =
entity( pair.first.impl().hostEntity() );
910 ip.point = makePoint( pair.second );
911 ip.v0 = ip.edge.impl().template subEntity<dim>(0).impl().hostEntity();
912 ip.v1 = ip.edge.impl().template subEntity<dim>(1).impl().hostEntity();
913 ip.insertionLevel = ip.edge.impl().insertionLevel() + 1;
914 ip.isInterface =
true;
917 if ( inserted_.insert( ip.edgeId ).second )
919 insert_.push_back( ip );
921 std::cout <<
"Insert interface vertex because of marked cell: " << ip.point << std::endl;
929 if ( ivertex !=
decltype(ivertex)() )
931 const Vertex& vertex =
entity( ivertex.impl().hostEntity() );
933 if ( removed_.insert(
globalIdSet().
id( vertex ) ).second )
935 remove_.push_back( vertex.impl().hostEntity() );
937 std::cout <<
"Remove interface vertex because of marked cell: " << vertex.geometry().center() << std::endl;
944 std::cout <<
"- insert " << insert_.size() <<
"\t remove " << remove_.size() << std::endl;
955 assert( shifts.size() == this->interfaceGrid().leafIndexSet().size(
dimension-1) );
959 for (
const auto& element : elements( this->leafGridView() ) )
960 if ( signedVolume_( element ) <= 0.0 )
961 DUNE_THROW( GridError,
"A cell has a negative volume! Maybe the interface has been moved too far?" );
966 for (
const auto& element : elements( this->leafGridView() ) )
967 if ( signedVolume_( element ) <= 0.0 )
970 if constexpr ( dim == 3 )
972 DUNE_THROW( GridError,
"Interface could not be moved, because the removal of vertices is not supported in 3D!" );
976 bool allInterface =
true;
977 for( std::size_t j = 0; j < element.subEntities(
dimension); ++j )
979 const auto& v = element.template subEntity<dimension>(j);
982 if ( !v.impl().isInterface() )
987 bool inserted = removed_.insert(
globalIdSet().
id( v ) ).second;
990 remove_.push_back( v.impl().hostEntity() );
993 std::cout <<
"Remove vertex because of negative volume: " << v.geometry().center() << std::endl;
995 allInterface =
false;
1003 for( std::size_t j = 0; j < element.subEntities(1); ++j )
1005 const auto& edge = element.template subEntity<1>(j);
1008 if (interfaceEdge !=
Edge())
1009 DUNE_THROW( GridError,
"Interface could not be moved because a constrained cell with more than one interface edge would have negative volume!" );
1011 interfaceEdge = edge;
1016 if (interfaceEdge ==
Edge())
1018 bool allNonRemovable =
true;
1019 for( std::size_t j = 0; j < element.subEntities(
dimension); ++j )
1021 const auto v = element.template subEntity<dimension>(j);
1025 allNonRemovable =
false;
1026 bool inserted = removed_.insert(
globalIdSet().
id( v ) ).second;
1029 remove_.push_back( v.impl().hostEntity() );
1032 std::cout <<
"Remove interface vertex because of negative volume: " << v.geometry().center() << std::endl;
1036 if ( allNonRemovable )
1037 DUNE_THROW( GridError,
"Interface could not be moved because a constrained cell without any interface edge would have negative volume!" );
1043 for( std::size_t j = 0; j < element.subEntities(
dimension); ++j )
1045 const auto& v = element.template subEntity<dimension>(j);
1046 if ( v != interfaceEdge.impl().template subEntity<dimension>(0)
1047 && v != interfaceEdge.impl().template subEntity<dimension>(1) )
1055 for (
const auto& e : incidentInterfaceElements( iThirdVertex ) )
1058 DUNE_THROW( GridError,
"Interface could not be moved because two interfaces cross!" );
1062 if ( e.impl().template subEntity<1>(0) == iThirdVertex )
1063 adjVertex =
entity( e.impl().template subEntity<1>(1).impl().hostEntity() );
1065 adjVertex =
entity( e.impl().template subEntity<1>(0).impl().hostEntity() );
1069 const auto iegeo = interfaceEdge.geometry();
1070 const auto& c0 = iegeo.corner(0);
1071 const auto& c1 = iegeo.corner(1);
1072 const auto cegeo = crossingEdge.geometry();
1073 GlobalCoordinate x = Dune::PolygonCutting<double, GlobalCoordinate>::lineIntersectionPoint( c0, c1, cegeo.corner(0), cegeo.corner(1) );
1076 if ( (c0 - x)*(c1 - x) > 0. )
1080 ip.edge = interfaceEdge;
1082 ip.point = makePoint( x );
1083 ip.v0 = thirdVertex.impl().hostEntity();
1084 ip.insertionLevel = thirdVertex.impl().insertionLevel() + 1;
1085 ip.isInterface =
true;
1087 (interfaceEdge.geometry().volume() > crossingEdge.geometry().volume())
1092 std::cout <<
"Insert interface intersection point: " << ip.point << std::endl;
1094 insert_.push_back( ip );
1099 thirdVertex.impl().hostEntity()->point() = makePoint( thirdVertex.geometry().center() - shifts[idx] );
1120 assert( shifts.size() == this->leafIndexSet().size(
dimension) );
1121 bool change =
false;
1126 for (
const auto& element : elements( this->leafGridView() ) )
1127 if ( signedVolume_( element ) <= 0.0 )
1130 if constexpr ( dim == 3 )
1132 DUNE_THROW( GridError,
"Vertices could not be moved, because the removal of vertices is not supported in 3D!" );
1136 for( std::size_t j = 0; j < element.subEntities(
dimension); ++j )
1138 const auto& v = element.template subEntity<dimension>(j);
1141 if ( !v.impl().isInterface() )
1146 bool inserted = removed_.insert(
globalIdSet().
id( v ) ).second;
1149 remove_.push_back( v.impl().hostEntity() );
1152 std::cout <<
"Remove vertex because of negative volume: " << v.geometry().center() << std::endl;
1168 template<
class Gr
idImp,
class DataHandle >
1169 bool adapt ( AdaptDataHandleInterface< GridImp, DataHandle > &handle )
1175 for (
const auto& element : elements( this->leafGridView() ))
1176 if (element.isNew())
1178 bool initialize =
true;
1180 for (
const auto& old : element.impl().connectedComponent().children() )
1182 const Entity& father = old;
1184 MMeshImpl::CutSetTriangulation<Entity> cutSetTriangulation( old, element );
1185 for (
auto& middle : cutSetTriangulation.triangles() )
1187 middle.impl().bindFather( father );
1188 handle.prolongLocal( father, middle,
true );
1189 middle.impl().bindFather( element );
1190 handle.restrictLocal( element, middle, initialize );
1202 template<
int d = dim>
1203 std::enable_if_t< d == 2, FieldType >
1204 signedVolume_(
const Entity& element )
const
1206 return hostgrid_.triangle( element.impl().hostEntity() ).area();
1209 template<
int d = dim>
1210 std::enable_if_t< d == 3, FieldType >
1211 signedVolume_(
const Entity& element )
const
1213 return hostgrid_.tetrahedron( element.impl().hostEntity() ).volume();
1216 bool adapt_(
bool buildComponents =
true )
1218 if (insert_.size() == 0 && remove_.size() == 0)
1221 std::vector<std::size_t> insertComponentIds;
1222 std::vector<std::size_t> removeComponentIds;
1223 static constexpr bool writeComponents = verbose_;
1225 if ( buildComponents )
1228 componentCount_ = connectedComponents_.size()+1;
1231 bool markAgain =
true;
1232 std::size_t componentNumber;
1236 insertComponentIds.clear();
1237 removeComponentIds.clear();
1238 insertComponentIds.reserve(insert_.size());
1239 removeComponentIds.reserve(remove_.size());
1242 for (
const auto& ip : insert_ )
1244 if ( ip.edgeId !=
IdType() )
1245 markAgain |= markElementsForInsertion_( ip.edge, componentNumber );
1247 markAgain |= markElementForInsertion_( ip.point, componentNumber );
1249 insertComponentIds.push_back( componentNumber-1 );
1253 for (
const auto& vh : remove_ )
1255 markAgain |= markElementsForRemoval_( vh, componentNumber );
1256 removeComponentIds.push_back( componentNumber-1 );
1260 buildConnectedComponents_();
1263 if( writeComponents )
1268 std::vector<VertexHandle> newVertices;
1269 for (
const auto& ip : insert_ )
1272 bool connect =
false;
1273 if ( ip.edgeId !=
IdType() )
1275 auto eh = ip.edge.impl().hostEntity();
1278 if ( this->
globalIdSet().
id( ip.edge ) != ip.edgeId )
1281 newVertices.emplace_back();
1287 if ( ip.v0 != ip.edge.impl().template subEntity<dim>(0).impl().hostEntity()
1288 && ip.v0 != ip.edge.impl().template subEntity<dim>(1).impl().hostEntity() )
1291 if ( ip.isInterface ==
true )
1292 vh = insertInInterface_( ip );
1294 vh = insertInEdge_( ip.point, eh );
1296 vh->info().insertionLevel = ip.insertionLevel;
1300 vh = insertInCell_( ip.point );
1307 hostgrid_.remove( vh );
1310 x = makeFieldVector( ip.point );
1311 x -= makeFieldVector( ip.v0->point() );
1313 x += makeFieldVector( ip.v0->point() );
1314 vh = insertInCell_( makePoint( x ) );
1319 std::cerr <<
"Error: Edge added to interface is not part of the new triangulation: " << ip.v0->point() <<
" to " << vh->point() << std::endl;
1324 globalIdSet_->setNextId( vh );
1325 vh->info().insertionLevel = ip.insertionLevel;
1327 if ( ip.isInterface )
1334 std::size_t
id = vh->info().id;
1335 vh->info().isInterface =
true;
1336 std::vector<std::size_t> ids;
1337 ids.push_back(
id );
1339 std::sort(ids.begin(), ids.end());
1340 interfaceSegments_.insert( std::make_pair(ids, 1) );
1343 interfaceGrid_->markAsRefined( {ids}, ip.connectedcomponent );
1346 auto v0id = interfaceGrid_->globalIdSet().id( interfaceGrid_->entity( ip.v0 ) ).vt()[0];
1347 auto it = interfaceGrid_->boundarySegments().find( { v0id } );
1348 if ( it != interfaceGrid_->boundarySegments().end() )
1349 interfaceGrid_->addBoundarySegment( {
id }, it->second );
1351 interfaceGrid_->addBoundarySegment( {
id }, 0 );
1355 newVertices.push_back( vh );
1360 for (
const auto& vh : remove_ )
1363 if ( vh->info().isInterface )
1364 elements = removeFromInterface_( vh );
1366 hostgrid_.removeAndGiveNewElements( vh, elements );
1369 if ( buildComponents )
1370 markElementsAfterRemoval_( elements, removeComponentIds[ci] );
1376 interfaceGrid_->setIds();
1380 partitionHelper_.updatePartitions();
1385 if ( buildComponents )
1388 for ( std::size_t i = 0; i < newVertices.size(); ++i )
1390 markElementsAfterInsertion_( newVertices[i], insertComponentIds[i] );
1394 interfaceGrid_->setIndices();
1396 if ( buildComponents )
1398 if( writeComponents )
1403 return newVertices.size() > 0;
1406 template<
int d = dim>
1407 std::enable_if_t< d == 2, void >
1410 assert( hostgrid_.is_edge( ip.v0, ip.v1 ) );
1411 hostgrid_.is_edge( ip.v0, ip.v1, eh.first, eh.second );
1414 template<
int d = dim>
1415 std::enable_if_t< d == 3, void >
1418 assert( hostgrid_.is_edge( ip.v0, ip.v1, eh.first, eh.second, eh.third ) );
1419 hostgrid_.is_edge( ip.v0, ip.v1, eh.first, eh.second, eh.third );
1422 template<
int d = dim>
1423 std::enable_if_t< d == 2, VertexHandle >
1426 return hostgrid_.insert_in_edge( point, eh.first, eh.second );
1429 template<
int d = dim>
1430 std::enable_if_t< d == 3, VertexHandle >
1433 return hostgrid_.insert_in_edge( point, eh.first, eh.second, eh.third );
1436 template<
int d = dim>
1437 std::enable_if_t< d == 2, VertexHandle >
1438 insertInCell_ (
const Point &point )
1440 auto face = hostgrid_.locate( point );
1441 return hostgrid_.insert_in_face( point, face );
1444 template<
int d = dim>
1445 std::enable_if_t< d == 3, VertexHandle >
1446 insertInCell_ (
const Point &point )
1448 auto cell = hostgrid_.locate( point );
1449 return hostgrid_.insert_in_cell( point, cell );
1459 assert( shifts.size() == iindexSet.size(
dimension-1) );
1461 for(
const auto& vertex : vertices( this->
interfaceGrid().leafGridView() ) )
1464 vh->point() = makePoint( vertex.geometry().center() + shifts[iindexSet.index(vertex)] );
1474 assert( shifts.size() == indexSet.size(
dimension) );
1476 for(
const auto& vertex : vertices( this->leafGridView() ) )
1479 vh->point() = makePoint( vertex.geometry().center() + shifts[indexSet.index(vertex)] );
1484 template<
typename Vertex >
1489 ip.point = makePoint( p );
1490 ip.v0 = vertex.impl().hostEntity();
1491 ip.insertionLevel = vertex.impl().insertionLevel() + 1;
1492 ip.isInterface =
true;
1495 for (
const auto& elem : incidentInterfaceElements( vertex ) )
1502 insert_.push_back( ip );
1504 std::cout <<
"Add vertex to interface: " << ip.point << std::endl;
1510 for(
const Entity&
entity : elements( this->leafGridView() ) )
1513 entity.impl().setIsNew(
false );
1514 entity.impl().setWillVanish(
false );
1515 entity.impl().hostEntity()->info().componentNumber = 0;
1520 createdEntityConnectedComponentMap_.clear();
1521 vanishingEntityConnectedComponentMap_.clear();
1522 connectedComponents_.clear();
1531 void writeComponents_()
const
1533 static int performCount = 0;
1534 const auto& gridView = this->leafGridView();
1537 std::vector<std::size_t> component( indexSet.size(0), 0 );
1538 std::vector<std::size_t> findcomponent( indexSet.size(0), 0 );
1539 std::vector<bool> isnew( indexSet.size(0), 0 );
1540 std::vector<bool> mightvanish( indexSet.size(0), 0 );
1542 for(
const auto& e : elements( gridView ) )
1544 component[indexSet.index(e)] = e.impl().hostEntity()->info().componentNumber;
1545 isnew[indexSet.index(e)] = e.isNew();
1546 mightvanish[indexSet.index(e)] = e.mightVanish();
1549 VTKWriter<typename Traits::LeafGridView> vtkWriter( gridView );
1550 vtkWriter.addCellData( component,
"component" );
1551 vtkWriter.addCellData( isnew,
"isnew" );
1552 vtkWriter.addCellData( mightvanish,
"mightvanish" );
1553 vtkWriter.write(
"mmesh-components-" + std::to_string( performCount ));
1555 VTKWriter<typename InterfaceGrid::LeafGridView> ivtkWriter( interfaceGrid_->leafGridView() );
1556 ivtkWriter.write(
"mmesh-components-interface-" + std::to_string( performCount++ ));
1559 void buildConnectedComponents_()
1561 for(
const Entity&
entity : elements( this->leafGridView() ) )
1563 if(
entity.mightVanish() )
1565 const auto& hostEntity =
entity.impl().hostEntity();
1569 const std::size_t componentId = hostEntity->info().componentNumber - 1;
1572 if( componentId < connectedComponents_.size() )
1578 if ( !component.hasEntity(
entity ) )
1579 component.update(
entity );
1582 vanishingEntityConnectedComponentMap_.insert( std::make_pair(
id, componentId ) );
1588 vanishingEntityConnectedComponentMap_.insert( std::make_pair(
id, componentId ) );
1600 std::vector<std::size_t> ids;
1601 for( std::size_t i = 0; i < ip.edge.subEntities(dim); ++i )
1602 ids.push_back(
globalIdSet().
id( ip.edge.impl().template subEntity<dim>(i) ).vt()[0] );
1603 std::sort(ids.begin(), ids.end());
1606 std::size_t marker = interfaceSegments_[ids];
1607 interfaceSegments_.erase( ids );
1610 auto eh = ip.edge.impl().hostEntity();
1611 const auto& vh = insertInEdge_( ip.point, eh );
1612 vh->info().isInterface =
true;
1615 std::size_t
id = globalIdSet_->setNextId( vh );
1618 std::vector< std::vector<std::size_t> > allNewIds;
1621 std::vector<std::size_t> newIds;
1622 newIds.push_back(
id );
1624 newIds.push_back( ids[(i+j)%
dimension] );
1626 std::sort(newIds.begin(), newIds.end());
1627 interfaceSegments_.insert( std::make_pair(newIds, marker) );
1628 allNewIds.push_back( newIds );
1632 interfaceGrid_->markAsRefined( allNewIds, ip.connectedcomponent );
1638 template<
int d = dimension >
1639 std::enable_if_t< d == 2, ElementOutput> removeFromInterface_(
const VertexHandle& vh )
1641 std::size_t
id = vh->info().id;
1645 std::size_t marker = 1;
1646 std::vector<VertexHandle> otherVhs;
1647 for (
const auto& e : incidentInterfaceElements( interfaceGrid_->entity( vh ) ) )
1650 assert( !interfaceGrid_->hasConnectedComponent( e ) );
1651 connectedComponent.add( e );
1653 const auto v0 = e.template subEntity<1>(0).impl().hostEntity();
1654 const auto v1 = e.template subEntity<1>(1).impl().hostEntity();
1658 std::vector<std::size_t> ids( 2 );
1660 ids[ 1 ] = other->info().id;
1661 std::sort(ids.begin(), ids.end());
1663 auto it = interfaceSegments_.find( ids );
1664 if ( it != interfaceSegments_.end() )
1666 marker = interfaceSegments_[ ids ];
1667 interfaceSegments_.erase( it );
1668 otherVhs.push_back( other );
1672 if( otherVhs.size() != 2 )
1675 std::list<EdgeHandle> hole;
1676 hostgrid_.make_hole(vh, hole);
1679 hostgrid_.remeshHoleConstrained(vh, hole, elements, otherVhs);
1682 std::vector<std::size_t> ids {{ otherVhs[0]->info().id, otherVhs[1]->info().id }};
1683 std::sort(ids.begin(), ids.end());
1684 interfaceSegments_.insert( std::make_pair(ids, marker) );
1687 interfaceGrid_->markAsRefined( { ids }, connectedComponent );
1692 template<
int d = dimension >
1693 std::enable_if_t< d == 3, ElementOutput> removeFromInterface_(
const VertexHandle& vh )
1695 DUNE_THROW( NotImplemented,
"removeFromInterface() in 3d" );
1709 std::size_t
size = 0;
1712 for (
const auto& e : elements(this->leafGridView(), Partitions::ghost))
1716 for (
const auto& f : facets(this->leafGridView()))
1717 if (f.partitionType() == GhostEntity)
1721 for (
const auto& v : vertices(this->leafGridView()))
1722 if (v.partitionType() == GhostEntity)
1744 partitionHelper_.distribute();
1755 DUNE_THROW(NotImplemented,
"MMesh::loadBalance(t)");
1758 void loadBalance(
int strategy,
int minlevel,
int depth,
int maxlevel,
int minelement){
1759 DUNE_THROW(NotImplemented,
"MMesh::loadBalance()");
1764 const Communication<Comm>&
comm ()
const
1769 template<
class Data,
class InterfaceType,
class CommunicationDirection >
1772 InterfaceType interface,
1773 CommunicationDirection direction,
1774 int level = 0 )
const
1780 if( (interface == InteriorBorder_All_Interface) || (interface == All_All_Interface) )
1782 MMeshCommunication<GridImp, GridImp> communication( partitionHelper_ );
1783 const auto& gv = this->leafGridView();
1787 case ForwardCommunication:
1788 communication( gv.template begin< 0, Interior_Partition >(), gv.template end< 0, Interior_Partition >(),
1789 gv.template begin< 0, Ghost_Partition >(), gv.template end< 0, Ghost_Partition >(),
1790 dataHandle, InteriorEntity, GhostEntity,
1791 (interface == All_All_Interface) );
1794 case BackwardCommunication:
1795 communication( gv.template begin< 0, Ghost_Partition >(), gv.template end< 0, Ghost_Partition >(),
1796 gv.template begin< 0, Interior_Partition >(), gv.template end< 0, Interior_Partition >(),
1797 dataHandle, GhostEntity, InteriorEntity,
1798 (interface == All_All_Interface) );
1803 DUNE_THROW( NotImplemented,
"Communication on interface type " << interface <<
" not implemented." );
1805 DUNE_THROW( NotImplemented,
"MPI not found!" );
1829 return *interfaceGrid_;
1835 return *interfaceGrid_;
1841 return interfaceGrid_;
1846 const auto& it = createdEntityConnectedComponentMap_.find( this->
globalIdSet().
id( entity ) );
1847 assert( it->second < connectedComponents_.size() );
1848 assert( it != createdEntityConnectedComponentMap_.end() );
1849 assert( connectedComponents_.at( it->second ).size() > 0 );
1850 return connectedComponents_.at( it->second );
1863 const auto& distance()
const
1868 int sequence()
const
1873 const PartitionHelper<GridImp>& partitionHelper()
const
1875 return partitionHelper_;
1880 mutable int coarsenMarked_;
1881 mutable int refineMarked_;
1882 mutable std::size_t componentCount_;
1885 std::unordered_map< IdType, ConnectedComponent > connectedComponents_;
1888 std::unordered_map< IdType, std::size_t > vanishingEntityConnectedComponentMap_;
1889 std::unordered_map< IdType, std::size_t > createdEntityConnectedComponentMap_;
1891 Communication<Comm> comm_;
1892 PartitionHelper<GridImp> partitionHelper_;
1894 std::unique_ptr<MMeshLeafIndexSet<const GridImp>> leafIndexSet_;
1895 std::unique_ptr<MMeshGlobalIdSet<const GridImp>> globalIdSet_;
1896 std::shared_ptr<InterfaceGrid> interfaceGrid_;
1898 std::vector<RefinementInsertionPoint> insert_;
1899 std::unordered_set< IdType > inserted_;
1900 std::vector<VertexHandle> remove_;
1901 std::unordered_set< IdType > removed_;
1910 static const bool verbose_ =
false;
1915 bool markElementsForInsertion_ (
const Edge& edge, std::size_t& componentNumber )
1918 getIncidentToEdge_( edge, elements );
1920 bool markAgain = getComponentNumber_( elements, componentNumber );
1923 for(
const auto& element : elements)
1925 element->info().componentNumber = componentNumber;
1926 element->info().mightVanish =
true;
1933 template<
int d = dimension >
1934 std::enable_if_t< d == 2, void > getIncidentToEdge_(
const Edge& edge,
ElementOutput& elements )
const
1936 const auto& eh = edge.impl().hostEntity();
1937 elements.push_back( eh.first );
1938 elements.push_back( eh.first->neighbor( eh.second ) );
1941 template<
int d = dimension >
1942 std::enable_if_t< d == 3, void > getIncidentToEdge_(
const Edge& edge,
ElementOutput& elements )
const
1944 const auto& eh = edge.impl().hostEntity();
1945 auto cit = this->
getHostGrid().incident_cells( eh );
1946 for ( std::size_t i = 0; i < CGAL::circulator_size(cit); ++i, ++cit )
1947 elements.push_back( cit );
1952 bool markElementForInsertion_ (
const Point& point, std::size_t& componentNumber )
1957 bool markAgain = getComponentNumber_( elements, componentNumber );
1960 for(
const auto& element : elements)
1962 element->info().componentNumber = componentNumber;
1963 element->info().mightVanish =
true;
1970 void markElementsAfterInsertion_ (
const HostGridEntity<dimension>& vh,
const std::size_t componentId )
1972 for(
const auto& element : incidentElements(
entity( vh ) ) )
1974 element.impl().hostEntity()->info().isNew =
true;
1975 element.impl().hostEntity()->info().componentNumber = componentId + 1;
1977 this->createdEntityConnectedComponentMap_.insert( std::make_pair(
id, componentId ) );
1982 bool markElementsForRemoval_ (
const HostGridEntity<dimension>& vh, std::size_t& componentNumber )
1985 for(
const auto& element : incidentElements(
entity( vh ) ) )
1986 elements.push_back( element.impl().hostEntity() );
1988 bool markAgain = getComponentNumber_( elements, componentNumber );
1991 for(
const auto& element : elements )
1993 element->info().componentNumber = componentNumber;
1994 element->info().mightVanish =
true;
2001 void markElementsAfterRemoval_ (
ElementOutput& elements,
const std::size_t componentId )
2004 for(
const auto& element : elements)
2006 element->info().isNew =
true;
2007 element->info().componentNumber = componentId + 1;
2010 this->createdEntityConnectedComponentMap_.insert( std::make_pair(
id, componentId ) );
2015 bool getComponentNumber_(
const ElementOutput& elements, std::size_t& componentNumber )
const
2017 bool markAgain =
false;
2018 componentNumber = 0;
2021 for(
const auto& element : elements )
2022 if( element->info().componentNumber > 0 )
2025 if( componentNumber != 0 && element->info().componentNumber != componentNumber )
2028 componentNumber = std::min( element->info().componentNumber, componentNumber );
2031 componentNumber = element->info().componentNumber;
2035 if ( componentNumber == 0 )
2036 componentNumber = componentCount_++;
2048 namespace Capabilities
2053 template<
class HostGr
id,
int dim>
2054 struct hasSingleGeometryType<MMesh<HostGrid, dim>>
2056 static const bool v =
true;
2057 static const unsigned int topologyId = Dune::GeometryType::simplex;
2063 template<
class HostGr
id,
int dim,
int codim>
2064 struct canCommunicate<MMesh<HostGrid, dim>, codim>
2066 static const bool v =
false;
2069 template<
class HostGr
id,
int dim>
2070 struct canCommunicate<MMesh<HostGrid, dim>, 0>
2072 static const bool v =
true;
2078 template<
class HostGr
id,
int dim,
int codim>
2079 struct hasEntity<MMesh<HostGrid, dim>, codim>
2081 static const bool v = (codim >= 0 && codim <= dim);
2084 template<
class HostGr
id,
int dim,
int codim>
2085 struct hasEntityIterator<MMesh<HostGrid, dim>, codim>
2087 static const bool v = (codim >= 0 && codim <= dim);
2093 template<
class HostGr
id,
int dim>
2094 struct isLevelwiseConforming<MMesh<HostGrid, dim>>
2096 static const bool v =
true;
2102 template<
class HostGr
id,
int dim>
2103 struct isLeafwiseConforming<MMesh<HostGrid, dim>>
2105 static const bool v =
true;
2111 template<
class HostGr
id,
int dim>
2112 struct hasBackupRestoreFacilities<MMesh<HostGrid, dim>>
2114 static const bool v =
false;
2123template<
int codim,
int dim,
class HostGr
id>
2126 return stream <<
"MMeshEntity<codim=" << codim <<
", dim=" << dim <<
", center=(" << entity.geometry().center() <<
")>";
2129#include "gridfactory.hh"
2130#include "structuredgridfactory.hh"
2131#include "dgfparser.hh"
2132#include "gmshgridfactory.hh"
2133#include "gmshreader.hh"
2134#include "../interface/grid.hh"
2135#include "../misc/capabilities.hh"
2136#include "../misc/persistentcontainer.hh"
Class defining a longest edge refinement strategy.
Definition: longestedgerefinement.hh:25
static auto refinement(const Element &element)
Returns the refinement/coarsening point for each grid cell.
Definition: longestedgerefinement.hh:44
static int boundaryFlag(const Vertex &v)
return if vertex is removable at the boundary
Definition: longestedgerefinement.hh:135
static Vertex coarsening(const Element &element)
return coarsening vertex (vertex of shortest edge)
Definition: longestedgerefinement.hh:69
static bool isRemoveable(const Vertex &vertex)
return if interface vertex is neither a tip nor a junction
Definition: longestedgerefinement.hh:170
The implementation of a connected component of entities in MMeshThe connected component stores a list...
Definition: connectedcomponent.hh:34
The implementation of entities in a MMesh.
Definition: entity.hh:53
The implementation of connected components in a MMeshInterfaceGridThe connected component copies the ...
Definition: connectedcomponent.hh:33
Provides a DUNE grid interface class for the interface of a MMesh interface grid.
Definition: grid.hh:97
const MMeshInterfaceGridLeafIndexSet< const GridImp > & leafIndexSet() const
Access to the LeafIndexSet.
Definition: grid.hh:251
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: grid.hh:383
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: grid.hh:259
std::enable_if_t< d==2, const MMeshInterfaceEntity< 0 > > mirrorHostEntity(const MMeshInterfaceEntity< 0 > &other) const
Mirror a host entity (2d)
Definition: grid.hh:646
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: intersections.hh:37
Iterator over all entities of a given codimension and level of a grid (2D).
Definition: leafiterator.hh:22
The MMesh class templatized by the CGAL host grid type and the dimension.
Definition: mmesh.hh:140
std::unordered_map< std::size_t, std::size_t > BoundaryIds
The boundary id map.
Definition: mmesh.hh:164
Dune::FieldVector< FieldType, dimension > GlobalCoordinate
The type used for coordinates.
Definition: mmesh.hh:186
const MMeshLeafIndexSet< const GridImp > & leafIndexSet() const
Access to the LeafIndexSet.
Definition: mmesh.hh:444
typename HostGrid::Point Point
The point type.
Definition: mmesh.hh:152
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:636
void globalRefine(int steps=1)
Global refine.
Definition: mmesh.hh:728
std::list< HostGridEntity< 0 > > ElementOutput
The type of the element output.
Definition: mmesh.hh:205
Intersection asIntersection(const Facet &facet) const
Return a facet as intersection.
Definition: mmesh.hh:700
bool isInterface(const OtherIntersection &intersection) const
Return if intersection is part of the interface.
Definition: mmesh.hh:608
MMeshInterfaceVertexIterator< const GridImp > interfaceVerticesBegin(bool includeBoundary=false) const
iterator to first interface entity
Definition: mmesh.hh:581
bool preAdapt()
returns false, if at least one entity is marked for adaption
Definition: mmesh.hh:787
InterfaceEntity asInterfaceEntity(const Intersection &intersection) const
Return an intersection as a interface grid codim 0 entity.
Definition: mmesh.hh:680
void update()
update the grid indices and ids
Definition: mmesh.hh:289
HostGridEntity< 0 > ElementHandle
The type of the underlying element handle.
Definition: mmesh.hh:193
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: mmesh.hh:526
const InterfaceGrid & interfaceGrid() const
Get reference to the interface grid.
Definition: mmesh.hh:1827
typename HostGridEntityChooser_< HostGridType, dimension, cd >::type HostGridEntity
The type of the underlying entities.
Definition: mmesh.hh:190
MMesh(HostGrid hostgrid)
Constructor that takes a CGAL triangulation.
Definition: mmesh.hh:256
void removeVertex(const Vertex &vertex)
Remove vertex manually.
Definition: mmesh.hh:840
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: mmesh.hh:336
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e) const
Mark entity for refinement.
Definition: mmesh.hh:746
const HostGrid & getHostGrid() const
Get reference to the underlying CGAL triangulation.
Definition: mmesh.hh:1815
bool loadBalance(const T &t)
Distributes this grid over the available nodes in a distributed machine.
Definition: mmesh.hh:1754
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: mmesh.hh:519
bool isOnInterface(const Entity &entity) const
Return if entity shares a facet with the interface.
Definition: mmesh.hh:664
HostGridEntity< dimension > VertexHandle
The type of the underlying vertex handle.
Definition: mmesh.hh:202
const auto & interfaceGridPtr()
Get a pointer to the interface grid.
Definition: mmesh.hh:1839
std::unordered_map< IdType, std::size_t > InterfaceSegments
The interface segment set.
Definition: mmesh.hh:167
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: mmesh.hh:1702
typename Traits::template Codim< 0 >::Entity Entity
The type of a codim 0 entity.
Definition: mmesh.hh:211
const MMeshLeafIndexSet< const GridImp > & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: mmesh.hh:436
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: mmesh.hh:1708
const InterfaceSegments & interfaceSegments() const
returns the interface segment set
Definition: mmesh.hh:360
typename InterfaceGrid::Traits::template Codim< 0 >::Entity InterfaceEntity
The type of an interface grid entity.
Definition: mmesh.hh:238
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: mmesh.hh:420
MMeshCachingEntity< 0, dimension, const GridImp > CachingEntity
The type of a caching entity.
Definition: mmesh.hh:223
const BoundarySegments & boundarySegments() const
returns the boundary segment to index map
Definition: mmesh.hh:348
MMeshInterfaceIterator< codim, const GridImp > interfaceEnd(bool includeBoundary=false) const
one past the end of the sequence of interface entities
Definition: mmesh.hh:574
void removeVertex(const typename InterfaceGrid::Traits::template Codim< dim-1 >::Entity &interfaceVertex)
Remove interface vertex manually.
Definition: mmesh.hh:833
typename GridFamily::Traits::Grid GridImp
The grid implementation.
Definition: mmesh.hh:177
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: mmesh.hh:781
typename Traits::template Codim< 1 >::Entity Facet
The type of a codim 1 entity ('facet')
Definition: mmesh.hh:214
HostGridEntity< dimension-1 > EdgeHandle
The type of the underlying edge handle.
Definition: mmesh.hh:199
bool adapt()
Triggers the grid adaptation process.
Definition: mmesh.hh:853
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: mmesh.hh:540
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: mmesh.hh:491
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: mmesh.hh:452
std::list< FacetHandle > BoundaryEdgesOutput
The type of the boundary edges output.
Definition: mmesh.hh:208
std::unordered_map< IdType, std::size_t > BoundarySegments
The boundary segment map.
Definition: mmesh.hh:161
InterfaceSegments & interfaceSegments()
returns the interface segment set
Definition: mmesh.hh:366
InterfaceGrid & interfaceGrid()
Get a non-const reference to the interface grid.
Definition: mmesh.hh:1833
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: mmesh.hh:413
MMeshConnectedComponent< const GridImp > ConnectedComponent
The type used to store connected components of entities.
Definition: mmesh.hh:226
typename GridFamily::Traits Traits
The Traits.
Definition: mmesh.hh:174
static constexpr int dimension
The world dimension.
Definition: mmesh.hh:143
bool isInterface(const Intersection &intersection) const
Return if intersection is part of the interface.
Definition: mmesh.hh:601
typename Traits::template Codim< 1 >::Entity InterfaceElement
The type of an interface element.
Definition: mmesh.hh:229
HostGrid & getHostGrid()
Get non-const reference to the underlying CGAL triangulation.
Definition: mmesh.hh:1821
typename Traits::template Codim< 0 >::LeafIterator LeafIterator
The leaf iterator.
Definition: mmesh.hh:183
void addToInterface(const Vertex &vertex, const GlobalCoordinate &p)
Insert p into the triangulation and add a new interface segment between p and vertex.
Definition: mmesh.hh:1485
typename Traits::template Codim< dimension-1 >::Entity Edge
The type of a codim dim-1 entity ('edge')
Definition: mmesh.hh:217
const Communication< Comm > & comm() const
Communication.
Definition: mmesh.hh:1764
void addInterface(const Intersection &intersection, const std::size_t marker=1)
Add an intersection to the interface.
Definition: mmesh.hh:372
bool adapt(AdaptDataHandleInterface< GridImp, DataHandle > &handle)
Callback for the grid adaptation process with restrict/prolong.
Definition: mmesh.hh:1169
MMeshInterfaceConnectedComponent< const InterfaceGrid > InterfaceGridConnectedComponent
The type of a connected component of interface grid entities.
Definition: mmesh.hh:241
bool isInterface(const Vertex &vertex) const
Return if vertex is part of the interface.
Definition: mmesh.hh:595
RatioIndicator< GridImp > RemeshingIndicator
The type of the employed remeshing indicator.
Definition: mmesh.hh:247
bool isInterface(const InterfaceElement &segment) const
Return if element is part of the interface.
Definition: mmesh.hh:614
bool ensureVertexMovement(std::vector< GlobalCoordinate > shifts)
Mark elements such that after movement of vertices no cell degenerates.
Definition: mmesh.hh:1118
HostGrid HostGridType
The hostgrid type.
Definition: mmesh.hh:146
void loadBalance()
Distributes this grid over the available nodes in a distributed machine.
Definition: mmesh.hh:1742
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: mmesh.hh:512
MMesh(HostGrid hostgrid, BoundarySegments boundarySegments, BoundarySegments interfaceBoundarySegments, BoundaryIds boundaryIds, InterfaceSegments interfaceSegments)
Constructor that takes additional about interface and boundary.
Definition: mmesh.hh:260
const GridImp * This() const
This pointer to derived class.
Definition: mmesh.hh:284
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: mmesh.hh:505
Intersection asIntersection(const InterfaceEntity &interfaceEntity) const
Return an interface entity as intersection of a MMesh entity.
Definition: mmesh.hh:693
bool ensureInterfaceMovement(std::vector< GlobalCoordinate > shifts)
Mark elements such that after movement of interface vertices no cell degenerates.
Definition: mmesh.hh:953
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: mmesh.hh:431
void insertVertexInCell(const GlobalCoordinate &position)
Insert vertex in cell manually.
Definition: mmesh.hh:822
void refineEdge(const Entity &entity, const std::size_t edgeIndex, const double where=0.5)
Refine edge manually.
Definition: mmesh.hh:793
typename Traits::template Codim< dimension >::Entity Vertex
The type of a codim dim entity ('vertex')
Definition: mmesh.hh:220
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: mmesh.hh:343
int maxLevel() const
Return maximum level defined in this grid.
Definition: mmesh.hh:330
Vertex entity(const HostGridEntity< dimension > &vertexHandle) const
Return the entity corresponding to a vertex handle.
Definition: mmesh.hh:466
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:196
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: mmesh.hh:1736
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: mmesh.hh:426
void postAdapt()
Clean up refinement markers.
Definition: mmesh.hh:1508
MMeshInterfaceIterator< codim, const GridImp > interfaceBegin(bool includeBoundary=false) const
iterator to first interface entity
Definition: mmesh.hh:566
MMeshInterfaceVertexIterator< const GridImp > interfaceVerticesEnd(bool includeBoundary=false) const
one past the end of the sequence of interface entities
Definition: mmesh.hh:588
InterfaceEntity asInterfaceEntity(const OtherIntersection &intersection) const
Return an intersection as a interface grid codim 0 entity.
Definition: mmesh.hh:687
bool markElements()
Mark elements for adaption using the default remeshing indicator.
Definition: mmesh.hh:757
typename Point::R::RT FieldType
The field type.
Definition: mmesh.hh:155
typename Traits::LeafIntersection Intersection
The type of an intersection.
Definition: mmesh.hh:232
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: mmesh.hh:498
MMeshImpl::MultiId IdType
The type of an id.
Definition: mmesh.hh:158
void moveVertices(const std::vector< GlobalCoordinate > &shifts)
Move vertices.
Definition: mmesh.hh:1471
MMeshFamily< dim, HostGrid > GridFamily
The grid family type.
Definition: mmesh.hh:149
const BoundaryIds & boundaryIds() const
returns the boundary segment index to boundary id map
Definition: mmesh.hh:354
void moveInterface(const std::vector< GlobalCoordinate > &shifts)
Move interface vertices.
Definition: mmesh.hh:1456
std::unique_ptr< GridImp > GridPtrType
The unique pointer to the grid.
Definition: mmesh.hh:180
const Entity locate(const GlobalCoordinate &p, const Entity &element={}) const
Locate an entity by coordinate using CGAL's locate.
Definition: mmesh.hh:719
InterfaceEntity asInterfaceEntity(const InterfaceElement &segment) const
Return a codim 1 entity as a interface grid codim 0 entity.
Definition: mmesh.hh:674
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: mmesh.hh:1730
Entity entity(const HostGridEntity< 0 > &elementHandle) const
Return the entity corresponding to a element handle.
Definition: mmesh.hh:472
RefinementInsertionPointStruct< Point, Edge, IdType, VertexHandle, InterfaceGridConnectedComponent > RefinementInsertionPoint
The type of a refinement insertion point.
Definition: mmesh.hh:244
Intersection asIntersection(const FacetHandle &host) const
Return a host facet as intersection.
Definition: mmesh.hh:707
int size(int codim) const
number of leaf entities per codim in this process
Definition: mmesh.hh:408
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: mmesh.hh:533
void init(const Grid &grid)
Calculates minH_ and maxH_ for the current interface edge length and sets factor_ to maxh / minh.
Definition: ratioindicator.hh:54
void update()
Update the distances of all vertices.
Definition: ratioindicator.hh:90
const DistanceType & distance() const
Returns distance object.
Definition: ratioindicator.hh:212
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:188
EntityIterator< codim, Grid, MMeshInterfaceIteratorImp< codim, Grid, Grid::dimension > > MMeshInterfaceIterator
The Entity Iterator alias.
Definition: interfaceiterator.hh:21
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.