flory.ensemble.canonical

Module for canonical ensemble of mixture.

Classes

CanonicalEnsemble

Class for an canonical ensemble that the average volume fractions are conserved.

CanonicalEnsembleCompiled

Compiled class for canonical ensemble.

class CanonicalEnsemble(num_comp, phi_means=None)[source]

Bases: EnsembleBase

Class for an canonical ensemble that the average volume fractions are conserved.

The particular form of the conservation law reads

\[\bar{\phi}_i = \frac{\sum_m \phi_i^{(m)} J_m }{\sum_m J_m}.\]
Parameters:
  • num_comp (int) – Number of components \(N_\mathrm{C}\).

  • phi_means (ndarray | None, default: None) – The average volume fractions of the components \(\bar{\phi}_i\). If omitted, an equimolar system is initialized.

Public Data Attributes:

phi_means

The average volume fractions of the components \(\bar{\phi}_i\).

Inherited from EnsembleBase:

num_comp

Component count

Public Methods:

Inherited from EnsembleBase:

compiled(**kwargs_full)

Make a compiled ensemble instance for CoexistingPhasesFinder.

Private Methods:

_compiled_impl()

Implementation of creating a compiled ensemble instance.

Inherited from EnsembleBase:

_compiled_impl(**kwargs)

Implementation of creating a compiled ensemble instance (Interface).


compiled(**kwargs_full)

Make a compiled ensemble instance for CoexistingPhasesFinder.

This function requires the implementation of _compiled_impl(). The ensemble instance is a compiled class, which must implement a list of methods or properties. See EnsembleBaseCompiled for the list and the detailed information. Also see CanonicalEnsembleCompiled for an example.

Parameters:

kwargs_full – The keyword arguments for _compiled_impl() but allowing redundant arguments.

Returns:

The compiled ensemble instance.

Return type:

EnsembleBaseCompiled

property num_comp: int

Component count

property phi_means: ndarray

The average volume fractions of the components \(\bar{\phi}_i\).

_compiled_impl()[source]

Implementation of creating a compiled ensemble instance.

This method overwrites the interface _compiled_impl() in EnsembleBase.

Returns:

Instance of CanonicalEnsembleCompiled.

Return type:

CanonicalEnsembleCompiled

class CanonicalEnsembleCompiled(phi_means)[source]

Bases: EnsembleBaseCompiled

Compiled class for canonical ensemble.

In canonical ensemble, the average volume fractions of the components are fixed. Therefore, the volume fractions distribution of the components in compartments can be obtained by normalizing the Boltzmann factors according to the average volume fractions,

\[\begin{split}\phi_i^{(m)} &= \frac{\bar{\phi}_i}{Q_i} p_i^{(m)} \\ Q_i &= \sum_m p_i^{(m)} J_m .\end{split}\]

Since (translational) entropy is always defined for each component, this class is only aware of the component-based description of the system.

Parameters:

phi_means (ndarray) – 1D array with the size of \(N_\mathrm{C}\), containing the mean volume fractions of the components, \(\bar{\phi}_i\). The number of components \(N_\mathrm{C}\) is inferred from this array.

Public Data Attributes:

num_comp

Number of components \(N_\mathrm{C}\).

Inherited from EnsembleBaseCompiled:

num_comp

Number of components \(N_\mathrm{C}\).

Public Methods:

normalize(phis_comp, Qs, masks)

Normalize the volume fractions of components.

Inherited from EnsembleBaseCompiled:

normalize(phis_comp, Qs, masks)

Normalize the volume fractions of components.


property num_comp

Number of components \(N_\mathrm{C}\).

normalize(phis_comp, Qs, masks)[source]

Normalize the volume fractions of components.

This method normalizes the Boltzmann factor stored in phis_comp into volume fractions of all components \(\phi_i^{(m)}\) and save it back to phis_comp, making use of the single molecule partition function in Qs. The exact form of such normalization depends on the emsemble. This method must report the incompressibility \(\sum_i \phi_i^{(m)} -1\). Note that this function is only aware of the number of components \(N_\mathrm{C}\). Mapping from/to features are handled by entropy.

Parameters:
  • phis_comp (ndarray) – Mutable. The 2D array with the size of \(N_\mathrm{C} \times N_\mathrm{M}\), containing Boltzmann factors of the components, which are proportional to resulting volume fractions.

  • Qs (ndarray) – Constant. The 1D array with the size of \(N_\mathrm{C}\), containing single molecule partition functions of the components.

  • masks (ndarray) – Constant. The 1D array with the size of \(N_\mathrm{M}\), containing the masks to mark whether the compartment is living or not.

Returns:

The incompressibility.

Return type:

ndarray