From 7014c6d5bd3aaa15562f157e8e9d5e2ff72655a2 Mon Sep 17 00:00:00 2001 From: AMaccarini Date: Wed, 18 Sep 2024 12:53:34 +0200 Subject: [PATCH] Moved block MovingAverage into protected code --- .../Validation/BESTEST/Cases6xx/Case600.mo | 195 +++++++++++++++++- .../Validation/BESTEST/Cases6xx/Case600FF.mo | 193 ++++++++++++++++- IBPSA/Utilities/Math/MovingAverage.mo | 187 ----------------- IBPSA/Utilities/Math/package.order | 1 - 4 files changed, 384 insertions(+), 192 deletions(-) delete mode 100644 IBPSA/Utilities/Math/MovingAverage.mo diff --git a/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600.mo b/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600.mo index d40120cb42..42df2500a1 100644 --- a/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600.mo +++ b/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600.mo @@ -93,10 +93,10 @@ model Case600 u(unit="W"), y(unit="J", displayUnit="J")) "Cooling energy in Joules" annotation (Placement(transformation(extent={{54,74},{66,86}}))); - IBPSA.Utilities.Math.MovingAverage PHea(delta=3600) + MovingAverage PHea(delta=3600) "Hourly averaged heating power" annotation (Placement(transformation(extent={{34,84},{42,92}}))); - IBPSA.Utilities.Math.MovingAverage PCoo(delta=3600) "Hourly averaged cooling power" + MovingAverage PCoo(delta=3600) "Hourly averaged cooling power" annotation (Placement(transformation(extent={{38,22},{46,30}}))); Modelica.Blocks.Sources.CombiTimeTable TSetCoo(table=[0.0,273.15 + 27]) @@ -106,6 +106,197 @@ model Case600 rotation=0))); Modelica.Blocks.Sources.Constant latGai(k=0) "Internal heat gains" annotation (Placement(transformation(extent={{-80,-60},{-60,-40}}))); + +protected + +block MovingAverage "Block to output moving average" + parameter Real delta( + final quantity="Time", + final unit="s", + min=1E-5) + "Time horizon over which the input is averaged"; + Modelica.Blocks.Interfaces.RealInput u + "Connector of Real input signal" + annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); + Modelica.Blocks.Interfaces.RealOutput y + "Connector of Real output signal" + annotation (Placement(transformation(extent={{100,-20},{140,20}}))); + +protected + parameter Real tStart( + final quantity="Time", + final unit="s", + fixed=false) + "Start time"; + Real mu + "Internal integrator variable"; + Real muDel + "Internal integrator variable with delay"; + Boolean mode( + start=false, + fixed=true) + "Calculation mode"; + +initial equation + tStart=time; + mu=0; + +equation + u=der(mu); + muDel=delay( + mu, + delta); + // Compute the mode so that Dymola generates + // time and not state events as it would with + // an if-then construct + when time >= tStart+delta then + mode=true; + end when; + if mode then + y=(mu-muDel)/delta; + else + y=(mu-muDel)/(time-tStart+1E-3); + end if; + annotation ( + defaultComponentName="movAve", + Icon( + graphics={ + Rectangle( + extent={{-100,-100},{100,100}}, + lineColor={0,0,127}, + fillColor={255,255,255}, + fillPattern=FillPattern.Solid), + Polygon( + points={{-78,90},{-86,68},{-70,68},{-78,90}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid), + Line( + points={{-78,68},{-78,-80}}, + color={192,192,192}), + Line( + points={{-88,0},{70,0}}, + color={192,192,192}), + Polygon( + points={{92,0},{70,8},{70,-8},{92,0}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid), + Line( + points={{-78,-31},{-64,-31},{-64,-15},{-56,-15},{-56,-63},{-48,-63}, + {-48,-41},{-40,-41},{-40,43},{-32,43},{-32,11},{-32,11},{-32,-49}, + {-22,-49},{-22,-31},{-12,-31},{-12,-59},{-2,-59},{-2,23},{4,23}, + {4,37},{10,37},{10,-19},{20,-19},{20,-7},{26,-7},{26,-37}, + {36,-37},{36,35},{46,35},{46,1},{54,1},{54,-65},{64,-65}}, + color={215,215,215}), + Line( + points={{-78,-24},{68,-24}}), + Text( + extent={{-140,152},{160,112}}, + textString="%name", + textColor={0,0,255}), + Text( + extent={{-42,-63},{41,-106}}, + textColor={192,192,192}, + textString="%delta s"), + Text( + extent={{226,60},{106,10}}, + textColor={0,0,0}, + textString=DynamicSelect("",String(y, + leftJustified=false, + significantDigits=3)))}), + Documentation( + info=" +

+This block outputs the mean value of its input signal as +

+
+      1  t
+y =   -  ∫   u(s) ds
+      δ  t-δ
+
+

+where δ is a parameter that determines the time window over +which the input is averaged. +For + t < δ seconds, it outputs +

+
+           1      t
+y =   --------    ∫   u(s) ds
+      t-t0+10-10   t0
+
+

+where t0 is the initial time. +

+

+This block can for example be used to output the moving +average of a noisy measurement signal. +

+

+See + +Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage +and + +Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage_nonZeroStart +for example. +

+", +revisions=" + +")); +end MovingAverage; + + equation connect(sumHeaCoo.y,preHeaCoo. Q_flow) annotation (Line(points={{62.4,60},{68,60}}, color={0,0,127})); diff --git a/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600FF.mo b/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600FF.mo index bd283754fd..11e7e4d564 100644 --- a/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600FF.mo +++ b/IBPSA/ThermalZones/ISO13790/Validation/BESTEST/Cases6xx/Case600FF.mo @@ -32,14 +32,203 @@ model Case600FF annotation (Placement(transformation(extent={{-80,10},{-60,30}}))); Modelica.Blocks.Sources.Constant intGai(k=200) "Internal heat gains" annotation (Placement(transformation(extent={{-80,-20},{-60,0}}))); - IBPSA.Utilities.Math.MovingAverage TRooHou(delta=3600) + MovingAverage TRooHou(delta=3600) "Continuous mean of room air temperature" annotation (Placement(transformation(extent={{60,-2},{80,18}}))); - IBPSA.Utilities.Math.MovingAverage TRooAnn(delta=86400*365) + MovingAverage TRooAnn(delta=86400*365) "Continuous mean of room air temperature" annotation (Placement(transformation(extent={{60,40},{80,60}}))); Modelica.Blocks.Sources.Constant latGai(k=0) "Internal heat gains" annotation (Placement(transformation(extent={{-80,-60},{-60,-40}}))); +protected + +block MovingAverage "Block to output moving average" + parameter Real delta( + final quantity="Time", + final unit="s", + min=1E-5) + "Time horizon over which the input is averaged"; + Modelica.Blocks.Interfaces.RealInput u + "Connector of Real input signal" + annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); + Modelica.Blocks.Interfaces.RealOutput y + "Connector of Real output signal" + annotation (Placement(transformation(extent={{100,-20},{140,20}}))); + + parameter Real tStart( + final quantity="Time", + final unit="s", + fixed=false) + "Start time"; + Real mu + "Internal integrator variable"; + Real muDel + "Internal integrator variable with delay"; + Boolean mode( + start=false, + fixed=true) + "Calculation mode"; + +initial equation + tStart=time; + mu=0; + +equation + u=der(mu); + muDel=delay( + mu, + delta); + // Compute the mode so that Dymola generates + // time and not state events as it would with + // an if-then construct + when time >= tStart+delta then + mode=true; + end when; + if mode then + y=(mu-muDel)/delta; + else + y=(mu-muDel)/(time-tStart+1E-3); + end if; + annotation ( + defaultComponentName="movAve", + Icon( + graphics={ + Rectangle( + extent={{-100,-100},{100,100}}, + lineColor={0,0,127}, + fillColor={255,255,255}, + fillPattern=FillPattern.Solid), + Polygon( + points={{-78,90},{-86,68},{-70,68},{-78,90}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid), + Line( + points={{-78,68},{-78,-80}}, + color={192,192,192}), + Line( + points={{-88,0},{70,0}}, + color={192,192,192}), + Polygon( + points={{92,0},{70,8},{70,-8},{92,0}}, + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid), + Line( + points={{-78,-31},{-64,-31},{-64,-15},{-56,-15},{-56,-63},{-48,-63}, + {-48,-41},{-40,-41},{-40,43},{-32,43},{-32,11},{-32,11},{-32,-49}, + {-22,-49},{-22,-31},{-12,-31},{-12,-59},{-2,-59},{-2,23},{4,23}, + {4,37},{10,37},{10,-19},{20,-19},{20,-7},{26,-7},{26,-37}, + {36,-37},{36,35},{46,35},{46,1},{54,1},{54,-65},{64,-65}}, + color={215,215,215}), + Line( + points={{-78,-24},{68,-24}}), + Text( + extent={{-140,152},{160,112}}, + textString="%name", + textColor={0,0,255}), + Text( + extent={{-42,-63},{41,-106}}, + textColor={192,192,192}, + textString="%delta s"), + Text( + extent={{226,60},{106,10}}, + textColor={0,0,0}, + textString=DynamicSelect("",String(y, + leftJustified=false, + significantDigits=3)))}), + Documentation( + info=" +

+This block outputs the mean value of its input signal as +

+
+      1  t
+y =   -  ∫   u(s) ds
+      δ  t-δ
+
+

+where δ is a parameter that determines the time window over +which the input is averaged. +For + t < δ seconds, it outputs +

+
+           1      t
+y =   --------    ∫   u(s) ds
+      t-t0+10-10   t0
+
+

+where t0 is the initial time. +

+

+This block can for example be used to output the moving +average of a noisy measurement signal. +

+

+See + +Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage +and + +Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage_nonZeroStart +for example. +

+", +revisions=" + +")); +end MovingAverage; + + equation connect(weaDat.weaBus,zonHVAC. weaBus) annotation (Line( points={{-60,20},{10,20},{10,11}}, diff --git a/IBPSA/Utilities/Math/MovingAverage.mo b/IBPSA/Utilities/Math/MovingAverage.mo deleted file mode 100644 index 274e5c7dbf..0000000000 --- a/IBPSA/Utilities/Math/MovingAverage.mo +++ /dev/null @@ -1,187 +0,0 @@ -within IBPSA.Utilities.Math; -block MovingAverage "Block to output moving average" - parameter Real delta( - final quantity="Time", - final unit="s", - min=1E-5) - "Time horizon over which the input is averaged"; - Modelica.Blocks.Interfaces.RealInput u - "Connector of Real input signal" - annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); - Modelica.Blocks.Interfaces.RealOutput y - "Connector of Real output signal" - annotation (Placement(transformation(extent={{100,-20},{140,20}}))); - -protected - parameter Real tStart( - final quantity="Time", - final unit="s", - fixed=false) - "Start time"; - Real mu - "Internal integrator variable"; - Real muDel - "Internal integrator variable with delay"; - Boolean mode( - start=false, - fixed=true) - "Calculation mode"; - -initial equation - tStart=time; - mu=0; - -equation - u=der(mu); - muDel=delay( - mu, - delta); - // Compute the mode so that Dymola generates - // time and not state events as it would with - // an if-then construct - when time >= tStart+delta then - mode=true; - end when; - if mode then - y=(mu-muDel)/delta; - else - y=(mu-muDel)/(time-tStart+1E-3); - end if; - annotation ( - defaultComponentName="movAve", - Icon( - graphics={ - Rectangle( - extent={{-100,-100},{100,100}}, - lineColor={0,0,127}, - fillColor={255,255,255}, - fillPattern=FillPattern.Solid), - Polygon( - points={{-78,90},{-86,68},{-70,68},{-78,90}}, - lineColor={192,192,192}, - fillColor={192,192,192}, - fillPattern=FillPattern.Solid), - Line( - points={{-78,68},{-78,-80}}, - color={192,192,192}), - Line( - points={{-88,0},{70,0}}, - color={192,192,192}), - Polygon( - points={{92,0},{70,8},{70,-8},{92,0}}, - lineColor={192,192,192}, - fillColor={192,192,192}, - fillPattern=FillPattern.Solid), - Line( - points={{-78,-31},{-64,-31},{-64,-15},{-56,-15},{-56,-63},{-48,-63}, - {-48,-41},{-40,-41},{-40,43},{-32,43},{-32,11},{-32,11},{-32,-49}, - {-22,-49},{-22,-31},{-12,-31},{-12,-59},{-2,-59},{-2,23},{4,23}, - {4,37},{10,37},{10,-19},{20,-19},{20,-7},{26,-7},{26,-37}, - {36,-37},{36,35},{46,35},{46,1},{54,1},{54,-65},{64,-65}}, - color={215,215,215}), - Line( - points={{-78,-24},{68,-24}}), - Text( - extent={{-140,152},{160,112}}, - textString="%name", - textColor={0,0,255}), - Text( - extent={{-42,-63},{41,-106}}, - textColor={192,192,192}, - textString="%delta s"), - Text( - extent={{226,60},{106,10}}, - textColor={0,0,0}, - textString=DynamicSelect("",String(y, - leftJustified=false, - significantDigits=3)))}), - Documentation( - info=" -

-This block outputs the mean value of its input signal as -

-
-      1  t
-y =   -  ∫   u(s) ds
-      δ  t-δ
-
-

-where δ is a parameter that determines the time window over -which the input is averaged. -For - t < δ seconds, it outputs -

-
-           1      t
-y =   --------    ∫   u(s) ds
-      t-t0+10-10   t0
-
-

-where t0 is the initial time. -

-

-This block can for example be used to output the moving -average of a noisy measurement signal. -

-

-See - -Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage -and - -Buildings.Controls.OBC.CDL.Continuous.Validation.MovingAverage_nonZeroStart -for example. -

-", -revisions=" - -")); -end MovingAverage; diff --git a/IBPSA/Utilities/Math/package.order b/IBPSA/Utilities/Math/package.order index b7e42ec325..72bc222a56 100644 --- a/IBPSA/Utilities/Math/package.order +++ b/IBPSA/Utilities/Math/package.order @@ -16,7 +16,6 @@ Interpolate InverseXRegularized Max Min -MovingAverage Polynomial PowerLinearized QuadraticLinear