emulsim.actors.function module

Provides a flexible actor based on a user-supplied python function.

FunctionActor

Actor that uses a python function to evolve elements.

NumbaFunctionActor

Actor that uses a compiled function to evolve the data of elements.

class FunctionActor(num_elements: int, func: Callable)[source]

Bases: ActorBase

Actor that uses a python function to evolve elements.

Parameters:
  • num_elements (int) – The number of elements this function expects

  • func (callable) – A python function that takes (elements, t, dt) as arguments and evolves the elements from time t to t + dt. elements is a tuple of the actual element classes. The function should not return anything. Better performance can be achieved when the function can be compiled by numba.

copy() FunctionActor[source]

Returns a copy the actor.

element_classes: tuple[type[_ElementBase] | tuple[type[_ElementBase], ...], ...] | EllipsisType = Ellipsis

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:

tuple

evolve(elements: tuple[_ElementBase, ...], t: float, dt: float)[source]

Evolve the state from time t to t + dt

Parameters:
  • elements (tuple of _ElementBase) – The elements that this actor affects

  • t (float) – The current time point

  • dt (float) – The time step

class NumbaFunctionActor(num_elements: int, func: Callable)[source]

Bases: ActorBase

Actor that uses a compiled function to evolve the data of elements.

Parameters:
  • num_elements (int) – The number of elements this function expects

  • func (callable) – A python function that takes (elements, t, dt) as arguments and evolves the elements from time t to t + dt. elements is a tuple of the data of elements. The function should not return anything. Better performance can be achieved when the function can be compiled by numba.

copy() NumbaFunctionActor[source]

Returns a copy the actor.

element_classes: tuple[type[_ElementBase] | tuple[type[_ElementBase], ...], ...] | EllipsisType = Ellipsis

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:

tuple

evolve(elements: tuple[_ElementBase, ...], t: float, dt: float)[source]

Evolve the state from time t to t + dt

Parameters:
  • elements (tuple of _ElementBase) – The elements that this actor affects

  • t (float) – The current time point

  • dt (float) – The time step

make_evolver_numba(elements: tuple[_ElementBase, ...]) Callable[[tuple[ndarray, ...], float, float], None][source]

Return a function evolve the state from time t to t + dt

Parameters:

elements (tuple of _ElementBase) – The elements that this actor affects

Returns:

A function with signature

(state_data: ndarray, t: float, dt: float), evolving state_data

Return type:

callable