flory.interaction.flory_huggins
Module for Flory-Huggins interaction energy of mixture.
Classes
Class for Flory-Huggins interaction energy of mixture. |
|
Compiled class for Flory-Huggins interaction energy. |
- class FloryHugginsInteraction(num_comp, chis)[source]
Bases:
InteractionBaseClass for Flory-Huggins interaction energy of mixture.
The particular form of interaction energy density reads
\[f_\mathrm{interaction}(\{\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\).
- Parameters:
Public Data Attributes:
The Flory-Huggins interaction matrix of components \(\chi_{ij}\).
Entries of the upper triangle of the \(\chi_{ij}\)
Public Methods:
from_uniform(num_comp, chi, *[, ...])Create Flory-Huggins interaction with uniform \(\chi_{ij}\) matrix.
from_random_normal(num_comp[, chi_mean, ...])Create Flory-Huggins interaction with random \(\chi_{ij}\) matrix.
set_uniform_chis(chi, *[, vanishing_diagonal])Set Flory-Huggins interaction with uniform \(\chi_{ij}\) matrix.
set_random_chis([chi_mean, chi_std, ...])Set Flory-Huggins interaction with random \(\chi_{ij}\) matrix.
Inherited from
InteractionBase:compiled(**kwargs_full)Make a compiled interaction instance for
CoexistingPhasesFinder.Private Methods:
_compiled_impl(*[, additional_chis_shift])Implementation of creating a compiled interaction instance.
_energy_impl(phis)Implementation of calculating interaction energy.
_jacobian_impl(phis)Implementation of calculating Jacobian \(\partial f_\mathrm{interaction}/\partial \phi_i\).
_hessian_impl(phis)Implementation of calculating Hessian \(\partial^2 f_\mathrm{interaction}/\partial \phi_i^2\).
Inherited from
InteractionBase:_compiled_impl(**kwargs)Implementation of creating a compiled interaction instance (Interface).
_energy_impl(phis)Implementation of calculating interaction energy \(f_\mathrm{interaction}\) (Interface).
_jacobian_impl(phis)Implementation of calculating Jacobian \(\partial f_\mathrm{interaction}/\partial \phi_i\) (Interface).
_hessian_impl(phis)Implementation of calculating Hessian \(\partial^2 f_\mathrm{interaction}/\partial \phi_i^2\) (Interface).
- classmethod from_uniform(num_comp, chi, *, vanishing_diagonal=True)[source]
Create Flory-Huggins interaction with uniform \(\chi_{ij}\) matrix.
- classmethod from_random_normal(num_comp, chi_mean=0, chi_std=1, *, vanishing_diagonal=True, rng=None)[source]
Create Flory-Huggins interaction with random \(\chi_{ij}\) matrix.
- Parameters:
chi_mean¶ (
float, default:0) – Mean interaction \(\bar{\chi}\).chi_std¶ (
float, default:1) – Standard deviation of the interactions \(\sigma_{\chi}\).vanishing_diagonal¶ (
bool, default:True) – Whether the diagonal elements of the \(\chi_{ij}\) matrix are set to be zero.rng¶ (
Generator|None, default:None) – The random number generator.
- set_uniform_chis(chi, *, vanishing_diagonal=True)[source]
Set Flory-Huggins interaction with uniform \(\chi_{ij}\) matrix.
- set_random_chis(chi_mean=0, chi_std=1, *, vanishing_diagonal=True, rng=None)[source]
Set Flory-Huggins interaction with random \(\chi_{ij}\) matrix.
- Parameters:
chi_mean¶ (
float, default:0) – Mean interaction \(\bar{\chi}\).chi_std¶ (
float, default:1) – Standard deviation of the interactions \(\sigma_{\chi}\).vanishing_diagonal¶ (
bool, default:True) – Whether the diagonal elements of the \(\chi_{ij}\) matrix are set to be zero.rng¶ (default:
None) – The random number generator.
- _compiled_impl(*, additional_chis_shift=1.0)[source]
Implementation of creating a compiled interaction instance.
This method overwrites the interface
_compiled_impl()inInteractionBase.- Parameters:
additional_chis_shift¶ (
float, default:1.0) – Shift of the entire chis matrix to improve the convergence by evolving towards incompressible system faster. This value should be larger than 0. This value only affects the numerics, not the actual physical system. Note that with very large value, the convergence will be slowed down, since the algorithm no longer have enough ability to temporarily relax the incompressibility.- Returns:
Instance of
FloryHugginsInteractionCompiled.- Return type:
- _energy_impl(phis)[source]
Implementation of calculating interaction energy.
This method overwrites the interface
_energy_impl()inInteractionBase.
- _jacobian_impl(phis)[source]
Implementation of calculating Jacobian \(\partial f_\mathrm{interaction}/\partial \phi_i\).
This method overwrites the interface
_jacobian_impl()inInteractionBase.
- _hessian_impl(phis)[source]
Implementation of calculating Hessian \(\partial^2 f_\mathrm{interaction}/\partial \phi_i^2\).
This method overwrites the interface
_hessian_impl()inInteractionBase.
- compiled(**kwargs_full)
Make a compiled interaction instance for
CoexistingPhasesFinder.This function requires the implementation of
_compiled_impl(). The interaction instance is a compiled class, which must implement a list of methods or properties. SeeInteractionBaseCompiledfor the list and the detailed information. See alsoFloryHugginsInteractionCompiledfor an example. Note that different from the classInteractionBaseitself, the returned compiled class use the feature-based description, and can consider the degeneracy of components.- Parameters:
kwargs_full¶ – The keyword arguments for
_compiled_impl()but allowing redundant arguments.- Returns:
The compiler interaction instance.
- Return type:
- class FloryHugginsInteractionCompiled(chis, chis_shift)[source]
Bases:
InteractionBaseCompiledCompiled class for Flory-Huggins interaction energy.
Flory-Huggins interaction is the second-ordered interaction, whose energy reads,
\[f(\{\phi_r\}) = \sum_{r,s=1}^{N_\mathrm{S}} \frac{\chi_{rs}}{2} \phi_r\phi_s .\]Note that here we use describe the system by features.
- Parameters:
chis¶ (
ndarray) – 2D array with the size of \(N_\mathrm{S} \times N_\mathrm{S}\), containing the Flory-Huggins interaction matrix \(\chi_{rs}\) for features. The number of features \(N_\mathrm{S}\) is inferred from this matrix.chis_shift¶ (
float) – The shift of entire Flory-Huggins matrix for theincomp_coef().
Public Data Attributes:
Number of features \(N_\mathrm{S}\).
Inherited from
InteractionBaseCompiled:Number of features \(N_\mathrm{S}\).
Public Methods:
volume_derivative(potential, phis_feat)Calculate the volume derivatives of interaction energy.
potential(phis_feat)Calculate part of \(w_r^{(m)}\) from interaction.
incomp_coef(phis_feat)Calculate the coefficient for incompressibility.
Inherited from
InteractionBaseCompiled:volume_derivative(potential, phis_feat)Calculate the volume derivatives of interaction energy.
potential(phis_feat)Calculate part of \(w_r^{(m)}\) from interaction.
incomp_coef(phis_feat)Calculate the coefficient for incompressibility.
- volume_derivative(potential, phis_feat)[source]
Calculate the volume derivatives of interaction energy.
This method calculates the partial derivative of interaction part of the free energy with respect to the volumes of the compartments \(\partial f_\mathrm{interaction}/\partial J_m\). In most of the cases, this is just the interaction energy density in all compartments.
- Parameters:
potential¶ (
ndarray) – Constant. 2D array with the size of \(N_\mathrm{S} \times N_\mathrm{M}\), containing the part of the field \(w_r^{(m)}\) contributed by the interaction. Usually this is the returned value ofpotential(). This parameter is passed in since usually the calculation of interaction energy density can be accelerated by directly using the potential.phis_feat¶ (
ndarray) – Constant. The 2D array with the size of \(N_\mathrm{S} \times N_\mathrm{M}\), containing the volume fractions of features \(\phi_r^{(m)}\).
- Returns:
The volume derivatives.
- Return type:
- potential(phis_feat)[source]
Calculate part of \(w_r^{(m)}\) from interaction.
This method calculates the part of mean field \(w_r^{(m)}\) contributed by the interaction. Usually this is just the Jacobian of the interaction energy with respect to the volume fractions of features in each compartment. This method should return the result directly.
- incomp_coef(phis_feat)[source]
Calculate the coefficient for incompressibility.
This method calculates the coefficient for incompressibility during iteration. This coefficient is derived heuristically. The most common way is to partially make use of the incompressibility in the expression of
potential(), and then determine the changes ofpotential()after applying incompressibility. The coefficient can be compartment-dependent. This method should return the result directly.