Introduction.#

Let’s look at the simplest simulation you can run with JaxDEM.

import tempfile
from pathlib import Path
import jaxdem as jdem

Initialize the Simulation State#

First, we create a jaxdem.state.State object. It holds all per-particle data in the simulation. Let’s create a single particle at the origin. By default, jaxdem.state.State.create() fills every unspecified attribute with a sensible default value.

state = jdem.State.create(pos=[[0.0, 0.0, 0.0]])

Note that we wrote pos=[[coords]], not pos=[coords]. jaxdem.state.State.create() expects a 2-D array of shape (N, dim), so even a single particle needs a list of lists.

Initialize the Simulation System#

Next, we create a jaxdem.system.System. It holds the global configuration of the simulation (domain, force model, integrator, …). Just like the state, jaxdem.system.System.create() fills in defaults for anything we don’t specify. The only requirement is that the system dimension matches the state dimension:

system = jdem.System.create(state.shape)

Run the Simulation#

Finally, we advance the simulation by calling jaxdem.system.System.step():

n_steps = 10
state, system = system.step(state, system, n=n_steps)

Saving the Simulation#

The last thing left to do is to save the simulation to VTK files so we can visualize it in ParaView:

tmp_dir = Path(tempfile.gettempdir()) / "data"
writer = jdem.VTKWriter(directory=tmp_dir)
writer.save(state, system)

Where to Go Next#

Now that you have seen the simplest simulation, explore the rest of the user guide to learn about each component in depth:

Total running time of the script: (0 minutes 1.472 seconds)