Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

geometry.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#ifndef DUNE_MMESH_GRID_GEOMETRY_HH
4#define DUNE_MMESH_GRID_GEOMETRY_HH
5
11// Dune includes
12#include <dune/common/fmatrix.hh>
13#include <dune/common/typetraits.hh>
14#include <dune/grid/common/geometry.hh>
15#include <dune/geometry/affinegeometry.hh>
16
17// local includes
19
20namespace Dune
21{
22
26 template<int mydim, int coorddim, class GridImp>
27 class MMeshGeometry {};
28
30
31 template<int md, class GridImp>
32 class MMeshGeometry<md, 2, GridImp> :
33 public AffineGeometry <typename GridImp::ctype, md, 2>
34 {
35 public:
36 static constexpr int mydim = md;
37 static constexpr int coorddim = 2;
38 typedef AffineGeometry <typename GridImp::ctype, mydim, coorddim> BaseType;
39 typedef FieldVector<typename GridImp::ctype, coorddim> FVector;
40 typedef typename GridImp::LeafIntersection Intersection;
41
42 enum { dimension = GridImp::dimension };
43 enum { dimensionworld = GridImp::dimensionworld };
44 enum { coorddimension = coorddim };
45 enum { mydimension = mydim };
46
47 explicit MMeshGeometry()
48 : BaseType(GeometryTypes::simplex(mydim),
49 std::array<FVector, 3>( {
50 FVector( { 0.0, 0.0 } ),
51 FVector( { 1.0, 0.0 } ),
52 FVector( { 0.0, 1.0 } )
53 } ) ) {}
54
56 MMeshGeometry(const typename GridImp::template HostGridEntity<0>& hostEntity)
57 : BaseType( GeometryTypes::simplex(mydim), getVertices(hostEntity) )
58 {}
59
60 MMeshGeometry(const std::array<FVector, 3> points)
61 : BaseType( GeometryTypes::simplex(mydim), points )
62 {}
63
65 MMeshGeometry(const typename GridImp::template HostGridEntity<1>& hostEntity)
66 : BaseType( GeometryTypes::simplex(mydim), getVertices(hostEntity) )
67 {}
68
70 MMeshGeometry( int idx )
71 : BaseType( GeometryTypes::simplex(mydim), getLocalVertices_( idx ) )
72 {}
73
75 MMeshGeometry(const typename GridImp::template HostGridEntity<2>& hostEntity)
76 : BaseType( GeometryTypes::simplex(mydim), std::array<FVector, 1>( { makeFieldVector( hostEntity->point() ) } ) )
77 {}
78
80 const FVector circumcenter () const
81 {
82 return computeCircumcenter(*this);
83 }
84
85 private:
86 static inline std::array<FVector, 3> getVertices ( const typename GridImp::template HostGridEntity<0> hostEntity )
87 {
88 const auto& cgalIdx = hostEntity->info().cgalIndex;
89
90 std::array<FVector, 3> vertices ( {
91 makeFieldVector( hostEntity->vertex(cgalIdx[0])->point() ),
92 makeFieldVector( hostEntity->vertex(cgalIdx[1])->point() ),
93 makeFieldVector( hostEntity->vertex(cgalIdx[2])->point() )
94 } );
95
96 return vertices;
97 }
98
99 static inline std::array<FVector, 2> getVertices ( const typename GridImp::template HostGridEntity<1>& hostEntity )
100 {
101 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
102
103 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<2, typename GridImp::template HostGridEntity<1>>( hostEntity );
104
105 std::array<FVector, 2> vertices;
106 for ( int k = 0; k < 2; ++k )
107 vertices[k] = makeFieldVector( hostEntity.first->vertex( cgalIdx[ MMeshImpl::ref<2>().subEntity(facetIdx, 1, k, 2) ] )->point() );
108
109 return vertices;
110 }
111
112 static inline std::array<FVector, 2> getLocalVertices_ ( int k )
113 {
114 static const std::array<FVector, 3> local = {
115 FVector( { 0.0, 0.0 } ),
116 FVector( { 1.0, 0.0 } ),
117 FVector( { 0.0, 1.0 } )
118 };
119
120 return { local[ k==2 ? 1 : 0 ], local[ k==0 ? 1 : 2 ] };
121 }
122 };
123
125
126 template<int md, class GridImp>
127 class MMeshGeometry<md, 3, GridImp> :
128 public AffineGeometry <typename GridImp::ctype, md, 3>
129 {
130 public:
131 static constexpr int mydim = md;
132 static constexpr int coorddim = 3;
133 typedef AffineGeometry <typename GridImp::ctype, mydim, coorddim> BaseType;
134 typedef typename GridImp::ctype ctype;
135 typedef FieldVector<ctype, coorddim> FVector;
136 typedef typename GridImp::LeafIntersection Intersection;
137
138 enum { dimension = GridImp::dimension };
139 enum { dimensionworld = GridImp::dimensionworld };
140 enum { coorddimension = coorddim };
141 enum { mydimension = mydim };
142
143 explicit MMeshGeometry()
144 : BaseType(GeometryTypes::simplex(mydim),
145 std::array<FVector, 4>( {
146 FVector( { 0.0, 0.0, 0.0 } ),
147 FVector( { 1.0, 0.0, 0.0 } ),
148 FVector( { 0.0, 1.0, 0.0 } ),
149 FVector( { 0.0, 0.0, 1.0 } )
150 } ) ) {}
151
153 MMeshGeometry(const typename GridImp::template HostGridEntity<0>& hostEntity)
154 : BaseType( GeometryTypes::simplex(mydim), getVertices<0>(hostEntity) )
155 {}
156
157 MMeshGeometry(const std::array<FVector, 4> points)
158 : BaseType( GeometryTypes::simplex(mydim), points )
159 {}
160
162 MMeshGeometry(const typename GridImp::template HostGridEntity<1>& hostEntity)
163 : BaseType( GeometryTypes::simplex(mydim), getVertices<1>(hostEntity) )
164 {}
165
167 MMeshGeometry( int idx )
168 : BaseType( GeometryTypes::simplex(mydim), getLocalVertices_( idx ) )
169 {}
170
172 MMeshGeometry(const typename GridImp::template HostGridEntity<2>& hostEntity)
173 : BaseType( GeometryTypes::simplex(mydim), getVertices<2>( hostEntity ) )
174 {}
175
177 MMeshGeometry(const typename GridImp::template HostGridEntity<3>& hostEntity)
178 : BaseType( GeometryTypes::simplex(mydim), std::array<FVector, 1>( { makeFieldVector( hostEntity->point() ) } ) )
179 {}
180
182 const FVector circumcenter () const
183 {
184 return computeCircumcenter(*this);
185 }
186
187 private:
188
189 template< int codim, typename Enable = std::enable_if_t< codim == 0 > >
190 static inline std::array<FVector, 4> getVertices ( const typename GridImp::template HostGridEntity<0>& hostEntity )
191 {
192 const auto& cgalIdx = hostEntity->info().cgalIndex;
193
194 std::array<FVector, 4> vertices;
195 for ( int i = 0; i < 4; ++i )
196 vertices[i] = makeFieldVector( hostEntity->vertex( cgalIdx[i] )->point() );
197 return vertices;
198 }
199
200 template< int codim, typename Enable = std::enable_if_t< codim == 1 > >
201 static inline std::array<FVector, 3> getVertices ( const typename GridImp::template HostGridEntity<1>& hostEntity )
202 {
203 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
204 const auto& cell = hostEntity.first;
205
206 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<3, typename GridImp::template HostGridEntity<1>>( hostEntity );
207
208 std::array<FVector, 3> vertices;
209 for ( int i = 0; i < 3; ++i )
210 vertices[i] = makeFieldVector( cell->vertex( cgalIdx[ MMeshImpl::ref<3>().subEntity(facetIdx, 1, i, 3) ] )->point() );
211 return vertices;
212 }
213
214 template< int codim, typename Enable = std::enable_if_t< codim == 2 > >
215 static inline std::array<FVector, 2> getVertices ( const typename GridImp::template HostGridEntity<2>& hostEntity )
216 {
217 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
218 const auto& cell = hostEntity.first;
219
220 auto edgeIdx = MMeshImpl::cgalEdgeToDuneEdge<3, typename GridImp::template HostGridEntity<2>>( hostEntity );
221
222 std::array<FVector, 2> vertices;
223 vertices[0] = makeFieldVector( cell->vertex( cgalIdx[ MMeshImpl::ref<3>().subEntity(edgeIdx, 2, 0, 3) ] )->point() );
224 vertices[1] = makeFieldVector( cell->vertex( cgalIdx[ MMeshImpl::ref<3>().subEntity(edgeIdx, 2, 1, 3) ] )->point() );
225
226 return vertices;
227 }
228
229 static inline std::array<FVector, 3> getLocalVertices_ ( int k )
230 {
231 static const std::array<FVector, 4> local = {
232 FVector( { 0.0, 0.0, 0.0 } ),
233 FVector( { 1.0, 0.0, 0.0 } ),
234 FVector( { 0.0, 1.0, 0.0 } ),
235 FVector( { 0.0, 0.0, 1.0 } )
236 };
237
238 return { local[ k<=2 ? 0 : 1 ], local[ k<=1 ? 1 : 2 ], local[ k==0 ? 2 : 3 ] };
239 }
240 };
241
242} // namespace Dune
243
244#endif
const FVector circumcenter() const
Obtain the circumcenter.
Definition: geometry.hh:80
MMeshGeometry(const typename GridImp::template HostGridEntity< 0 > &hostEntity)
Constructor from host geometry with codim 0.
Definition: geometry.hh:56
MMeshGeometry(const typename GridImp::template HostGridEntity< 1 > &hostEntity)
Constructor from host geometry with codim 1.
Definition: geometry.hh:65
MMeshGeometry(const typename GridImp::template HostGridEntity< 2 > &hostEntity)
Constructor from host geometry with codim 2.
Definition: geometry.hh:75
MMeshGeometry(int idx)
Constructor of local intersection geometry.
Definition: geometry.hh:70
const FVector circumcenter() const
Obtain the circumcenter.
Definition: geometry.hh:182
MMeshGeometry(const typename GridImp::template HostGridEntity< 1 > &hostEntity)
Constructor from host geometry with codim 1.
Definition: geometry.hh:162
MMeshGeometry(const typename GridImp::template HostGridEntity< 2 > &hostEntity)
Constructor from host geometry with codim 1.
Definition: geometry.hh:172
MMeshGeometry(const typename GridImp::template HostGridEntity< 0 > &hostEntity)
Constructor from host geometry with codim 0.
Definition: geometry.hh:153
MMeshGeometry(const typename GridImp::template HostGridEntity< 3 > &hostEntity)
Constructor from host geometry with codim 3.
Definition: geometry.hh:177
MMeshGeometry(int idx)
Constructor of local intersection geometry.
Definition: geometry.hh:167
Geometry.
Definition: geometry.hh:27
STL namespace.
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
auto computeCircumcenter(const Geometry &geo)
Compute circumcenter.
Definition: pointfieldvector.hh:82
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 6, 22:49, 2025)