tcollision.py - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
(HTM) git clone git://src.adamsgaard.dk/sphere
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
tcollision.py (1826B)
---
1 #!/usr/bin/env python
2 '''
3 Example of two particles colliding.
4 Place script in sphere/python/ folder, and invoke with `python collision.py`
5 '''
6
7 # Import the sphere module for setting up, running, and analyzing the
8 # experiment. We also need the numpy module when setting arrays in the sphere
9 # object.
10 import sphere
11 import numpy
12
13
14 ### SIMULATION SETUP
15
16 # Create a sphere object with two preallocated particles and a simulation ID
17 SB = sphere.sim(np = 2, sid = 'collision')
18
19 SB.radius[:] = 0.3 # set radii to 0.3 m
20
21 # Define the positions of the two particles
22 SB.x[0, :] = numpy.array([10.0, 5.0, 5.0]) # particle 1 (idx 0)
23 SB.x[1, :] = numpy.array([11.0, 5.0, 5.0]) # particle 2 (idx 1)
24
25 # The default velocity is [0,0,0]. Slam particle 1 into particle 2 by defining
26 # a positive x velocity for particle 1.
27 SB.vel[0, 0] = 1.0
28
29 # Set the world limits and the particle sorting grid. The particles need to stay
30 # within the world limits for the entire simulation, otherwise it will stop!
31 SB.initGridAndWorldsize(margin = 5.0)
32
33 # Define the temporal parameters, e.g. the total time (total) and the file
34 # output interval (file_dt), both in seconds
35 SB.initTemporal(total = 2.0, file_dt = 0.1)
36
37 # Using a 'dry' run, the sphere main program will display important parameters.
38 # sphere will end after displaying these values.
39 SB.run(dry = True)
40
41
42 ### RUNNING THE SIMULATION
43
44 # Start the simulation on the GPU from the sphere program
45 SB.run()
46
47
48 ### ANALYSIS OF SIMULATION RESULTS
49
50 # Plot the system energy through time, image saved as collision-energy.png
51 SB.visualize(method = 'energy')
52
53 # Render the particles using the built-in raytracer
54 SB.render()
55
56 # Alternative visualization using ParaView. See the documentation of
57 # ``sim.writeVTKall()`` for more information about displaying the
58 # particles in ParaView.
59 SB.writeVTKall()