Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Model: Change some uses of subs to symbol_replace for performance #340

Merged
merged 1 commit into from May 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions pycalphad/model.py
Expand Up @@ -728,7 +728,7 @@ def magnetic_energy(self, dbe):
(1., True),
evaluate=False
)
self.BMAG = self.beta = beta.subs(self._symbols)
self.BMAG = self.beta = self.symbol_replace(beta, self._symbols)

curie_temp = \
self.redlich_kister_sum(phase, param_search, tc_param_query)
Expand All @@ -737,7 +737,7 @@ def magnetic_energy(self, dbe):
(1., True),
evaluate=False
)
self.TC = self.curie_temperature = tc.subs(self._symbols)
self.TC = self.curie_temperature = self.symbol_replace(tc, self._symbols)

# Used to prevent singularity
tau_positive_tc = v.T / (curie_temp + 1e-9)
Expand Down Expand Up @@ -817,9 +817,9 @@ def xiong_magnetic_energy(self, dbe):
neel_temp = \
self.redlich_kister_sum(phase, param_search, nt_param_query)

self.TC = self.curie_temperature = curie_temp.subs(self._symbols)
self.NT = self.neel_temperature = neel_temp.subs(self._symbols)
self.BMAG = self.beta = beta.subs(self._symbols)
self.TC = self.curie_temperature = self.symbol_replace(curie_temp, self._symbols)
self.NT = self.neel_temperature = self.symbol_replace(neel_temp, self._symbols)
self.BMAG = self.beta = self.symbol_replace(beta, self._symbols)

tau_curie = v.T / curie_temp
tau_curie = tau_curie.xreplace({zoo: 1.0e10})
Expand Down Expand Up @@ -1187,12 +1187,12 @@ def _pure_element_test(constituent_array):
# set all the free site fractions to one, this should effectively delete any mixing terms spuriously added, e.g. idmix
site_frac_subs = {sf: 1 for sf in mod_pure.ast.free_symbols if isinstance(sf, v.SiteFraction)}
for mod_key, mod_val in mod_pure.models.items():
mod_pure.models[mod_key] = mod_val.subs(site_frac_subs)
mod_pure.models[mod_key] = self.symbol_replace(mod_val, site_frac_subs)
moles = self.moles(ref_state.species)
# get the output property of interest, substitute the fixed state variables (e.g. T=298.15) and add the pure element moles weighted term to the list of terms
# substitution of fixed state variables has to happen after getting the attribute in case there are any derivatives involving that state variable
for out in reference_dict.keys():
mod_out = getattr(mod_pure, out).subs(ref_state.fixed_statevars)
mod_out = self.symbol_replace(getattr(mod_pure, out), ref_state.fixed_statevars)
reference_dict[out].append(mod_out*moles)

# set the attribute on the class
Expand Down