blockSort

Sort elements of input vector in ascending or descending order

Information

Block that sorts the elements of the input signal u. If the parameter ascending = true, then the output signal y satisfies yi <= yi+1 for all i ∈ {1, ..., n-1}. Otherwise, it satisfies yi >= yi+1 for all i ∈ {1, ..., n-1}. The output signal yIdx contains the indices of the sorted elements, with respect to the input vector u.

Usage

Note that this block shall only be used for input signals u that are time sampled.
Otherwise, in simulation, numerical noise from a nonlinear solver or from an implicit time integration algorithm may cause the simulation to stall. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system.
In real controllers, measurement noise may cause the output to change frequently.

This block may for example be used in a variable air volume flow controller to access the position of the dampers that are most open.

Parameters

TypeNameDefaultDescription
Integernin0Number of input signals
BooleanascendingtrueSet to true if ascending order, otherwise order is descending

Connectors

TypeNameDefaultDescription
Buildings.Controls.OBC.CDL.Interfaces.RealInput[nin]uInput to be sorted
Buildings.Controls.OBC.CDL.Interfaces.RealOutput[nin]yOutput with sorted input
Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput[nin]yIdxIndices of the sorted vector with respect to the original vector

Revisions

  • April 18, 2024, by Jianjun Hu:
    Added an output variable with the indices of the sorted elements. This is for Buildings, issue 3809.
  • March 2, 2020, by Michael Wetter:
    Changed icon to display dynamically the output value.
  • September 22, 2017, by Michael Wetter:
    Reimplemented function to make it work with OpenModelica.
  • September 14, 2017, by Jianjun Hu:
    Changed model name.
  • January 10, 2017, by Milica Grahovac:
    Initial CDL implementation.
  • November 21, 2011, by Michael Wetter:
    Removed assert statement.
  • November 25, 2008, by Michael Wetter:
    First implementation.