pypdevsbbl.generic.math module¶
Set of PythonPDEVS building blocks for doing math.
The core of this module is the Equation block,
which allows a user to execute a function on a set of
inputs.
Additionally, some few blocks with a variable set of inputs (like the sum and the product) will provide the remaining functionality.
-
class
pypdevsbbl.generic.math._SP(name, n)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSSuperclass for the
AdderandMultiplierblocks.Warning
This class should not be used as a block by itself.
Parameters: - name (str) – The name of the block.
- n (int) – The amount of input ports the block must have.
These ports are accessible from the
inputslist, using a 0-based index.
State: - result (numeric) – The computed result of the block.
- input-n (numeric) – The value of the n th input port.
Input Ports: inputs (list) – The list of all the input ports.
Output Ports: result (numeric) – The result of the computation.
-
class
pypdevsbbl.generic.math.Adder(name, n)[source]¶ Bases:
pypdevsbbl.generic.math._SPComputes the sum of a set of inputs.
Parameters: - name (str) – The name of the block.
- n (int) – The amount of input ports the block must have.
These ports are accessible from the
inputslist, using a 0-based index.
State: - result (numeric) – The computed result of the block.
- input-n (numeric) – The value of the n th input port.
Input Ports: inputs (list) – The list of all the input ports.
Output Ports: result (numeric) – The result of the computation.
-
class
pypdevsbbl.generic.math.Multiplier(name, n)[source]¶ Bases:
pypdevsbbl.generic.math._SPComputes the product of a set of inputs.
Parameters: - name (str) – The name of the block.
- n (int) – The amount of input ports the block must have.
These ports are accessible from the
inputslist, using a 0-based index.
State: - result (numeric) – The computed result of the block.
- input-n (numeric) – The value of the n th input port.
Input Ports: inputs (list) – The list of all the input ports.
Output Ports: result (numeric) – The result of the computation.
-
class
pypdevsbbl.generic.math.Equation(name, function)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSExecute an equation on a set of inputs.
The input ports of this block are determined by the arguments of the passed
function. Whenever a change happens on these ports and both have values, their result is outputted on the result port.Warning
- The
functioncannot have aresultparameter to prevent ambiguity with the output port. - The
functionmust not change the values of the inputs. - This block is optimized for numerical equations, yet it is (because of Python) perfectly possible to use some other attributes.
See also
pypdevsbbl.extra.equationsfor a set of predefined equations which can be used as a function without too much thought.Parameters: - name (str) – The name of the block.
- function (def) – The function that needs to be executed. Note that
defaults can be used, but the
*argsand**kwargsinformation will be ignored.
Input Ports: Depends on the
functionthat was passed. Say thefunctionhas two arguments:aandb, the input ports are also a and b.Output Ports: result (any) – The output of the provided equation.
- The
-
class
pypdevsbbl.generic.math._DI(name, ic=0)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSSuperclass of the
DifferentiatorandIntegratorblocks.Warning
This class should not be used as a block by itself.
Parameters: - name (str) – The name of the block.
- ic (numeric) – The initial condition of the block. Defaults to 0.
State: - prev (numeric) – The previous value. Defaults to the initial condition.
- v (numeric) – The current value.
Input Ports: input (numeric) – The new value.
Output Ports: result (numeric) – The differential.
-
class
pypdevsbbl.generic.math.Differentiator(name, ic=0)[source]¶ Bases:
pypdevsbbl.generic.math._DIDifferentiates the input over time.
This block will make use of the backwards difference:
\(\dfrac{d}{dt}f(t) = \lim_{\Delta t\to 0}\dfrac{f(t) - f(t - \Delta t)}{\Delta t} = \dfrac{x_i - x_{i-1}}{\Delta t}\)
Parameters: - name (str) – The name of the block.
- ic (numeric) – The initial condition of the block. Defaults to 0.
State: - prev (numeric) – The previous value of the differential. Defaults to the initial condition.
- v (numeric) – The current differential.
Input Ports: input (numeric) – The new value.
Output Ports: result (numeric) – The differential.
-
class
pypdevsbbl.generic.math.Integrator(name, ic=0, method=<function Integrator.INTEGRAL_TRAPEZOID>)[source]¶ Bases:
pypdevsbbl.generic.math._DIIntegrates the input over time.
\(v(t) = {\displaystyle \int} f(\tau)\ d\tau = ic + {\displaystyle \int_0^t} f(\tau)\ d\tau = v(t - \Delta t) + {\displaystyle \int_{t - \Delta t}^t} f(\tau)\ d\tau\)
Parameters: - name (str) – The name of the block.
- ic (numeric) – The initial condition of the block. Defaults to 0.
- method (def) – A function to determine the computation of the integral.
It’s preferrably one of
INTEGRAL_LOWER(),INTEGRAL_UPPER()orINTEGRAL_TRAPEZOID(). Defaults toINTEGRAL_TRAPEZOID().
State: - prev (numeric) – The previous value of the integral. Defaults to the initial condition.
- v (numeric) – The current integral.
- fprev (numeric) – The previous value of the function. When
None, themethodis ignored.
Input Ports: input (numeric) – The new value.
Output Ports: result (numeric) – The differential.
-
INTEGRAL_LOWER(curr)[source]¶ Computes the integral from the lower-bound.
\({\displaystyle \int_{t - \Delta t}^t} f(\tau)\ d\tau = \Delta t\cdot f(t - \Delta t)\)
Parameters: curr (numeric) – Current input value.
-
INTEGRAL_UPPER(curr)[source]¶ Computes the integral from the upper-bound.
\({\displaystyle \int_{t - \Delta t}^t} f(\tau)\ d\tau = \Delta t\cdot f(t)\)
Parameters: curr (numeric) – Current input value.
-
class
pypdevsbbl.generic.math.Random(name: str, seed=None, dist=<function Random.<lambda>>, args=())[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSAtomicDEVSthat generates a random number every time a message arrives.It makes use of the RngStreams random number generator i.i.d. (0, 1). Using the
distargument, one can simply change the distribution over which numbers need to be generated. Thepypdevsbbl.extra.rngstreams.distributionsmodule provides an extensive implementation of a lot of distributions.See also
pypdevsbbl.generic.generators.RandomNumberGeneratorpypdevsbbl.generic.generators.RandomDelayGeneratorpypdevsbbl.extra.rngstreamspypdevsbbl.extra.rngstreams.distributions
Parameters: - name (str) – The name of the block and the RNG.
- seed (numeric) – The seed for the generator. When
None, no seed will be set. Defaults toNone. - dist (def) – A stateless function that implements an inversive cumulative distribution function. It takes at least a single argument, which falls in (0, 1). Defaults to a uniform distribution over (0, 1).
- args (tuple) – Optional additional arguments to add to the distribution.
State: - num (numeric) – The random number that’s being/needs to be outputted.
- item (any) – The item that’s passing through.
Input Ports: input (any) – A new input, indicative of an random number request.
Output Ports: - random (numeric) – The random number.
- value (any) – Outputs the input once more.