## Introduction

Concepts from topology have played a key role in understanding a wide range of physical phenomena by providing an intuitive and mathematically rich effective description of the system1,2. In classical systems, topology has played a crucial role, for instance, in characterizing 2D turbulence3 and defect-mediated phase transitions4. Topological defects abound in soft matter systems, such as dislocation and disclination pairs in 2D melting5 and various liquid crystalline systems6, and have recently featured in a variety of intrinsically non-equilbrium active matter systems7,8,9,10,11. An early example of topological protection arose from use of the Gauss-Bonnet theorem in the physics of membranes12. More recent work examined relevant topological invariants in mechanical lattices13 or dissipative systems in continuous space14 or lattice models with underlying periodic structure15,16,17,18,19,20. Many such systems exhibit non-Hermitian properties such as exceptional points21,22,23,24,25 and a non-zero topological vorticity of the edge state14,20. The topological systems that support protected edge states are robust to disorder and perturbations, providing a key towards understanding such phenomena.

Fluctuations can give rise to particle trajectories with negative entropy, which appears to contradict a fundamental law of macroscopic physics. Fluctuation theorems provide a quantitative, probabilistic prediction for this negative entropy production. These universal laws are valid even during processes that drive systems far from equilibrium. While the probability to observe such “violations” is typically exponentially small in the relevant system size, it can be appreciable in small systems. The first theorem was discovered over two decades ago by computer simulations and justified heuristically26, then proven for a large class of systems27,28,29. This led to a class of relations dealing with the distribution functions of thermodynamic quantities such as exchanged heat, applied work or entropy production30. Additional relations were moreover found in a variety of systems with non-reversible microscopic dynamics31,32,33,34,35,36. Further work extended the concepts of thermodynamics to the level of individual trajectories37,38. Another key insight related entropy production in the medium to that part of the stochastic action, which determines the weight of trajectories that is odd under time reversal39,40. These and other developments opened the possibility for experimental or numerical measurements on the single molecule level, providing verification of the fluctuation theorems41,42. Notably, critical insights were obtained for the behavior of bio-molecules43. Brownian dynamics of tracers in the presence of vortex-like singularities has been studied with an empasis on the winding number distribution and extensions to entanglement problems in polymer physics44,45,46,47,48. However, no connection has so far been made to stochastic thermodynamics.

Here, we identify a topological invariant that predicts observable quantities, in a strongly fluctuating system without underlying periodic structure. Our analysis allows us to quantify the ratio of particles with negative entropy production, purely as a function of winding number around vortex cores. We build on the geometrical properties of individual trajectories under the influence of external forces. This is studied in the context of a stochastic particle in a force-field, which is ubiquitous in nature (see Fig. 1). In particular, a particle moving around a closed path picks out only the non-conservative component of the force-field, which gives the entropy production. This allows us to formulate a topological fluctuation theorem based only on the vortex winding number. While previous work looked at entropy production in flow-fields49,50, the topological equivalence of particle trajectories and its consequences have not been studied. We begin with a general statement of the theorem using the examination of entropy production in the medium. We then demonstrate it in various examples including one or several vortices by calculating the corresponding exact winding number distribution or performing Brownian dynamics simulations. We find that even when the winding number distributions are non-Gaussian functions of the vortex circulation, the theorem holds exactly.

## Results

Consider the motion in d dimensions of a tracer particle with diffusivity D and mobility μ in a stationary force field F(r), where D = μkBT with kBT representing the thermal energy. The stochastic dynamics of the particle is characterized as a function of time 0≤τt by its trajectory r(τ), which satisfies the Langevin equation

$$\dot{{{{{{{{\bf{r}}}}}}}}}(\tau )=\mu {{{{{{{\bf{F}}}}}}}}({{{{{{{\bf{r}}}}}}}}(\tau ))+\sqrt{2D}\,{{{{{{{\boldsymbol{\xi }}}}}}}}(\tau ),$$
(1)

where ξ represents a d-dimensional Gaussian white noise of zero mean and unit variance. Using the Helmholtz-Hodge decomposition, the force field can generally be separated into a conservative component that derives from a potential U(r) and a rotational component f(r) that satisfies f(r) = 0, i.e., F(r) = − U(r) + f(r). Let us assume that the rotational component of the force field is generated by a topological defect, such as the vortex line shown in Fig. 1a for the physically relevant case d = 3. In the general case, such a defect takes the form of codimension 2 manifold Σ giving rise to a vorticity field satisfying

$$Q\equiv \int_{S}{{{{{{{\rm{d}}}}}}}}{r}^{i}\wedge {{{{{{{\rm{d}}}}}}}}{r}^{j}\left({\partial }_{i}{f}_{j}-{\partial }_{j}{f}_{i}\right),$$
(2)

where S is an arbitrary smooth surface intersecting Σ transversally at a single point, the constant Q is the strength of the vortex and summation is performed over i < j (distinct pairs)51,52. For such a vortex-induced force-field, we derive a topological fluctuation theorem in terms of the probability p(n, t) for any closed trajectory of duration t to wind n times around the vortex, which reads

$$\frac{p(-n,t)}{p(n,t)}=\exp \left(-\frac{nQ}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}\right),$$
(3)

for any U(r) (see Fig. 1a for a depiction of a representative force profile and closed loop in d = 3). Here, Q corresponds to the quantum of heat generated via the closed trajectories of the tracer particle that enclose the vortex domain. It is helpful to define γ ≡ Q/(kBT) as the quantum of entropy production (in units of kB). Figure 1b shows a number of exemplar closed trajectories with different winding numbers. Note that the theorem [Eq. (3)] is valid at any time t. Therefore, while the positive and negative winding number distributions are expected to evolve with time and be affected by conservative contributions from the force, their ratio is topologically protected.

The derivation of the topological fluctuation theorem starts from the probability distribution of the particle to be at position x after time t starting initially from x0, which can be be found via

$${{{{{{{\mathcal{P}}}}}}}}({{{{{{{\bf{x}}}}}}}},t| {{{{{{{{\bf{x}}}}}}}}}_{0},0)=\int\nolimits_{{{{{{{{\bf{r}}}}}}}}(0) = {{{{{{{{\bf{x}}}}}}}}}_{0}}^{{{{{{{{\bf{r}}}}}}}}(t) = {{{{{{{\bf{x}}}}}}}}}{{{{{{{\mathcal{D}}}}}}}}{{{{{{{\bf{r}}}}}}}}(\tau )P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}],$$
(4)

where the probability of a specific stochastic trajectory is defined in terms of the Onsager-Machlup action associated with Eq. (1) as

$$P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]=\\ {{{{{{{\mathcal{N}}}}}}}}\exp \left(-\int\nolimits_{0}^{t}{{{{{{{\rm{d}}}}}}}}\tau \left[\frac{1}{4D}{\left(\dot{{{{{{{{\bf{r}}}}}}}}}(\tau )-\mu {{{{{{{\bf{F}}}}}}}}({{{{{{{\bf{r}}}}}}}}(\tau ))\right)}^{2}+\frac{\mu }{2}\nabla \cdot {{{{{{{\bf{F}}}}}}}}({{{{{{{\bf{r}}}}}}}}(\tau ))\right]\right),$$
(5)

where $${{{{{{{\mathcal{N}}}}}}}}$$ is a normalization factor, and the Stratonovich convention is implied. Defining the kinematically reversed, or backward, trajectory $$\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )$$ as $$\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )\equiv {{{{{{{\bf{r}}}}}}}}(t-\tau )$$, we then find from Eq. (5) that the ratio between the probabilities of the backward and forward paths is given by the part of the stochastic action that is odd under this transformation, namely,

$$\frac{P[\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )| {{{{{{{\bf{x}}}}}}}}]}{P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]}=\exp \left(-{{\Gamma }}\right),$$
(6)

where $${{\Gamma }}\equiv \frac{1}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}\int\nolimits_{0}^{t}{{{{{{{\rm{d}}}}}}}}\tau \,\dot{{{{{{{{\bf{r}}}}}}}}}(\tau )\cdot {{{{{{{\bf{F}}}}}}}}({{{{{{{\bf{r}}}}}}}}(\tau ))$$ corresponds to the heat generated (in units of kBT), or entropy production, during the motion of the particle along the trajectory. We then consider a closed trajectory described by a curve C (by setting x = x0), which does not intersect with Σ, and implement the Stokes Theorem ∫Sω = ∫Sdω for the 1-form ω = Fidri over the surface S enclosed by C2, namely

$${{\Gamma }}= \frac{1}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}\oint _{C}{{{{{{{\rm{d}}}}}}}}{{{{{{{\bf{r}}}}}}}}\cdot {{{{{{{\bf{F}}}}}}}}\left({{{{{{{\bf{r}}}}}}}}\right)=\frac{1}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}{\int_{\partial S\,=\,C}}{{{{{{{\rm{d}}}}}}}}{r}^{i}{F}_{i}\\ = \,\frac{1}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}{\int_S}{{{{{{{\rm{d}}}}}}}}{r}^{i}\wedge {{{{{{{\rm{d}}}}}}}}{r}^{j}\left({\partial }_{i}{F}_{j}-{\partial }_{j}{F}_{i}\right).$$
(7)

It is manifest in Eq. (7) that Γ picks out only the rotational component of the force. Moreover, using the decomposition F = − U + f and Eq. (2) directly yields Γ = γn, with n the number of times that the forward trajectory winds around the vortex singularity. We thus find that Γ is independent of the initial position x0 or the specific shape of C so long as it corresponds to the same winding number n. Hence, Γ is identical for topologically equivalent curves (see Fig. 1b), and independent of the conservative component of the force-field.

To complete the calculation, we thus set x = x0 in Eq. (6) and integrate over all initial positions and topologically equivalent loops to obtain a topological fluctuation theorem for vortex-induced force fields (details in Methods)

$$\frac{p(-n,t)}{p(n,t)}=\exp \left(-n\gamma \right),$$
(8)

where p(n, t) denotes the probability for any closed trajectory of length t to wind n times around the vortex axis.

The above derivation is easily generalizable to the case of m non-intersecting vortex branes. Denoting γi and ni the dimensionless quantum of heat and winding number associated with a given vortex i, the entropy production becomes $${{\Gamma }}=\mathop{\sum }\nolimits_{i = 1}^{m}{\gamma }_{i}{n}_{i}$$. Integrating Eq. (6) over initial conditions and trajectories, which share the same set of winding numbers $${\{{n}_{i}\}}_{i = 1,\ldots m}$$, the topological fluctuation theorem for multiple vortices then reads

$$\frac{p(\{-{n}_{i}\},t)}{p(\{{n}_{i}\},t)}=\exp \left(-\mathop{\sum }\limits_{i=1}^{m}{\gamma }_{i}{n}_{i}\right),$$
(9)

where p({ni}, t) is the probability that a closed trajectory of length t has wrapped ni times around each vortex i for i = 1, …m.

As for a single vortex, Eq. (9) is set by topology and thus holds at all times and for any conservative force affecting the particle motion. Moreover, as both sides of Eq. (9) depend only on the set of winding numbers {ni} reached at time t, the fluctuation theorem is insensitive to the history leading to {ni} and in particular to the order in which the trajectory winds around each vortex. Since any combination of winding numbers leading to the same value of Γ leaves the r.h.s. of Eq. (9) unchanged, the latter can be further summed over all such configurations in order to get a weaker formulation of the theorem:

$$\frac{p({{\Gamma }}=-\mathop{\sum }\nolimits_{i = 1}^{m}{\gamma }_{i}{n}_{i},t)}{p({{\Gamma }}=\mathop{\sum }\nolimits_{i = 1}^{m}{\gamma }_{i}{n}_{i},t)}=\exp \left(-\mathop{\sum }\limits_{i=1}^{m}{\gamma }_{i}{n}_{i}\right).$$
(10)

### Exact solution for a single vortex

To shed some light on the topological fluctuation theorem (3), we now focus on the physically relevant case d = 3 and consider the motion of a tracer particle in a flow field created by a single straight vortex line oriented along ez, which is given in cylindrical coordinates (r, ϕ, z) by

$${{{{{{{\bf{f}}}}}}}}({{{{{{{\bf{r}}}}}}}})=\frac{Q}{2\pi r}\,{{{{{{{{\bf{e}}}}}}}}}_{\phi },\qquad {{{{{{{\boldsymbol{\nabla }}}}}}}}\times {{{{{{{\bf{f}}}}}}}}({{{{{{{\bf{r}}}}}}}})=Q{{{{{{{{\bf{e}}}}}}}}}_{z}{\delta }^{2}({{{{{{{{\bf{r}}}}}}}}}_{\perp }),$$
(11)

where $${{{{{{{{\bf{e}}}}}}}}}_{\phi }=(-\sin \phi ,\cos \phi ,0)$$ and $${{{{{{{{\bf{r}}}}}}}}}_{\perp }=r(\cos \phi ,\sin \phi )$$, so that from Eq. (7) we can readily evaluate $${{\Gamma }}=\frac{1}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}{\int}_{S}{{{{{{{\rm{d}}}}}}}}{{{{{{{\bf{S}}}}}}}}\cdot \nabla \times {{{{{{{\bf{F}}}}}}}}({{{{{{{\bf{r}}}}}}}})=\gamma n$$. The simple case where the particle motion is restricted to a ring following the flow streamlines, such that the drive is effectively uniform, has been treated previously38. This problem (generalizable to higher dimensions) corresponds to a biased random walk and the fluctuation theorem can be shown to result from the Gaussian form of the winding distribution.

However, from the above derivation the relation (3) holds even when the Brownian particle is allowed to move transversally to flow streamlines. Considering closed trajectories winding around a vortex line in free space, the Fokker–Planck equation describing the evolution of the distribution $${{{{{{{\mathcal{P}}}}}}}}(r,\phi ,z,t)$$ can be solved exactly53, such that the winding distribution is given, up to a normalizing constant, by (details in the Methods section below)

$$p(n,t| {r}_{0})\propto \int\nolimits_{0}^{\infty }{{{{{{{\rm{d}}}}}}}}u\,{{{{{{{\rm{Re}}}}}}}}\left[{e}^{2i\pi nu}{I}_{{k}_{u}}\left(\frac{{r}_{0}^{2}}{2Dt}\right)\right],$$
(12)

where $${k}_{u}=\sqrt{{u}^{2}+iu\gamma /(2\pi )}$$, r0 denotes the initial radial position of the particle and Iν is the modified Bessel function of the first kind, of order ν.

A detailed examination of this probability distribution reveals that it is strongly non-Gaussian. Indeed, for positive winding numbers p(n, tr0) is asymptotically scale free: p(n, tr0) $$\mathop{\sim}\limits_{{n}\,{{{{\rightarrow}}}}+\infty}$$n−3/253 (see Fig. 2a), while, as a consequence of the fluctuation theorem (3), it decays exponentially as n → − . This difference in scaling behaviors results in a strong asymmetry of the overall distribution between the positive and negative winding number sectors (see Fig. 2b).

### Computational verification of the theorem

For more complicated force profiles, solving the Fokker–Planck equation may not be possible, and one needs to resort to Brownian dynamics simulations. Below we address two such non-trivial cases in order to illustrate the quantization of the medium entropy production in presence of an external potential, as well as the application of the theorem to the multi-vortex case.

As the data shown in Fig. 2b suggests, a numerical verification of the theorem in free space would be very demanding due to the need for excessive sampling. On the contrary, constraining the stochastic trajectories inside a finite volume with an externally applied potential U(r) significantly speeds up the winding number statistics convergence. In practice, however, such confinement also imposes to make sure that stochastic trajectories cannot reach the vortex cores where the winding angle is ill-defined; which we achieve by means of a stiff potential barrier (see Methods for details about numerical simulations). For simplicity, we moreover consider the case of an effectively two-dimensional vortex force such that all vortex lines are along the third spatial direction, as described by Eq. (11). For such force fields, the dissipated heat (7) reads

$${{\Gamma }}=\mathop{\sum }\limits_{i=1}^{m}\frac{{\gamma }_{i}{{\Delta }}{\phi }_{i}}{2\pi }-\frac{{{\Delta }}U}{{k}_{{{{{{{{\rm{B}}}}}}}}}T}\,,$$
(13)

where, as before, γi denotes the ith vortex strength, while Δϕi and ΔU are the corresponding total winding angle and potential energy difference between the final and initial positions. Note that Eq. (13) holds irrespectively of the observation time, such that the numerical verification of the theorem can be carried out either looking at finite time distributions, or after time averaging at fixed initial conditions.

### Quantization of the medium entropy production

We first discuss the quantization of the medium entropy production for closed trajectories as predicted by Eqs. (2) and (7) in a configuration where the Brownian particle is harmonically trapped, namely for which

$$U(x,y,z)=\frac{k}{2}\left[{(x-{x}_{c})}^{2}+{\alpha }^{-2}{y}^{2}+{z}^{2}\right],$$

where (x, y, z) denote the cartesian coordinates of r, while the parameter α introduces anisotropy in the confinement and the position of the potential minimum can be shifted along x by varying xc. In an experiment, U would, e.g., model the confinement operated on a colloidal particle by optical tweezers.

From Eq. (13), the dissipated heat only depends on the total winding angle around the vortex and the potential difference between both ends of the trajectories. It is thus enlightening to consider the probability ratio

$$\vartheta ({{\Delta }}\phi ,{{\Delta }}{{{{{{{\bf{r}}}}}}}},t| {{{{{{{{\bf{r}}}}}}}}}_{0})\equiv \frac{p(-{{\Delta }}\phi ,-{{\Delta }}{{{{{{{\bf{r}}}}}}}},t| {{{{{{{{\bf{r}}}}}}}}}_{0}+{{\Delta }}{{{{{{{\bf{r}}}}}}}})}{p({{\Delta }}\phi ,{{\Delta }}{{{{{{{\bf{r}}}}}}}},t| {{{{{{{{\bf{r}}}}}}}}}_{0})}={e}^{-{{\Gamma }}},$$
(14)

where pϕ, Δr, tr0) denotes the joint probability of total winding angle Δϕ and difference between initial and final positions Δr for a trajectory of length t given an initial condition r0. Naturally, setting Δr = 0 (closed trajectories) leads to Δϕ = 2πn and vanishing ΔU, such that the theorem (8) is readily recovered.

Let us now consider trajectories for which the initial and final points share the same radial and axial coordinates: Δr = Δz = 0, while the total winding angle Δϕ remains arbitrary. In case I where the potential is isotropic (α = 1) and its ground state coincides with the vortex core (xc = 0), ΔU is independent of the winding angle Δϕ such that the probability ratio ϑ averaged over trajectory time and initial positions follows the predicted exponential scaling for all winding angles (see orange line in Fig. 2f). In general, however, Γ is affected by the symmetries of the trap such that ϑ does not decay exponentially with the winding angle Δϕ. Setting α ≠ 1 (case II, Fig. 2d), ΔU depends explicitly on Δϕ and vanishes only for Δϕ = nπ. Consequently, the averaged winding angle probability ratio departs from the exponential scaling for all Δϕ not multiple of π (see red line in Fig. 2f). Moreover, in the third case of an isotropic harmonic potential, but whose minimum is shifted of xc ≠ 0 (Fig. 2e), the winding angle probability ratio shows similar oscillations as in case II, except that due to the lack of reflection symmetry of U those are 2π-periodic (blue line in Fig. 2f). In all cases, thanks to the topological protection offered by closed loops the data shown in Fig. 2f systematically falls on the predicted exponential curve for Δϕ integer factor of 2π.

### The multi-vortex case

To simplify the following analysis and allow for the study of fixed time trajectories, we now consider the case where the potential U(r) acts as a stiff wall confining the particles inside a cylinder of radius R and such that U = 0 inside of the cylinder. For such confinement and a single vortex line located at r = 0, we find that for tR2/D the distribution p(ϕ, t) exhibits exponential tails, while for tR2/D the effect of confining boundaries leads to p(ϕ, t) being Gaussian (see Fig 2c). As expected from Eq. (13), in this case one can set ΔU = 0 and the fluctuation theorem is found to hold at winding angles for all observation times, independently of the particular shape of the distribution.

We now address the multi-vortex case considering a configuration of four counter rotating vortices of strengths ± Q in a closed domain of radius R, all located at r = R/2 and 90 degrees from each other, as depicted in Fig. 1d, except that for simplicity the particle motion in simulations is restricted to two dimensions.

To be able to sample winding number distributions with sufficiently accurate statistics, we define the joint probability p({ϕ+, ϕ}, t) of total winding angles ϕ+ and ϕ around, respectively, counter-clockwise (CCW) and clockwise (CW) rotating vortices. The distribution, shown in Fig. 3a, exhibits a non-trivial, time-invariant, 2π-periodic structure. In particular, while p({ϕ+, ϕ}, t) shows local maxima when both ϕ+ and ϕ are integer factors of 2π, it vanishes up to numerical precision when both of them are odd integer factors of π. Despite this complex behavior, representing the ratio p({−ϕ+, −ϕ}, t)/p({ϕ+, ϕ}, t) as a function of γ(ϕ+ −ϕ) reveals a clear exponential scaling at all accessible times (see Fig. 3b), in agreement with Eq. (9).

We now examine the total entropy production distribution p(Γ, t). Figure 3c shows that although it exhibits a Gaussian envelope, it features prominent modulations that can not be described in terms of simple functions. Nevertheless, the ratio p( − Γ, t)/p(Γ, t) always verifies Eq. (10) at all times and for all winding angle configurations (see Fig. 3d).

Lastly, our Brownian dynamics simulations allow us to record the individual winding distributions p±(ϕ, t) associated with CCW(+) and CW(−) rotating vortices. As shown in Fig. 3e, the two distributions show smooth damped oscillations and are symmetric with respect to each other. Examining the ratios p±( − ϕ, t)/p±(ϕ, t), we find that they do not satisfy the theorem. Namely, we find in both cases that the probability ratio of winding oppositely to the direction set by the vortex flow to that of winding along it is always larger than predicted by the theorem (see Fig. 3f). This striking feature is a direct consequence of the fact that in presence of many vortices, trajectories winding with an angle ϕ around a given vortex are not all topologically equivalent.

### Towards a description of emergent topological phases

It would be interesting to connect the fluctuation theorem (8) to the topologically protected edge currents found in a variety of condensed matter systems driven out of equilibrium13,15,16,17,18,19,20,25. Although in depth treatment of this problem, in particular the formulation of a counterpart of (8) for field theories describing emergent features of many body systems (see refs. 54,55,56,57 for relevant references), lies outside of the scope of this work, here we outline a possible avenue to tackle it in non-equilibrium Markov networks.

In this part, we consider the minimal model introduced and studied in ref. 20, which consists of a two-dimensional on-lattice dynamics made of repeating motifs playing the role of non-equilibrium cycles in some abstract space (conformation, chemical, etc...). We moreover restrict the study to a square lattice as represented in Fig. 4 such that to each motif, or lattice site, are associated four internal states labeled from A to D. The following results nevertheless remain easily generalizable to other types of lattices, and we show in the SM that similar conclusions can be reached from the study of an analogous one-dimensional model.

The lattice model sketched in Fig. 4 involves two kinds of transitions, respectively, referred to as “internal” and “external”, respectively, between internal states (A–D) at each site or between neighboring sites. We denote γext and γin the associated clockwise external and counter-clockwise internal rates, while the reverse transition rates are written with primes. The possible moves from a lattice site at position (x, y) are thus:

$$\begin{array}{ccc}{(x,y)}_{{{{{{{{\rm{D}}}}}}}}}&\rightleftarrows &{(x,y)}_{{{{{{{{\rm{A}}}}}}}}}\\ \uparrow \downarrow &{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{({\prime} )}& \uparrow \downarrow \\ {(x,y)}_{{{{{{{{\rm{C}}}}}}}}}&\rightleftarrows &{(x,y)}_{{{{{{{{\rm{B}}}}}}}}}\end{array}; \begin{array}{ccc}{(x,y+a)}_{{{{{{{{\rm{B}}}}}}}}}& \rightleftarrows & {(x+a,y+a)}_{{{{{{{{\rm{C}}}}}}}}}\\ \uparrow \downarrow&{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{({\prime} )}&\uparrow \downarrow\\ {(x,y)}_{{{{{{{{\rm{A}}}}}}}}}& \rightleftarrows & {(x+a,y)}_{{{{{{{{\rm{D}}}}}}}}}\end{array}$$

with a denoting the lattice step. In ref. 20 it was found that for chiral systems (e.g. $${\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{\prime}\ll {\gamma }_{{{{{{{{\rm{ext}}}}}}}}}$$, $${\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{\prime}\ll {\gamma }_{{{{{{{{\rm{in}}}}}}}}}$$) and fast external rates (γextγin) this dynamics leads to topologically protected chiral modes localized at the edge of the simulation domain.

Using a systematic coarse-graining approach, we derive the Fokker–Planck equation describing the effective dynamics of the total density ρ ≡ ρA + ρB + ρC + ρD:

$${\partial }_{t}\rho =-{\partial }_{\alpha }\left[{v}_{\alpha }\rho -{\partial }_{\beta }\left({D}_{\alpha \beta }\rho \right)\right],$$
(15)

where Einstein summation over repeated indices is implied. The derivation of Eq. (15) for the fully chiral case is presented in Methods, while the longer version accounting for reversed transitions can be found in the SM. The effective drift v and diffusivity D are non-trivial functions of the rates $${\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{({\prime} )}$$ and $${\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{({\prime} )}$$, and their general expressions are given in Methods. We find that the bulk dynamics is essentially diffusive with $${v}_{\alpha }^{{{{{{{{\rm{bulk}}}}}}}}}=0$$ and $${D}_{\alpha \beta }^{{{{{{{{\rm{bulk}}}}}}}}}={D}_{{{{{{{{\rm{b}}}}}}}}}{\delta }_{\alpha \beta }$$. At the system’s boundaries, however, vedge = ve is non-zero and Dedge = Dee + Dee, where the unit vector e is orthogonal to the boundaries and points inside the system, while e is obtained from e by a $$-\frac{\pi }{2}$$ rotation (see Fig. 4).

Moreover, our derivation leads to conclude that the density ρ takes distinct values in the bulk and at the edges of the system. Namely, we find in the limit $${\gamma }_{{{{{{{{\rm{in}}}}}}}}},{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{\prime}\ll {\gamma }_{{{{{{{{\rm{ext}}}}}}}}},{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{\prime}$$ of interest that

$$\frac{{\rho }^{{{{{{{{\rm{edge}}}}}}}}}}{{\rho }^{{{{{{{{\rm{bulk}}}}}}}}}}\simeq 1+\frac{1}{4}\frac{(1-{\zeta }_{{{{{{{{\rm{in}}}}}}}}})(1-{\zeta }_{{{{{{{{\rm{ext}}}}}}}}})}{{\zeta }_{{{{{{{{\rm{ext}}}}}}}}}+{\zeta }_{{{{{{{{\rm{in}}}}}}}}}},$$
(16)

where we have introduced the ratios $${\zeta }_{{{{{{{{\rm{in}}}}}}}}}\equiv {\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{\prime}/{\gamma }_{{{{{{{{\rm{in}}}}}}}}}$$ and $${\zeta }_{{{{{{{{\rm{ext}}}}}}}}}\equiv {\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{\prime}/{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}$$. For fully chiral rates corresponding to small or large values of the ratios ζin and ζext, it appears clearly from Eq. (16) that most of the density is concentrated at the boundaries. Namely, in this limit ρ is found to decay from ρedge to ρbulk exponentially with a penetration depth a20. Considering without loss of generality both ζin 1 and ζext 1, the effective drift at the edges simplifies at leading order as vγina, while the bulk and edge diffusivities are given by

$${D}_{{{{{{{{\rm{b}}}}}}}}}\simeq \frac{{\gamma }_{{{{{{{{\rm{in}}}}}}}}}{a}^{2}}{4},\quad \frac{{D}_{\parallel }}{2{D}_{{{{{{{{\rm{b}}}}}}}}}}\simeq 9{\zeta }_{{{{{{{{\rm{ext}}}}}}}}}+{\zeta }_{{{{{{{{\rm{in}}}}}}}}},\quad \frac{{D}_{\perp }}{2{D}_{{{{{{{{\rm{b}}}}}}}}}}\simeq {\zeta }_{{{{{{{{\rm{ext}}}}}}}}}+{\zeta }_{{{{{{{{\rm{in}}}}}}}}}.$$

Thus, as the system is brought to the fully chiral limit its bulk is depleted and its edges retain most of the probability density. The global dynamics is essentially one-dimensional with chiral currents traveling along the borders with mean speed v > 0 and vanishing fluctuations strength D.

In this context, we can apply the fluctuation theorem to this problem considering closed trajectories following the boundary of the system. We then obtain for the winding number probability ratio

$$\frac{p(-n,t)}{p(n,t)}\simeq \exp \left(-\frac{2{N}_{{{{{{{{\rm{edge}}}}}}}}}}{9{\zeta }_{{{{{{{{\rm{ext}}}}}}}}}+{\zeta }_{{{{{{{{\rm{in}}}}}}}}}}n\right),$$
(17)

with Nedge denoting the total number of lattice sites at the edge and where n here corresponds to the number of times the trajectory has wound around the system. Equation (17) shows that the ratio of clockwise to counter-clockwise flux probabilities is topologically protected as it does not depend explicitly on the shape of the system boundary. However, it depends on the total perimeter as the transition rates $${\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{({\prime} )}$$ and $${\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{({\prime} )}$$ were assumed constant. We finally note that Eq. (17) was formally obtained in the limits ζext 1 and ζin 1. Thus and since the ratio in the exponential involves a factor that scales with the system size, computational or experimental verification of Eq. (17) might be challenging in practice.

## Discussion

We have demonstrated a topological fluctuation theorem that identifies a relevant topological invariant able to predict observable quantities, in a strongly fluctuating system without underlying periodic structure. The ratio of particle trajectories going against the flow to those going along it is purely a function of heat generated along the vortices and is topologically protected against deformations of these trajectories. Thanks to this property, the theorem holds for any finite observation time and is insensitive to conservative contributions to the force-field such as a confining potential, which makes it generic and observable in realistic experimental conditions.

In the context of micro-machines, where some degrees of freedom are driven out-of-equilibrium by external forces and torques that are even under time-reversal, the fluctuation theorem constrains the probability ratio of negative and positive entropy production created over cycles performed by the machine. Remarkably, the theorem predicts that this ratio is topologically protected for closed cycles in phase space, as discussed recently for the one-dimensional case in ref. 58, thus providing some insight for the optimization and design of micro-machines.

Finally, it will be interesting to investigate how the above results generalize with the introduction of non-equilibrium activity, be it as a correlated bath or as persistence in the particle motion59.

## Methods

### Detailed derivation of the topological fluctuation theorem

For closed trajectories of total duration t, the winding number distribution is defined up to a normalizing constant as $$p(n,t)\propto \int {{{{{{{\rm{d}}}}}}}}{{{{{{{{\bf{x}}}}}}}}}_{0}\pi ({{{{{{{{\bf{x}}}}}}}}}_{0}){\oint }_{{{{{{{{{\bf{x}}}}}}}}}_{0}}{{{{{{{\mathcal{D}}}}}}}}{{{{{{{\bf{r}}}}}}}}(\tau )P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]\delta ({{\Gamma }}-\gamma n)$$, with π(x0) the distribution of initial positions x0. Using the same convention as in the main text that + n windings correspond to trajectories evolving forward in time, we thus write

$$p(-n,t)\propto \int {{{{{{{\rm{d}}}}}}}}{{{{{{{{\bf{x}}}}}}}}}_{0}\pi ({{{{{{{{\bf{x}}}}}}}}}_{0})\oint _{{{{{{{{{\bf{x}}}}}}}}}_{0}}{{{{{{{\mathcal{D}}}}}}}}\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )P[\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]\delta (\tilde{{{\Gamma }}}+\gamma n)\\ \propto \int {{{{{{{\rm{d}}}}}}}}{{{{{{{{\bf{x}}}}}}}}}_{0}\pi ({{{{{{{{\bf{x}}}}}}}}}_{0})\oint _{{{{{{{{{\bf{x}}}}}}}}}_{0}}{{{{{{{\mathcal{D}}}}}}}}\tilde{{{{{{{{\bf{r}}}}}}}}}(\tau )P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]{e}^{-{{\Gamma }}}\delta (\tilde{{{\Gamma }}}+\gamma n)\\ \propto \int {{{{{{{\rm{d}}}}}}}}{{{{{{{{\bf{x}}}}}}}}}_{0}\pi ({{{{{{{{\bf{x}}}}}}}}}_{0})\oint _{{{{{{{{{\bf{x}}}}}}}}}_{0}}{{{{{{{\mathcal{D}}}}}}}}{{{{{{{\bf{r}}}}}}}}(\tau )P[{{{{{{{\bf{r}}}}}}}}(\tau )| {{{{{{{{\bf{x}}}}}}}}}_{0}]{e}^{-{{\Gamma }}}\delta ({{\Gamma }}-\gamma n)\\ = \,p(n,t){e}^{-\gamma n},$$

where the first equality makes use of Eq. (6), while the second equality is obtained noting that the total circulation is odd under time reversal ($$\tilde{{{\Gamma }}}=-{{\Gamma }}$$) and that integrating over forward and time-reversed trajectories is equivalent42. Finally, the the last equality derives from the relation Γ = γn valid when the rotational component of the force field satisfies Eq. (2).

### Brownian dynamics simulations

Here, we provide the details of the Langevin dynamics simulations. Denoting r(τ) the particle position at time τ, which is discretized in units of dτ, it is updated by means of an Euler–Maruyama scheme:

$${{{{{{{\bf{r}}}}}}}}(\tau +{{{{{{{\rm{d}}}}}}}}\tau )-{{{{{{{\bf{r}}}}}}}}(\tau )=\mu \left[{{{{{{{\bf{f}}}}}}}}({{{{{{{\bf{r}}}}}}}}(\tau ))-\nabla U({{{{{{{\bf{r}}}}}}}}(\tau ))\right]{{{{{{{\rm{d}}}}}}}}\tau +\sqrt{2D{{{{{{{\rm{d}}}}}}}}\tau }\,{{{{{{{\boldsymbol{\xi }}}}}}}}(\tau ),$$
(18)

where f(r) denotes the applied vortex field, μ is the mobility of the particle, U is a confining potential, and ξ is a Gaussian white noise vector with unit variance.

For the multi-vortex study, the potential U was chosen to ensure that all trajectories are confined inside a cylinder of radius R, and that they cannot reach the vortex centers where the winding angles are not defined. Namely, we used the following form for the potential

$$U({{{{{{{\bf{r}}}}}}}})=\frac{k}{2}\times \left\{\begin{array}{cc}{(| {{{{{{{\bf{r}}}}}}}}| -R)}^{2}&| {{{{{{{\bf{r}}}}}}}}| \ge R\\ {(| {{{{{{{\bf{r}}}}}}}}-{{{{{{{{\bf{r}}}}}}}}}_{i}| -{R}_{* })}^{2}&| {{{{{{{\bf{r}}}}}}}}-{{{{{{{{\bf{r}}}}}}}}}_{i}| \le {R}_{* }\\ 0&{{{{{{{\rm{otherwise}}}}}}}}\end{array}\right.\,.$$
(19)

When the length-scale $$\ell \equiv \sqrt{{k}_{{{{{{{{\rm{B}}}}}}}}}T/k}$$ is small compared to R* and R, the trajectories do not penetrate the limiting regions with r > R and r − ri < R* (see Fig. 5), such that ΔU in Eq. (13) can be set to 0.

Rescaling space and time in Eq. (18), we set D = 1 and μk = 103. With these units, we used in all simulations γ = 0.1 × 2π, dt/(μk) = 10−5, $$R/\ell =1{0}^{3}\sqrt{10}$$, and $${R}_{* }/\ell =50\sqrt{10}$$. We have verified that varying moderately these parameters did not affect our results. Both the data shown in Figs. 2 and 3 were obtained by sampling the winding distributions over 106 to 108 independent trajectories with uniform initial conditions.

### The two-dimensional lattice model with out-of-equilibrium cycles

Here we detail the coarse-graining of the non-equilibrium lattice model described in the text and pictured in Fig. 4. As it involves less lengthy expressions, we restrict here to fully chiral rates ($${\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{\prime}={\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{\prime}=0$$) while for completeness the derivation for the general case is presented in the SM.

#### The bulk dynamics

We first investigate the behavior of the system far from any boundary. Assuming an infinite system or periodic boundary conditions, the dynamics each state density can be written in the following compact form

$${\partial }_{t}{\rho }_{\sigma (i)}({{{{{{{\bf{x}}}}}}}},t)={\gamma }_{{{{{{{{\rm{ext}}}}}}}}}\left[{\rho }_{\sigma (i-1)}({{{{{{{\bf{x}}}}}}}}+{{\Delta }}{{{{{{{{\bf{x}}}}}}}}}_{i},t)-{\rho }_{\sigma (i)}({{{{{{{\bf{x}}}}}}}},t)\right]+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}\left[{\rho }_{\sigma (i+1)}({{{{{{{\bf{x}}}}}}}},t)-{\rho }_{\sigma (i)}({{{{{{{\bf{x}}}}}}}},t)\right],$$
(20)

where σ is the 4-periodic map of i {0, . . . , 3} to {A, . . . , D}, x = xex + yey and $${{\Delta }}{{{{{{{{\bf{x}}}}}}}}}_{i}=a{{{{{{{\mathcal{R}}}}}}}}(-\frac{i\pi }{2}){{{{{{{{\bf{e}}}}}}}}}_{x}$$ where the operator $${{{{{{{\mathcal{R}}}}}}}}(\theta )$$ rotates vectors in the plane by an angle θ. We now use the fact that to Eq. (20) only corresponds one conserved quantity: the total bulk density $${\rho }_{{{{{{{{\rm{b}}}}}}}}}=\frac{1}{4}({\rho }_{{{{{{{{\rm{A}}}}}}}}}+{\rho }_{{{{{{{{\rm{B}}}}}}}}}+{\rho }_{{{{{{{{\rm{C}}}}}}}}}+{\rho }_{{{{{{{{\rm{D}}}}}}}}})$$. To complete the set of fields, we moreover define three additional auxiliary fields:

$$\begin{array}{rcl}&&{\rho }_{1}\equiv \frac{1}{4}\left({\rho }_{{{{{{{{\rm{A}}}}}}}}}-{\rho }_{{{{{{{{\rm{B}}}}}}}}}+{\rho }_{{{{{{{{\rm{C}}}}}}}}}-{\rho }_{{{{{{{{\rm{D}}}}}}}}}\right),\\ &&{\rho }_{2}\equiv \frac{1}{4}\left({\rho }_{{{{{{{{\rm{A}}}}}}}}}+{\rho }_{{{{{{{{\rm{B}}}}}}}}}-{\rho }_{{{{{{{{\rm{C}}}}}}}}}-{\rho }_{{{{{{{{\rm{D}}}}}}}}}\right),\\ &&{\rho }_{3}\equiv \frac{1}{4}\left({\rho }_{{{{{{{{\rm{A}}}}}}}}}-{\rho }_{{{{{{{{\rm{B}}}}}}}}}-{\rho }_{{{{{{{{\rm{C}}}}}}}}}+{\rho }_{{{{{{{{\rm{D}}}}}}}}}\right).\end{array}$$

After straightforward algebra, the set of equations given by Eq. (20) for i = 0, . . . , 3 is then recast up to second order in a as

$${\partial }_{t}{\rho }_{{{{{{{{\rm{b}}}}}}}}}=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{2}\left[\frac{{a}^{2}}{2}{{\Delta }}{\rho }_{{{{{{{{\rm{b}}}}}}}}}-\frac{{a}^{2}}{2}{{{{{{{\mathcal{D}}}}}}}}{\rho }_{1}-a\partial {\rho }_{2}+a\bar{\partial }{\rho }_{3}\right],$$
(21a)
$${\partial }_{t}{\rho }_{1}=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{2}\left[\frac{{a}^{2}}{2}{{{{{{{\mathcal{D}}}}}}}}{\rho }_{{{{{{{{\rm{b}}}}}}}}}-\frac{{a}^{2}}{2}{{\Delta }}{\rho }_{1}-a\bar{\partial }{\rho }_{2}+a\partial {\rho }_{3}\right]-2\bar{\gamma }{\rho }_{1},$$
(21b)
$${\partial }_{t}{\rho }_{2}=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{2}\left[a\bar{\partial }{\rho }_{{{{{{{{\rm{b}}}}}}}}}-a\partial {\rho }_{1}-\frac{{a}^{2}}{2}{{{{{{{\mathcal{D}}}}}}}}{\rho }_{2}+\frac{{a}^{2}}{2}{{\Delta }}{\rho }_{3}\right]-\bar{\gamma }{\rho }_{2}+{{\Delta }}\gamma {\rho }_{3},$$
(21c)
$${\partial }_{t}{\rho }_{3}=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{2}\left[a\partial {\rho }_{{{{{{{{\rm{b}}}}}}}}}-a\bar{\partial }{\rho }_{1}-\frac{{a}^{2}}{2}{{\Delta }}{\rho }_{2}+\frac{{a}^{2}}{2}{{{{{{{\mathcal{D}}}}}}}}{\rho }_{3}\right]-\bar{\gamma }{\rho }_{3}-{{\Delta }}\gamma {\rho }_{2},$$
(21d)

where we have defined the operators

$$\partial \equiv {\partial }_{x}+{\partial }_{y},\quad\bar{\partial }\equiv {\partial }_{x}-{\partial }_{y},\quad{{\Delta }}\equiv {\partial }_{xx}^{2}+{\partial }_{yy}^{2},\quad{{{{{{{\mathcal{D}}}}}}}}\equiv {\partial }_{xx}^{2}-{\partial }_{yy}^{2},$$

while $$\bar{\gamma }\equiv {\gamma }_{{{{{{{{\rm{ext}}}}}}}}}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}$$ and Δγ ≡ γext − γin.

Since the total bulk density ρb is the only slow field, we now enslave ρ1,2,3 keeping terms up to second order in a. A quick inspection of the rhs of Eq. (21a) indicates that ρ1 should be expressed at zeroth order in a, while the expressions of ρ2 and ρ3 should include terms up to order a. However, we find from Eq. (21b) that setting ∂tρ1 = 0 the resulting solution for ρ1 is at least of order a, such that the ρ1 terms contribute to orders a3 and a2 in the equations for ρb and ρ2,3, respectively. We thus neglect these terms in what follows.

Setting ∂tρ2 = ∂tρ3 = 0, we end up with

$$\left(\begin{array}{cc}\bar{\gamma }&-{{\Delta }}\gamma \\ {{\Delta }}\gamma &\bar{\gamma }\end{array}\right)\left(\begin{array}{c}{\rho }_{2}\\ {\rho }_{3}\end{array}\right)=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}a}{2}\left(\begin{array}{c}\bar{\partial }\\ \partial \end{array}\right){\rho }_{{{{{{{{\rm{b}}}}}}}}}+{{{{{{{\mathcal{O}}}}}}}}({a}^{2}).$$
(22)

Inverting the 2 × 2 matrix on the lhs, we finally get

$$\left(\begin{array}{c}{\rho }_{2}\\ {\rho }_{3}\end{array}\right)=\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}a}{2({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{2}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2})}\left(\begin{array}{c}{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\partial }_{x}-{\gamma }_{{{{{{{{\rm{in}}}}}}}}}{\partial }_{y}\\ {\gamma }_{{{{{{{{\rm{in}}}}}}}}}{\partial }_{x}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\partial }_{y}\end{array}\right){\rho }_{{{{{{{{\rm{b}}}}}}}}}+{{{{{{{\mathcal{O}}}}}}}}({a}^{2}).$$
(23)

Replacing these expressions in Eq. (21a), we find that the bulk density dynamics simply amounts to isotropic diffusion:

$${\partial }_{t}{\rho }_{{{{{{{{\rm{b}}}}}}}}}={D}_{{{{{{{{\rm{b}}}}}}}}}{{\Delta }}{\rho }_{{{{{{{{\rm{b}}}}}}}}},\qquad \,{{\mbox{with}}}\,\quad {D}_{{{{{{{{\rm{b}}}}}}}}}\equiv \frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}){a}^{2}}{4({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{2}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2})}.$$
(24)

Here, we note that the bulk diffusivity is symmetric by exchange of γext ↔ γin and is essentially controlled by the smallest transition rate, as

$${D}_{{{{{{{{\rm{b}}}}}}}}} \mathop{\sim}_{ {\gamma }_{{{{{{{{\rm{ext}}}}}}}}}\gg {\gamma }_{{{{{{{{\rm{in}}}}}}}}}}\frac{{\gamma }_{{{{{{{{\rm{in}}}}}}}}}{a}^{2}}{4},\qquad {{{{{{{\rm{and}}}}}}}}\qquad {D}_{{{{{{{{\rm{b}}}}}}}}} \mathop{\sim}_{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}\ll {\gamma }_{{{{{{{{\rm{in}}}}}}}}}}\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{a}^{2}}{4}.$$

#### The dynamics near boundaries

It was discovered in ref. 20 that when considered in a finite volume, the lattice model dynamics is dominated by the effect of boundaries. Namely, the model shows persistent chiral modes localized at its edges. Here, we consider an effective description where the system boundary in contact with an homogeneous bulk whose density satisfies Eq. (24). Considering without loss of generality the bottom boundary (see Fig. 4 for a schematic) such that external transitions to B and from C are suppressed, we have

$${\partial }_{t}{\rho }_{{{{{{{{\rm{B}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)=-{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\rho }_{{{{{{{{\rm{B}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}\left[{\rho }_{{{{{{{{\rm{C}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)-{\rho }_{{{{{{{{\rm{B}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)\right],$$
(25a)
$${\partial }_{t}{\rho }_{{{{{{{{\rm{C}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)={\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\rho }_{{{{{{{{\rm{B}}}}}}}}}({{{{{{{\bf{x}}}}}}}}+{{\Delta }}{{{{{{{{\bf{x}}}}}}}}}_{2},t)+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}\left[{\rho }_{{{{{{{{\rm{b}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)-{\rho }_{{{{{{{{\rm{C}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)\right],$$
(25b)
$${\partial }_{t}{\rho }_{{{{{{{{\rm{b}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)={D}_{{{{{{{{\rm{b}}}}}}}}}{{\Delta }}{\rho }_{{{{{{{{\rm{b}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)+\frac{{\gamma }_{{{{{{{{\rm{in}}}}}}}}}}{2}\left[{\rho }_{{{{{{{{\rm{B}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)-{\rho }_{{{{{{{{\rm{b}}}}}}}}}({{{{{{{\bf{x}}}}}}}},t)\right],$$
(25c)

where ρb here accounts effectively the states A and D close to the boundary. As before, we now define

$${\rho }_{{{{{{{{\rm{e}}}}}}}}}\equiv \,\frac{1}{4}\left(2{\rho }_{{{{{{{{\rm{b}}}}}}}}}+{\rho }_{{{{{{{{\rm{B}}}}}}}}}+{\rho }_{{{{{{{{\rm{C}}}}}}}}}\right),\\ {\rho }_{1}^{\prime}\equiv \,\frac{1}{4}\left(2{\rho }_{{{{{{{{\rm{b}}}}}}}}}+{\rho }_{{{{{{{{\rm{B}}}}}}}}}-{\rho }_{{{{{{{{\rm{C}}}}}}}}}\right),\\ {\rho }_{2}^{\prime}\equiv \,\frac{1}{4}\left(2{\rho }_{{{{{{{{\rm{b}}}}}}}}}-{\rho }_{{{{{{{{\rm{B}}}}}}}}}+{\rho }_{{{{{{{{\rm{C}}}}}}}}}\right).$$

Carrying out a similar calculation as for the bulk dynamics, we find that ρe is the only conserved field such that $${\rho }_{1,2}^{\prime}$$ can be enslaved to it. Solving the resulting equations for $${\rho }_{1,2}^{\prime}$$, we get

$${\rho }_{1}^{\prime}=\frac{2{\gamma }_{{{{{{{{\rm{in}}}}}}}}}-{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{\rho }_{{{{{{{{\rm{e}}}}}}}}}+\frac{3a{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}}{{(4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}})}^{2}}{\partial }_{x}{\rho }_{{{{{{{{\rm{e}}}}}}}}}+{{{{{{{\mathcal{O}}}}}}}}({a}^{2}),$$
(26a)
$${\rho }_{2}^{\prime}=\frac{2{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}}{\rho }_{{{{{{{{\rm{e}}}}}}}}}-\frac{a{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}}{{(4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}})}^{2}}{\partial }_{x}{\rho }_{{{{{{{{\rm{e}}}}}}}}}+{{{{{{{\mathcal{O}}}}}}}}({a}^{2}).$$
(26b)

Replacing these expressions into that of ρe, we finally obtain

$${\partial }_{t}{\rho }_{{{{{{{{\rm{e}}}}}}}}}=-{v}_{\parallel }{\partial }_{x}{\rho }_{{{{{{{{\rm{e}}}}}}}}}+{D}_{\parallel }{\partial }_{xx}^{2}{\rho }_{{{{{{{{\rm{e}}}}}}}}}+{D}_{\perp }{\partial }_{yy}^{2}{\rho }_{{{{{{{{\rm{e}}}}}}}}},$$
(27)

with the coefficients

$${v}_{\parallel }\equiv \,\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}a}{4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}},\\ {D}_{\parallel }\equiv \,\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2}(5{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}})+8{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2})}{2{(4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}})}^{2}({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{2}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2})}{a}^{2},\\ {D}_{\perp }\equiv \,\frac{{\gamma }_{{{{{{{{\rm{ext}}}}}}}}}{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2}({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}})}{2(4{\gamma }_{{{{{{{{\rm{in}}}}}}}}}+{\gamma }_{{{{{{{{\rm{ext}}}}}}}}})({\gamma }_{{{{{{{{\rm{ext}}}}}}}}}^{2}+{\gamma }_{{{{{{{{\rm{in}}}}}}}}}^{2})}{a}^{2}.$$

Finally, for a general boundary defined by the unit vectors e and e, respectively, tangent and orthogonal to the boundary, where e always points inside the system and $${{{{{{{{\bf{e}}}}}}}}}_{\perp }={{{{{{{\mathcal{R}}}}}}}}(\frac{\pi }{2}){{{{{{{{\bf{e}}}}}}}}}_{\parallel }$$, Eq. (27) is rewritten in a more general form as

$${\partial }_{t}{\rho }_{{{{{{{{\rm{e}}}}}}}}}=-\nabla \cdot \left({v}_{\parallel }{{{{{{{{\bf{e}}}}}}}}}_{\parallel }{\rho }_{{{{{{{{\rm{e}}}}}}}}}\right)+\nabla \nabla :\left({{{{{{{\bf{D}}}}}}}}{\rho }_{{{{{{{{\rm{e}}}}}}}}}\right),$$
(28)

with the Frobenius norm defined as $${{{{{{{\bf{A}}}}}}}}:{{{{{{{\bf{B}}}}}}}}={{{{{{{\rm{Tr}}}}}}}}({{{{{{{\bf{A}}}}}}}}{{{{{{{\bf{B}}}}}}}})$$ and D ≡ Dee + Dee.