# External forces¶

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

• The sollicitation consists to apply 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;
• 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¶

Python section:

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

def user_ExtForces(PxF,RxF,VxF,OMxF,AxF,OMPxF,mbs,tsim,ixF):
#...

# get the force id
F1 = mbs.get_F_sensor_id('LateralBumpstop')

if ixF == F1:
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_ExtForces function):

• idpt = mbs.xfidpt(ixF)
• dxF = mbs.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 avilaible in resultsR/ folder) and check your results with the following graph.