In [3]:
import numpy as np
from pycalphad import Model, Database, calculate, equilibrium
from pycalphad.core.compiled_model import CompiledModel
import pycalphad.variables as v
dbf = Database('alfe_sei.TDB')
models = {key: CompiledModel(dbf, ['AL', 'FE', 'VA'], key) for key in dbf.phases.keys()}

In [4]:
equilibrium(dbf, ['AL', 'FE', 'VA'], ['BCC_A2'], {v.T: 700, v.X('AL'): 0.3, v.P: 101325}, model=models, verbose=True, _diagnostic=True)


Calculation Backend: Compiled (autowrap)
Components: AL FE VA
Phases: BCC_A2 [done]
('Phases', array(['BCC_A2'], 
      dtype='<U6'))
('step', array([ -6.01202405e-04,   6.01202405e-04,  -2.66405367e-17,
         4.69398059e-17,  -1.72517179e+04,  -2.65800736e+04,
        -7.26061654e+04,  -3.44833687e+04]))
('Site fractions', array([ 0.3,  0.7,  1. ]))
('Phase fractions', array([ 1.]))
('NEW_L_MULTIPLIERS', array([-17251.71786268, -26580.07358682, -72606.16541156, -34483.36873261]))
('Chem pot progress', array([ 82.41973855,  -2.76362506]))
('Energy progress', -22.970729499771551)
('Driving force', 45.762113524207962)
('obj weight', 1.0)
('Phases', array(['BCC_A2'], 
      dtype='<U6'))
('step', array([ -2.75267951e-18,  -2.65231812e-17,  -1.34826065e-17,
         9.02392987e-17,  -1.72288697e+04,  -2.65800631e+04,
        -7.26290280e+04,  -3.45062577e+04]))
('Site fractions', array([ 0.3,  0.7,  1. ]))
('Phase fractions', array([ 1.]))
('NEW_L_MULTIPLIERS', array([-17228.86965737, -26580.06314083, -72629.02795652, -34506.25772957]))
('Chem pot progress', array([-22.86254495, -22.88899696]))
('Energy progress', 22.881052166121663)
('Driving force', 1.4551915228366852e-11)
('obj weight', 1.0)
('Phases', array(['BCC_A2'], 
      dtype='<U6'))
('step', array([ -2.75267951e-18,  -2.65231812e-17,  -1.34826065e-17,
         9.02392987e-17,  -1.72288697e+04,  -2.65800631e+04,
        -7.26290280e+04,  -3.45062577e+04]))
('Site fractions', array([ 0.3,  0.7,  1. ]))
('Phase fractions', array([ 1.]))
('NEW_L_MULTIPLIERS', array([-17228.86965737, -26580.06314083, -72629.02795652, -34506.25772957]))
('Chem pot progress', array([ 0.,  0.]))
('Energy progress', 0.0)
('Driving force', 1.4551915228366852e-11)
('obj weight', 1.0)
No progress
Out[4]:
<xarray.Dataset>
Dimensions:       (P: 1, T: 1, X_AL: 1, component: 2, internal_dof: 3, vertex: 2)
Coordinates:
  * P             (P) float64 1.013e+05
  * T             (T) float64 700.0
  * X_AL          (X_AL) float64 0.3
  * vertex        (vertex) int64 0 1
  * component     (component) <U2 'AL' 'FE'
  * internal_dof  (internal_dof) int64 0 1 2
Data variables:
    MU            (P, T, X_AL, component) float64 -7.263e+04 -3.451e+04
    GM            (P, T, X_AL) float64 -4.594e+04
    NP            (P, T, X_AL, vertex) float64 1.0 nan
    X             (P, T, X_AL, vertex, component) float64 0.3 0.7 nan nan
    Phase         (P, T, X_AL, vertex) <U6 'BCC_A2' ''
    Y             (P, T, X_AL, vertex, internal_dof) float64 0.3 0.7 1.0 nan ...
Attributes:
    hull_iterations: 1
    solve_iterations: 3
    engine: pycalphad 0.4.2+158.g3471e93.dirty
    created: 2017-03-18 18:16:40.404924

In [ ]:
from pycalphad.core.sympydiff_utils import build_functions
from pycalphad import Model
import pycalphad.variables as v
mod = Model(dbf, ['AL', 'FE', 'VA'], 'BCC_A2')
obj,grad,hess = build_functions(mod.ast,mod.variables)

In [ ]:
hess.kernel(np.asfortranarray([[7.00000000e+02,   2.98217195e-01,
         7.01782805e-01,   1.00000000e+00]]), 0)[1:,1:]

In [ ]:
grad.kernel(np.asfortranarray([[7.00000000e+02,   2.96346127e-01,
         7.03653873e-01,   1.00000000e+00]]), 0)[-1]

In [ ]:
(grad.kernel(np.asfortranarray([[7.00000000e+02,   2.98217195e-01,
         7.01782805e-01,   1.00000000e+00+1e-12]]), 0)[1:] - grad.kernel(np.asfortranarray([[7.00000000e+02,   2.98217195e-01,
         7.01782805e-01,   1.00000000e+00]]), 0)[1:])/1e-12

In [ ]:
('fe', 6849.096857268174, 6849.096857294899, 2.6724592316895723e-08)
('dof', array([  1.01325000e+05,   7.00000000e+02,   2.96346127e-01,
         7.03653873e-01,   1.00000000e+00]))

In [ ]:
mod.GM.diff(v.Y('BCC_A2', 1, 'VA'))

In [ ]:
8.3145*700*(0.3*np.log(0.3)+0.7*np.log(0.7))

In [ ]: