3#ifndef DUNE_MMESH_GRID_GEOMETRY_HH
4#define DUNE_MMESH_GRID_GEOMETRY_HH
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>
25template <
int mydim,
int coorddim,
class Gr
idImp>
30template <
int md,
class Gr
idImp>
32 :
public AffineGeometry<typename GridImp::ctype, md, 2> {
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;
40 enum { dimension = GridImp::dimension };
41 enum { dimensionworld = GridImp::dimensionworld };
42 enum { coorddimension = coorddim };
43 enum { mydimension = mydim };
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})})) {}
52 MMeshGeometry(
const typename GridImp::template HostGridEntity<0>& hostEntity)
53 : BaseType(GeometryTypes::simplex(mydim), getVertices(hostEntity)) {}
56 : BaseType(GeometryTypes::simplex(mydim), points) {}
59 MMeshGeometry(
const typename GridImp::template HostGridEntity<1>& hostEntity)
60 : BaseType(GeometryTypes::simplex(mydim), getVertices(hostEntity)) {}
64 : BaseType(GeometryTypes::simplex(mydim), getLocalVertices_(idx)) {}
67 MMeshGeometry(
const typename GridImp::template HostGridEntity<2>& hostEntity)
69 GeometryTypes::simplex(mydim),
70 std::array<FVector, 1>({makeFieldVector(hostEntity->point())})) {}
76 static inline std::array<FVector, 3> getVertices(
77 const typename GridImp::template HostGridEntity<0> hostEntity) {
78 const auto& cgalIdx = hostEntity->info().cgalIndex;
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())});
88 static inline std::array<FVector, 2> getVertices(
89 const typename GridImp::template HostGridEntity<1>& hostEntity) {
90 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
92 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<
93 2,
typename GridImp::template HostGridEntity<1>>(hostEntity);
95 std::array<FVector, 2> vertices;
96 for (
int k = 0; k < 2; ++k)
97 vertices[k] = makeFieldVector(
100 cgalIdx[MMeshImpl::ref<2>().subEntity(facetIdx, 1, k, 2)])
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})};
110 return {local[k == 2 ? 1 : 0], local[k == 0 ? 1 : 2]};
116template <
int md,
class Gr
idImp>
118 :
public AffineGeometry<typename GridImp::ctype, md, 3> {
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;
127 enum { dimension = GridImp::dimension };
128 enum { dimensionworld = GridImp::dimensionworld };
129 enum { coorddimension = coorddim };
130 enum { mydimension = mydim };
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})})) {}
139 MMeshGeometry(
const typename GridImp::template HostGridEntity<0>& hostEntity)
140 : BaseType(GeometryTypes::simplex(mydim), getVertices<0>(hostEntity)) {}
143 : BaseType(GeometryTypes::simplex(mydim), points) {}
146 MMeshGeometry(
const typename GridImp::template HostGridEntity<1>& hostEntity)
147 : BaseType(GeometryTypes::simplex(mydim), getVertices<1>(hostEntity)) {}
151 : BaseType(GeometryTypes::simplex(mydim), getLocalVertices_(idx)) {}
154 MMeshGeometry(
const typename GridImp::template HostGridEntity<2>& hostEntity)
155 : BaseType(GeometryTypes::simplex(mydim), getVertices<2>(hostEntity)) {}
158 MMeshGeometry(
const typename GridImp::template HostGridEntity<3>& hostEntity)
160 GeometryTypes::simplex(mydim),
161 std::array<FVector, 1>({makeFieldVector(hostEntity->point())})) {}
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;
172 std::array<FVector, 4> vertices;
173 for (
int i = 0; i < 4; ++i)
174 vertices[i] = makeFieldVector(hostEntity->vertex(cgalIdx[i])->point());
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;
184 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<
185 3,
typename GridImp::template HostGridEntity<1>>(hostEntity);
187 std::array<FVector, 3> vertices;
188 for (
int i = 0; i < 3; ++i)
189 vertices[i] = makeFieldVector(
191 cgalIdx[MMeshImpl::ref<3>().subEntity(facetIdx, 1, i, 3)])
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;
202 auto edgeIdx = MMeshImpl::cgalEdgeToDuneEdge<
203 3,
typename GridImp::template HostGridEntity<2>>(hostEntity);
205 std::array<FVector, 2> vertices;
206 vertices[0] = makeFieldVector(
207 cell->vertex(cgalIdx[MMeshImpl::ref<3>().subEntity(edgeIdx, 2, 0, 3)])
209 vertices[1] = makeFieldVector(
210 cell->vertex(cgalIdx[MMeshImpl::ref<3>().subEntity(edgeIdx, 2, 1, 3)])
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})};
221 return {local[k <= 2 ? 0 : 1], local[k <= 1 ? 1 : 2],
222 local[k == 0 ? 2 : 3]};
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
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
auto computeCircumcenter(const Geometry &geo)
Compute circumcenter.
Definition: pointfieldvector.hh:78