emulsim.actors.coupling.spherical_droplet module
Provides a coupling of extended spherical droplets to a field.
This module also provides a class for managing a collection of spherical shells with different subdivisions into spherical sectors. Each sector is defined by a unit vector pointing to its center and an associated weight, which captures is local size compared to all other shell sectors. These shell sectors are used to connect the diffusive fluxes right outside droplets to the background field; see the publication for details: A. Kulkarni, E. Vidal-Henriquez, and D. Zwicker, Sci. Rep. 13, 733.
Class representing the sectors of a single shell. |
|
Class representing a collection of shells. |
|
Actor coupling spherical droplets to a field. |
- class PointsOnSphere(points)[source]
Bases:
objectClass representing points on an n-dimensional unit sphere.
- Parameters:
points (
ndarray) – The list of points on the unit sphere
- get_area_weights(balance_axes: bool = True)[source]
Return the weight of each point associated with the unit cell size.
- get_distance_matrix()[source]
Calculate the (spherical) distances between each point.
- Returns:
The distance of each point to each other
- Return type:
- classmethod make_uniform(dim: int, num_points: int | None = None)[source]
Create uniformly distributed points on a sphere.
- class ShellCollection(shells: Sequence[ShellSectors], max_radii: Sequence[float], info_dict: dict[str, Any] | None = None)[source]
Bases:
objectClass representing a collection of shells.
- Parameters:
- classmethod from_dictlist(dictlist: Sequence[dict[str, Any]], info_dict: dict[str, Any] | None = None) ShellCollection[source]
Create shell collection from a list of dictionaries.
- Parameters:
- Returns:
- classmethod generate(dim: int, sector_size_max: float = 1, radius_max: float = inf, info_dict: dict[str, Any] | None = None) ShellCollection[source]
Generate a
ShellCollectionfor a simulation.- Parameters:
Note
One-dimensional shells are special in that there can only be exactly two sectors. Consequently, max_sector_size and radius_max are not used in this case.
- Returns:
- get_shell(radius: float) ShellSectors[source]
Return shell corresponding to droplet of given radius.
- Parameters:
radius (float) – The radius of the droplet
- Returns:
The shell associated with this radius
- Return type:
- make_shell_data_getter() Callable[[float], tuple[ndarray, ndarray]][source]
Returns a function for obtaining a shell.
- Returns:
- A function that is called with a radius and returns a
tuple (numpy.ndarray, numpy.ndarray) of the shell vectors and the associated weights. The shell vectors are unit vectors pointing from the droplet center to the shell center. The weights give the fraction of the droplet surface that is covered by the respective shell, so that the sum of all weights is unity
- Return type:
callable
- class ShellSectors(vectors: ndarray, weights: ndarray | None = None)[source]
Bases:
objectClass representing the sectors of a single shell.
- Parameters:
- classmethod generate(dim: int, sector_count: int = 1) ShellSectors[source]
Generate a
ShellSectorsfor a simulation.- Parameters:
Note
One-dimensional shells are special in that there can only be exactly two sectors. Consequently, sector_count is not used in this case.
- Returns:
- get_shell(radius: float) ShellSectors[source]
Return shell corresponding to droplet of given radius.
- Parameters:
radius (float) – The radius of the droplet
- Returns:
The shell associated with this radius
- Return type:
- make_shell_data_getter() Callable[[float], tuple[ndarray, ndarray]][source]
Returns a function for obtaining a shell.
- Returns:
- A function that is called with a radius and returns a
tuple (numpy.ndarray, numpy.ndarray) of the shell vectors and the associated weights. The shell vectors are unit vectors pointing from the droplet center to the shell center. The weights give the fraction of the droplet surface that is covered by the respective shell, so that the sum of all weights is unity
- Return type:
callable
- class SphericalDropletActor(parameters: dict[str, Any] | None = None)[source]
Bases:
ActorBaseActor coupling spherical droplets to a field.
- Parameters Dictionary:
background_correction: Flag determining whether the reaction flux in the droplet is corrected to ensure material conservation in the case where the reaction dynamics are first-order rate laws (default=False)
diffusivity: Diffusivity in the shell surrounding the droplets (default=1.0)
drift_enabled: Flag determining whether droplets can move (default=True)
equilibrium_concentration: Expression for the equilibrium concentration (default=’1e-5 / radius’)
mean_reaction_inside: Mean reaction rate inside the droplet, which determines the production of droplet material per unit volume (default=’automatic’)
num_threads: The number of threads to use in the parallel update of the droplets (default=1)
reaction_outside: Reaction rate outside the droplet, which determines the production of droplet material per unit volume in the shell region (default=’0’)
shell_sector_count: The number of shell sectors when shell_sector_method == “count” (default=6)
shell_sector_method: Determines the method that is used to determine the shell sector size (default=’size’)
shell_sector_size: The typical azimuthal size of a shell sector (default=’dx’)
shell_thickness: The thickness of the shell around droplets (default=’dx’)
- Parameters:
parameters (dict) – Parameters defining the behavior of the actor. Call
show_parameters()for details.
Parameters of SphericalDropletActor:
- equilibrium_concentration
Expression for the equilibrium concentration. This expression can contain the variables position, radius, and id denoting the droplet radius, its position vector, and its identity (the index in the list of droplets), respectively. Alternatively, the value can also be an instance defining a __call__ method that returns the equilibrium concentration and a get_function method that returns a numba compiled function for calculating it. These functions must have the signature (position, radius, i). (Default value:
'1e-5 / radius')- diffusivity
Diffusivity in the shell surrounding the droplets (Default value:
1.0)- reaction_outside
Reaction rate outside the droplet, which determines the production of droplet material per unit volume in the shell region. This can be an expression that depends on position, the local concentration value c outside the droplet, or the droplets identity id (the index in the list of droplets). (Default value:
'0')- mean_reaction_inside
Mean reaction rate inside the droplet, which determines the production of droplet material per unit volume. This can be an expression that depends on the droplet radius R, its location position, or its identity id (the index in the list of droplets). Use negative values to destroy droplet material inside the droplet. The special value automatic will determine this rate by using the parameter reaction_outside evaluated at droplet_concentration specified by the droplets. (Default value:
'automatic')- background_correction
Flag determining whether the reaction flux in the droplet is corrected to ensure material conservation in the case where the reaction dynamics are first-order rate laws. Since we do not fully understand the implications of this correction at this point, we disabled it by default. (Default value:
False)- drift_enabled
Flag determining whether droplets can move (Default value:
True)- shell_thickness
The thickness of the shell around droplets. This can be either a length in non-dimensional units or an expression that can be parsed with sympy. In the latter case, the grid discretization is available as the variable dx (Default value:
'dx')- shell_sector_method
Determines the method that is used to determine the shell sector size. Possible values are size and count. (Default value:
'size')- shell_sector_size
The typical azimuthal size of a shell sector. This can be either a length in non-dimensional units or an expression that can be parsed with sympy. In the latter case, the grid discretization is available as the variable dx. This value is only used when shell_sector_method == “size” (Default value:
'dx')- shell_sector_count
The number of shell sectors when shell_sector_method == “count” (Default value:
6)- num_threads
The number of threads to use in the parallel update of the droplets. This can either be a positive integer or auto, in which case the number of threads are based on the value of numba.config.NUMBA_NUM_THREADS. (Default value:
1)
- element_classes: tuple[type[_ElementBase] | tuple[type[_ElementBase], ...], ...] | EllipsisType = (<class 'emulsim.elements.spherical_droplets.SphericalDropletsElement'>, (<class 'emulsim.elements.fields.ReservoirElement'>, <class 'emulsim.elements.fields.FieldElementBase'>))
defines the elements this actor handles and in what order they need to be supplied. An ellipsis (…) indicates that all elements and lists of elements are accepted. Setting this attribute allows internal consistency checks.
- Type:
- estimate_dt(elements: tuple[SphericalDropletsElement, FieldElementBase]) float[source]
Estimate the maximal time step for simulating this actor.
The time step is based on the time scale of diffusion in the shell. In the special case of large shells (for instance in mean-field coarsening simulations) the defining length scale is the mean droplet radius instead. This estimate is based on the growth rate of droplets, dR/dt ∝ D/R, where D is the diffusivity and R is the mean droplet radius. Therefore, ΔR/Δt ∝ D/R and ΔR/R = ε implies Δt = ε * R**2 / D, where we chose ε=0.1.
- evolve(elements: tuple[SphericalDropletsElement, FieldElementBase], t: float, dt: float) None[source]
Evolve the state from time t to t + dt
- get_equilibrium_concentrations(droplets: SphericalDropletsElement) ndarray[source]
Returns the equilibrium concentration outside each droplet.
- Parameters:
droplets (
SphericalDropletsElement) – The state of all the droplets- Returns:
- The equilibrium concentration for each
droplet with non-zero radius.
- Return type:
- get_flux_outside(radius: float, c_far: float, cEqOut: float, droplet_id: int) float[source]
Returns the integrated outwards flux at the droplet surface given some imposed concentration value at the outer shell.
Note
We assume that the flux is integrated over the entire spherical surface, so that it needs to be multiplied by the surface fraction when only a sector is considered. The fluxes are calcuated by solving the ReactionDiffusion or the Diffusion equation inside each shell sector. Detailed documentation for calculating the material fluxes (both inside and outside the droplets) is located at /emulsim/docs/methods.
- Parameters:
radius (float) – The current droplet radius
c_far (float) – The concentration at the outer side of the shell sector
cEqOut (float) – The concentration right at the inner side of the shell sector, right at the droplet surface.
droplet_id (int) – The id of the droplet, i.e., its position in the internal droplet list. This is ignored in the standard implementation given here, but is required by the interface since it is useful in other situations.
- Returns:
the integrated flux in the outward normal direction.
- Return type:
- make_evolver_numba(elements: tuple[SphericalDropletsElement, FieldElementBase]) Callable[[tuple[ndarray, ...], float, float], None][source]
Return a function evolve the state from time t to t + dt
- plot_shell_points(droplets: SphericalDropletsElement, background: FieldElementBase, state_style: dict[str, Any] | None = None, point_style: dict[str, Any] | None = None, shell_style: dict[str, Any] | None = None, *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs) PlotReference[source]
Plot all shell points around the droplets of a given state.
- Parameters:
title (str) – Title of the plot. If omitted, the title might be chosen automatically.
filename (str, optional) – If given, the plot is written to the specified file.
action (str) – Decides what to do with the final figure. If the argument is set to show,
matplotlib.pyplot.show()will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling
matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling
matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.ax (
matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.droplets (
SphericalDropletsElementorEmulsion) – Information about all the dropletsbackground (
FieldElementBaseorScalarField) – Information about the background fieldstate_style (dict, optional) – Dictionary with keyword arguments that are used in the
AgentState.plot()call. This affects the style of the background and the actual droplets.point_style (dict, optional) – Dictionary with keyword arguments that are used in the
matplotlib.pyplot.plot()call. This affects the style of the shell points.shell_style (dict, optional) – Dictionary with keyword arguments that are used in the
matplotlib.patches.Wedge()call that is responsible for drawing the shell area.
- get_spherical_polygon_area(vertices: ndarray, radius: float = 1) float[source]
Calculate the surface area of a polygon on the surface of a sphere. Based on equation provided here: http://mathworld.wolfram.com/LHuiliersTheorem.html Decompose into triangles, calculate excess for each
Adapted from https://github.com/tylerjereddy/spherical-SA-docker-demo Licensed under MIT License (see copy in root of this project)
- haversine_distance(point1: ndarray, point2: ndarray) ndarray[source]
Calculate the haversine-based distance between two points on the surface of a sphere. Should be more accurate than the arc cosine strategy. See, for example: https://en.wikipedia.org/wiki/Haversine_formula
Adapted from https://github.com/tylerjereddy/spherical-SA-docker-demo Licensed under MIT License (see copy in root of this project)