Implementation

In this section, we will explain the structure of the collision model implementation: we will detail the configuration of the parameters, the organization of the functions and the execution of the code.

1. Configuration of model parameters

The fixed parameters of the collision models are defined in a json file. For this purpose we added a section called CollisionForce. In this section we differ between contact models and shape types, i.e. bodies with a spherical, articulated or complex shape. The section is given by:

"CollisionForce":
{
    "body":
    {
        "setup":
        {
            "model":"contactAvoidance", (1)
            "type":"complexShapedBody", (2)
            "forceParam" (3)
            {
                "forceRange":0.03, (4)
                "epsBody":0.0001,  (5)
                "epsWall":0.01,     (6)
            }
        }
    }
}
1 Specification of the collision model. One can easily add models, so far the possible choices are
  • contactAvoidance : repulsive force model avoiding any contact.

2 Specification of the type of contact model. The possible choices are:
  • spericalShapedBody : collision model used for spherical shaped bodies only.

  • complexShapedBody : collision model used for all body shapes.

  • articulatedBody : collision model for articulated bodies.

3 Definition of collision model parameters.
4 Collision force activation threshold.
5 Stiffness parameter for body-body collisions.
6 Stiffness parameter for body-wall collisions.

2. Functions organization

All functions modeling the collision forces are defined in the file contactforce.hpp. This file contains a function for each pair (model,type). Thus, when considering the ContactAvoidance model, the script includes the three algorithms ContactAvoidanceSphericalType, ContactAvoidanceComplexType and ContactAvoidanceArticulatedType. When adding more models the number of defined functions gets high. For this reason we have added a central function, named ContactForceModels. This function reads the json file, and stores the model, type and parameters of the collision force. From this data it calls the concerned algorithm. This function allows in particular to add only two definitions in the Python layer of the fluid toolbox :

  • addContactForceModel : add model for linear case.

  • addContactForceResModel add model for non-linear case.

3. Code execution

To simulate the collisions using the Python layer of the fluid toolbox one just has to add the two lines:

f.addContactForceModel()
f.addContactForceResModel()

before looping over the iterations and after the call to the remeshing function. Here the parameter f represents the fluid toolbox. These two lines allow to add the collision forces before solving the problem. As we use Python language, the sequential and parallel execution is respectively done through the following command line:

python3 file.py
mpirun -np 4 python3 file.py

The -np indicates the number of processor. In this example one considers four processors, but one can also use a larger number.