Legendre-Fenchel transforms capture layering transitions in porous media

We have investigated the state of a nanoconfined fluid in a slit pore in the canonical and isobaric ensembles. The systems were simulated with molecular dynamics simulations. The fluid has a transition to a close-packed structure when the height of the slit approaches the particle diameter. The Helmholtz energy is a non-convex function of the slit height if the number of particles does not exceed that of one monolayer. As a consequence, the Legendre transform cannot be applied to obtain the Gibbs energy. The Gibbs energy of a non-deformable slit pore can be transformed into the Helmholtz energy of a deformable slit pore using the Legendre-Fenchel transform. The Legendre-Fenchel transform corresponds to the Maxwell construction of equal areas.


Introduction
Over the last years, there has been an increasing number of observations of phase transitions in conned uids. Fluids can for instance change their critical temperature by several tens of degrees, 1,2 a two-dimensional layer at an interface may develop more than one structure, 3 and adsorption to droplets may depend largely on droplet size. 4,5 Classical Gibbs thermodynamics ceases to exist on the nanoscale. The need for the inclusion of shape and size has been met in several ways. Gibbs and followers included curvature as a variable 6 to deal with droplet size dependence. Not only size and shape will matter for the outcome of the analysis of simulations; the thermodynamic properties will also depend on the small system's environment or the set of variables that control the system (the ensemble) according to Hill. 7,8 Dong 9 argued that thermodynamic variables, like the surface tension, change as we shrink the small system, and proposed to add as variable the integral surface tension, to complement the normal (differential) surface tension. The pressure of uids in porous media is of special interest as its gradient is the main driving force for mass transport. 10,11 A systematic way to address these problems was given by Hill 7,8 already 50 years ago. We have argued that the problems are best addressed by his method, 3,[12][13][14] because the method provides a general description of small systems. In this work, we investigate a slit pore of large surface area and small height. The system has periodic boundary conditions in the directions tangential to the slit pore wall. In this way, the system is conned, but the number of particles is large. We have for instance been able to write scaling laws for small system variables, 15 and a new equilibrium criterion for pressure was developed for two-phase equilibria in slit pores. 15 Hill's method is therefore our rst choice when the aim is to learn more about structural transitions in conned uids or how variables change. A rst-order phase transition is dened as a discontinuity in the relation between the normal pressure and the slit pore height. In connement a phase transition is no longer sharp, the transition is smooth, 8 this is by denition not a rstorder phase transition. We shall nd here that a transforming procedure exists in terms of the Legendre-Fenchel transform. This is a more general transform than the Legendre transform and can be used for large as well as small systems. It will enable us to compute the Gibbs energy from the Helmholtz energy and vice versa.
We have recently reported the changes in free energy during polymer stretching. The free energy depends on the conditions used, whether the polymer is stretched at controlled length or force. 16,17 For sufficiently short polymers, the Helmholtz energy is a non-convex function of the controlled length of the polymer. A convex function has a non-negative second derivative everywhere. To transform from the Helmholtz to the Gibbs energy the Legendre-Fenchel transform could be applied. Similarly, we observed that the grand potential of a uid in a slit pore is a non-convex function of the distance between the parallel plates at constant chemical potential and temperature. 3 Also, the Helmholtz energy of solid colloids in solution is non-convex as a function of the controlled distance between the colloids, keeping the temperature, volume, and the number of particles constant. 18 Both cases can be explained by a disjoining pressure (also known as the solvation pressure), 19 which is the excess normal pressure relative to the bulk pressure due to the packing of uid particles between the solids. The observations mentioned all stem from size effects. To obtain the free energy of the corresponding constant pressure ensemble the Legendre-Fenchel transform must be applied, and not the Legendre transform.
The three pillars that science progresses from are theory, experiments, and simulations. The theory part is lacking in nanotechnology. Energy converting devices are abundant, but there is little available general theory of energy conversion for the nanoscale. The laws of energy conversion are the laws of thermodynamics, and the question we are asking is which form these take. Nanothermodynamics has been constructed, mostly by adding terms to Gibbs's classical formulation for large-scale systems. While this mending procedure may serve the purpose in some special cases, it does not present us with a systematic procedure to be used as a general tool. Here we argue that the theory of Hill presented more than 50 years ago, presents an underused opportunity for a systematic procedure. To show the advantage of this approach, we study a transition between two structural regimes in a molecular uid in a porous media model and document the applicability of an important tool, namely the Legendre-Fenchel transform.
Several problems arise for systems dependent on size and shape. To which extent can we still use the thermodynamic tools on nanoscale systems that apply to macroscale systems? When additional independent variables are needed in the Gibbs equation, from which pool do we draw them and how?
The free energies of a molecular uid in a slit pore will be investigated at two conditions; at constant volume and constant normal pressure. In the rst case, the system is in the canonical ensemble, and in the second case, the system is in the isobaric ensemble. In the thermodynamic limit, where the free energy is convex, we can transform the free energy from one ensemble to another using the Legendre transform. For small systems, this is not always the case. However, in the case of polymer stretching, we have recently found that the Legendre-Fenchel transform can be used. 17 This experience has led us to wonder whether Legendre-Fenchel transforms can be used also for uids conned to the slit pore, thereby motivating this paper. In the isochoric ensemble, the volume of the slit pore is controlled, and we will consider this as a simple model of a non-deformable porous medium. In the isobaric ensemble, the pore normal pressure is controlled, and the pore volume can uctuate. We will consider this as a simple model of a deformable porous medium.
The paper is outlined as follows. We give the theoretical background in Section 2, including the Legendre-Fenchel transform in Section 2.1. We proceed to present the simulation technique in Section 3 and show in Section 4, that the Helmholtz energy of an isochoric slit pore can be transformed into the Gibbs energy of an isobaric slit pore using the Legendre-Fenchel transform. The ndings are discussed and perspectives are pointed out. In short, we shall see that systems that are small in Hill's sense have additional transitions than the bulk systems have. The system is more restricted when we control the uid height than when we control the normal pressure.

System description
We investigate a single-phase uid in a slit pore. This can be seen as a simple model suited to bring out the features described above. The system consists of a uid placed between two parallel solid walls, see Fig. 1. The system has periodic boundary conditions in the y-and z-directions. In the canonical ensemble, the walls do not move, while in the isobaric ensemble, the top wall can move in the x-direction and will act as a piston with controlled normal pressure on the uid.
In the canonical ensemble the volume of the system is controlled, and the normal pressure P uctuates. In the isobaric ensemble, the normal pressure P is controlled, and the volume V ¼ L 2 h ¼ Ah uctuates, where A ¼ L 2 is the uid-solid surface area of one of the walls. The side lengths in the y-and z-directions are xed equal to L, and it is only the distance between the walls h (height) that uctuates. The side lengths L are much larger than the height such that the system may be considered to be independent of the surface area A.

Theory
In the canonical ensemble, the Helmholtz energy describes the maximum obtainable work of the system. The total differential of the Helmholtz energy is where N is the number of uid particles, T is the temperature, S is the entropy, P is the normal pressure, A is the uid-solid surface area, g is the uid-solid surface tension and m is the chemical potential. In the isobaric ensemble, it is the Gibbs energy that describes the maximum obtainable work of the system. The total differential of the Gibbs energy is Fig. 1 The fluid is placed between two parallel solid walls. The walls are separated by a distance h (height) and the side lengths of the walls are L. In the canonical ensemble the height h is controlled and the normal pressure P fluctuates, while in the isobaric ensemble the normal pressure P is controlled and the height h fluctuates.
dG(N,P,A,T) ¼ ÀSdT + AhdP + 2gdA + mdN. (2) The normal pressure and height are dened in terms of the free energies as The difference in the specic Helmholtz energy Df ¼ F/M, where M is the total mass of the uid, is calculated by integrating the mean normal pressure as a function of the volume in the canonical ensemble where hPi is the mean normal pressure. Similarly, the difference in the specic Gibbs energy Dg ¼ G/M is calculated by integrating the mean height as a function of the normal pressure in the isobaric ensemble Dg ¼ gðN; P; A; TÞ À gðN; P 0 ; A; TÞ ¼ A M where hhi is the mean height, and f 0 ¼ f(N,h 0 ,A,T) and g 0 ¼ g(N,P 0 ,A,T) are reference states at a large height h 0 and low pressure P 0 . The difference in the specic entropy of the system in the isochoric ensemble is where Du is the change in the specic internal energy of the system. The changes in specic entropy and internal energy are relative to a system at height h 0 .

The Legendre-Fenchel transform
In the isobaric ensemble, the control variables are temperature T, normal pressure P, and the number of uid particles N. The normal pressure is equal to the absolute force acting on the walls divided by the surface area A. This is equal to the normal component of the mechanical pressure tensor of the uid. 3 The isobaric partition function can be obtained by a Laplace transform of the canonical partition function Z ðN; P; A; TÞ ¼ bPA where Z(N,h,A,T) is the canonical partition function and b ¼ (k B T) À1 where k B is the Boltzmann constant. The Helmholtz and Gibbs energies are given by the corresponding partition functions and GðN; P; A; TÞ ¼ Àk B T ln Z ðN; P; A; TÞ; respectively. From the three equations above it follows that the Gibbs energy can be obtained from the Helmholtz energy, exp½ ÀbGðN; P; A; TÞ ¼ bPA For sufficiently high surface number densities G ¼ N/A, the system is large and the Helmholtz energy F is a differentiable and convex function of the height, and the above expression reduces to the Legendre transform of the Helmholtz energy to the Gibbs energy, For low surface number densities G, the system is small, and the Helmholtz energy is non-convex and the integral in eqn (10) does not reduce to the Legendre transform. If the distribution of the normal pressure is sharply peaked it can however be calculated with a saddlepoint approximation, 17,20,21 This is the Legendre-Fenchel (LF) transform of the Helmholtz energy F to the Gibbs energy G LF . The LF transform returns only convex functions. If we apply it again, we obtain the convex envelope of the Helmholtz energy F**. The convex envelope is the largest function satisfying F** # F, which is only equal to the original Helmholtz energy F if it is a convex function. In other words, the LF transform is not selfinverse if the function is non-convex. 20,21 The LF transform can be dened as either the maximum or minimum. Since G LF must be convex, we can also obtain F** from a Legendre transform of G LF .
The Maxwell construction of equal areas for liquid-vapor coexistence is equivalent to the convex envelope of the Helmholtz energy F**. The equal area rule states that for a liquidvapor coexistence the system follows a constant pressure P eq from volume V l to V g when the system evaporates, and conversely for condensation. The two volumes V l and V g at the pressure P eq are the binodal points of the pressure-volume curve. The equal area rule states where P(V) is a cubic equation of state, for example, the van der Waals equation, below the critical point. This corresponds to nding the double tangent line of the non-convex Helmholtz energy. The double tangent line is a tangent of the function at two different points. A double tangent line does not exist for convex functions. The double tangent line is exactly the convex envelope, as it is the largest function that satises F** # F.
A uid between two parallel solid walls in the canonical and the isobaric ensemble was investigated with molecular dynamics simulations using LAMMPS. 22,23 The temperature of the uid was controlled using the Nosé-Hoover thermostat to T ¼ 2.26T c ¼ 23/k B , where T c ¼ 0.885 is the critical temperature of the bulk uid. 24 The temperature was controlled above the critical point to avoid the liquid-vapor coexistence region. The walls were made up of solid particles in a face-centered cubic lattice with a number density n * s ¼ 1=s 3 corresponding to a lattice constant a ¼ 2 2/3 s, where s is the uid particle diameter. Each wall had N p ¼ 5 Â 10 4 solid particles and side lengths L ¼ 100a z 159s. Each solid particle had a mass equal to the uid particle mass, implying that the mass of the top solid wall (piston) was 5 Â 10 4 times greater than a uid particle. The mass of each particle were equal to m, which in reduced units is equal to one. The total mass of the uid particles were M ¼ Nm.
In the canonical ensemble, the solid particles were xed in space and could not move. In the isobaric ensemble, the solid particles in the lower wall were xed in space, while the solid particles in the piston were free to move as a single rigid body in the x-direction. The piston could not rotate or move in the y-or z-directions. The uid particles were placed between the walls. The system is visualized in Fig. 2 using OVITO. 25 The uid particles are drawn in red and the solid particles are drawn in blue. The simulation box had periodic boundary conditions in the y-and z-directions.
The uid-uid and uid-solid particles interacted with the Lennard-Jones/spline potential, 24 where r ¼ jr j À r i j is the distance between particle i and j, s is the particle diameter, and 3 is the well-depth of the interactions. The parameter r s ¼ (26/7) (1/6) s z 1.24s is the inection point of the Lennard-Jones potential, and the parameters a ¼ À24 192/ 3211(3/r s 2), b ¼ À387 072/61 009(3/r 3 s ) and r c ¼ 67/48r s z 1.74s were set such that the potential energy and the force were continuous and smooth at r s . The potential is suitable to model noble gases or methane. An advantage of the Lennard-Jones/ spline potential is that the cut-off is much shorter than the regular Lennard-Jones potential with a typical cut-off at 2.5s, which considerably decreases the computation time. See for more details on the properties of the Lennard-Jones/spline potential the work of Hafskjold et al. 24 and Kristiansen. 26 The uid-uid and uid-solid interactions were equal, while the solid-solid interaction was zero. The size of the timesteps was set equal to dt ¼ 0.002. All units are in reduced Lennard-Jones units, meaning that they are reduced with the mass, particle diameter s, the minimum of the interaction potential 3, and the Boltzmann constant k B . The Lennard-Jones/spline potential is suitable to model argon or methane. However, we do not.
The system was initialized by creating one slab of uid particles between two slabs of solid particles, all in a facecentered cubic lattice. The uid particles were initialized with a velocity such that the temperature was equal to T ¼ 23/k B , and they were free to move for 10 4 timesteps to melt the facecentered cubic lattice of the uid. In the canonical ensemble, the piston was moved with a constant velocity for 10 5 timesteps to reach the desired height h, from here on dened as the minimum distance between the center of a solid particle in the bottom solid wall and the center of a solid particle in the piston. The controlled height was in the range h˛[1.7, 110]s. Then the position of the piston was xed, and the system was run for 10 6 timesteps to calculate the mean normal pressure, hPi.
The mean normal pressure was calculated as the arithmetic mean of the instantaneous forces of the particles in the piston at time t at time intervals where f x,i,t is the force in the x-direction acting on the solid particle i in the piston at time t, N p is the number of solid Paper Nanoscale Advances particles, and n ¼ 10 6 (dt/Dt) ¼ 10 4 is the number of samples where dt is the size of the timestep. Alternatively, the normal pressure could be calculated as the normal component of the mechanical pressure tensor in the uid. 3 This has been done as a consistency check.
In the isobaric ensemble, an external force was added to the piston aer melting the face-centered cubic lattice of the uid. The simulations with controlled normal pressures were run sequentially from low to high normal pressure to obtain the compression curve, and from high to low normal pressure to obtain the expansion curve. This was done to reach all available states of the system in the isobaric ensemble. The controlled normal pressures were in the range P˛[0.0045, 25]3/s 3 . Each of the simulations was run for 10 6 timesteps to calculate the mean height hhi.
An external force f x in the x-direction was applied to each solid particle in the piston, where N p is the number of particles in the piston. The mean height hhi was calculated as the arithmetic mean of the instantaneous height at time t at time intervals of Dt ¼ 0.
The mean of the specic internal energy was calculated as the mean potential energy plus the mean kinetic energy of the uid particles, where v i is the velocity of particle i, m is the mass of each uid particle and M ¼ Nm is the total mass of the uid particles. The specic internal energy was used together with the specic Helmholtz energy to calculate the specic entropy. The reference states f 0 , u 0 , and s 0 were calculated at height h 0 ¼ 110s 0 , and g 0 was calculated at pressure P 0 corresponding to a mean height hh 0 i ¼ 110s 0 .

Results and discussion
The results are illustrated in Fig. 3 to 10. Fig. 3 shows the normal pressure-height relationship in isochoric conditions for various surface number densities. To investigate that the results are independent of the surface area, we have simulated a system with a surface area four times larger (results not shown). We found that the results were independent of the surface area. Fig. 4 to 6, give the specic internal energy, difference in specic entropy, and difference in specic Helmholtz energy, respectively, all properties as a function of a controlled height. The difference in specic entropy and Helmholtz energy are given as the difference relative to the reference state at h 0 ¼ 110s. Fig. 7 visualises two cases in isochoric conditions when close to hexagonal packing appears.
The impact of the choice of environmental control variables on the normal pressure-height relationship, the basis of the ndings reported, is illustrated in Fig. 8. This provides a basis for examination of Legendre and the Legendre-Fenchel transforms, see Fig. 9 and 10. The various results will now be explained and discussed.

The normal pressure, specic internal energy, entropy, and Helmholtz energy as a function of height
The normal pressure-height relationship as a function of height and for various number densities was presented in Fig. 3. The thermodynamic limit behavior is seen for large heights or large surface number densities. The large system has a differentiable convex Helmholtz energy, approximately when the height h > 3s and when the surface number densities are G $ 1.18. The typical small system behaviour appears for heights h < 3s and surface densities G < 1.18.
For smaller heights or surface number densities, the normal pressure goes through a local minimum and maximum as the height changes. This implies that the Helmholtz energy is nonconvex. The specic internal energy has also a minimum, see    4. The entropy is monotonically increasing, except for the case G ¼ 1.18 which has a local minimum, see Fig. 5. The Helmholtz energy in Fig. 6 captures the trade-off between the internal energy and the entropy. The Helmholtz energy as a function of height is non-convex for surface densities G < 1.18, which entails that the Legendre transform can not be applied. The insert in Fig. 6 magnies the interesting region. The emerging structures are stabilized by the ability of the system to go to lower energy and higher entropy. The curves indicate a smooth structural transition. Fig. 3 to 6 showed a family of curves that represent the small system in a transition region for small values of h. This transition is special for a small thermodynamic system, it disappears when surface number density increases. The top panel in Fig. 7 illustrates the uid particles at height h ¼ 2 2/3 s z 1.59s and surface number density G ¼ 0.22. The uid particles cluster together and form dense patches. How can we understand better the behavior of the particles in this region?

A small system phase transition
For the system to change from a uid to a close-packing structure (face-centered cubic or hexagonal close-packed) without defects, the surface number density G must be where k is the number of layers (for a monolayer k ¼ 1) and r is the distance between the uid particles. The total potential energy is at a minimum at the distance r ¼ 2 1/6 s z 1.12s, which is where the Lennard-Jones/spline interaction potential is at a minimum. The interaction potential is short-ranged, it is zero for distances larger than the cut-off at r c z 1.74s. The surface number density for a monolayer (k ¼ 1) is G z 0.79, and for a double layer (k ¼ 2) it is G z 1.59. An odd number of layers can complete the face-centered cubic lattice of walls without faults, while an even number of layers must have an odd number of stacking faults. In the extreme case of a monolayer, we assume that the uid is packed in such a way that each uid particle lies on average at a distance r 0 ¼ 2 1/6 s away from eight solid particles and four uid particles. In addition, there are two solid particle neighbours and four uid particle neighbours each at a distance r a ¼ 2 2/3 s. All other particles lie beyond the cutoff distance r c and do not contribute to the potential energy.
The minimum specic potential energy of a monolayer is then   where m is the particle mass. Taking into account thermal uctuations, it is where a is a constant. Assuming no defects, the average deviation from the average position can be set to zero. The quadratic term represents the lowest order correction to the mean specic potential energy due to thermal uctuations making the uid particle spend on average more time away from the average position. By the equipartition theorem, we then obtain the mean potential energy of a uid particle e p ¼ e p;0 þ 3 2 k B T z À7:393=m: The expected minimum mean specic internal energy is the sum of the mean specic potential and kinetic energies where we have used that the mean specic kinetic energy is The observed minimum of the specic internal energy for G ¼ 0.79 is indeed hui ¼ (À4.39 AE 0.03)3/m at h ¼ 2 2/3 s z 1.59s, see Fig. 4. The simulated structure is visualised in the bottom panel of Fig. 7. The gure shows that the uid particles have formed a hexagonal monolayer layer. The mean normal pressure is hPi ¼ (9.4 AE 0.1)3/s 3 , difference in the specic entropy hDsi ¼ À9.7k B /m, and difference in specic Helmholtz energy is hDfi ¼ 11.43/m. The specic internal energy is at a minimum at this height, however, the Helmholtz energy is not.
A transition from a uid to a close-packed structure under stress does not imply a rst-order phase transition, a continuous transition from a uid to a close-packed structure packing may occur. In other words, the free energy can be smooth and continuous during the transition.
Consider for comparison the familiar pressure-volume isotherms of cubic equations of state, for example, the van der Waals equation, for temperatures below the critical point. The Helmholtz energy is a non-convex function of volume. The binodal curve intersects the pressure-volume isotherms at two points a ¼ (p eq , V l ) and b ¼ (p eq , V g ) for T < T c . The part of the isotherm between point a and b is known as the van der Waals loop. The Helmholtz energy is a non-convex function in this region. The line between the points a and b corresponds to the Maxwell construction of equal areas. See eqn (14). The double Legendre-Fenchel transform of the specic Helmholtz energy f gives its convex envelope f**, which corresponds to the Maxwell construction of equal areas. The spinodal curve intersects the isotherm at the local minimum and maximum, the spinodal region is a subset of the binodal region. The binodal region is metastable, while the spinodal region is unstable. Experimentally it is observed that uids do not necessarily follow the van der Waals loop, but rather the straight line connecting points a and b. This is a rst-order phase transition, as the pressure is non-smooth at the points a and b. The system is free to decompose in the binodal and spinodal region, which is energetically more favorable. During liquid-vapor phase decomposition the pressure is constant and equal to P eq . The constant pressure corresponds to the double tangent line in the free energy. This double tangent line is the largest convex curve that satises f** # f, which is exactly its convex envelope.
The states in the binodal and spinodal regions can be stable due to the restrictions that the connement imposes on the system. The coexistence of uid and close-packed structures is not possible in these simulations, as this would imply that there would be regions with differing heights. This could be possible if the walls were free to rotate or deform, however, the system is restricted such that the height is everywhere the same. In isochoric conditions, there is a smooth transition from a uid to a close-packed structure. In isobaric conditions, the system is less restricted, and the system undergoes a rst-order phase transition when it enters the spinodal region, see Fig. 8 (center). This is because the spinodal region is unstable. The set of control variables provide different stable states with their different restrictions on the system.

Response functions
In the isobaric conditions, it is useful to consider the response function where K N,T /Ah is the isothermal compressibility. 27 As the states with negative K N,T cannot be stable under height uctuations, K N,T is restricted to be non-negative. This can be seen in Fig. 8, where the states with negative K N,T in isochoric conditions are not available in isobaric conditions. The region with negative compressibility (positive slope) corresponds to the spinodal region, which is the region between the local minimum and maximum. In the isochoric ensemble, the height is a control variable, and states with negative isothermal compressibility can be realized. In other words, the response function can be negative. This can be seen in Fig. 8. The function g LF (N,P,A,T) presents two non-smooth points, indicating a rst-order phase transition. The isothermal compressibility in isochoric conditions is negative, and is well dened in all available states. In isobaric conditions, the isothermal compressibility is undened when the free energy is non-smooth. It is well dened and non-negative for all other states. The reason for this is that the normal pressure is increased by applying a directed force that seeks to compress the system. If the system was to increase its volume in response to this compression force, the uid center of mass would have to move in the direction opposite to the applied force, thus violating conservation of linear momentum.

4.4
The specic Gibbs energy as a function of normal pressure. Legendre-Fenchel transforms Fig. 8 presents the normal pressure-height relationships for isochoric and isobaric conditions. The states available for the system to follow in isochoric conditions are blue, while isobaric conditions provide states given by the orange and green curves. The orange curve is for isobaric compression and the green curve is for isobaric expansion. Once the maximum in a curve is reached during isobaric compression, the system will switch to a smaller height. Alternatively, by isobaric expansion all points near the minimum become accessible. The dotted line is the height computed from the derivative of the Legendre-Fenchel transform g LF with respect to the normal pressure P, see eqn (3). This curve gives the Maxwell construction of equal areas, or in other words the straight line across the van der Waals loop or the binodal region. For isobaric conditions, the system is metastable in the binodal region and unstable in the spinodal region.
The specic Gibbs energy is presented in Fig. 9 and 10 as a function of normal pressure and height, respectively. For the  At lower surface number densities, the Legendre transform ceases to apply. But we can still understand the system in terms of its thermodynamic properties. The normal pressure-height curves form a van der Waals loop for isochoric conditions. The specic Gibbs energy from compression differs from that of expansion for isobaric conditions. The Legendre-Fenchel transform (dotted curve) follows the Legendre transform (blue curve), except in the van der Waals loop, which is cut out by the Legendre-Fenchel transform.
The underlying distribution of normal pressures in the isochoric conditions is highly peaked, implying that the conditions for the saddlepoint approximation, necessary for the Legendre-Fenchel transform, are obeyed. The small error bar in the normal pressure, which is the standard deviation, testies to this, see Fig. 8. The mean relative standard deviation is 1.1%, 0.4%, 0.09% for G ¼ 0.22, G ¼ 0.81, and G ¼ 1.18, respectively.
The results of the slit pore simulations show that structural changes are more restricted when in isochoric conditions than in isobaric conditions. The ndings are similar to observations of polymer stretching. 16 Also here a transition was found between states. But then the different regimes referred to the type of degrees of freedom of the molecule (active or frozen rotational or stretching degrees of freedom). 16,17 We have seen that the Legendre-Fenchel transforms apply to two widely different cases, so we may pose the question: Does the transform apply in general to energy conversion in small systems? From the mathematics point of view, this seems likely. 28,29 More data is needed before we may conclude, but this study brings out an interesting perspective. If the answer is yes, we may have a new tool for energy conversion in small systems.
When the Helmholtz energy is non-convex in the isochoric ensemble the system exhibits hysteresis in the isobaric ensemble. Hysteresis means that the state of the system depends on the system's history. The specic Gibbs energy depends on whether the system comes from a compressed or expanded state. In the isobaric ensemble, available states can be explored by rst compressing and then expanding the system. One of the two available states at the same controlled normal pressure in the compression and expansion curves are metastable, the other state is stable. The Legendre-Fenchel transform gives the stable states. Since the piston cannot deform the energy barrier to go from a metastable state to a stable state is high, which is the reason for the pronounced hysteresis in this system. The loop created in the specic Gibbs energy prole in isobaric conditions is interesting. The existence of a loop means in principle, that work can be extracted from the loop by only two steps, namely compression, and expansion. The slit pore may serve as a very rst model for deformable porous media in this context.

Conclusions and perspectives
The normal pressure varies with the height of the slit pore. The excess normal pressure, the normal pressure minus the bulk pressure, is oen called the disjoining or solvation pressure. 3,19 The disjoining pressure is typically dened in the grand canonical ensemble (an open system). The disjoining pressure oscillates with a period equal to the uid particle diameter because of the uid packing between the walls. The mechanism of the excess normal pressure is the same here as for an open system, but the behaviour of the normal pressure observed in the closed system is different than for an open system. The observation of disjoining pressure is not new, see for example the work by Israelachvili. 19 In the height-controlled system, there is no rst-order phase transition. We observe a smooth transition from a uid to a close-packed structure with oscillating normal pressure, in a manner similar to disjoining pressures. Disjoining pressures have been observed in simulations as well as by experiments. However, Israelachvili does not apply thermodynamics and the machinery that follows it. In this work, we have expanded upon the work by Israelachvili and others by giving a thermodynamic description. As a result, we get additional relations that can be used, for example, Maxwell relations.
In isochoric conditions, there is a smooth transition from a uid to a close-packed structure. The Helmholtz energy of this smooth transition is non-convex for small surface number densities. The system is restricted in such a way that there must be a smooth transition. It is not possible for the system to have coexistence of a uid and a close-packed structure because that would imply that the system could have two different heights at the same time. A possible future generalization of this work could be to allow the solid walls to deform in a less restricted manner such that it would be possible for the system to have varying heights. In this way the system might allow for coexistence of a uid and a close-packed structure. We hypothesize that the hysteresis in such a system will be less pronounced. Vapor-liquid coexistence is not restricted in this way, the vapor and liquid can have two different volumes. Since the height is controlled, the system is restricted to that height. However, the normal pressure is controlled in isobaric conditions. As a result, there is a rst-order phase transition from a uid to a closepacked structure for small surface number densities. There is no coexistence of uid and close-packed structure for the same reason as for isochoric conditions. The Legendre transform does not apply to non-convex free energies, and we have shown the Legendre-Fenchel transform must be applied.
Small systems in Hill's sense are not extensive. The system is large in the surface area A, and small in the height h. They are characterized by giving different responses to their ensemble of control. In the present case, we have studied and compared two small systems, i.e. isochoric and isobaric uids conned to slit pores. Despite their smallness, we have found that they are perfectly well describable by thermodynamics when the theory is adjusted to deal with smallness. One such adjustment means to use Legendre-Fenchel transforms, rather than Legendre transforms. Doing that, we have shown that the specic Helmholtz energy can be transformed into the specic Gibbs energy. The ndings are general, and support the systematic approach of Hill for descriptions of other small systems.

Author contributions
O. G. contributed to formal analysis, investigation, methodology, soware, and visualisation. D. B. and S. K. contributed by supervision. All authors contributed to conceptualization, writing original dras, reviewing, and editing. All authors have read and agreed to the published version of the manuscript.

Conflicts of interest
There are no conicts to declare.