In [1]:
import matplotlib.pyplot as plt
from pycalphad import equilibrium
from pycalphad import Database, Model
import pycalphad.variables as v
import numpy as np

db = Database('Issue43.tdb')
my_phases = ['FCC_A1', 'GAMMA_PRIME']
#my_phases = ['FCC_A1']

xcr = np.linspace(.15, .1846, 100)
#xcr = [1e-9, 1e-9+1e-16, 1e-9+2e-10, 1e-9+3e-10, 1e-9+4e-10, 1e-9+5e-10]#xcr[0:6]
eq = equilibrium(db, ['AL', 'NI', 'CR', 'VA'], my_phases,
                 {v.X('AL'): 0.1241, v.X('CR'): xcr, v.T: 1273, v.P: 101325},
                 verbose=False, pbar=False)
print(eq)


<xarray.Dataset>
Dimensions:       (P: 1, T: 1, X_AL: 1, X_CR: 100, component: 3, internal_dof: 6, vertex: 3)
Coordinates:
  * P             (P) float64 1.013e+05
  * T             (T) float64 1.273e+03
  * X_AL          (X_AL) float64 0.1241
  * X_CR          (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 ...
  * vertex        (vertex) int64 0 1 2
  * component     (component) object 'AL' 'CR' 'NI'
  * internal_dof  (internal_dof) int64 0 1 2 3 4 5
Data variables:
    GM            (P, T, X_AL, X_CR) float64 -8.459e+04 -8.458e+04 ...
    NP            (P, T, X_AL, X_CR, vertex) float64 1.0 1.464e-05 3.68e-07 ...
    MU            (P, T, X_AL, X_CR, component) float64 -1.817e+05 ...
    X             (P, T, X_AL, X_CR, vertex, component) float64 0.1241 0.15 ...
    Y             (P, T, X_AL, X_CR, vertex, internal_dof) float64 0.1241 ...
    Phase         (P, T, X_AL, X_CR, vertex) object 'FCC_A1' 'FCC_A1' ...
Attributes:
    engine: pycalphad 0.3.6+39.gaccfd84.dirty
    solve_iterations: 0
    hull_iterations: 1
    created: 2016-08-03 23:04:56.406604

In [2]:
print(eq.GM)


<xarray.DataArray 'GM' (P: 1, T: 1, X_AL: 1, X_CR: 100)>
array([[[[-84585.13625292, -84582.16125536, -84579.16734178,
          -84576.15453913, -84573.12287437, -84570.0723744 ,
          -84567.00306605, -84563.91497606, -84560.80813093,
          -84557.68255678, -84554.53828087, -84551.37532891,
          -84548.19372769, -84544.9935028 , -84541.77468057,
          -84538.53728699, -84535.28134795, -84532.00688927,
          -84528.7139367 , -84525.40251589, -84522.07265251,
          -84518.72437158, -84515.35769908, -84511.9726604 ,
          -84508.56928006, -84505.14758377, -84501.7075962 ,
          -84498.24934284, -84494.77284853, -84491.27813787,
          -84487.76523547, -84484.2341665 , -84480.68495527,
          -84477.11762633, -84473.53220414, -84469.92871309,
          -84466.30717747, -84462.66762151, -84459.01006937,
          -84455.33454512, -84451.64107277, -84447.92967651,
          -84444.2003797 , -84440.45320637, -84436.68818024,
          -84432.90532493, -84429.10466404, -84425.28622106,
          -84421.45001943, -84417.5960825 , -84413.72443358,
          -84409.83509589, -84405.92809259, -84402.00344677,
          -84398.06118145, -84394.10131958, -84390.12388407,
          -84386.12889771, -84382.11638333, -84378.08636358,
          -84374.03886107, -84369.97389838, -84365.891498  ,
          -84361.79168212, -84357.67447366, -84353.53989462,
          -84349.38796726, -84345.21871353, -84341.03215612,
          -84336.82831699, -84332.60721736, -84328.36887996,
          -84324.11332625, -84319.84057833, -84315.55065786,
          -84311.24358653, -84306.91938598, -84302.57807755,
          -84298.21968322, -84293.84422425, -84289.45172204,
          -84285.04219789, -84280.61567322, -84276.1721692 ,
          -84271.711707  , -84267.23430776, -84262.73999268,
          -84258.22878251, -84253.70069834, -84249.15576107,
          -84244.59399156, -84240.01541125, -84235.42003891,
          -84230.80789721, -84226.17900613, -84221.53338609,
          -84216.87105788, -84212.19204214, -84207.49635865,
          -84202.78402849]]]])
Coordinates:
  * P        (P) float64 1.013e+05
  * T        (T) float64 1.273e+03
  * X_AL     (X_AL) float64 0.1241
  * X_CR     (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 0.1521 ...

In [3]:
print(eq.MU / (8.31451 * eq['T']))
total_comp = np.nansum(eq.NP.values[..., np.newaxis] * eq.X.values, axis=-2)
#print(total_comp)
print((eq.MU * total_comp).sum(axis=-1))
print((eq.MU * total_comp).sum(axis=-1) - eq.GM)
print((eq.NP * eq.X.sel(component='CR')).sum(axis=-1) - eq.X_CR)


<xarray.DataArray (P: 1, T: 1, X_AL: 1, X_CR: 100, component: 3)>
array([[[[[-17.16958661,  -6.02675378,  -6.8284252 ],
          [-17.16564572,  -6.02307224,  -6.82986092],
          [-17.1617059 ,  -6.01939865,  -6.83129727],
          [-17.15776716,  -6.015733  ,  -6.83273425],
          [-17.15382948,  -6.01207526,  -6.83417186],
          [-17.14989287,  -6.0084254 ,  -6.8356101 ],
          [-17.14595734,  -6.00478339,  -6.83704896],
          [-17.14202287,  -6.00114921,  -6.83848844],
          [-17.13808947,  -5.99752284,  -6.83992854],
          [-17.13415713,  -5.99390424,  -6.84136927],
          [-17.13022587,  -5.99029339,  -6.84281061],
          [-17.12629567,  -5.98669026,  -6.84425257],
          [-17.12236654,  -5.98309484,  -6.84569515],
          [-17.11843847,  -5.9795071 ,  -6.84713834],
          [-17.11451147,  -5.975927  ,  -6.84858215],
          [-17.11058553,  -5.97235453,  -6.85002657],
          [-17.10666066,  -5.96878966,  -6.85147159],
          [-17.10273686,  -5.96523237,  -6.85291723],
          [-17.09881411,  -5.96168263,  -6.85436348],
          [-17.09489243,  -5.95814042,  -6.85581033],
          [-17.09097181,  -5.95460572,  -6.85725778],
          [-17.08705225,  -5.9510785 ,  -6.85870584],
          [-17.08313375,  -5.94755873,  -6.86015451],
          [-17.07921632,  -5.9440464 ,  -6.86160377],
          [-17.07529994,  -5.94054148,  -6.86305363],
          [-17.07138463,  -5.93704394,  -6.86450409],
          [-17.06747037,  -5.93355377,  -6.86595515],
          [-17.06355717,  -5.93007094,  -6.8674068 ],
          [-17.05964503,  -5.92659544,  -6.86885904],
          [-17.05573395,  -5.92312722,  -6.87031188],
          [-17.05182392,  -5.91966628,  -6.8717653 ],
          [-17.04791495,  -5.91621259,  -6.87321932],
          [-17.04400704,  -5.91276613,  -6.87467392],
          [-17.04010018,  -5.90932688,  -6.87612911],
          [-17.03619438,  -5.90589481,  -6.87758489],
          [-17.03228963,  -5.90246991,  -6.87904125],
          [-17.02838594,  -5.89905214,  -6.88049819],
          [-17.0244833 ,  -5.8956415 ,  -6.88195571],
          [-17.02058171,  -5.89223795,  -6.88341381],
          [-17.01668118,  -5.88884148,  -6.88487249],
          [-17.01278169,  -5.88545207,  -6.88633175],
          [-17.00888326,  -5.88206969,  -6.88779158],
          [-17.00498588,  -5.87869432,  -6.88925198],
          [-17.00108955,  -5.87532595,  -6.89071296],
          [-16.99719427,  -5.87196455,  -6.89217451],
          [-16.99330004,  -5.8686101 ,  -6.89363663],
          [-16.98940686,  -5.86526258,  -6.89509931],
          [-16.98551473,  -5.86192198,  -6.89656256],
          [-16.98162364,  -5.85858826,  -6.89802638],
          [-16.9777336 ,  -5.85526141,  -6.89949076],
          [-16.97384461,  -5.85194142,  -6.9009557 ],
          [-16.96995667,  -5.84862825,  -6.90242121],
          [-16.96606977,  -5.8453219 ,  -6.90388727],
          [-16.96218392,  -5.84202234,  -6.90535389],
          [-16.95829911,  -5.83872954,  -6.90682107],
          [-16.95441534,  -5.8354435 ,  -6.90828881],
          [-16.95053262,  -5.8321642 ,  -6.9097571 ],
          [-16.94665094,  -5.8288916 ,  -6.91122594],
          [-16.94277031,  -5.82562571,  -6.91269533],
          [-16.93889072,  -5.82236648,  -6.91416527],
          [-16.93501217,  -5.81911392,  -6.91563576],
          [-16.93113466,  -5.81586799,  -6.9171068 ],
          [-16.92725819,  -5.81262868,  -6.91857838],
          [-16.92338276,  -5.80939597,  -6.92005051],
          [-16.91950837,  -5.80616984,  -6.92152318],
          [-16.91563502,  -5.80295028,  -6.92299639],
          [-16.91176271,  -5.79973726,  -6.92447014],
          [-16.90789144,  -5.79653077,  -6.92594443],
          [-16.9040212 ,  -5.79333079,  -6.92741925],
          [-16.90015201,  -5.7901373 ,  -6.92889461],
          [-16.89628384,  -5.78695028,  -6.93037051],
          [-16.89241672,  -5.78376972,  -6.93184694],
          [-16.88855063,  -5.7805956 ,  -6.9333239 ],
          [-16.88468557,  -5.77742789,  -6.93480139],
          [-16.88082155,  -5.77426659,  -6.93627941],
          [-16.87695857,  -5.77111168,  -6.93775795],
          [-16.87309662,  -5.76796313,  -6.93923703],
          [-16.8692357 ,  -5.76482094,  -6.94071662],
          [-16.86537581,  -5.76168507,  -6.94219674],
          [-16.86151696,  -5.75855553,  -6.94367738],
          [-16.85765913,  -5.75543228,  -6.94515855],
          [-16.85380234,  -5.75231532,  -6.94664023],
          [-16.84994658,  -5.74920462,  -6.94812242],
          [-16.84609185,  -5.74610018,  -6.94960514],
          [-16.84223814,  -5.74300197,  -6.95108837],
          [-16.83838547,  -5.73990997,  -6.95257211],
          [-16.83453382,  -5.73682417,  -6.95405636],
          [-16.83068321,  -5.73374456,  -6.95554113],
          [-16.82683362,  -5.73067111,  -6.9570264 ],
          [-16.82298505,  -5.72760382,  -6.95851218],
          [-16.81913752,  -5.72454266,  -6.95999847],
          [-16.81529101,  -5.72148762,  -6.96148526],
          [-16.81144552,  -5.71843869,  -6.96297256],
          [-16.80760106,  -5.71539584,  -6.96446036],
          [-16.80375762,  -5.71235906,  -6.96594865],
          [-16.79991521,  -5.70932834,  -6.96743745],
          [-16.79607382,  -5.70630367,  -6.96892675],
          [-16.79223346,  -5.70328501,  -6.97041654],
          [-16.78839411,  -5.70027237,  -6.97190683],
          [-16.78455579,  -5.69726572,  -6.97339761]]]]])
Coordinates:
  * P          (P) float64 1.013e+05
  * T          (T) float64 1.273e+03
  * X_AL       (X_AL) float64 0.1241
  * X_CR       (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 0.1521 ...
  * component  (component) object 'AL' 'CR' 'NI'
<xarray.DataArray 'MU' (P: 1, T: 1, X_AL: 1, X_CR: 100)>
array([[[[-84585.13625292, -84582.16125536, -84579.16734178,
          -84576.15453913, -84573.12287437, -84570.0723744 ,
          -84567.00306605, -84563.91497606, -84560.80813093,
          -84557.68255678, -84554.53828087, -84551.37532891,
          -84548.19372769, -84544.9935028 , -84541.77468057,
          -84538.53728699, -84535.28134795, -84532.00688927,
          -84528.7139367 , -84525.40251589, -84522.07265251,
          -84518.72437158, -84515.35769908, -84511.9726604 ,
          -84508.56928006, -84505.14758377, -84501.7075962 ,
          -84498.24934284, -84494.77284853, -84491.27813787,
          -84487.76523547, -84484.2341665 , -84480.68495527,
          -84477.11762633, -84473.53220414, -84469.92871309,
          -84466.30717747, -84462.66762151, -84459.01006937,
          -84455.33454512, -84451.64107277, -84447.92967651,
          -84444.2003797 , -84440.45320637, -84436.68818024,
          -84432.90532493, -84429.10466404, -84425.28622106,
          -84421.45001943, -84417.5960825 , -84413.72443358,
          -84409.83509589, -84405.92809259, -84402.00344677,
          -84398.06118145, -84394.10131958, -84390.12388407,
          -84386.12889771, -84382.11638333, -84378.08636358,
          -84374.03886107, -84369.97389838, -84365.891498  ,
          -84361.79168212, -84357.67447366, -84353.53989462,
          -84349.38796726, -84345.21871353, -84341.03215612,
          -84336.82831699, -84332.60721736, -84328.36887996,
          -84324.11332625, -84319.84057833, -84315.55065786,
          -84311.24358653, -84306.91938598, -84302.57807755,
          -84298.21968322, -84293.84422425, -84289.45172204,
          -84285.04219789, -84280.61567322, -84276.1721692 ,
          -84271.711707  , -84267.23430776, -84262.73999268,
          -84258.22878251, -84253.70069834, -84249.15576107,
          -84244.59399156, -84240.01541125, -84235.42003891,
          -84230.80789721, -84226.17900613, -84221.53338609,
          -84216.87105788, -84212.19204214, -84207.49635865,
          -84202.78402849]]]])
Coordinates:
  * P        (P) float64 1.013e+05
  * T        (T) float64 1.273e+03
  * X_AL     (X_AL) float64 0.1241
  * X_CR     (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 0.1521 ...
<xarray.DataArray (P: 1, T: 1, X_AL: 1, X_CR: 100)>
array([[[[ -1.45519152e-11,   1.45519152e-11,  -2.91038305e-11,
            1.45519152e-11,  -2.91038305e-11,   2.91038305e-11,
            2.91038305e-11,   1.45519152e-11,   1.45519152e-11,
            2.91038305e-11,   0.00000000e+00,  -1.45519152e-11,
           -2.91038305e-11,   1.45519152e-11,  -1.45519152e-11,
            0.00000000e+00,   1.45519152e-11,   0.00000000e+00,
           -2.91038305e-11,   0.00000000e+00,   1.45519152e-11,
            0.00000000e+00,   0.00000000e+00,   1.45519152e-11,
           -1.45519152e-11,   1.45519152e-11,   0.00000000e+00,
            0.00000000e+00,   0.00000000e+00,   2.91038305e-11,
            1.45519152e-11,  -1.45519152e-11,   1.45519152e-11,
            0.00000000e+00,   0.00000000e+00,   4.36557457e-11,
            0.00000000e+00,  -1.45519152e-11,   0.00000000e+00,
           -1.45519152e-11,   1.45519152e-11,  -1.45519152e-11,
           -1.45519152e-11,   1.45519152e-11,   1.45519152e-11,
           -1.45519152e-11,  -1.45519152e-11,  -2.91038305e-11,
            0.00000000e+00,   2.91038305e-11,   0.00000000e+00,
            0.00000000e+00,  -1.45519152e-11,   0.00000000e+00,
            1.45519152e-11,   0.00000000e+00,   2.91038305e-11,
            0.00000000e+00,  -2.91038305e-11,  -1.45519152e-11,
           -1.45519152e-11,   0.00000000e+00,  -2.91038305e-11,
            0.00000000e+00,   1.45519152e-11,  -1.45519152e-11,
            1.45519152e-11,   0.00000000e+00,   1.45519152e-11,
           -1.45519152e-11,   0.00000000e+00,   1.45519152e-11,
           -2.91038305e-11,   0.00000000e+00,   1.45519152e-11,
            0.00000000e+00,  -1.45519152e-11,   0.00000000e+00,
            0.00000000e+00,  -2.91038305e-11,  -1.45519152e-11,
            1.45519152e-11,  -1.45519152e-11,  -2.91038305e-11,
            1.45519152e-11,   1.45519152e-11,   2.91038305e-11,
            2.91038305e-11,   2.91038305e-11,   2.91038305e-11,
           -1.45519152e-11,  -1.45519152e-11,   0.00000000e+00,
            0.00000000e+00,  -1.45519152e-11,   1.45519152e-11,
            0.00000000e+00,   1.45519152e-11,   1.45519152e-11,
            0.00000000e+00]]]])
Coordinates:
  * P        (P) float64 1.013e+05
  * T        (T) float64 1.273e+03
  * X_AL     (X_AL) float64 0.1241
  * X_CR     (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 0.1521 ...
<xarray.DataArray (P: 1, T: 1, X_AL: 1, X_CR: 100)>
array([[[[  2.84439139e-13,  -2.86068391e-12,  -2.70788947e-12,
           -2.51271226e-12,  -2.23759899e-12,  -1.86203830e-12,
           -1.98330241e-12,   1.17184040e-13,  -9.49240686e-15,
           -4.00735001e-13,  -1.23531740e-12,   6.38655795e-14,
            3.48915341e-13,   5.93913807e-13,   8.02496958e-13,
            9.71639436e-13,   1.13489773e-12,   1.26829103e-12,
            1.34281475e-12,   1.34622868e-12,   4.83613150e-13,
            1.66633374e-12,   1.76023085e-12,   2.33146835e-14,
            1.28833055e-12,   4.97157870e-13,   2.06906714e-12,
            2.16729412e-12,  -9.18903842e-13,  -2.35056419e-12,
           -1.23774602e-11,  -1.39924738e-11,  -1.47838131e-11,
           -1.50278123e-11,  -1.49023849e-11,  -1.45181644e-11,
           -1.39480094e-11,  -1.32385491e-11,  -1.24226462e-11,
           -1.15207566e-11,  -1.05469244e-11,  -2.37809772e-12,
           -2.10495510e-12,  -1.81979432e-12,  -1.52219903e-12,
           -1.21372357e-12,  -8.94229135e-13,  -5.63826763e-13,
           -2.23238095e-13,   1.27758915e-13,   4.89303043e-13,
            8.61505312e-13,   1.24372734e-12,   1.63660752e-12,
            2.04009032e-12,   2.45456433e-12,   2.88033486e-12,
            3.53631013e-12,   3.19605453e-12,   2.85363400e-12,
            2.51010324e-12,   2.17265095e-12,   1.83705828e-12,
            6.01582673e-12,   4.70024020e-12,   3.40699691e-12,
            2.16465734e-12,   4.02564093e-12,  -1.36224365e-13,
           -6.01691752e-11,  -6.85745905e-12,  -9.50692303e-12,
           -3.21348503e-12,  -3.71797038e-12,  -4.19550505e-12,
           -4.64370209e-12,  -5.05293030e-12,  -1.33154598e-12,
           -1.21211374e-12,  -1.05609965e-12,  -4.68430850e-13,
            0.00000000e+00,  -1.04527498e-13,  -1.11799459e-13,
           -1.19348975e-13,  -1.26204602e-13,  -2.12641016e-12,
           -2.22558083e-12,  -2.32561193e-12,  -2.41445752e-12,
           -2.50599541e-12,  -1.13578036e-11,  -2.66942024e-12,
           -2.74358314e-12,  -2.81599744e-12,  -7.20729032e-13,
            0.00000000e+00,  -3.00620639e-12,  -7.65609798e-13,
           -2.85677038e-12]]]])
Coordinates:
  * P          (P) float64 1.013e+05
  * T          (T) float64 1.273e+03
  * X_AL       (X_AL) float64 0.1241
  * X_CR       (X_CR) float64 0.15 0.1503 0.1507 0.151 0.1514 0.1517 0.1521 ...
    component  <U2 'CR'

In [9]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(12,12))
ax = fig.gca()
X = eq.X_CR.values
ax.set_xlabel('X(CR)')
#ax.scatter(X, eq.GM)
ax.scatter(X, eq.MU.sel(component='AL'), label='Al', c='r')
ax.set_ylabel('MU(AL)')
#ax.scatter(X, eq.MU.sel(component='CR'), label='Cr', c='g')
#ax.scatter(X, eq.MU.sel(component='NI'), label='Ni', c='b')
plt.show()



In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
color_dict = {'FCC_A1': 'r', 'GAMMA_PRIME': 'g', '': 'w'}
fig = plt.figure(figsize=(12,12))
ax = fig.gca()
X = eq.X_CR.values
ax.set_xlabel('X(CR)')
for phase, color in color_dict.items():
    phase_indices = np.nonzero(eq.Phase.values == phase)
    if len(phase_indices[0]) == 0:
        continue
    phase_array = eq.X.sel(component='CR').isel_points(dim='new', **dict(zip(eq.Phase.coords.keys(), phase_indices)))
    ax.scatter(phase_array.X_CR.values, phase_array.values, c=color)
plt.show()



In [6]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
color_dict = {'FCC_A1': 'r', 'GAMMA_PRIME': 'g', '': 'w'}
fig = plt.figure(figsize=(12,12))
ax = fig.gca()
X = eq.X_CR.values
ax.set_xlabel('X(CR)')
for phase, color in color_dict.items():
    phase_indices = np.nonzero(eq.Phase.values == phase)
    if len(phase_indices[0]) == 0:
        continue
    phase_array = eq.NP.isel_points(dim='new', **dict(zip(eq.Phase.coords.keys(), phase_indices)))
    ax.scatter(phase_array.X_CR.values, phase_array.values, c=color)
plt.show()



In [7]:
from pycalphad import calculate
res = calculate(db, ['AL', 'NI', 'CR', 'VA'], 'FCC_A1', pdens=100, T=1273, P=101325)

In [8]:
%matplotlib qt
import matplotlib.tri
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
triang = matplotlib.tri.Triangulation(np.squeeze(res.X.sel(component='AL').values), np.squeeze(res.X.sel(component='CR').values))
ax.scatter(np.squeeze(res.X.sel(component='AL').values), np.squeeze(res.X.sel(component='CR').values),
           np.squeeze(res.GM.values), c='b')
ax.set_xlabel('X_AL')
ax.set_ylabel('X_CR')
ax.set_zlabel('GM')
ax.plot(np.full_like(eq.X_CR, eq.X_AL), eq.X_CR, np.squeeze(eq.GM.values), c='r')
plt.show()



In [ ]: