> For the complete documentation index, see [llms.txt](https://tlcfem.gitbook.io/suanpan-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tlcfem.gitbook.io/suanpan-manual/example/structural/dynamics/particle-collision.md).

# particle collision

In this example, we illustrate the contact problem by simulating a 2D particle collision problem. The model can be downloaded [here](https://github.com/TLCFEM/suanPan-manual/tree/dev/docs/Example/Structural/Dynamics/particle-collision.zip).

## General Information

The container is assumed to be a square with edge length of $$10$$. A certain number of nodes are randomly generated within the container with randomly generated initial velocities. A small program is written to generate the model script. One could compile the `Generator.cpp` file and run it with the number of particles needed. For example,

```bash
g++ -o Generator.exe Generator.cpp
Generator.exe 20
```

The model file will be generated as `Collision.supan`.

## Collision

The collision force $$F$$ is assumed to be a function of distance $$d$$ between two particles.

$$
F(d)=\alpha\ln\left(\dfrac{d}{s}\right),
$$

where $$s$$ is the approximate size of particles, $$\alpha$$ is a factor that can be used to adjust response. To define such a collision, one can use

```
particlecollision2d 1 2.
```

in which $$s=2$$ and $$\alpha$$ is defaulted to be unity.

## Container Boundary

The four edges of the container can be assigned by using the rigid wall constraint. For example,

```
rigidwall 2 5 0 -1 0
rigidwall 3 0 5 0 -1
rigidwall 4 -5 0 1 0
rigidwall 5 0 -5 0 1
```

## Other Caveats

It shall be noted that a full matrix storage scheme shall be enabled to perform a collision simulation, since any two particles can collide with each other based on different initial conditions, there is no way to obtain a sparse/banded matrix in advance.

```
set band_mat false
set symm_mat false
```

## Output

The global kinetic energy can be recorded by using

```
hdf5recorder 1 Global KE
```

Besides, it may be helpful to visualize the collision progress, to do that, a `Visualisation` recorder can be defined.

```
hdf5recorder 2 Visualisation U every 20 width 4
```

## Result

The kinetic energy history is obtained as follows. It can be seen that the total energy level is increasing with the number of collisions. The parameters can be further adjusted for more realistic results. Here the model is presented for the purpose of illustration.

![kinetic energy history](https://1124082496-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEquxr3H9WpPg4iPvT2mB%2Fuploads%2Fgit-blob-3ffaba86c0d224bdc03a32e8eb066b354df120a3%2Fparticle-collision.svg?alt=media)

The animation is presented as follows.

![animation](https://1124082496-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEquxr3H9WpPg4iPvT2mB%2Fuploads%2Fgit-blob-a0ffb690937741a7579595e022b1b6c3f9174a77%2Fparticle-collision.gif?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://tlcfem.gitbook.io/suanpan-manual/example/structural/dynamics/particle-collision.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
