PolyFEM
Loading...
Searching...
No Matches
Mesh3D.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
5
6#include "Navigation3D.hpp"
7#include "Mesh3DStorage.hpp"
8#include <geogram/mesh/mesh.h>
9#include <iostream>
10#include <Eigen/Dense>
11#include <vector>
12#include <array>
13
14namespace polyfem
15{
16 namespace mesh
17 {
18 class Mesh3D : public Mesh
19 {
20 public:
21 Mesh3D() = default;
22 virtual ~Mesh3D() = default;
23 Mesh3D(Mesh3D &&) = default;
24 Mesh3D &operator=(Mesh3D &&) = default;
25 Mesh3D(const Mesh3D &) = default;
26 Mesh3D &operator=(const Mesh3D &) = default;
27
28 inline bool is_volume() const override { return true; }
29
30 virtual int n_cell_edges(const int c_id) const = 0;
31 virtual int n_cell_faces(const int c_id) const = 0;
32 virtual int cell_face(const int c_id, const int lf_id) const = 0;
33 virtual int cell_edge(const int c_id, const int le_id) const = 0;
34
35 void elements_boxes(std::vector<std::array<Eigen::Vector3d, 2>> &boxes) const override;
36 void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override;
37
38 void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const;
39
40 virtual RowVectorNd kernel(const int cell_id) const = 0;
41
42 double tri_area(const int gid) const override;
43
44 std::pair<RowVectorNd, int> edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const;
45 std::pair<RowVectorNd, int> face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const;
46 std::pair<RowVectorNd, int> cell_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j, const int k) const;
47
48 void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override;
49 void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1, const std::vector<bool> &valid_elements) const override;
50
51 // navigation wrapper
52 virtual Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const = 0;
54
55 virtual Navigation3D::Index get_index_from_element_edge(int hi, int v0, int v1) const = 0;
56 virtual Navigation3D::Index get_index_from_element_face(int hi, int v0, int v1, int v2) const = 0;
57
58 virtual std::vector<uint32_t> vertex_neighs(const int v_gid) const = 0;
59 virtual std::vector<uint32_t> edge_neighs(const int e_gid) const = 0;
60
61 // Navigation in a surface mesh
66
67 // Iterate in a mesh
70
71 void to_face_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 6> &to_face) const;
72 void to_vertex_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 8> &to_vertex) const;
73 void to_edge_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 12> &to_edge) const;
74
75 // Retrieves hex vertices numbered as follows:
76 // v7────v6
77 // ╱┆ ╱│
78 // v4─┼──v5 │
79 // │v3┄┄┄┼v2
80 // │╱ │╱
81 // v0────v1
82 std::array<int, 8> get_ordered_vertices_from_hex(const int element_index) const;
83 virtual std::array<int, 4> get_ordered_vertices_from_tet(const int element_index) const;
84
85 virtual void get_vertex_elements_neighs(const int v_id, std::vector<int> &ids) const = 0;
86 virtual void get_edge_elements_neighs(const int e_id, std::vector<int> &ids) const = 0;
87
88 void compute_element_barycenters(Eigen::MatrixXd &barycenters) const override { cell_barycenters(barycenters); }
89 };
90 } // namespace mesh
91} // namespace polyfem
void to_vertex_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 8 > &to_vertex) const
Definition Mesh3D.cpp:285
Mesh3D & operator=(const Mesh3D &)=default
virtual Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const =0
virtual Navigation3D::Index switch_element(Navigation3D::Index idx) const =0
double tri_area(const int gid) const override
area of a tri face of a tet mesh
Definition Mesh3D.cpp:18
virtual void get_edge_elements_neighs(const int e_id, std::vector< int > &ids) const =0
void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
Definition Mesh3D.cpp:424
virtual Navigation3D::Index get_index_from_element_edge(int hi, int v0, int v1) const =0
virtual ~Mesh3D()=default
virtual int n_cell_edges(const int c_id) const =0
virtual int cell_edge(const int c_id, const int le_id) const =0
virtual RowVectorNd kernel(const int cell_id) const =0
Mesh3D(const Mesh3D &)=default
void compute_element_barycenters(Eigen::MatrixXd &barycenters) const override
utility for 2d/3d.
Definition Mesh3D.hpp:88
Mesh3D(Mesh3D &&)=default
void elements_boxes(std::vector< std::array< Eigen::Vector3d, 2 > > &boxes) const override
constructs a box around every element (3d cell, 2d face)
Definition Mesh3D.cpp:388
std::array< int, 8 > get_ordered_vertices_from_hex(const int element_index) const
Definition Mesh3D.cpp:322
std::pair< RowVectorNd, int > cell_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j, const int k) const
Definition Mesh3D.cpp:199
virtual int n_cell_faces(const int c_id) const =0
virtual int cell_face(const int c_id, const int lf_id) const =0
virtual std::vector< uint32_t > edge_neighs(const int e_gid) const =0
void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override
Get all the edges.
Definition Mesh3D.cpp:33
virtual Navigation3D::Index next_around_edge(Navigation3D::Index idx) const =0
virtual Navigation3D::Index switch_edge(Navigation3D::Index idx) const =0
void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override
constructs barycentric coodiantes for a point p.
Definition Mesh3D.cpp:410
std::pair< RowVectorNd, int > face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const
Definition Mesh3D.cpp:99
virtual std::vector< uint32_t > vertex_neighs(const int v_gid) const =0
std::pair< RowVectorNd, int > edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const
Definition Mesh3D.cpp:80
Mesh3D & operator=(Mesh3D &&)=default
bool is_volume() const override
checks if mesh is volume
Definition Mesh3D.hpp:28
virtual void get_vertex_elements_neighs(const int v_id, std::vector< int > &ids) const =0
virtual std::array< int, 4 > get_ordered_vertices_from_tet(const int element_index) const
Definition Mesh3D.cpp:346
void to_edge_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 12 > &to_edge) const
Definition Mesh3D.cpp:298
virtual Navigation3D::Index next_around_face(Navigation3D::Index idx) const =0
virtual Navigation3D::Index switch_face(Navigation3D::Index idx) const =0
virtual Navigation3D::Index get_index_from_element_face(int hi, int v0, int v1, int v2) const =0
virtual Navigation3D::Index get_index_from_element(int hi) const =0
void to_face_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 6 > &to_face) const
Definition Mesh3D.cpp:267
virtual Navigation3D::Index switch_vertex(Navigation3D::Index idx) const =0
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
void cell_barycenters(Eigen::MatrixXd &barycenters) const
all cells barycenters
Definition Mesh.cpp:320
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13