dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
interface/gridfactory.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
5#define DUNE_MMESH_INTERFACE_GRIDFACTORY_HH
6
7// Dune includes
9#include <dune/grid/common/gridfactory.hh>
10
11namespace Dune {
12
19template <class MMeshImp>
21 : public GridFactoryInterface<MMeshInterfaceGrid<MMeshImp> > {
23
24 public:
27
29 typedef typename Grid::ctype ctype;
30 typedef typename Grid::HostGridType HostGrid;
31 typedef typename HostGrid::Vertex_handle VertexHandle;
32
34 typedef MMeshImp MMesh;
35
37 static const int dimension = Grid::dimension;
39 static const int dimensionworld = Grid::dimensionworld;
40
45
51
53
54 template <int codim>
55 struct Codim {
56 typedef typename Grid::template Codim<codim>::Entity Entity;
57 };
58
59 public:
61 static const bool supportsBoundaryIds = true;
63 static const bool supportPeriodicity = false;
64
66 GridFactory(const std::shared_ptr<MMesh> mMesh) : mMesh_(mMesh) {}
67
70 DUNE_THROW(NotImplemented, "GridFactory() for MMeshInterfaceGrid");
71 }
72
78 void insertElement(const GeometryType &type,
79 const std::vector<unsigned int> &vertices) {
80 // mark vertices as interface segment in host mmesh
82 for (const auto &v : vertices) ids.push_back(vertexIdMap_.at(v));
83
84 std::sort(ids.begin(), ids.end());
85
86 (mMesh_->interfaceSegments()).insert(std::make_pair(ids, 1));
87
88 insertionIndexMap_.insert({ids, countElements++});
89 };
90
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());
103
104 if (boundarySegments_.find(sorted_vertices) != boundarySegments_.end())
105 DUNE_THROW(GridError, "A boundary segment was inserted twice.");
106
107 boundarySegments_.insert(
108 std::make_pair(sorted_vertices, countBoundarySegments++));
109 }
110
112 const std::vector<unsigned int> &vertices,
113 const std::shared_ptr<BoundarySegment> &boundarySegment) {
115 "insertBoundarySegments with Dune::BoundarySegment");
116 }
117
124 void insertVertex(const WorldVector &pos) {
125 // get the vertex handle from the host mmesh
126 VertexHandle vh = mMesh_->getHostGrid().insert(makePoint(pos));
127
128 vertexIdMap_.insert({countVertices, vh->info().id});
129 vh->info().isInterface = true;
130
131 countVertices++;
132 }
133
142 vertexIdMap_.insert({countVertices, vh->info().id});
143 vh->info().isInterface = true;
144
145 countVertices++;
146 }
147
152 unsigned int insertionIndex(const typename Codim<0>::Entity &entity) const {
154 for (std::size_t i = 0; i < entity.subEntities(dimension); ++i)
155 ids.push_back(entity.template subEntity<dimension>(i)
156 .impl()
157 .hostEntity()
158 ->info()
159 .id);
160 std::sort(ids.begin(), ids.end());
161 auto it = insertionIndexMap_.find(ids);
162 if (it != insertionIndexMap_.end())
163 return it->second;
164 else
165 return 0; // should not happen
166 }
167
172 unsigned int insertionIndex(
173 const typename Codim<dimension>::Entity &entity) const {
174 std::size_t index = mMesh_->interfaceGrid().leafIndexSet().index(entity);
176 return index;
177 }
178
190 "The interface grid cannot be created, get the pointer by getGrid()!");
191 return nullptr;
192 }
193
194 auto getGrid() {
195 mMesh_->interfaceGridPtr()->setIds();
196 mMesh_->interfaceGridPtr()->setIndices();
197 mMesh_->interfaceGridPtr()->setBoundarySegments(boundarySegments_);
198
199 // Return pointer to grid
200 return mMesh_->interfaceGridPtr();
201 }
202
203 private:
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;
212};
213
214} // end namespace Dune
215
216#endif
void insert(const T &v)
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
static auto makePoint(const Dune::FieldVector< ctype, 2 > &v)
Convert FieldVector to CGAL Point 2.
Definition pointfieldvector.hh:63
const EntityType & entity() const
Hash a UInt vector.
Definition grid/common.hh:13
Provides a DUNE grid interface class for the interface of a MMesh interface grid .
Definition mmesh/interface/grid.hh:90
typename MMesh::HostGridType HostGridType
the underlying hostgrid
Definition mmesh/interface/grid.hh:115
FieldType ctype
The type used to store coordinates, inherited from the MMesh.
Definition mmesh/interface/grid.hh:124
specialization of the GridFactory for MMesh InterfaceGrid
Definition interface/gridfactory.hh:21
FieldVector< ctype, dimensionworld > WorldVector
type of vector for world coordinates
Definition interface/gridfactory.hh:42
unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
return insertion index of vertex entity
Definition interface/gridfactory.hh:172
auto getGrid()
Definition interface/gridfactory.hh:194
std::unordered_map< std::vector< std::size_t >, std::size_t, HashUIntVector > BoundarySegments
Definition interface/gridfactory.hh:49
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)
insert a boundary segment into the macro grid
Definition interface/gridfactory.hh:97
std::map< std::vector< std::size_t >, unsigned int > InsertionIndexMap
Definition interface/gridfactory.hh:50
GridFactory()
Definition interface/gridfactory.hh:69
Grid::GridPtrType createGrid()
finalize grid creation and hand over the grid
Definition interface/gridfactory.hh:187
void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
insert an element into the macro grid
Definition interface/gridfactory.hh:78
void insertVertex(const WorldVector &pos)
Insert a vertex into the macro grid.
Definition interface/gridfactory.hh:124
unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
return insertion index of entity
Definition interface/gridfactory.hh:152
FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix
type of matrix from world coordinates to world coordinates
Definition interface/gridfactory.hh:44
GridFactory(const std::shared_ptr< MMesh > mMesh)
Definition interface/gridfactory.hh:66
std::map< std::size_t, std::size_t > VertexIdMap
Definition interface/gridfactory.hh:52
Dune::BoundarySegment< dimension, dimensionworld > BoundarySegment
Definition interface/gridfactory.hh:46
MMeshImp MMesh
type of corresponding mmesh
Definition interface/gridfactory.hh:34
void insertBoundarySegment(const std::vector< unsigned int > &vertices, const std::shared_ptr< BoundarySegment > &boundarySegment)
Definition interface/gridfactory.hh:111
MMeshInterfaceGrid< MMeshImp > Grid
type of interface grid
Definition interface/gridfactory.hh:26
Grid::ctype ctype
type of (scalar) coordinates
Definition interface/gridfactory.hh:29
Grid::HostGridType HostGrid
Definition interface/gridfactory.hh:30
void addVertexHandle(const VertexHandle &vh)
Add existing vertex handle from the macro grid to the interface grid.
Definition interface/gridfactory.hh:141
HostGrid::Vertex_handle VertexHandle
Definition interface/gridfactory.hh:31
Grid::template Codim< codim >::Entity Entity
Definition interface/gridfactory.hh:56
T begin(T... args)
T end(T... args)
T make_pair(T... args)
T push_back(T... args)
T sort(T... args)