Skip to content

Dry active nematics

A dry active nematic.

  • Class: DryActiveNematicsSystem
  • Import: from skcomplex.systems.physics.active_matter import DryActiveNematicsSystem
  • Field: physics/active_matter
  • Topics: field, active matter, nematic, tensor, liquid crystal, giant number fluctuations, pde
  • References:
    • Marchetti et al. 2013
    • arXiv:1207.2929

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 DryActiveNematicsSystem

trajectory = DryActiveNematicsSystem().prepare().simulate()

Parameters

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

Parameter Default
shape (64, 64)
density 1.5
critical_density 1.0
a 1.0
c 2.0
K 1.0
gamma 1.0
D 0.5
current 0.5
beta 0.5
perturbation 0.01
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 lattice
Laws rate
Randomness unknown
Domains real, vector
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class DryActiveNematicsSystem(BaseSystem):
    """A dry active nematic.

    A conserved density is coupled to a symmetric traceless alignment tensor.

    On a periodic lattice the density and the tensor follow Section II.2 of Marchetti et al.,

        rho_t = -div(J),    J = -D grad(rho) - current div(Q),
        Q_t = H / gamma + beta (partial_i partial_j rho - delta_ij laplacian(rho) / 2),

    with the molecular field `H` of the Landau-de Gennes energy, whose coefficient `a (1 - rho / rho_c)` turns negative
    above the critical density `rho_c`. The current along `div(Q)` is the active current, which no free energy gives.
    The system has the fields `nematic.rho` and `nematic.Q`.

    Args:
        shape:
            The number of sites along every axis of the periodic lattice.

        density:
            The mean density, which the dynamics conserve.

        critical_density:
            The density at which the isotropic state loses stability.

        a:
            The scale of the coefficient of `tr(Q^2) / 2` of the energy.

        c:
            The coefficient of `tr(Q^2)^2 / 4` of the energy.

        K:
            The elastic constant.

        gamma:
            The rotational viscosity.

        D:
            The diffusion coefficient of the density.

        current:
            The coefficient of the active current along `div(Q)`.

        beta:
            The coupling of the tensor to the curvature of the density.

        perturbation:
            The standard deviation of the initial noise of the density and the tensor.

        random_state:
            The seed or generator of the initial noise.

        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 RK4 with the step 0.02.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for Numba.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import DryActiveNematicsSystem
        >>> DryActiveNematicsSystem((8, 8)).prepare().system_.interactions[0].beta
        0.5
    """

    field = 'physics/active_matter'
    topics = ('field', 'active matter', 'nematic', 'tensor', 'liquid crystal', 'giant number fluctuations', 'pde')
    references = ('Marchetti et al. 2013', 'arXiv:1207.2929')
    until = 100.0
    dt = 5.0

    def __init__(
        self,
        shape: Sequence[int] = (64, 64),
        *,
        density: float = 1.5,
        critical_density: float = 1.0,
        a: float = 1.0,
        c: float = 2.0,
        K: float = 1.0,
        gamma: float = 1.0,
        D: float = 0.5,
        current: float = 0.5,
        beta: float = 0.5,
        perturbation: float = 0.01,
        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.shape = shape
        self.density = density
        self.critical_density = critical_density
        self.a = a
        self.c = c
        self.K = K
        self.gamma = gamma
        self.D = D
        self.current = current
        self.beta = beta
        self.perturbation = perturbation
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the noisy density and tensor with their alignment, energy, and current.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        shape = tuple(self.shape)
        rng = np.random.default_rng(self.random_state)
        sites = int(np.prod(shape))
        rho = self.density + self.perturbation * rng.standard_normal(sites)
        Q = self.perturbation * rng.standard_normal((sites, 2))
        nematic = NematicDensitySiteElement('nematic', rho=rho, Q=Q, space=LatticeSpace(shape))
        critical = self.critical_density
        interactions = [
            CurvatureAlignmentInteraction('alignment', target='nematic', beta=self.beta),
            LandauDeGennesEnergyInteraction(
                'energy',
                target='nematic',
                a=self.a,
                c=self.c,
                K=self.K,
                gamma=self.gamma,
                quadratic=lambda s: s.a * (1 - s.target.rho / critical),
            ),
            ActiveCurrentInteraction('transport', target='nematic', D=self.D, current=self.current),
        ]
        self.system_ = System(
            self.label,
            elements=[nematic],
            interactions=interactions,
            solver=RK4Solver(dt=0.02),
            backend=NumbaBackend(),
        )

Components

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

Elements:

  • NematicDensitySiteElement, from Element

Interactions:

  • CurvatureAlignmentInteraction, from Interaction
  • LandauDeGennesEnergyInteraction, from Interaction, through the shared recipe GradientInteraction
  • ActiveCurrentInteraction, from Interaction
class NematicDensitySiteElement(Element):
    """Sites of a dry active nematic, with a density and a symmetric traceless alignment tensor.

    Args:
        label:
            The label of the site or the field.

        rho:
            The initial density, or one density per site.

        Q:
            The initial alignment tensor, its independent components `Q_xx` and `Q_xy`, or one tensor per site.

        space:
            The lattice of the sites, or `None` for one site.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import NematicDensitySiteElement
        >>> NematicDensitySiteElement('site', rho=2.0).rho
        2.0
    """

    def __init__(
        self,
        label: str,
        *,
        rho: object = 1.0,
        Q: Annotated[object, Tensor('traceless')] = 0.0,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.rho = rho
        self.Q = Q

class CurvatureAlignmentInteraction(Interaction):
    """Growth of an alignment tensor with the traceless curvature of a density.

    The rate of the tensor is `beta (partial_i partial_j rho - delta_ij laplacian(rho) / 2)`, so rods align along the
    ridges of the density. It is the coupling of the order of a dry active nematic, of a bacterial colony, or of a
    layer of cells to the variations of their density.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the field, whose values are the density `rho` and the tensor `Q`.

        beta:
            The coupling of the tensor to the curvature of the density.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import CurvatureAlignmentInteraction
        >>> CurvatureAlignmentInteraction('alignment', target='nematic', beta=0.25).beta
        0.25
    """

    def __init__(self, label: str, *, target: Role, beta: float = 0.5) -> None:
        super().__init__(label)
        self.target = target
        self.beta = beta

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the rate of the tensor from the curvature of the density.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        field = context.target
        curvature = symmetric_part(vector_gradient(gradient(field.rho)))
        traceless = curvature - curvature.trace() / 2 * identity_matrix(SR, 2)
        self.laws_ = [RateLaw(field.Q, context.beta * traceless)]

class LandauDeGennesEnergyInteraction(GradientInteraction):
    """Landau-de Gennes free energy gradient flow of a symmetric traceless tensor `Q`.

    The free energy is `F = integral a tr(Q^2) / 2 + c tr(Q^2)^2 / 4 + K |grad Q|^2 / 2`. Its negative functional
    derivative among symmetric traceless tensors is the molecular field `H = -a Q - c tr(Q^2) Q + K laplacian(Q)`, and
    the tensor relaxes as `Q_t = H / gamma`. A uniform tensor `S (n n - I / 2)` in two dimensions with `a < 0` relaxes
    to the scalar order `S = sqrt(-2 a / c)`.

    Args:
        label:
            The label of the interaction, unique among the components of its system.

        target:
            The path of the field.

        state:
            The name of the value of the field that holds the tensor.

        a:
            The coefficient of `tr(Q^2) / 2`, negative in the ordered phase.

        c:
            The coefficient of `tr(Q^2)^2 / 4`.

        K:
            The elastic constant.

        gamma:
            The rotational viscosity, which divides the molecular field.

        quadratic:
            A function of the namespace that returns the coefficient of `tr(Q^2) / 2` instead of `a`, such as an
            expression of a density, or `None` for `a`.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import LandauDeGennesEnergyInteraction
        >>> LandauDeGennesEnergyInteraction('energy', target='nematic', a=-1.0).a
        -1.0
    """

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        state: str = 'Q',
        a: float = -1.0,
        c: Annotated[float, RealSet.open(0, oo)] = 2.0,
        K: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        gamma: Annotated[float, RealSet.open(0, oo)] = 1.0,
        quadratic: Callable[[SimpleNamespace], object] | None = None,
    ) -> None:
        super().__init__(label, target=target, states=state, variational=True)
        self.state = state
        self.a = a
        self.c = c
        self.K = K
        self.gamma = gamma
        self.quadratic = quadratic

    @staticmethod
    def _get_density(tensor: Matrix, a: object, c: object, K: object) -> Expression:
        """Return the density of the free energy, with the gradient term by parts."""
        square = (tensor * tensor).trace()
        return a * square / 2 + c * square**2 / 4 - K * (tensor * tensor.apply_map(laplacian)).trace() / 2

    @classmethod
    def _get_molecular_field(cls, tensor: Matrix, a: object, c: object, K: object) -> Matrix:
        """Return the molecular field of a tensor.

        The field is the negative functional derivative of the free energy.
        """
        energy = cls('energy', target='field')
        return -energy._get_matrix_derivative(cls._get_density(tensor, a, c, K), tensor)

    def _get_potential(self, namespace: SimpleNamespace) -> Expression:
        """Return the density of the free energy over the rotational viscosity.

        Its gradient is `H / gamma`.

        Args:
            namespace:
                The namespace of the symbols the density can use.

        Returns:
            density:
                The density that the tensor moves down.
        """
        quadratic = namespace.a if self.quadratic is None else self.quadratic(namespace)
        tensor = getattr(namespace.target, self.state)
        return self._get_density(tensor, quadratic, namespace.c, namespace.K) / namespace.gamma

class ActiveCurrentInteraction(Interaction):
    """Conserved current of a density, by diffusion and along the divergence of an alignment tensor.

    The density follows `rho_t = -div(J)` with `J = -D grad(rho) - current div(Q)`. The current along `div(Q)` is the
    active current of a nematic, which no free energy gives, as bacteria or cells move along the bend of their order.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the field, whose values are the density `rho` and the tensor `Q`.

        D:
            The diffusion coefficient of the density.

        current:
            The coefficient of the active current along `div(Q)`.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import ActiveCurrentInteraction
        >>> ActiveCurrentInteraction('transport', target='nematic', D=0.1).D
        0.1
    """

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        D: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
        current: float = 0.5,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.D = D
        self.current = current

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the rate of the density, the divergence of its current.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        field = context.target
        active = tensor_divergence(field.Q)
        flux = [-self.D * item - self.current * other for item, other in zip(gradient(field.rho), active, strict=True)]
        self.laws_ = [RateLaw(field.rho, -divergence(flux))]