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:14<?, ?it/s]
0%| | 0.01/100.0 [00:16<46:15:56, 1665.73s/it]
0%| | 0.02/100.0 [00:16<23:07:51, 832.88s/it]
0%| | 0.18/100.0 [00:16<2:33:58, 92.55s/it]
6%|▌ | 5.56/100.0 [00:16<04:43, 3.00s/it]
37%|███▋ | 37.19/100.0 [00:16<00:28, 2.21it/s]
37%|███▋ | 37.19/100.0 [00:17<00:28, 2.17it/s]
100%|██████████| 100.0/100.0 [00:17<00:00, 5.84it/s]
100%|██████████| 100.0/100.0 [00:17<00:00, 5.84it/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 17.222 seconds)