In [1]:
from pycalphad import Database, Model, variables as v
from pycalphad import equilibrium, calculate
import numpy as np
from pycalphad.tests.datasets import *
dbf = Database('alzn_mey.tdb')

In [2]:
from pycalphad.core.solver import InteriorPointSolver
class ProblemSaver(InteriorPointSolver):
    saved_problem = [None]
    def solve(self, prob):
        self.saved_problem[0] = prob
        self.verbose = True
        return super(ProblemSaver, self).solve(prob)
#v.T.default_value = 300
eq2 = equilibrium(dbf, ['AL', 'ZN', 'VA'], ['FCC_A1', 'LIQUID', 'HCP_A3'],
                 {v.X('ZN'): 1e-3, v.NP('LIQUID'): 1e-3,
                  v.P: 1e5}, verbose=True, solver=ProblemSaver())
print(eq2)


Components: AL VA ZN
Phases: FCC_A1 
HCP_A3 
LIQUID 
[done]
Composition Sets [CompositionSet(FCC_A1, [0.12024048 0.87975952], NP=0.3333333333333333, GM=-10489.356271065852), CompositionSet(HCP_A3, [1.e-13 1.e+00], NP=0.3333333333333333, GM=-12489.369042323267), CompositionSet(LIQUID, [0.00200401 0.99799599], NP=0.001 [fixed], GM=-8422.501520948857)]
Chemical Potentials [0. 0.]
Trying to improve poor solution
Chemical Potentials [-28221.13721901 -85342.64062357]
[ 1.00000000e+00  1.00000000e+05  9.99999999e-05 -2.60627075e-11
  0.00000000e+00  3.72324394e-11  1.00000000e+06  1.00000000e+03
  6.36824117e+01 -7.07161713e-05 -1.36278686e-08]
[1.00000000e+00 1.00000000e+05 9.28031190e+02 9.99970699e-01
 2.93005242e-05 3.44941624e-01 6.55058376e-01 9.99913560e-01
 8.64397802e-05 9.98418091e-01 1.48190943e-03 9.99999999e-05]
Status: 2 b'Algorithm converged to a point of local infeasibility. Problem may be infeasible.'
Rebuilding grid {'N': 1.0, 'P': 100000.0, 'T': 928.0311895921062}
Adding CompositionSet(FCC_A1, [9.99165120e-01 8.34879849e-04], NP=0.25, GM=-37595.38295656821) Driving force: 9326.556145413335
Redundant phase: CompositionSet(FCC_A1, [9.99165120e-01 8.34879849e-04], NP=0.25, GM=-37595.38295656821)
Removing CompositionSet(FCC_A1, [9.99165120e-01 8.34879849e-04], NP=nan, GM=-37595.38295656821)
Trying to improve poor solution
Calculation Failed:  OrderedDict([('N', array(1.)), ('NP_LIQUID', array(0.001)), ('P', array(100000.)), ('X_ZN', array(0.001))]) b"Restoration phase failed, algorithm doesn't know how to proceed."
Chemical Potentials [-28524.1709219  -86138.75168865]
[ 1.00000000e+00  1.00000000e+05  1.00000000e-04  2.23856489e-11
  0.00000000e+00  6.93063384e-11  1.00000001e+06  1.00000000e+03
 -4.51562912e-06 -1.81582943e-01  6.40586748e+01]
[1.00000000e+00 1.00000000e+05 9.33578970e+02 9.99970758e-01
 2.92417956e-05 3.46746680e-01 6.53253320e-01 9.99913655e-01
 8.63445774e-05 9.98413916e-01 1.48609417e-03 1.00000000e-04]
Status: -2 b"Restoration phase failed, algorithm doesn't know how to proceed."
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Adding CompositionSet(FCC_A1, [0.997999 0.002001], NP=0.25, GM=-37988.973458142595) Driving force: 9320.429161622724
Trying to improve poor solution
Calculation Failed:  OrderedDict([('N', array(1.)), ('NP_LIQUID', array(0.001)), ('P', array(100000.)), ('X_ZN', array(0.001))]) b'Maximum number of iterations exceeded (can be specified by an option).'
Chemical Potentials [-34595.13520232 -80575.1656946 ]
[ 1.00000264e+00  1.00000000e+05  2.57983216e-03 -1.25909310e-02
  4.31764638e-04  8.44970382e-01 -8.35894332e-01  1.00000000e+06
  1.07353499e+03 -1.94108442e+01 -1.47277016e+03 -2.10774338e+01
  2.17262059e+01]
[1.00000264e+00 1.00000000e+05 9.34695267e+02 9.97738101e-01
 2.26188659e-03 5.79560762e-01 4.20439238e-01 9.98713800e-01
 1.28704464e-03 9.98980689e-01 1.01847536e-03 9.65107550e-03
 1.01009960e-04 2.57983216e-03 9.87668082e-01]
Status: -1 b'Maximum number of iterations exceeded (can be specified by an option).'
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Adding CompositionSet(FCC_A1, [0.997999 0.002001], NP=0.2, GM=-38056.05699843922) Driving force: 9320.429161622724
Redundant phase: CompositionSet(FCC_A1, [0.99898152 0.00101848], NP=0.9876680824052152, GM=-38005.20366567674)
Redundant phase: CompositionSet(FCC_A1, [0.997999 0.002001], NP=0.2, GM=-38056.05699843922)
Exceeded zero seen: CompositionSet(HCP_A3, [0.57956076 0.42043924], NP=0.0001, GM=-43807.36130751368)
Removing CompositionSet(FCC_A1, [0.997999 0.002001], NP=nan, GM=-38056.05699843922)
Removing CompositionSet(FCC_A1, [0.99898152 0.00101848], NP=nan, GM=-38005.20366567674)
Removing CompositionSet(HCP_A3, [0.57956076 0.42043924], NP=nan, GM=-43807.36130751368)
Trying to improve poor solution
Chemical Potentials [-37826.97532632 -92518.24565636]
[ 1.00000264e+00  1.00000000e+05  2.57983216e-03 -2.11457518e-11
 -1.31876732e-10  1.00000000e+06  1.00000000e+03 -1.61179025e-06
  1.57091337e-04]
[1.00000264e+00 1.00000000e+05 9.32654612e+02 9.99003634e-01
 9.96365959e-04 9.97594999e-01 2.40500080e-03 9.97420168e-01
 2.57983216e-03]
Status: 1 b'Algorithm stopped at a point that was converged, not to "desired" tolerances, but to "acceptable" tolerances (see the acceptable-... options).'
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [0.997999 0.002001] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [0.997999 0.002001] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [0.997999 0.002001] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [0.997999 0.002001] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [9.99165120e-01 8.34879849e-04] is not distinct from previously removed phase
Candidate composition set FCC_A1 at [0.997999 0.002001] is not distinct from previously removed phase
Composition Sets [CompositionSet(FCC_A1, [9.99003634e-01 9.96365959e-04], NP=0.9974201678413114, GM=-37881.467849036235), CompositionSet(LIQUID, [0.997595 0.002405], NP=0.0025798321586886297 [fixed], GM=-37958.507870368776)]
<xarray.Dataset>
Dimensions:    (N: 1, NP_LIQUID: 1, P: 1, X_ZN: 1, component: 2, internal_dof: 2, vertex: 3)
Coordinates:
  * N          (N) float64 1.0
  * NP_LIQUID  (NP_LIQUID) float64 0.001
  * P          (P) float64 1e+05
  * X_ZN       (X_ZN) float64 0.001
  * vertex     (vertex) int64 0 1 2
  * component  (component) <U2 'AL' 'ZN'
Dimensions without coordinates: internal_dof
Data variables:
    NP         (N, P, NP_LIQUID, X_ZN, vertex) float64 0.9974 0.00258 nan
    GM         (N, P, NP_LIQUID, X_ZN) float64 -3.788e+04
    MU         (N, P, NP_LIQUID, X_ZN, component) float64 -3.783e+04 -9.252e+04
    X          (N, P, NP_LIQUID, X_ZN, vertex, component) float64 0.999 ... nan
    Y          (N, P, NP_LIQUID, X_ZN, vertex, internal_dof) float64 0.999 ... nan
    Phase      (N, P, NP_LIQUID, X_ZN, vertex) <U6 'FCC_A1' 'LIQUID' ''
    T          (N, P, NP_LIQUID, X_ZN) float64 932.7
Attributes:
    engine:   pycalphad 0.7.1.post2+37.g3135877.dirty
    created:  2019-05-28T23:18:22.244054

In [3]:
%matplotlib inline
from pycalphad import calculate
from pycalphad.plot.utils import phase_legend
import numpy as np
import matplotlib.pyplot as plt

my_phases = ['FCC_A1', 'LIQUID', 'HCP_A3']
legend_handles, colorlist = phase_legend(my_phases)
fig = plt.figure(figsize=(9,6))
ax = fig.gca()
for name in my_phases:
    result = calculate(dbf, ['AL', 'ZN', 'VA'], name, P=101325, T=float(eq2['T'].values.flat[0]), output='GM')
    ax.scatter(result.X.sel(component='ZN'), result.GM,
               marker='.', s=5, color=colorlist[name.upper()])
ax.set_xlim((0, 1))
ax.legend(handles=legend_handles, loc='center left', bbox_to_anchor=(1, 0.6))

ax.plot([0,1], eq2['MU'].values.flatten(), c='k')
#plt.xlim((0,0.01))
#plt.ylim((-40000, -30000))
plt.show()



In [ ]: