Lab1: First Step with Sofa


In this lab, we will use SOFA to perform the simulations. If you are using a computer at the university, Sofa should already be complied and installed on your environment. Alternatively you can download and use the Virtual Machine Here (6.2 Go). It includes a precompiled version of Sofa running on Ubuntu 20.04. The root login is sofa and the password is sofa. Finally, you can choose to download and install the software following this page. Then you will need to build Sofa with additional plugins:


Additionally, you will need to add the path of the build directory in your environment in order to run Sofa from any location. For this purpose add the following variables in the file ~/.bashrc

export PATH

Where SOFA is the build directory (for instance /home/sofa/work/sofa/build-src-Desktop-Release in the VM).

Installation and visualization

Launch the command runSofa from any location in the terminal. Sofa starts with a default example:

Note that you can run Sofa with double-click on SOFA/bin/runSofa. However, running Sofa via the graphical interface prevents visualizing errors. In this lab, we will launch the software from the terminal. Check in the terminal the warnings and eventual errors that are given when Sofa starts.

You can move around the scene using the wheel to move forward / backward. Right click allows going up / down and left click to rotate the scene. Click Animate to start the simulation and see the collisions and deformations. With Shift + Left Shift, you can apply external forces on the deformable model to pull and deform it.

The View tab allows you to change the view mode. For example, you can visualize the mechanical mesh or collision. Display the mechanical mesh by clicking on Force Fields, a set of hexahedra appears to represent the elements on which the mechanical behavior is calculated. You can also display the collision mesh. For that click on Collision Model then disable the Visual Models visual model. The displayed meshes are simpler meshes which are used for the computation of the collisions. Finally, you can view other information such as contacts (Interactions) or wireframe mode.

Scene files

Component Graph

Sofa is based on a component graph system. Each component is specialized for a specific task in the simulation (solver, visualization, topology, …). The principle is then to describe a simulation with a hierarchy of components that will interact with each other to form the simulation.

This Root node contains the main parameters of the simulations (such as the gravity). Sub nodes contain a list of components that will constitute the simulation. Each of these components accepts several parameters (sometimes called attributes or data). You can edit the values of data with by double-clicking on the components. A second window opens and you can edit the values and click on the update button.

Although almost any data can be edited online, some of them does not have any influence when the simulation is already loaded (this is the case for precomputed parameters for instance) or it may have a lot of side effect. It is therefore always better to save the desired value of data in a file. The scene files describe the components in a format similar to XML which is called a scene file (.scn) in the Sofa nomination.


The Modeler is a graphical tool for creating and editing scene files. Run the command Modeler from a terminal (Note: it is located in the SOFA/build/bin directory). On the left panel you can find a list of the Sofa components, at the center a visualization of the scene file and on the right the value of parameters of each component.

Open the file SOFA_SRC/src/examples/Demos/caduceus.scn. In the central tab, you can see a hierarchical description of the components of the scene. The main node is named scene. By clicking on these nodes, you will be able to specify the global parameters of the simulation in the tab on the right. For example, we can change the gravity and the time step in the Root node of the scene. You can save the file caduceus_modified.scn (File -> saveAs). You can now run the file and click on Animate to see the effect of the modification.

Scene files

In practice, the use of the Modeler remains limited. Indeed, the formatting of the file after the backup makes it difficult to read and edit the scene later. It is generally preferred to edit scene files using a text editor. Open the modified scene file in a text editor (for instance kate).

The file contains the hierarchy of components and their names, as they were described in the Modeler . The hierarchical structure is done opening the <Node> tag. This tag is open in the first line by <Node> and closed to the last line by </ Node> which represents the Root node of the scene .

Sub nodes and components are then declared to define the simulation. Inside, each component there is a declarative list of attributes that represents the parameters of the component with name = “value” . In order to know the name of data that can be specified for each component you can either use the Modeler, or directly open the component in Sofa and edit the value in the .scn file.

Edit the gravity of the scene from the text editor. Save the file and restart Sofa.