25#ifndef VULPES_GEOMETRY_MESH_MESH_2D_HPP_
26#define VULPES_GEOMETRY_MESH_MESH_2D_HPP_
37#include <unordered_map>
44#include <vtkCellArray.h>
48#include <vtkPolyData.h>
49#include <vtkPolyDataReader.h>
50#include <vtkPolygon.h>
51#include <vtkPolyhedron.h>
52#include <vtkSmartPointer.h>
54#include <vtkUnstructuredGrid.h>
55#include <vtkXMLUnstructuredGridReader.h>
56#include <vtkXMLUnstructuredGridWriter.h>
88template <
typename FloatType,
typename IndexType>
94 Mesh2D<FloatType, IndexType>> {
105 static inline constexpr IndexType
UNDEF =
static_cast<IndexType
>(-1);
120 const std::vector<SelfPoint>& vertexes,
123 this->
m_cell_to_vtx = cell_vertices.template compress<IndexType>();
134 const std::vector<SelfPoint>& vertexes,
148 const std::vector<SelfPoint>& vertexes,
151 :
Mesh2D(vertexes, cell_vertices) {
163 const std::vector<SelfPoint>& vertexes,
166 :
Mesh2D(vertexes, cell_vertices) {
174 template <
class Archive>
187 return static_cast<const BaseType&
>(lhs) ==
197 constexpr IndexType
nEntity(std::size_t dim)
const {
200 }
else if (dim == 1) {
202 }
else if (dim == 2) {
206 throw std::invalid_argument(
"invalid entity dimension");
215 template <std::
size_t dim>
217 if constexpr (dim == 0) {
219 }
else if constexpr (dim == 1) {
223 dim < 2,
"Dimension for getEntityToCellMap must be 0 or 1.");
238 agg_mesh.fixVertexAndFacetsOrders();
247 Mesh2D subMesh(
const std::vector<IndexType>& cell_ids)
const;
283extern template class Mesh2D<double, int32_t>;
284extern template class Mesh2D<double, uint32_t>;
285extern template class Mesh2D<double, int64_t>;
286extern template class Mesh2D<double, uint64_t>;
303template <
typename FloatType,
typename IndexType>
308 constexpr auto MAX = std::numeric_limits<FloatType>::max();
311 for (
const auto& point : mesh.getVertexes()) {
312 min_corner = min_corner.cwiseMin(point);
313 max_corner = max_corner.cwiseMax(point);
317 constexpr auto DELTA = 1e-2;
318 min_corner -= bbox_size * DELTA;
319 max_corner(0) += bbox_size(0) * DELTA;
320 using Vectord = Eigen::Vector<FloatType, -1>;
321 const Vectord x_grid =
322 Vectord::LinSpaced(n_cells_x + 1, min_corner(0), max_corner(0));
323 std::array<FloatType, 2> h = {(max_corner(0) - min_corner(0)) / n_cells_x, 0};
324 h[1] = h[0] * stretch;
325 std::array<std::vector<FloatType>, 2> grids = {
326 std::vector<FloatType>{min_corner[0]},
327 std::vector<FloatType>{min_corner[1]}};
328 for (std::size_t d = 0; d < 2; ++d) {
331 grids[d].push_back(grids[d][0] + i * h[d]);
333 }
while (grids[d].back() < max_corner(d));
352template <
typename FloatType,
typename IndexType>
355 const std::array<std::vector<FloatType>, 2>& grids,
356 FloatType agglomeration_threshold = 0.25);
372template <
typename FloatType,
typename IndexType>
376 FloatType stretch = 1,
377 FloatType agglomeration_threshold = 0.25) {
398template <
typename FloatType,
typename IndexType>
402 FloatType atol = 0.0,
403 FloatType rtol = 1e-4);
413template <
typename FloatType,
typename IndexType>
415 const std::string& filename,
416 bool check_vtxs_unique =
true,
417 bool add_tags =
true);
428template <
typename FloatType,
typename IndexType>
433 bool tria_elements =
false);
458template <
typename FloatType,
typename IndexType>
463 bool tria_elements =
false,
464 bool x_periodic =
true,
465 bool y_periodic =
true);
473template <
typename FloatType,
typename IndexType>
481 const std::array<std::vector<double>, 2>&,
494 const std::string&,
bool,
bool);
496 const std::string&,
bool,
bool);
498 const std::string&,
bool,
bool);
500 const std::string&,
bool,
bool);
558template <
typename FloatType,
typename IndexType>
561extern template bool isPeriodic<double, int32_t>(
567template <
typename FloatType,
typename IndexType>
579template <
typename FloatType,
typename IndexType>
588template <
typename FloatType,
typename IndexType>
589std::vector<Point<FloatType, 2>> getCellVertexesPeriodic(
592extern template std::vector<Point<double, 2>>
593getCellVertexesPeriodic<double, int32_t>(
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
Definition crs_map.hpp:72
IndexType size() const
Get the number of rows in the CRS map.
Definition crs_map.hpp:331
A class for a 2D mesh, inheriting from MeshBase.
Definition mesh_2d.hpp:94
static constexpr IndexType UNDEF
Definition mesh_2d.hpp:105
Mesh2D agglomerate(const std::vector< IndexType > &old_to_new_cell) const
Creates a new, coarser mesh by grouping cells together.
Definition mesh_2d.hpp:236
Mesh2D(const std::vector< SelfPoint > &vertexes, const CellToVtxMapUncompressed &cell_vertices)
Constructs a mesh from vertices and an uncompressed cell-to-vertex map.
Definition mesh_2d.hpp:119
constexpr IndexType nEntity(std::size_t dim) const
Returns the total number of entities of a given dimension.
Definition mesh_2d.hpp:197
Mesh2D()=default
Default constructor. Creates an empty mesh.
void buildMesh()
Builds all the necessary connectivity maps for the mesh.
Definition mesh_2d.hpp:255
Mesh2D(const std::vector< SelfPoint > &vertexes, const CellToVtxMapUncompressed &cell_vertices, const MeshTag< 2, IndexType > &tags)
Constructs a mesh from vertices, an uncompressed cell-to-vertex map, and tags.
Definition mesh_2d.hpp:162
Point< FloatType, 2 > SelfPoint
Alias for a 2D point.
Definition mesh_2d.hpp:96
MeshBase< FloatType, IndexType, 2, 2, Mesh2D< FloatType, IndexType > > BaseType
Alias for the map from cells to vertices.
Definition mesh_2d.hpp:98
void serialize(Archive &ar, const unsigned int)
Serializes the mesh data by calling the base class's serialization.
Definition mesh_2d.hpp:175
Mesh2D subMesh(const std::vector< IndexType > &cell_ids) const
Creates a new mesh from a subset of cells of the current mesh.
Definition mesh_2d.cpp:181
void fixVertexAndFacetsOrders()
Enforces the CCW ordering conventions for the mesh.
Definition mesh_2d.cpp:73
void buildFacetToCellAndCellToFacetAndFacetToVertex()
Builds the core connectivity maps relating facets (edges) to cells and vertices.
Definition mesh_2d.cpp:126
constexpr auto & getEntityToCellMap() const
Gets the connectivity map from a given entity dimension to cells.
Definition mesh_2d.hpp:216
friend bool operator==(const Mesh2D &lhs, const Mesh2D &rhs)
Checks if two 2D meshes are identical by comparing their base class data.
Definition mesh_2d.hpp:186
datastructure::CrsMapUncompressed< IndexType > CellToVtxMapUncompressed
A special value used to represent an undefined or invalid index.
Definition mesh_2d.hpp:103
Mesh2D(const std::vector< SelfPoint > &vertexes, const CellToVtxMap &cell_vertices, const MeshTag< 2, IndexType > &tags)
Constructs a mesh from vertices, a cell-to-vertex map, and tags.
Definition mesh_2d.hpp:147
datastructure::CrsMap< IndexType, IndexType > CellToVtxMap
Alias for the uncompressed version of the cell-to-vertex map.
Definition mesh_2d.hpp:101
Mesh2D(const std::vector< SelfPoint > &vertexes, const CellToVtxMap &cell_vertices)
Constructs a mesh from vertices and a compressed cell-to-vertex map.
Definition mesh_2d.hpp:133
A base class for creating and managing mesh data structures.
Definition mesh_base.hpp:370
FacetToCellMap & getFacetToCellMap()
Definition mesh_base.hpp:464
Mesh2D< FloatType, IndexType > agglomerateBase(const std::vector< index_t > &old_to_new_cell, bool check_connected=true) const
CellToFacetMap m_cell_to_facet
Definition mesh_base.hpp:733
VtxToCellMap & getVtxToCellMap()
Definition mesh_base.hpp:474
MeshTag< SelfDim, IndexType > m_mesh_tags
Definition mesh_base.hpp:749
std::vector< SelfPoint > m_vertexes
Definition mesh_base.hpp:728
DualMap & getDualMap()
Definition mesh_base.hpp:448
std::vector< SelfPoint > & getVertexes()
Definition mesh_base.hpp:442
CellToVtxMap m_cell_to_vtx
Definition mesh_base.hpp:735
std::array< std::vector< FloatType >, 2 > buildCartesianBbox(const Mesh2D< FloatType, IndexType > &mesh, IndexType n_cells_x, FloatType stretch)
Builds a 2D Cartesian grid that encloses a given mesh.
Definition mesh_2d.hpp:304
Mesh2D< FloatType, IndexType > intersectCartesianGrid(const Mesh2D< FloatType, IndexType > &mesh, const std::array< std::vector< FloatType >, 2 > &grids, FloatType agglomeration_threshold)
Creates a new mesh by intersecting an existing mesh with a Cartesian grid.
Definition mesh_2d.cpp:900
Definition abs_agg_model.cpp:40
Eigen::Matrix< DataType, Dim, 1, Eigen::ColMajor > Point
Definition traits.hpp:34
Definition cell_manager.hpp:38
A structure to store tags for different parts of a mesh.
Definition mesh_base.hpp:333