flory.free_energy.base
Module for a general free energy of mixture.
Classes
Base class for a general free energy of mixture. |
- class FreeEnergyBase(interaction, entropy)[source]
Bases:
objectBase class for a general free energy of mixture.
A free energy is constructed by an interactions energy and a entropic energy. Once the energy, Jacobian and Hessian of both interactions energy and entropic energy are implemented, class
FreeEnergyBaseprovides methods such as the chemical potential of the components.- Parameters:
interaction¶ (
InteractionBase) – The interaction energy instance.entropy¶ (
EntropyBase) – The entropic energy instance.
Public Methods:
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:
_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\).
- interaction_compiled(**kwargs_full)[source]
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:
- entropy_compiled(**kwargs_full)[source]
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:
- _energy_impl(phis)[source]
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.
- _jacobian_impl(phis)[source]
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.
- _hessian_impl(phis)[source]
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.
- check_volume_fractions(phis, axis=-1)[source]
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:
- jacobian(phis, index=None)[source]
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:
- hessian(phis, index=None)[source]
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:
- exchange_chemical_potentials(phis, index)[source]
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:
- pressure(phis, index)[source]
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:
- num_unstable_modes(phis, conserved=True)[source]
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:
- is_stable(phis, conserved=True)[source]
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: