4#ifndef DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
5#define DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
8#include <dune/grid/common/gridfactory.hh>
9#include <dune/grid/common/boundarysegment.hh>
20 template<
class MMeshImp >
22 :
public GridFactoryInterface< MMeshInterfaceGrid<MMeshImp> >
24 typedef GridFactory< MMeshInterfaceGrid<MMeshImp> >
This;
33 typedef typename HostGrid::Vertex_handle VertexHandle;
39 static const int dimension = Grid::dimension;
41 static const int dimensionworld = Grid::dimensionworld;
46 typedef FieldMatrix< ctype, dimensionworld, dimensionworld >
WorldMatrix;
48 typedef Dune::BoundarySegment< dimension, dimensionworld > BoundarySegment;
49 typedef std::unordered_map< std::vector< std::size_t >, std::size_t,
HashUIntVector > BoundarySegments;
50 typedef std::map< std::vector< std::size_t >,
unsigned int > InsertionIndexMap;
52 typedef std::map< std::size_t, std::size_t > VertexIdMap;
57 typedef typename Grid::template Codim< codim >::Entity Entity;
62 static const bool supportsBoundaryIds =
true;
64 static const bool supportPeriodicity =
false;
74 DUNE_THROW(NotImplemented,
"GridFactory() for MMeshInterfaceGrid");
83 const std::vector< unsigned int > &vertices )
86 std::vector< std::size_t > ids;
87 for (
const auto& v : vertices )
88 ids.push_back( vertexIdMap_.at( v ) );
90 std::sort(ids.begin(), ids.end());
92 (mMesh_->interfaceSegments()).insert( std::make_pair(ids, 1) );
94 insertionIndexMap_.insert( { ids, countElements++ } );
105 std::vector< std::size_t > sorted_vertices;
106 for (
const auto& v : vertices )
107 sorted_vertices.push_back( vertexIdMap_.at( v ) );
108 std::sort(sorted_vertices.begin(), sorted_vertices.end());
110 if( boundarySegments_.find( sorted_vertices ) != boundarySegments_.end() )
111 DUNE_THROW( GridError,
"A boundary segment was inserted twice." );
113 boundarySegments_.insert( std::make_pair( sorted_vertices, countBoundarySegments++ ) );
116 void insertBoundarySegment (
const std::vector< unsigned int >& vertices,
117 const std::shared_ptr< BoundarySegment >& boundarySegment )
119 DUNE_THROW( NotImplemented,
"insertBoundarySegments with Dune::BoundarySegment" );
131 VertexHandle vh = mMesh_->getHostGrid().insert( makePoint( pos ) );
133 vertexIdMap_.insert( { countVertices, vh->info().
id } );
134 vh->info().isInterface =
true;
147 vertexIdMap_.insert( { countVertices, vh->info().
id } );
148 vh->info().isInterface =
true;
159 std::vector< std::size_t > ids;
160 for( std::size_t i = 0; i < entity.subEntities(dimension); ++i )
161 ids.push_back( entity.template subEntity<dimension>(i).impl().hostEntity()->info().id );
162 std::sort(ids.begin(), ids.end());
163 auto it = insertionIndexMap_.find( ids );
164 if( it != insertionIndexMap_.end() )
174 unsigned int insertionIndex (
const typename Codim< dimension >::Entity &entity )
const
176 std::size_t index = mMesh_->interfaceGrid().leafIndexSet().index( entity );
177 assert( index < std::numeric_limits<unsigned int>::max() );
191 DUNE_THROW( InvalidStateException,
"The interface grid cannot be created, get the pointer by getGrid()!" );
197 mMesh_->interfaceGridPtr()->setIds();
198 mMesh_->interfaceGridPtr()->setIndices();
199 mMesh_->interfaceGridPtr()->setBoundarySegments( boundarySegments_ );
202 return mMesh_->interfaceGridPtr();
207 std::shared_ptr<MMesh> mMesh_;
208 BoundarySegments boundarySegments_;
209 std::size_t countBoundarySegments = 0;
210 VertexIdMap vertexIdMap_;
211 InsertionIndexMap insertionIndexMap_;
212 unsigned int countElements = 0;
213 std::size_t countVertices = 0;
specialization of the GridFactory for MMesh InterfaceGrid
Definition: gridfactory.hh:23
unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
return insertion index of vertex entity
Definition: gridfactory.hh:174
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)
insert a boundary segment into the macro grid
Definition: gridfactory.hh:103
GridFactory()
Definition: gridfactory.hh:72
Grid::GridPtrType createGrid()
finalize grid creation and hand over the grid
Definition: gridfactory.hh:189
void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
insert an element into the macro grid
Definition: gridfactory.hh:82
void insertVertex(const WorldVector &pos)
Insert a vertex into the macro grid.
Definition: gridfactory.hh:128
unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
return insertion index of entity
Definition: gridfactory.hh:157
FieldVector< ctype, dimensionworld > WorldVector
type of vector for world coordinates
Definition: gridfactory.hh:44
FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix
type of matrix from world coordinates to world coordinates
Definition: gridfactory.hh:46
GridFactory(const std::shared_ptr< MMesh > mMesh)
Definition: gridfactory.hh:67
MMeshImp MMesh
type of corresponding mmesh
Definition: gridfactory.hh:36
MMeshInterfaceGrid< MMeshImp > Grid
type of interface grid
Definition: gridfactory.hh:28
Grid::ctype ctype
type of (scalar) coordinates
Definition: gridfactory.hh:31
void addVertexHandle(const VertexHandle &vh)
Add existing vertex handle from the macro grid to the interface grid.
Definition: gridfactory.hh:145
Provides a DUNE grid interface class for the interface of a MMesh interface grid.
Definition: grid.hh:97
typename MMesh::HostGridType HostGridType
the underlying hostgrid
Definition: grid.hh:122
std::unique_ptr< GridImp > GridPtrType
the unique pointer to the grid
Definition: grid.hh:119
FieldType ctype
The type used to store coordinates, inherited from the MMesh.
Definition: grid.hh:131
Hash a UInt vector.
Definition: common.hh:14