4#ifndef DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
5#define DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
8#include <dune/grid/common/boundarysegment.hh>
9#include <dune/grid/common/gridfactory.hh>
19template <
class MMeshImp>
21 :
public GridFactoryInterface<MMeshInterfaceGrid<MMeshImp> > {
22 typedef GridFactory<MMeshInterfaceGrid<MMeshImp> >
This;
31 typedef typename HostGrid::Vertex_handle VertexHandle;
37 static const int dimension = Grid::dimension;
39 static const int dimensionworld = Grid::dimensionworld;
44 typedef FieldMatrix<ctype, dimensionworld, dimensionworld>
WorldMatrix;
46 typedef Dune::BoundarySegment<dimension, dimensionworld> BoundarySegment;
47 typedef std::unordered_map<std::vector<std::size_t>, std::size_t,
50 typedef std::map<std::vector<std::size_t>,
unsigned int> InsertionIndexMap;
52 typedef std::map<std::size_t, std::size_t> VertexIdMap;
56 typedef typename Grid::template Codim<codim>::Entity Entity;
61 static const bool supportsBoundaryIds =
true;
63 static const bool supportPeriodicity =
false;
66 GridFactory(
const std::shared_ptr<MMesh> mMesh) : mMesh_(mMesh) {}
70 DUNE_THROW(NotImplemented,
"GridFactory() for MMeshInterfaceGrid");
79 const std::vector<unsigned int> &vertices) {
81 std::vector<std::size_t> ids;
82 for (
const auto &v : vertices) ids.push_back(vertexIdMap_.at(v));
84 std::sort(ids.begin(), ids.end());
86 (mMesh_->interfaceSegments()).insert(std::make_pair(ids, 1));
88 insertionIndexMap_.insert({ids, countElements++});
98 const std::vector<unsigned int> &vertices) {
99 std::vector<std::size_t> sorted_vertices;
100 for (
const auto &v : vertices)
101 sorted_vertices.push_back(vertexIdMap_.at(v));
102 std::sort(sorted_vertices.begin(), sorted_vertices.end());
104 if (boundarySegments_.find(sorted_vertices) != boundarySegments_.end())
105 DUNE_THROW(GridError,
"A boundary segment was inserted twice.");
107 boundarySegments_.insert(
108 std::make_pair(sorted_vertices, countBoundarySegments++));
111 void insertBoundarySegment(
112 const std::vector<unsigned int> &vertices,
113 const std::shared_ptr<BoundarySegment> &boundarySegment) {
114 DUNE_THROW(NotImplemented,
115 "insertBoundarySegments with Dune::BoundarySegment");
126 VertexHandle vh = mMesh_->getHostGrid().insert(makePoint(pos));
128 vertexIdMap_.insert({countVertices, vh->info().
id});
129 vh->info().isInterface =
true;
142 vertexIdMap_.insert({countVertices, vh->info().
id});
143 vh->info().isInterface =
true;
153 std::vector<std::size_t> ids;
154 for (std::size_t i = 0; i < entity.subEntities(dimension); ++i)
155 ids.push_back(entity.template subEntity<dimension>(i)
160 std::sort(ids.begin(), ids.end());
161 auto it = insertionIndexMap_.find(ids);
162 if (it != insertionIndexMap_.end())
173 const typename Codim<dimension>::Entity &entity)
const {
174 std::size_t index = mMesh_->interfaceGrid().leafIndexSet().index(entity);
175 assert(index < std::numeric_limits<unsigned int>::max());
189 InvalidStateException,
190 "The interface grid cannot be created, get the pointer by getGrid()!");
195 mMesh_->interfaceGridPtr()->setIds();
196 mMesh_->interfaceGridPtr()->setIndices();
197 mMesh_->interfaceGridPtr()->setBoundarySegments(boundarySegments_);
200 return mMesh_->interfaceGridPtr();
205 std::shared_ptr<MMesh> mMesh_;
206 BoundarySegments boundarySegments_;
207 std::size_t countBoundarySegments = 0;
208 VertexIdMap vertexIdMap_;
209 InsertionIndexMap insertionIndexMap_;
210 unsigned int countElements = 0;
211 std::size_t countVertices = 0;
specialization of the GridFactory for MMesh InterfaceGrid
Definition: gridfactory.hh:21
FieldVector< ctype, dimensionworld > WorldVector
type of vector for world coordinates
Definition: gridfactory.hh:42
unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
return insertion index of vertex entity
Definition: gridfactory.hh:172
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)
insert a boundary segment into the macro grid
Definition: gridfactory.hh:97
GridFactory()
Definition: gridfactory.hh:69
Grid::GridPtrType createGrid()
finalize grid creation and hand over the grid
Definition: gridfactory.hh:187
void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
insert an element into the macro grid
Definition: gridfactory.hh:78
void insertVertex(const WorldVector &pos)
Insert a vertex into the macro grid.
Definition: gridfactory.hh:124
unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
return insertion index of entity
Definition: gridfactory.hh:152
FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix
type of matrix from world coordinates to world coordinates
Definition: gridfactory.hh:44
GridFactory(const std::shared_ptr< MMesh > mMesh)
Definition: gridfactory.hh:66
MMeshImp MMesh
type of corresponding mmesh
Definition: gridfactory.hh:34
MMeshInterfaceGrid< MMeshImp > Grid
type of interface grid
Definition: gridfactory.hh:26
Grid::ctype ctype
type of (scalar) coordinates
Definition: gridfactory.hh:29
void addVertexHandle(const VertexHandle &vh)
Add existing vertex handle from the macro grid to the interface grid.
Definition: gridfactory.hh:141
Provides a DUNE grid interface class for the interface of a MMesh interface grid .
Definition: grid.hh:90
typename MMesh::HostGridType HostGridType
the underlying hostgrid
Definition: grid.hh:115
std::unique_ptr< GridImp > GridPtrType
the unique pointer to the grid
Definition: grid.hh:112
FieldType ctype
The type used to store coordinates, inherited from the MMesh.
Definition: grid.hh:124
Hash a UInt vector.
Definition: common.hh:13