Bulk-boundary coupling

Demonstrates coupling of bulk and boundary fields.

bulk boundary coupling
  0%|          | 0/100.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/100.0 [00:00<?, ?it/s]
  0%|          | 0/100.0 [00:09<?, ?it/s]
  0%|          | 0.1/100.0 [00:12<3:24:21, 122.74s/it]
  0%|          | 0.2/100.0 [00:12<1:42:04, 61.37s/it]
  0%|          | 0.3/100.0 [00:12<1:07:59, 40.91s/it]
 18%|█▊        | 18.3/100.0 [00:12<00:54,  1.49it/s]
 18%|█▊        | 18.3/100.0 [00:12<00:54,  1.49it/s]
100%|██████████| 100.0/100.0 [00:12<00:00,  8.15it/s]
100%|██████████| 100.0/100.0 [00:12<00:00,  8.15it/s]

import numpy as np

import pde

import emulsim

# set up a 2d cytosol with a 1d boundary membrane
grid = pde.UnitGrid([32, 8], periodic=[True, False])
cytosol = emulsim.ScalarFieldElement.from_field(pde.ScalarField(grid, 0.001))
membrane = emulsim.ScalarBoundaryFieldElement.from_bulk_grid(
    grid, axis=1, upper=True, data=np.random.uniform(-1, 1, 32)
)
state = emulsim.State({"cytosol": cytosol, "membrane": membrane})

# set up simulation of phase separation in membrane and diffusion in cytosol
simulation = emulsim.Simulation(state)
simulation.add_actor("cytosol", emulsim.DiffusionActor())
simulation.add_actor("membrane", emulsim.ScalarPDEActor(pde.CahnHilliardPDE()))
# couple both domains using an exchange flux
boundary_coupling = emulsim.FieldBoundaryExchangeActor(
    {"exchange_flux": "0.1 * (bulk - boundary)"}
)
simulation.add_actor(("cytosol", "membrane"), boundary_coupling)

# run the simulation
result = simulation.run(t_range=100)
result.plot(vmin=-0.2, vmax=0.2)

Total running time of the script: (0 minutes 12.357 seconds)