From 410d60b22304755db96c761d4d61fe151d8094f6 Mon Sep 17 00:00:00 2001 From: Matt Stinson <11094799+mestinso@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:23:49 -0600 Subject: [PATCH] Added new power block for raising an input to a user parameterized exponent (#4006) * Added new power block for raising an input to a user parameterized exponent * Add tester with various use cases for exponentiation block * Added comparison signals file --- Modelica/Blocks/Math.mo | 36 ++++++++++++ ModelicaTest/Blocks.mo | 55 +++++++++++++++++++ .../Exponentiation/comparisonSignals.txt | 8 +++ 3 files changed, 99 insertions(+) create mode 100644 ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Exponentiation/comparisonSignals.txt diff --git a/Modelica/Blocks/Math.mo b/Modelica/Blocks/Math.mo index 0bfd63e565..7feb81e0ad 100644 --- a/Modelica/Blocks/Math.mo +++ b/Modelica/Blocks/Math.mo @@ -1759,6 +1759,42 @@ y = base ^ u; ")); end Power; + block Exponentiation "Output the input raised to an exponent" + extends Interfaces.SISO; + parameter Real exponent=2 "Exponent of power" annotation (Evaluate=true); + equation + y = u^exponent; + annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100}, + {100,100}}), graphics={ + Line(points={{0,-80},{0,68}}, color={192,192,192}), + Polygon( + points={{0,90},{-8,68},{8,68},{0,90}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid), + Text( + extent={{-86,50},{-14,2}}, + textColor={192,192,192}, + textString="^"), + Line(points={{-80,60},{-70,27.2},{-60,-1.3},{-50,-25.3},{-40,-45},{-30,-60.3}, + {-20,-71.3},{-10,-77.8},{0,-80},{10,-77.8},{20,-71.3},{30,-60.3},{ + 40,-45},{50,-25.3},{60,-1.3},{70,27.2},{80,60}}, smooth=Smooth.Bezier), + Line( + points={{-90,-80.3976},{68,-80.3976}}, + color={192,192,192}, + smooth=Smooth.Bezier), + Polygon( + points={{90,-80.3976},{68,-72.3976},{68,-88.3976},{90,-80.3976}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid)}), Documentation(info=" +

This blocks computes the output y as the input u raised to exponent:

+
+y = u ^ exponent;
+
+")); + end Exponentiation; + block Log "Output the logarithm (default base e) of the input (input > 0 required)" diff --git a/ModelicaTest/Blocks.mo b/ModelicaTest/Blocks.mo index 49e14cbcb1..326bc8180a 100644 --- a/ModelicaTest/Blocks.mo +++ b/ModelicaTest/Blocks.mo @@ -2048,4 +2048,59 @@ the whole homotopy transformation.

")); end LimPID; + model Exponentiation + extends Modelica.Icons.Example; + + Modelica.Blocks.Sources.Ramp negativeToPositiveRamp( + height=4, + duration=1, + offset=-2, + startTime=0) + annotation (Placement(transformation(extent={{-100,80},{-80,100}}))); + Modelica.Blocks.Math.Exponentiation evenExponent(exponent=2) + annotation (Placement(transformation(extent={{0,80},{20,100}}))); + Modelica.Blocks.Math.Exponentiation oddExponent(exponent=3) + annotation (Placement(transformation(extent={{0,50},{20,70}}))); + Modelica.Blocks.Math.Exponentiation oneExponent(exponent=1) + annotation (Placement(transformation(extent={{0,20},{20,40}}))); + Modelica.Blocks.Math.Exponentiation zeroExponent(exponent=0) + annotation (Placement(transformation(extent={{0,-10},{20,10}}))); + Modelica.Blocks.Math.Abs abs1 + annotation (Placement(transformation(extent={{-40,-40},{-20,-20}}))); + Modelica.Blocks.Math.Exponentiation nonInteger(exponent=2.1) + annotation (Placement(transformation(extent={{0,-40},{20,-20}}))); + Modelica.Blocks.Math.Exponentiation sqrtExponent(exponent=0.5) + annotation (Placement(transformation(extent={{0,-70},{20,-50}}))); + Modelica.Blocks.Math.Max max1 + annotation (Placement(transformation(extent={{-40,-100},{-20,-80}}))); + Modelica.Blocks.Sources.Constant oneTenth(k=0.1) + annotation (Placement(transformation(extent={{-80,-100},{-60,-80}}))); + Modelica.Blocks.Math.Exponentiation inverse(exponent=-1) + annotation (Placement(transformation(extent={{0,-100},{20,-80}}))); + equation + connect(negativeToPositiveRamp.y, evenExponent.u) + annotation (Line(points={{-79,90},{-2,90}}, color={0,0,127})); + connect(abs1.u, evenExponent.u) annotation (Line(points={{-42,-30},{-50,-30}, + {-50,90},{-2,90}}, + color={0,0,127})); + connect(abs1.y, nonInteger.u) + annotation (Line(points={{-19,-30},{-2,-30}},color={0,0,127})); + connect(oddExponent.u, evenExponent.u) annotation (Line(points={{-2,60},{ + -20,60},{-20,90},{-2,90}}, + color={0,0,127})); + connect(oneExponent.u, evenExponent.u) annotation (Line(points={{-2,30},{ + -20,30},{-20,90},{-2,90}}, + color={0,0,127})); + connect(sqrtExponent.u, nonInteger.u) annotation (Line(points={{-2,-60},{ + -10,-60},{-10,-30},{-2,-30}}, color={0,0,127})); + connect(max1.y, inverse.u) + annotation (Line(points={{-19,-90},{-2,-90}}, color={0,0,127})); + connect(zeroExponent.u, evenExponent.u) annotation (Line(points={{-2,0},{ + -20,0},{-20,90},{-2,90}}, color={0,0,127})); + connect(max1.u1, evenExponent.u) annotation (Line(points={{-42,-84},{-50, + -84},{-50,90},{-2,90}}, color={0,0,127})); + connect(oneTenth.y, max1.u2) annotation (Line(points={{-59,-90},{-50,-90},{ + -50,-96},{-42,-96}}, color={0,0,127})); + annotation (experiment(StopTime=1.0)); + end Exponentiation; end Blocks; diff --git a/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Exponentiation/comparisonSignals.txt b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Exponentiation/comparisonSignals.txt new file mode 100644 index 0000000000..7f32a937e1 --- /dev/null +++ b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Exponentiation/comparisonSignals.txt @@ -0,0 +1,8 @@ +time +evenExponent.y +oddExponent.y +oneExponent.y +zeroExponent.y +nonInteger.y +sqrtExponent.y +inverse.y