flory.interaction.base
Module for a general interaction energy of mixture.
Classes
Base class for a general interaction energy of mixture. |
|
Abstract base class for a general compiled interaction. |
- class InteractionBase(num_comp)[source]
Bases:
objectBase class for a general interaction energy of mixture.
The class
InteractionBaseis designed to use number of components \(N_\mathrm{C}\) since this is the more physically comprehensive way to describe a mixture, even though there might be redundancies in such definition. For example, in a incompressible canonical mixture of polydispersed components, the system can be uniquely described by volume fractions of features, where one feature can contain multiple components with different molecule sizes. In such cases the interaction be expressed by the interaction between features, giving significant simplification of the numerics. In other words, there exists degeneracy of components. However, the classInteractionBasedoes not include this directly. Instead, such system-specific things are considered by the compiled interaction classes, which should only be aware of the feature-based description. seeFloryHugginsInteractionCompiledfor an example.Public Methods:
compiled(**kwargs_full)Make a compiled interaction instance for
CoexistingPhasesFinder.Private Methods:
_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).
- _compiled_impl(**kwargs)[source]
Implementation of creating a compiled interaction instance (Interface).
This interface is meant to be overridden in derived classes. See
compiled()for more information on the compiled interaction instance.- Return type:
- _energy_impl(phis)[source]
Implementation of calculating interaction energy \(f_\mathrm{interaction}\) (Interface).
This interface is meant to be overridden in derived classes. Multiple compositions should be allowed. This method is not necessary for the core algorithm.
- _jacobian_impl(phis)[source]
Implementation of calculating Jacobian \(\partial f_\mathrm{interaction}/\partial \phi_i\) (Interface).
This interface is meant to be overridden in derived classes. Multiple compositions should be allowed. This method is not necessary for the core algorithm.
- _hessian_impl(phis)[source]
Implementation of calculating Hessian \(\partial^2 f_\mathrm{interaction}/\partial \phi_i^2\) (Interface).
This interface is meant to be overridden in derived classes. Multiple compositions should be allowed. This method is not necessary for the core algorithm.
- compiled(**kwargs_full)[source]
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 InteractionBaseCompiled[source]
Bases:
objectAbstract base class for a general compiled interaction.
This abstract class defines the necessary members of a compiled constraint instance. This abstract class does not inherit from
abc.ABC, since thenumba.experimental.jitclass()currently does not support some members ofabc.ABC. A compiled class derived fromInteractionBaseCompiledis in general stateless. In other words, the compiled interaction instance never managers its own data. Note that the methods may change the input arrays inplace to avoid creating them each time.Public Data Attributes:
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.
- 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.