# bouncing of a ball

In this example we show the application of the [`RigidWall`](/suanpan-manual/constraint/rigidwall.md) and [`RestitutionWall`](/suanpan-manual/constraint/restitutionwall.md) constraints. It is also possible to define a rigid wall with finite dimension. The model script can be [downloaded](https://github.com/TLCFEM/suanPan-manual/blob/dev/docs/Example/Structural/Dynamics/bouncing-of-a-ball.supan).

A mass point is used to idealize the ball. As this is a dynamics problem of rigid body, there is no need to define any material models to provide stiffness matrix. For this reason, it is possible to just define a point mass at the target point.

```
# define a node at (-1,2)
node 1 -1 2
# define a unit point mass element at node 1, both DoF 1 and DoF 2 are activated
mass 1 1 1 1 2
```

No matter how the gravity load is applied, it is required to define a constant amplitude that provides a constant level of either gravity force or acceleration. We define a proper amplitude first.

```
amplitude Constant 1
```

To apply the gravity, we use a constant vertical acceleration load, to do so,

```
# define a acceleration load of magnitude -1 using amplitude 1 on DoF 2 of node 1
acceleration 1 1 -1 2 1
```

Alternatively, a vertical load can be applied

```
cload 1 1 -1 2 1
```

Since the initial state is always in equilibrium, an initial condition can be added.

```
# assign initial acceleration of maginutde of -1 on DoF 2 of node 1
initial acc -1 2 1
```

## Free Fall

Now the model is ready to run a free fall simulation.

```
step dynamic 1 1
set ini_step_size 1E-1
set fixed_step_size 1
converger RelIncreDisp 1 1E-8 10 1
analyze
peek node 1
exit
```

A default Newmark time integration algorithm will be assigned if no valid integrator is defined. The output is

```
Node 1:
  -1.0000   2.0000
Displacement:
        0  -0.5000
Resistance:
        0        0
Velocity:
        0  -1.0000
Acceleration:
        0  -1.0000
```

The analytical displacement can be simply computed as

$$
u=\dfrac{1}{2}at^2=\dfrac{1}{2}.
$$

## Rigid Wall Constraint

We define two infinite rigid wall constraints inclined $$\pi/4$$ and $$3\pi/4$$ to form a right angle. The ball can bounce between two walls. Two walls are both anchored at the origin and have infinite dimension, the outer normals are $$(1,1)$$ and $$(-1,1)$$, respectively. The penalty factor is chosen to be $$0.1$$ in this particular example. Accounting for the time step defined below ($$0.005$$), the actual penalty factor applied to the effective stiffness is $$0.1/0005/0.005=4000$$.

```
rigidwall 1 0 0 1 1 1E-1
rigidwall 2 0 0 -1 1 1E-1
```

The penalty factor can be altered to achieve different levels of satisfactions of the constraint. But higher values also result in greater high frequency noise.

It may be of interest to record the motion of the ball.

```
hdf5recorder 1 Node U 1
hdf5recorder 2 Node V 1
hdf5recorder 3 Node A 1
```

Then configure the analysis,

```
step dynamic 1 40
set ini_step_size 5E-3
set fixed_step_size 1

converger RelIncreDisp 1 1E-8 7 1

analyze
```

The results are shown as follows.

![bouncing of a ball between two rigid walls](/files/-MQ5s1N3EXTUXvSUHD14)

The energy of the system is **not** conserved. To alleviate this problem, one can use the [`RestitutionWall`](/suanpan-manual/constraint/restitutionwall.md) constraint.

## Restitution Wall Constraint

### Elastic Collision

The constraints can be replaced by

```
restitutionwall 1 0 0 1 1 1. 1E4
restitutionwall 2 0 0 -1 1 1. 1E4
```

Here the coefficient of restitution is set to 1.

![animation](/files/vg1pNk9M4oLV80NbCHg9)

### Plastic Collision

One can define a plastic collision by using a coefficient of restitution smaller than unity.

```
restitutionwall 1 0 0 1 1 .9 1E4
restitutionwall 2 0 0 -1 1 .9 1E4
```

![animation](/files/K5yFIoZmlhaArWY52UT3)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tlcfem.gitbook.io/suanpan-manual/example/structural/dynamics/bouncing-of-a-ball.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
