-
-
Save beutlich/e630b2bf6cdf3efe96e5e9a637124fe1 to your computer and use it in GitHub Desktop.
Modelica library for investigations of data aggregation ideas as presented at http://www.modelisax.de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CP: 65001 | |
/* DataAggregation.mo - Modelica library for investigations of data aggregation ideas | |
* | |
* Copyright (C) 2018, ESI ITI GmbH | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are met: | |
* | |
* 1. Redistributions of source code must retain the above copyright notice, | |
* this list of conditions and the following disclaimer. | |
* 2. Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
within ; | |
package DataAggregation "Investigations of data aggregation ideas" | |
package Interfaces | |
record R "Data to be aggregated" | |
Real x "Abscissa"; | |
Real y "Ordinate"; | |
end R; | |
connector RIn = input R annotation(Icon(graphics={ | |
Ellipse( | |
extent={{-100,100},{100,-100}}, | |
lineColor={255,85,170}, | |
fillColor={255,85,170}, | |
fillPattern=FillPattern.Solid)})); | |
connector ROut = output R annotation(Icon(graphics={ | |
Polygon( | |
points={{-100,100},{100,0},{-100,-100}}, | |
lineColor={255,85,170}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid)})); | |
end Interfaces; | |
model Example0 "Idea using explicit references" | |
model S | |
parameter Real x=60 "Abscissa" annotation(HideResult=true); | |
parameter Real y=0 "Ordinate" annotation(HideResult=true); | |
output Interfaces.R o=Interfaces.R(x, y) annotation(HideResult=true); | |
annotation(Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255})})); | |
end S; | |
model M | |
input Interfaces.R u[:] "Data" annotation(HideResult=true); | |
Real data[:,2]=[u.x,u.y] "Aggregated data"; | |
annotation(Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={ | |
Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), | |
Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255}), | |
Polygon( | |
points=DynamicSelect({{0,0}}, data), | |
fillColor={255,255,0}, | |
fillPattern=FillPattern.Solid)})); | |
end M; | |
S s1( | |
x=-60, | |
y=80) annotation(Placement(transformation(extent={{-80,60},{-60,80}}))); | |
S s2( | |
x=-60, | |
y=-80) annotation(Placement(transformation(extent={{-80,20},{-60,40}}))); | |
M m(u={s1.o, s2.o}) annotation(Placement(transformation(extent={{-20,60},{0,80}}))); | |
annotation(Documentation(info="<html> | |
<h4>Description</h4> | |
<p>This model uses explicit references in <code>m.u</code> to allocate the aggregated data.</p> | |
<h4>Pros</h4> | |
<ul> | |
<li>Plain and straightforward</li> | |
</ul> | |
<h4>Cons</h4> | |
<ul> | |
<li>Adding and deleting instances of model <code>S</code> subsequently requires (manual) updating of <code>m.u</code></li> | |
</ul> | |
</html>")); | |
end Example0; | |
model Example1 "Idea relying on explicit connects and connectorSizing" | |
model S | |
parameter Real x=60 "Abscissa" annotation(HideResult=true); | |
parameter Real y=0 "Ordinate" annotation(HideResult=true); | |
Interfaces.ROut o annotation( | |
Placement( | |
transformation(extent={{100,-10},{120,10}}), | |
iconTransformation(extent={{100,-10},{120,10}})), | |
HideResult=true); | |
equation | |
o.x = x; | |
o.y = y; | |
annotation(Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255})})); | |
end S; | |
model M | |
parameter Integer n(min=0)=0 "Number of instances" annotation( | |
Dialog(connectorSizing=true), | |
HideResult=true); | |
Interfaces.RIn u[n] annotation( | |
Placement( | |
transformation(extent={{-120,-20},{-80,20}}), | |
iconTransformation(extent={{-120,-60},{-80,60}})), | |
HideResult=true); | |
Real data[n,2]=[u.x,u.y] "Aggregated data"; | |
annotation(Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={ | |
Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), | |
Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255}), | |
Text( | |
extent={{-100,-110},{100,-150}}, | |
lineColor={0,0,0}, | |
textString="n=%n"), | |
Polygon( | |
points=DynamicSelect({{0,0}}, data), | |
fillColor={255,255,0}, | |
fillPattern=FillPattern.Solid)})); | |
end M; | |
S s1( | |
x=-60, | |
y=80) annotation(Placement(transformation(extent={{-80,60},{-60,80}}))); | |
S s2( | |
x=-60, | |
y=-80) annotation(Placement(transformation(extent={{-80,20},{-60,40}}))); | |
M m(n=2) annotation(Placement(transformation(extent={{-20,60},{0,80}}))); | |
equation | |
connect(s1.o,m.u[1]) annotation(Line( | |
points={{-59,70},{-54,70},{-25,70},{-25,67.7},{-20,67.7}}, | |
color={255,85,170})); | |
connect(s2.o,m.u[2]) annotation(Line( | |
points={{-59,30},{-54,30},{-25,30},{-25,72.3},{-20,72.3}}, | |
color={255,85,170})); | |
annotation(Documentation(info="<html> | |
<h4>Description</h4> | |
<p>This model relies on explicit connects and the connectorSizing GUI feature.</p> | |
<h4>Pros</h4> | |
<ul> | |
<li>Plain and straightforward</li> | |
<li>Size of aggregated data is automatically updated with each new/deleted connection, if the GUI supports the <code>connectorSizing</code> GUI feature</li> | |
</ul> | |
<h4>Cons</h4> | |
<ul> | |
<li>Connection lines increase complexity and are not required for model comprehension</li> | |
<li>Order is determined by order of connecting</li> | |
</ul> | |
</html>")); | |
end Example1; | |
model Example2 "Idea relying on inherited connects and inner/outer" | |
connector C | |
end C; | |
model CM | |
Interfaces.ROut o; | |
C c; | |
end CM; | |
partial model ConnectWithOuter | |
parameter Integer i "Instance index"; | |
outer M m; | |
CM cm; | |
// String name = getInstanceName(); | |
equation | |
connect(m.c, cm.c); | |
connect(m.u[i], cm.o); | |
end ConnectWithOuter; | |
model S | |
extends ConnectWithOuter; | |
parameter Real x=60 "Abscissa" annotation(HideResult=true); | |
parameter Real y=0 "Ordinate" annotation(HideResult=true); | |
equation | |
cm.o.x = x; | |
cm.o.y = y; | |
annotation(Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255})})); | |
end S; | |
model M | |
C c; | |
parameter Integer n(min=0)=cardinality(c) "Number of instances" annotation(HideResult=true); | |
Interfaces.RIn u[n] annotation(HideResult=true); | |
Real data[n,2]=[u.x,u.y] "Aggregated data"; | |
//equation | |
// for i in 1:n loop | |
// data[i,1] = u[i].x; | |
// data[i,2] = u[i].y; | |
// end for; | |
annotation( | |
defaultComponentName="m", | |
defaultComponentPrefixes="inner", | |
Icon( | |
coordinateSystem( | |
preserveAspectRatio=true, | |
extent={{-100,-100},{100,100}}), | |
graphics={ | |
Rectangle( | |
extent={{-100,-100},{100,100}}, | |
lineColor={0,0,127}, | |
fillColor={255,255,255}, | |
fillPattern=FillPattern.Solid), | |
Text( | |
extent={{-150,150},{150,110}}, | |
textString="%name", | |
lineColor={0,0,255}), | |
Text( | |
extent={{-100,-110},{100,-150}}, | |
lineColor={0,0,0}, | |
textString="n=%n"), | |
Polygon( | |
points=DynamicSelect({{0,0}}, data), | |
fillColor={255,255,0}, | |
fillPattern=FillPattern.Solid)})); | |
end M; | |
S s1( | |
i=1, | |
x=-60, | |
y=80) annotation(Placement(transformation(extent={{-80,60},{-60,80}}))); | |
S s2( | |
i=2, | |
x=-60, | |
y=-80) annotation(Placement(transformation(extent={{-80,20},{-60,40}}))); | |
inner M m(n=2) annotation(Placement(transformation(extent={{-20,60},{0,80}}))); | |
annotation(Documentation(info="<html> | |
<h4>Description</h4> | |
<p>This model relies on inherited connects and inner/outer. It was inspired by the <a href=\"http://www.ep.liu.se/ecp/118/046/ecp15118427.pdf\">article</a> \"Generic Modelica Framework for MultiBody Contacts and Discrete Element Method\" from H. Elmqvist et al. for the <a href=\"https://modelica.org/events/modelica2015\">11th International Modelica Conference</a> in 2015.</p> | |
<h4>Pros</h4> | |
<ul> | |
<li>Connections are inherited and do not need to be drawn manually</li> | |
<li>Order is determined by order of instance index</li> | |
</ul> | |
<h4>Cons</h4> | |
<ul> | |
<li>Harder to comprehend</li> | |
<li>Adding and deleting instances of model <code>S</code> subsequently requires (manual) updating of the instance indices <code>i</code> and the total number of instances <code>m.n</code></li> | |
<li>Neither GUI nor Modelica language support to update the instance indices automatically \"<code>instanceSizing</code>\"</li> | |
<li>Neither GUI nor Modelica language support to update the total number of instances automatically (<code>cardinality</code> unfortunately does not work out nevertheless it is deprecated)</li> | |
</ul> | |
</html>")); | |
end Example2; | |
annotation(preferredView="info", Documentation(info="<html> | |
<h4>Intention</h4> | |
<p>The idea originated from a Helpdesk entry of <a href=\"http://www.ea-energie.de\">EA Systems</a> for <a href=\"https://www.simulationx.de\">ESI ITI</a>. The task was to investigate a general Modelica compliant and user-friendly approach to gather data from an arbitrary number of components and aggregate it for e.g., visualization or plotting.</p> | |
<p>The library was presented at the 20th meeting of the <a href=\"http://www.modelisax.de\">Modelica User Group Saxony</a>.</p> | |
<h4>Use scenarios</h4> | |
<ul> | |
<li>Add new component</li> | |
<li>Delete previously available component</li> | |
</ul> | |
<h4>Ideas</h4> | |
<p>Three ideas have been investigated</p> | |
<ol start=\"0\"> | |
<li>Using explicit references in <a href=\"modelica://DataAggregation.Example0\">Example0</a></li> | |
<li>Relying on explicit connects and connectorSizing in <a href=\"modelica://DataAggregation.Example1\">Example1</a></li> | |
<li>Relying on inherited connects and inner/outer in <a href=\"modelica://DataAggregation.Example2\">Example2</a></li> | |
</ol> | |
<p>Each of the examples contains an arbitrary number of instances of model <code>S</code> and exactly one instance of model <code>M</code>. Think of <code>S</code> as Sibling, Sensor or Slave. Think of <code>M</code> as Mother, Master, Mux or Multi-Something.</p> | |
<h4>Summary</h4> | |
The idea of <a href=\"modelica://DataAggregation.Example1\">Example1</a> was proposed as Helpdesk answer to <a href=\"http://www.ea-energie.de\">EA Systems</a>. It turns out that it is superior w.r.t. user-friendliness and Modelica comprehension compared to the other two investigated ideas as long as there is no <code>connectorSizing</code> feature on inherited connections (or something as \"<code>instanceSizing</code>\") in the Modelica language. | |
</html>")); | |
end DataAggregation; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment