Skip to content

[Simulation] Mapping graph visitors#6087

Open
alxbilger wants to merge 41 commits intosofa-framework:masterfrom
alxbilger:mappinggraphvisitor
Open

[Simulation] Mapping graph visitors#6087
alxbilger wants to merge 41 commits intosofa-framework:masterfrom
alxbilger:mappinggraphvisitor

Conversation

@alxbilger
Copy link
Copy Markdown
Contributor

@alxbilger alxbilger commented Apr 17, 2026

This PR implements a MappingGraph-based approach for core mechanical operations, specifically for computing forces and the df += (mM + bB + kK)v accumulation. It refactors MappingGraph by extracting traversal logic into a dedicated MappingGraphAlgorithms class and introduces parallel execution support using a .

The EulerImplicitSolver and EulerExplicitSolver are updated to utilize this graph for force computations and to efficiently check for diagonal mass matrices.

Additionally, new functionality for exporting the mapping graph to DOT format is added for visualization. The update also includes comprehensive unit tests and documentation for the new graph-based traversal API.

Quick benchmark on building the mapping graph at each time step:

  • on TorusFall.scn
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID   
   5       0.74    5       0.03    0.39    0.07    0.03    0.35    0.78 .....MappingGraphBuild               
  • on fallingSOFA.scn
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID                                                                                                                                                    
   5       0.19    1       0.05    0.18    0.09    0.03    0.09    0.42 .....MappingGraphBuild  
  • on SofaScene.scn:
 LEVEL   START    NUM      MIN     MAX   MEAN     DEV    TOTAL  PERCENT ID                                                                                                                             
   5       0.36    6       0.03    0.46    0.06    0.02    0.34    0.37 .....MappingGraphBuild    

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request labels Apr 17, 2026
@alxbilger alxbilger force-pushed the mappinggraphvisitor branch from 0adee88 to 583fbd5 Compare April 17, 2026 18:04
alxbilger added 26 commits May 7, 2026 15:11
Adds support for targeted node traversal in `MappingGraph::traverseTopDown` using defined scopes:
*   `ONLY_MAPPED_NODES`: Visits only components involved in mappings.
*   `ONLY_MAIN_NODES`: Visits component groups that do not rely on external mapping inputs.

This change updates the API to provide fine-grained control over which nodes are processed during traversal, and includes new tests validating these scoped behaviors.
…ersal

Updates `MappingGraph::traverseBottomUp` to accept a `VisitorApplication` scope, ensuring consistent node filtering logic with top-down traversal.

This allows targeted processing of nodes (e.g., only mapped or main nodes) when traversing dependencies from the bottom up. Tests are updated to validate scoped bottom-up behavior.
Updates `BaseMappingGraphNode::isMapped()` to use `std::optional<bool>` for managing and lazily computing the node's mapped status, improving efficiency of repeated checks.
Updates `MappingGraph::traverseComponentGroups` to accept a scope parameter, allowing controlled filtering and processing of component groups during graph traversal.
Updates `MappingGraph2_test` to prepend descriptive prefixes (e.g., `[STATE]`, `[MAPPING]`) to node names visited during traversals, ensuring clear identification of the component type for accurate testing results.
Implements overloads for `traverseTopDown_` and `traverseBottomUp_` in `MappingGraph`, allowing users to pass a callable object or lambda directly.

This approach simplifies graph traversal by leveraging the new `CallableVisitor` pattern, which automatically handles invoking the provided logic against visited components. Tests are updated to validate lambda usage during complex graph traversals.
Introduces a `clear()` method for `MappingGraph` to reset the entire graph state. This function ensures that all internal members, such as root node pointers, build flags, mapping status tracking, and associated data containers, are properly initialized back to their default empty state.
Introduces `traverseComponentGroups_` in `MappingGraph`, allowing users to pass a callable object or lambda directly for graph component group traversal. This standardizes the usage of callable visitors across all major graph traversal methods, improving API consistency and reducing boilerplate code.
Extracts all core graph traversal methods (Top-Down, Bottom-Up, component group traversals) from `MappingGraph` and moves their implementation to a dedicated `MappingGraphAlgorithms` class. This improves modularity by separating the algorithm details from the main graph structure API.

Updates headers and tests to utilize the new `algorithms` member struct for all traversal calls.
alxbilger added 10 commits May 7, 2026 15:11
Adds an overloaded `traverse` method to `MappingGraphAlgorithms`. This overload allows the graph traversal process to utilize a `TaskScheduler`, executing node visits concurrently for improved performance when processing large graphs on multi-threaded environments. It falls back to synchronous traversal if no scheduler is provided.
@alxbilger alxbilger added the pr: highlighted in next release Highlight this contribution in the notes of the upcoming release label May 7, 2026
@alxbilger alxbilger force-pushed the mappinggraphvisitor branch from 672455c to 010326e Compare May 7, 2026 15:15
alxbilger added 5 commits May 8, 2026 10:24
Replaces direct member variable access for internal graph structures (e.g., `m_allNodes`, `m_children`) with public accessor methods like `getAllNodes()` and `getChildren()`.
@alxbilger alxbilger marked this pull request as ready for review May 8, 2026 15:51
@alxbilger
Copy link
Copy Markdown
Contributor Author

[ci-build][with-all-tests]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: enhancement About a possible enhancement pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant