Note
Go to the end to download the full example code.
Simulation of multicomponent droplets in 3D
This example shows how to simulate droplets comprising two components.

0%| | 0/1000.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/1000.0 [00:00<?, ?it/s]
0%| | 0/1000.0 [00:25<?, ?it/s]
0%| | 0.01/1000.0 [00:33<932:41:03, 3357.70s/it]
0%| | 0.02/1000.0 [00:33<466:20:29, 1678.86s/it]
0%| | 0.13/1000.0 [00:33<71:44:17, 258.29s/it]
0%| | 4.92/1000.0 [00:33<1:53:14, 6.83s/it]
4%|▍ | 39.98/1000.0 [00:33<13:30, 1.19it/s]
13%|█▎ | 134.33/1000.0 [00:34<03:39, 3.94it/s]
29%|██▉ | 290.85/1000.0 [00:34<01:24, 8.38it/s]
49%|████▉ | 491.88/1000.0 [00:35<00:36, 13.86it/s]
72%|███████▏ | 720.33/1000.0 [00:36<00:14, 19.81it/s]
96%|█████████▋| 963.11/1000.0 [00:37<00:01, 25.82it/s]
96%|█████████▋| 963.11/1000.0 [00:37<00:01, 25.72it/s]
100%|██████████| 1000.0/1000.0 [00:37<00:00, 26.71it/s]
100%|██████████| 1000.0/1000.0 [00:37<00:00, 26.71it/s]
import numpy as np
from pde import CartesianGrid, FieldCollection
import emulsim
# set up state
grid = CartesianGrid([[0, 128]] * 3, 1)
fc = FieldCollection.scalar_random_uniform(2, grid, 0.01, 0.05)
background_el = emulsim.FieldCollectionElement.from_fields(fc)
droplet_data = [
emulsim.MulticomponentDroplet.from_composition(
position=grid.get_random_point(),
radius=np.random.uniform(1, 5),
phis=[0.4, 0.4],
)
for _ in range(20)
]
droplets_el = emulsim.MulticomponentDropletsElement.from_droplets(droplet_data)
state = emulsim.State({"background": background_el, "droplets": droplets_el})
# set up simulation
simulation = emulsim.Simulation(state)
droplets_actor = emulsim.MulticomponentDropletActor.from_linear_reactions(
{
"chis": [[-1, 0], [0, -1]], # interactions between internal components
"chis_solvent": [2.5, 2.5], # interactions of components with solvent
},
rates=np.diag([-0.01, -0.01]),
production=[0.002, 0.002],
)
simulation.add_actor(("droplets", "background"), droplets_actor)
# run simulation
result = simulation.run(t_range=1000, dt=1e-2)
result.plot(title=f"{result['droplets'].droplet_count} droplets")
Total running time of the script: (0 minutes 37.581 seconds)