Repository navigation
IsolatedPhase fix and composition Jansson derivative default change - #595
Conversation
One dependent component for Jansson derivatives wrt composition
IsolatedPhase chemical potentials now computed properly.
|
I'm not sure what's going on with the Windows tests, but that code seems to be orthogonal to the code here and also occurring in #594 |
|
@cjkunselman18 is there any test you can write to verify the new behavior? The test should fail under the current develop branch that's incorrect and pass after applying the changes in this PR. |
|
I came up with test for this: from importlib.resources import files
import pycalphad.tests.databases
from pycalphad import Database, Workspace, calculate, variables as v
from pycalphad.property_framework import IsolatedPhase
import numpy as np
import matplotlib.pyplot as plt
temperature = 100 # K
dbf = Database(files(pycalphad.tests.databases).joinpath("pbsn.tdb"))
wks = Workspace(dbf, phases=["BCT_A5"], components=["PB", "SN", "VA"], conditions={v.T: temperature, v.P:101325, v.X("SN"): 0.5})
calc_res = calculate(dbf, ["PB", "SN", "VA"], ["BCT_A5"], T=temperature, pdens=1000)
global_GM = wks.get("GM")
global_chempots = np.asarray(wks.get("MU(*)"))
global_sitefracs = wks.get("Y(BCT_A5,0,*)")
isolated_GM = wks.get(IsolatedPhase("BCT_A5",wks=wks)("GM"))
isolated_chempots = np.asarray(wks.get(IsolatedPhase("BCT_A5",wks=wks)("MU(*)")))
isolated_chempots_manually_extracted = np.asarray([wks.get(IsolatedPhase("BCT_A5",wks=wks)(x)) for x in ["MU(PB)", "MU(SN)"]])
# isolated_sitefracs = wks.get(IsolatedPhase("BCT_A5",wks=wks)("Y(BCT_A5,0,*)")) # currently fails
print("Global")
print(global_GM)
print(global_chempots)
print(global_sitefracs)
print("Isolated")
print(isolated_GM)
print(isolated_chempots) # TODO: this is a bug, we should bet an array out
print(isolated_chempots_manually_extracted) # TODO: this is also a bug, it"s the same as the global min hyperplane these look like chempots in the MG
# print(isolated_sitefracs) # currently fails
plt.scatter(calc_res.X.sel(component="SN").squeeze(), calc_res.GM.squeeze(), s=2, label="GM", c='blue')
plt.scatter(wks.get(IsolatedPhase("BCT_A5",wks=wks)("X(SN)")), wks.get(IsolatedPhase("BCT_A5",wks=wks)("GM")), c='k', label="Isolated phase GM")
plt.scatter(wks.get("X(SN)"), wks.get("GM"), c='red', label="Global GM")
plt.plot([0, 1], np.asarray([wks.get(IsolatedPhase("BCT_A5",wks=wks)(x)) for x in ["MU(PB)", "MU(SN)"]]), c='k', ls='-', label="Isolated phase MU")
plt.plot([0, 1], np.asarray(wks.get("MU(*)")), c='red', label="MU", ls='--')
plt.xlabel("X(SN)")
plt.ylabel("GM")
plt.title(f"Pb-Sn T = {temperature} K")
plt.legend(loc="center left", bbox_to_anchor=(1.01, 0.5))
plt.savefig(f"Pb-Sn-GM@{temperature}K.png", dpi=150, bbox_inches="tight")The test actually demonstrates two apparent bugs:
On current develop you get this: After apply changes so far up to 0911aef you get this (which is correct): I committed a test to this branch for the chemical potentials fix. The second bug is still unaddressed and we also still need a test for the change to |
|
I've played a little bit with the isolated phase wildcard expansion, but I'm not very happy with the internal hacks I had to do to make it work, so I think we should treat that as out of scope for the purpose of this PR. I opened #604 for that. @cjkunselman18 can you give an example where the Jansson derivative fix is comes into play? I can help write the test if needed and then this is ready for review and merge. |
|
I would love help writing a test. For any system with three or more components, the fix ensures that Jansson derivatives with respect to an independent composition variable only define one dependent component. A simple way to test for this is ensuring that dG/dX(A) = mu(A) - mu(B) where B is the dependent component. Prior to the fix, for system A-B-C, dG/dX(A) = mu(A) - mu(B)/2 - mu(C)/2. Below is an example for Hf-Nb-Ti-V: from pycalphad import Workspace, Database, variables as v wks = Workspace(database=Database('HF_NB_TI_V.TDB'), components=['HF', 'NB', 'TI', 'V'], phases=['BCC_A2'], import matplotlib.pyplot as plt plt.figure(0) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #595 +/- ##
========================================
Coverage 91.95% 91.96%
========================================
Files 77 77
Lines 12338 12357 +19
========================================
+ Hits 11346 11364 +18
- Misses 992 993 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|




IsolatedPhase was not constraining chemical potentials to the compset, but was allowing phase separation in miscibility gaps.
Currently, the default for composition Jansson derivatives is to define n-1 dependent components rather than just 1. Defining one dependent component seems more intuitive and applicable.