Skip to content

Instantly share code, notes, and snippets.

@richardotis
Last active March 4, 2016 00:56
Show Gist options
  • Save richardotis/e9830f8f3ed4434bfd5e to your computer and use it in GitHub Desktop.
Save richardotis/e9830f8f3ed4434bfd5e to your computer and use it in GitHub Desktop.
Creating a custom model in pycalphad
from pycalphad import Database, Model, calculate
import pycalphad.variables as v
import numpy as np
import sympy
dbf = Database('NI_AL_DUPIN_2001.TDB')
class NewModel(Model):
def build_phase(self, dbe, phase_name, symbols, param_search):
self.models['test'] = -13000*v.T*v.R*v.Y(phase_name, 0, 'AL')*v.Y(phase_name, 0, 'NI')
bubbles = property(lambda self: self.models['test'] / 10)
# pycalphad needs custom properties to be defined for all phases, at the moment
# Maybe 'bubbles' has no meaning for FCC, so we return NaN
class FCCModel(Model):
# Constant values need to be wrapped in sympy.S() so they are made symbolic
bubbles = property(lambda self: sympy.S(np.nan))
result = calculate(dbf, ['AL', 'NI', 'VA'], ['LIQUID', 'FCC_L12'], model={'LIQUID': NewModel, 'FCC_L12': FCCModel},
output='bubbles', T=1500, P=101325, points={'LIQUID': [[0.9, 0.1], [0.2, 0.8]],
'FCC_L12': [[0.2, 0.8, 0.2, 0.8, 1], [0.4, 0.6, 0.6, 0.4, 1]]})
print(result['bubbles'].values[np.nonzero(result.Phase.values == 'LIQUID')])
print(result['bubbles'].values[np.nonzero(result.Phase.values == 'FCC_L12')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment