Skip to content

Active Ornstein-Uhlenbeck particles

Active Ornstein-Uhlenbeck particles in the plane.

  • Class: ActiveOrnsteinUhlenbeckParticlesSystem
  • Import: from skcomplex.systems.physics.active_matter import ActiveOrnsteinUhlenbeckParticlesSystem
  • Field: physics/active_matter
  • Topics: active matter, sde, self-propulsion, colored noise
  • References:
    • Bechinger et al. 2016
    • Fodor et al. 2016

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.active_matter import ActiveOrnsteinUhlenbeckParticlesSystem

trajectory = ActiveOrnsteinUhlenbeckParticlesSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
n_particles 200
tau 1.0
D 1.0
D_t 0.0
size 50.0
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 ActiveOrnsteinUhlenbeckParticlesSystem(BaseSystem):
    """Active Ornstein-Uhlenbeck particles in the plane.

    The particles are driven by exponentially correlated propulsion.

    The propulsion starts in its stationary distribution, normal with variance `D / tau` per component. The system has
    the positions `swimmers.x` and propulsions `swimmers.u`.

    Args:
        n_particles:
            The number of particles.

        tau:
            The persistence time.

        D:
            The active diffusion coefficient.

        D_t:
            The translational diffusion coefficient.

        size:
            The side of the square in which the particles start.

        random_state:
            The seed or generator of the initial positions and propulsions.

        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 the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import ActiveOrnsteinUhlenbeckParticlesSystem
        >>> ActiveOrnsteinUhlenbeckParticlesSystem(10, tau=0.5).prepare().system_.interactions[0].tau
        0.5
    """

    field = 'physics/active_matter'
    topics = ('active matter', 'sde', 'self-propulsion', 'colored noise')
    references = ('Bechinger et al. 2016', 'Fodor et al. 2016')
    until = 20.0
    dt = 0.5

    def __init__(
        self,
        n_particles: int = 200,
        *,
        tau: float = 1.0,
        D: float = 1.0,
        D_t: float = 0.0,
        size: float = 50.0,
        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.tau = tau
        self.D = D
        self.D_t = D_t
        self.size = size
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of active Ornstein-Uhlenbeck particles in the plane.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        rng = np.random.default_rng(self.random_state)
        positions = rng.uniform(0.0, self.size, (self.n_particles, 2))
        propulsion = rng.normal(0.0, math.sqrt(self.D / self.tau), (self.n_particles, 2))
        swimmers = OrnsteinUhlenbeckParticleElement(
            'swimmers',
            x=positions,
            u=propulsion,
            size=self.n_particles,
            space=ContinuousSpace(n_dim=2),
        )
        self.system_ = System(
            self.label,
            elements=[swimmers],
            interactions=[
                OrnsteinUhlenbeckPropulsionInteraction(
                    'propulsion',
                    target='swimmers',
                    tau=self.tau,
                    D=self.D,
                    D_t=self.D_t,
                ),
            ],
            solver=EulerMaruyamaSolver(dt=0.01),
        )

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • OrnsteinUhlenbeckParticleElement, from Element

Interactions:

  • OrnsteinUhlenbeckPropulsionInteraction, from Interaction
class OrnsteinUhlenbeckParticleElement(Element):
    """Active particles with the positions `x` and the propulsion velocities `u`.

    Args:
        label:
            The label of the particles.

        x:
            The initial positions, one row per particle or shared.

        u:
            The initial propulsion velocities, one row per particle or shared.

        size:
            The number of particles, or `None` for one.

        space:
            The continuous space of the particles, or `None` for none.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import OrnsteinUhlenbeckParticleElement
        >>> OrnsteinUhlenbeckParticleElement('swimmer', u=(1.0, 0.0)).u
        (1.0, 0.0)
    """

    visual = POINTS

    def __init__(
        self,
        label: str,
        *,
        x: object = (0.0, 0.0),
        u: object = (0.0, 0.0),
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, size=size, space=space)
        self.x = x
        self.u = u

class OrnsteinUhlenbeckPropulsionInteraction(Interaction):
    """Propulsion of active particles by an Ornstein-Uhlenbeck process.

    The laws are `dx = u dt + sqrt(2 D_t) dW` and `tau du = -u dt + sqrt(2 D) dW`, so the propulsion keeps its
    direction for the persistence time `tau` and the particle diffuses with `D + D_t` at long times. It is a bacterium
    or a colloid whose swimming direction forgets itself smoothly.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the particles, with the positions `x` and the propulsions `u`.

        tau:
            The persistence time.

        D:
            The active diffusion coefficient.

        D_t:
            The translational diffusion coefficient.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import OrnsteinUhlenbeckPropulsionInteraction
        >>> OrnsteinUhlenbeckPropulsionInteraction('propulsion', target='swimmers').tau
        1.0
    """

    law_classes = (NoiseLaw, RateLaw)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        tau: Annotated[float, RealSet.open(0, oo)] = 1.0,
        D: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        D_t: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.tau = tau
        self.D = D
        self.D_t = D_t

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the propulsion of the position, the relaxation and noise of the propulsion, and the position noise.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        x, u = s.target.x, s.target.u
        self.laws_ = [
            RateLaw(x, u),
            NoiseLaw(x, sqrt(2 * s.D_t)),
            RateLaw(u, -u / s.tau),
            NoiseLaw(u, sqrt(2 * s.D) / s.tau),
        ]