Note
Go to the end to download the full example code.
Custom Brownian motion class
Demonstrates the custom implementation of Brownian motion.

0%| | 0/10.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/10.0 [00:00<?, ?it/s]
0%| | 0/10.0 [00:00<?, ?it/s]
10%|█ | 1.0/10.0 [00:00<00:00, 1139.45it/s]
10%|█ | 1.0/10.0 [00:00<00:00, 943.60it/s]
100%|██████████| 10.0/10.0 [00:00<00:00, 8871.20it/s]
100%|██████████| 10.0/10.0 [00:00<00:00, 8346.87it/s]
import numpy as np
import emulsim
class BrownianParticlesActor(emulsim.ActorBase):
diffusivity = 1
def evolve(self, elements, t, dt):
"""Evolve the particles in time."""
(particles,) = elements
scale = np.sqrt(dt) * self.diffusivity
size = particles.positions.shape
particles.positions[...] += scale * np.random.normal(size=size)
# set up state
particle_data = np.random.uniform(0, 100, size=(10, 2))
particles = emulsim.PointsElement(particle_data)
state = emulsim.State({"particles": particles})
# set up simulation
simulation = emulsim.Simulation(state)
simulation.add_actor("particles", BrownianParticlesActor())
# run simulation
result = simulation.run(t_range=10)
result.plot()
Total running time of the script: (0 minutes 0.040 seconds)