flory.free_energy.flory_huggins
Module for Flory-Huggins free energy. Flory-Huggins free energy is a combination of Flory-Huggins interaction energy and ideal gas entropy.
Classes
represents the free energy of a multicomponent mixture |
- class FloryHuggins(num_comp, chis, sizes=None)[source]
Bases:
FreeEnergyBaserepresents the free energy of a multicomponent mixture
The particular implementation of the free energy density reads
\[f(\{\phi_i\}) = \sum_{i=1}^{N_\mathrm{C}} \frac{\nu}{\nu_i}\phi_i \ln(\phi_i) + \sum_{i,j=1}^{N_\mathrm{C}} \frac{\chi_{ij}}{2} \phi_i\phi_j\]where \(\phi_i\) is the fraction of component \(i\). All components are assumed to have the same molecular volume \(\nu\) by default and the interactions are quantified by the Flory matrix \(\chi_{ij}\). The relative molecular sizes \(l_i=\nu_i/\nu\) can be changed by setting the optional parameter sizes. Note that no implicit solvent is assumed.
- Parameters:
Public Data Attributes:
The Flory-Huggins interaction matrix of components \(\chi_{ij}\).
The relative molecule volumes \(l_i = \nu_i/\nu\).
Public Methods:
from_uniform(num_comp, chi, *[, sizes, ...])Create Flory-Huggins free energy with uniform \(\chi_{ij}\) matrix.
from_random_normal(num_comp[, chi_mean, ...])Create Flory-Huggins free energy with random \(\chi_{ij}\) matrix.
Inherited from
FreeEnergyBase:interaction_compiled(**kwargs_full)Get the compiled instance of the interaction.
entropy_compiled(**kwargs_full)Get the compiled instance of the entropy.
check_volume_fractions(phis[, axis])Check whether volume fractions are valid.
free_energy_density(phis)Calculate the free energy density.
jacobian(phis[, index])Calculate the Jacobian with/without volume conservation.
hessian(phis[, index])Calculate the Hessian with/without volume conservation.
chemical_potentials(phis)Calculate original chemical potentials by unit volume.
exchange_chemical_potentials(phis, index)Calculate exchange chemical potentials.
pressure(phis, index)Calculate osmotic pressure of the solvent.
num_unstable_modes(phis[, conserved])Count the number of unstable modes with/without volume conservation.
is_stable(phis[, conserved])Determine whether the mixture is locally stable.
Private Methods:
Inherited from
FreeEnergyBase:_energy_impl(phis)Implementation of calculating free energy \(f\).
_jacobian_impl(phis)Implementation of calculating Jacobian \(\partial f/\partial \phi_i\).
_hessian_impl(phis)Implementation of calculating Hessian \(\partial^2 f/\partial \phi_i^2\).
- _energy_impl(phis)
Implementation of calculating free energy \(f\).
This method is general, thus does not need to be overwritten. The method makes use of
_energy_impl()inInteractionBaseand_energy_impl()inEntropyBase. Consider define custom interaction or entropy if a custom free energy is needed.
- _hessian_impl(phis)
Implementation of calculating Hessian \(\partial^2 f/\partial \phi_i^2\).
This method is general, thus does not need to be overwritten. The method makes use of
_hessian_impl()inInteractionBaseand_hessian_impl()inEntropyBase. Consider define custom interaction or entropy if a custom free energy is needed.
- _jacobian_impl(phis)
Implementation of calculating Jacobian \(\partial f/\partial \phi_i\).
This method is general, thus does not need to be overwritten. The method makes use of
_jacobian_impl()inInteractionBaseand_jacobian_impl()inEntropyBase. Consider define custom interaction or entropy if a custom free energy is needed.
- check_volume_fractions(phis, axis=-1)
Check whether volume fractions are valid.
If the shape of
phisor it has non-positive values, an exception will be raised. Note that this method does not forbid volume fractions to be larger than 1.- Parameters:
phis¶ (
ndarray) – The volume fractions of the phase(s) \(\phi_{p,i}\). if multiple phases are included, the index of the components must be the last dimension.axis¶ (
int, default:-1) – The axis of the index of components. By the default the last dimension ofphisis considered as the index of components.
- Returns:
The volume fractions
phis- Return type:
- chemical_potentials(phis)
Calculate original chemical potentials by unit volume.
- entropy_compiled(**kwargs_full)
Get the compiled instance of the entropy.
- Parameters:
kwargs_full¶ – The keyword arguments for method
compiled()of the entropy instance but allowing redundant arguments.- Return type:
- exchange_chemical_potentials(phis, index)
Calculate exchange chemical potentials.
Component
indexis treated as the solvent. The exchange chemical potentials is obtained by removing chemical potential of the solvent. The exchange chemical potential of the solvent is always zero and kept in the result. The nonzero values are identical to the conserved Jacobian, seejacobian()for more information.- Parameters:
- Returns:
The exchange chemical potentials of component with respect to the solvent component.
- Return type:
- free_energy_density(phis)
Calculate the free energy density.
- classmethod from_uniform(num_comp, chi, *, sizes=None, vanishing_diagonal=True)[source]
Create Flory-Huggins free energy with uniform \(\chi_{ij}\) matrix.
See
from_uniform()for parameter details.
- hessian(phis, index=None)
Calculate the Hessian with/without volume conservation.
If parameter
indexis specified, the system will be considered as conserved and the volume fraction of componentindexis treated to be not independent. Note that different fromexchange_chemical_potentials(),hessian()removed the dependent variable completely, whileexchange_chemical_potentials()keeps the exchange chemical potential of the componentindex. Pass None toindexindicates the system is not conserved.- Parameters:
- Returns:
The Hessian with/without volume conservation.
- Return type:
- interaction_compiled(**kwargs_full)
Get the compiled instance of the interaction.
- Parameters:
kwargs_full¶ – The keyword arguments for method
compiled()of the interaction instance but allowing redundant arguments.- Return type:
- is_stable(phis, conserved=True)
Determine whether the mixture is locally stable.
- Parameters:
phis¶ (
ndarray) – The volume fractions of the phase(s) \(\phi_{p,i}\). if multiple phases are included, the index of the components must be the last dimension.conserved¶ (
bool, default:True) – Whether the system conserves volume. If True, the first component is considered as the dependent on when calculating the Hessian. Seehessian()for more information.
- Returns:
The number of negative eigenvalues of the Hessian.
- Return type:
- jacobian(phis, index=None)
Calculate the Jacobian with/without volume conservation.
If parameter
indexis specified, the system will be considered as conserved and the volume fraction of componentindexis treated to be not independent. Note that different fromexchange_chemical_potentials(),jacobian()removed the dependent variable completely, whileexchange_chemical_potentials()keeps the exchange chemical potential of the componentindex. Pass None toindexindicates the system is not conserved.- Parameters:
- Returns:
Jacobian of each phase with/without volume conservation.
- Return type:
- num_unstable_modes(phis, conserved=True)
Count the number of unstable modes with/without volume conservation.
- Parameters:
phis¶ (
ndarray) – The volume fractions of the phase(s) \(\phi_{p,i}\). if multiple phases are included, the index of the components must be the last dimension.conserved¶ (
bool, default:True) – Whether the system conserves volume. If True, the first component is considered as the dependent on when calculating the Hessian. Seehessian()for more information.
- Returns:
The number of negative eigenvalues of the Hessian.
- Return type:
- pressure(phis, index)
Calculate osmotic pressure of the solvent.
Component
indexis treated as the solvent. The osmotic pressure of the solvent is proportional to the original chemical potential of the solvent.- Parameters:
- Returns:
The osmotic pressure of the solvent component index.
- Return type:
- classmethod from_random_normal(num_comp, chi_mean=0, chi_std=1, *, sizes=None, vanishing_diagonal=True, rng=None)[source]
Create Flory-Huggins free energy with random \(\chi_{ij}\) matrix.
See
from_random_normal()for parameter details.