11email: [email protected],
WWW home page: http://www.algarcia.org
DSMC: A Statistical Mechanics Perspective
Abstract
This paper presents a perspective in which Direct Simulation Monte Carlo (DSMC) is viewed not in its traditional role as an algorithm for solving the Boltzmann equation but as a numerical method for statistical mechanics. First, analytical techniques such as the collision virial and Green-Kubo relations, commonly used in molecular dynamics, are used to study the numerical properties of the DSMC algorithm. The stochastic aspect of DSMC, which is often viewed as unwanted numerical noise, is shown to be a useful feature for problems in statistical physics, such as Brownian motion and thermodynamic fluctuations. Finally, it is argued that fundamental results from statistical mechanics can provide guardrails when applying machine learning to DSMC.
keywords:
Direct Simulation Monte Carlo, statistical mechanics, molecular dynamics, kinetic theory, fluctuations1 MD and DSMC – Brothers separated at birth
Three scientific eras dawned in the middle of the last century: the atomic age, the space age, and the age of the computer. Numerical algorithms were developed for the study of fluids under extreme conditions, such as nuclear explosions and orbital reentry, that were beyond the realm of conventional laboratory experiments. An early example is the Metropolis Monte Carlo method, which in 1953 showed that a particle representation could be used to map phase space and using statistical mechanics extract a fluid’s thermodynamic properties, such as the equation of state.[39] It was closely followed by molecular dynamics (MD), introduced in 1959 by Alder and Wainwright, which uses a similar particle representation but includes dynamics, allowing it to measure transport properties such as viscosity.[2]
In 1963, Graeme Bird submitted to Physics of Fluids a paper entitled “Approach to Translational Equilibrium in a Rigid Sphere Gas.” In this article he introduced a stochastic collision algorithm that would become the cornerstone of Direct Simulation Monte Carlo (DSMC). The paper was rejected (G.A. Bird, personal communication). The referee had failed to recognize that DSMC differed significantly from MD; after revising it to explain these differences, Bird’s paper was accepted.[12]
DSMC went on to become the dominant numerical method in aerospace engineering for rarefied gas dynamics while MD established popularity in the field of statistical mechanics for the simulation of microscopic systems. For many years, these communities remained separate, yet recently they have found common interests in topics such as nanofluidics and granular flows. This paper presents several short stories in which DSMC is used by researchers, such as myself, whose background is in statistical mechanics and molecular dynamics. As we shall see, by approaching DSMC from an unconventional perspective, a number of new avenues are opened. This narrative is intentionally personal, since Graeme Bird, to whom this paper is dedicated, was a colleague and friend for nearly 30 years. In the interest of space, a summary of the DSMC algorithm is omitted; see [4] for an introduction and [14, 15, 20] for full treatments.
2 But why ideal gas law?
In 1989 I joined the faculty at San Jose State University, located in Silicon Valley. About that time I met Berni Alder and started working with him at the nearby Livermore Lab. Alder took an immediate interest in DSMC and we eventually published 16 papers together, most of them on ways to extend the DSMC algorithm. Yet when I first explained DSMC to Berni, he was puzzled and asked “But why does it give the ideal gas law?” Graeme Bird did not address this question in his books on DSMC [13, 14, 15] since he always viewed the algorithm as numerically solving the Boltzmann equation, a perspective that was reinforced by a proof by Wagner [48].
In their seminal MD simulations Alder and Wainwright [3] measured the equation of state for hard spheres (mass , diameter ) as
(1) |
where , , are pressure, number density, and temperature; is the Boltzmann constant. The collision rate is and
(2) |
is the virial. For a collision between particles and , is the change in velocity for particle and is their separation. The virial is an average over collisions and depends on the particle diameter since . In (1) the pressure is the sum of translational and collisional contributions to momentum transfer.
In DSMC collisions occur within cells and the probability of a collision is independent of the positions of the particles, so and so . Since the virial contribution is zero, the equation of state for DSMC is the ideal gas law. Note that Wagner’s proof is for infinitesimal collision cells yet we have the ideal gas law even for finite cell size due to symmetry in the selection of collision partners in DSMC.
Alder found this unsatisfactory, so, together with Frank Alexander, we formulated the Consistent Boltzmann Algorithm (CBA).[5] It is identical to DSMC except that collisions change both the velocities and the positions of colliding particles. Specifically, after computing the post-collision velocities the positions are shifted as
(3) |
where is a unit vector in the direction of the apse line (line between centers) for a hard sphere collision with this change in velocity. Simulations verified that CBA gives the correct pressure and reasonably accurate transport coefficients up to moderately high densities.
The Consistent Universal Boltzmann Algorithm (CUBA) makes the post-collision displacement a function of density and temperature, which allows one to choose the desired equation of state.[6, 34] For example, by choosing the van der Waals equation, we were able to simulate the condensation of vapor into liquid droplets. However, for simulating liquids, we found that CUBA was not competitive with MD in terms of computational cost.
Today, the most popular variants of DSMC for dense gases are based on the Enskog equation.[27, 40] Instead of using a CBA displacement, the correct virial can be obtained by using a collision probability that depends on both the relative velocity and the relative position for a collision pair.[25] In other words, the Enskog perspective is that particle positions affect collisions, while in CBA, collisions affect particle positions.
3 A lesson on transport from molecular dynamics
In his first book, Graeme Bird said of DSMC, “the results are remarkably insensitive…and no deleterious effects are generally present…if the cell size approaches the mean free path or if the time step approaches the mean collision time.”[13] Nevertheless, the demonstration program in this book for the Rayleigh problem sets the collision cell size to half a mean free path and the time step to a fifth of a mean free collision time.
A common way of quantifying the error due to cell size and time step is to measure viscosity or thermal conductivity and, at low Knudsen number, compare with Chapman-Enskog theory. These transport coefficients can be obtained by measuring the momentum (or heat) flux in a DSMC simulation with a linear velocity (or temperature) gradient.[19] From the perspective of non-equilibrium thermodynamics, the transport coefficient is an Onsager coefficient that relates the thermodynamic flux to the thermodynamic force due to the gradient.[24, 41]
Yet in the early days of molecular dynamics, such non-equilibrium measurements were not feasible since simulations were limited to a few hundred particles. Instead, transport properties were measured in simulations of equilibrium systems using results from statistical mechanics.
The basic idea is to apply the fluctuation-dissipation theorem, which connects statistical fluctuations to the rate of dissipation. The best known example is Brownian motion in which the mobility, , of a particle is obtained from measuring the variance of its position in time as
(4) |
By contrast, a non-equilibrium measurement obtains the mobility from the terminal velocity, , for the particle under an external force of magnitude .
Using Einstein-Helfand theory one can measure the viscosity of a fluid from molecular trajectories as [1]
(5) |
where is the number of molecules, is the system volume, , are components of , and . This allows us to measure the viscosity (and other transport coefficients) from equilibrium simulations. A related approach uses the off-diagonal stress tensor component,
(6) |
where is the force between molecules. Our previous result now takes the more familiar form from Green-Kubo theory,
(7) |
Notice from (6) that is the sum of a kinetic (ballistic) contribution and a contribution due to the transfer of momentum by intermolecular forces.
For hard sphere collisions Wainwright wrote [49]
(8) |
where is the time of a collision. He was able to evaluate (7) and express it as the sum of three contributions, The kinetic contribution is precisely the Chapman-Enskog viscosity. The cross term and the collision term are dense gas corrections.
In DSMC, the collision term is not zero due to the finite distance between the collision partners (i.e., the finite collision cell size). Unlike the equation of state contribution due to the virial (see (2)), this contribution to the viscosity does not average to zero over DSMC collisions within a cell. In fact, following a similar analysis as Wainwright one finds
(9) |
For cubic collision cells of size the average ; at equilibrium . In DSMC the cross term is zero and so the hard sphere viscosity is [7]
(10) |
where is the mean free path. Note that the error goes as ; for a cell size of one mean free path the viscosity deviates from its Chapmann-Enskog value by 11 percent. A similar analysis (with a similar result) may be applied to obtain the error in thermal conductivity due to finite cell size. Finally, this approach also gives the error in the transport coefficients due to a finite time step ; in DSMC this error goes as .[32, 33]
In his last book Bird wrote “(In) early DSMC programs… the mean spacing between collision pairs was too large in comparison with the mean free path and this led to the introduction of sub-cells…(and) an option to select the collision pairs from the nearest-neighbour pairs within the cell.”[15] He also mentions that “The time step is set to a specified small fraction of the sampled mean collision time.” A challenge for modern DSMC codes is to minimize the distance between colliding particles and to minimize the time between ballistic movement steps while avoiding unphysical bias errors (see Section 5).
4 Fluctuations – One man’s garbage…
My introduction to DSMC came in 1983 as I was finishing my doctoral studies at The University of Texas at Austin in what is now The Ilya Prigogine Center for Studies in Statistical Mechanics and Complex Systems. At that time there were theoretical results, confirmed by light scattering experiments, indicating that hydrodynamic fluctuations had weak, long-ranged correlations in non-equilibrium systems (e.g., under a temperature gradient).
In his first book, Bird describes fluctuations in DSMC as an unavoidable annoyance but that with a sufficiently large sample size the desired mean value can be measured to the desired accuracy.[13] One commonly held misconception was that these fluctuations came from the Monte Carlo nature of the collision algorithm in DSMC. Yet the very same fluctuations are also found in molecular dynamics, which has deterministic dynamics.
Due to computer memory constraints, the number of particles (or “simulators”) in a DSMC calculation is typically a small fraction of the number of physical molecules. For example, at standard temperature and pressure, the mean free path in air is roughly 60 nanometers and a cubic mean free path contains about 6000 molecules. In contrast, a typical DSMC simulation uses 20 particles per cubic mean free path, that is, each DSMC particle represents physical molecules. This number scales as the Knudsen number so it is much higher for rarefied flows.
Statistical mechanics gives us the standard deviation of hydrodynamic variables, allowing us to estimate the expected statistical standard error in particle simulations.[35] For example, in a cell with particles, the variance in each component of fluid velocity is .[36] For both MD and DSMC the fractional error in estimating from independent statistical samples is
(11) |
where is the Mach number of the flow. This result illustrates why nanofluidic flows, in which , are much harder to measure in DSMC compared to hypersonic flows. In DSMC is smaller than the number of physical molecules by a factor of , the variance in fluid velocity increases by the same factor.
After accounting for this amplification factor, we find that hydrodynamic fluctuations in DSMC are physically correct [31] and yield hydrodynamic information. For example, from the time correlation of density fluctuations one may measure the sound speed and viscosity from the location and width of the Brillouin peak, mimicking the technique used by light scattering.[10, 21] This dynamic structure factor is a useful way to compare DSMC models (e.g. internal energy relaxation) with laboratory measurements and theoretical predictions.[22]
The first numerical observations of long-ranged correlations of hydrodynamic fluctuations were made using DSMC for systems with a temperature gradient [37] and a velocity gradient [30]. The “giant fluctuation” phenomenon, first reported in diffusive mixing experiments [46], is due to such non-equilibrium correlations for fluctuations of concentration and fluid velocity, as confirmed by DSMC [26]. Most recently DSMC simulations have been used to study the impact of thermal fluctuations on turbulence.[28, 38] They confirm theoretical predictions [9] and numerical fluctuating hydrodynamic observations [11] that molecular fluctuations dominate the turbulent energy cascade at the Kolmogorov length scale.
Bird wrote in his last book, “While the fluctuations are unphysical when is large, they are physically realistic… (with) a one-to-one correspondence between real and simulated molecules. This is another instance of DSMC going beyond the Boltzmann equation because fluctuations are neglected in the Boltzmann model.” His last three papers were on Brownian motion.[16, 17, 18]
5 Exorcising the demons
In 1887 Maxwell presented a thought experiment, “… conceive of a being whose faculties are so sharpened that he can follow every molecule in its course … so as to allow only the swifter molecules to pass from (chamber) A to B, and only the slower molecules to pass from B to A. He will thus, without expenditure of work, raise the temperature of B and lower that of A, in contradiction to the second law of thermodynamics.” The DSMC algorithm has full information and control of the particle’s dynamics and modern implementations have many complex stages. How can we be sure that we do not have a Maxwell demon hiding in our simulations? In other words, how do we test that our simulations satisfy the Second Law of Thermodynamics? Boltzmann’s H-theorem is not helpful, since, due to fluctuations, it only applies in the limit .
Consider an isolated system with microstate dynamics[44]
(12) |
where is the probability of state and is the transition rate from to . At equilibrium . If , then we have microscopic reversibility. At equilibrium we have detailed balance () and ergodicity () iff we have microscopic reversibility. Finally, the dynamics satisfies the Second Law () iff we have ergodicity.[44]
Detailed balance is a necessary condition for microscopic reversibility, which is a sufficient condition for the dynamics to obey the Second Law. Yet, it is not uncommon to find DSMC implementations that do not satisfy detailed balance. For example, some of the early surface scattering models were ad hoc empirical fits to experimental data, which led Cercignani and Lampis to formulate a model that imposed detailed balance.[23] Many implementations of inflow/outflow boundaries also fail to satisfy detailed balance.[45] If machine learning methods are used to handle some elements in a DSMC calculation, such as chemical reactions and internal degrees of freedom, we may not know if detailed balance is satisfied.[8] And even when the algorithm in a DSMC code is theoretically sound, there is always the possibility that the implementation has a ’bug’ (coding error).
In testing for the presence of Maxwell demons in a DSMC code, equilibrium hydrodynamic fluctuations can serve as a coal mine canary. For example, at equilibrium, the number of particles in each cell is independently Poisson distributed, and this result is independent of the collision model, boundary conditions, etc. Statistical mechanics provides further relations for the variances and correlations of fluid velocity, temperature, internal energy, and other variables.[29, 36] While this is a necessarily but not sufficient statistical test, it is a sensitive one that can reveal malevolent problems. Ensuring the correctness of simulation data is increasingly important as we enter the age of artificial intelligence. Given the AI systems’ voracious appetite for such data, we must avoid having machines learn the wrong lessons.
6 Concluding Remarks
Graeme Bird and Berni Alder met for the first time at the 22nd Rarefied Gas Dynamics Symposium in Sydney, Australia, nearly 40 years after their original publications on DSMC and MD. In the 25 years since that meeting, we find increasing cooperation between the two algorithms’ communities. One example is the study of rotational relaxation using all-atom molecular dynamics simulations combined with DSMC.[47] Yet perhaps the best example is the shared heritage of LAMPPS [43] and SPARTA [42], two of the most widely used codes for molecular dynamics and direct simulation Monte Carlo. Although separated at birth, MD and DSMC are now the patriarchs overseeing a large family of particle-based fluid algorithms.
Acknowledgement
The author acknowledges support from the US Department of Energy, Office of Science, Office of Advanced Scientific Computing Research, Applied Mathematics Program under contract no. DE-AC02-05CH11231.
References
- [1] B. Alder, D. Gass, and T. Wainwright, Studies in molecular dynamics. viii. the transport coefficients for a hard-sphere fluid, The Journal of Chemical Physics, 53 (1970), pp. 3813–3826.
- [2] B. J. Alder and T. E. Wainwright, Studies in molecular dynamics. i. general method, The Journal of Chemical Physics, 31 (1959), pp. 459–466.
- [3] B. J. Alder and T. E. Wainwright, Studies in molecular dynamics. ii. behavior of a small number of elastic spheres, The Journal of Chemical Physics, 33 (1960), pp. 1439–1451.
- [4] F. J. Alexander and A. L. Garcia, The direct simulation monte carlo method, Computers in Physics, 11 (1997), pp. 588–593.
- [5] F. J. Alexander, A. L. Garcia, and B. J. Alder, A consistent boltzmann algorithm, Physical Review Letters, 74 (1995), p. 5212.
- [6] , The consistent boltzmann algorithm for the van der waals equation of state, Physica A: Statistical Mechanics and its Applications, 240 (1997), pp. 196–201.
- [7] , Cell size dependence of transport coefficients in stochastic particle algorithms, Physics of Fluids, 10 (1998), pp. 1540–1542.
- [8] N. D. Ball, J. F. MacArt, and J. Sirignano, Online optimisation of machine learning collision models to accelerate direct molecular simulation of rarefied gas flows, arXiv preprint arXiv:2411.13423, (2024).
- [9] D. Bandak, N. Goldenfeld, A. A. Mailybaev, and G. Eyink, Dissipation-range fluid turbulence and thermal noise, Physical Review E, 105 (2022), p. 065113.
- [10] F. Baras, M. M. Mansour, A. Garcia, and M. Mareschal, Particle simulation of complex flows in dilute systems, Journal of Computational Physics, 119 (1995), pp. 94–104.
- [11] J. B. Bell, A. Nonaka, A. L. Garcia, and G. Eyink, Thermal fluctuations in the dissipation range of homogeneous isotropic turbulence, Journal of Fluid Mechanics, 939 (2022), p. A12.
- [12] G. Bird, Approach to translational equilibrium in a rigid sphere gas, Phys. fluids, 6 (1963), pp. 1518–1519.
- [13] , Molecular Gas Dynamics, Oxford engineering science series, Clarendon Press, 1976.
- [14] , Molecular Gas Dynamics and the Direct Simulation of Gas Flows, no. v. 1 in Molecular Gas Dynamics and the Direct Simulation of Gas Flows, Clarendon Press, 1994.
- [15] , The DSMC Method, CreateSpace Independent Publishing Platform, 2013.
- [16] , The rate of energy transfer from air as an initially stationary particle acquires brownian motion, Nano energy, 11 (2015), pp. 463–470.
- [17] , Brownian relaxation of an inelastic sphere in air, Physics of Fluids, 28 (2016).
- [18] , The possibility of harvesting useful energy from the thermal motion of air molecules, NanoWorld J, 3 (2017), pp. 18–22.
- [19] G. Bird, M. Gallis, J. Torczynski, and D. Rader, Accuracy and efficiency of the sophisticated direct simulation monte carlo algorithm for simulating noncontinuum gas flows, Physics of Fluids, 21 (2009).
- [20] I. Boyd and T. Schwartzentruber, Nonequilibrium Gas Dynamics and Molecular Simulation, Cambridge Aerospace Series, Cambridge University Press, 2017.
- [21] D. Bruno, A. Frezzotti, and G. P. Ghiroldi, Rayleigh–brillouin scattering in molecular oxygen by ct-dsmc simulations, European Journal of Mechanics-B/Fluids, 64 (2017), pp. 8–16.
- [22] D. Bruno and V. Giovangigli, Internal energy relaxation processes and bulk viscosities in fluids, Fluids, 7 (2022), p. 356.
- [23] C. Cercignani and M. Lampis, Kinetic models for gas-surface interactions, Transport theory and statistical physics, 1 (1971), pp. 101–114.
- [24] S. De Groot and P. Mazur, Non-Equilibrium Thermodynamics, Dover Books on Physics, Dover Publications, 2013.
- [25] A. Donev, B. J. Alder, and A. L. Garcia, Stochastic hard-sphere dynamics for hydrodynamics of nonideal fluids, Physical review letters, 101 (2008), p. 075902.
- [26] A. Donev, J. B. Bell, A. de La Fuente, and A. L. Garcia, Diffusive transport by thermal velocity fluctuations, Physical review letters, 106 (2011), p. 204501.
- [27] A. Frezzotti, A particle scheme for the numerical solution of the enskog equation, Physics of Fluids, 9 (1997), pp. 1329–1335.
- [28] M. Gallis, N. Bitter, T. Koehler, J. Torczynski, S. Plimpton, and G. Papadakis, Molecular-level simulations of turbulence and its decay, Physical review letters, 118 (2017), p. 064501.
- [29] A. Garcia, Estimating hydrodynamic quantities in the presence of microscopic fluctuations, Communications in Applied Mathematics and Computational Science, 1 (2007), pp. 53–78.
- [30] A. Garcia, M. M. Mansour, G. Lie, and E. Clementi, Hydrodynamic fluctuations in a dilute gas under shear, Physical Review A, 36 (1987), p. 4348.
- [31] A. Garcia and C. Penland, Fluctuating hydrodynamics and principal oscillation pattern analysis, Journal of statistical physics, 64 (1991), pp. 1121–1132.
- [32] A. Garcia and W. Wagner, Time step truncation error in direct simulation monte carlo, Physics of Fluids, 12 (2000), pp. 2621–2633.
- [33] N. G. Hadjiconstantinou, Analysis of discretization in the direct simulation monte carlo, Physics of Fluids, 12 (2000), pp. 2634–2638.
- [34] N. G. Hadjiconstantinou, A. L. Garcia, and B. J. Alder, The surface properties of a van der waals fluid, Physica A: Statistical Mechanics and its Applications, 281 (2000), pp. 337–347.
- [35] N. G. Hadjiconstantinou, A. L. Garcia, M. Z. Bazant, and G. He, Statistical error in particle simulations of hydrodynamic phenomena, Journal of computational physics, 187 (2003), pp. 274–297.
- [36] L. D. Landau and E. M. Lifshitz, Statistical Physics: Volume 5, vol. 5, Elsevier, 2013.
- [37] M. M. Mansour, A. L. Garcia, G. C. Lie, and E. Clementi, Fluctuating hydrodynamics in a dilute gas, Physical review letters, 58 (1987), p. 874.
- [38] R. M. McMullen, M. C. Krygier, J. R. Torczynski, and M. A. Gallis, Navier-stokes equations do not describe the smallest scales of turbulence in gases, Physical Review Letters, 128 (2022), p. 114501.
- [39] N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller, and E. Teller, Equation of state calculations by fast computing machines, The journal of chemical physics, 21 (1953), pp. 1087–1092.
- [40] J. M. Montanero and A. Santos, Simulation of the enskog equation a la bird, Physics of Fluids, 9 (1997), pp. 2057–2060.
- [41] H. Öttinger, Beyond Equilibrium Thermodynamics, Wiley, 2005.
- [42] S. J. Plimpton, S. Moore, A. Borner, A. Stagg, T. Koehler, J. Torczynski, and M. Gallis, Direct simulation monte carlo on petaflop supercomputers and beyond, Physics of Fluids, 31 (2019).
- [43] A. P. Thompson, H. M. Aktulga, R. Berger, D. S. Bolintineanu, W. M. Brown, P. S. Crozier, P. J. In’t Veld, A. Kohlmeyer, S. G. Moore, T. D. Nguyen, et al., Lammps-a flexible simulation tool for particle-based materials modeling at the atomic, meso, and continuum scales, Computer Physics Communications, 271 (2022), p. 108171.
- [44] J. S. Thomsen, Logical relations among the principles of statistical mechanics and thermodynamics, Physical Review, 91 (1953), p. 1263.
- [45] M. W. Tysanner and A. L. Garcia, Non-equilibrium behaviour of equilibrium reservoirs in molecular simulations, International journal for numerical methods in fluids, 48 (2005), pp. 1337–1349.
- [46] A. Vailati and M. Giglio, Giant fluctuations in a free diffusion process, Nature, 390 (1997), pp. 262–265.
- [47] P. Valentini, C. Zhang, and T. E. Schwartzentruber, Molecular dynamics simulation of rotational relaxation in nitrogen: Implications for rotational collision number models, Physics of Fluids, 24 (2012).
- [48] W. Wagner, A convergence proof for bird’s direct simulation monte carlo method for the boltzmann equation, Journal of Statistical Physics, 66 (1992), pp. 1011–1044.
- [49] T. Wainwright, Calculation of hard-sphere viscosity by means of correlation functions, The Journal of Chemical Physics, 40 (1964), pp. 2932–2937.