Gibbs Phase Rule Interpreted via Euler's Formula (Draft)
using Pkg
Pkg.update()
Pkg.add(["LightGraphs", "GraphRecipes", "Plots", "PrettyTables"])
using LightGraphs, GraphRecipes, Plots, PrettyTables
"""
K1_Plot(self_edges = 1, pnts_per_edge = 50)
This function plots the K1 graph with as many self edges as desired.
"""
function K1_Plot(self_edges = 1, pnts_per_edge = 50; title = "")
θ = ( 1 : (360 / ( self_edges * pnts_per_edge ) ) : 360 ) * (pi / 180.0)
coefficient = (self_edges != 1 ) ? 2. .* (1. .- cos.( self_edges .* θ )) :#Rotated cardiod
cos.(self_edges*θ) #rosette
plot(coefficient .* cos.( θ ), coefficient .* sin.( θ ),
label = "", xlabel = "", ylabel = "", title = title,
xaxis = false, yaxis = false, ticks = false, linecolor = :black)
return scatter!( [0.0], [0.0] , label = "", markershape = :circle, size = (400,300), markercolor = :blue)
end
Plots.default(size = (600, 400) )
Gibbs Phase Rule
Gibbs phase rule relates how the cardinality of intensive variables in any physical system is related to the cardinalities of the constituents and phases at equilibrium. In plain English, intensive variables are the independent variables required to completely determine a system's thermodynamic state. In physics/chemistry, these are often referred to as degrees of freedom (denoted here as inline_formula not implemented) and are the set of compoonent concentrations, and state variables (pressure, temperature, etc). Although the definition of Degrees of Freedom is related to the traditional statistical definition(via statistical mechanics), it may not be as obvious to someone outside of physical science that it upholds the same fundamental definition here.
Consider the ideal gas law, where pressure(inline_formula not implemented) and volume(inline_formula not implemented) are equated to temperature(inline_formula not implemented) and the number of moles of substance(inline_formula not implemented) times a constant(inline_formula not implemented),
formula not implementedThis model suggests that if the volume of a container which encloses a fixed quantity of nitrogen gas(1 compound) that there are 2 degrees of freedom. Those would be pressure, and temperature. Although, somewhat scary at first, the matter is relatively trivial.
Now, the remainder of Gibbs phase rule is pretty simple. We must only concern ourselves with the components in the system(inline_formula not implemented) and the number of phases ocurring in the system inline_formula not implemented. Gibbs proved the following elegant relationship involving the degrees of freedom, composition of the chemical system, and the number of phases ocurring at the equilibrium point,
formula not implementedAlternatively,
formula not implementedThat is Gibbs phase rule! A very simple, sanity check for finding, or ensuring a value given any of the other two. What is interesting here is that Josiah Gibbs discovered this in 1873, while Leonhard Euler, a famous mathematician established a very similar relationship in a completely different area - graph theory.
Eulers Formula
In 1753 Leonhard Euler, a very similar equation was expressed in the publication "Elementa doctrinae solidorum" during the birth of what is now called graph theory. If you have not been inundated in the basic mechanics of graph theory a very short incomplete, explanation of what graph's are is given in the following 2 paragraphs.
Graphs are mathematical objects which express relationships between any set, or sets of elements, via a notion of connectivity. The premise is that, the connection and identity of the items are of relevance. In graph theory every element is represented or called a vertex (denoted here as inline_formula not implemented), and the connections between any vertex, or with itself, are called edges(inline_formula not implemented). A node can be anything, animals, numbers, users on a computer network, observations from a case study, etc. Edges can also be any chosen metric, one could consider, familial lineage, distance/proximity, a service used, or an arbitrary score.
These two items, edges and nodes, can be as abstract or concrete as desired. What graph theory offers is a fundamental, and objective view on such elements. Graphs, sometimes, can be displayed, or visualized with dots (vertices) and lines (edges). It is of serious importance to realize that, in most graphical representations, the locations of nodes, angles between them, and/or the lengths of their edges are arbitrary. They need not, and most often do not contain any geometrical meaning, nor any abstraction of geometrical meaning.
Now that we have brushed aside an incredibly rich and foundational area of modern mathematics to the authors satisfaction - Euler's Formula states that for a connected, graph (inline_formula not implemented) it can be called polygonal if,
formula not implementedwhere, inline_formula not implemented is the number of faces in a graph. It also follows that the graph must be connected, planar, and every edge borders on 2 different faces.
Faces in a graph, crudely speaking, are any such enclosed body/area of a graph, including the area included by the infinite bound surrounding the graph. Confusing? Let's use some quick examples to clarify what a face is.
G = SimpleGraph(6)
[ add_edge!(G, i, ( i % nv(G) ) + 1 ) for i in 1:nv(G)]
single_cycle = graphplot( G, title = "Single Cycle Graph", markershape = :circle, linecolor = :black )
add_edge!(G, 4, 6 )
double_cycle = graphplot( G, title = "Two Cycle Graph", markershape = :circle, linecolor = :black )
l = [a b]
plot(single_cycle, double_cycle, layout = l)
Above you will notice that the single cycle graph satisfys the conditions for being polygonal. But also, that it possesses 2 faces. One interior face, and one "exterior". Similarly the double cycle graph has 3 faces. Both graphs contain 6 vertices, but possess a different number of edges (6 & 7).
Is there a connection?
One might propose that, Euler's Formula could be used as a means of exploring/explaining Gibbs phase rule. They do, after-all have the same expression. In this post I will share one such interpretation.
Consider the graph made from the following ordered pair: inline_formula not implemented. Note we typically denote graphs via the following notation inline_formula not implemented. Here we are making our vertices the degrees of freedom in a given system, and the components included in the system the edges. What is interesting here, is that, the degrees of freedom of such a graph - if successful, would be the number of faces in a graph.
Logically, we might expect that a given degree of freedom corresponds, to some extent a given component in our system. Infact, concentration of component species, is one such relation. Let us explore if this is true.
Experiment 1: Nitrogen Gas in Closed Cylinder
In the first section an example of nitrogen gas in a closed cylinder was posed. Let us turn this into a graph. There is 1 component, and 2 degrees of freedom.
pretty_table(Any[ :2 :1 :? ], [:F :C :P;], screen_size = (10,30))
G = SimpleGraph(2)
add_edge!(G, 1, 2 )
graphplot( G, title = "Nitrogen In a Cylinder", markershape = :circle, linecolor = :black, size = (400,300) )
How many faces are there? There is 1. Thus there is 1 phase according to our conjecture. This matches reality! Let's try some more.
Experiment 2: Nitrogen Gas above Water
Now let us consider we add water to our canister containing nitrogen gas.
pretty_table(Any[ :2 :2 :? ], [:F :C :P;], screen_size = (10,30))
G = SimpleDiGraph(2)
add_edge!(G, 1, 2 )
add_edge!(G, 2, 1 )
graphplot( G, title = "Nitrogen(g) and Water(l) In a Cylinder", markershape = :circle, linecolor = :black, size = (400,300) )
We notice there are 2 faces and thus 2 phases in our container! This is also correct. Let's try another...
Experiment 3: Aqueous Ethanol Solution
Now let us consider we add have a mixture of ethanol and water. This means, we now have an additional degree of freedom.
pretty_table(Any[ :3 :2 :? ], [:F :C :P;], screen_size = (10,30))
G = SimpleGraph(3)
add_edge!(G, 1, 2 )
add_edge!(G, 2, 3 )
graphplot( G, title = "Ethanol solution",markershape = :circle, linecolor = :black, size = (400,300) )
Here we would discern that - there is 1 face, and thus 1 phase. This is also correct! Let's try a more confounding example.
Experiment 4: Water at the triple point
Water at it's triple point. The triple point is an invariant equilibrium meaning there are 0 degrees of freedom. It is a uniquely defined temperature and pressure.
pretty_table(Any[ :0 :1 :? ], [:F :C :P;], screen_size = (10,30))
Well... We can't make a graph with 0 nodes and 1 edge... I mean we could play a lot of games to do this, but this appears to be a point where our scheme has broken down.
formula not implementedThankfully the phase rule correctly predicts 3 phases ocurring at the triple point... But what does this mean for the application of Euler's Formula? Maybe it is best to examine say, the freezing point of water.
Experiment 5: Water at the freezing point
Water at it's freezing point means that the degrees of freedom is 1.
pretty_table(Any[ :1 :1 :? ], [:F :C :P;], screen_size = (10,30))
K1_Plot(1, 100; title = "Water at Freezing Point")
So a single node with an edge connected to itself is the simplest graph with a loop in it. Surprisingly it features 2 faces, and matches what we expect from Gibbs phase rule.
Exploring the Dual Representation
Over-all it appears that the equation and both interpretations appear to hold in most circumstances. But, there is one notable caveats worth entertaining. In most cases, for most people Gibb's phase rule is used to predict the number of degrees of freedom from the phases and components. This is because degrees of freedom aren't easy for a lot of people to think about.
Thankfully, there is an identity, stating that every planar graph has a dual graph which is also planar. Now, we can denote our graph as follows: inline_formula not implemented. Thus now, the cardinality of faces in a graph represent the number of degrees of freedom in the system.
Experiment 1: Nitrogen Gas in Closed Cylinder
pretty_table(Any[ :? :1 :1 ], [:F :C :P;], screen_size = (10,30))
K1_Plot(1, 100; title = "Nitrogen in a Closed Cylinder")
This gives us 2 faces and thus 2 degrees of freedom! Great.
Experiment 2: Nitrogen Gas above Water
pretty_table(Any[ :? :2 :2 ], [:F :C :P;], screen_size = (10,30))
G = SimpleDiGraph(2)
add_edge!(G, 1, 2 )
add_edge!(G, 2, 1 )
graphplot( G, title = "Nitrogen(g) and Water(l) In a Cylinder", markershape = :circle, linecolor = :black, size = (400,300) )
This gives us 2 faces, or an F of 2! Excellent.
Experiment 3: Aqueous Ethanol Solution
pretty_table(Any[ :? :2 :1 ], [:F :C :P;], screen_size = (10,30))
K1_Plot(2, 100; title = "Aqueous Ethanol")
Again, we obtain an F of 3. Great!
Experiment 4: Water at the triple point
pretty_table(Any[ :? :1 :3 ], [:F :C :P;], screen_size = (10,30))
println("cannot make this plot in LightGraphs.jl yet")
Most interestingly... The dual representation of this system is a valid graph! We have 3 vertices with 1 edge to share amongst them all. Despite being a valid graph, it is not a connected graph(2 vertices have no edges), and thus Euler's Formula cannot be applied in any meaningful way.
Experiment 5: Water at the freezing point
pretty_table(Any[ :? :1 :2 ], [:F :C :P;], screen_size = (10,30))
G = SimpleGraph(2)
add_edge!(G, 1, 2 )
graphplot( G, title = "Water at the Freezing point", markershape = :circle, linecolor = :black, size = (400,300) )
Now we can see that, we have 1 face, and thus 1 degree of freedom. This is also correct.
Discussion
It appears that the primal and dual graphs of these systems allow us to count faces to find either the number of phases, or the number of degrees of freedom using Gibb's phase rule. This is most interesting, but isn't without some issues.
What does it mean when we have a system that either has an invalid graph representation (ie: 3 edges no vertices) or fails to be represented by Euler's Formula(ie: unconnected graph)? Clearly from the dual, the triple point example would prevent us from examining the invalid graph. So it seems ideal to first consider the graph inline_formula not implemented. It seems a simple interpretation is that, systems that are entirely determined, and lack useful representations. But, if this finding were to have theoretical merit, what might this limitation imply?
What does it mean for systems of phases to be representible as planar/polygonal graphs? I feel that, for nonequilibrium thermodynamics such a representation could provide some richness. However, I haven't looked into this. The purpose of blogs is to share things you know/find, not necesarrily perform considerable research to discover. Can't afford to self publish scientific papers - but maybe this will kick start someones interest! Feel free to remix this or do your own thing.
Ultimately, this is a visual way to remember Gibbs phase rule. I am a huge fan of visualizations, so this was a blast to explore. Thank you for reading!