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()
Traceback (most recent call last):
File "C:\Users\ansys\actions-runner\_work\pyrocky\pyrocky\examples\basic_examples\minimal.py", line 46, in <module>
project = rocky.api.CreateProject()
File "C:\Users\ansys\actions-runner\_work\_tool\Python\3.13.5\x64\Lib\site-packages\Pyro5\client.py", line 510, in __call__
return self.__send(self.__name, args, kwargs)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ansys\actions-runner\_work\_tool\Python\3.13.5\x64\Lib\site-packages\Pyro5\client.py", line 256, in _pyroInvoke
msg = protocol.recv_stub(self._pyroConnection, [protocol.MSG_RESULT])
File "C:\Users\ansys\actions-runner\_work\_tool\Python\3.13.5\x64\Lib\site-packages\Pyro5\protocol.py", line 189, in recv_stub
header = connection.recv(6) # 'PYRO' + 2 bytes protocol version
File "C:\Users\ansys\actions-runner\_work\_tool\Python\3.13.5\x64\Lib\site-packages\Pyro5\socketutil.py", line 435, in recv
return receive_data(self.sock, size)
File "C:\Users\ansys\actions-runner\_work\_tool\Python\3.13.5\x64\Lib\site-packages\Pyro5\socketutil.py", line 166, in receive_data
raise ConnectionClosedError("receiving: connection lost: " + str(x))
Pyro5.errors.ConnectionClosedError: receiving: connection lost: [WinError 10054] An existing connection was forcibly closed by the remote host
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()
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()
Total running time of the script: (0 minutes 27.599 seconds)