Skip to content

Commit

Permalink
Issue3809 add sort output backward compatible (#3813)
Browse files Browse the repository at this point in the history
* updated sort block

* Added output yIdx to CDL.Reals.Sort

This is a backward compatible version of #3810

---------

Co-authored-by: JayHuLBL <[email protected]>
  • Loading branch information
mwetter and JayHuLBL authored Apr 23, 2024
1 parent c7220f4 commit 16be388
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
20 changes: 15 additions & 5 deletions Buildings/Controls/OBC/CDL/Reals/Sort.mo
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ block Sort
Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nin]
"Connector of Real output signals"
annotation (Placement(transformation(extent={{100,-20},{140,20}})));

Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yIdx[nin]
"Indices of the sorted vector with respect to the original vector"
annotation (Placement(transformation(extent={{100,-80},{140,-40}}),
iconTransformation(extent={{100,-80},{140,-40}})));
equation
y=Modelica.Math.Vectors.sort(
(y, yIdx)=Modelica.Math.Vectors.sort(
u,
ascending=ascending);

annotation (
defaultComponentName="sort",
Icon(
Expand All @@ -42,10 +46,12 @@ equation
info="<html>
<p>
Block that sorts the elements of the input signal <i>u</i>.
If the parameter <code>ascending = true</code>, then the output signal satisfies
If the parameter <code>ascending = true</code>, then the output signal <i>y</i> satisfies
<i>y<sub>i</sub> &lt;= y<sub>i+1</sub></i> for all <i>i &isin; {1, ..., n-1}</i>.
Otherwise, it satisfies
<i>y<sub>i</sub> &gt;= y<sub>i+1</sub></i> for all <i>i &isin; {1, ..., n-1}</i>.
The output signal <i>yIdx</i> contains the indices of the sorted elements,
with respect to the input vector <i>u</i>.
</p>
<h4>Usage</h4>
<p>
Expand All @@ -62,10 +68,14 @@ 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.
</p>
</html>",
revisions="<html>
</html>", revisions="<html>
<ul>
<li>
April 18, 2024, by Jianjun Hu:<br/>
Added an output variable with the indices of the sorted elements.
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3809\">issue 3809</a>.
</li>
<li>
March 2, 2020, by Michael Wetter:<br/>
Changed icon to display dynamically the output value.
</li>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
simulateModel("Buildings.Controls.OBC.CDL.Reals.Validation.Sort", method="Cvode", tolerance=1e-06, stopTime=1.0, resultFile="Sort1");
createPlot(id=1, position={53, 14, 959, 905}, y={"sorAsc.u[1]", "sorAsc.u[2]", "sorAsc.u[3]", "sorAsc.u[4]", "sorAsc.u[5]"}, range={0.0, 0.0, -4.0, 6.0}, grid=true, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}});
createPlot(id=1, position={53, 14, 959, 299}, y={"sorAsc.y[1]", "sorAsc.y[2]", "sorAsc.y[3]", "sorAsc.y[4]", "sorAsc.y[5]"}, range={0.0, 0.0, -6.0, 6.0}, grid=true, subPlot=2, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}});
createPlot(id=1, position={53, 14, 959, 299}, y={"sorDes.y[1]", "sorDes.y[2]", "sorDes.y[3]", "sorDes.y[4]", "sorDes.y[5]"}, range={0.0, 0.0, -6.0, 6.0}, grid=true, subPlot=3, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}});
createPlot(id=1, position={24, 14, 959, 865}, y={"sorAsc.u[1]", "sorAsc.u[2]", "sorAsc.u[3]", "sorAsc.u[4]", "sorAsc.u[5]"}, range={0.0, 1.0, -4.0, 6.0}, grid=true, subPlot=101, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}}, timeUnit="s");
createPlot(id=1, position={24, 14, 959, 865}, y={"sorAsc.y[1]", "sorAsc.y[2]", "sorAsc.y[3]", "sorAsc.y[4]", "sorAsc.y[5]"}, range={0.0, 1.0, -4.0, 6.0}, grid=true, subPlot=102, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}}, timeUnit="s");
createPlot(id=1, position={24, 14, 959, 865}, y={"sorDes.y[1]", "sorDes.y[2]", "sorDes.y[3]", "sorDes.y[4]", "sorDes.y[5]"}, range={0.0, 1.0, -6.0, 6.0}, grid=true, subPlot=103, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}}, timeUnit="s");
createPlot(id=2, position={1001, 330, 1147, 549}, y={"sorAsc.yIdx[1]", "sorAsc.yIdx[2]", "sorAsc.yIdx[3]", "sorAsc.yIdx[4]", "sorAsc.yIdx[5]"}, range={0.0, 1.0, 0.0, 6.0}, grid=true, subPlot=101, colors={{28,108,200}, {28,108,200}, {28,108,200}, {28,108,200}, {28,108,200}}, timeUnit="s");
createPlot(id=2, position={1001, 330, 1147, 549}, y={"sorDes.yIdx[1]", "sorDes.yIdx[2]", "sorDes.yIdx[3]", "sorDes.yIdx[4]", "sorDes.yIdx[5]"}, range={0.0, 1.0, 0.0, 6.0}, grid=true, subPlot=102, colors={{28,108,200}, {28,108,200}, {28,108,200}, {28,108,200}, {28,108,200}}, timeUnit="s");


Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@ compareVars :=
"sorDes.y[2]",
"sorDes.y[3]",
"sorDes.y[4]",
"sorDes.y[5]"
"sorDes.y[5]",
"sorAsc.yIdx[1]",
"sorAsc.yIdx[2]",
"sorAsc.yIdx[3]",
"sorAsc.yIdx[4]",
"sorAsc.yIdx[5]",
"sorDes.yIdx[1]",
"sorDes.yIdx[2]",
"sorDes.yIdx[3]",
"sorDes.yIdx[4]",
"sorDes.yIdx[5]"
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ block SortRuntime
Buildings.Controls.OBC.CDL.Logical.Sources.Constant u1Res[nEquAlt](
each k=false) "Signal for staging runtime reset"
annotation (Placement(transformation(extent={{-180,-110},{-160,-90}})));
Utilities.SortWithIndices sor(
Buildings.Controls.OBC.CDL.Reals.Sort sor(
final ascending=true,
nin=nEquAlt)
"Sort equipment by increasing weighted runtime"
Expand Down Expand Up @@ -291,8 +291,8 @@ Note that the staging runtime and the time elapsed since an equipment became una
are both computed from Boolean signals (<code>u1Run</code> and <code>u1Ava</code>).
These are discrete-time, piecewise constant variables,
which is why the caveat in the documentation of
<a href=\"modelica://Buildings.Templates.Plants.Controls.Utilities.SortWithIndices\">
Buildings.Templates.Plants.Controls.Utilities.SortWithIndices</a>
<a href=\"modelica://Buildings.Controls.OBC.CDL.Reals.Sort\">
Buildings.Controls.OBC.CDL.Reals.Sort</a>
for purely continuous time-varying variables does not apply here.
Therefore, no sampling is performed before sorting the equipment runtimes.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ model EquipmentEnable "Validation model for equipment enable logic"
Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea[3]
"Cast to real"
annotation (Placement(transformation(extent={{-28,50},{-8,70}})));
Utilities.SortWithIndices sort(
Buildings.Controls.OBC.CDL.Reals.Sort sort(
ascending=false,
nin=3)
"Sort lead/lag alternate equipment with available equipment first"
annotation (Placement(transformation(extent={{0,50},{20,70}})));
Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea1[2]
"Cast to real"
annotation (Placement(transformation(extent={{-28,-90},{-8,-70}})));
Utilities.SortWithIndices sort1(
Buildings.Controls.OBC.CDL.Reals.Sort sort1(
ascending=false,
nin=2)
"Sort lead/lag alternate equipment with available equipment first"
Expand Down
8 changes: 7 additions & 1 deletion Buildings/UsersGuide/ReleaseNotes/Version_11_0_1.mo
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ have been <b style=\"color:blue\">improved</b> in a
<tr><td colspan=\"2\"><b>Buildings.Controls.OBC.CDL</b>
</td>
</tr>
<tr><td valign=\"top\">Buildings.Controls.OBC.CDL.Reals.Sort
</td>
<td valign=\"top\">Added an output variable with the indices of the sorted elements.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3809\">issue 3809</a>.
</td>
</tr>
<tr><td valign=\"top\">Buildings.Controls.OBC.CDL.Logical.Latch
</td>
<td valign=\"top\">Simplified the implementation.<br/>
Expand All @@ -65,7 +71,7 @@ have been <b style=\"color:blue\">improved</b> in a
<b style=\"color:blue\">non-backward compatible</b> way:
</p>
<table class=\"releaseTable\" summary=\"summary\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" style=\"border-collapse:collapse;\">
<tr><td colspan=\"2\"><b>xxx</b>
<tr><td colspan=\"2\"><b>xxx</b>
</td>
</tr>
<tr><td valign=\"top\">xxx
Expand Down

0 comments on commit 16be388

Please sign in to comment.