Generating a contact network from a 3D sphere packing
Begin with a few package imports:
[1]:
from IPython.display import HTML
import numpy as np
import matplotlib.pyplot as plt
from packing_utils import *
from plot_imports import *
Simulation
Generate a packing of 128 bidisperse spheres in 3D:
[2]:
n = 128
seed = 0
dim = 3
net = Packing(n, dim=dim, seed=seed)
net.generate()
progress: 100%|###############################################################| 1000.00/1000.00 [00:12<00:00]
Plotting
Visualization of the 3D packings requires the povray ray-tracing software to be installed, and makes use of the vapory package in Python.
[3]:
%matplotlib notebook
net.plot(spheres=True, edges=False)
View only the contact network:
[4]:
net.plot(spheres=False)
Animation
An animation of the packing simulation can be generated and visualized with the following code cell:
[ ]:
%matplotlib inline
ani = net.animate(spheres=True, edges=False)
HTML(ani.to_html5_video())
Output
Save the network to a file. The text file can be used to initialize a graph for physical learning with elastic networks.
[6]:
net.save('packing_3d.txt')