push impure function

Requirements.Internal.SlidingWindow.push  ยท source

Icon of push

Store an element on the sliding window buffer and remove elements that are older as the window length

Extends Modelica.Icons.Function

Stores the pair (t, b) as the newest element of the buffer and returns the updated buffer. First, all elements that have left the window are removed, those with buffer.t[i] ≤ t - (1 - eps)*T (eps = 1000*Modelica.Constants.eps, so that an element exactly one window length old is removed despite rounding), as in removeOldest. Then the new element is written at the index after the newest one, wrapping around from nBuffer to 1.

If the buffer is full (nElem ≥ nBuffer after the removal), the warning "buffer of sliding window too small" is printed and the oldest element is dropped to make room, so that the buffer keeps at most nBuffer elements; t0 is set to the time of the dropped element, so the duration functions count from there and the results hold for a shorter window. The function is impure because of this print. It is called by the blocks of ChecksInSlidingWindow: by the duration checks (MinDuration, MaxAccumulatedDuration, ...) at every change of the checked Boolean signal, with its new value, so consecutive elements alternate between true and false (which maxDuration and accumulatedDuration assume); by the counting checks (MinRising, MaxFrequency, ...) at every rising edge, with the default b = false, where only the number of elements matters.

Revisions

2026-12-03, Model Based Innovation LLC: a full buffer drops its oldest element before the new one is stored (before, the new element overwrote the oldest one without moving last, and nElem grew beyond nBuffer); tested by TestSlidingWindow.testFullBuffer.

Inputs

NameTypeDescription
buffer inputBufferMemory of sliding window
t inputRealTime instant of v to be stored in buffer
b inputBooleanValue b at time instant t to be stored in buffer

Outputs

NameTypeDescription
newBuffer outputBufferUpdated memory of sliding window