11#include <../Math/math.hpp>
13#ifndef _POLYTOPE2D_HPP
14#define _POLYTOPE2D_HPP
20 using VectorRd = Eigen::Matrix<double, DIMENSION, 1>;
21 using VectorZd = Eigen::Matrix<int, DIMENSION, 1>;
23 template <
size_t object_dim>
24 using Simplex = std::array<VectorRd, object_dim + 1>;
26 template <
size_t object_dim>
30 template <
size_t object_dim>
34 template <
size_t object_dim>
53 template <
size_t object_dim>
75 inline double diam()
const {
return _diameter; }
77 inline double measure()
const {
return _measure; }
83 inline std::vector<Polytope<0> *>
get_vertices()
const {
return _vertices; }
84 inline std::vector<Polytope<1> *>
get_edges()
const {
return _edges; }
86 inline std::vector<Polytope<DIMENSION> *>
get_cells()
const {
return _cells; }
88 inline size_t n_vertices()
const {
return _vertices.size(); }
89 inline size_t n_edges()
const {
return _edges.size(); }
90 inline size_t n_faces()
const {
return _edges.size(); }
91 inline size_t n_cells()
const {
return _cells.size(); }
123 void plot(std::ofstream *
out)
const;
134 std::vector<int> _face_directions;
136 std::vector<Polytope<0> *> _vertices;
137 std::vector<Polytope<1> *> _edges;
139 std::vector<Polytope<DIMENSION> *> _cells;
160 template <
size_t object_dim>
163 VectorRd center_mass = VectorRd::Zero();
175 template <
size_t object_dim>
201 template <
size_t object_dim>
212 _is_boundary =
false;
215 _center_mass = VectorRd::Zero();
231 _center_mass /= _measure;
238 _diameter = std::max(_diameter, (*
it - *
jt).
norm());
245 _normal =
VectorRd(-_tangent(1), _tangent(0));
249 template <
size_t object_dim>
255 template <
size_t object_dim>
262 template <
size_t object_dim>
265 template <
size_t object_dim>
268 template <
size_t object_dim>
271 assert(std::find(_vertices.begin(), _vertices.end(), vertex) == _vertices.end());
272 _vertices.push_back(vertex);
275 template <
size_t object_dim>
278 assert(std::find(_edges.begin(), _edges.end(), edge) == _edges.end());
279 _edges.push_back(edge);
282 template <
size_t object_dim>
285 assert(std::find(_edges.begin(), _edges.end(), face) == _edges.end());
286 _edges.push_back(face);
289 template <
size_t object_dim>
292 assert(std::find(_cells.begin(), _cells.end(), cell) == _cells.end());
293 _cells.push_back(cell);
296 template <
size_t object_dim>
303 template <
size_t object_dim>
310 template <
size_t object_dim>
317 template <
size_t object_dim>
324 template <
size_t object_dim>
328 for (
size_t iF = 0;
iF < _edges.size(); ++
iF)
351 _face_directions.push_back(
Math::sgn((_edges[
iF]->center_mass() - center).
dot(normal)));
356 template <
size_t object_dim>
364 template <
size_t object_dim>
370 template <
size_t object_dim>
374 return this->get_simplices()[0][0];
377 template <
size_t object_dim>
384 template <
size_t object_dim>
392 template <
size_t object_dim>
395 auto itr = std::find(_vertices.begin(), _vertices.end(), vertex);
396 if (
itr != _vertices.end())
398 return itr - _vertices.begin();
402 throw "Vertex not found";
406 template <
size_t object_dim>
409 auto itr = std::find(_edges.begin(), _edges.end(), edge);
410 if (
itr != _edges.end())
412 return itr - _edges.begin();
416 throw "Edge not found";
420 template <
size_t object_dim>
423 auto itr = std::find(_edges.begin(), _edges.end(), face);
424 if (
itr != _edges.end())
426 return itr - _edges.begin();
430 throw "Face not found";
434 template <
size_t object_dim>
437 auto itr = std::find(_cells.begin(), _cells.end(), cell);
438 if (
itr != _cells.end())
440 return itr - _cells.begin();
444 throw "Cell not found";
448 template <
size_t object_dim>
456 template <
size_t object_dim>
464 template <
size_t object_dim>
469 return ( (_vertices[
vertex_index]->coords()-_center_mass).
dot(this->tangent()) > 0 ? 1 : -1);
472 template <
size_t object_dim>
476 for (
auto &
simplex : _simplices)
488 template <
size_t object_dim>
492 for (
size_t i = 0;
i < _vertices.size(); ++
i)
494 size_t i_next = (
i + 1) % _vertices.size();
495 *
out << _vertices[
i]->coords()(0) <<
" " << _vertices[
i]->coords()(1) << std::endl;
496 *
out << _vertices[
i_next]->coords()(0) <<
" " << _vertices[
i_next]->coords()(1) << std::endl;
A Vertex is a Polytope with object_dim = 0.
Definition Polytope2D.hpp:55
for i
Definition convergence_analysis.m:48
for j
Definition convergence_analysis.m:19
VectorRd normal() const
Return the normal of a Face.
Definition Polytope2D.hpp:378
double measure() const
Return the Lebesgue measure of the Polytope.
Definition Polytope2D.hpp:77
void construct_face_normals()
Set the directions of the face normals of a cell.
Definition Polytope2D.hpp:325
int index_cell(const Polytope< DIMENSION > *cell) const
Returns the local index of a cell.
Definition Polytope2D.hpp:435
int index_edge(const Polytope< 1 > *edge) const
Returns the local index of an edge.
Definition Polytope2D.hpp:407
void add_edge(Polytope< 1 > *edge)
Add an edge to the Polytope.
Definition Polytope2D.hpp:276
VectorRd center_mass() const
Return the center mass of the Polytope.
Definition Polytope2D.hpp:76
void plot(std::ofstream *out) const
Plot the polytope to out.
Definition Polytope2D.hpp:489
std::vector< Polytope< DIMENSION > * > get_cells() const
Return the cells of the Polytope.
Definition Polytope2D.hpp:86
VectorRd tangent() const
Return the tangent of a Edge.
Definition Polytope2D.hpp:385
void set_global_index(const size_t idx)
Set the global index.
Definition Polytope2D.hpp:79
size_t n_vertices() const
Return the number of vertices of the Polytope.
Definition Polytope2D.hpp:88
void plot_simplices(std::ofstream *out) const
Plot the simplices to out.
Definition Polytope2D.hpp:473
VectorRd face_normal(const size_t face_index) const
Return the outer normal of a Cell towards the Face located at face_index.
Definition Polytope2D.hpp:357
size_t n_edges() const
Return the number of edges of the Polytope.
Definition Polytope2D.hpp:89
int index_face(const Polytope< DIMENSION - 1 > *face) const
Returns the local index of a face.
Definition Polytope2D.hpp:421
void add_vertex(Polytope< 0 > *vertex)
Add a vertex to the Polytope.
Definition Polytope2D.hpp:269
void add_cell(Polytope< DIMENSION > *cell)
Add a cell to the Polytope.
Definition Polytope2D.hpp:290
int index_vertex(const Polytope< 0 > *vertex) const
Returns the local index of a vertex.
Definition Polytope2D.hpp:393
Polytope< DIMENSION > * cell(const size_t i) const
Return the i-th cell of the Polytope.
Definition Polytope2D.hpp:318
int vertex_orientation(const size_t vertex_index) const
Return the orientation of a Vertex.
Definition Polytope2D.hpp:465
std::vector< Polytope< DIMENSION - 1 > * > get_faces() const
Return the faces of the Polytope.
Definition Polytope2D.hpp:85
double diam() const
Return the diameter of the Polytope.
Definition Polytope2D.hpp:75
~Polytope()
Definition Polytope2D.hpp:266
Polytope< DIMENSION - 1 > * face(const size_t i) const
Return the i-th face of the Polytope.
Definition Polytope2D.hpp:311
void add_face(Polytope< DIMENSION - 1 > *face)
Add a face to the Polytope.
Definition Polytope2D.hpp:283
void set_boundary(bool val)
Set the boundary value of the Polytope.
Definition Polytope2D.hpp:81
size_t n_faces() const
Return the number of faces of the Polytope.
Definition Polytope2D.hpp:90
Polytope< 1 > * edge(const size_t i) const
Return the i-th edge of the Polytope.
Definition Polytope2D.hpp:304
std::vector< Polytope< 0 > * > get_vertices() const
Return the vertices of the Polytope.
Definition Polytope2D.hpp:83
bool is_boundary() const
Return true if Polytope is a boundary object, false otherwise.
Definition Polytope2D.hpp:80
VectorRd edge_normal(const size_t edge_index) const
Return the edge normal of a 2D object.
Definition Polytope2D.hpp:365
double simplex_measure(Simplex< object_dim > simplex)
Definition Polytope2D.hpp:176
size_t global_index() const
Return the global index of the Polytope.
Definition Polytope2D.hpp:74
std::vector< Polytope< 1 > * > get_edges() const
Return the edges of the Polytope.
Definition Polytope2D.hpp:84
int face_orientation(const size_t face_index) const
Return the orientation of a Face.
Definition Polytope2D.hpp:449
Polytope()
Destructor.
Definition Polytope2D.hpp:263
Simplices< object_dim > get_simplices() const
Return the simplices making up the Polytope.
Definition Polytope2D.hpp:78
int edge_orientation(const size_t edge_index) const
Return the orientation of a Edge.
Definition Polytope2D.hpp:457
Polytope< 0 > * vertex(const size_t i) const
Return the i-th vertex of the Polytope.
Definition Polytope2D.hpp:297
VectorRd simplex_center_mass(Simplex< object_dim > simplex)
Method to find the Lebesgue measure of an arbitrary simplex in arbitrary space.
Definition Polytope2D.hpp:161
VectorRd coords() const
Return the coordinates of a Vertex.
Definition Polytope2D.hpp:371
size_t n_cells() const
Return the number of cells of the Polytope.
Definition Polytope2D.hpp:91
depending on the Matrix Market format indicated by or array(dense array storage). The data will be duplicated % as appropriate if symmetry is indicated in the header. % % Optionally
end Read size then branch according to sparse or dense format count
Definition mmread.m:75
const int sgn(T val)
Definition math.hpp:42
const size_t factorial(size_t n)
Definition math.hpp:12
std::array< VectorRd, object_dim+1 > Simplex
Definition Polytope2D.hpp:24
constexpr int DIMENSION
Definition Polytope2D.hpp:18
std::vector< Simplex< object_dim > > Simplices
Method to find the center mass of an arbitrary simplex in arbitrary space.
Definition Polytope2D.hpp:29
Eigen::Matrix< int, DIMENSION, 1 > VectorZd
Definition Polytope2D.hpp:21
Eigen::Matrix< double, DIMENSION, 1 > VectorRd
Definition Polytope2D.hpp:20