Loading...
Searching...
No Matches
element.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_ELEMENT_HPP__
26#define __BITPIT_ELEMENT_HPP__
27
28#include <cstddef>
29#include <memory>
30#include <unordered_map>
31#include <vector>
32
33#include "bitpit_common.hpp"
34#include "bitpit_containers.hpp"
35
36#include "element_type.hpp"
37#include "element_reference.hpp"
38
39namespace bitpit {
40
41class Element;
42
43IBinaryStream & operator>>(IBinaryStream &buf, Element& element);
44OBinaryStream & operator<<(OBinaryStream &buf, const Element& element);
45
46class Element {
47
48friend OBinaryStream& (operator<<) (OBinaryStream& buf, const Element& element);
49friend IBinaryStream& (operator>>) (IBinaryStream& buf, Element& element);
50
51public:
68 struct IdHasher {
77 template<typename U>
78 constexpr std::size_t operator()(U&& value) const noexcept
79 {
80 return static_cast<std::size_t>(std::forward<U>(value));
81 }
82 };
83
84 static int getDimension(ElementType type);
85 static bool isThreeDimensional(ElementType type);
86
87 static int getFaceStreamPosition(const long *connectivity, int face);
88 static ConstProxyVector<long> getVertexIds(ElementType type, const long *connectivity);
89
90 Element();
91 Element(long id, ElementType type, int connectSize = 0);
92 Element(long id, ElementType type, std::unique_ptr<long[]> &&connectStorage);
93
94 Element(const Element &other);
95 Element(Element&& other) = default;
96 Element& operator = (const Element &other);
97 Element& operator=(Element&& other) = default;
98
99 void swap(Element &other) noexcept;
100
101 void initialize(long id, ElementType type, int connectSize = 0);
102 void initialize(long id, ElementType type, std::unique_ptr<long[]> &&connectStorage);
103
104 bool hasInfo() const;
105 const ReferenceElementInfo & getInfo() const;
106
107 void setId(long id);
108 long getId() const;
109
110 void setType(ElementType type);
111 ElementType getType() const;
112
113 void setPID(int pid);
114 int getPID() const;
115
116 int getDimension() const;
117 bool isThreeDimensional() const;
118
119 void setConnect(std::unique_ptr<long[]> &&connect);
120 void unsetConnect();
121 int getConnectSize() const;
122 const long * getConnect() const;
123 long * getConnect();
124 bool hasSameConnect(const Element &other) const;
125
126 int getFaceCount() const;
127 ElementType getFaceType(int face) const;
128 int getFaceVertexCount(int face) const;
132 long getFaceVertexId(int face, int vertex) const;
134
135 int getEdgeCount() const;
136 ElementType getEdgeType(int edge) const;
137 int getEdgeVertexCount(int edge) const;
141 long getEdgeVertexId(int edge, int vertex) const;
143
144 int getVertexCount() const;
145 int renumberVertices(const std::unordered_map<long, long> &map);
147 long getVertexId(int vertex) const;
148 int findVertex(long vertexId) const;
149
150 int getFaceStreamSize() const;
151 std::vector<long> getFaceStream() const;
152 static void renumberFaceStream(const PiercedStorage<long, long> &map, std::vector<long> *faceStream);
153 int getFaceStreamPosition(int face) const;
154
155 BITPIT_PUBLIC_API static const long NULL_ID;
156
157 std::array<double, 3> evalCentroid(const std::array<double, 3> *coordinates) const;
158
159 double evalSize(const std::array<double, 3> *coordinates) const;
160
161 double evalVolume(const std::array<double, 3> *coordinates) const;
162 double evalArea(const std::array<double, 3> *coordinates) const;
163 double evalLength(const std::array<double, 3> *coordinates) const;
164
165 std::array<double, 3> evalNormal(const std::array<double, 3> *coordinates, const std::array<double, 3> &orientation = {{0., 0., 1.}}, const std::array<double, 3> &point = {{0.5, 0.5, 0.5}}) const;
166
167 void evalPointProjection(const std::array<double, 3> &point, const std::array<double, 3> *coordinates, std::array<double, 3> *projection, double *distance) const;
168 double evalPointDistance(const std::array<double, 3> &point, const std::array<double, 3> *coordinates) const;
169
170 unsigned int getBinarySize() const;
171
172private:
173 class Tesselation {
174
175 friend class Element;
176
177 public:
178 Tesselation();
179
180 int importVertexCoordinates(const std::array<double, 3> &coordinates);
181 int importVertexCoordinates(std::array<double, 3> &&coordinates);
182 std::vector<int> importVertexCoordinates(const std::array<double, 3> * coordinates, int nVertices);
183
184 void importPolygon(const std::vector<int> &vertexIds);
185 void importPolyhedron(const std::vector<int> &vertexIds, const std::vector<std::vector<int>> &faceVertexIds);
186
187 int getTileCount() const;
188 ElementType getTileType(int tile) const;
189 std::vector<std::array<double, 3>> getTileVertexCoordinates(int tile) const;
190
191 private:
192 int m_nTiles;
193 std::vector<ElementType> m_types;
194 std::vector<std::vector<int>> m_connects;
195
196 std::vector<std::array<double, 3>> m_coordinates;
197 };
198
199 static int countPolygonVertices(const long *connectivity);
200
201 static int countPolygonFaces(const long *connectivity);
202 static int countPolyhedronFaces(const long *connectivity);
203
204 long m_id;
205
206 ElementType m_type;
207
208 int m_pid;
209
210 std::unique_ptr<long[]> m_connect;
211
212 void _initialize(long id, ElementType type = ElementType::UNDEFINED, int connectSize = 0);
213 void _initialize(long id, ElementType type, std::unique_ptr<long[]> &&connectStorage);
214
215 Tesselation generateTesselation(const std::array<double, 3> *coordinates) const;
216
217 std::vector<ConstProxyVector<long>> evalEdgeConnects(int maxEdges = -1) const;
218
219};
220
221template<class DerivedElement>
223
224public:
225 enum Winding {
226 WINDING_NATURAL = 1,
227 WINDING_REVERSE = -1
228 };
229
230 struct Hasher {
231 std::size_t operator()(const ElementHalfItem &item) const;
232 };
233
234 const ConstProxyVector<long> & getVertexIds() const;
235
236 Winding getWinding() const;
237 void setWinding(Winding winding);
238
239 bool operator==(const ElementHalfItem &other) const;
240 bool operator!=(const ElementHalfItem &other) const;
241
242protected:
243 DerivedElement &m_element;
244
245 ConstProxyVector<long> m_vertexIds;
246 std::size_t m_firstVertexId;
247
248 Winding m_winding;
249
250 ElementHalfItem(DerivedElement &element, ConstProxyVector<long> &&vertexIds, ElementHalfItem<DerivedElement>::Winding winding);
251
252 DerivedElement & getElement() const;
253
254};
255
256template<class DerivedElement>
257class ElementHalfEdge : public ElementHalfItem<DerivedElement> {
258
259public:
260 typedef typename ElementHalfItem<DerivedElement>::Winding Winding;
261
262 int getEdge() const;
263
264protected:
265 int m_edge;
266
267 ElementHalfEdge(DerivedElement &element, int edge, Winding winding);
268
269};
270
271template<class DerivedElement>
272class ElementHalfFace : public ElementHalfItem<DerivedElement> {
273
274public:
275 typedef typename ElementHalfItem<DerivedElement>::Winding Winding;
276
277 int getFace() const;
278
279protected:
280 int m_face;
281
282 ElementHalfFace(DerivedElement &element, int face, Winding winding);
283
284};
285
286extern template class PiercedVector<Element>;
287
288}
289
290// Include template implementations
291#include "element.tpp"
292
293#endif
The Tesselation class allows to tessalete polygons and polyhedrons.
The ElementHalfEdge class defines element half-edge items.
Definition element.hpp:257
ElementHalfEdge(DerivedElement &element, int edge, Winding winding)
Definition element.tpp:220
The ElementHalfFace class defines element half-faces.
Definition element.hpp:272
ElementHalfFace(DerivedElement &element, int face, Winding winding)
Definition element.tpp:257
The ElementHalfItem class is the base calss for defining element half-edge and half-faces.
Definition element.hpp:222
bool operator!=(const ElementHalfItem &other) const
Definition element.tpp:152
ElementHalfItem(DerivedElement &element, ConstProxyVector< long > &&vertexIds, ElementHalfItem< DerivedElement >::Winding winding)
Definition element.tpp:49
const ConstProxyVector< long > & getVertexIds() const
Definition element.tpp:86
DerivedElement & getElement() const
Definition element.tpp:75
bool operator==(const ElementHalfItem &other) const
Definition element.tpp:121
void setWinding(Winding winding)
Definition element.tpp:108
Winding getWinding() const
Definition element.tpp:97
The Element class provides an interface for defining elements.
Definition element.hpp:46
Element & operator=(const Element &other)
Definition element.cpp:384
long getId() const
Definition element.cpp:510
int getDimension() const
Definition element.cpp:1119
ConstProxyVector< int > getFaceLocalConnect(int face) const
Definition element.cpp:773
double evalVolume(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1646
ConstProxyVector< long > getFaceVertexIds(int face) const
Definition element.cpp:1320
ElementType getType() const
Definition element.cpp:551
int getEdgeVertexCount(int edge) const
Definition element.cpp:981
double evalArea(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1685
long getFaceVertexId(int face, int vertex) const
Definition element.cpp:1343
void swap(Element &other) noexcept
Definition element.cpp:399
void setType(ElementType type)
Definition element.cpp:541
double evalLength(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1724
ConstProxyVector< long > getEdgeVertexIds(int edge) const
Definition element.cpp:1410
int findVertex(long vertexId) const
Definition element.cpp:1302
const ReferenceElementInfo & getInfo() const
Definition element.cpp:531
bool isThreeDimensional() const
Definition element.cpp:1142
unsigned int getBinarySize() const
Definition element.cpp:2144
ConstProxyVector< int > getEdgeLocalVertexIds(int edge) const
Definition element.cpp:1437
ElementType getFaceType(int face) const
Definition element.cpp:701
ConstProxyVector< int > getEdgeLocalConnect(int edge) const
Definition element.cpp:994
ConstProxyVector< long > getVertexIds() const
Definition element.cpp:1181
long getEdgeVertexId(int edge, int vertex) const
Definition element.cpp:1424
ConstProxyVector< int > getFaceLocalVertexIds(int face) const
Definition element.cpp:1372
void initialize(long id, ElementType type, int connectSize=0)
Definition element.cpp:415
double evalSize(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1549
bool hasSameConnect(const Element &other) const
Definition element.cpp:655
int getFaceVertexCount(int face) const
Definition element.cpp:743
const long * getConnect() const
Definition element.cpp:609
void evalPointProjection(const std::array< double, 3 > &point, const std::array< double, 3 > *coordinates, std::array< double, 3 > *projection, double *distance) const
Definition element.cpp:1846
double evalPointDistance(const std::array< double, 3 > &point, const std::array< double, 3 > *coordinates) const
Definition element.cpp:1828
bool hasInfo() const
Definition element.cpp:521
void setId(long id)
Definition element.cpp:498
ConstProxyVector< long > getFaceConnect(int face) const
Definition element.cpp:848
long getVertexId(int vertex) const
Definition element.cpp:1269
std::array< double, 3 > evalNormal(const std::array< double, 3 > *coordinates, const std::array< double, 3 > &orientation={{0., 0., 1.}}, const std::array< double, 3 > &point={{0.5, 0.5, 0.5}}) const
Definition element.cpp:1759
static void renumberFaceStream(const PiercedStorage< long, long > &map, std::vector< long > *faceStream)
Definition element.cpp:2012
ConstProxyVector< long > getEdgeConnect(int edge) const
Definition element.cpp:1052
void unsetConnect()
Definition element.cpp:599
void setConnect(std::unique_ptr< long[]> &&connect)
Definition element.cpp:591
void setPID(int pid)
Definition element.cpp:566
int getEdgeCount() const
Definition element.cpp:922
std::array< double, 3 > evalCentroid(const std::array< double, 3 > *coordinates) const
Definition element.cpp:1521
std::vector< long > getFaceStream() const
Definition element.cpp:1982
int getFaceCount() const
Definition element.cpp:678
int renumberVertices(const std::unordered_map< long, long > &map)
Definition element.cpp:1451
int getVertexCount() const
Definition element.cpp:1152
int getConnectSize() const
Definition element.cpp:629
int getFaceStreamSize() const
Definition element.cpp:1969
static int getFaceStreamPosition(const long *connectivity, int face)
Definition element.cpp:2047
int getPID() const
Definition element.cpp:581
ElementType getEdgeType(int edge) const
Definition element.cpp:955
Output binary stream.
Output binary stream.
Metafunction for generating a pierced storage.
Metafunction for generating a pierced vector.
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
The ReferenceElementInfo class allows to define information about reference elements.
std::ostream & operator<<(std::ostream &, const std::vector< T > &)
The ElementHalfItem::Hasher class allows to create hashes for the half-items.
Definition element.hpp:230
std::size_t operator()(const ElementHalfItem &item) const
Definition element.tpp:172
constexpr std::size_t operator()(U &&value) const noexcept
Definition element.hpp:78
--- layout: doxygen_footer ---