Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
cell.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22
23#ifndef VULPES_GEOMETRY_CELL_HPP_
24#define VULPES_GEOMETRY_CELL_HPP_
25
26#include <algorithm>
27#include <set>
28#include <utility>
29#include <vector>
30
31#include <boost/unordered/unordered_flat_map.hpp>
32
37
38namespace vulpes {
39
40// forward declaration
41namespace geometry {
42template <typename FloatType, typename IndexType>
43class Cell2D;
44template <typename FloatType, typename IndexType>
45class Cell3D;
46} // namespace geometry
47
48// forward declaration
49namespace qfree {
50template <bool PPoly, typename FloatType, typename IndexType>
53template <bool PPoly, typename FloatType, typename IndexType>
56template <bool PPoly, typename FloatType, typename IndexType>
57std::pair<
61 const geometry::Cell2D<FloatType, IndexType>& cell, IndexType deg);
62template <bool PPoly, typename FloatType, typename IndexType>
65template <bool PPoly, typename FloatType, typename IndexType>
68template <bool PPoly, bool Pruning, typename FloatType, typename IndexType>
69std::pair<
73 const geometry::Cell3D<FloatType, IndexType>& elem, IndexType deg);
74} // namespace qfree
75
76namespace geometry {
77
78enum CellInitOptions : uint32_t {
80 CellInitNormals = (1ULL << 0ULL),
81 CellInitLocalMaps = (1ULL << 1ULL),
82 CellInitInverseMaps = (1ULL << 2ULL),
83 CellInitEdgeToCompute = (1ULL << 3ULL),
84 CellInitFaces = (1ULL << 4ULL),
85 CellInitBBox = (1ULL << 5ULL),
86 CellInitDiameter = (1ULL << 6ULL),
87 CellInitMeasure = (1ULL << 7ULL),
88 CellInitBarycenter = (1ULL << 8ULL),
89 CellInitFaceDiameter = (1ULL << 9ULL),
90 CellInitFaceKb = (1ULL << 10ULL),
91 CellInitInscribedDiameter = (1ULL << 11ULL),
92 CellInitAll = 0xFFFFFFFFUL,
93};
94
95using CellInitOptionsType = std::underlying_type_t<CellInitOptions>;
96
97template <typename FloatType, typename IndexType = int32_t>
98class Cell2D {
99 public:
100 Cell2D() = default;
101 Cell2D(
103 IndexType cell_id,
104 CellInitOptionsType cell_init_options = CellInitVtxOnly);
105
106 void computeBbox() {
107 m_bbox.col(0) = m_vtxs.rowwise().minCoeff();
108 m_bbox.col(1) = m_vtxs.rowwise().maxCoeff();
109 }
110
111 void computeNormals();
112 void computeCellDiameter();
113 void computeFaceDiameter();
115 void computeFaceKb();
116
117 void computeMeasure(bool compute_barycenter);
118
119 const auto& vtxs() const { return m_vtxs; }
120 auto& vtxs() { return m_vtxs; }
121 const auto& bbox() const { return m_bbox; }
122 const auto& normals() const { return m_normals; }
123 Eigen::Index nfaces() const { return m_vtxs.cols(); }
124 Eigen::Index nedges() const { return m_vtxs.cols(); }
125 const auto& barycenter() const { return m_barycenter; }
126 auto diameter() const { return m_diameter; }
128 auto measure() const { return m_measure; }
129 auto frontierMeasure() const { return m_frontier_measure; }
130 const auto& faceDiam() const { return m_face_diameter; }
131 const auto& faceMeasures() const { return m_face_measures; }
132 const auto& faceKb() const { return m_face_kb; }
133
134 protected:
135 void init(CellInitOptionsType cell_init_options);
136 Eigen::Matrix<FloatType, 2, -1, Eigen::ColMajor> m_vtxs;
137 Eigen::Matrix<FloatType, 2, -1, Eigen::ColMajor> m_normals;
138 Eigen::Matrix<FloatType, 2, 2> m_bbox;
139 FloatType m_diameter = 0.0;
140 FloatType m_inscribed_diameter = 0.0;
141 FloatType m_measure = 0.0;
142 FloatType m_frontier_measure = 0.0;
143 Eigen::Vector<FloatType, -1> m_face_measures;
144 Eigen::Vector<FloatType, 2> m_barycenter;
145
146 Eigen::Vector<FloatType, -1> m_face_diameter;
147 Eigen::Vector<FloatType, -1> m_face_kb;
148};
149
150template <typename FloatType, typename IndexType>
151class Cell3D {
152 public:
153 Cell3D() = default;
154
155 Cell3D(
157 const std::vector<Point<FloatType, 3>>& coords,
158 CellInitOptionsType cell_init_options = CellInitAll);
159
160 Cell3D(
162 IndexType cell_id,
163 CellInitOptionsType cell_init_options = CellInitVtxOnly);
164
165 void computeBbox() {
166 m_bbox.col(0) = m_vtxs.rowwise().minCoeff();
167 m_bbox.col(1) = m_vtxs.rowwise().maxCoeff();
168 }
169
170 void init(CellInitOptionsType cell_init_options);
171
172 void computeCellDiameter();
173
174 void computeMeasure(bool compute_barycenter);
175 void computeNormals();
176
178 void computeFaceDiameter();
179 void computeFaceKb();
180
181 const auto& vtxs() const { return m_vtxs; }
182 auto& vtxs() { return m_vtxs; }
183 const auto& faces() const { return m_faces; }
184 Eigen::Index nfaces() const { return m_faces.size(); }
185 Eigen::Index nedges() const {
186 assert(m_local_map_built);
187 return m_edges.size();
188 }
189 const auto& normals() const { return m_normals; }
190 const auto& edges() const {
191 assert(m_local_map_built);
192 return m_edges;
193 }
194 const auto& getEdgeToFaces() const {
195 assert(m_local_map_built);
196 return m_edges_to_faces;
197 }
198 const auto& getFaceCenterIdx() const {
200 return m_face_xF_idx;
201 }
202 const auto& getEdgesToCompute() const {
204 return m_edges_to_compute;
205 }
206 const auto& getVtxToFace() const {
207 assert(m_inverse_map_built);
208 return m_vtx_to_faces;
209 }
210 const auto& bbox() const { return m_bbox; }
211 const auto& barycenter() const { return m_barycenter; }
212 auto diameter() const { return m_diameter; }
213 auto measure() const { return m_measure; }
214 auto frontierMeasure() const { return m_frontier_measure; }
215 const auto& faceDiam() const { return m_face_diameter; }
216 const auto& faceMeasures() const { return m_face_measures; }
217 const auto& faceKb() const { return m_face_kb; }
218
219 protected:
220 void buildEdgeToFace();
221 void buildInverseMaps();
222 void findEdgesToCompute();
223
224 bool m_local_map_built = false;
227
228 // list of indices defining a face (order must point towards outer normal)
230 // pairs of indices defining and edge
231 std::vector<std::array<IndexType, 2>> m_edges;
232 // list of physical coordinates
233 Eigen::Matrix<FloatType, 3, -1> m_vtxs;
234 Eigen::Matrix<FloatType, 3, 2> m_bbox;
235 Eigen::Matrix<FloatType, 3, -1> m_normals;
236 // map each edge to the two faces (indexes) to which the edge belongs to
237 // the order is important, because the two edges are traversed in opposed
238 // ways in order to point towards the outer normal, the first face is the
239 // one where the edges are traversed in increasing order of the indices
240 std::vector<std::array<IndexType, 2>> m_edges_to_faces;
241 // origin of the coordinates system for each face as the index of a vertex
242 std::vector<IndexType> m_face_xF_idx;
243 // list of indices of the edges that necessitates the integrals to be
244 // computed
245 std::vector<IndexType> m_edges_to_compute;
246
250
251 FloatType m_diameter = 0.0;
252 FloatType m_inscribed_diameter = 0.0;
253 FloatType m_measure = 0.0;
254 FloatType m_frontier_measure = 0.0;
255 Eigen::Vector<FloatType, -1> m_face_measures;
256 Eigen::Vector<FloatType, 3> m_barycenter;
257
258 Eigen::Vector<FloatType, -1> m_face_diameter;
259 Eigen::Vector<FloatType, -1> m_face_kb;
260};
261
262template <
263 std::size_t Dim,
264 typename FloatType,
265 typename IndexType,
266 typename = std::enable_if_t<(Dim == 2) || (Dim == 3)>>
267using Cell = std::conditional_t<
268 Dim == 2,
271
272extern template class Cell2D<double, int32_t>;
273// extern template class Cell2D<double, uint32_t>;
274// extern template class Cell2D<double, int64_t>;
275// extern template class Cell2D<double, uint64_t>;
276extern template class Cell3D<double, int32_t>;
277// extern template class Cell3D<double, uint32_t>;
278// extern template class Cell3D<double, int64_t>;
279// extern template class Cell3D<double, uint64_t>;
280
281} // namespace geometry
282} // namespace vulpes
283
284#endif // VULPES_GEOMETRY_CELL_HPP_
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
Definition crs_map.hpp:72
A class that represents a tetrahedral matrix or tensor, with optional support for higher-dimensional ...
Definition tensor.hpp:307
A class that represents a triangular or square matrix, with optional support for tensor-like multi-di...
Definition tensor.hpp:60
Definition cell.hpp:98
auto diameter() const
Definition cell.hpp:126
void init(CellInitOptionsType cell_init_options)
Definition cell.cpp:83
Eigen::Vector< FloatType, -1 > m_face_kb
Definition cell.hpp:147
auto & vtxs()
Definition cell.hpp:120
const auto & faceKb() const
Definition cell.hpp:132
FloatType m_measure
Definition cell.hpp:141
void computeInscribedDiameter()
Definition cell.cpp:120
const auto & faceDiam() const
Definition cell.hpp:130
Eigen::Matrix< FloatType, 2, -1, Eigen::ColMajor > m_normals
Definition cell.hpp:137
auto frontierMeasure() const
Definition cell.hpp:129
auto inscribedDiameter() const
Definition cell.hpp:127
const auto & vtxs() const
Definition cell.hpp:119
Eigen::Index nedges() const
Definition cell.hpp:124
Eigen::Matrix< FloatType, 2, 2 > m_bbox
Definition cell.hpp:138
Eigen::Matrix< FloatType, 2, -1, Eigen::ColMajor > m_vtxs
Definition cell.hpp:136
void computeCellDiameter()
Definition cell.cpp:109
auto measure() const
Definition cell.hpp:128
void computeNormals()
Definition cell.cpp:71
Eigen::Vector< FloatType, 2 > m_barycenter
Definition cell.hpp:144
Eigen::Vector< FloatType, -1 > m_face_diameter
Definition cell.hpp:146
void computeFaceKb()
Definition cell.cpp:149
const auto & faceMeasures() const
Definition cell.hpp:131
void computeMeasure(bool compute_barycenter)
Definition cell.cpp:167
FloatType m_frontier_measure
Definition cell.hpp:142
FloatType m_inscribed_diameter
Definition cell.hpp:140
const auto & normals() const
Definition cell.hpp:122
void computeFaceDiameter()
Definition cell.cpp:136
FloatType m_diameter
Definition cell.hpp:139
Eigen::Vector< FloatType, -1 > m_face_measures
Definition cell.hpp:143
void computeBbox()
Definition cell.hpp:106
const auto & barycenter() const
Definition cell.hpp:125
Eigen::Index nfaces() const
Definition cell.hpp:123
const auto & bbox() const
Definition cell.hpp:121
Definition cell.hpp:151
const auto & faceMeasures() const
Definition cell.hpp:216
void buildInverseMaps()
Definition cell.cpp:420
void init(CellInitOptionsType cell_init_options)
Definition cell.cpp:242
Eigen::Vector< FloatType, -1 > m_face_diameter
Definition cell.hpp:258
void computeInscribedDiameter()
Definition cell.cpp:295
const auto & getEdgesToCompute() const
Definition cell.hpp:202
auto frontierMeasure() const
Definition cell.hpp:214
void computeFaceKb()
Definition cell.cpp:382
void findEdgesToCompute()
Definition cell.cpp:502
Eigen::Matrix< FloatType, 3, -1 > m_vtxs
Definition cell.hpp:233
bool m_inverse_map_built
Definition cell.hpp:225
const auto & faceDiam() const
Definition cell.hpp:215
const auto & faceKb() const
Definition cell.hpp:217
const auto & getFaceCenterIdx() const
Definition cell.hpp:198
const auto & faces() const
Definition cell.hpp:183
FloatType m_frontier_measure
Definition cell.hpp:254
const auto & edges() const
Definition cell.hpp:190
Eigen::Matrix< FloatType, 3, -1 > m_normals
Definition cell.hpp:235
Eigen::Vector< FloatType, 3 > m_barycenter
Definition cell.hpp:256
std::vector< std::array< IndexType, 2 > > m_edges_to_faces
Definition cell.hpp:240
FloatType m_inscribed_diameter
Definition cell.hpp:252
const auto & getEdgeToFaces() const
Definition cell.hpp:194
auto & vtxs()
Definition cell.hpp:182
void computeNormals()
Definition cell.cpp:333
datastructure::CrsMap< IndexType, IndexType > m_vtx_to_faces
Definition cell.hpp:247
std::vector< std::array< IndexType, 2 > > m_edges
Definition cell.hpp:231
Eigen::Vector< FloatType, -1 > m_face_kb
Definition cell.hpp:259
bool m_edges_to_compute_built
Definition cell.hpp:226
auto measure() const
Definition cell.hpp:213
Eigen::Index nfaces() const
Definition cell.hpp:184
void computeCellDiameter()
Definition cell.cpp:284
Eigen::Matrix< FloatType, 3, 2 > m_bbox
Definition cell.hpp:234
std::vector< IndexType > m_edges_to_compute
Definition cell.hpp:245
FloatType m_diameter
Definition cell.hpp:251
const auto & vtxs() const
Definition cell.hpp:181
datastructure::CrsMap< IndexType, IndexType > m_face_to_edge
Definition cell.hpp:249
const auto & normals() const
Definition cell.hpp:189
void computeFaceDiameter()
Definition cell.cpp:367
bool m_local_map_built
Definition cell.hpp:224
datastructure::CrsMap< IndexType, IndexType > m_vtx_to_edge
Definition cell.hpp:248
void buildEdgeToFace()
Definition cell.cpp:455
void computeMeasure(bool compute_barycenter)
Definition cell.cpp:313
Eigen::Index nedges() const
Definition cell.hpp:185
const auto & barycenter() const
Definition cell.hpp:211
const auto & bbox() const
Definition cell.hpp:210
FloatType m_measure
Definition cell.hpp:253
auto diameter() const
Definition cell.hpp:212
datastructure::CrsMap< IndexType, IndexType > m_faces
Definition cell.hpp:229
void computeBbox()
Definition cell.hpp:165
const auto & getVtxToFace() const
Definition cell.hpp:206
std::vector< IndexType > m_face_xF_idx
Definition cell.hpp:242
Eigen::Vector< FloatType, -1 > m_face_measures
Definition cell.hpp:255
A class for a 2D mesh, inheriting from MeshBase.
Definition mesh_2d.hpp:94
Represents a 3D mesh.
Definition mesh_3d.hpp:82
Definition abs_agg_model.cpp:40
Eigen::Matrix< DataType, Dim, 1, Eigen::ColMajor > Point
Definition traits.hpp:34
std::conditional_t< Dim==2, Cell2D< FloatType, IndexType >, Cell3D< FloatType, IndexType > > Cell
Definition cell.hpp:267
std::underlying_type_t< CellInitOptions > CellInitOptionsType
Definition cell.hpp:95
CellInitOptions
Definition cell.hpp:78
@ CellInitAll
Definition cell.hpp:92
@ CellInitEdgeToCompute
Definition cell.hpp:83
@ CellInitVtxOnly
Definition cell.hpp:79
@ CellInitFaceKb
Definition cell.hpp:90
@ CellInitFaceDiameter
Definition cell.hpp:89
@ CellInitInverseMaps
Definition cell.hpp:82
@ CellInitBarycenter
Definition cell.hpp:88
@ CellInitFaces
Definition cell.hpp:84
@ CellInitLocalMaps
Definition cell.hpp:81
@ CellInitBBox
Definition cell.hpp:85
@ CellInitMeasure
Definition cell.hpp:87
@ CellInitNormals
Definition cell.hpp:80
@ CellInitInscribedDiameter
Definition cell.hpp:91
@ CellInitDiameter
Definition cell.hpp:86
Definition cell.hpp:49
datastructure::TetraTensor< PPoly, false, FloatType, IndexType > VolumeIntegral3D
Definition cell.hpp:63
std::pair< VolumeIntegral3D< PPoly, FloatType, IndexType >, LowerIntegral3D< PPoly, FloatType, IndexType > > integrateMonomialsQFree3D(const geometry::Cell3D< FloatType, IndexType > &elem, IndexType deg)
Computes the volume and lower-dimensional integrals over a 3D element without quadrature.
Definition qfree.cpp:106
datastructure::TriMatrix< PPoly, true, FloatType, IndexType > EdgeIntegral2D
Definition cell.hpp:54
datastructure::TetraTensor< PPoly, true, FloatType, IndexType > LowerIntegral3D
Definition cell.hpp:66
std::pair< AreaIntegral2D< PPoly, FloatType, IndexType >, EdgeIntegral2D< PPoly, FloatType, IndexType > > integrateMonomialsQFree2D(const geometry::Cell2D< FloatType, IndexType > &cell, IndexType deg)
Computes the 2D area and edge integrals over a polygonal cell without requiring quadrature points of ...
Definition qfree.cpp:36
datastructure::TriMatrix< PPoly, false, FloatType, IndexType > AreaIntegral2D
Definition cell.hpp:51
Definition cell_manager.hpp:38