
\section{How To create a new Force Field}

In SOFA, the Force Field already existing are located in the namespace sofa::component::forcefield. They derive from the core class sofa::core::componentmodel::behavior::ForceField. It is templated by the type of elements you want to model. It can be a deformable object of 1,2,3 or 6 dimensions, or rigid bodies of 2 and 3 dimensions.\\
The simplest way to implement your own ForceField is :
\begin{enumerate}
 \item make it derive from sofa::core::componentmodel::behavior::ForceField
 \item implements the following virtual functions: addForce, getPotentialEnery. Others virtual functions exist like  addDForce, addDForceV (if you want to make dynamics), and you should read the doxygen documentation about ForceField. 
 \item as with all the others component you might create, you have to add it to the project. \\Edit \$SOFA\_DIR/modules/sofa/component/component.pro, and add the path to new files in the section HEADERS and SOURCES.
 \item Edit \$SOFA\_DIR/modules/sofa/component/init.cpp and add your new forcefield to the list. This step is compulsory for Windows system, and does the linking of a new component to the factory. If you forget it, your component won't be created at initialization time.
\end{enumerate}

The method addForce computes and accumulates the forces given the positions and velocities of its associated mechanical state.\\
If the ForceField can be represented as a matrix, this method computes
    $$ f += B v + K x $$
     This method is usually called by the generic ForceField::addForce() method.
