Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (unstable)

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