You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unary plugins (see the unary skeleton repo) need to be written with the energy functions as valid SymPy expressions using pycalphad StateVariables. Many users have unary Gibbs energies and pure element lattice stabilities implemented as functions in TDB files.
A tool should exist to convert these TDB files valid Python/SymPy expressions so that it's easier to create reference state plugins for ESPEI. Here's some example code based on an old notebook that I wrote
frompycalphadimportDatabasedbf=Database('Mg-piecewise-example.tdb')
fromsympyimportSymbolfromsympy.utilitiesimporttopological_sortfrompycalphadimportvariablesasvdefextract_symbol_value(symbol):
"""Return the value of a Piecewise if it only has one expression """# A Piecewise with a length of 2 has the expression over the range and then 0 otherwise.# We want to return the expression in this case, otherwise the expression is a "real" Piecewise.iflen(symbol.args) ==2:
returnsymbol.args[0].exprreturnsymboldefsorted_symbols(symbols):
"""Takes a dictionary of {Symbol: Piecewise} and returns the topological sort replacement """# Topological sorting requires the verticies and edges of the a graph of symbol dependencies.verticies=list(symbols.keys())
edges= []
forvertexinverticies:
free_symbols=symbols[vertex].free_symbols# Filter out the StateVariables.# This will ensure P, T variables are not included in the graph because they can be variables in TDBs.free_symbols= [symbolforsymbolinfree_symbolsifnotisinstance(symbol, v.StateVariable)]
# construct the edges (dependencies) of the symbols if there are anyiflen(free_symbols):
edges.extend([(str(vertex), str(symbol)) forsymbolinfree_symbols])
returntopological_sort((verticies, edges))
defget_reduced_expression(dbf, symbol):
"""Return an expression for the passed symbol (as a string) reduced to only a function of state variables """# To reduce an expression, we have to pass a list of substitions to the expression in the order# we want to substitute them to get to having only StateVaribles as degrees of freedom.# Topological sorting orders the replacements in the correct order.topologically_sorted_symbols=sorted_symbols(dbf.symbols)
# Then we construct the values that we will replace each symbol with, deconstructing the# symbols that are Piecewise, if necessary.replacements= [(sym, extract_symbol_value(dbf.symbols[sym])) forsymintopologically_sorted_symbols]
returndbf.symbols[symbol].subs(replacements)
Unary plugins (see the unary skeleton repo) need to be written with the energy functions as valid SymPy expressions using pycalphad StateVariables. Many users have unary Gibbs energies and pure element lattice stabilities implemented as functions in TDB files.
A tool should exist to convert these TDB files valid Python/SymPy expressions so that it's easier to create reference state plugins for ESPEI. Here's some example code based on an old notebook that I wrote
This can be run via
Which for, example, may print:
This output could be directly pasted into a module starting with:
The text was updated successfully, but these errors were encountered: