Geometric Modeling for Control of Thermodynamic Systems

This paper discusses the way that energy and entropy can be regarded as storage functions with respect to supply rates corresponding to the power and thermal ports of the thermodynamic system. Then, this research demonstrates how the factorization of the irreversible entropy production leads to quasi-Hamiltonian formulations, and how this can be used for stability analysis. The Liouville geometry approach to contact geometry is summarized, and how this leads to the definition of port-thermodynamic systems is discussed. This notion is utilized for control by interconnection of thermodynamic systems.


Introduction
Since the early 1970s [1] contact geometry has been recognized as underlying macroscopic thermodynamics, starting from Gibbs' fundamental thermodynamic relation. This has spurred a series of papers on the geometry of thermodynamics; including ; see [28] for an introduction and survey. Nevertheless, this literature points to major differences with, for example, the geometric theory of classical mechanics (using symplectic geometry), and hints at aspects which have not yet been addressed. First, the thermodynamic phase space (which is formulated as a contact manifold) comprises the extensive and intensive variables, and thus, its dimension is more than twice the minimal number of variables to describe the thermodynamic system at any moment of time. Second, most of the theory is about thermostatics, and the proper geometric formulation of the dynamics is much less clear. Third, the contact geometric approach to thermodynamics is usually based on the energy representation of thermodynamic systems and its corresponding Gibbs one-form. On the other hand, there is also the entropy formulation which corresponds to another (although conformally equivalent) one-form. This led [29] to the use of homogeneous coordinates for the intensive variables, and thus to extend the thermodynamic phase space by one more degree of freedom. This was followed up in [25,26] by emphasizing the formulation of the thermodynamic phase space as the projection of the cotangent bundle over the space of extensive variables. Thus contact geometry is approached from the vantage point of the geometry of cotangent bundles with their Liouville one-form. Fourth, until now, not much work has been performed regarding the geometry of irreversible thermodynamics, based on the factorization of the irreversible entropy production. Fifth, how to use these geometric frameworks for the control of thermodynamic systems has not yet been addressed.
The present paper continues the investigation of all of these aspects. In Section 2, a systems and control perspective on macroscopic thermodynamics is emphasized by primarily regarding thermodynamic systems as systems interacting with their surroundings via heat, mechanical work, exchange of chemical species, etc. A classical example is, of course, the heat engine. A summary of how dissipativity theory provides a natural framework for interpreting and formulating the first and second laws of thermodynamics, Clausius' inequality, and eventually entropy is provided. Indeed, energy and entropy reveal themselves to be the storage functions corresponding to two supply rates involving the thermal and mechanical ports of the thermodynamic system. Finally, this leads to Gibbs' fundamental relation and to the definition of the thermodynamic phase space. Section 3 focuses on geometric descriptions of irreversible thermodynamic systems. The way that the classical factorization of the irreversible entropy production suggests quasi-Hamiltonian formulations (somewhat resembling GENERIC [30]) based on energy conservation and the increase of entropy of the autonomous part of the dynamics are discussed. This paper also indicates how such formulations may be used for stability analysis. Section 4 starts with the geometry of the thermodynamic phase space from the point of view of the Liouville geometry of the cotangent bundle over the space of extensive variables. Identifying the constitutive relations ('thermostatics') of the thermodynamic system as a Liouville submanifold, and the dynamics as homogeneous Hamiltonian dynamics lead to the definition of a port-thermodynamic system. Such systems interact with their environment via power ports and/or entropy flow ports. In Section 5, this is used for 'control by interconnection' of port-thermodynamic systems, where the dynamics of the system are sought to be controlled by interconnection with a suitable controller port-thermodynamic system. Finally, Section 6 contains conclusions and a discussion of venues for further research.
The sections are illustrated by three running examples: the gas-piston-damper system, chemical reaction networks, and the heat exchanger. Overall, the paper heavily builds upon previous papers [25,26,[31][32][33][34], in which further details and background can be found.

The First and Second Law from the Point of View of Dissipativity Theory
The first law of thermodynamics expresses two fundamental properties: (1) the different types of interaction of a thermodynamic system with its surroundings (e.g., heat flow, mechanical work, flow of chemical species, etc.) all result in an exchange of a common quantity called energy, (2) there exists a function of the macroscopic thermodynamic variables that represents the energy stored in the system, and the increase of this function during any time interval is equal to the sum of the energies supplied to the system during this time interval by its surroundings (conservation of energy). Thus, energy manifests itself in different physical forms, which are equivalent and to a certain extent exchangeable. 'To a certain extent' because, as expressed by the second law of thermodynamics, there are limitations to the conversion of heat to other forms of energy.
The first law can be mathematically formulated through the use of dissipativity theory as formulated in [35]; see also [31,36,37]. Consider a simple thermodynamic system such as a gas, described by three variables: volume V, pressure P, and temperature T. Then, mechanical power (rate of mechanical work) provided by the surroundings to the thermodynamic system is given by −Pu V , where u V :=V is the rate of volume change. (In the physics convention for the pressure P, Pu V is the rate of mechanical work exerted by the system on the surroundings). The second type of interaction with the surroundings comes from heat delivered to the system (for instance, from a heat source). Let us denote, using q, the heat flow (heat per second) from the heat source into the system. Then the first law is expressed by the existence of a function E(x) of the thermodynamic state x (e.g., (V, P, T) satisfying the equation of state), expressing the energy of the system and satisfying, at all That is, the increase of the total energy E of the thermodynamic system is equal to the incoming heat flow (through the thermal port) minus the mechanical work performed by the system on its surroundings (through the mechanical port). Equivalently, in the terminology of dissipativity theory, the first law amounts to the system being cyclo-lossless for the supply rate q − Pu V , with storage function E. This is directly extended to more involved thermodynamic systems. For example, suppose that apart from mechanical and thermal interaction with the surroundings, there is additional mass inflow of chemical species. Then, the supply rate q − Pu V is extended to q − Pu V + ∑ k µ k ν k . Here, ν k = dN k dt , with N k the mole number of the k-th chemical species, and µ k its chemical potential.
The first law emphasizes the role of thermodynamic systems as devices for energy conversion; energy from one physical domain is converted into energy in another domain. 'Optimal' conversion of heat into mechanical work, motivated by the design of steam engines in the beginning of the 19th century, was one of the starting points of thermodynamic theory. Electro-chemical devices such as batteries, and electro-mechanical systems including electrical motors and generators, are among the many other classical examples of energy-converting devices [38]. On the other hand, almost from the very start of thermodynamic theory, it was realized that there are intrinsic limitations to energy conversion. In particular, heat cannot just be converted into mechanical work. This is the origin of the second law of thermodynamics. The second law also admits a dissipativity interpretation; however, more involved than that of the first law. Let us start with the formulation of the second law, as given by Lord Kelvin (see [39]): A transformation of a thermodynamic system whose only final result is to transform into work heat extracted from a source which is at the same temperature throughout is impossible.
Since the work done during a time interval [t 1 , t 2 ] is equal to Kelvin's formulation immediately implies that for each constant temperature T, any thermodynamic system is cyclo-passive with respect to the supply rate −Pu V . However, the second law is stronger than that. Namely, Kelvin's formulation also forbids the conversion into work of heat from a source at constant temperature for all transformations in which the system interacts as well with a second heat source at another temperature, as long as the net heat taken from this second heat source is zero. As demonstrated by Carnot, the interaction with heat sources at different temperatures is crucial for the conversion of heat into mechanical energy. This led to the famous Carnot cycle which can be described as follows: consider a simple thermodynamic system, in particular, a fluid or gas in a confined space of a certain volume. Control of the system functions in two ways: (1) via isothermal transformations, where heat is supplied to, or taken from, the system at a constant temperature (classically described as the interconnection of the thermodynamic system with an infinite heat reservoir at the temperature of the isothermal process), (2) via adiabatic transformations, where the only interaction with the surroundings is via work supplied to, or taken from, the system (classically described by the movement of a piston that changes the volume of the system, with a pressure equal to the pressure of the gas). A cycle consists of two isothermal transformations and two adiabatic transformations: first, an isothermal transformation at temperature T h ('hot') takes the system from an initial state to another state, secondly, an adiabatic transformation lowers the temperature of the system to T c ('cold'), thirdly, an isothermal transformation at temperature T c takes the system to a state from which, fourthly, an adiabatic transformation takes the system back to the original initial state; see Figure 1. The cycle is called a Carnot cycle if it is reversible; i.e., can be traversed in the opposite direction as well.

Remark 1.
In the exposition of the Carnot cycle, often terminologies such as 'infinitesimally slow', 'quasi-reversible', 'quasi-static', etc., are used. This is largely with regard to the interaction of a system with its surroundings as being implemented by actual physical devices. For example, an isothermal transformation is viewed as the result of the 'real' physical action of a force exerted by a piston on the gas (implying that the pressure delivered by the piston could be different from the pressure of the gas). Furthermore, the system is considered to be in 'real' physical contact with a heat reservoir at a certain temperature (which could differ from that of the gas). In contrast in, e.g., electrical network theory and control theory the concept of an 'ideal' control action is employed, where, for instance, the pressure and the temperature are directly controlled.
The heat delivered to the system during the first isothermal at temperature T h is denoted by Q h , and during the second isothermal at T c by Q c (generally Q c is negative). Then, by the first law, since the final state is equal to the initial state, Q h + Q c = W, where W = PdV is the mechanical work that is done by the thermodynamic system on its surroundings.
By an intricate reasoning from [39], see also [31], Kelvin's formulation of the second law yields for any cycle the fundamental inequality with equality in the case of a Carnot cycle. Furthermore, the reasoning can be extended to complex cycles, consisting of n isothermals at temperatures T i and absorbed heat quantities Q i , i = 1, 2, · · · , n, interlaced by n adiabatics, leading to with equality in the case of reversibility. Finally, a slight extension (approximating continuous heat flow time-functions q(·) by step functions with step values Q 1 , · · · , Q n ) yields the celebrated Clausius inequality q(t) for all cyclic processes q(·), T(·) (where q is the heat flow into the thermodynamic system, and T is the temperature of the system), with equality holding for all reversible cyclic processes (see [31] for details and refinements). From the point of view of dissipativity theory [31,35] the Clausius inequality (4) is the same as cyclo-dissipativity of the thermodynamic system with respect to the supply rate − q T . Thus, assuming reachability from and controllability from some ground state x * this means, see [40], that there exists a storage function F for the supply rate − q T , that is d The function S was called 'entropy' by Clausius, from the Greek word τρoπη for 'transformation'.
From the point of view of dissipativity theory, the storage function F need not be unique. In order to guarantee the uniqueness of F (modulo a constant), and therefore of the entropy S, we additionally assume [31,40] that, given some ground state, for every thermodynamic state there exists a reversible cyclic transformation through this state and the ground state satisfying q(t) T(t) = 0 This uniqueness of S is, explicitly or implicitly, always assumed in expositions of macroscopic thermodynamics, and also in this paper.

Remark 2.
The dissipativity theory formulation of the second law already appears in [35], but under the additional assumption that F is nonnegative. In fact, in [35,37] there exists a nonnegative storage function for the supply rate − q T (and thus the system is dissipative instead of merely cyclo-dissipative) if and only if for all initial conditions x where the supremum is taken over all τ ≥ 0 and all heat flow functions q(·) on the time interval[0, τ], and corresponding temperature profiles T(·) resulting from x(0) = x. Furthermore, if (8) holds, then F a ≥ 0 is minimal among all nonnegative storage functions. It follows that S a = −F a ≤ 0 given by is maximal among all nonpositive storage functions. Since an arbitrary constant may be added to S while still satisfying (6), the assumption that S is nonpositive is equivalent to S being bounded from above. However, in many thermodynamic systems the entropy is not bounded from above. Thus thermodynamic systems are generally only cyclo-dissipative with respect to the supply rate − q T , and not dissipative.

The Thermodynamic Phase Space and Gibbs' Relation
The next step is now to add the energy and entropy as extra extensive variables to the description of the thermodynamic system. In order to illustrate this, consider a simple thermodynamic system, with extensive variable V (volume) and intensive variables P, T (pressure and temperature). The equation of state is an equation f (V, P, T) = 0 for some scalar function f . (For example, for an ideal gas PV = RT with R the universal gas constant.) Any (V, P, T) satisfying f (V, P, T) = 0 is called a state of the thermodynamic system. Hence, under regularity conditions the set of states of the thermodynamic system is a 2-dimensional submanifold M of R 3 . Then, consider the functions E : M → R (energy) and S : M → R (entropy) as obtained from dissipativity theory. Then, we may equally well represent the set of states M ⊂ R 3 by the 2-dimensional submanifold L ⊂ R 5 comprising the total set of extensive and intensive variables R 5 : (With some abuse of notation, the extra variables E, S, are denoted by the same letters as used for the functions defined before.) The space R 5 of all extensive and intensive variables is called the thermodynamic phase.
Furthermore, by the first law d dt E = −P d dt V + q, while for any state there exists a path through this state and the ground state such that d dt E = −P d dt V + T d dt S. Taken together, this implies that the Gibbs one-form on the thermodynamic phase space R 5 defined as is zero restricted to L. This is called Gibbs' fundamental thermodynamic relation. The thermodynamic phase space, together with the Gibbs one-form, defines a contact manifold. Furthermore, a submanifold of the thermodynamic phase space R 5 restricted to which the Gibbs one-form (11) is zero, and moreover has maximal dimension (in this case 2), is called a Legendre submanifold. Gibbs' fundamental relation implies that any Legendre submanifold L is actually given as for some energy functions E(S, V). Thus, L is completely described by expressing the energy E as a function E(S, V) of the other two extensive variables S, V, hence the name energy representation. Instead of relying on such an energy function (or its partial Legendre transforms), there is still an alternative way of describing L. This is to start, not with E(S, V), but instead with the expression of the entropy as a function S(E, V). For a simple thermodynamic system this leads to the entropy representation of the submanifold L ⊂ R 5 given as

Irreversible Thermodynamics
Clausius interpreted the term q T in the inequality (6) as the part of the infinitesimal transformation d dt S that is compensated by the opposite rate of change − q T of the entropy of the surroundings; that is, of the reservoir supplying the heat to the thermodynamic system. The remaining part was called the 'uncompensated transformation' by Clausius, and later the irreversible entropy production [38]. Irreversible thermodynamics is concerned with thermodynamics where σ is different from zero, implying an autonomous (independent from external heat flow) increase of the entropy S. Sometimes it is also referred to as non-equilibrium thermodynamics, because the entropy increase is resulting from (internal) non-equilibrium conditions. The standard postulate of irreversible thermodynamics (see e.g., [38]) is that σ can be factorized as where F k are called the thermodynamic forces and J k are the thermodynamic flows (or fluxes), in such a way that In linear irreversible thermodynamics [38] it is furthermore assumed that the vectors F and J with components F k and J k , k = 1, · · · , s, are related by a symmetric linear map These are the celebrated Onsager reciprocity relations [38], corresponding to the symmetric factorization σ = F LF.
Example 1 (The heat exchanger). The perhaps simplest example of irreversible dynamics and irreversible entropy production is offered by the heat exchanger. Consider two heat compartments, having temperatures T h and T c ('hot' and 'cold'), connected by a heat-conducting wall. In the absence of the conducting wall (and thus, without irreversible entropy production), these are two separate systems with entropies S h and S c , each satisfying Due to the conducting wall, there is a heat flow q from the hot to the cold compartment, which is given by Fourier's law for heat conduction as q = λ(T h − T c ) for some positive constant λ. Furthermore, in view of the first law q = −q h = q c . Hence, the total entropy S := S h + S c satisfies This yields the following expression for the irreversible entropy production σ = d dt S due to heat conduction (non-equilibrium conditions) In this example the thermodynamic force is and only if, F = 0. Despite its simplicity, this is an example of nonlinear irreversible thermodynamics, since the thermodynamic flow q = λ(T h − T c ) cannot be expressed as a linear function of the thermodynamic force F = 1 Example 2 (The gas-piston-damper system). Another simple example is the gas-piston-damper system. Consider a cylinder containing a gas whose volume can be controlled by a piston actuated by an external force u, and is subject to linear damping. The total energy E of the system can be expressed as a function of the other extensive variables as with S representing entropy, V volume, π momentum of the piston with mass m, and U(S, V) representing the internal energy of the gas. Assuming that the heat as produced by the damping of the piston is fully absorbed by the gas in the cylinder, the dynamics are given aṡ with v = π m the velocity of the piston, A its area, d the damping constant, T = ∂U ∂S the temperature, and u the external force on the piston. The thermodynamic force F is identified as dv T and the thermodynamic flow as J = v. Clearly Onsager relations J = LF are satisfied with L = T d .

Example 3 (Chemical reaction network).
A third, more involved, example of irreversible thermodynamics are the dynamics of chemical reaction networks [34,41]. Consider an isolated (no incoming or outgoing chemical species, and no external heat flow) reaction network, with m chemical species and r reactions. Disregarding volume and pressure, consider the vector x ∈ R m of concentrations of the chemical species. The dynamics take the forṁ where v ∈ R r is the vector of reaction fluxes. The m × r stoichiometric matrix N, which consists of positive and negative integer elements, captures the structural balance laws of the reactions. Chemical reaction network theory, as originating from [42][43][44], identifies the edges of the underlying directed graph with the r reactions, and the nodes with the c complexes of the chemical reactions, i.e., the different left-and right-hand sides of the reactions in the network. This means that the stoichiometric matrix N is factorized as N = ZB, with B denoting the c × r incidence matrix of the graph of complexes, and Z denoting the m × c complex composition matrix (a matrix of nonnegative integers), whose ρ-th column captures the expression of the ρ-th complex in the m chemical species. It is shown in [45] that the dynamicsẋ = Nv(x) of a large class of chemical reaction networks (including detailed-balanced mass action kinetics networks) can be written into the compact forṁ where Exp is the vector exponential mapping Exp(z) = (exp z 1 , · · · , exp z c ) , R is the gas constant, T is the temperature, and µ is the m-dimensional vector of chemical potentials of the chemical species (for which e.g., in the case of detailed-balanced mass action kinetics explicit expressions are available). Furthermore, the matrix L := BKB in (24) defines a weighted Laplacian matrix for the graph of complexes, with the diagonal elements κ 1 , · · · , κ r of the diagonal matrix K, depending on the temperature T and the reference state. We have the following fundamental property [45] γ Expressing the entropy S as a function of x and the total energy E, Gibbs' fundamental relation with equality if, and only if, B Z µ = N µ = 0, i.e., if and only if the chemical affinities N µ of the reactions are all zero. Hence the equilibria of the system correspond to states of minimal (i.e., zero) entropy production σ, in accordance with the theory of irreversible thermodynamics [38]. The vectors of thermodynamic forces F and thermodynamic flows J are given as and indeed by (25) σ = 0 if and only if F = 0. Note that J cannot be expressed as a linear function of F and thus, in general, chemical reaction networks define nonlinear irreversible thermodynamics.

Quasi-Hamiltonian Formulation of Irreversible Thermodynamic Systems
Conservative mechanical systems are well-known to admit a Hamiltonian formulation. The same holds for many other physical systems. The Hamiltonian formulation of the dynamics of thermodynamic systems is, however, much more elusive. This has already studied and elaborated upon in, e.g., [16,24,41,46]. The present formulation emphasizes the factorization (15) of the irreversible entropy production.
Consider an isolated thermodynamic system with entropy S and energy E. Collect all other extensive variables in a vector denoted by z. The energy E can be expressed as a function E = E(z, S) of z and S. Now consider the irreversible entropy productioṅ S = σ = J F, with J the vector of thermodynamic flows and F the vector of thermodynamic forces. Often (as illustrated by the examples to be discussed), the thermodynamic force F can be expressed as C ∂E ∂z for some matrix C, whose elements are possibly depending on ∂E ∂z , ∂E ∂S , as well as on z, S. Note that ∂E ∂z equals the vector of intensive variables associated with the extensive variables z, while the intensive variable ∂E ∂S equals the temperature T. Energy conservation d dt E(z, S) = 0 together with d dt S(z, E) = J F suggests writing the dynamics of z and S into the form for some skew-symmetric matrix J , possibly depending on ∂E ∂z , ∂E ∂S and z, S. This implies that the extended matrix J e is also skew-symmetric, and thus indeed d dt E(z, S) = 0. Note however, that since the matrix J e may depend on the intensive variables ∂E ∂z , ∂E ∂S , it does not define a Poisson bracket on the state space with coordinates z, S. Therefore (28) will be called a quasi-Hamiltonian formulation. This is illustrated by the previously discussed examples of the gas-piston-damper system, chemical reaction network, and heat exchanger as follows.
Example 4 (Gas-piston-damper system continued). The dynamics of the gas-piston-damper system (22) can be written into the quasi-Hamiltonian form as (see also [41]) with v = ∂E ∂π = π m as the velocity of the piston and T = ∂E ∂S the temperature. The thermodynamic flow and force are J = v and F = d T v, respectively. Hence, J e is of the form as given in (28) with C = 0 d T . J e depends on the intensive variables T and v, therefore, it does not define a Poisson bracket.
Example 5 (Chemical reaction network continued). In the case of chemical reaction networks, the vector of thermodynamic forces is given as F = 1 T N µ = C ∂E ∂x with C = 1 T N, and ∂E ∂x = µ the vector of chemical potentials. Furthermore, according to (27) the vector of thermodynamic flows is given as J = KB Exp Z µ RT . This leads to the quasi-Hamiltonian representation Example 6 (Heat exchanger continued). The quasi-Hamiltonian formulation of the heat exchanger is slightly different. This caused by the fact that, in this example, we have two entropies, S 1 and S 2 , corresponding to the two compartments (and not a total entropy as in the previous two examples). In fact, the quasi-Hamiltonian formulation of the heat exchanger is given as (see [41]) since ∂E ∂S i = T i , i = 1, 2, and the heat flow from compartment 1 to 2 is given by q = λ(T 1 − T 2 ).
Here, we recognize 1 T 1 − 1 T 2 as the thermodynamic force.
A further structured form of quasi-Hamiltonian modeling of irreversible thermodynamic systems, called irreversible port-Hamiltonian systems, was introduced in [24]; see [41,46,47] for more developments and references.
A special case occurs if the total energy E(z, S) splits as for some thermal energy U(S) and remaining energy H(z). In this case, one obtains the equationsż If, furthermore, J = LF with L = L (Onsager's reciprocity relations) then the dynamical equations for the extensive variables z can be combined intȯ This is the standard internal dynamics of a port-Hamiltonian system with state vector z; see e.g., [37,48,49]. In this case, irreversibility means that, even though the total energy E(z, S) = H(z) + U(S) is preserved, the part of the energy given by H(z) is continuously transformed (by the resistive power flow TṠ) into the thermal energy U(S). Conversely, one can show [31] that any port-Hamiltonian system can be embedded into an energyconserving thermodynamic system. Example 7 (Mass-spring-damper system). A simple example is the ubiquitous mass-springdamper system. Its dynamics are very similar to that of the gas-piston-damper system, the difference being that the internal energy U(V, S) of the gas is replaced by the sum 1 2 kx 2 + U(S), where 1 2 kx 2 is the potential energy of the spring (with x denoting the elongation of the spring), and U(S) is the thermal energy of the system. This leads to the dynamics (compare with (29)) as well as the following port-Hamiltonian formulation of the mass-spring-damper system

Stability Analysis
The quasi-Hamiltonian formulation can be readily used for stability analysis. Note, however, that the conditions ∂E ∂z = 0, ∂E ∂S = 0 for E having a minimum often do not correspond to equilibria of interest. This is illustrated by the gas-piston-damper system, where these conditions correspond to pressure, velocity, and temperature all being equal to zero. Instead, in such cases it is of much more interest to consider the stability of steady states (V,π = 0,S) corresponding to a non-zero forceū delivered by the piston. In view of (29) and the energy expression E(V, π, S) = π 2 2m + U(V, S), this corresponds to the steady state condition (Note thatṠ = 0 is ensured byπ = 0 implying thatv =π m = 0, and thus corresponds to a singularity in the skew-symmetric matrix J e , instead of a vanishing of all the partial derivatives of E. In particular, the temperature T = ∂E ∂S at steady state will not be zero.) Instead of using E(z, S) as a candidate Lyapunov function which leads to the consideration of the availability function [50] (also called Bregman divergence or shifted Hamiltonian [37]) where P = − ∂U ∂V (S,V) andT = ∂U ∂S (S,V) are the pressure and temperature at steady state, for some arbitrary valueS. Indeed, using the steady state condition (37), a direct computation yields for all values of the temperature T > 0 and the steady state temperatureT > 0. Furthermore, given that for thermodynamic systems the internal energy U(V, S) (and therefore E(V, π, S)) is a convex function, E(V, π, S) is also convex with minimum atV,π = 0,S. Hence, if E(V, π, S) is strictly convex (which is often the case), then this proves the asymptotic stability of the steady state. The use of the availability function for stability analysis and stabilization was already advocated for in [51]; see also, e.g., [47,52] for related work using the availability function in the context of passivity-based control of irreversible port-Hamiltonian systems. This is extended to general quasi-Hamiltonian systems where the skew-symmetric matrix J e and the input matrix G may both depend on the extensive variables z, S and the intensive variables ∂E ∂z (z, S), ∂E ∂S (z, S) = T. The steady state condition for u =ū is given asJ Assuming the energy function E(z, S) to be convex (which is normally the case in thermodynamic systems), then the availability function is given as the convex function having a minimum at (z,S). A key property of the availability function E is that where ∇ E(z, S) denotes the gradient vector of E (written as a column vector). The computation of d dt E(z, S) yields, exploiting the steady state condition (41), (This condition is similar to the condition for asymptotic stability of steady states of port-Hamiltonian systems as derived in [53]; see also [37].) Hence if (46) is satisfied and E(z, S) is not only convex but even strictly convex, then E(z, S) serves as a Lyapunov function for assessing the (asymptotic) stability of the steady state (z,S). Instead of expressing the energy E as a function E(z, S) of the remaining extensive variables z, S and writing the dynamics as a quasi-Hamiltonian system with Hamiltonian given by E, one may also write the entropy S as a function S(z, E) and try to express the dynamics as being generated by the gradient of this entropy function. However, since (in the isolated case) d dt S ≥ 0, this constitutes quite a different scenario. An example where it is possible is a chemical reaction network as mentioned before. Instead of the quasi-Hamiltonian formulation (30), one rewrites the dynamics as (with z replaced by the vector of concentrations x) because of F = 1 T N µ. Since d dt S ≥ 0, the availability function corresponding to V(z) := −S(x,Ē), withĒ the constant total energy of the system, can be used as a Lyapunov function for stability analysis; cf. [34] for details. Note that the matrix F e , in the right-hand of (47), is not a skew-symmetric matrix anymore. In fact, the formulation (47) resembles the formulation of thermodynamic systems as used in the GENERIC formalism; see, e.g., [30].
Another interesting case are isothermal chemical reaction networks. In this case [45] one considers the Gibbs free energy (Legendre transform of E(z, S) with respect to S) for constant T. By the properties of the Legendre transform ∂G ∂z = ∂E ∂z = µ (the vector of chemical potentials). Hence, in view of (47) one obtains for constant T with σ the irreversible entropy production. Alternatively expressed, whenever the temperature T is constant, d dt G = d dt E − T d dt S, while d dt E = q (with q the heat flow needed to keep the temperature constant) and d dt S = q − σ. Taken together this indeed yields d dt G = −Tσ.

Thermodynamic Phase Space and Liouville Geometry
A typical feature of thermodynamic systems modeling is the use of many more variables than the minimal number of variables to describe the 'state' of the system. For example, a simple thermodynamic system is described by a 2-dimensional submanifold L of the 3-dimensional space of macroscopic quantities V, P, T; one extensive, and two intensive. Then, based on the first and second laws of thermodynamics, two extra extensive variables E, S are introduced. As a result, the system is described as a 2-dimensional submanifold L of R 5 ; the thermodynamic phase space is generated by the three extensive variables E, S, V, and the two intensive variables T, P. This is immediately extended to the general thermodynamic case, where L is an n-dimensional submanifold of the (2n + 1)dimensional thermodynamic phase space (comprising n + 1 extensive variables and n intensive variables).

Constitutive Relations and Liouville Submanifolds
The Legendre submanifold L only defines the constitutive relations of the thermodynamic system, i.e., its thermostatics. The first and second laws impose constraints on any possible dynamics of the thermodynamic system, but do not define it. On the other hand, two requirements for any dynamics on the full thermodynamic phase space are natural: (1) the dynamics should respect the 'structure' of the thermodynamic phase space, (2) it should respect the constitutive relations; i.e., should leave the submanifold L invariant. The proper geometry to address this is contact geometry. However, in order to unify the energy and entropy representation we will take one more abstraction step; from contact geometry to Liouville geometry. This will have the additional benefit of making a clear separation between extensive and intensive variables, and of being computationally more easy; see [25,26,54,55] for further details and ramifications.
For a simple thermodynamic system with extensive variables E, S, V and intensive variables T, −P, the step from contact to Liouville geometry amounts to replacing the intensive variables T, −P (in the energy representation) with their homogeneous coordinates p E , p S , p V with p E = 0, i.e., and thereby to express the intensive variables 1 T , P T in the entropy representation as In this way, the two Gibbs one-forms dE − TdS + PdV and dS − 1 T dE − P T dV are replaced by a single symmetric expression, namely by the Liouville one-form on the cotangent bundle T * R 3 , with R 3 the space of extensive variables E, S, V. By definition of homogeneous coordinates, the vector (p E , p S , p V ) is always different from the 0-vector. Hence, the space {(E, S, V, p E , p S , p V )} is actually the cotangent bundle T * R 3 minus its zero section. Using homogeneous coordinates, the 2-dimensional Legendre submanifold L is now replaced by the 3-dimensional submanifold L ⊂ T * R 3 , given as It turns out that L is a Lagrangian submanifold [56][57][58], which is moreover homogeneous, in the sense that whenever (E, S, V, p E , p S , p V ) ∈ L then also (E, S, V, λp E , λp S , λp V ) ∈ L, for any non-zero λ ∈ R. Such submanifolds are fully characterized as maximal manifolds restricted to which the Liouville form p E dE + p S dS + p V dV is zero, and are therefore called homogeneous Lagrangian submanifolds or Liouville submanifolds [25].
In general, one considers the (n + 1)-dimensional manifold Q of all the extensive variables (including E and S), and its (2n + 2)-dimensional cotangent bundle without zero section, denoted by T * Q. The constitutive properties of the thermodynamic system are defined by a (n + 1)-dimensional Liouville submanifold L. Conversely, starting from T * Q we may define a contact manifold in the following way [57]. For each q ∈ Q and cotangent space T * q Q consider the projective space P(T * q Q), given as the set of rays in T * q Q, that is, all the non-zero multiples of a non-zero cotangent vector. Thus, the projective space P(T * q Q) has dimension n, and there is the canonical projection π q : T * q Q → P(T * q Q), where T * q Q denotes the cotangent space without its zero vector. The fiber bundle of the projective spaces P(T * q Q), q ∈ Q, over the base manifold Q will be denoted by P(T * Q). Furthermore, the bundle projection obtained by considering π q : T * q Q → P(T * q Q) for every q ∈ Q is denoted by π : T * Q → P(T * Q). As detailed in [26,57,58], P(T * Q) defines a contact manifold of dimension 2n + 1, and will serve as the canonical thermodynamic phase space for the thermodynamic system with space of external variables Q. In the case of a simple thermodynamic system the bundle projection π is given in coordinates as whenever p E = 0 (energy representation), or as whenever p S = 0 (entropy representation). The cotangent bundle T * Q, and therefore also T * Q, are endowed with the natural one-form α, called the Liouville form, which in natural cotangent bundle coordinates (q, p) = (q 1 , · · · , q n+1 , p 1 , · · · , p n+1 ) is given as A submanifold L ⊂ T * Q is a Liouville submanifold if α restricted to L is zero, and furthermore L is maximal with respect to this property. It turns out that maximality of L is equivalent to dim L = n + 1.
For any point in a Liouville submanifold L there exists a neighborhood of this point, a splitting of the index set {1, · · · , n + 1} = I ∪ J and a function F(q I , p J ) that is homogeneous of degree 1 in p J (in particular J = ∅), where q I denotes the vector of coordinates q i with i ∈ I and p J denotes the vector of coordinates p j with j ∈ J, such that on this neighborhood By homogeneity of F in p J it follows that for any j ∈ J we can write, whenever p j = 0, for some function F. The choice of j ∈ J corresponds to a choice of the coordinates for the contact manifold P(T * Q) (for example, corresponding to the energy or the entropy representation). The Liouville submanifold L projects under π to a Legendre submanifold L ⊂ P(T * Q), and conversely any Legendre submanifold L ⊂ P(T * Q) is the projection of a Liouville submanifold L ⊂ T * Q. Furthermore, the function F serves as a generating function for the Legendre submanifold L. Although the close relation of contact geometry with the Liouville geometry of cotangent bundles is well-known in differential geometry [57,58], the use of homogeneous coordinates for thermodynamics was first advocated for in [29].

Homogeneous Hamiltonian Dynamics and Port-Thermodynamic Systems
The dynamics of the thermodynamic system should now satisfy the following two basic requirements. First, it should respect the structure of T * Q, and therefore of the contact manifold P(T * Q). Second, it should leave invariant the Liouville submanifold L specifying the constitutive relations. The first requirement amounts to a requirement that the dynamics are Hamiltonian on T * Q, with the additional property that the Liouville forms on T * Q is preserved. This can be seen to correspond to Hamiltonian dynamics with a Hamiltonian K that is homogeneous of degree 1 in the p-variables. Thus, if q are coordinates for Q and (q, p) are corresponding cotangent bundle coordinates for T * Q (such that the Liouville form is α = ∑ n+1 i=1 p i dq i ), then we consider Hamiltonians K(q, p) satisfying K(q, λp) = λK(q, p) for all λ ∈ R different from zero. Equivalently, by Euler's theorem, the Hamiltonian K(q, p) should satisfy with the functions ∂K ∂p i (q, p) homogeneous of degree 0 in p, i = 1, · · · , n + 1. The second requirement is equivalent to K being such that K restricted to L is zero. Finally, we will split K into two parts, i.e., Here K a : T * Z → R is the Hamiltonian corresponding to the autonomous dynamics due to internal non-equilibrium conditions, while K c = (K c 1 , · · · , K c m ) is a row vector of Hamiltonians corresponding to dynamics arising from interaction with the surroundings of the system, parameterized by a vector u of control or input variables. (However, as we will notice in the context of the damper system (81), there are cases where the dependence on u is not affine.) Thus all these Hamiltonians K a , K c 1 , · · · , K c m are zero on L. This implies that the dynamics of the extensive variables are given as where the right-hand side is homogeneous of degree 0 in p. (Note that this does not mean that the right-hand side is necessarily independent of p; it may depend on degree 0 variables p i −p E ; i.e., on the intensive variables!) Finally, there are two important extra constraints on K a (the Hamiltonian governing the autonomous dynamics corresponding to u = 0) which are directly imposed by the first and second laws. By the first law 0 =Ė = ∂K a ∂p E on L. Furthermore, by the second law necessarily ∂K a ∂p S | L ≥ 0. In fact, using the postulate of factorization of the irreversible entropy production as discussed in Section 3 one has where σ = 0 if and only if F k = 0, k = 1, · · · , s. Such constraints do not hold for the control (interaction) Hamiltonians K c . In fact, the corresponding terms of the control Hamiltonians define natural outputs conjugated to the inputs u. The first option is to define the m-dimensional row vector with the subscript p in y p standing for power. Then, it follows that d dt E = y p u, and thus, y p is the vector of power-conjugate (passive) outputs corresponding to the input vector u. Similarly, by defining the m-dimensional row vector it follows that d dt S ≥ y e u. Hence y e is the output vector which is conjugate to u in terms of entropy flow. This is summarized in the following definition of a port-thermodynamic system as given in [25,26]. Definition 1. Consider a manifold Q of extensive variables. A port-thermodynamic system on Q is defined by a Liouville submanifold L ⊂ T * Q specifying the constitutive relations of the system, together with a Hamiltonian K a + K c u, u ∈ R m , homogeneous of degree 1 in p, which is zero on L for every u and satisfying ∂K a ∂p E = 0 on L, and ∂K a ∂p S ≥ 0 on L. Its power port is defined by u together with the output y p = ∂K c ∂p E , and its entropy flow port by u and y e = ∂K c ∂p S . Remark 3. The Hamiltonian K generates the dynamics, but does not have an interpretation in terms of energy. In fact, K is dimensionless; see [25,26] for further information.

Remark 4.
Through the use of entropy flow ports, one could express the irreversible entropy production σ = ∑ s k=1 F k J k ≥ 0 as being the result of the interconnection of the system with a pure entropy producing element. This is especially clear if the vector of thermodynamic flows J can be expressed as a function of the vector of thermodynamic forces F, like in Onsager's relations J = LF, L = L . Namely, in this case one may consider u = J and entropy conjugate outputs y e = F, and then 'close' the loop by setting u = Ly e .
Because of the homogeneity of the Liouville submanifold L and of the Hamiltonian K, the port-thermodynamic system defined on T * Q, including its power and entropy flow ports, projects to a system on the thermodynamic phase space P(T * Q) with Legendre submanifold L; see [25] for details. In fact, the resulting class of systems on P(T * Q) is very close to the classes of input-output contact systems and conservative control contact systems on contact manifolds as introduced and studied in [7][8][9]59,60].
The definition of port-thermodynamic systems (Definition 1) is illustrated by the examples of the gas-piston-damper system, chemical reaction network, and heat exchanger as follows.
Example 8 (Gas-piston-damper system continued [26]). As discussed before, the extensive variables are E (energy), S (entropy), V (volume), and π (momentum of the piston). For simplicity we will take A = 1. The constitutive properties are given by the Liouville submanifold with generating function −p E U(S, V) + π 2 2m . The dynamics are given by the Hamiltonian (homogeneous of degree 1 in p) which obviously is zero on L. The power-conjugate output y p = π m is the velocity of the piston. One could also add an extra control Hamiltonian ∂S is the temperature, and v is the heat flow from an external heat source into the cylinder. The corresponding entropy conjugate output is y e = 1 T .
Example 9 (Chemical reaction network continued [33]). Consider a chemical reaction network in entropy representation, with the entropy S represented as a function S = S(E, x) of the vector of chemical concentrations x and energy E. Then the Liouville submanifold describing the state properties of the reaction network is given as with generating function −p S S(x, E) and ∂S ∂x (E, x) = − µ T , ∂S ∂E (E, x) = 1 T . The internal dynamics of the chemical reaction network are generated by the Hamiltonian Furthermore, the control Hamiltonian corresponds to a heat flow input, and an entropy flow conjugate output y e = ∂S ∂E (x, E) |L equal to the reciprocal temperature. Another possible choice is corresponding to material in/outflow of the i-th chemical species, with entropy flow conjugate output y e = ∂S ∂x i (E, x) |L equal to the chemical potential µ i of the i-th chemical species divided by the temperature T.

Example 10 (Heat exchanger continued [26]
). The extensive variables are S 1 , S 2 (entropies of the two compartments), and E (total internal energy). The state properties are described by the Liouville submanifold corresponding to the generating function −p E (E 1 (S 1 ) + E 2 (S 2 )), with E 1 , E 2 as the internal energies of the two compartments. Denoting the temperatures T 1 = E 1 (S 1 ), T 2 = E 2 (S 2 ), the internal dynamics corresponding to Fourier's law is given by the Hamiltonian with λ Fourier's conduction coefficient.

Control by Interconnection
Control by interconnection is the paradigm of controlling a system by interconnecting it (through its inputs and outputs) to an additional controller system. The aim is to influence the dynamics of the original system by shaping the dynamics of the interconnected system by a proper choice of the controller system. Applied to port-thermodynamic systems, this means that given a plant thermodynamic system we interconnect it to a controller port-thermodynamic system such that in the closed-loop port-thermodynamic system the plant states converge to the desired set-point values. Port-thermodynamic systems can be interconnected, either by their power ports or by their entropy flow ports; cf.
[26] for details. For example, the power port interconnection of two systems with variables is defined as follows. With the homogeneity assumption in p in mind, impose the following constraint This leads to the summation of the Liouville one-forms α 1 and α 2 given by on the composed space T * Q 1 • T * Q 2 defined as T * Q 1 • T * Q 2 := {(E, S 1 , S 2 , q 1 , q 2 , p E , p S 1 , p S 2 , p 1 , p 2 )} Let the constitutive relations of the two port-thermodynamic systems be defined by the Liouville submanifolds L i ⊂ T * Q i , i = 1, 2. Then, the constitutive relations of the interconnected system are defined by the composition Furthermore, consider the dynamics on L i defined by Hamiltonians K i = K a i + K c i u i , i = 1, 2, where K c i is the row vector of control Hamiltonians of system i, i = 1, 2. Additionally assume that the functions K i do not depend on the energy variables E i , i = 1, 2. Then K 1 + K 2 is well-defined on L 1 • L 2 for all u 1 , u 2 . Next, consider the power conjugate outputs y p1 , y p2 . By imposing interconnection constraints on the power port variables u 1 , u 2 , y p1 , y p2 satisfying the power preservation property y p1 u 1 + y p2 u 2 = 0 (78) one obtains an interconnected port-thermodynamic system with constitutive relations described by L 1 • L 2 . Similarly, interconnecting the inputs u 1 , u 2 to the entropy flow outputs y e1 , y e2 in such a way that leads again to a port-thermodynamic system. A basic control problem concerns the stabilization of a system to a desired set-point value (regulation). How can we use control by interconnection to address this problem? Suppose we want to stabilize the system at some set-point value (z * , S * ). If E(z, S) already has a strict minimum at (z * , S * ) then one may asymptotically stabilize (z * , S * ) by the interconnection with a damper system [32]. In fact, assume for simplicity of exposition that m = 1 (scalar output y p ). Then, consider an additional linear damper system (cf. [26]), whose Liouville submanifold is given as (note the quadratic dependence on the input u d ), with power conjugate output y d = du d (damping force). Then interconnect the plant port-thermodynamic system (L, K = K a + K c u) to this damper system by setting This results (after setting p U d = p E ) in the interconnected port-thermodynamic system with total Hamiltonian given as )dy 2 (83) with total energy E(S, z) + U d (S d ). This implies Hence, by an application of LaSalle's invariance principle, the system converges to the largest invariant set within the set where the power conjugate output y p is zero. Note that y = 0 corresponds to zero entropy productionṠ d = 0; in accordance with irreversible thermodynamics. If the largest invariant set where y is zero equals the singleton (E * , S * , q * ) then asymptotic stability of (E * , S * , q * ) results; for some limiting value S * d of the entropy S d of the damper system; see also [32].
What can be done if E(S, z) does not have a strict minimum at (S * , z * )? This can be approached via the (generalized) Energy-Casimir method; similar to the theory of control by interconnection for port-Hamiltonian systems, see e.g., [37,61]. Consider a portthermodynamic system with Liouville submanifold L ⊂ T * Q with the generating function (in the energy representation) −p E E(S, z). A classical tool in the stability analysis of ordinary Hamiltonian dynamics is to consider additional conserved quantities; see e.g., [56][57][58]. In order to extend this idea to the present case, let us strengthen our assumption on K a by requiring that ∂K a ∂p E = 0 everywhere on T * Q; i.e., not just on L. Next, consider additional conserved quantities for the dynamics X K a that are only depending on the extensive vari-ables S, z; i.e., functions C(S, z) such that {K a , C} = 0, where {· , ·} is the standard Poisson bracket on T * Q. Hence, also {K a , E + C} = 0. Subsequently, note that [32] Hence, the transformation is a point transformation (that is, leaving the Liouville form invariant). Note that in the new coordinates the intensive variables In these new coordinates the generating function for L in entropy representation is given by E(S, z) = E(S, z) + C(S, z). Furthermore, since {K a , E + C} = 0, the transformed Hamiltonian K a ( E, S, q, p E , p S , p) := K a (E, S, q, p E , p S , p) (88) satisfies { K a , E} = 0. Hence, in the new coordinates we are back to the situation considered before: if E(S, z) has a strict minimum at (S * , z * ), then E is a Lyapunov function for the dynamics restricted to L, and the equilibrium (E * , S * , z * ) with E * = E(S * , z * ), is stable with respect to the dynamics on L. Finally, note that the row vector K c in the new coordinates transforms to K c ( E, S, z, p E , p S , p z ), leading to the transformed power conjugate outputs and the transformed entropy flow conjugate outputs All this is illustrated by the stabilization of the gas-piston system in the following example.
Example 11 (Regulation of gas-piston system). Consider the gas-piston system (without a damper) with extensive variables (E, S, V, π), as before. The constitutive properties of the system are given by the Liouville submanifold as in (65) with energy expression E p (S, V, π) := U(S, V) + π 2 2m ('p' for plant). Without damping (d = 0) the dynamics are generated by the Hamiltonian with power conjugate output y p = π m (velocity of the piston). A scalar controller system with extensive variables (E c , z c ) is given by the port-thermodynamic system (L c , K c ), with energy E c = E c (z c ), and dynamics with output y c = E c (z c ). The function E c (z c ) is a design parameter, specifying the controller system.
The closed-loop system is obtained by the negative feedback (with v a new external input) together with This leads to the closed-loop Hamiltonian It is immediately seen that C(V, π, z c ) = Φ(V − z c ) for any function Φ : R → R is a conserved quantity. This motivates a consideration of new canonical coordinates ( E, V, π, q c , p E , p V , p π , p c ), where while V = V, π = π, z c = z c , p E = p E , p π = p π . In the new coordinates we compute K as leading to the same power conjugate output y p = y p = π m (velocity of the piston). For any set-point V * the functions Φ and E c should be chosen in such a way that the function E(S, V, π, Φ(V − z c )) has a strict minimum at (S * , V * , π * = 0, z * c ) for some value of S * and state z * c of the controller system. As discussed before, this can be turned into asymptotic stabilization by additionally interconnecting the obtained closed-loop system with a damper system through the power port (v, y p ).

Conclusions and Outlook
Ever since the fundamental contributions of Gibbs and Maxwell to thermodynamics, geometry has played an essential role. Nevertheless, the development of the geometric theory of macroscopic thermodynamics still poses fundamental questions, especially when it comes to thermodynamics instead of thermostatics. In this paper, the focus has been on quasi-Hamiltonian formulations based on the factorization of the irreversible entropy production, and on the contact-geometric approach using Liouville geometry. The first topic is intimately related to the GENERIC framework, as well as to the theory of irreversible port-Hamiltonian systems. With respect to the second topic, Liouville geometry offers a versatile framework for dealing with the general thermodynamic phase space, in particular by providing a unification of the energy and entropy representation. Although in this approach the necessary conditions for the dynamics on the thermodynamic phase space are clear, natural specifications of the dynamics are still somewhat lacking. In this regard, a combination of the quasi-Hamiltonian and GENERIC formulations with contact and Liouville geometry should be promising.
Finally, it should not be forgotten that thermodynamics started as an engineering subject (dealing with the efficiency of the steam engine). The interaction of thermodynamic systems with their surroundings is key to the theory. This has been demonstrated in this paper through a discussion of the definitions of the energy and entropy as storage functions with respect to supply rates corresponding to the thermal and the (mechanical) power port, and through the definition of port-thermodynamic systems. Furthermore, it naturally leads to control of thermodynamic systems, including the theory of 'control by interconnection'.