Skip to content

Active nematic and polar gels

An active gel.

  • Class: ActiveGelsSystem
  • Import: from skcomplex.systems.physics.active_matter import ActiveGelsSystem
  • Field: physics/active_matter
  • Topics: field, active matter, nematic, polar, tensor, gel, stokes flow, active turbulence, pde
  • References:
    • Marchetti et al. 2013
    • arXiv:1207.2929
    • Kruse et al. 2005
    • Voituriez, Joanny, and Prost 2005
    • Giomi et al. 2012
    • arXiv:1110.4338

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 ActiveGelsSystem

trajectory = ActiveGelsSystem().prepare().simulate()

Parameters

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

Parameter Default
shape None
order 'nematic'
spacing None
a None
c None
K 1.0
xi None
gamma 1.0
eta 1.0
zeta None
film False
perturbation None
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 vector
Structure fixed

Class

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

class ActiveGelsSystem(BaseSystem):
    """An active gel.

    A nematic tensor or a polarisation is transported in the Stokes flow of its own stresses.

    On a periodic lattice with spectral operators, the order parameter follows its co-rotational derivative in the flow,
    Section III of Marchetti et al. The flow solves the overdamped Stokes equation of the elastic stress and the active
    stress, `-zeta Q` for the nematic and `-zeta p p` for the polar gel, and the elastic energy relaxes the order. An
    extensile nematic, `zeta > 0`, is unstable to bend, and a contractile polar gel, `zeta < 0`, is unstable to splay
    above a threshold.

    The defaults of the nematic are the chaotic state of Giomi et al. 2012, cited by Marchetti et al., whose free energy
    has the same form: a box of side 10, the critical density `3 pi / 2`, the density twice that, which give `a` and
    `c`, the activity `3` times the squared density, and the flow alignment 0.1, in units of the elastic constant, the
    rotational viscosity, and the viscosity. The density stays uniform here. At these defaults pairs of `+1/2` and
    `-1/2` defects move in a chaotic flow, active turbulence.

    The nematic starts from the tensor along the first axis at the order `sqrt(-2 a / c)`, and the polar gel from the
    polarisation along the first axis at the length `sqrt(-a / c)`, both with noise. With `film=True` the polarisation
    along the second axis is odd about the sites 0 and `shape[1] / 2` of the second axis, and the other one even, which
    holds the polarisation along the first axis at these two walls, with stress-free flow there. The system has the
    field `gel.Q` or `gel.p`. The tuned run is that of the nematic, and the polar gel, whose flow is slow, runs with
    RK4 at the step 0.05 and is best simulated for 200 time units with frames every time unit.

    Args:
        shape:
            The number of sites along every axis of the periodic lattice, in two dimensions, or `None` for `(128, 128)`
            for the nematic and `(32, 32)` for the polar gel.

        order:
            `'nematic'` or `'polar'`.

        spacing:
            The distance between neighbouring sites, or `None` for a nematic box of side 10 along the first axis and 1
            for the polar gel.

        a:
            The coefficient of the quadratic energy, negative in the ordered phase, or `None` for `-3 pi / 4` for the
            nematic and -1 for the polar gel.

        c:
            The coefficient of the quartic energy, or `None` for `3 pi` for the nematic and 1 for the polar gel.

        K:
            The elastic constant.

        xi:
            The flow-alignment parameter, or `None` for 0.1 for the nematic and 0 for the polar gel.

        gamma:
            The rotational viscosity.

        eta:
            The viscosity of the flow.

        zeta:
            The activity, or `None` for `3 (3 pi)^2` for the nematic and -0.5 for the polar gel.

        film:
            Whether the polar gel lies between walls of fixed polarisation.

        perturbation:
            The standard deviation of the initial noise of the order parameter, or `None` for 0.1 for the nematic and
            0.01 for the polar gel.

        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 5e-4 for the nematic and 0.05 for the polar
            gel.

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

    Raises:
        ValidationError:
            The order is unknown, or a nematic is asked to lie in a film.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import ActiveGelsSystem
        >>> ActiveGelsSystem((8, 8), order='polar').prepare().system_.elements[0].zeta
        -0.5
        >>> ActiveGelsSystem(order='polar').prepare().system_.elements[0].space.shape
        (32, 32)
    """

    field = 'physics/active_matter'
    topics = ('field', 'active matter', 'nematic', 'polar', 'tensor', 'gel', 'stokes flow', 'active turbulence', 'pde')
    references = (
        'Marchetti et al. 2013',
        'arXiv:1207.2929',
        'Kruse et al. 2005',
        'Voituriez, Joanny, and Prost 2005',
        'Giomi et al. 2012',
        'arXiv:1110.4338',
    )
    until = 0.5
    dt = 0.025
    observables = (
        Observable('u_x', _get_velocity_x, group='gel', reduce=_get_sites),
        Observable('u_y', _get_velocity_y, group='gel', reduce=_get_sites),
    )

    def __init__(
        self,
        shape: Sequence[int] | None = None,
        *,
        order: str = 'nematic',
        spacing: float | None = None,
        a: float | None = None,
        c: float | None = None,
        K: float = 1.0,
        xi: float | None = None,
        gamma: float = 1.0,
        eta: float = 1.0,
        zeta: float | None = None,
        film: bool = False,
        perturbation: float | None = None,
        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.order = order
        self.spacing = spacing
        self.a = a
        self.c = c
        self.K = K
        self.xi = xi
        self.gamma = gamma
        self.eta = eta
        self.zeta = zeta
        self.film = film
        self.perturbation = perturbation
        self.random_state = random_state

    def _get_gel(self) -> Element:
        """Return the gel on its spectral lattice, from the tensor or the polarisation along the first axis."""
        polar = self.order == 'polar'
        shape = ((32, 32) if polar else (128, 128)) if self.shape is None else tuple(self.shape)
        sites = int(np.prod(shape))
        rng = np.random.default_rng(self.random_state)
        quadratic = (-1.0 if polar else (NEMATIC_CRITICAL_DENSITY - NEMATIC_DENSITY) / 2) if self.a is None else self.a
        cubic = (1.0 if polar else NEMATIC_DENSITY) if self.c is None else self.c
        activity = (-0.5 if polar else NEMATIC_ACTIVITY * NEMATIC_DENSITY**2) if self.zeta is None else self.zeta
        alignment = (0.0 if polar else NEMATIC_XI) if self.xi is None else self.xi
        distance = (1.0 if polar else NEMATIC_BOX / shape[0]) if self.spacing is None else self.spacing
        amplitude = (0.01 if polar else 0.1) if self.perturbation is None else self.perturbation
        noise = amplitude * rng.standard_normal((sites, 2))
        size = np.sqrt(-quadratic / cubic) if polar else np.sqrt(-2 * quadratic / cubic) / 2
        start = np.column_stack([np.full(sites, size), np.zeros(sites)]) + noise if quadratic < 0 else noise
        symmetry = {'p': ((None, 'even'), (None, 'odd'))} if self.film else None
        space = LatticeSpace(shape, spacing=distance, discretization='spectral', symmetry=symmetry)
        constants = {
            'a': quadratic,
            'c': cubic,
            'K': self.K,
            'xi': alignment,
            'gamma': self.gamma,
            'eta': self.eta,
            'zeta': activity,
        }
        if polar:
            return PolarGelSiteElement('gel', p=start, space=space, **constants)
        return NematicGelSiteElement('gel', Q=start, space=space, **constants)

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the gel and the flow of its order.

        Args:
            context:
                The observables to compile with the problem, or `None` for the tuned ones.

        Raises:
            ValidationError:
                The order is unknown, or a nematic is asked to lie in a film.
        """
        super()._prepare(context)
        if self.order not in GEL_ORDERS:
            error_msg = f'The order of the gel is {self.order!r}. Use one of {", ".join(GEL_ORDERS)}.'
            raise ValidationError(error_msg)
        if self.film and self.order != 'polar':
            error_msg = 'A film of the gel holds a polarisation at its walls. Use order=polar.'
            raise ValidationError(error_msg)
        polar = self.order == 'polar'
        flow = (
            PolarGelFlowInteraction('flow', target='gel') if polar else NematicGelFlowInteraction('flow', target='gel')
        )
        self.system_ = System(
            self.label,
            elements=[self._get_gel()],
            interactions=[flow],
            solver=RK4Solver(dt=POLAR_STEP if polar else NEMATIC_STEP),
        )

Components

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

Elements:

  • NematicGelSiteElement, from Element

Interactions:

  • NematicGelFlowInteraction, from Interaction
class NematicGelSiteElement(Element):
    """Sites of an active nematic gel, with a symmetric traceless tensor and the constants of the gel.

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

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

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

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

        K:
            The elastic constant.

        xi:
            The flow-alignment parameter.

        gamma:
            The rotational viscosity.

        eta:
            The viscosity of the flow.

        zeta:
            The activity.

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

    Examples:
        >>> from skcomplex.systems.physics.active_matter import NematicGelSiteElement
        >>> NematicGelSiteElement('site').zeta
        0.5
    """

    def __init__(
        self,
        label: str,
        *,
        Q: Annotated[object, Tensor('traceless')] = 0.0,
        a: float = -1.0,
        c: Annotated[float, RealSet.open(0, oo)] = 2.0,
        K: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        xi: float = 0.0,
        gamma: Annotated[float, RealSet.open(0, oo)] = 1.0,
        eta: Annotated[float, RealSet.open(0, oo)] = 1.0,
        zeta: float = 0.5,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.Q = Q
        self.a = a
        self.c = c
        self.K = K
        self.xi = xi
        self.gamma = gamma
        self.eta = eta
        self.zeta = zeta

class NematicGelFlowInteraction(Interaction):
    """Transport and relaxation of the tensor of an active nematic gel in the Stokes flow of its stresses.

    The tensor follows `Q_t = -C(Q, u, xi) + H / gamma`, with the corotational transport `C` of Beris and Edwards
    and the molecular field `H` of the Landau-de Gennes energy. The velocity solves
    `eta laplacian(u) - grad(P) + div(sigma) = 0`, `div(u) = 0`, with the stress `sigma = -xi H + Q H - H Q - zeta Q`.
    An activity `zeta > 0` is extensile and an activity `zeta < 0` contractile. It is the active turbulence of
    microtubule bundles, of dense bacteria, or of a monolayer of cells.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the gel, whose values are the tensor `Q` and the constants of the gel.

    Examples:
        >>> from skcomplex.systems.physics.active_matter import NematicGelFlowInteraction
        >>> NematicGelFlowInteraction('flow', target='gel').target
        'gel'
    """

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

    @staticmethod
    def _get_velocity(s: SimpleNamespace) -> FreeModuleElement:
        """Return the velocity of the Stokes flow of the elastic and active stresses at a site."""
        field = LandauDeGennesEnergyInteraction._get_molecular_field(s.Q, s.a, s.c, s.K)
        stress = -s.xi * field + s.Q * field - field * s.Q - s.zeta * s.Q
        force = tensor_divergence(stress)
        return leray_projection(force.apply_map(lambda item: inverse_helmholtz(-item / s.eta)))

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the rate of the tensor, its transport in the flow and its relaxation.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context.target
        field = LandauDeGennesEnergyInteraction._get_molecular_field(s.Q, s.a, s.c, s.K)
        transport = PolarGelFlowInteraction._get_corotational_transport(s.Q, self._get_velocity(s), s.xi)
        self.laws_ = [RateLaw(s.Q, -transport + field / s.gamma)]