Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

gridfactory.hh
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
8#include <dune/grid/common/gridfactory.hh>
9#include <dune/grid/common/boundarysegment.hh>
10
11namespace Dune
12{
13
20 template< class MMeshImp >
21 class GridFactory< MMeshInterfaceGrid<MMeshImp> >
22 : public GridFactoryInterface< MMeshInterfaceGrid<MMeshImp> >
23 {
24 typedef GridFactory< MMeshInterfaceGrid<MMeshImp> > This;
25
26 public:
29
31 typedef typename Grid::ctype ctype;
32 typedef typename Grid::HostGridType HostGrid;
33 typedef typename HostGrid::Vertex_handle VertexHandle;
34
36 typedef MMeshImp MMesh;
37
39 static const int dimension = Grid::dimension;
41 static const int dimensionworld = Grid::dimensionworld;
42
44 typedef FieldVector< ctype, dimensionworld > WorldVector;
46 typedef FieldMatrix< ctype, dimensionworld, dimensionworld > WorldMatrix;
47
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;
51
52 typedef std::map< std::size_t, std::size_t > VertexIdMap;
53
54 template< int codim >
55 struct Codim
56 {
57 typedef typename Grid::template Codim< codim >::Entity Entity;
58 };
59
60 public:
62 static const bool supportsBoundaryIds = true;
64 static const bool supportPeriodicity = false;
65
67 GridFactory ( const std::shared_ptr<MMesh> mMesh )
68 : mMesh_( mMesh )
69 {}
70
73 {
74 DUNE_THROW(NotImplemented, "GridFactory() for MMeshInterfaceGrid");
75 }
76
82 void insertElement ( const GeometryType &type,
83 const std::vector< unsigned int > &vertices )
84 {
85 // mark vertices as interface segment in host mmesh
86 std::vector< std::size_t > ids;
87 for ( const auto& v : vertices )
88 ids.push_back( vertexIdMap_.at( v ) );
89
90 std::sort(ids.begin(), ids.end());
91
92 (mMesh_->interfaceSegments()).insert( std::make_pair(ids, 1) );
93
94 insertionIndexMap_.insert( { ids, countElements++ } );
95 };
96
103 virtual void insertBoundarySegment ( const std::vector< unsigned int >& vertices )
104 {
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());
109
110 if( boundarySegments_.find( sorted_vertices ) != boundarySegments_.end() )
111 DUNE_THROW( GridError, "A boundary segment was inserted twice." );
112
113 boundarySegments_.insert( std::make_pair( sorted_vertices, countBoundarySegments++ ) );
114 }
115
116 void insertBoundarySegment ( const std::vector< unsigned int >& vertices,
117 const std::shared_ptr< BoundarySegment >& boundarySegment )
118 {
119 DUNE_THROW( NotImplemented, "insertBoundarySegments with Dune::BoundarySegment" );
120 }
121
128 void insertVertex ( const WorldVector &pos )
129 {
130 // get the vertex handle from the host mmesh
131 VertexHandle vh = mMesh_->getHostGrid().insert( makePoint( pos ) );
132
133 vertexIdMap_.insert( { countVertices, vh->info().id } );
134 vh->info().isInterface = true;
135
136 countVertices++;
137 }
138
145 void addVertexHandle ( const VertexHandle &vh )
146 {
147 vertexIdMap_.insert( { countVertices, vh->info().id } );
148 vh->info().isInterface = true;
149
150 countVertices++;
151 }
152
157 unsigned int insertionIndex ( const typename Codim<0>::Entity &entity ) const
158 {
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() )
165 return it->second;
166 else
167 return 0; // should not happen
168 }
169
174 unsigned int insertionIndex ( const typename Codim< dimension >::Entity &entity ) const
175 {
176 std::size_t index = mMesh_->interfaceGrid().leafIndexSet().index( entity );
177 assert( index < std::numeric_limits<unsigned int>::max() );
178 return index;
179 }
180
190 {
191 DUNE_THROW( InvalidStateException, "The interface grid cannot be created, get the pointer by getGrid()!" );
192 return nullptr;
193 }
194
195 auto getGrid ()
196 {
197 mMesh_->interfaceGridPtr()->setIds();
198 mMesh_->interfaceGridPtr()->setIndices();
199 mMesh_->interfaceGridPtr()->setBoundarySegments( boundarySegments_ );
200
201 // Return pointer to grid
202 return mMesh_->interfaceGridPtr();
203 }
204
205 private:
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;
214 };
215
216} // end namespace Dune
217
218#endif
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
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 6, 22:49, 2025)