During the different steps of the simulation (initialization, system assembly, solving, visualization), information needs to be recovered from all graph nodes. SOFA relies on an implicit mechanism: the Visitors. You can find the abstract Visitor class in the SofaSimulation package.
Visitors traverse the scene top-down and bottom-up and call the corresponding virtual functions at each graph node traversal. Visitors are therefore used to trigger actions by calling the associated virtual functions (e.g. animating the simulation, accumulating forces). Algorithmic operations on the simulated objects are implemented by deriving the Visitor class and overloading its virtual functions processNodeTopDown( ) and processNodeBottomUp( ).
This approach hides the scene structure (parent, children) from the components, for more implementation flexibility and a better control of the execution model. Moreover, various parallelism strategies can be applied independently of the mechanical computations performed at each node. The data structure is actually extended from strict hierarchies to directed acyclic graphs to handle more general kinematic dependencies. The top-down node traversals are pruned unless all the parents of the current node have been traversed already, so that nodes with multiple parents are traversed only once all their parents have been traversed. The bottom-up traversals are made in the reverse order.
at the level of an AnimationLoop, visitors are used for instance to trigger the simulation step (AnimateVisitor), update the context (UpdateSimulationContextVisitor) and update the mappings (UpdateMappingVisitor).
at the level of the ODESolver, visitors allow to build the linear matrix system by abstract functions. For instance, the computation of the right hand side vector b is triggered by the MechanicalComputeForceVisitor, accumulating forces is used to compute all the forces (internal or external) applied on our object. The solver then triggers the associate Visitor and the action is propagated through the graph and calls the appropriate (bottom-up) methods at each force and mapping node. All components able to compute forces will accumulate their contributions. This information is finally gathered in the MechanicalObject and the solver will use this “force” vector to solve the mathematical system.
Here is the usual sequence diagram of a SOFA simulation.
Last modified: 30 November 2021