Inertial and overdamped Brownian motion
Free Brownian particles with or without inertia.
- Class:
BrownianMotionSystem - Import:
from skcomplex.systems.physics.soft_matter import BrownianMotionSystem - Field:
physics/soft_matter - Topics:
brownian motion,sde,diffusion,inertia - References:
- Argun et al. 2021
- Li et al. 2010
- Volpe and Volpe 2013
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.soft_matter import BrownianMotionSystem
trajectory = BrownianMotionSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_particles |
500 |
inertial |
True |
m |
1.0 |
gamma |
1.0 |
kT |
1.0 |
n_dim |
1 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | continuous |
| Laws | noise, rate |
| Randomness | stochastic |
| Domains | vector |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class BrownianMotionSystem(BaseSystem):
"""Free Brownian particles with or without inertia.
With inertia they follow `m x'' = -gamma x' + sqrt(2 kT gamma) W`.
With inertia the motion is ballistic, `<x^2> = kT t^2 / m`, below the momentum relaxation time `m / gamma`, and
diffusive, `<x^2> = 2 kT t / gamma` per axis, above it. Without inertia it is diffusive at every time. The system
has the positions `beads.x`.
Args:
n_particles:
The number of particles.
inertial:
Whether the particles have inertia.
m:
The mass, used with inertia.
gamma:
The friction coefficient.
kT:
The thermal energy.
n_dim:
The number of dimensions.
random_state:
The seed or generator of the thermal initial velocities.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for Euler-Maruyama with the step 0.005.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.soft_matter import BrownianMotionSystem
>>> type(BrownianMotionSystem(10, inertial=False).prepare().system_.elements[0]).__name__
'BrownianParticleElement'
"""
field = 'physics/soft_matter'
topics = ('brownian motion', 'sde', 'diffusion', 'inertia')
references = ('Argun et al. 2021', 'Li et al. 2010', 'Volpe and Volpe 2013')
until = 10.0
dt = 0.1
def __init__(
self,
n_particles: int = 500,
*,
inertial: bool = True,
m: float = 1.0,
gamma: float = 1.0,
kT: float = 1.0,
n_dim: int = 1,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_particles = n_particles
self.inertial = inertial
self.m = m
self.gamma = gamma
self.kT = kT
self.n_dim = n_dim
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set `system_` to free Brownian particles with or without inertia.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
space = ContinuousSpace(n_dim=self.n_dim)
solver = EulerMaruyamaSolver(dt=0.005)
start = np.zeros((self.n_particles, self.n_dim))
if not self.inertial:
beads = BrownianParticleElement(
'beads',
x=start,
gamma=self.gamma,
temperature=self.kT,
size=self.n_particles,
space=space,
)
bath = ThermalNoiseInteraction('bath', target='beads')
self.system_ = System(self.label, elements=[beads], interactions=[bath], space=space, solver=solver)
return
velocities = np.random.default_rng(self.random_state).normal(
0.0,
math.sqrt(self.kT / self.m),
(self.n_particles, self.n_dim),
)
beads = BeadElement('beads', x=start, m=self.m, values={"x'": velocities}, size=self.n_particles, space=space)
bath = LangevinThermostatInteraction('bath', target='beads', temperature=self.kT, gamma=self.gamma)
self.system_ = System(self.label, elements=[beads], interactions=[bath], space=space, solver=solver)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BeadElement, fromElement, through the shared recipePointElement
Interactions:
LangevinThermostatInteraction, fromInteraction
class BeadElement(MassPointElement):
"""Point mass drawn as a point at its position.
Examples:
>>> from skcomplex.systems.physics.soft_matter import BeadElement
>>> BeadElement('bead', m=2.0).m
2.0
"""
visual = POINTS
class LangevinThermostatInteraction(Interaction):
"""Langevin thermostat, a drag `-gamma x'` and a random force that hold particles at a temperature.
The velocity `x'` of every particle of mass `m` follows `dx' = -gamma x' / m dt + sqrt(2 gamma temperature) / m
dW`, with the temperature in energy units, so the velocities relax over the time `m / gamma` to the
Maxwell-Boltzmann distribution at that temperature. It is the solvent around a colloid, the heat bath of a
molecular simulation, or the gas around a dust grain. The LAMMPS solver runs it as `fix langevin`.
Args:
label:
The label of the interaction.
target:
The path of the particle or particle group.
temperature:
The temperature in energy units.
gamma:
The friction coefficient.
state:
The name of the position of the particles.
Examples:
>>> from skcomplex.systems.physics.common.particles import LangevinThermostatInteraction
>>> LangevinThermostatInteraction('bath', target='gas', temperature=2.0).temperature
2.0
"""
law_classes = (RateLaw, NoiseLaw)
def __init__(
self,
label: str,
*,
target: Role,
temperature: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
gamma: Annotated[float, RealSet.open(0, oo)] = 1.0,
state: str = 'x',
) -> None:
super().__init__(label)
self.target = target
self.temperature = temperature
self.gamma = gamma
self.state = state
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the drag and the random force on the velocity of the particles.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s, t = context, context.t
x, m = getattr(s.target, self.state), s.target.m
self.laws_ = [
RateLaw(x.diff(t, 2), -x.diff(t) / (1 / s.gamma) / m),
NoiseLaw(x.diff(t, 2), sqrt(2 * s.gamma * s.temperature) / m),
]