Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Improved database reading for out of order type definitions #269

Merged
merged 16 commits into from Mar 31, 2020

Conversation

bocklund
Copy link
Collaborator

@bocklund bocklund commented Mar 30, 2020

TYPE_DEFINITION lines in pycalphad needed to be defined prior to the PHASE keyword that the type definition belonged to, otherwise the type definition would not be applied when _process_phase was called. This PR puts all the added type definitions in a queue so they can be processed after all phases are processed, which decouples processing of type definitions from the the order that they are defined in the database. This has the following consequences

  • _process_typedef now adds the model_hints to each phase directly, rather than _process_phase building model hints from the existing type definitions
  • Two warnings are added. One warning if a type definition is defined in the PHASE keyword, but has no corresponding type definition. This can occur from a typo, or if the PHASE line was copied and the corresponding type definition left behind. Another warning is raised when there are type definitions defined, but not used by any phase, which could happen for similar reasons.
  • model_hints are now added to both the ordered and disordered phases in the order-disorder partitioned model. This fixes a bug where filter_phases would not correctly filter out phases that did not have model_hints defined. This means that when writing TDBs, the type definition for the partitioned model will be applied to both phases*.
  • A test is added that verifies that no matter the order of the ordered phase, disordered phase, and type definition, the order-disorder model_hints are applied to both phases. In this test, the type definition is applied only to the ordered phase, since that seems to be the predominant way that TDBs are found in the literature. Other variants for this test are possible, such as the type definition being applied to only the disordered phase or to both phases. All should produce the same result.
  • Another test is added for a database in the test suite that filter_phases would fail to remove the disordered phase from.
  • The test_eq_ternary_inside_mass test was failing. At first this seemed spurious, but after a closer look, I found that the type definitions for magnetism were after the definition of the BCC_A2 phase the magnetic model_hints was not getting added to the BCC_A2 phase. I added a test to check that these model hints are correctly added (it fails on develop, but passes here). This helps correctness. We weren't seeing this issue with the order-disorder type definition because the implementation of _process_typedef always updated the ordered phase model_hints explicitly if the ordered phase was in the database. I updated the Gibbs energies and chemical potentials of the test_eq_ternary_inside_mass to what are presumably the correct values now that magnetism is considered.
  • A call to filter_phases is added to binplot to remove phases that cannot exist. Required because we don't directly call equilibrium, which would normally do this for us.

*The way the TDBs are read by Thermo-Calc seems to be that one phase is specified, then the type definition, then the other phase in the partitioned model, and it doesn't matter which one is first. Thermo-Calc will give a warning if the type definition line is run before both PHASE lines are run, but it seems to produce the correct phases and internal understanding.

@bocklund bocklund requested a review from richardotis Mar 31, 2020
pycalphad/io/tdb.py Outdated Show resolved Hide resolved
pycalphad/tests/test_database.py Show resolved Hide resolved
pycalphad/tests/test_equilibrium.py Outdated Show resolved Hide resolved
pycalphad/tests/test_database.py Outdated Show resolved Hide resolved
@bocklund bocklund merged commit 25e4170 into develop Mar 31, 2020
5 checks passed
@bocklund bocklund mentioned this pull request Mar 31, 2020
3 tasks
@bocklund bocklund deleted the fix-filter_phases-order_disorder branch Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants