SOFA API  4006d812
Open source framework for multi-physics simuation
sofa::simulation::MappingGraph Class Reference

#include <MappingGraph.h>

Represents the overall mechanical simulation graph structure (Mapping Graph). More...

Detailed Description

Represents the overall mechanical simulation graph structure (Mapping Graph).

This class builds and manages a dependency graph connecting all major components (MechanicalStates, Mappings, ForceFields, Masses) within an SOFA scene. It allows for systematic traversal (Top-down/Bottom-up) to determine the correct order of calculation required during simulation initialization or execution.

Classes

struct  InputLists
 Container struct holding lists of all potential input components collected from a scene context. More...
 

Public Attributes

MappingGraphAlgorithms algorithms { this }
 

Public Member Functions

 MappingGraph ()=default
 Default constructor initializes an empty graph. More...
 
 MappingGraph (const InputLists &input)
 Constructs the graph using pre-collected input lists. More...
 
 MappingGraph (core::objectmodel::BaseContext *node)
 Constructs the graph by traversing a starting node in the SOFA object model context. More...
 
void clear ()
 
core::objectmodel::BaseContextgetRootNode () const
 Returns the root node used during the initial construction of the graph. More...
 
const sofa::type::vector< core::behavior::BaseMechanicalState * > & getMainMechanicalStates () const
 Gets the list of all main mechanical states that are not used as outputs in any mapping (i.e., they are root inputs). More...
 
MappingInputs getTopMostMechanicalStates (core::behavior::BaseMechanicalState *state) const
 Recursively finds top-most mechanical states that are unmapped but serve as inputs to a mapping involving the provided state. More...
 
MappingInputs getTopMostMechanicalStates (core::behavior::StateAccessor *stateAccessor) const
 Recursively finds top-most mechanical states that are unmapped but serve as inputs to a mapping involving the mechanical states associated with a given accessor. More...
 
bool hasAnyMapping () const
 Checks if any mapping exists anywhere in the graph structure. More...
 
bool hasAnyMappingInput (core::behavior::BaseMechanicalState *mstate) const
 Determines if a specific mechanical state is an output of any mapping node connected to the graph. More...
 
bool hasAnyMappingInput (core::behavior::StateAccessor *stateAccessor) const
 Determines if the mechanical states associated with a component are outputs of any mapping node connected to the graph. More...
 
sofa::Size getTotalNbMainDofs () const
 Calculates the total number of degrees of freedom (DoF) contributed by all main mechanical states in the graph. More...
 
type::Vec2u getPositionInGlobalMatrix (core::behavior::BaseMechanicalState *mstate) const
 Finds the global matrix indices (row/column) where a specific state contributes its degrees of freedom. More...
 
type::Vec2u getPositionInGlobalMatrix (core::behavior::BaseMechanicalState *a, core::behavior::BaseMechanicalState *b) const
 Finds the global matrix indices where two specified states contribute their degrees of freedom. (Used for cross-axis checks). More...
 
sofa::type::vector< core::BaseMapping * > getBottomUpMappingsFrom (core::behavior::BaseMechanicalState *) const
 Retrieves all mapping components that depend on (receive input from) the provided mechanical state. This is used for bottom-up dependency checks. More...
 
bool isBuilt () const
 Checks if the graph has been successfully built and analyzed. More...
 
void build (const InputLists &input)
 Builds the mapping graph using a provided set of input components. More...
 
void build (core::objectmodel::BaseContext *rootNode)
 Builds the mapping graph by traversing and collecting components starting from a specific root node in the object model hierarchy. More...
 
const sofa::type::vector< BaseMappingGraphNode::SPtr > & getAllNodes () const
 

Friends

struct MappingGraphAlgorithms
 

Attribute details

◆ algorithms

MappingGraphAlgorithms sofa::simulation::MappingGraph::algorithms { this }

Constructor details

◆ MappingGraph() [1/3]

sofa::simulation::MappingGraph::MappingGraph ( )
default

Default constructor initializes an empty graph.

◆ MappingGraph() [2/3]

sofa::simulation::MappingGraph::MappingGraph ( const InputLists input)
explicit

Constructs the graph using pre-collected input lists.

Parameters
inputThe list of all components found in the scene.

◆ MappingGraph() [3/3]

sofa::simulation::MappingGraph::MappingGraph ( core::objectmodel::BaseContext node)
explicit

Constructs the graph by traversing a starting node in the SOFA object model context.

Parameters
nodeThe root context node from which to build the graph.

Function details

◆ build() [1/2]

void sofa::simulation::MappingGraph::build ( const InputLists input)

Builds the mapping graph using a provided set of input components.

Parameters
inputThe collected list of all potential SOFA components.

◆ build() [2/2]

void sofa::simulation::MappingGraph::build ( core::objectmodel::BaseContext rootNode)

Builds the mapping graph by traversing and collecting components starting from a specific root node in the object model hierarchy.

Parameters
rootNodeThe starting context node.

◆ clear()

void sofa::simulation::MappingGraph::clear ( )

◆ getAllNodes()

const sofa::type::vector<BaseMappingGraphNode::SPtr>& sofa::simulation::MappingGraph::getAllNodes ( ) const
inline

◆ getBottomUpMappingsFrom()

sofa::type::vector< core::BaseMapping * > sofa::simulation::MappingGraph::getBottomUpMappingsFrom ( core::behavior::BaseMechanicalState state) const

Retrieves all mapping components that depend on (receive input from) the provided mechanical state. This is used for bottom-up dependency checks.

Parameters
mstateThe mechanical state acting as an input source.
Returns
A vector of shared pointers to dependent BaseMapping nodes.

◆ getMainMechanicalStates()

const sofa::type::vector< core::behavior::BaseMechanicalState * > & sofa::simulation::MappingGraph::getMainMechanicalStates ( ) const

Gets the list of all main mechanical states that are not used as outputs in any mapping (i.e., they are root inputs).

Returns
Const reference to the vector of non-mapped mechanical state pointers.

◆ getPositionInGlobalMatrix() [1/2]

type::Vec2u sofa::simulation::MappingGraph::getPositionInGlobalMatrix ( core::behavior::BaseMechanicalState a,
core::behavior::BaseMechanicalState b 
) const

Finds the global matrix indices where two specified states contribute their degrees of freedom. (Used for cross-axis checks).

Parameters
aThe first mechanical state.
bThe second mechanical state.
Returns
A pair representing (global row index, global column index) for the combined contribution.

◆ getPositionInGlobalMatrix() [2/2]

type::Vec2u sofa::simulation::MappingGraph::getPositionInGlobalMatrix ( core::behavior::BaseMechanicalState mstate) const

Finds the global matrix indices (row/column) where a specific state contributes its degrees of freedom.

Parameters
mstateThe mechanical state.
Returns
A pair representing (global row index, global column index).

◆ getRootNode()

core::objectmodel::BaseContext * sofa::simulation::MappingGraph::getRootNode ( ) const

Returns the root node used during the initial construction of the graph.

Returns
A pointer to the root object model context.

◆ getTopMostMechanicalStates() [1/2]

MappingGraph::MappingInputs sofa::simulation::MappingGraph::getTopMostMechanicalStates ( core::behavior::BaseMechanicalState state) const

Recursively finds top-most mechanical states that are unmapped but serve as inputs to a mapping involving the provided state.

This search is recursive, handling multiple levels of dependencies.

Parameters
stateThe starting mechanical state for dependency checking.
Returns
A list of top-most unmapped mechanical states required by state.

◆ getTopMostMechanicalStates() [2/2]

MappingGraph::MappingInputs sofa::simulation::MappingGraph::getTopMostMechanicalStates ( core::behavior::StateAccessor stateAccessor) const

Recursively finds top-most mechanical states that are unmapped but serve as inputs to a mapping involving the mechanical states associated with a given accessor.

This search is recursive, handling multiple levels of dependencies.

Parameters
stateAccessorThe starting state accessor for dependency checking.
Returns
A list of top-most unmapped mechanical states required by stateAccessor.

◆ getTotalNbMainDofs()

sofa::Size sofa::simulation::MappingGraph::getTotalNbMainDofs ( ) const

Calculates the total number of degrees of freedom (DoF) contributed by all main mechanical states in the graph.

Returns
The sum of DoFs across all primary states.

◆ hasAnyMapping()

bool sofa::simulation::MappingGraph::hasAnyMapping ( ) const

Checks if any mapping exists anywhere in the graph structure.

Returns
True if at least one mapping is present, false otherwise.

◆ hasAnyMappingInput() [1/2]

bool sofa::simulation::MappingGraph::hasAnyMappingInput ( core::behavior::BaseMechanicalState mstate) const

Determines if a specific mechanical state is an output of any mapping node connected to the graph.

Parameters
mstateThe mechanical state to check.
Returns
True if mstate is an output, false otherwise.

◆ hasAnyMappingInput() [2/2]

bool sofa::simulation::MappingGraph::hasAnyMappingInput ( core::behavior::StateAccessor stateAccessor) const

Determines if the mechanical states associated with a component are outputs of any mapping node connected to the graph.

Parameters
stateAccessorThe state accessor for the component to check.
Returns
True if the associated states are mapped output, false otherwise.

◆ isBuilt()

bool sofa::simulation::MappingGraph::isBuilt ( ) const

Checks if the graph has been successfully built and analyzed.

Returns
True if building is complete, false otherwise.

Related details

◆ MappingGraphAlgorithms

friend struct MappingGraphAlgorithms
friend