Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::geometry::internal Namespace Reference

Helpers implementing VulPoly's Voronoi construction and cleanup. More...

Functions

template<typename MeshType>
AbstractAgglomerationModel< MeshType >::float_t maxVtxToVtxSquaredDistance (const std::vector< typename MeshType::SelfPoint > &vertexes, const typename AbstractAgglomerationModel< MeshType >::IndVec &subset, float_t early_stop=std::numeric_limits< float_t >::infinity())
template<typename T>
constexpr torch::ScalarType toTorchType ()
 Map C++ mesh types (float, double, int32_t, int64_t) to the corresponding Torch scalar type.
static CellInitOptionsType normalizeCellFlags (CellInitOptionsType cell_init_options)
template<typename Dst, typename Src>
constexpr auto cast (const datastructure::CrsMap< Src, Src > &map)
 Re-types a CRS map to use a different integral type for indices and values.
template<typename VecType>
void checkEmptySets (const VecType &labels)
 Checks for and warns about empty classes in a label vector.
template<typename index_t>
datastructure::CrsMap< index_t, index_t > buildSubDual (const datastructure::CrsMap< index_t, index_t > &dual_map, const std::vector< index_t > &subset_idxs)
 Extracts the dual subgraph corresponding to a subset of vertices.
template<typename index_t>
index_t removeEmptySets (std::vector< index_t > &labels)
 Compresses labels to a contiguous range [0, N-1].
template<typename IndexType>
void importVtkMeshTags (vtkFieldData *field_data, std::string_view association, std::unordered_map< std::string, std::vector< IndexType > > &tags)
 Imports scalar numeric VTK arrays into an integer mesh-tag table.
template<int32_t Dim>
std::pair< double, double > updateVoronoiCentroid (const std::array< Point< double, Dim >, 2 > &bbox, std::vector< Point< double, Dim > > &points, int32_t n_inside_seeds)
 Move each Voronoi seed to its cell centroid and estimate relaxation error.
template<typename FloatType, typename IndexType, IndexType Dim, typename D>
Point< FloatType, Dim > computeGradient (const Point< FloatType, Dim > x, const DistanceExpression< double, Dim, D > &distanceFunction, IndexType idx, FloatType finite_difference_h)
 Estimate a signed-distance gradient by centered finite differences.
template<int32_t Dim, typename D>
Mesh2D< double, int32_t > computeVoronoiMesh2D (const std::array< Point< double, 2 >, 2 > &bbox, const std::vector< Point< double, 2 > > &points, const DistanceExpression< double, Dim, D > &distanceFunction)
 Convert in-domain 2D Voronoi cells into a Vulpes mesh.
template<int32_t Dim, typename D>
Mesh3D< double, int32_t > computeVoronoiMesh3D (const std::array< Point< double, 3 >, 2 > &bbox, const std::vector< Point< double, 3 > > &points, const DistanceExpression< double, Dim, D > &distanceFunction)
 Convert in-domain 3D Voronoi cells into a Vulpes mesh.
template<typename FloatType, typename IndexType, IndexType Dim>
void vulPolyAdjustFixedPoints (const std::vector< Point< FloatType, Dim > > &fixed_pts, const std::vector< IndexType > &near_boundary_idxs, std::vector< Point< FloatType, Dim > > &seed_pts)
 Adjust nearby seeds to keep fixed points represented in the mesh.
template<typename FloatType, typename IndexType, IndexType Dim, typename D>
std::vector< IndexType > vulPolyReflect (const DistanceExpression< FloatType, Dim, D > &distanceFunction, FloatType alpha, const vulpoly::VulPolyParams< FloatType > &params, std::vector< Point< FloatType, Dim > > &seed_pts)
 Add reflected seeds near domain boundaries.
template<typename FloatType, typename MeshType, typename D>
void vulPolyClipToBoundary (MeshType &mesh, FloatType alpha, const DistanceExpression< FloatType, MeshType::self_dim, D > &distanceFunction, const vulpoly::VulPolyParams< FloatType > &params)
 Improve positions of mesh vertices close to the domain boundary.
template<typename FloatType, typename IndexType>
FloatType vulPolyComputeEdgeAngle (const Mesh2D< FloatType, IndexType > &mesh, IndexType cell_id, const std::array< IndexType, 2 > &edge)
 Estimate an edge's normalized angular size in an adjacent cell.
template<typename FloatType, typename IndexType, IndexType Dim, typename D>
void vulPolyCollapseEdges (Mesh2D< FloatType, IndexType > &mesh, const DistanceExpression< FloatType, Dim, D > &distanceFunction, FloatType edge_collapse_tol)
 Collapse isolated undersized edges in a 2D mesh.

Detailed Description

Helpers implementing VulPoly's Voronoi construction and cleanup.

The PolyMesher-derived algorithms are identified in their documentation. This namespace also adapts Voro++ output to Vulpes mesh data structures.

Function Documentation

◆ buildSubDual()

template<typename index_t>
datastructure::CrsMap< index_t, index_t > vulpes::geometry::internal::buildSubDual ( const datastructure::CrsMap< index_t, index_t > & dual_map,
const std::vector< index_t > & subset_idxs )

Extracts the dual subgraph corresponding to a subset of vertices.

Given a dual graph for an entire mesh and a list of vertex indices, this function constructs and returns the induced subgraph containing only the specified vertices and the edges between them. The vertices in the resulting subgraph are re-indexed to form a contiguous range [0, N-1], where N is the number of vertices in the subset.

Template Parameters
index_tThe integral type used for graph indices.
Parameters
dual_mapThe dual graph of the entire mesh, represented as a CrsMap.
subset_idxsA vector of vertex indices defining the subgraph to extract.
Returns
A new CrsMap representing the extracted subgraph.

◆ cast()

template<typename Dst, typename Src>
auto vulpes::geometry::internal::cast ( const datastructure::CrsMap< Src, Src > & map)
inlineconstexpr

Re-types a CRS map to use a different integral type for indices and values.

This function converts a CrsMap from a source integral type Src to a destination integral type Dst. If Dst and Src are the same, the input map is returned unchanged. Otherwise, it constructs a new CrsMap by performing an element-wise cast on both the data and index arrays.

Template Parameters
DstThe destination integral type for the new map's indices and values.
SrcThe source integral type for the input map's indices and values.
Parameters
mapThe input CrsMap with data and indices of type Src.
Returns
The original map if Dst is the same as Src, otherwise a new CrsMap<Dst, Dst> with casted elements.
Warning
This operation may result in narrowing if values or indices in the source map do not fit within the range of the Dst type.
Note
Complexity is Linear in the number of elements: $O(|map.data()| + |map.indices()|)$.

◆ checkEmptySets()

template<typename VecType>
void vulpes::geometry::internal::checkEmptySets ( const VecType & labels)

Checks for and warns about empty classes in a label vector.

This function inspects a vector of labels and determines the number of classes as max(labels) + 1. It then checks if every class ID in the range [0, max(labels)] is present at least once. A warning message is printed to std::cerr for each class that has no members.

Template Parameters
VecTypeA random-access container type that supports size() and operator[], such as std::vector.
Parameters
labelsA container of partition labels. Values are expected to be non-negative.
Note
complexity $O(N + M)$, where $N$ is the number of labels and $M$ is the maximum label value.
This function has no side effects other than potentially printing diagnostic messages to standard error.

◆ computeGradient()

template<typename FloatType, typename IndexType, IndexType Dim, typename D>
Point< FloatType, Dim > vulpes::geometry::internal::computeGradient ( const Point< FloatType, Dim > x,
const DistanceExpression< double, Dim, D > & distanceFunction,
IndexType idx,
FloatType finite_difference_h )

Estimate a signed-distance gradient by centered finite differences.

Template Parameters
FloatTypeCoordinate scalar type.
IndexTypeIndex type used for the selected distance component.
DimSpatial dimension.
DDistance-expression implementation type.
Parameters
xPoint where the gradient is evaluated.
distanceFunctionSigned-distance expression.
idxDistance component to differentiate, or -1 for the final domain distance.
finite_difference_hCentered-difference step size.
Returns
Estimated gradient of the requested distance component.

◆ computeVoronoiMesh2D()

template<int32_t Dim, typename D>
Mesh2D< double, int32_t > vulpes::geometry::internal::computeVoronoiMesh2D ( const std::array< Point< double, 2 >, 2 > & bbox,
const std::vector< Point< double, 2 > > & points,
const DistanceExpression< double, Dim, D > & distanceFunction )

Convert in-domain 2D Voronoi cells into a Vulpes mesh.

Template Parameters
DimDimension parameter of the distance expression.
DDistance-expression implementation type.
Parameters
bboxBounding box for Voronoi cell construction.
pointsVoronoi seeds.
distanceFunctionDomain signed-distance expression used to retain cells inside the domain.
Returns
A 2D mesh with coincident neighboring cell vertices merged.

◆ computeVoronoiMesh3D()

template<int32_t Dim, typename D>
Mesh3D< double, int32_t > vulpes::geometry::internal::computeVoronoiMesh3D ( const std::array< Point< double, 3 >, 2 > & bbox,
const std::vector< Point< double, 3 > > & points,
const DistanceExpression< double, Dim, D > & distanceFunction )

Convert in-domain 3D Voronoi cells into a Vulpes mesh.

Template Parameters
DimDimension parameter of the distance expression.
DDistance-expression implementation type.
Parameters
bboxBounding box for Voronoi cell construction.
pointsVoronoi seeds.
distanceFunctionDomain signed-distance expression used to retain cells inside the domain.
Returns
A 3D mesh with shared vertices and face connectivity.

◆ importVtkMeshTags()

template<typename IndexType>
void vulpes::geometry::internal::importVtkMeshTags ( vtkFieldData * field_data,
std::string_view association,
std::unordered_map< std::string, std::vector< IndexType > > & tags )

Imports scalar numeric VTK arrays into an integer mesh-tag table.

Mesh tags currently store one integer per entity. Numeric arrays with more than one component are therefore skipped, while scalar floating-point arrays are converted with an explicit warning. Nonnumeric arrays are rejected.

Template Parameters
IndexTypeThe integer type used to store mesh tags.
Parameters
field_dataVTK point or cell data containing the arrays to import.
associationHuman-readable array association used in diagnostics.
tagsDestination mesh-tag table.

◆ maxVtxToVtxSquaredDistance()

template<typename MeshType>
AbstractAgglomerationModel< MeshType >::float_t vulpes::geometry::internal::maxVtxToVtxSquaredDistance ( const std::vector< typename MeshType::SelfPoint > & vertexes,
const typename AbstractAgglomerationModel< MeshType >::IndVec & subset,
float_t early_stop = std::numeric_limits<float_t>::infinity() )

◆ normalizeCellFlags()

CellInitOptionsType vulpes::geometry::internal::normalizeCellFlags ( CellInitOptionsType cell_init_options)
inlinestatic

◆ removeEmptySets()

template<typename index_t>
index_t vulpes::geometry::internal::removeEmptySets ( std::vector< index_t > & labels)

Compresses labels to a contiguous range [0, N-1].

This function modifies a vector of labels in-place, remapping them so that the set of unique labels becomes a dense range [0, N-1], where N is the total number of unique labels originally present. The relative ordering of labels is preserved.

For example, an input of {3, 0, 3, 5, 0} would be modified to {1, 0, 1, 2, 0}, and the function would return 3.

Template Parameters
index_tThe integral type of the labels.
Parameters
[in,out]labelsThe vector of labels to be modified.
Returns
The number of unique labels, N.

◆ toTorchType()

template<typename T>
torch::ScalarType vulpes::geometry::internal::toTorchType ( )
constexpr

Map C++ mesh types (float, double, int32_t, int64_t) to the corresponding Torch scalar type.

Template Parameters
TC++ mesh type

◆ updateVoronoiCentroid()

template<int32_t Dim>
std::pair< double, double > vulpes::geometry::internal::updateVoronoiCentroid ( const std::array< Point< double, Dim >, 2 > & bbox,
std::vector< Point< double, Dim > > & points,
int32_t n_inside_seeds )

Move each Voronoi seed to its cell centroid and estimate relaxation error.

Template Parameters
DimSpatial dimension.
Parameters
bboxTwo opposite corners of the box containing the Voronoi diagram.
pointsSeeds, updated in place by adding each cell's centroid offset.
n_inside_seedsNumber of original in-domain seeds used for error and area accumulation; appended reflected seeds are excluded.
Returns
The normalized centroid displacement error and summed in-domain cell area/measure.
Note
Centroidal Voronoi relaxation follows PolyMesher; see the file reference.

◆ vulPolyAdjustFixedPoints()

template<typename FloatType, typename IndexType, IndexType Dim>
void vulpes::geometry::internal::vulPolyAdjustFixedPoints ( const std::vector< Point< FloatType, Dim > > & fixed_pts,
const std::vector< IndexType > & near_boundary_idxs,
std::vector< Point< FloatType, Dim > > & seed_pts )

Adjust nearby seeds to keep fixed points represented in the mesh.

Template Parameters
FloatTypeCoordinate scalar type.
IndexTypeSeed index type.
DimSpatial dimension.
Parameters
fixed_ptsLocations to preserve.
near_boundary_idxsIndices of seeds close to the domain boundary.
seed_ptsSeeds to update in place.
Note
Preserving fixed points during Voronoi relaxation follows the PolyMesher approach; see the file reference.

◆ vulPolyClipToBoundary()

template<typename FloatType, typename MeshType, typename D>
void vulpes::geometry::internal::vulPolyClipToBoundary ( MeshType & mesh,
FloatType alpha,
const DistanceExpression< FloatType, MeshType::self_dim, D > & distanceFunction,
const vulpoly::VulPolyParams< FloatType > & params )

Improve positions of mesh vertices close to the domain boundary.

Template Parameters
FloatTypeCoordinate scalar type.
MeshTypeMesh type being modified.
DDistance-expression implementation type.
Parameters
meshMesh whose vertices may be clipped.
alphaCharacteristic cell width.
distanceFunctionDomain signed-distance expression.
paramsVulPoly algorithm parameters.
Note
This boundary-vertex correction is a Vulpes addition to the PolyMesher-derived meshing procedure.

◆ vulPolyCollapseEdges()

template<typename FloatType, typename IndexType, IndexType Dim, typename D>
void vulpes::geometry::internal::vulPolyCollapseEdges ( Mesh2D< FloatType, IndexType > & mesh,
const DistanceExpression< FloatType, Dim, D > & distanceFunction,
FloatType edge_collapse_tol )

Collapse isolated undersized edges in a 2D mesh.

Template Parameters
FloatTypeCoordinate scalar type.
IndexTypeMesh index type.
DimDimension parameter of the distance expression.
DDistance-expression implementation type.
Parameters
meshMesh to simplify in place.
distanceFunctionDomain signed-distance expression, used to preserve the boundary approximation.
edge_collapse_tolThreshold for an edge's normalized angular size.
Note
Short-edge removal follows PolyMesher; see the file reference.

◆ vulPolyComputeEdgeAngle()

template<typename FloatType, typename IndexType>
FloatType vulpes::geometry::internal::vulPolyComputeEdgeAngle ( const Mesh2D< FloatType, IndexType > & mesh,
IndexType cell_id,
const std::array< IndexType, 2 > & edge )

Estimate an edge's normalized angular size in an adjacent cell.

Template Parameters
FloatTypeCoordinate scalar type.
IndexTypeMesh index type.
Parameters
mesh2D mesh containing the cell and edge.
cell_idAdjacent cell index, or -1 for a boundary side.
edgeThe edge's two vertex indices in the requested orientation.
Returns
Normalized angular size, or the maximum scalar value for cell_id -1.

◆ vulPolyReflect()

template<typename FloatType, typename IndexType, IndexType Dim, typename D>
std::vector< IndexType > vulpes::geometry::internal::vulPolyReflect ( const DistanceExpression< FloatType, Dim, D > & distanceFunction,
FloatType alpha,
const vulpoly::VulPolyParams< FloatType > & params,
std::vector< Point< FloatType, Dim > > & seed_pts )

Add reflected seeds near domain boundaries.

Template Parameters
FloatTypeCoordinate scalar type.
IndexTypeSeed index type.
DimSpatial dimension.
DDistance-expression implementation type.
Parameters
distanceFunctionDomain signed-distance expression.
alphaCharacteristic distance used to select seeds near boundaries.
paramsVulPoly algorithm parameters.
seed_ptsSeeds, extended in place with successful reflections.
Returns
Indices of original seeds near the boundary and of the reflected points appended to seed_pts.
Note
Boundary reflection follows PolyMesher; see the file reference.