Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
Polyhedron.h
Go to the documentation of this file.
1/* This file is part of MoDELib, distributed under GNU GPL v2. */
2#ifndef model_Polyhedron_H_
3#define model_Polyhedron_H_
4#include <Eigen/Dense>
5#include <StaticID.h>
7#include <map>
8#include <set>
9#include <memory>
10#include <vector>
11#include <type_traits>
12
13namespace model
14{
15 template <short int dim, short int order> class Simplex;
16 template <int dim> struct Plane;
17 template <int dim> class PolyhedralMesh;
18 template <int dim> class SimplicialMesh;
19 template <int dim, int order> struct Polyhedron;
20 template <int dim, int order> struct PolyhedronFactory;
21 template <int dim, int order>
22 using PolyhedronKey = std::conditional_t<(order >= dim - 1), size_t, std::vector<size_t>>;
23
24 template <int dim, int order, bool enabled = (order > 0)> struct PolyhedralChildren
25 {
26 using Child = Polyhedron<dim, order - 1>;
27 using Children = std::map<PolyhedronKey<dim, order - 1>, std::shared_ptr<Child>>;
29 };
30 template <int dim, int order> struct PolyhedralChildren<dim, order, false>
31 {
32 };
33 template <int dim, int order, bool enabled = (order < dim)> struct PolyhedralParents
34 {
35 using Parent = Polyhedron<dim, order + 1>;
36 std::map<PolyhedronKey<dim, order + 1>, std::weak_ptr<Parent>> parents;
37 };
38 template <int dim, int order> struct PolyhedralParents<dim, order, false>
39 {
40 };
41
42 // An oriented edge of a polygonal 2-cell, including regions in 2D.
43 template <int dim> struct PolyhedralFaceIncidence
44 {
45 std::weak_ptr<Polyhedron<dim, 2>> face;
46 std::shared_ptr<Polyhedron<dim, 1>> edge;
47 size_t index;
49 std::shared_ptr<Polyhedron<dim, 0>> source() const;
50 std::shared_ptr<Polyhedron<dim, 0>> sink() const;
51 Eigen::Matrix<double, dim, 1> tangent() const;
52 Eigen::Matrix<double, dim, 1> outNormal(size_t regionID) const
53 requires(dim == 3);
56 PolyhedralFaceIncidence otherFace(size_t regionID) const
57 requires(dim == 3);
58 };
59 template <int dim, int order> struct PolyhedralGeometry
60 {
61 };
62 template <int dim> struct PolyhedralGeometry<dim, 0>
63 {
64 Eigen::Matrix<double, dim, 1> position = Eigen::Matrix<double, dim, 1>::Zero();
65 };
66 template <int dim> struct PolyhedralGeometry<dim, 1>
67 {
68 std::map<PolyhedronKey<dim, 2>, size_t> faceIncidences;
69 };
70 template <int dim> struct PolyhedralGeometry<dim, 2>
71 {
72 std::vector<PolyhedralFaceIncidence<dim>> perimeter;
73 };
74 template <int dim, int order, bool face = (order == dim - 1)> struct PolyhedralFaceData
75 {
76 template <typename Key> explicit PolyhedralFaceData(const Key &)
77 {
78 }
79 };
80 template <int dim, int order> struct PolyhedralFaceData<dim, order, true>
81 {
82 using VectorDim = Eigen::Matrix<double, dim, 1>;
83 const size_t sID;
84 explicit PolyhedralFaceData(size_t id) : sID(id)
85 {
86 }
87 std::pair<int, int> regionIDs{-1, -1};
88 VectorDim n = VectorDim::Zero();
89 VectorDim c = VectorDim::Zero();
90 std::vector<const Simplex<dim, 0> *> hull;
91 std::pair<VectorDim, const Polyhedron<dim, order> *> periodicFacePair{VectorDim::Zero(), nullptr};
92 };
93 template <int dim, int order, bool region = (order == dim)> struct PolyhedralRegionData
94 {
95 template <typename Key> explicit PolyhedralRegionData(const Key &)
96 {
97 }
98 };
99 template <int dim, int order> struct PolyhedralRegionData<dim, order, true>
100 {
101 const size_t regionID;
102 explicit PolyhedralRegionData(size_t id) : regionID(id)
103 {
104 }
105 };
106
107 template <int dim, int order>
108 struct Polyhedron : PolyhedralChildren<dim, order>,
109 PolyhedralParents<dim, order>,
110 PolyhedralGeometry<dim, order>,
111 PolyhedralFaceData<dim, order>,
112 PolyhedralRegionData<dim, order>,
113 std::set<const Simplex<dim, order> *>
114 {
115 static_assert(order >= 0 && order <= dim);
117 using CompareType = std::less<KeyType>;
118 using VectorDim = Eigen::Matrix<double, dim, 1>;
120 using SimplexContainerType = std::set<const SimplexType *>;
121 using MeshFacesContainerType = std::map<size_t, std::shared_ptr<Polyhedron<dim, dim - 1>>>;
125 : PolyhedralFaceData<dim, order>(id), PolyhedralRegionData<dim, order>(id), key(id), cellFactory(factory)
126 {
127 }
129 {
130 return *this;
131 }
133 {
134 return *this;
135 }
137 requires(order == dim)
138 {
139 return this->children;
140 }
142 requires(order == dim)
143 {
144 return this->children;
145 }
146 bool isExternal() const
147 requires(order == dim - 1)
148 {
149 return this->parents.size() == 1;
150 }
151 void initialize(const SimplexType *simplex)
152 requires(order == dim - 1);
154 requires(order == dim - 1)
155 {
156 return *this;
157 }
158 const std::vector<const Simplex<dim, 0> *> &convexHull() const
159 requires(order == dim - 1);
160 void finalize()
161 requires(order == dim - 1);
163 requires(order == dim - 1);
164 VectorDim outNormal(const int &regionID) const
165 requires(order == dim - 1);
166 const VectorDim &center() const
167 requires(order == dim - 1);
168 Plane<dim> asPlane() const
169 requires(order == dim - 1);
170 VectorDim outNormal(const std::set<size_t> &ids) const
171 requires(order == dim);
172 void update()
173 requires(order == dim);
174
175 private:
176 void buildFaces()
177 requires(order == dim);
178 void buildSingleFace(const Simplex<dim, dim - 1> *start, std::shared_ptr<Polyhedron<dim, dim - 1>> face,
179 std::map<std::vector<size_t>, const Simplex<dim, dim - 1> *> &remaining)
180 requires(order == dim);
181 };
182 template <int dim, int order>
187} // namespace model
188#endif
the R vector(source to field) R
std::conditional_t<(order >=dim - 1), size_t, std::vector< size_t > > PolyhedronKey
Definition Polyhedron.h:22
Polyhedron< dim, order - 1 > Child
Definition Polyhedron.h:26
std::map< PolyhedronKey< dim, order - 1 >, std::shared_ptr< Child > > Children
Definition Polyhedron.h:27
std::pair< VectorDim, const Polyhedron< dim, order > * > periodicFacePair
Definition Polyhedron.h:91
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Polyhedron.h:82
std::vector< const Simplex< dim, 0 > * > hull
Definition Polyhedron.h:90
PolyhedralFaceData(const Key &)
Definition Polyhedron.h:76
std::weak_ptr< Polyhedron< dim, 2 > > face
Definition Polyhedron.h:45
PolyhedralFaceIncidence prev() const
Eigen::Matrix< double, dim, 1 > outNormal(size_t regionID) const
PolyhedralFaceIncidence next() const
PolyhedralFaceIncidence otherFace(size_t regionID) const
std::shared_ptr< Polyhedron< dim, 0 > > sink() const
std::shared_ptr< Polyhedron< dim, 0 > > source() const
Eigen::Matrix< double, dim, 1 > tangent() const
std::shared_ptr< Polyhedron< dim, 1 > > edge
Definition Polyhedron.h:46
Eigen::Matrix< double, dim, 1 > position
Definition Polyhedron.h:64
std::map< PolyhedronKey< dim, 2 >, size_t > faceIncidences
Definition Polyhedron.h:68
std::vector< PolyhedralFaceIncidence< dim > > perimeter
Definition Polyhedron.h:72
std::map< PolyhedronKey< dim, order+1 >, std::weak_ptr< Parent > > parents
Definition Polyhedron.h:36
PolyhedralRegionData(const Key &)
Definition Polyhedron.h:95
PolyhedralMesh< dim > * owner
Definition Polyhedron.h:185
std::set< const SimplexType * > SimplexContainerType
Definition Polyhedron.h:120
MeshFacesContainerType & faces()
Definition Polyhedron.h:141
PolyhedronKey< dim, order > KeyType
Definition Polyhedron.h:116
Polyhedron(PolyhedronFactory< dim, order > &factory, const KeyType &id)
Definition Polyhedron.h:124
Plane< dim > asPlane() const
SimplexContainerType & simplices()
Definition Polyhedron.h:132
PolyhedronFactory< dim, order > & cellFactory
Definition Polyhedron.h:123
std::less< KeyType > CompareType
Definition Polyhedron.h:117
std::map< size_t, std::shared_ptr< Polyhedron< dim, dim - 1 > > > MeshFacesContainerType
Definition Polyhedron.h:121
const MeshFacesContainerType & faces() const
Definition Polyhedron.h:136
const SimplexContainerType & simplices() const
Definition Polyhedron.h:128
const VectorDim & center() const
bool isExternal() const
Definition Polyhedron.h:146
const SimplexContainerType & internalSimplices() const
Definition Polyhedron.h:153
Simplex< dim, order > SimplexType
Definition Polyhedron.h:119
Eigen::Matrix< double, dim, 1 > VectorDim
Definition Polyhedron.h:118
void initialize(const SimplexType *simplex)
const std::vector< const Simplex< dim, 0 > * > & convexHull() const
b order