Different results from the same starting conditions (equilibrium)

50 views
Skip to first unread message

Marcelo Falcão de Oliveira

unread,
Nov 30, 2022, 7:29:16 AM11/30/22
to pycalphad
Dear pycalphad community,

I'm getting different results from the same starting conditions with equilibrium. Sometimes I get one result and other times another one. I think I can understand why this may happen. I think I should refine the calculation grid for the convex hull. Am I correct thinking in this way? If my understanding is correct, is there a way of passing this information to the solver?

Thank you.

Marcelo Falcão de Oliveira

unread,
Dec 2, 2022, 10:15:44 PM12/2/22
to pycalphad
I've figured out how to change the grid density. If anyone else needs to set this option whith equilibrium() use calc_opts={"pdens=N"} where N is the grid density. Actually this variable is passed to calculate(); pdens=500 by default when calculate() is called by equilibrium() otherwise it is 2000. However, in my case, it doesn't work. Even by largely increasing pdens the result seems to never converge, see bellow. I have no idea why this is happening...

pdens=500, default when calculate() is called by equilibrium()
Molar fractions:
+-----------+--------+--------+---------+--------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+--------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   -    |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |   -    |    -    | 0.3606 |   0.0313  | 0.5403 |
|   973.0   |   -    | 0.9108 |    -    |   -    |   0.0214  | 0.0678 |
+-----------+--------+--------+---------+--------+-----------+--------+

pdens=1000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   |   -    |    -    |     -     | 1.0000 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=2000, usual default for calculation()
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |  0.5819 |   0.0228  | 0.3274 |
+-----------+--------+---------+-----------+--------+

pdens=3000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=4000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |   -    |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 | 0.5819 |    -    |   0.0228  | 0.3274 |
+-----------+--------+--------+---------+-----------+--------+

pdens=5000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |   -    |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 | 0.5819 |    -    |   0.0228  | 0.3274 |
+-----------+--------+--------+---------+-----------+--------+

pdens=6000
Molar fractions:
+-----------+--------+---------+--------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+---------+--------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   -    |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |  0.3606 |   -    |   0.0313  | 0.5403 |
|   973.0   | 0.0679 |    -    | 0.5819 |   0.0228  | 0.3274 |
+-----------+--------+---------+--------+-----------+--------+

pdens=7000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |   -    |  0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.0679 | 0.5819 |    -    |   0.0228  | 0.3274 |
+-----------+--------+--------+---------+-----------+--------+

pdens=8000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |  0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=9000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |   -    |  0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.0679 | 0.5819 |    -    |   0.0228  | 0.3274 |
+-----------+--------+--------+---------+-----------+--------+

pdens=10000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=11000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=12000
Molar fractions:
+-----------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0677 |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+---------+-----------+--------+

pdens=13000
Molar fractions:
+-----------+--------+---------+--------+-----------+--------+
| Temp. (K) | A1_FCC | BCC_2SL | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+---------+--------+-----------+--------+
|   673.0   | 0.0672 |  0.4251 |   -    |   0.0378  | 0.4698 |
|   873.0   | 0.0678 |    -    | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.0679 |  0.5308 |   -    |   0.0239  | 0.3774 |
+-----------+--------+---------+--------+-----------+--------+

pdens=14000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0675 | 0.1033 |    -    |   0.0371  | 0.7920 |
|   873.0   | 0.0677 |   -    |  0.3951 |   0.0319  | 0.5053 |
|   973.0   | 0.0679 |   -    |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+--------+---------+-----------+--------+

pdens=15000
Molar fractions:
+-----------+--------+--------+---------+-----------+--------+
| Temp. (K) | A1_FCC | A2_BCC | BCC_2SL | C14_LAVES | FCC_A1 |
+-----------+--------+--------+---------+-----------+--------+
|   673.0   | 0.0672 |   -    |  0.4251 |   0.0378  | 0.4698 |
|   873.0   | 0.0678 | 0.3606 |    -    |   0.0313  | 0.5403 |
|   973.0   | 0.0679 |   -    |  0.5308 |   0.0239  | 0.3774 |
+-----------+--------+--------+---------+-----------+--------+

Brandon Bocklund

unread,
Dec 3, 2022, 3:42:31 AM12/3/22
to pycalphad
Hi Marcelo,

What database is this for? It looks like there are multiple instances of the same phase. FCC_A1 and A1_FCC are probably the same phase and A2_BCC and BCC_2SL are likely the same as well (with BCC_2SL having the ordered and disordered parts). I suspect that the energies of these phases are the same and therefore there are some degenerate solutions. Can you share a self-contained reproducible example?

Cheers,
Brandon

Marcelo Falcão de Oliveira

unread,
Dec 3, 2022, 3:57:42 PM12/3/22
to Brandon Bocklund, pycalphad
Dear Brandon,

     This is PrecHiMn-4, a database for high Mn steels, reference: https://doi.org/10.1016/j.calphad.2016.11.006
     You are absolutely right, there are different descriptions for the same phase, some of them include order-disorder. I was quite naive thinking that I'd have no problems just keeping all of them in the calculation. However, even if I remove concurrent phase descriptions from the calculations I still get different results, although in this case the phases are always the same. Notice that increasing pdens doesn't help, see below. At the end of this message you can find the python script I'm using to calculate. Link for the database: https://drive.google.com/file/d/1cGZyiGPNfk_kIsiTIchohmz04M8d_Lww/view?usp=share_link

     Thank you for your reply and help.

pdens=500 (default)
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.7920 |
|   873.0   |   -    |     -     | 1.0000 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=1000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.0678 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=2000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.9022 |   0.0303  | 0.0675 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=3000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=4000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=5000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=6000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.0678 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=7000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.0678 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=8000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=9000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.0678 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+

pdens=10000
Molar fractions:
+-----------+--------+-----------+--------+
| Temp. (K) | BCC_A2 | C14_LAVES | FCC_A1 |
+-----------+--------+-----------+--------+
|   673.0   | 0.1033 |   0.0371  | 0.0675 |
|   873.0   | 0.3606 |   0.0313  | 0.5403 |
|   973.0   | 0.5819 |   0.0228  | 0.0679 |
+-----------+--------+-----------+--------+


Python script:

import time
ini=time.time()
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

from pycalphad import Database, equilibrium, variables as v
from pycalphad.plot.utils import phase_legend
from prettytable import PrettyTable

matplotlib.style.use('bmh')

dbf = Database('PrecHiMn-04-pycalphad.tdb')
phases_in_database = list(dbf.phases.keys())
phases_input=phases_in_database

phases_to_remove=['CUB_A13','FCC_4SL','BCC_4SL','BCC_2SL','A1_FCC','A2_BCC']
for i in phases_to_remove:
    phases_input.remove(i)

print(' ')
print('Phases selected from database:')
print(phases_input)
print(' ')
print('Phases removed from calculation:')
print(phases_to_remove)
print(' ')

comps = ['FE','MN','AL','NB','C','VA']
conds = {v.P: 101325, v.T: [673,873,973], v.X('MN'): 0.26, v.X('AL'): 0.16, v.X('NB'): 0.05, v.X('C'): 0.03}

print('Selected compounds:')
print(comps)
print(' ')
print('Conditions:')
print(conds)
print(' ')

print('Calculating')
eq = equilibrium(dbf,comps,phases_input,conds,calc_opts={"pdens":500})
print(' ')

phases_in_eq =  sorted(np.intersect1d(phases_input,eq.Phase.values,assume_unique=False,return_indices=False))
print('Phases in equilibrium:')
print(phases_in_eq)
print(' ')

tabela={}
for t in eq.T.values:
    tabela[t]={}
for t in eq.T.values:
    for v in eq.vertex.values:
        tabela[t][np.reshape(eq.sel(T=t,vertex=v).Phase.values,1)[0]]="{:1.4f}".format(np.reshape(eq.sel(T=t,vertex=v).NP.values,1)[0])
final=[]
for t in eq.T.values:
    linha=[t]
    for p in phases_in_eq:
        if p in tabela[t].keys():
            linha=linha+[tabela[t][p]]
        else:
            linha=linha+['-']
    final=final+[linha]
putz=PrettyTable(['Temp. (K)']+phases_in_eq)
for i in final:
  putz.add_row(i)
print('Molar fractions:')
print(putz)
print(' ')

phase_handles, phasemap = phase_legend(phases_in_eq)
plt.gca().set_title('Equilibrium Phases')
plt.gca().set_xlabel('Temperature (K)')
plt.gca().set_ylabel('Phase Fraction')
plt.gca().set_ylim((0,1.1))
tmin=min(eq.T.values)
tmax=max(eq.T.values)
plt.gca().set_xlim((tmin-100, tmax+200))
for name in phases_in_eq:
    plt.scatter(np.squeeze(eq.T.broadcast_like(eq.NP)), np.squeeze(eq.NP.where(eq.Phase == name)),color=phasemap[name], label=name)
plt.gca().legend(phase_handles, phasemap, loc="best")
plt.savefig('Equilibrium.png')

fim=time.time()
print('Exec. Time: ',time.strftime("%T", time.gmtime(fim-ini)))
print(' ')




--
You received this message because you are subscribed to a topic in the Google Groups "pycalphad" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pycalphad/FZBvi7NDI7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pycalphad+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pycalphad/2e96da5c-07b2-453f-addc-9133dba87777n%40googlegroups.com.


--
Marcelo Falcão de Oliveira
Professor Associado
Departamento de Engenharia de Materiais
EESC - USP
Av. João Dagnone, 1100,  Jd. Sta Angelina
CEP: 13563-120, São Carlos - SP - Brasil
e-mail: marcelo...@usp.br
Fone: (16) 3373-9583
Fax: (16) 3373-9590
Agenda: http://www.google.com/calendar/embed?src=marcelo.falcao%40usp.br&ctz=America/Sao_Paulo&mode=week
Reply all
Reply to author
Forward
0 new messages