10 return (
A(0) * (B(1) - C(1)) + B(0) * (C(1) -
A(1)) + C(0) * (
A(1) - B(1))) / 2.0;
31 for (
auto &
vertex : _vertices)
35 for (
auto &
edge : _edges)
39 for (
auto &
cell : _cells)
45 void set_name(std::string name) { _mesh_name = name; }
46 inline std::string
get_name() {
return _mesh_name; }
51 for (
auto &
cell : _cells)
60 inline std::size_t
n_vertices()
const {
return _vertices.size(); }
61 inline std::size_t
n_edges()
const {
return _edges.size(); }
62 inline std::size_t
n_faces()
const {
return _edges.size(); }
63 inline std::size_t
n_cells()
const {
return _cells.size(); }
65 inline std::size_t
n_b_vertices()
const {
return _b_vertices.size(); }
66 inline std::size_t
n_b_edges()
const {
return _b_edges.size(); }
67 inline std::size_t
n_b_faces()
const {
return _b_edges.size(); }
68 inline std::size_t
n_b_cells()
const {
return _b_cells.size(); }
70 inline std::size_t
n_i_vertices()
const {
return _i_vertices.size(); }
71 inline std::size_t
n_i_edges()
const {
return _i_edges.size(); }
72 inline std::size_t
n_i_faces()
const {
return _i_edges.size(); }
73 inline std::size_t
n_i_cells()
const {
return _i_cells.size(); }
75 inline std::vector<Vertex *>
get_vertices()
const {
return _vertices; }
76 inline std::vector<Edge *>
get_edges()
const {
return _edges; }
77 inline std::vector<Face *>
get_faces()
const {
return _edges; }
78 inline std::vector<Cell *>
get_cells()
const {
return _cells; }
81 inline std::vector<Edge *>
get_b_edges()
const {
return _b_edges; }
82 inline std::vector<Face *>
get_b_faces()
const {
return _b_edges; }
83 inline std::vector<Cell *>
get_b_cells()
const {
return _b_cells; }
86 inline std::vector<Edge *>
get_i_edges()
const {
return _i_edges; }
87 inline std::vector<Face *>
get_i_faces()
const {
return _i_edges; }
88 inline std::vector<Cell *>
get_i_cells()
const {
return _i_cells; }
92 assert(std::find(_vertices.begin(), _vertices.end(),
vertex) == _vertices.end());
93 _vertices.push_back(
vertex);
98 assert(std::find(_edges.begin(), _edges.end(),
edge) == _edges.end());
99 _edges.push_back(
edge);
104 assert(std::find(_edges.begin(), _edges.end(),
face) == _edges.end());
105 _edges.push_back(
face);
110 assert(std::find(_cells.begin(), _cells.end(),
cell) == _cells.end());
111 _cells.push_back(
cell);
116 assert(std::find(_b_vertices.begin(), _b_vertices.end(),
vertex) == _b_vertices.end());
117 _b_vertices.push_back(
vertex);
122 assert(std::find(_b_edges.begin(), _b_edges.end(),
edge) == _b_edges.end());
123 _b_edges.push_back(
edge);
128 assert(std::find(_b_edges.begin(), _b_edges.end(),
face) == _b_edges.end());
129 _b_edges.push_back(
face);
134 assert(std::find(_b_cells.begin(), _b_cells.end(),
cell) == _b_cells.end());
135 _b_cells.push_back(
cell);
140 assert(std::find(_i_vertices.begin(), _i_vertices.end(),
vertex) == _i_vertices.end());
141 _i_vertices.push_back(
vertex);
146 assert(std::find(_i_edges.begin(), _i_edges.end(),
edge) == _i_edges.end());
147 _i_edges.push_back(
edge);
152 assert(std::find(_i_edges.begin(), _i_edges.end(),
face) == _i_edges.end());
153 _i_edges.push_back(
face);
158 assert(std::find(_i_cells.begin(), _i_cells.end(),
cell) == _i_cells.end());
159 _i_cells.push_back(
cell);
165 assert(index < _vertices.size());
166 return _vertices[index];
170 assert(index < _edges.size());
171 return _edges[index];
175 assert(index < _edges.size());
176 return _edges[index];
180 assert(index < _cells.size());
181 return _cells[index];
186 assert(index < _b_vertices.size());
187 return _b_vertices[index];
191 assert(index < _b_edges.size());
192 return _b_edges[index];
196 assert(index < _b_edges.size());
197 return _b_edges[index];
201 assert(index < _b_cells.size());
202 return _b_cells[index];
207 assert(index < _i_vertices.size());
208 return _i_vertices[index];
212 assert(index < _i_edges.size());
213 return _i_edges[index];
217 assert(index < _i_edges.size());
218 return _i_edges[index];
222 assert(index < _i_cells.size());
223 return _i_cells[index];
235 std::vector<std::vector<double>> reg_cell(
n_cells(), {0.0, 0.0});
236 std::size_t
count = 0;
237 for (
auto &
T : _cells)
239 double hT =
T->diam();
245 std::vector<Face *> faces =
T->get_faces();
246 for (
auto &F : faces)
248 double hF = F->diam();
252 reg_cell[
count][0] = std::max(reg_cell[
count][0], hT / hF);
254 rhoT = std::min(rhoT, std::abs((xT - xF).dot(nTF)));
256 reg_cell[
count][1] = hT / rhoT;
260 std::vector<double> value(2, 0.0);
261 for (
size_t iT = 0; iT <
n_cells(); iT++)
263 value[0] = std::max(value[0], reg_cell[iT][0]);
264 value[1] = std::max(value[1], reg_cell[iT][1]);
270 void renum(
const char B,
const std::vector<size_t> new_to_old)
277 std::vector<Cell *> old_index = _cells;
278 for (
size_t i = 0;
i < _cells.size();
i++)
280 old_index[new_to_old[
i]]->set_global_index(
i);
281 _cells[
i] = old_index[new_to_old[
i]];
288 std::vector<Face *> old_index = _edges;
289 for (
size_t i = 0;
i < _edges.size();
i++)
291 old_index[new_to_old[
i]]->set_global_index(
i);
292 _edges[
i] = old_index[new_to_old[
i]];
299 std::vector<Edge *> old_index = _edges;
300 for (
size_t i = 0;
i < _edges.size();
i++)
302 old_index[new_to_old[
i]]->set_global_index(
i);
303 _edges[
i] = old_index[new_to_old[
i]];
310 std::vector<Vertex *> old_index = _vertices;
311 for (
size_t i = 0;
i < _vertices.size();
i++)
313 old_index[new_to_old[
i]]->set_global_index(
i);
314 _vertices[
i] = old_index[new_to_old[
i]];
325 std::vector<size_t> neighbouring_cells;
328 if ((
T->center_mass() - x).norm() <=
T->diam())
330 neighbouring_cells.push_back(
T->global_index());
338 while (
i < neighbouring_cells.size() && !found)
340 iT = neighbouring_cells[
i];
343 for(
auto& simplex :
T->get_simplices())
345 double area1 =
signed_area(x, simplex[0], simplex[1]);
346 double area2 =
signed_area(x, simplex[1], simplex[2]);
347 double area3 =
signed_area(x, simplex[2], simplex[0]);
349 found = (area1 >= 0.0 && area2 >= 0.0 && area3 >= 0.0) || (area1 <= 0.0 && area2 <= 0.0 && area3 <= 0.0);
361 for (
auto &
cell : _cells)
369 for (
auto &
edge : _edges)
376 std::string _mesh_name;
378 std::vector<Vertex *> _vertices;
379 std::vector<Edge *> _edges;
381 std::vector<Cell *> _cells;
383 std::vector<Vertex *> _b_vertices;
384 std::vector<Edge *> _b_edges;
386 std::vector<Cell *> _b_cells;
388 std::vector<Vertex *> _i_vertices;
389 std::vector<Edge *> _i_edges;
391 std::vector<Cell *> _i_cells;
A Vertex is a Polytope with object_dim = 0.
Definition Polytope2D.hpp:54
Compute max and min eigenvalues of all matrices for i
Definition compute_eigs.m:5
std::vector< Cell * > get_cells() const
lists the cells in the mesh.
Definition Mesh2D.hpp:78
std::vector< Face * > get_b_faces() const
lists the boundary faces in the mesh.
Definition Mesh2D.hpp:82
std::size_t n_b_edges() const
number of boundary edges in the mesh.
Definition Mesh2D.hpp:66
Cell * i_cell(std::size_t index) const
get a constant pointer to an internal cell using an index
Definition Mesh2D.hpp:220
double h_max() const
< max diameter of cells
Definition Mesh2D.hpp:48
std::vector< Face * > get_faces() const
lists the faces in the mesh.
Definition Mesh2D.hpp:77
std::size_t n_faces() const
number of faces in the mesh.
Definition Mesh2D.hpp:62
void add_face(Face *face)
Definition Mesh2D.hpp:102
std::string get_name()
getter for the mesh name
Definition Mesh2D.hpp:46
void plot(std::ofstream *out) const
Plot the polytope to out.
Definition Polytope2D.hpp:489
std::size_t n_vertices() const
number of vertices in the mesh.
Definition Mesh2D.hpp:60
std::size_t n_i_cells() const
number of internal cells in the mesh.
Definition Mesh2D.hpp:73
std::size_t dim() const
dimension of the mesh
Definition Mesh2D.hpp:58
Face * face(std::size_t index) const
get a constant pointer to a face using its global index
Definition Mesh2D.hpp:173
void add_vertex(Vertex *vertex)
Definition Mesh2D.hpp:90
Vertex * b_vertex(std::size_t index) const
get a constant pointer to a boundary vertex using an index
Definition Mesh2D.hpp:184
Cell * cell(std::size_t index) const
get a constant pointer to a cell using its global index
Definition Mesh2D.hpp:178
void add_b_cell(Cell *cell)
Definition Mesh2D.hpp:132
void add_i_cell(Cell *cell)
Definition Mesh2D.hpp:156
void add_b_vertex(Vertex *vertex)
Definition Mesh2D.hpp:114
std::vector< Edge * > get_i_edges() const
lists the internal edges in the mesh.
Definition Mesh2D.hpp:86
void plot_simplices(std::ofstream *out) const
Plot the simplices to out.
Definition Polytope2D.hpp:473
std::vector< double > regularity()
Definition Mesh2D.hpp:226
Edge * i_edge(std::size_t index) const
get a constant pointer to an internal edge using an index
Definition Mesh2D.hpp:210
std::vector< Edge * > get_edges() const
lists the edges in the mesh.
Definition Mesh2D.hpp:76
Edge * edge(std::size_t index) const
get a constant pointer to a edge using its global index
Definition Mesh2D.hpp:168
void add_i_vertex(Vertex *vertex)
Definition Mesh2D.hpp:138
void set_name(std::string name)
set the name of the mesh
Definition Mesh2D.hpp:45
std::vector< Edge * > get_b_edges() const
lists the boundary edges in the mesh.
Definition Mesh2D.hpp:81
void add_i_face(Face *face)
Definition Mesh2D.hpp:150
~Mesh()
Definition Mesh2D.hpp:29
void plot_simplices(std::ofstream *out)
Definition Mesh2D.hpp:359
std::vector< Face * > get_i_faces() const
lists the internal faces in the mesh.
Definition Mesh2D.hpp:87
Face * i_face(std::size_t index) const
get a constant pointer to an internal face using an index
Definition Mesh2D.hpp:215
double diam() const
Return the diameter of the Polytope.
Definition Polytope2D.hpp:74
void plot_mesh(std::ofstream *out)
Definition Mesh2D.hpp:367
Mesh()
Definition Mesh2D.hpp:28
std::size_t n_b_faces() const
number of boundary faces in the mesh.
Definition Mesh2D.hpp:67
std::size_t n_i_faces() const
number of internal faces in the mesh.
Definition Mesh2D.hpp:72
void add_i_edge(Edge *edge)
Definition Mesh2D.hpp:144
Edge * b_edge(std::size_t index) const
get a constant pointer to boundary a edge using an index
Definition Mesh2D.hpp:189
std::size_t n_cells() const
number of cells in the mesh.
Definition Mesh2D.hpp:63
std::vector< Cell * > get_i_cells() const
lists the internal cells in the mesh.
Definition Mesh2D.hpp:88
void renum(const char B, const std::vector< size_t > new_to_old)
Definition Mesh2D.hpp:270
std::size_t n_i_edges() const
number of internal edges in the mesh.
Definition Mesh2D.hpp:71
void add_b_face(Face *face)
Definition Mesh2D.hpp:126
Cell * b_cell(std::size_t index) const
get a constant pointer to boundary a cell using an index
Definition Mesh2D.hpp:199
size_t find_cell(const VectorRd x) const
< returns the index of the cell containing the point x
Definition Mesh2D.hpp:321
std::vector< Vertex * > get_b_vertices() const
lists the boundary vertices in the mesh.
Definition Mesh2D.hpp:80
std::vector< Vertex * > get_i_vertices() const
lists the internal vertices in the mesh.
Definition Mesh2D.hpp:85
Vertex * i_vertex(std::size_t index) const
get a constant pointer to an internal vertex using an index
Definition Mesh2D.hpp:205
std::size_t n_b_cells() const
number of boundary cells in the mesh.
Definition Mesh2D.hpp:68
Vertex * vertex(std::size_t index) const
get a constant pointer to a vertex using its global index
Definition Mesh2D.hpp:163
std::size_t n_i_vertices() const
number of internal vertices in the mesh.
Definition Mesh2D.hpp:70
Face * b_face(std::size_t index) const
get a constant pointer to boundary a face using an index
Definition Mesh2D.hpp:194
std::size_t n_edges() const
number of edges in the mesh.
Definition Mesh2D.hpp:61
std::vector< Cell * > get_b_cells() const
lists the boundary cells in the mesh.
Definition Mesh2D.hpp:83
void add_cell(Cell *cell)
Definition Mesh2D.hpp:108
void add_edge(Edge *edge)
Definition Mesh2D.hpp:96
void add_b_edge(Edge *edge)
Definition Mesh2D.hpp:120
std::size_t n_b_vertices() const
number of boundary vertices in the mesh.
Definition Mesh2D.hpp:65
std::vector< Vertex * > get_vertices() const
lists the vertices in the mesh.
Definition Mesh2D.hpp:75
if(strcmp(field, 'real')) % real valued entries T
Definition mmread.m:93
end Read size then branch according to sparse or dense format count
Definition mmread.m:75
double signed_area(VectorRd A, VectorRd B, VectorRd C)
Definition Mesh2D.hpp:8
constexpr int DIMENSION
Definition Polytope2D.hpp:17
Eigen::Matrix< double, DIMENSION, 1 > VectorRd
Definition Polytope2D.hpp:19