We develop an algorithm based on the method proposed by Dickman for directly measuring pressure in lattice-gas models. The algorithm gives the possibility to access the equation of state with a single run by adding multiple ghost sites to the original system. This feature considerably improves calculations and makes the algorithm particularly efficient for systems with inhomogeneous density profiles, both in equilibrium and nonequilibrium steady states. We illustrate its broad applicability by considering some paradigmatic systems of statistical mechanics such as the lattice gas under gravity, nearest-neighbor exclusion models in finite dimension and on regular random graphs, and the boundary-driven simple symmetric exclusion process.

## INTRODUCTION

Pressure is a key thermodynamic parameter encoding the phase behavior of macroscopic systems in thermal equilibrium.^{1} As first realized by Tammann long ago,^{2,3} for systems with many degrees of freedom, the pressure behavior may not be as a simple as a mechanical interpretation would suggest. This is essentially due to the entropic contribution coming from the integral (or the sum) over the whole configuration space, which is at the root of several unusual and counter-intuitive phenomena, such as inverse melting.^{4–6} There is also a fundamental interest in extending the notion of pressure to active matter, a crucial step toward the formulation of a nonequilibrium statistical mechanics.^{7} It is therefore of paramount importance to rely on flexible and viable algorithms that are capable of measuring the pressure directly, with no reference to a special state as in the standard thermodynamic integration method. This is all the more true for (athermal) lattice systems where Monte Carlo algorithms are far less developed than their molecular dynamics counterpart.^{8,9} Previously proposed methods generally sacrifice the usual periodic boundary as they involve hard walls and volume fluctuations due to the removal or addition of a layer next to the wall.^{10} We consider here an elegant proposed some time ago by Dickman in the context of lattice polymers,^{11,12} which bears a strong resemblance with the ghost particle insertion trick suggested by Widom for computing the chemical potential.^{13} The Dickman method consists of three simple yet important observations. First, for a lattice gas with volume *V* and Helmholtz free energy *F*, the pressure *P* = −*∂F*/*∂V* is written as

where *Z* is the canonical partition function. Then, one observes that the partition function of a system with volume *V* is equivalent to that of a modified system with volume *V* + Δ*V* in which one has added an infinite repulsive potential acting on the sites contained in Δ*V* (preventing particles from entering Δ*V*). Thus, if we introduce a repulsive potential of finite magnitude *U*_{λ} = −*k*_{B}*T* ln *λ* acting on the sites in Δ*V* (in such a way that *λ* = 0 corresponds to *U* = ∞, and *λ* = 1 corresponds to *U* = 0) and denote with *Z*_{λ} the partition function of this modified system, we get *Z*(*V*) ≡ *Z*_{0}(*V* + Δ*V*) and *Z*(*V* + Δ*V*) ≡ *Z*_{1}(*V* + Δ*V*), whence the partition function ratio in Eq. (1) becomes

To transform this into something useful for the design of a Monte Carlo algorithm, one finally needs to remark that the partition function *Z*_{λ} for the modified system can be written as

where the summation is taken over the possible configurations of Δ*N* particles in Δ*V* and Ω is the total number of configurations with Δ*N* particles in Δ*V* and *N* + Δ*N* in *V* + Δ*V*. Thus, the average number ⟨Δ*N*⟩ of particles in Δ*V* can be obtained as

This leads to the desired expression for the pressure

The practical implementation of Eq. (5) in a Monte Carlo algorithm obviously requires the interval of *λ* values be discretized and numerical simulations carried out for different finite values of the repulsive potential. In addition, the sites of Δ*V* on which the potential acts needs to be finite. To the best of our knowledge, this is typically chosen to be as small as 1, and the single pressure-probe site is generally embedded in a wall of codimension 1 confining the system from one side. In this form, it has been observed that the algorithm becomes problematic in the presence of a strong external bias, as in a lattice gas under gravity.^{14} When dealing with pressures as tiny as those generated by the Casimir effect in a nonequilibrium driven system,^{15} the algorithm may require excessively long execution times, which is all the more troublesome for cooperative driven dynamics. Moreover, a naive extension of the algorithm allowing probing the pressure at different locations, simultaneously, leads to unreliable results in nonequilibrium conditions.

We show in this paper that these drawbacks can be actually overcome and that an efficient formulation of the algorithm can be consistently applied to a variety of physical situations of growing complexity, from a simple sedimentation problem to fluctuation-induced forces in a driven diffusive system. First of all, one should notice that some care is required when dealing with systems in which ⟨Δ*N*⟩ ≈ Δ*V*. In these cases, there exists a limitation on the maximum value of pressure *P*_{max} that can be measured, as Eq. (4) diverges for *λ* → 0, while *P*_{max} ≈ −log *λ*_{min}, (where *λ*_{min} is the minimum value of the *λ* discretization). Evidently, to correctly quantify the pressure when ⟨Δ*N*⟩ ≈ Δ*V*, one has to choose a suitable value of *λ*_{min}. Second, it is important to emphasize that the presence of a confining wall is not a necessary ingredient for computing pressure in a Monte Carlo simulation. If for some reason the spatial translational invariance of system geometry and interactions has to be preserved, one can use periodic boundary conditions (unless, of course, one is interested in the wall effects, as in wetting phenomena, for example). Third, the size of Δ*V* can be relatively large, Δ*V* ≫ 1, provided that it is sub-extensive, Δ*V* ≪ *V*. This improves data statistics and becomes particularly relevant when the system under study displays an inhomogeneous density profile. In this case, multiple pressure probes distributed uniformly over the whole system can give access to the entire pressure profile with a single simulation run. Finally, once the wall is suppressed, it is important to specify how the (ghost) sites of Δ*V* are added to the original system. We do so by adding an extra nearest neighboring site to a certain number, Δ*V*, of sites of the original system. In this way, the local geometric structure of the original system is preserved, and its intrinsic dynamics will be only weakly perturbed by the presence of these extra ghost sites (for a schematic representation, see Fig. 1). This point is particularly important as statistical mechanical models of interest generally involve static or dynamic spatially extended interactions.

In the following, the above points are implemented and carefully examined in systems for which the pressure has a purely entropic content, i.e., athermal systems. Comparison with theory is made whenever analytical results are partially or fully available. Monte Carlo simulations are carried out in the grand canonical ensemble, in which the system of volume *V* (or one of its parts) is coupled to a reservoir R at chemical potential *μ* = log[*ρ*_{R}/(1 − *ρ*_{R})], where *ρ*_{R} is the reservoir density. Unless otherwise mentioned, the pressure-probe ghost sites are equally spaced in both the transverse and longitudinal directions of the system. At every Monte Carlo time step, a lattice bond in the coupled system (Δ*V* + *V* + R) is randomly selected, and depending on the pair of sites involved, one of the three possibilities is considered: hole-particle exchange within the volume *V*, hole-particle exchange between *V* and the reservoir R, and hole-particle exchange between *V* and the ghost volume Δ*V*. It is important to emphasize that the dynamics of the particle reservoir R is not explicitly simulated. Rather, every time the randomly selected bond involves a site of R, its occupation state is randomly established by extracting a number with probability *ρ*_{R}. The results we present were obtained by using the cutoff *λ*_{min} = 0.001 and discretizing *λ* ∈ [0, 1] into 24 values equally spaced over three contiguous subintervals [0.01, 0.04], [0.04, 0.2], and [0.2, 1], with steps Δ*λ* = 0.01, 0.02, and 0.1, respectively. Compared to a simple uniform discretization of [0, 1], this makes the numerical evaluation of Eq. (5) more effective because the contribution of smaller values of *λ*, which give a large contribution to the integral, is better weighted.

## LATTICE GAS UNDER GRAVITY

To begin with, we discuss what is perhaps the simplest equilibrium system with a non-trivial inhomogeneous density profile, the hard-core lattice gas under gravity. This provides a natural test bed for the algorithm as the system thermodynamics is simple enough to allow for a detailed comparison with the exactly known results. For a system of height *h*_{top} enclosed on the bottom and with the top in contact with a reservoir at density *ρ*_{top}, the pressure at height *h* is given by

where *ρ*(*h*) is the density profile defined as

with *mg* being the gravity force. A further advantage of this problem is that the average number ⟨Δ*N*⟩ of particles in Δ*V*, Eq. (4), can be computed easily,^{14}

providing a further detailed check of the algorithm. In the Monte Carlo, simulation we assume that the boundary condition in the direction transverse to the gravity force is periodic and the ghost sites are uniformly distributed along the system diagonal. The square lattice is tilted by 45°, and particle hopping is ruled by the standard Metropolis transition probability, *p* = min{1, exp(−*βmg*Δ*h*)}, where Δ*h* = ±1 is the height difference due to a single hop. In Fig. 2, we show the results for the density profile *P*(*h*) for two different values of the gravity force, when the system top is kept in contact with a particle reservoir at density *ρ*_{top} = 0.01. As we can see, the analytic results are perfectly recovered.^{16} In this form, the algorithm can be applied to more complex lattice models of colloidal sedimentation and granular compaction, like those of Refs. 17 and 18.

## LATTICE GAS WITH NEAREST NEIGHBOR EXCLUSION

Next, we turn to a more interesting system of interacting particles, that is, the lattice gas with nearest neighbor exclusion, where particles are forbidden to occupy the same or neighboring sites. This model has a long tradition in the study of critical phenomena as a schematic lattice model of hard-sphere fluids and is closely related to the classical NP-hard combinatorial optimization problem of finding a minimum vertex cover on a random graph.^{19} Numerical and theoretical studies for various finite dimensional lattices^{20–27} have shown that there exists a critical density *ρ*_{c} (for a square lattice *ρ*_{c} = 0.367 74 …) at which the model exhibits a continuous phase transition to an ordered state with exponents that belong to the Ising universality class.^{25} Above *ρ*_{c}, particles tend to occupy preferentially one of the two sublattices in which the original lattice can be decomposed (in such a way that the nearest-neighbors of any sites of one sublattice belong to the other sublattice and vice-versa). The ground state, therefore, corresponds to a fully occupied sublattice, and the maximum packing density is *ρ*_{max} = 1/2. In Fig. 3, we show the parametric plot of the equation of state *P*(*ρ*) obtained in a grand-canonical simulation by slowly increasing the chemical potential. In agreement with the well-established numerical and theoretical results, the equation of state displays an inflection point, corresponding to a divergent compressibility, near the critical density at which sublattice ordering occurs. The full line below the critical density is a one-parameter fit obtained from the approach in Ref. 27, while the full line at higher densities is the non-interacting entropic pressure −log(1 − *ρ*/*ρ*_{max}) near the closest packing density *ρ*_{max} = 1/2.

## BETHE LATTICE GLASS

The previously considered model can be interestingly generalized to situations in which every particle cannot have more than *ℓ* particles as nearest neighbors (thus, the nearest neighbor exclusion models is recovered for *ℓ* = 0). This class of models was introduced in the attempt of providing a microscopic finite-dimensional realization of the thermodynamic scenario for the elusive glass transition.^{28} Subsequent works have shown that in finite dimension, a freezing transition toward an ordered ground state occurs.^{30,31} However, some more sophisticated variants appear to be quite stable against crystallization and display properties of fragile glass-forming liquids.^{32,33} For the purpose of testing the present algorithm in a geometric structure other than the usual Euclidean lattices, we focus here on the monodisperse lattice glass model on the Bethe lattice. This is also known as the regular random graph, which is a locally tree-like geometric structure with a fixed connectivity *k* + 1, and with long loops of order ln *N*. This latter feature, an analog of generic boundary conditions, prevents unphysical surface effects and gives rise to frustration precluding crystalline orderings. The resulting glassy behavior can be studied analytically with the tools of disordered systems theory^{28,29} and has been extended to the quantum domain as well.^{34} In Fig. 4, we show a parametric plot of the equation of state obtained in a grand canonical Monte Carlo simulation for the Bethe lattice glass (with connectivity *k* + 1 mimicking the square and cubic lattice) for two values of *ℓ*. Consistent with the analytical calculation,^{28} no sign of crystallization is observed in the equation of state and, for large chemical potential, the pressure tends to diverge at a density very near the closest packing limit, *μ* → ∞, obtained with the cavity method of disordered systems theory.^{29}

## FLUCTUATION-INDUCED FORCE IN A DRIVEN LATTICE GAS

As a final more stringent test of the present algorithm, we now consider a two-dimensional system driven into a nonequilibrium steady state by two reservoirs at different densities, *ρ*_{0} and *ρ*_{1}, located at its edges *x* = 0 and *x* = *L*, respectively. For such driven diffusive systems, it is known that there exists long-range correlations,^{35} even for purely hard-core interactions.^{36} A striking consequence is the appearance of Casimir-like forces in a finite geometry.^{15} To the leading order in *ρ*_{1} − *ρ*_{0} and for a simple symmetric exclusion process^{37} on a square lattice of size *L* × *d*, this fluctuation-induced pressure, Π(*x*), is given by^{15}

where *ρ*(*x*) = *ρ*_{0} + (*ρ*_{1} − *ρ*_{0})*x*/*L* is the system density profile, and we set *k*_{B}*T* = 1. For the lattice system with only infinite hard-core repulsion, the thermodynamic limit of the average density of particle, ⟨*ρ*_{ΔV}⟩, in the ghost volume Δ*V* is exactly known, see Eq. (8). This means that the Casimir pressure, Π_{MC}(*x*), in a Monte Carlo simulation with a finite Δ*V* can be measured as

where it is understood that the integral has to be properly discretized. In Fig. 5, we compare the Monte Carlo results for Π_{MC}(*x*) at reservoirs densities *ρ*_{0} = 0.1 and *ρ*_{1} = 0.7 and different system sizes, with the theoretical result for Π(*x*), Eq. (9), in the rescaled form $\Pi \u0303(x)=L\u2009d\u2009\Pi (x)$. Data points of each curve were simultaneously obtained for a dynamical evolution long 10^{9} Monte Carlo sweeps and averaged over a sample of 10–20 elements (statistical errors are not visible because of the order of symbol size). The agreement is excellent and fully confirms the efficiency and functionality of our algorithm.

In conclusion, we have developed an algorithm based on the Dickman method which can considerably improve the accuracy of Monte Carlo calculations of pressure in lattice models, and is especially suited for systems with inhomogeneous density profiles, both in equilibrium and nonequilibrium steady states. The algorithm is quite general and holds the key to many other statistical mechanics applications.

## ACKNOWLEDGMENTS

I gratefully acknowledge Daniel Martin and José Luis Iguain for valuable suggestions in the early stage of this work. I also thank Avi Aminov, Jef Arenzon, and Yariv Kafri for kindly clarifying some aspects of their work.^{15,27} Numerical simulations were performed by using ICTP computer facilities.

## DATA AVAILABILITY

The data that support the findings of this study are available from the corresponding author upon reasonable request.

## REFERENCES

Notice that for values of *βmg* larger that those we used the bottom layers become densely occupied, ⟨Δ*N*⟩ ≈ Δ*V*, and pressure is correctly measured only if a suitable value of *λ*_{min} is properly chosen.