Skip to content

ENH: Workspace integration#39

Merged
bocklund merged 15 commits into
masterfrom
Workspace-integration
Nov 3, 2025
Merged

ENH: Workspace integration#39
bocklund merged 15 commits into
masterfrom
Workspace-integration

Conversation

@bocklund

@bocklund bocklund commented May 21, 2025

Copy link
Copy Markdown
Collaborator

This branch only has WIP changes for directly using Workspace in simulate_scheil_solidification

Outstanding TODO items:

  • Fix broken tests
  • Port ordering handler to Workspace
  • Port simulate_equilibrium_solidification to Workspace
  • Support getting properties in the API via output keyword argument (analogous to PyCalphad equilibrium output)? See Add options to save equilibrium results during scheil simulation #38. Also would want to export the properties to the SolidificationResult object API.

bocklund added 5 commits June 20, 2025 13:55
- Ordering handling is now special cased for Scheil since it's difficult to use eq_results
- Equilibrium is updated to use Workspace at a high level, but still falls back on xarray Dataset objects for most the work
@bocklund bocklund marked this pull request as ready for review June 20, 2025 21:57
@bocklund bocklund force-pushed the Workspace-integration branch from d107924 to 1e88aca Compare June 20, 2025 22:17
@bocklund

bocklund commented Jun 20, 2025

Copy link
Copy Markdown
Collaborator Author

@Chuangye-Wang @sorkins I think I'm happy with Workspace support here in general.

The latest commit adds notional support to demo the custom property use case. The idea is that you can pass anything that works for PyCalphad Workspace to output

    sol_res = simulate_scheil_solidification(dbf, comps, phases, initial_composition, start_temperature, step_temperature=20.0, verbose=True, output=["HM", "CPM", "NP(LIQUID)"])

These properties give the properties of the state of the properties are for 1 mole of solidifying liquid values at any instant in the simulation (that is, we don't account for the properties of the previously solidified solid at all or the remaining amount of liquid). This is conceptually the same thing that happens in the implementation of #38, i.e. leaving it all up to the user.

I'm a little hesitant to not account for the simulation's sense of how much liquid remains and the properties of the frozen-in solid, since that's what the equilibrium picture would look like if we took the same kind of approach there. I don't like the idea that equilibrium and Scheil solidification simulations give different physical pictures of the properties. But I'm open to the idea of deferring on supporting the equilibrium solidification support for now until we reconcile handling the Scheil case better.

Does this approach serve your use case? I'm curious on how you're addressing handling the properties of the frozen-in solid if that's relevant for your use case. Happy to accept feedback in general.

@sorkins

sorkins commented Jun 23, 2025

Copy link
Copy Markdown

Thanks so much for the work here @bocklund! We'll test things out with this branch ASAP and give some feedback.

We'll think on the frozen-in solid question, it's nothing too complex so I'm sure it wouldn't be a problem to share some details.

@Chuangye-Wang

Copy link
Copy Markdown

@bocklund Thanks for this nice implementation! I tried to use this branch to get solidified fraction during solidification, but the results turned out to be different from the branch I made. I got a lot of duplicated values for the fraction_solid in the scheil's results. I tried to debug a bit, and found multiplicity_aware_stable_phases only include liquid phase from the fourth iteration, which leads to the duplication. Could you help to identify the root cause for this issue? I used alloy Fe-0.3Cr-0.02C in mole fraction. Sorry I cannot provide our internal database for you to debug. If you need I provide a test case to debug, I will try to make one for you.

image

Branch I made.
image

Current branch.
image

Debugged at:
image

@Chuangye-Wang

Copy link
Copy Markdown

@bocklund I created an example for you to test on.
You can see that there are lots of duplicated values in the fraction_solid as temperature decreases.
test_scheil_solidification_ternary_system.zip

image

@sorkins

sorkins commented Jul 18, 2025

Copy link
Copy Markdown

@bocklund reminder

@bocklund

Copy link
Copy Markdown
Collaborator Author

@bocklund I created an example for you to test on. You can see that there are lots of duplicated values in the fraction_solid as temperature decreases. test_scheil_solidification_ternary_system.zip

Apologies, I've been swamped recently. Thank you for the test, it helps a lot debugging this stuff. I just want to verify that the expected behavior of the test is that it passes (it does for me), but you see that there are duplicated values in the fraction of solid? I am able to reproduce that behavior (test passes, but has duplicated fraction liquid/solid values)

@Chuangye-Wang

Copy link
Copy Markdown

@bocklund Correct. It passes but the results contain a lot of duplicated values.

@sorkins

sorkins commented Aug 14, 2025

Copy link
Copy Markdown

@bocklund reminder on this when you have the time. If there's anything you can point us at to help figure this out, please let us know!

@sorkins

sorkins commented Sep 8, 2025

Copy link
Copy Markdown

@bocklund reminder, no rush.

@bocklund

bocklund commented Oct 24, 2025

Copy link
Copy Markdown
Collaborator Author

Do you guys want to try this again on this branch with the newly released version of PyCalphad (0.11.1)? Seems to be the fix for me locally:

from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from pycalphad import Database, variables as v
from scheil import simulate_scheil_solidification

here = Path(".").resolve()

dbf = Database(here / "CCrFe-2014Khvan.tdb")
comps = ["FE", "CR", "C", "VA"]
phases = sorted(dbf.phases.keys())

initial_composition = {v.X("CR"): 0.3, v.X("C"): 0.02}
start_temperature = 1750

sol_res = simulate_scheil_solidification(dbf, comps, phases, initial_composition, start_temperature, step_temperature=1, verbose=False)

fig, ax = plt.subplots()

for phase_name, amounts in sol_res.cum_phase_amounts.items():
    if amounts[-1] > 0:
        ax.scatter(sol_res.fraction_solid, amounts, label=phase_name, s=2)
ax.scatter(sol_res.fraction_solid, sol_res.fraction_liquid, label='LIQUID', s=2)
ax.set_ylabel('Phase Fraction')
ax.set_xlabel('Fraction solid')
# ax.title('Al-30Zn Scheil simulation, phase fractions')
ax.legend(loc='center left', bbox_to_anchor=(1.02, 0.5))
fig.savefig("Fe-Cr-C_scheil_phase_fractions.png", bbox_inches='tight')
Fe-Cr-C_scheil_phase_fractions image

@Chuangye-Wang

Copy link
Copy Markdown

@bocklund Thanks a lot! I will test and let you know next week.

@Chuangye-Wang

Copy link
Copy Markdown

@bocklund @sorkins Confirmed that it fixes the duplicated values with pycalphad 0.11.1.
@bocklund Thanks a lot for your help!

@bocklund

Copy link
Copy Markdown
Collaborator Author

Great, I'll try to make any last polishing changes and try to get it merged and a new release out 😄 Thanks for your patience through my busy summer.

@bocklund bocklund merged commit 8fc6ef2 into master Nov 3, 2025
16 checks passed
@bocklund bocklund deleted the Workspace-integration branch November 3, 2025 18:58
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.

3 participants