flory.entropy.ideal_gas_polydispersed
Module for polydispersed ideal gas entropic energy of mixture.
Classes
Class for entropic energy of mixture of polydispersed ideal gas. |
|
Compiled class for the entropic energy of mixture of polydispersed ideal gas. |
- class IdealGasPolydispersedEntropy(num_feat, sizes=None, num_comp_per_feat=1)[source]
Bases:
IdealGasEntropyBaseClass for entropic energy of mixture of polydispersed ideal gas.
The particular form of dimensionless entropic energy reads
\[f_\mathrm{entropy}(\{\phi_i\}) = \sum_{i=1}^{N_\mathrm{C}} \frac{\nu}{\nu_i}\phi_i \ln(\phi_i),\]where \(\phi_i\) is the fraction of component \(i\). All components are assumed to have the same molecular volume \(\nu\) by default. 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:
sizes¶ (
ndarray|None, default:None) – The relative molecule volumes \(l_i = \nu_i/\nu\) with respect to the volume of a reference molecule \(\nu\). It is treated as all-one vector by default.num_comp_per_feat¶ (
ndarray|int, default:1) – The number of components in each feature. An integer indicates that this value is the same for all features.
Public Data Attributes:
The relative molecule volumes \(l_i = \nu_i/\nu\).
Public Methods:
Inherited from
EntropyBase:compiled(**kwargs_full)Make a compiled entropy instance for
CoexistingPhasesFinder.Private Methods:
Implementation of creating a compiled entropy instance.
Inherited from
IdealGasEntropyBase:_energy_impl(phis)Implementation of calculating entropic energy \(f_\mathrm{entropy}\).
_jacobian_impl(phis)Implementation of calculating Jacobian \(\partial f_\mathrm{entropy}/\partial \phi_i\).
_hessian_impl(phis)Implementation of calculating Hessian \(\partial^2 f_\mathrm{entropy}/\partial \phi_i^2\).
_jacobian_fractions_impl(phis)Implementation of calculating \(\phi_i \partial f_\mathrm{entropy}/\partial \phi_i\).
Inherited from
EntropyBase:_compiled_impl(**kwargs)Implementation of creating a compiled entropy instance (Interface).
_energy_impl(phis)Implementation of calculating entropic energy \(f_\mathrm{entropy}\) (Interface).
_jacobian_impl(phis)Implementation of calculating Jacobian \(\partial f_\mathrm{entropy}/\partial \phi_i\) (Interface).
_hessian_impl(phis)Implementation of calculating Hessian \(\partial^2 f_\mathrm{entropy}/\partial \phi_i^2\) (Interface).
- _compiled_impl()[source]
Implementation of creating a compiled entropy instance.
This method overwrites the interface
_compiled_impl()inEntropyBase.- Returns:
Instance of
IdealGasPolydispersedEntropyCompiled.- Return type:
- _energy_impl(phis)
Implementation of calculating entropic energy \(f_\mathrm{entropy}\).
This method overwrites the interface
_energy_impl()inEntropyBase.
- _hessian_impl(phis)
Implementation of calculating Hessian \(\partial^2 f_\mathrm{entropy}/\partial \phi_i^2\).
This method overwrites the interface
_hessian_impl()inEntropyBase.
- _jacobian_fractions_impl(phis)
Implementation of calculating \(\phi_i \partial f_\mathrm{entropy}/\partial \phi_i\).
This method is not included in the interface, since it is only needed when \(\phi_i \partial f_\mathrm{entropy}/\partial \phi_i\) exist but \(\partial f_\mathrm{entropy}/\partial \phi_i\) diverges.
- _jacobian_impl(phis)
Implementation of calculating Jacobian \(\partial f_\mathrm{entropy}/\partial \phi_i\).
This method overwrites the interface
_jacobian_impl()inEntropyBase.
- compiled(**kwargs_full)
Make a compiled entropy instance for
CoexistingPhasesFinder.This function requires the implementation of
_compiled_impl(). The entropy instance is a compiled class, which must implement a list of methods or properties. SeeEntropyBaseCompiledfor the list and the detailed information.Note that the compiled entropy instance acts as the bridge between the component-based description and the feature-based description of the system’s states. In contrast, compiled classes in
ensembleshould be only aware of component-based description, compiled classes ininteractionandconstraintshould be only aware of feature-based description.See
IdealGasEntropyCompiledfor an example.- Parameters:
kwargs_full¶ – The keyword arguments for
_compiled_impl()but allowing redundant arguments.- Returns:
The compiled entropy instance.
- Return type:
- class IdealGasPolydispersedEntropyCompiled(sizes, num_comp_per_feat)[source]
Bases:
EntropyBaseCompiledCompiled class for the entropic energy of mixture of polydispersed ideal gas.
For ideal gas, the Boltzmann factor \(p_i^{(m)}\) is determined by the relative volumes of the molecules \(l_i = \nu_i/\nu\) and the mean fields it feel, \(w_r^{(m)}\),
\[p_i^{(m)} = \exp(-l_i w_r^{(m)}).\]Note that this class assumes that there’s degeneracy of the components’ features, in other words several components in a group can correspond to one feature, such that all components in this group share the same field. Therefore the number of features \(N_\mathrm{S}\) is larger than the number of components \(N_\mathrm{C}\).
- Parameters:
sizes¶ (
ndarray) – 1D array with the size of \(N_\mathrm{C}\), containing the relative molecule volumes \(l_i = \nu_i/\nu\). The number of components \(N_\mathrm{C}\) is inferred from this array.num_comp_per_feat¶ (
ndarray) – 1D array with the size of \(N_\mathrm{S}\), containing the number component of each feature. The number of features \(N_\mathrm{S}\) is inferred from this array. The sum of this array must be the number of components \(N_\mathrm{C}\).
Public Data Attributes:
Number of components \(N_\mathrm{C}\).
Number of features \(N_\mathrm{S}\).
Inherited from
EntropyBaseCompiled:Number of components \(N_\mathrm{C}\).
Number of features \(N_\mathrm{S}\).
Public Methods:
partition(phis_comp, omegas, Js)Calculate the partition function and Boltzmann factors.
comp_to_feat(phis_feat, phis_comp)Convert the fractions of components into features.
volume_derivative(phis_comp)Calculate the volume derivatives of entropic energy.
Inherited from
EntropyBaseCompiled:partition(phis_comp, omegas, Js)Calculate the partition function and Boltzmann factors.
comp_to_feat(phis_feat, phis_comp)Convert the fractions of components into features.
volume_derivative(phis_comp)Calculate the volume derivatives of entropic energy.
- partition(phis_comp, omegas, Js)[source]
Calculate the partition function and Boltzmann factors.
This method calculates the Boltzmann factors \(p_i^{(m)}\) of the components under the mean fields
omegasand stores them inphis_compas the volume fractions of components before normalization. This method must return the single molecule partition functions of the components \(Q_i\), which is the sum of the Boltzmann factors weighted by the volumes of compartments \(J_m\) inJs. Note thatomegascontains the mean fields for the features \(w_r^{(m)}\) instead of components. For example when we have polydispersity of the molecule sizes, all the polydispersed components of the same kind share the same external fields, but with different volume fractions. In such cases the number of features \(N_\mathrm{S}\) can be much smaller than number of components \(N_\mathrm{C}\). This method acts as the mapping from feature-based description of the system to the component-based description of the system. Note that this method should modifyphis_compdirectly.- Parameters:
phis_comp¶ (
ndarray) – Output. The 2D array with the size of \(N_\mathrm{C} \times N_\mathrm{M}\), containing Boltzmann factors \(p_i^{(m)}\), namely the volume fractions of components before normalization.omegas¶ (
ndarray) – Constant. The 2D array with the size of \(N_\mathrm{S} \times N_\mathrm{M}\), containing the mean field felt by the features \(\phi_r^{(m)}\).Js¶ (
ndarray) – Constant. The 1D array with the size of \(N_\mathrm{M}\), containing the relative volumes of compartments \(J_m\).
- Returns:
The single molecule partition functions of components \(Q_i\).
- Return type:
- comp_to_feat(phis_feat, phis_comp)[source]
Convert the fractions of components into features.
This method converts the volume fractions of components \(\phi_i^{(m)}\) in
phis_compto the volume fractions of features \(\phi_r^{(m)}\) inphis_feat. Note that this method should modifyphis_featdirectly.- Parameters:
phis_feat¶ (
ndarray) – Output. The 2D array with the size of \(N_\mathrm{S} \times N_\mathrm{M}\), containing the volume fractions of features \(\phi_r^{(m)}\).phis_comp¶ (
ndarray) – Constant. The 2D array with the size of \(N_\mathrm{C} \times N_\mathrm{M}\), containing the volume fractions of components \(\phi_i^{(m)}\).
- Return type:
- volume_derivative(phis_comp)[source]
Calculate the volume derivatives of entropic energy.
This method calculates the partial derivative of partition function part of the free energy with respect to the volumes of the compartments \(\partial f_\mathrm{entropy}/\partial J_m\).
In most of the cases, this is equivalent to the negative sum of the volume fractions of the components \(\phi_i^{(m)}\) divided by the relative volumes of the molecules \(l_i\). Note that this module is separated from the iteration algorithm to remove from it any explicit dependence of the molecule parameters such as \(l_i\).
- Returns:
The volume derivatives.
- Return type: