def estimate_hyperplane(dbf, comps, phases, current_statevars, comp_dicts, phase_models, parameters):
region_chemical_potentials = []
parameters = OrderedDict(sorted(parameters.items(), key=str))
for cond_dict, phase_flag in comp_dicts:
# We are now considering a particular tie vertex
for key, val in cond_dict.items():
if val is None:
cond_dict[key] = np.nan
cond_dict.update(current_statevars)
if np.any(np.isnan(list(cond_dict.values()))):
# This composition is unknown -- it doesn't contribute to hyperplane estimation
pass
else:
# Extract chemical potential hyperplane from multi-phase calculation
# Note that we consider all phases in the system, not just ones in this tie region
multi_eqdata = equilibrium(dbf, comps, phases, cond_dict, verbose=False,
model=phase_models, scheduler=dask.local.get_sync, parameters=parameters)
# Does there exist only a single phase in the result with zero internal degrees of freedom?
# We should exclude those chemical potentials from the average because they are meaningless.
num_phases = len(np.squeeze(multi_eqdata['Phase'].values != ''))
zero_dof = np.all((multi_eqdata['Y'].values == 1.) | np.isnan(multi_eqdata['Y'].values))
if (num_phases == 1) and zero_dof:
region_chemical_potentials.append(np.full_like(np.squeeze(multi_eqdata['MU'].values), np.nan))
else:
region_chemical_potentials.append(np.squeeze(multi_eqdata['MU'].values))
region_chemical_potentials = np.nanmean(region_chemical_potentials, axis=0, dtype=np.float)
return region_chemical_potentials
评论列表
文章目录