pycalphad triangluar

Make ternary isotherms with pycalphad.

The following database can be found at https://doi.org/10.1016/j.jnoncrysol.2016.09.031. It is not linked in this repo because the file is behind a paywall. Nevertheless, changing the database and component names should give you the same plot in any case.


In [1]:
database_file = '/Users/brandon/Box Sync/databases/literature/Al-Cu-Zr_Zhou.tdb'

Imports and setup of the database


In [2]:
%matplotlib inline
from matplotlib import pyplot as plt
from pycalphad import equilibrium, Database, ternplot, eqplot, Model, variables as v
dbf = Database(database_file)
phases = list(dbf.phases.keys())
comps = ['AL','CU','ZR','VA']
conditions = {v.X('ZR'): (0,1,0.008), v.X('AL'): (0,1,0.009), v.P: 101325, v.T: 1373}

In [4]:
eq = equilibrium(dbf, comps, phases, conditions, x=v.X('ZR'), y=v.X('AL'), calc_opts={'pdens': 2000}, model=Model) 
eqplot(eq, x=v.X('AL'), y=v.X('CU'))


/Users/brandon/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/async.py:13: UserWarning: `dask.async.get_sync` has been moved to `dask.local.get_sync`, please update your imports
  warnings.warn(_msg.format('get_sync'))
/Users/brandon/.virtualenvs/espei-emcee/lib/python3.6/site-packages/pycalphad/core/utils.py:57: RuntimeWarning: divide by zero encountered in log
  pts = -np.log(pts)
/Users/brandon/.virtualenvs/espei-emcee/lib/python3.6/site-packages/pycalphad/core/utils.py:61: RuntimeWarning: invalid value encountered in true_divide
  pts[:, cur_idx:end_idx] /= pts[:, cur_idx:end_idx].sum(axis=1)[:, None]
---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-4-6dcdc726977e> in <module>()
----> 1 eq = equilibrium(dbf, comps, phases, conditions, x=v.X('ZR'), y=v.X('AL'), calc_opts={'pdens': 2000}, model=Model)
      2 eqplot(eq, x=v.X('AL'), y=v.X('CU'))

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/pycalphad/core/equilibrium.py in equilibrium(dbf, comps, phases, conditions, output, model, verbose, broadcast, calc_opts, scheduler, parameters, **kwargs)
    356         properties = delayed(properties.merge, pure=False)(eqcal, inplace=True, compat='equals')
    357     if scheduler is not None:
--> 358         properties = dask.compute(properties, get=scheduler)[0]
    359     properties.attrs['created'] = datetime.utcnow().isoformat()
    360     if len(kwargs) > 0:

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/base.py in compute(*args, **kwargs)
    203     dsk = collections_to_dsk(variables, optimize_graph, **kwargs)
    204     keys = [var._keys() for var in variables]
--> 205     results = get(dsk, keys, **kwargs)
    206 
    207     results_iter = iter(results)

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/async.py in get_sync(*args, **kwargs)
     12 def get_sync(*args, **kwargs):
     13     warnings.warn(_msg.format('get_sync'))
---> 14     return local.get_sync(*args, **kwargs)
     15 
     16 

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in get_sync(dsk, keys, **kwargs)
    560     """
    561     kwargs.pop('num_workers', None)    # if num_workers present, remove it
--> 562     return get_async(apply_sync, 1, dsk, keys, **kwargs)
    563 
    564 

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, **kwargs)
    527 
    528                 while state['ready'] and len(state['running']) < num_workers:
--> 529                     fire_task()
    530 
    531             succeeded = True

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in fire_task()
    502                             args=(key, dumps((dsk[key], data)),
    503                                   dumps, loads, get_id, pack_exception),
--> 504                             callback=queue.put)
    505 
    506             # Seed initial tasks into the thread pool

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in apply_sync(func, args, kwds, callback)
    549 def apply_sync(func, args=(), kwds={}, callback=None):
    550     """ A naive synchronous version of apply_async """
--> 551     res = func(*args, **kwds)
    552     if callback is not None:
    553         callback(res)

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
    293         failed = False
    294     except BaseException as e:
--> 295         result = pack_exception(e, dumps)
    296         failed = True
    297     return key, result, failed

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
    288     try:
    289         task, data = loads(task_info)
--> 290         result = _execute_task(task, data)
    291         id = get_id()
    292         result = dumps((result, id))

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/dask/local.py in _execute_task(arg, cache, dsk)
    269         func, args = arg[0], arg[1:]
    270         args2 = [_execute_task(a, cache) for a in args]
--> 271         return func(*args2)
    272     elif not ishashable(arg):
    273         return arg

pycalphad/core/eqsolver.pyx in pycalphad.core.eqsolver._solve_eq_at_conditions (pycalphad/core/eqsolver.c:12843)()

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/numpy/linalg/linalg.py in solve(a, b)
    373     signature = 'DD->D' if isComplexType(t) else 'dd->d'
    374     extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
--> 375     r = gufunc(a, b, signature=signature, extobj=extobj)
    376 
    377     return wrap(r.astype(result_t, copy=False))

~/.virtualenvs/espei-emcee/lib/python3.6/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_singular(err, flag)
     88 
     89 def _raise_linalgerror_singular(err, flag):
---> 90     raise LinAlgError("Singular matrix")
     91 
     92 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix

In [3]:
fig = plt.figure(figsize=(20,20))
ternplot(dbf, comps, phases, conditions, x=v.X('ZR'), y=v.X('AL'), eq_kwargs={'calc_opts': {'pdens': 2000}})


/Users/brandon/.virtualenvs/pycalphad-vis/lib/python3.6/site-packages/dask/async.py:13: UserWarning: `dask.async.get_sync` has been moved to `dask.local.get_sync`, please update your imports
  warnings.warn(_msg.format('get_sync'))
/Users/brandon/Projects/pycalphad/pycalphad/core/utils.py:146: RuntimeWarning: divide by zero encountered in log
  pts = -np.log(pts)
/Users/brandon/Projects/pycalphad/pycalphad/core/utils.py:150: RuntimeWarning: invalid value encountered in true_divide
  pts[:, cur_idx:end_idx] /= pts[:, cur_idx:end_idx].sum(axis=1)[:, None]
Out[3]:
<matplotlib.axes._subplots.TriangularAxesSubplot at 0x1027639e8>
<matplotlib.figure.Figure at 0x10770dbe0>

In [11]:
equilibrium?

In [34]:
fig = plt.figure(figsize=(50,50))
ax = eqplot(eq, x=v.X('AL'), y=v.X('CU'))
plt.savefig('isotherm.eps')


<matplotlib.figure.Figure at 0x117b4e7b8>

In [ ]: