# Creating a composite object using a SubsetMultiMapping

François Faure, 2013
This page explains how to create a composite object as illustrated in the following image, in an efficient way. The object is composed of a deformable beam connected to rigid parts at the two ends. This requires to attach points to the rigid objects using a RigidMapping, and to connect these points to the FEM.
Using AttachConstraint is not an option because it works only for independent DOFs, and the points mapped to the rigid object are not independent.
The classic way would be to connect the deformable object to the rigid objects using springs. However, this would require stiff springs which harm the numerical conditioning of the system, without attaching the points rigidly.
Replacing the spring with hard constraints using Lagrange multipliers requires a constraint solver which consumes computation time.
The solution we propose avoids these drawbacks.

An FE model connected to two rigid objects. The yellow squares highlight FE nodes embedded in the rigid objects using a mapping. The white points are independent FE nodes.

Our approach is to distribute the FE vertices in two separate groups: the mapped vertices at the ends, and the independent vertices in the central part. This requires separate State components and graph nodes. Unfortunately, the FEM force fields are internal, therefore they can not be used to connect vertices of different objects. More generally, FE models are typically defined as a whole and it is not easy to split them.
To overcome this limitation, we define the whole FE model as a common child of the independent and the mapped particles, using a MultiMapping, as illustrated in the next figure. The complete FEM, including elements and masses, is defined at the bottom, while the independent DOFs are the independent particles and the frames near the top. The SubsetMultiMapping simply copies values from and to the two subsets of particles.
This way, there is no need to constrain FE vertices on the rigid objects. They are perfectly attached using a mapping, without introducing stiffness or hard constraints. The only additional cost is due to the copies of state vectors through the SubsetMultiMapping.

The kinematic hierarchy used to create the composite object.

The implementation in SOFA requires to address some issues:

1. Multimappings (mappings with several parents) can not generally match tree structures. A directed acyclic graph (DAG) is required, therefore the sofa::simulation::Simulation must be an instance of DAGSimulation. This requires to uncheck the following line in you sofa-local.prf file:`DEFINES += SOFA_HAVE_DAG`
2. DAG structures can not currently be parsed from xml files. Such a simulation must be created in C++, as given in this directory, or in Python (no example available yet).
3. The initialization of the scene is made bottom-up, because the FEM is given, and the mapped and independent particles are created based on it. This is opposite to the standard, top-down mapping initialization of SOFA. Therefore, the mapped and independent particles must be carefully set before the standard initialization, so that their top-down propagation to the FE model does not change the position of the vertices.

An example is given in compositeObject.cpp. To compile it, you need to activate the tutorials by uncommenting the following line in your sofa-local.prf: `DEFINES += SOFA_HAVE_TUTORIALS`