dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
interface/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_INTERFACE_GEOMETRY_HH
4#define DUNE_MMESH_INTERFACE_GEOMETRY_HH
5
11// Dune includes
15#include <dune/grid/common/geometry.hh>
16
17// local includes
20
21namespace Dune {
22
26template <int mydim, int coorddim, class GridImp>
28
30
31template <int md, class GridImp>
32class MMeshInterfaceGridGeometry<md, 2, GridImp>
33 : public AffineGeometry<typename GridImp::ctype, md, 2> {
34 public:
35 static constexpr int mydim = md;
36 static constexpr int coorddim = 2;
39
40 enum { dimension = GridImp::dimension };
41 enum { dimensionworld = GridImp::dimensionworld };
42 enum { coorddimension = coorddim };
43 enum { mydimension = mydim };
44
47 const typename GridImp::template MMeshInterfaceEntity<0>& hostEntity)
48 : BaseType(GeometryTypes::simplex(mydim), getVertices(hostEntity)) {}
49
52 : BaseType(GeometryTypes::simplex(mydim), points) {}
53
56 const typename GridImp::template MMeshInterfaceEntity<1>& hostEntity)
57 : BaseType(
58 GeometryTypes::simplex(mydim),
59 std::array<FVector, 1>({makeFieldVector(hostEntity->point())})) {}
60
64 : BaseType(GeometryTypes::simplex(1),
65 std::array<FVector, 2>(
66 {FVector({i == 2 ? 1.0 : 0.0, 0.0}),
67 FVector({i == 0 ? 1.0 : 0.0, i > 0 ? 1.0 : 0.0})})) {}
68
70 const FVector circumcenter() const { return computeCircumcenter(*this); }
71
72 private:
73 static inline std::array<FVector, 2> getVertices(
74 const typename GridImp::template MMeshInterfaceEntity<0>& hostEntity) {
75 const auto& cgalIdx = MMeshInterfaceImpl::computeCGALIndices<
76 typename GridImp::template MMeshInterfaceEntity<0>, 1>(hostEntity);
77
79 {makeFieldVector(hostEntity.first->vertex(cgalIdx[0])->point()),
80 makeFieldVector(hostEntity.first->vertex(cgalIdx[1])->point())});
81
82 return vertices;
83 }
84};
85
87
88template <int md, class GridImp>
89class MMeshInterfaceGridGeometry<md, 3, GridImp>
90 : public AffineGeometry<typename GridImp::ctype, md, 3> {
91 public:
92 static constexpr int mydim = md;
93 static constexpr int coorddim = 3;
95 typedef typename GridImp::ctype ctype;
97
98 enum { dimension = GridImp::dimension };
99 enum { dimensionworld = GridImp::dimensionworld };
100 enum { coorddimension = coorddim };
101 enum { mydimension = mydim };
102
105 const typename GridImp::template MMeshInterfaceEntity<0>& hostEntity)
106 : BaseType(GeometryTypes::simplex(mydim), getVertices<0>(hostEntity)) {}
107
110 : BaseType(GeometryTypes::simplex(mydim), points) {}
111
114 const typename GridImp::template MMeshInterfaceEntity<1>& hostEntity)
115 : BaseType(GeometryTypes::simplex(mydim), getVertices<1>(hostEntity)) {}
116
119 const typename GridImp::template MMeshInterfaceEntity<2>& hostEntity)
120 : BaseType(
121 GeometryTypes::simplex(mydim),
122 std::array<FVector, 1>({makeFieldVector(hostEntity->point())})) {}
123
125 const FVector circumcenter() const { return computeCircumcenter(*this); }
126
127 private:
128 template <int codim, typename Enable = std::enable_if_t<codim == 0> >
129 static inline std::array<FVector, 3> getVertices(
130 const typename GridImp::template MMeshInterfaceEntity<0>& hostEntity) {
131 const auto& cgalIdx = MMeshInterfaceImpl::computeCGALIndices<
132 typename GridImp::template MMeshInterfaceEntity<0>, 2>(hostEntity);
133
134 std::array<FVector, 3> vertices;
135
136 const auto& cell = hostEntity.first;
137
138 // use the CGAL index convention to obtain the vertices
139 for (int i = 0; i < 3; ++i)
140 vertices[i] = makeFieldVector(cell->vertex(cgalIdx[i])->point());
141
142 return vertices;
143 }
144
145 template <int codim, typename Enable = std::enable_if_t<codim == 1> >
146 static inline std::array<FVector, 2> getVertices(
147 const typename GridImp::template MMeshInterfaceEntity<1>& hostEntity) {
148 const auto& cell = hostEntity.first;
149 const auto& i = hostEntity.second;
150 const auto& j = hostEntity.third;
151
152 std::array<FVector, 2> vertices;
153 vertices[0] = makeFieldVector(cell->vertex(i)->point());
154 vertices[1] = makeFieldVector(cell->vertex(j)->point());
155
156 if (cell->vertex(i)->info().id > cell->vertex(j)->info().id)
157 std::swap(vertices[0], vertices[1]);
158
159 return vertices;
160 }
161};
162
164template <int md, class GridImp>
165class MMeshInterfaceGridGeometry<md, 1, GridImp>
166 : public AffineGeometry<typename GridImp::ctype, md, 1> {
167 public:
168 static constexpr int mydim = md;
169 static constexpr int coorddim = 1;
172
173 enum { dimension = GridImp::dimension };
174 enum { dimensionworld = GridImp::dimensionworld };
175 enum { coorddimension = coorddim };
176 enum { mydimension = mydim };
177
180 : BaseType(GeometryTypes::simplex(mydim), std::array<FVector, 1>({i})) {}
181
184 : BaseType(GeometryTypes::simplex(mydim), points) {}
185};
186
187} // namespace Dune
188
189#endif
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
STL namespace.
static auto computeCGALIndices(const HostEntity &hostEntity)
Return list of indices sorted by id.
Definition interface/common.hh:16
static FieldVector< typename Kernel::RT, 2 > makeFieldVector(const CGAL::Point_2< Kernel > &p)
Helper function to create DUNE::FieldVector from CGAL::Point_2.
Definition pointfieldvector.hh:20
auto computeCircumcenter(const Geometry &geo)
Compute circumcenter.
Definition pointfieldvector.hh:78
Geometry.
Definition interface/geometry.hh:27
const FVector circumcenter() const
Obtain the circumcenter.
Definition interface/geometry.hh:70
MMeshInterfaceGridGeometry(const typename GridImp::template MMeshInterfaceEntity< 1 > &hostEntity)
Constructor from host geometry with codim 1.
Definition interface/geometry.hh:55
AffineGeometry< typename GridImp::ctype, mydim, coorddim > BaseType
Definition interface/geometry.hh:37
MMeshInterfaceGridGeometry(const typename GridImp::template MMeshInterfaceEntity< 0 > &hostEntity)
Constructor from host geometry with codim 0.
Definition interface/geometry.hh:46
MMeshInterfaceGridGeometry(int i)
Definition interface/geometry.hh:63
FieldVector< typename GridImp::ctype, coorddim > FVector
Definition interface/geometry.hh:38
MMeshInterfaceGridGeometry(const std::array< FVector, 2 > &points)
Constructor from vertex array.
Definition interface/geometry.hh:51
FieldVector< ctype, coorddim > FVector
Definition interface/geometry.hh:96
MMeshInterfaceGridGeometry(const typename GridImp::template MMeshInterfaceEntity< 0 > &hostEntity)
Constructor from host geometry with codim 0.
Definition interface/geometry.hh:104
MMeshInterfaceGridGeometry(const std::array< FVector, 3 > &points)
Constructor from vertex list.
Definition interface/geometry.hh:109
GridImp::ctype ctype
Definition interface/geometry.hh:95
MMeshInterfaceGridGeometry(const typename GridImp::template MMeshInterfaceEntity< 2 > &hostEntity)
Constructor from host geometry with codim 2.
Definition interface/geometry.hh:118
const FVector circumcenter() const
Obtain the circumcenter.
Definition interface/geometry.hh:125
MMeshInterfaceGridGeometry(const typename GridImp::template MMeshInterfaceEntity< 1 > &hostEntity)
Constructor from host geometry with codim 1.
Definition interface/geometry.hh:113
AffineGeometry< typename GridImp::ctype, mydim, coorddim > BaseType
Definition interface/geometry.hh:94
FieldVector< typename GridImp::ctype, coorddim > FVector
Definition interface/geometry.hh:171
MMeshInterfaceGridGeometry(const std::array< FVector, 2 > &points)
Constructor from vertex array.
Definition interface/geometry.hh:183
AffineGeometry< typename GridImp::ctype, mydim, coorddim > BaseType
Definition interface/geometry.hh:170
MMeshInterfaceGridGeometry(int i)
Constructor for local geometry of intersection from intersection index.
Definition interface/geometry.hh:179
Some common helper methods.
T swap(T... args)