Generating a contact network from a 2D disk 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 disks:

[2]:
n = 128
seed = 0

net = Packing(n, seed=seed)
net.generate()
progress: 100%|###############################################################| 1000.00/1000.00 [00:06<00:00]

Plotting

Visualize the final state:

[3]:
%matplotlib notebook

net.plot()

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()
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_2d.txt')