Note
Go to the end to download the full example code.
Simple particle simulation#
This example sets up and solves a simple particle simulation workflow.
Perform imports and create a project#
Perform the required imports and create an empty project.
import os.path
import tempfile
import ansys.rocky.core as pyrocky
# Create a temp directory to save the project.
project_dir = tempfile.mkdtemp(prefix="pyrocky_")
# Launch Rocky and open a project.
rocky = pyrocky.launch_rocky()
project = rocky.api.CreateProject()
Configure the study#
Create a particle entity and then inject it through a circular surface.
study = project.GetStudy()
# The default particle entity has a spherical shape and just one size distribution with
# the sieve size of 0.1 m.
particle = study.CreateParticle()
# The default circular surface is defined in the XZ plane and has a maximum radius
# of 1.0 m and center in the Cartesian coordinates of (0.0, 0.0, 0.0).
circular_surface = study.CreateCircularSurface()
study.CreateParticleInlet(entry_point=circular_surface, particle=particle)
# The domain settings define the domain limits where the particles are enabled to be
# computed in the simulation.
domain = study.GetDomainSettings()
domain.DisableUseBoundaryLimits()
domain.SetCoordinateLimitsMaxValues((10, 1, 10))
Set up the solver and run the simulation#
solver = study.GetSolver()
solver.SetSimulationDuration(2) # Simulate for 2 sec.
project.SaveProject(os.path.join(project_dir, "rocky-testing.rocky"))
study.StartSimulation()
True
Postprocess#
# Get the particles count curve that shows the number of particles inside the domain at
# each time step of the simulation.
times, particles_count = study.GetParticles().GetNumpyCurve("Particles Count")
for time, count in zip(times, particles_count):
print(f"Time: {time}s, Count: {count}")
rocky.close()
Time: 0.0s, Count: 0
Time: 0.05s, Count: 1
Time: 0.1s, Count: 2
Time: 0.15s, Count: 3
Time: 0.2s, Count: 4
Time: 0.25s, Count: 5
Time: 0.3s, Count: 6
Time: 0.35s, Count: 7
Time: 0.4s, Count: 8
Time: 0.45s, Count: 9
Time: 0.5s, Count: 10
Time: 0.55s, Count: 11
Time: 0.6s, Count: 12
Time: 0.65s, Count: 13
Time: 0.7s, Count: 14
Time: 0.75s, Count: 15
Time: 0.8s, Count: 16
Time: 0.85s, Count: 17
Time: 0.9s, Count: 18
Time: 0.95s, Count: 19
Time: 1.0s, Count: 20
Time: 1.05s, Count: 21
Time: 1.1s, Count: 22
Time: 1.15s, Count: 23
Time: 1.2s, Count: 24
Time: 1.25s, Count: 25
Time: 1.3s, Count: 26
Time: 1.35s, Count: 27
Time: 1.4s, Count: 28
Time: 1.45s, Count: 28
Time: 1.5s, Count: 28
Time: 1.55s, Count: 28
Time: 1.6s, Count: 28
Time: 1.65s, Count: 27
Time: 1.7s, Count: 27
Time: 1.75s, Count: 27
Time: 1.8s, Count: 28
Time: 1.85s, Count: 27
Time: 1.9s, Count: 27
Time: 1.95s, Count: 27
Time: 2.0s, Count: 28
Total running time of the script: (0 minutes 46.634 seconds)