Plotting Ternary Phase Diagrams and Using Triangular Axes¶
Often in thermodynamics, it is useful to use a two dimensional plot to express equilibria in a three component system with fixed potentials. The ternplot API provides a straightforward way to calculate equilibria and generate ternary phase diagrams. Alternatively, if you already have an equilibrium calculation, you can directly import and use eqplot.
ternplot¶
Here we will use the ternplot API to plot an isothermal section of the Cr-Fe-Nb system from the thermodynamic database found at Liquidus projection and thermodynamic modeling of the Cr-Fe-Nb ternary system by Jacob et al., Calphad 54 (2016) 1-15
[1]:
import time
import matplotlib.pyplot as plt
from pycalphad import Database, ternplot
from pycalphad import variables as v
db_cr_fe_nb = Database('CrFeNb_Jacob2016.tdb')
comps = ['CR', 'FE', 'NB', 'VA']
phases = list(db_cr_fe_nb.phases.keys())
conds = {v.T: 1323, v.P:101325, v.X('CR'): (0,1,0.015), v.X('FE'): (0,1,0.015)}
start_time = time.perf_counter()
ax = ternplot(db_cr_fe_nb, comps, phases, conds, x=v.X('CR'), y=v.X('FE'))
fig = ax.figure
ax.set_title("Cr-Fe-Nb Ternary Phase Diagram")
fig.set_size_inches(9, 6)
fig.set_dpi(150)
end_time = time.perf_counter()
print(f"Wall Time (Total elapsed): {round(end_time - start_time)} s")
Wall Time (Total elapsed): 13 s
Here is another example for plotting the isothermal section of the Al-Cu-Y system from the thermodynamic database found at the NIST CALPHAD assessments assessed by Zhang et al. in Thermodynamic description of the Al–Cu–Y ternary system (Calphad 35 (2011)). Labels for phases in the three-phase equilibria can be added for clarity.
[2]:
db_al_cu_y = Database('Al-Cu-Y.tdb')
comps = ['AL', 'CU', 'Y', 'VA']
phases = list(db_al_cu_y.phases.keys())
conds = {v.T: 830, v.P:101325, v.X('AL'): (0,1,0.015), v.X('Y'): (0,1,0.015)}
ax = ternplot(db_al_cu_y, comps, phases, conds, x=v.X('AL'), y=v.X('Y'), label_nodes=True)
fig = ax.figure
ax.set_title("Al-Cu-Y Ternary Phase Diagram")
fig.set_size_inches(9, 6)
fig.set_dpi(150)
By default, the mapping code will attempt to generate a list of starting points by searching around the axes of the phase diagram. However, in some cases, phase regions in the phase diagram will not connect to the axis. This is the case if we want to plot the Al-Cu-Y ternary at higher temperatures (e.g. >1360 K). The following will show how to use the mapping API to add custom starting points to generate the correct phase diagram.
[3]:
from pycalphad.mapping import TernaryStrategy, plot_ternary
db_al_cu_y = Database('Al-Cu-Y.tdb')
comps = ['AL', 'CU', 'Y', 'VA']
phases = list(db_al_cu_y.phases.keys())
conds = {v.T: 1770, v.P:101325, v.X('AL'): (0,1,0.015), v.X('Y'): (0,1,0.015)}
strat = TernaryStrategy(db_al_cu_y, comps, phases, conds)
# Add automatic starting points by searching along the axes
strat.generate_automatic_starting_points()
# Add custom starting point near middle of phase diagram
strat.add_nodes_from_conditions({v.T: 1770, v.P: 101325, v.X('AL'): 0.35, v.X('Y'): 0.3})
strat.do_map()
ax = plot_ternary(strat, x=v.X('AL'), y=v.X('Y'), label_nodes=True)
fig = ax.figure
ax.set_title("Al-Cu-Y Ternary Phase Diagram")
fig.set_size_inches(9, 6)
fig.set_dpi(150)
Molar Ratios and Linear Combination Conditions¶
[4]:
from pycalphad import Workspace
db_al_cu_y = Database('Al-Cu-Y.tdb')
comps = ['AL', 'CU', 'Y', 'VA']
phases = list(db_al_cu_y.phases.keys())
conds = {v.T: 830, v.P:101325,
v.X('AL')/v.X('CU'): 5, # molar ratio condition
0.1 * v.X('Y') + v.X('AL'): 0.6} # linear combination of mole fractions condition
wks = Workspace(db_al_cu_y, comps, phases, conds)
print(wks.get('X(AL)', 'X(CU)', 'X(Y)'))
[array(0.56818182), array(0.11363636), array(0.31818182)]