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 Al-Cu-Y system from the thermodynamic database found at Jacob et al, Calphad 54 (2016) (1-15) (https://doi.org/10.1016/j.calphad.2016.04.013)
[1]:
%matplotlib inline
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)}
%time ternplot(db_cr_fe_nb, comps, phases, conds, x=v.X('CR'), y=v.X('FE'))
CPU times: total: 11.8 s
Wall time: 33.9 s
[1]:
<TriangularAxes: title={'center': 'Cr-Fe-Nb'}, xlabel='X(Cr)', ylabel='X(Fe)'>
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. Calphad 35 (2011). Labels for phases in the three-phase equilibria can be added for clarity.
[2]:
%matplotlib inline
from pycalphad import Database, ternplot
from pycalphad import variables as v
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)}
%time ternplot(db_al_cu_y, comps, phases, conds, x=v.X('AL'), y=v.X('Y'), label_nodes=True)
CPU times: total: 8.61 s
Wall time: 28.2 s
[2]:
<TriangularAxes: title={'center': 'Al-Cu-Y'}, xlabel='X(Al)', ylabel='X(Y)'>
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 (ex. >1360K). The following will show how to use the mapping API to add custom starting points to generate the correct phase diagram.
[3]:
%matplotlib inline
from pycalphad import Database
from pycalphad import variables as v
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: 1360, 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})
%time strat.do_map()
plot_ternary(strat, x=v.X('AL'), y=v.X('Y'), label_nodes=True)
CPU times: total: 1.73 s
Wall time: 6.86 s
[3]:
<TriangularAxes: title={'center': 'Al-Cu-Y'}, xlabel='X(Al)', ylabel='X(Y)'>
Molar Ratios and Linear Combination Conditions¶
[4]:
from pycalphad import Database, Workspace, variables as v
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)]
[ ]: