Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SimplexTraits.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_SimplexTraits_H_
9#define model_SimplexTraits_H_
10
11#include <iostream>
12#include <memory> // shared_ptr
13#include <array> // std::array
14#include <set>
15#include <Eigen/Dense>
16
17namespace model
18{
19
20
21 template<short int dim, short int order>
22 class Simplex;
23
24 template<short int dim,short int order>
25 class SimplexChild;
26
27 template<short int nVertices>
28 struct SimplexID : public std::array<size_t,nVertices>
29 {
30 typedef size_t ScalarIDType;
31 typedef typename std::array<size_t,nVertices>::size_type size_type;
32
33 SimplexID(const std::set<size_t>& set)
34 {
35 if(set.size()==nVertices)
36 {
37 int k(0);
38 for (const size_t& m : set)
39 {
40 this->operator[](k)=m;
41 ++k;
42 }
43 }
44 else
45 {
46 std::cout<<"set= ";
47 for (const size_t& m : set)
48 {
49 std::cout<<m<<" ";
50 }
51 std::cout<<std::endl;
52 throw std::runtime_error("Cannot create SimplexID from this set.");
53 }
54 }
55
57 {
58 return this->operator[](k);
59 }
60
61 const ScalarIDType& operator()(const size_type& k) const
62 {
63 return this->operator[](k);
64 }
65
66
67 template <class T>
68 friend T& operator << (T& os, const SimplexID& xID)
69 {
70 for(const auto& val : xID)
71 {
72 os << val<<" ";
73 }
74 return os;
75 }
76 };
77
78 template<short int dim, short int order>
80 {
81 static_assert(dim>0,"dim must be > 0");
82 static_assert(order>0,"order must be >= 0");
83 static_assert(order<=dim,"order must be <= dim");
84
85 static constexpr int nVertices=SimplexTraits<dim,order-1>::nVertices+1;
87 static constexpr int nFaces=nVertices;
88
91
92 typedef std::array<std::shared_ptr<Simplex<dim,order-1> >,nFaces> BaseArrayType;
93
96
98 {
99 std::set<size_t> set;
100 for (int k=0;k<nVertices;++k)
101 {
102 set.insert(vIN(k));
103 }
104 return SimplexIDType(set);
105 }
106
107
108 static typename SimplexTraits<dim,order-1>::SimplexIDType faceID(const SimplexIDType& xID,
109 const size_t& j)
110 {
114 assert(j<nVertices && "REQUESTING NON-EXISTING FACE");
115 std::set<size_t> set;
116 for (size_t k=0;k<nVertices;++k)
117 {
118 if(k!=j)
119 {
120 set.insert(xID[k]);
121 }
122 }
124 }
125
126 static std::array<std::shared_ptr<typename SimplexTraits<dim,order-1>::SimplexIDType>,nFaces> faceIDs(const SimplexIDType& xID)
127 {
128 std::array<std::shared_ptr<typename SimplexTraits<dim,order-1>::SimplexIDType>,nFaces> temp;
129 for (size_t j=0;j<nFaces;++j)
130 {
131 temp[j].reset(new typename SimplexTraits<dim,order-1>::SimplexIDType(faceID(xID,j)));
132 }
133 return temp;
134 }
135
136 static size_t faceOrder(const SimplexIDType& parentID,
137 const typename SimplexTraits<dim,order-1>::SimplexIDType& childID)
138 {
139 const std::array<std::shared_ptr<typename SimplexTraits<dim,order-1>::SimplexIDType>,nFaces> faceIDS(faceIDs(parentID));
140
141 int temp=-1;
142 for(size_t k=0;k<nFaces;++k)
143 {
144 if(*faceIDS[k]==childID)
145 {
146 temp=k;
147 break;
148 }
149 }
150 assert(temp>=0 && "FACE NOT FOUND");
151 return temp;
152 }
153
154 };
155
156 template<short int dim>
157 struct SimplexTraits<dim,0>
158 {
159 enum {order=0};
160 enum {nVertices=1};
161 enum {nEdges=0};
163
168
170 {
171 return vIN;
172 }
173 };
174}
175#endif
const ScalarIDType & operator()(const size_type &k) const
ScalarIDType & operator()(const size_type &k)
std::array< size_t, nVertices >::size_type size_type
friend T & operator<<(T &os, const SimplexID &xID)
SimplexID(const std::set< size_t > &set)
Simplex< dim, order > SimplexType
Simplex< dim, order+1 > ParentSimplexType
SimplexID< nVertices >::ScalarIDType ScalarIDType
SimplexID< nVertices > SimplexIDType
static SimplexIDType sortID(const SimplexIDType &vIN)
static SimplexTraits< dim, order-1 >::SimplexIDType faceID(const SimplexIDType &xID, const size_t &j)
static SimplexIDType sortID(const SimplexIDType &vIN)
std::array< std::shared_ptr< Simplex< dim, order-1 > >, nFaces > BaseArrayType
Simplex< dim, order > SimplexType
static constexpr int nEdges
static constexpr int nFaces
static constexpr int nVertices
SimplexID< nVertices >::ScalarIDType ScalarIDType
static size_t faceOrder(const SimplexIDType &parentID, const typename SimplexTraits< dim, order-1 >::SimplexIDType &childID)
SimplexID< nVertices > SimplexIDType
static std::array< std::shared_ptr< typename SimplexTraits< dim, order-1 >::SimplexIDType >, nFaces > faceIDs(const SimplexIDType &xID)
Simplex< dim, order+1 > ParentSimplexType
int j
b order
int k
vertex temp
void t struct mesh * m