Simulation of multicomponent droplets in 3D

This example shows how to simulate droplets comprising two components.

20 droplets
  0%|          | 0/1000.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/1000.0 [00:00<?, ?it/s]
  0%|          | 0/1000.0 [00:24<?, ?it/s]
  0%|          | 0.01/1000.0 [00:32<900:56:42, 3243.43s/it]
  0%|          | 0.02/1000.0 [00:32<450:28:18, 1621.73s/it]
  0%|          | 0.15/1000.0 [00:32<60:03:22, 216.23s/it]
  1%|          | 5.84/1000.0 [00:32<1:32:04,  5.56s/it]
  5%|▍         | 47.95/1000.0 [00:32<10:47,  1.47it/s]
 16%|█▋        | 163.13/1000.0 [00:32<02:49,  4.95it/s]
 35%|███▌      | 353.8/1000.0 [00:33<01:01, 10.54it/s]
 60%|█████▉    | 599.39/1000.0 [00:34<00:22, 17.46it/s]
 88%|████████▊ | 878.29/1000.0 [00:35<00:04, 24.94it/s]
 88%|████████▊ | 878.29/1000.0 [00:35<00:04, 24.67it/s]
100%|██████████| 1000.0/1000.0 [00:35<00:00, 28.09it/s]
100%|██████████| 1000.0/1000.0 [00:35<00:00, 28.09it/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 35.714 seconds)