# External forces¶

The external forces are used to impose a solicitation from the environment on to the system:

The solicitation consists of applying an external force and/or an external torque on the body;

The three components of the force and/or torque must be calculated by the user in the

*user_ExtForces*function;The application point is defined in MBsysPad and its kinematics is provided in the input of the

*user_ExtForces*;The

*user_ExtForces*function must return:the 3 components of the force in the inertial frame;

the 3 components of the torque in the inertial frame;

the 3 components of the application point in the body fixed frame, which allows to modify the position where the force is applied;

Each external force is associated with a “F sensor” which give the kinematics of the application point;

## Back to the pendulum-spring example¶

The goal is to add a wall next to the pendulum with the following assumptions:

The end of the pendulum hits the wall;

The thickness of the pendulum is neglected;

The wall is modelled as a spring in the horizontal direction with a stiffness K = 10 kN/m.

REMARK:

Step 2, 4 and 5 are not impacted by theses modifications.

### Step 1: Draw your multibody system¶

Open the Pendulum Spring model in MBsysPad;

Add an anchor on the pendulum;

Enter the coordinates to locate the point at the end of the pendulum;

Add the external force:

Click on the ExtForce button;

Click on the anchor point at the end of the pendulum;

A “

*F*” is added next to the anchor point;Click on the “

*F*” to edit its properties and give it a name;

### Step 2: Generate your multibody equations¶

You have to generate the multibody equations after the creation of an external force.

### Step 3: Write your user function¶

Edit the *user_ExtForces* function (open the file from the userfctR
subfolder of your project) and write the force equations.

```
import numpy as np
def user_ExtForces(PxF, RxF, VxF, OMxF, AxF, OMPxF, mbs_data, tsim, ixF):
#...
# get the force id
F1_id = mbs_data.extforce_id["LateralBumpstop"]
if ixF == F1_id:
gap = 0.3
if PxF[1] > gap:
Fx = -10000*(PxF[1]-gap)
#...
Swr=np.zeros(9+1)
Swr[1:]=np.r_[Fx,Fy,Fz,Mx,My,Mz,dxF]
return Swr
```

REMARK:

By default, the dxF components to the position of the anchor point defined in MBsysPad using the following commands (see the first commands of the

user_ExtForcesfunction):

idpt = mbs_data.xfidpt(ixF)

dxF = mbs_data.dpt(1:,idpt)

This behaviour can be modified if the force application point is moving with respect to the body (example: wheel/ground contact).

REMARK:

If there are several external forces in the model, all the constitutive laws are introduced in the user_ExtForces function and the if condition is used to distinguish the various forces.

### Step 4: Run your simulation¶

WARNING:

Keeping initial joint angle of 1 [rad] for pendulum leads to an initial position deep in the wall => generating high forces. This might be intractable for the simulation.

To avoid this set initial angle at -0.1 [rad].

### Check the results¶

Plot the graph of the joint position (results ares available in resultsR/ folder) and check your results with the following graph.