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/100.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/100.0 [00:00<?, ?it/s]
0%| | 0/100.0 [00:16<?, ?it/s]
0%| | 0.01/100.0 [00:18<51:44:55, 1863.14s/it]
0%| | 0.02/100.0 [00:18<25:52:20, 931.59s/it]
0%| | 0.15/100.0 [00:18<3:26:43, 124.22s/it]
5%|▍ | 4.51/100.0 [00:18<06:35, 4.14s/it]
30%|███ | 30.36/100.0 [00:18<00:43, 1.61it/s]
94%|█████████▍| 94.13/100.0 [00:19<00:01, 4.91it/s]
94%|█████████▍| 94.13/100.0 [00:19<00:01, 4.90it/s]
100%|██████████| 100.0/100.0 [00:19<00:00, 5.21it/s]
100%|██████████| 100.0/100.0 [00:19<00:00, 5.21it/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(50)
]
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(
{
"chis": [[-1, 0], [0, -1]], # interactions between internal components
"chis_solvent": [2.5, 2.5], # interactions of components with solvent
}
)
simulation.add_actor(("droplets", "background"), droplets_actor)
# run simulation
result = simulation.run(t_range=100, dt=1e-2)
result.plot(title=f"{result['droplets'].droplet_count} droplets")
Total running time of the script: (0 minutes 19.330 seconds)