Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commonly used Blocks and Interfaces #4518

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Modelica/Blocks/Interfaces.mo
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ continuous Real output signal y.

end SI2SO;

partial block SI2SO2
"2 Single Input / 2 Single Output continuous control block"
extends Modelica.Blocks.Icons.Block;

RealInput u1 "Connector of Real input signal 1" annotation (Placement(
transformation(extent={{-140,40},{-100,80}})));
RealInput u2 "Connector of Real input signal 2" annotation (Placement(
transformation(extent={{-140,-80},{-100,-40}})));
RealOutput y1 "Connector of Real output signal 1" annotation (Placement(
transformation(extent={{100,50},{120,70}})));
RealOutput y2 "Connector of Real output signal 2" annotation (Placement(
transformation(extent={{100,-70},{120,-50}})));

annotation (Documentation(info="<html>
<p>
Block has two continuous Real input signals u1 and u2 and two
continuous Real output signals y1 and y2.
</p>
</html>"));

end SI2SO2;

partial block SIMO "Single Input Multiple Output continuous control block"
extends Modelica.Blocks.Icons.Block;
parameter Integer nout=1 "Number of outputs";
Expand All @@ -370,6 +392,22 @@ continuous Real output signal y.
</html>"));
end SIMO;

partial block SI2MO "2 Single Input / 1 Multiple Output continuous control block"
extends Modelica.Blocks.Icons.Block;
parameter Integer nout=1 "Number of outputs";
RealInput u1 "Connector of Real input signal 1" annotation (Placement(
transformation(extent={{-140,40},{-100,80}}, rotation=0)));
RealInput u2 "Connector of Real input signal 2" annotation (Placement(
transformation(extent={{-140,-80},{-100,-40}}, rotation=0)));
RealOutput y[nout] "Connector of Real output signal" annotation (Placement(
transformation(extent={{100,-10},{120,10}}, rotation=0)));

annotation (Documentation(info="<html>
<p>Block has two continuous Real input signals and a vector of continuous Real output signals.</p>
</html>"));

end SI2MO;

partial block MISO "Multiple Input Single Output continuous control block"

extends Modelica.Blocks.Icons.Block;
Expand All @@ -386,6 +424,24 @@ one continuous Real output signal.
</html>"));
end MISO;

partial block MI2SO
"2 Multiple Input / Single Output continuous control block"
extends Modelica.Blocks.Icons.Block;
parameter Integer n=1 "Dimension of input vector.";
RealInput u1[n] "Connector 1 of Real input signals" annotation (Placement(
transformation(extent={{-140,40},{-100,80}})));
RealInput u2[n] "Connector 2 of Real input signals" annotation (Placement(
transformation(extent={{-140,-80},{-100,-40}})));
RealOutput y "Connector of Real output signals" annotation (Placement(
transformation(extent={{100,-10},{120,10}})));

annotation (Documentation(info="<html>
<p>Block has two continuous Real input vectors u1 and u2 and one
continuous Real output signal y. All input vectors have the same number of elements.
</p>
</html>"));
end MI2SO;

partial block PartialRealMISO
"Partial block with a RealVectorInput and a RealOutput signal"

Expand Down
46 changes: 46 additions & 0 deletions Modelica/Blocks/Logical.mo
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,52 @@ u1, else it is set equal to u3.</p>
extent={{2,-6},{18,8}})}));
end LogicalSwitch;

block IntegerSwitch "Switch between two Integer signals"
extends Modelica.Blocks.Icons.PartialBooleanBlock;
Blocks.Interfaces.IntegerInput u1 "First input signal"
annotation (Placement(transformation(extent={{-140,60},{-100,100}})));
Blocks.Interfaces.BooleanInput u2 "Boolean condition to select between u1 and u3"
annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
Blocks.Interfaces.IntegerInput u3 "Second input signal"
annotation (Placement(transformation(extent={{-140,-100},{-100,-60}})));
Blocks.Interfaces.IntegerOutput y "Output signal"
annotation (Placement(transformation(extent={{100,-10},{120,10}})));

equation
y = if u2 then u1 else u3;
annotation (
Documentation(info="<html>
<p>The IntegerSwitch switches, depending on the
Boolean u2 connector (the middle connector),
between the two possible input signals
u1 (upper connector) and u3 (lower connector).</p>
<p>If u2 is true, connector y is set equal to
u1, else it is set equal to u3.</p>
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{12,0},{100,0}},
color={255,127,0}),
Line(points={{-100,0},{-40,0}},
color={255,0,255}),
Line(points={{-100,-80},{-40,-80},{-40,-80}},
color={255,127,0}),
Line(points={{-40,12},{-40,-12}},
color={255,0,255}),
Line(points={{-100,80},{-38,80}},
color={255,127,0}),
Line(points=DynamicSelect({{-38,80},{6,2}}, if u2 then {{-38,80},{6,2}} else {{-38,-80},{6,2}}),
color={255,127,0},
thickness=1,
smooth=Smooth.Bezier),
Ellipse(lineColor={255,127,0},
pattern=LinePattern.None,
fillPattern=FillPattern.Solid,
extent={{-2,-8},{14,8}},
fillColor={244,125,35})}));
end IntegerSwitch;

block Switch "Switch between two Real signals"
extends Modelica.Blocks.Icons.PartialBooleanBlock;
Blocks.Interfaces.RealInput u1 "Connector of first Real input signal"
Expand Down
137 changes: 137 additions & 0 deletions Modelica/Blocks/Math.mo
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,67 @@
Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}})}));
end Product;

block VectorProduct "Output product of the two inputs with dimension n"
extends Modelica.Blocks.Interfaces.MI2SO;

equation
y = u1 * u2;

annotation (
Documentation(
info = "<html>
<p>This blocks computes the output <b>y</b> as <i>product</i> of the two input vectors <b>u1</b> and <b>u2</b>: </p>

Check warning on line 1009 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.

Check warning on line 1009 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "i" misuse.

Check warning on line 1009 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.

Check warning on line 1009 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.
<blockquote><pre>
y = u1 * u2;
</pre></blockquote>
<p>As example, for three-dimentional input vectors the equation would be: </p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>As example, for three-dimentional input vectors the equation would be: </p>
<p>As example, for three-dimensional input vectors the equation would be: </p>

<blockquote><pre>
y = u1[1]*u2[1] + u1[2]*u2[2] + u1[3]*u2[3];
</pre></blockquote>
The output <b>y</b> is scalar.

Check warning on line 1017 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "b" misuse.
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{-100,60},{-40,60},{-30,40}}, color={0,0,127}),
Line(points={{-100,-60},{-40,-60},{-30,-40}}, color={0,0,127}),
Line(points={{50,0},{100,0}}, color={0,0,127}),
Line(points={{-30,0},{30,0}}),
Line(points={{-15,25.99},{15,-25.99}}),
Line(points={{-15,-25.99},{15,25.99}}),
Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}})}),
Diagram(
coordinateSystem(
preserveAspectRatio = true,
extent = {
{-100, -100},
{100, 100}}),
graphics = {
Line(
points = {
{-100, 60},
{-40, 60},
{-30, 40}},
color = {0, 0, 255}),
Line(
points = {{-100, -60}, {-40, -60}, {-30, -40}},
color = {0, 0, 255}),
Line(points = {{50, 0}, {100, 0}}, color = {0, 0, 255}),
Line(points = {{-30, 0}, {30, 0}}),
Line(
points = {
{-15, 25.99},
{15, -25.99}}),
Line(
points = {
{-15, -25.99},
{15, 25.99}}),
Ellipse(
extent = {{-50, 50}, {50, -50}},
lineColor = {0, 0, 255})}));

end VectorProduct;

block Division "Output first input divided by second input"
extends Interfaces.SI2SO;

Expand Down Expand Up @@ -1033,6 +1094,82 @@
color={0,0,255})}));
end Division;

block NormalizeVector "Normalizes a vector"
extends Modelica.Blocks.Interfaces.MIMOs(n = 3);

parameter Real eps(min = 0.0) = 100 * Modelica.Constants.eps
"if |v| < eps then result = y0";
parameter Real y0[n] = {1, 0, 0}
"Output vector if length(u) < eps";

equation
y = noEvent(Modelica.Math.Vectors.normalize(u, eps));

annotation (
Icon(
graphics = {
Line(
points = {{-42.1048, -27.0405}, {34, -28}, {34, -28}, {14, -18}, {14, -18}, {14, -38}, {14, -38}, {34, -28}, {34, -28}},
color = {0, 86, 134},
rotation = 55,
origin = {-14, 50},
visible = true,
pattern = LinePattern.Dash,
thickness = 0.5,
smooth = Smooth.Bezier),
Line(
points = {
{-46.5285, -27.6965},
{-46.5285, -27.6965},
{33.92, -27.5215},
{33.92, -27.5215},
{14, -18},
{14, -18},
{14, -38},
{14, -38},
{33.92, -27.5215},
{33.92, -27.5215}},
color = {0, 86, 134},
rotation = 55,
origin = {-58, -12},
pattern = LinePattern.Solid,
thickness = 0.5,
smooth = Smooth.Bezier),
Line(points = {{-62, -74}, {-62, 58}}, color = {200, 200, 200}),
Polygon(
points = [-62.0, 72.0; -62.0, 72.0; -66.0, 56.0; -66.0, 56.0; -58.0, 56.0; -58.0, 56.0; -62.0, 72.0; -62.0, 72.0],
lineColor = {200, 200, 200},
fillColor = {200, 200, 200},
fillPattern = FillPattern.Solid,
pattern = LinePattern.None,
smooth = Smooth.Bezier),
Line(points = {{-68, -66}, {58, -66}}, color = {200, 200, 200}),
Polygon(
points = {{0, 8}, {0, 8}, {-4, -8}, {-4, -8}, {4, -8}, {4, -8}, {0, 8}, {0, 8}},
lineColor = {200, 200, 200},
fillColor = {200, 200, 200},
fillPattern = FillPattern.Solid,
pattern = LinePattern.None,
smooth = Smooth.Bezier,
origin = {58, -66},
rotation = 270),
Line(
points = {{12, -60}, {12, -76}},
color = {200, 200, 200},
pattern = LinePattern.None,
smooth = Smooth.Bezier),
Line(points = {{20, -70}, {20, -62}}, color = {200, 200, 200}),
Line(
points = {{0, -4}, {0, 4}},
color = {200, 200, 200},
origin = {-62, 16},
rotation = 90)}),
Documentation(
info = "<html>
<p>This block normalizes an input vector <i>u</i> using the <a href=\"modelica://Modelica.Math.Vectors.normalize\">normalize</a> function.</p>

Check warning on line 1169 in Modelica/Blocks/Math.mo

View workflow job for this annotation

GitHub Actions / html_documentation_checks

HTML tag "i" misuse.
</html>"));
end NormalizeVector;

block Abs "Output the absolute value of the input"
extends Interfaces.SISO;
parameter Boolean generateEvent=false
Expand Down
Loading
Loading