pySimBlocks.blocks.operators.saturation

class pySimBlocks.blocks.operators.saturation.Saturation(name: str, u_min: ArrayLike = -inf, u_max: ArrayLike = inf, sample_time: float | None = None)[source]

Bases: Block

Discrete-time saturation operator.

Applies element-wise saturation to the input signal:

y = clip(u, u_min, u_max)

Bounds are resolved component-wise on the first call using explicit broadcasting rules: scalar (1,1) broadcasts to (m,n); vector (m,1) broadcasts across columns; matrix (m,n) must match exactly. Once the input shape is resolved it must remain constant.

u_min_raw

Raw lower bound before broadcasting.

u_max_raw

Raw upper bound before broadcasting.

u_min

Broadcasted lower bound matched to the input shape, or None before the first resolution.

u_max

Broadcasted upper bound matched to the input shape, or None before the first resolution.

direct_feedthrough = True

True if outputs depend directly on inputs.

initialize(t0: float) None[source]

Resolve bounds from the initial input and compute the initial output.

Parameters:

t0 – Initial simulation time in seconds.

Raises:
  • RuntimeError – If input 'in' is None at initialization.

  • ValueError – If input is not 2D, bounds have incompatible shapes, or u_min > u_max for any component.

output_update(t: float, dt: float) None[source]

Saturate the input and write the result to the output port.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:
  • RuntimeError – If input 'in' is None.

  • ValueError – If input is not 2D or its shape changed after initialization.

state_update(t: float, dt: float) None[source]

No-op: Saturation is a stateless block.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.