![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
GNN-based agglomeration model (GraphSAGE via TorchScript). More...
#include <gnn_agglomeration.hpp>
Public Types | |
| using | ClassFloatType = typename AbstractAgglomerationModel<MeshType>::float_t |
| using | ClassIndexType = typename AbstractAgglomerationModel<MeshType>::index_t |
| using | MapType = typename AbstractAgglomerationModel<MeshType>::MapType |
| using | MeshFloatType = typename MeshType::float_t |
| using | MeshIndexType = typename MeshType::index_t |
| using | CellType = Cell<MeshType::self_dim, MeshFloatType, MeshIndexType> |
| using | IndVec = typename AbstractAgglomerationModel<MeshType>::IndVec |
| using | IndexTrackerType |
| using | Module = torch::jit::script::Module |
| using | ParamType = typename AbstractAgglomerationModel<MeshType>::ParamType |
| using | float_t = double |
| using | index_t = int64_t |
Public Member Functions | |
| GNNAgglomeration (const std::string &name, SAGEType SAGE_t) | |
| Construct a GNN agglomerator. | |
| std::vector< MeshType > | agglomerate (const MeshType &mesh, MethodType method_type, ParamType params, bool return_hierarchy=true, const std::string &segregated_tag="", const IndVec &subset={}) override |
| Agglomerate a mesh using a selected high-level strategy. | |
| std::vector< IndVec > | multFactor (const MeshType &mesh, const float_t target_h, IndexTrackerType &indicator, const std::vector< bool > &agglomerate) |
| Partitions the mesh based on a multiplicative factor strategy. | |
| std::vector< IndVec > | bisectNRef (const MeshType &mesh, const index_t n_refs, IndexTrackerType &indicator, const std::vector< bool > &agglomerate) |
| Applies recursive bisection n_refs times. | |
Static Public Attributes | |
| static constexpr auto | s_torch_mesh_float_type |
| static constexpr auto | s_torch_mesh_index_type |
| static constexpr auto | s_torch_class_index_type |
| static constexpr ClassIndexType | dim = MeshType::outer_dim |
Protected Member Functions | |
| std::vector< IndVec > | invokeMethod (const MeshType &mesh, MethodType method_type, ParamType params, const std::string &segregation_tag, const IndVec &subset) |
| Dispatches to the correct agglomeration method to compute cell labels. | |
| void | connectedComponents (const IndVec &subset, IndexTrackerType &indicator, index_t &max_id) |
| Splits a set of cells into its connected components. | |
| void | groupToBisection (const IndVec &subset, const IndVec &classes, IndexTrackerType &indicator, index_t new_id) |
| Post-processes a binary labeling to ensure two connected partitions. | |
Protected Attributes | |
| MapType | m_dual_map |
| The dual graph of the mesh, cached for performance. | |
Private Member Functions | |
| void | directKWay (const MeshType &, std::size_t, IndexTrackerType &, const std::vector< bool > &) override |
| Direct k-way partition is not supported by the GNN backend. | |
| IndVec | bisectSubGraph (const MeshType &mesh, const IndVec &subgraph) override |
| Backend implementation of a single bisection operation. | |
| torch::Tensor | bisectGraph (const GNNGraph &graph) |
| Run the TorchScript SAGE model on a graph to obtain a 2-class split. | |
Private Attributes | |
| ClassIndexType | m_n_kmeans_calls |
| SAGEType | m_sage_t |
| GNNGraph | m_graph |
| torch::Tensor | m_feature_tensor |
| Module | m_model |
| Eigen::Matrix< MeshFloatType, -1, -1, Eigen::RowMajor > | m_feature_mat |
GNN-based agglomeration model (GraphSAGE via TorchScript).
Uses a pretrained TorchScript SAGE module to perform 2-way bisections on a subgraph extracted from the input mesh's dual graph. This class implements the bisectSubGraph() primitive and inherits the high-level strategies (e.g., BisectNRef, MultFactor, SegregateBisection) from AbstractAgglomerationModel.
| MeshType | Concrete mesh type providing: |
| using vulpes::geometry::GNNAgglomeration< MeshType >::CellType = Cell<MeshType::self_dim, MeshFloatType, MeshIndexType> |
| using vulpes::geometry::GNNAgglomeration< MeshType >::ClassFloatType = typename AbstractAgglomerationModel<MeshType>::float_t |
| using vulpes::geometry::GNNAgglomeration< MeshType >::ClassIndexType = typename AbstractAgglomerationModel<MeshType>::index_t |
|
inherited |
|
inherited |
| using vulpes::geometry::GNNAgglomeration< MeshType >::IndexTrackerType |
| using vulpes::geometry::GNNAgglomeration< MeshType >::IndVec = typename AbstractAgglomerationModel<MeshType>::IndVec |
| using vulpes::geometry::GNNAgglomeration< MeshType >::MapType = typename AbstractAgglomerationModel<MeshType>::MapType |
| using vulpes::geometry::GNNAgglomeration< MeshType >::MeshFloatType = typename MeshType::float_t |
| using vulpes::geometry::GNNAgglomeration< MeshType >::MeshIndexType = typename MeshType::index_t |
| using vulpes::geometry::GNNAgglomeration< MeshType >::Module = torch::jit::script::Module |
| using vulpes::geometry::GNNAgglomeration< MeshType >::ParamType = typename AbstractAgglomerationModel<MeshType>::ParamType |
| vulpes::geometry::GNNAgglomeration< MeshType >::GNNAgglomeration | ( | const std::string & | name, |
| SAGEType | SAGE_t ) |
Construct a GNN agglomerator.
| name | Identifier or filesystem path to the TorchScript (.pt) module. |
| SAGE_t | Variant of SAGE model to load (see SAGEType). |
| std::runtime_error | if the model cannot be loaded. |
|
overridevirtual |
Agglomerate a mesh using a selected high-level strategy.
Dispatches to the inherited strategies (e.g., BisectNRef, MultFactor) while using the GNN as the bisection primitive.
| mesh | Input mesh. |
| method_type | Strategy to apply (see MethodType). |
| params | Strategy parameter (k, n_refs, or mult_fact). |
| return_hierarchy | If true, returns all intermediate meshes from recursive strategies. If false, returns only the final agglomerated mesh. |
| segregated_tag | If non-empty, specifies the mesh tag for segregated agglomeration, where each tagged region is processed independently. |
| subset | Optional list of cell IDs to agglomerate. If empty, the entire mesh is processed. |
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
|
private |
Run the TorchScript SAGE model on a graph to obtain a 2-class split.
Expects the graph's feature tensor and edge index to match the module's input signature. Returns a 1D tensor of size |V| with values in {0,1}.
| graph | Subgraph to classify. |
|
inherited |
Applies recursive bisection n_refs times.
This method takes an initial partitioning and refines it by applying the bisectSubGraph() primitive recursively for n_refs levels. Each step splits a partition into two. The base cases are finalized by ensuring connectivity via connectedComponents().
| mesh | The input mesh. | |
| n_refs | The number of recursive bisection levels to apply ( \(n_{refs} \ge 0\)). | |
| [in,out] | indicator | The label tracker, which is updated with the results. |
| agglomerate | A boolean vector indicating which initial classes in indicator are eligible for bisection. |
|
overrideprivatevirtual |
Backend implementation of a single bisection operation.
Given a set of cell IDs forming a subgraph, this function uses the GNN to bisect the cells by checking if the probability is < 0.5
| mesh | The input mesh. |
| subgraph | A vector of cell IDs to be split. |
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
|
protectedinherited |
Splits a set of cells into its connected components.
This function examines the dual graph restricted to the cells in subset. If the subgraph is disconnected, each connected component is assigned a new, unique label. This is often used as a finalization step in recursive strategies.
| subset | The set of cell IDs to process. | |
| [in,out] | indicator | The global label tracker, which will be updated. |
| [in,out] | max_id | The last used label ID; it is incremented for each new component found. |
|
inlineoverrideprivatevirtual |
Direct k-way partition is not supported by the GNN backend.
| std::runtime_error | Always. |
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
|
protectedinherited |
Post-processes a binary labeling to ensure two connected partitions.
Given a provisional two-class labeling for a subset of cells, this method refines the labels to ensure that the resulting two partitions are each internally connected. It can relabel "islands" of cells to join the surrounding partition.
| subset | The set of cell IDs under consideration. | |
| classes | A vector of provisional binary labels for the cells in subset. | |
| [in,out] | indicator | The global label tracker to update with the final bisection. |
| new_id | The fresh label ID to be assigned to one of the two final partitions. |
|
protectedinherited |
Dispatches to the correct agglomeration method to compute cell labels.
This is a wrapper function typically used by agglomerate(). It selects the appropriate backend method based on method_type and restricts the computation to subset if it is non-empty.
| mesh | The input mesh. |
| method_type | The strategy to apply. |
| params | The parameters for the chosen strategy. |
| segregation_tag | If non-empty, the mesh tag to use for segregated processing. |
| subset | An optional subset of cell IDs to operate on. |
|
inherited |
Partitions the mesh based on a multiplicative factor strategy.
This method recursively bisects any group whose vertex-vertex diameter exceeds the target_h. After geometric splitting, each resulting group is finalized by splitting it into its connected components. It uses bisectSubGraph() as the core splitting primitive.
| mesh | The input mesh. | |
| target_h | The target characteristic length. Any group with a diameter larger than this will be split. | |
| [in,out] | indicator | The label tracker, which is updated with the results. |
| agglomerate | A boolean vector indicating which initial classes in indicator are eligible for splitting. |
|
staticconstexpr |
|
protectedinherited |
The dual graph of the mesh, cached for performance.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |