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/grid/common/geometry.hh>
15#include <dune/geometry/affinegeometry.hh>
26 template<
int mydim,
int coorddim,
class Gr
idImp>
31 template<
int md,
class Gr
idImp>
33 public AffineGeometry <typename GridImp::ctype, md, 2>
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;
42 enum { dimension = GridImp::dimension };
43 enum { dimensionworld = GridImp::dimensionworld };
44 enum { coorddimension = coorddim };
45 enum { mydimension = mydim };
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 } )
56 MMeshGeometry(
const typename GridImp::template HostGridEntity<0>& hostEntity)
57 : BaseType( GeometryTypes::simplex(mydim), getVertices(hostEntity) )
61 : BaseType( GeometryTypes::simplex(mydim), points )
65 MMeshGeometry(
const typename GridImp::template HostGridEntity<1>& hostEntity)
66 : BaseType( GeometryTypes::simplex(mydim), getVertices(hostEntity) )
71 : BaseType( GeometryTypes::simplex(mydim), getLocalVertices_( idx ) )
75 MMeshGeometry(
const typename GridImp::template HostGridEntity<2>& hostEntity)
76 : BaseType( GeometryTypes::simplex(mydim),
std::array<FVector, 1>( { makeFieldVector( hostEntity->point() ) } ) )
86 static inline std::array<FVector, 3> getVertices (
const typename GridImp::template HostGridEntity<0> hostEntity )
88 const auto& cgalIdx = hostEntity->info().cgalIndex;
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() )
99 static inline std::array<FVector, 2> getVertices (
const typename GridImp::template HostGridEntity<1>& hostEntity )
101 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
103 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<2, typename GridImp::template HostGridEntity<1>>( hostEntity );
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() );
112 static inline std::array<FVector, 2> getLocalVertices_ (
int k )
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 } )
120 return { local[ k==2 ? 1 : 0 ], local[ k==0 ? 1 : 2 ] };
126 template<
int md,
class Gr
idImp>
128 public AffineGeometry <typename GridImp::ctype, md, 3>
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;
138 enum { dimension = GridImp::dimension };
139 enum { dimensionworld = GridImp::dimensionworld };
140 enum { coorddimension = coorddim };
141 enum { mydimension = mydim };
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 } )
153 MMeshGeometry(
const typename GridImp::template HostGridEntity<0>& hostEntity)
154 : BaseType( GeometryTypes::simplex(mydim), getVertices<0>(hostEntity) )
158 : BaseType( GeometryTypes::simplex(mydim), points )
162 MMeshGeometry(
const typename GridImp::template HostGridEntity<1>& hostEntity)
163 : BaseType( GeometryTypes::simplex(mydim), getVertices<1>(hostEntity) )
168 : BaseType( GeometryTypes::simplex(mydim), getLocalVertices_( idx ) )
172 MMeshGeometry(
const typename GridImp::template HostGridEntity<2>& hostEntity)
173 : BaseType( GeometryTypes::simplex(mydim), getVertices<2>( hostEntity ) )
177 MMeshGeometry(
const typename GridImp::template HostGridEntity<3>& hostEntity)
178 : BaseType( GeometryTypes::simplex(mydim),
std::array<FVector, 1>( { makeFieldVector( hostEntity->point() ) } ) )
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 )
192 const auto& cgalIdx = hostEntity->info().cgalIndex;
194 std::array<FVector, 4> vertices;
195 for (
int i = 0; i < 4; ++i )
196 vertices[i] = makeFieldVector( hostEntity->vertex( cgalIdx[i] )->point() );
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 )
203 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
204 const auto& cell = hostEntity.first;
206 auto facetIdx = MMeshImpl::cgalFacetToDuneFacet<3, typename GridImp::template HostGridEntity<1>>( hostEntity );
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() );
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 )
217 const auto& cgalIdx = hostEntity.first->info().cgalIndex;
218 const auto& cell = hostEntity.first;
220 auto edgeIdx = MMeshImpl::cgalEdgeToDuneEdge<3, typename GridImp::template HostGridEntity<2>>( hostEntity );
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() );
229 static inline std::array<FVector, 3> getLocalVertices_ (
int k )
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 } )
238 return { local[ k<=2 ? 0 : 1 ], local[ k<=1 ? 1 : 2 ], local[ k==0 ? 2 : 3 ] };
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
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
auto computeCircumcenter(const Geometry &geo)
Compute circumcenter.
Definition: pointfieldvector.hh:82