Functions Library

Define functions that can update the simulation parameters.

Base Operations

Define simple operations to initialize parameters in the configuration.

class Sum(add: Iterable[Any] = <factory>, subtract: Iterable[Any] | None = None)

Sum the elements in add and subtract the elements in subtract.

add: Iterable[Any]

the values to sum

subtract: Iterable[Any] | None = None

the values to subtract

property operation_value: Any

Value used with base operators.

Returns:

the current evaluation of the function

Return type:

Any

eval() Any

Sum the elements in add and subtract the elements in subtract.

Returns:

the sum result

Return type:

Any

class Product(factors: Iterable[Any] = <factory>, inverses: Iterable[Any] | None = None)

Multiply all values provided in factors list and divide the result with the multiplication of the values in the inverses list.

..note:: It uses the numpy multiply function

factors: Iterable[Any]

The values to multiply

inverses: Iterable[Any] | None = None

The values to inverse then multiply

property operation_value: Any

Value used with base operators.

Returns:

the current evaluation of the function

Return type:

Any

eval() Any

Child Functions have to overwrite this method to compute the function result.

Watchers

Watcher are useful functions to use to set Output Functions in the configuration.

class WatchQuantity(quantity: Quantity[Any])

Return the current value of the watch quantity.

quantity: Quantity[Any]

The quantities to watch

property operation_value: Any

Value used with base operators.

Returns:

the current evaluation of the function

Return type:

Any

eval() Any

Just return the watched quantity current value

Returns:

the watched quantity current value

Return type:

np.float64 | np.ndarray

class SumBlocksQuantity(quantity_id: str, elements: Iterable[Block] = <factory>)

Sum the current values of quantities with the given name for each the blocks.

quantity_id: str

block local id of the quantity to sum

elements: Iterable[Block]

the blocks holding the quantity to sum

property operation_value: Any

Value used with base operators.

Returns:

the current evaluation of the function

Return type:

Any

eval() Any

Sum the quantities

Returns:

the sum of the quantities

Return type:

Any

Piecewise

Declare functions to define piecewise functions in the configuration

class PiecewiseLinear(points_abscissas: NDArray[np.float64], points_ordinates: NDArray[np.float64], left_value: np.float64 | None = None, right_value: np.float64 | None = None)

Defines an evaluation method to get the value of a piecewise function for the given time.

points_abscissas: NDArray[np.float64]

The function abscissas

points_ordinates: NDArray[np.float64]

The function ordinates

left_value: np.float64 | None = None

Function value when the evaluation point is before the provided abscissas. If it is not provided, it is the first ordinate value.

right_value: np.float64 | None = None

Function value when the evaluation point is after the provided abscissas. If it is not provided, it is the last ordinate value.

eval(time: float64) Any

Evaluate piecewise function for the given time.

Parameters:

time (np.float64) – the evaluated time

Returns:

the activation point_value

Return type:

np.float64

class PiecewiseLinearPeriodic(period: np.float64, points_abscissas: NDArray[np.float64], points_ordinates: NDArray[np.float64])

Defines an evaluation method to get the value of a piecewise periodic function for the given time.

period: np.float64

The function period

points_abscissas: NDArray[np.float64]

The function abscissas

points_ordinates: NDArray[np.float64]

The function ordinates

eval(time: float64) Any

Evaluate piecewise periodic function for the given time.

Parameters:

time (np.float64) – the evaluated time

Returns:

the activation point_value

Return type:

np.float64

class RescaleTwoPhasesFunction(rescaled_period: float, reference_function: list[tuple[float, float]], alpha: float, phases: list[int])

Rescale each part of the input function (a linear interpollation) depending on the proportion of variation of phase 0 when the period differs from the reference function.

reference_function: list[tuple[float, float]]

The reference function. Coordinates format is (abscissa, ordinate)

phases: list[int]

For each intervals point of the reference, determine if it belong to phase 0 or 1.

alpha: float

Proportion of the variation of phase 0

rescaled_period: float

The actual function period

eval(time: float) Any

Evaluate the function.

Parameters:

time (float) – the evaluated time

Returns:

the function value

Return type:

np.float64

Trigonometric

Declare configuration function to set parameter with trigonometric function.

class SinusOffset(offset_value: float, amplitude: float, frequency: float, phase_shift: float)

Defines an evaluation method to get the value of a offset sinus function.

offset_value: float

Offset value of the function

amplitude: float

Peak amplitude of the function

frequency: float

Frequency of the function

phase_shift: float

Phase shift of the function

eval(time: float) Any

Evaluate function value at the given time.

Parameters:

time (float) – evaluation time

Returns:

the function value

Return type:

np.float64

First Order

class FirstOrder(times_start: NDArray[np.float64], amplitudes: NDArray[np.float64], time_constants: NDArray[np.float64], baseline_value: np.float64)

Defines an evaluation method to get the value of a sum of first order functions with heavyside for the given time.

times_start: NDArray[np.float64]

Start times of first order components

amplitudes: NDArray[np.float64]

Amplitudes of first order components

time_constants: NDArray[np.float64]

Time constants of first order components

baseline_value: np.float64

Baseline value of the function

eval(time: float64) Any

Evaluate function value at the given time.

Parameters:

time (np.float64) – evaluation time

Returns:

the function value

Return type:

np.float64