Skip to content

Commit

Permalink
Merging IBPSA change simulating over 1Y with Buildings (#3374)
Browse files Browse the repository at this point in the history
* Merging IBPSA change simulating over 1Y with Buildings

* Added equation of time to changes
  • Loading branch information
EttoreZ authored May 20, 2023
1 parent 60727ae commit 62d7b29
Show file tree
Hide file tree
Showing 51 changed files with 365 additions and 360 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Buildings.BoundaryConditions.SolarGeometry.BaseClasses;
block Declination "Declination angle"
extends Modelica.Blocks.Icons.Block;
extends Buildings.BoundaryConditions.WeatherData.BaseClasses.PartialConvertTime;
Modelica.Blocks.Interfaces.RealInput nDay(quantity="Time", unit="s")
"Day number with units of seconds"
annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
Expand All @@ -13,7 +13,8 @@ protected
constant Real k1 = sin(23.45*2*Modelica.Constants.pi/360) "Constant";
constant Real k2 = 2*Modelica.Constants.pi/365.25 "Constant";
equation
decAng = Modelica.Math.asin(-k1 * Modelica.Math.cos((nDay/86400 + 10)*k2))
modTimAux = nDay;
decAng = Modelica.Math.asin(-k1 * Modelica.Math.cos((calTimAux/86400 + 10)*k2))
"(A4.5)";
annotation (
defaultComponentName="decAng",
Expand All @@ -36,6 +37,11 @@ Buildings.BoundaryConditions.SolarGeometry.BaseClasses.Examples.Declination</a>.
</html>", revisions="<html>
<ul>
<li>
March 27, 2023, by Ettore Zanetti:<br/>
Updated to use partial class for conversion from simulation time to calendar time.<br/>
This is for <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1716\">IBPSA #1716</a>.
</li>
<li>
January 6, 2015, by Michael Wetter:<br/>
Updated documentation and added validation.
This is for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ This component computes the sky clearness.
</p>
<h4>Implementation</h4>
<p>
In the <code>Buildings</code> library, <code>HGloHor</code>
In the <code>Buildings</code> library, <code>HDirNor</code>
is always larger than <i>1E-4</i>,
minus some small undershoot due to regularization. Hence,
the implementation is not simplified for
<code>HGloHor &lt; Modelica.Constants.small</code>.
<code>HDirNor &lt; Modelica.Constants.small</code>.
</p>
<p>
The function call
Expand All @@ -68,7 +68,7 @@ is such that the regularization is usually not triggered.
<li>
September 6, 2021, by Ettore Zanetti:<br/>
Changed <code>lat</code> from being a parameter to an input from weather bus.<br/>
Changed input connector <code>HGloHor</code> to <code>HDirHor</code>.<br/>
Changed input connector <code>HGloHor</code> to <code>HDirNor</code>.<br/>
This is for
<a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1477\">IBPSA, #1477</a>.
</li>
Expand Down Expand Up @@ -113,7 +113,7 @@ First implementation.
Text(
extent={{-48,54},{-100,66}},
textColor={0,0,127},
textString="HGloHor"),
textString="HDirNor"),
Text(
extent={{-48,-66},{-100,-54}},
textColor={0,0,127},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
within Buildings.BoundaryConditions.WeatherData.BaseClasses;
block ConvertTime
"Converts the simulation time to calendar time in scale of 1 year (365 days), or a multiple of a year"
extends Modelica.Blocks.Icons.Block;

parameter Modelica.Units.SI.Time weaDatStaTim(displayUnit="d")
"Start time of weather data";
parameter Modelica.Units.SI.Time weaDatEndTim(displayUnit="d")
"End time of weather data";

extends PartialConvertTime;
Modelica.Blocks.Interfaces.RealInput modTim(
final quantity="Time",
final unit="s") "Simulation time"
Expand All @@ -20,23 +14,11 @@ block ConvertTime
protected
constant Modelica.Units.SI.Time shiftSolarRad=1800
"Number of seconds for the shift for solar radiation calculation";
parameter Modelica.Units.SI.Time lenWea=weaDatEndTim - weaDatStaTim
"Length of weather data";

parameter Boolean canRepeatWeatherFile = abs(mod(lenWea, 365*24*3600)) < 1E-2
"=true, if the weather file can be repeated, since it has the length of a year or a multiple of it";

discrete Modelica.Units.SI.Time tNext(start=0, fixed=true)
"Start time of next period";

equation
when {initial(), canRepeatWeatherFile and modTim > pre(tNext)} then
// simulation time stamp went over the end time of the weather file
//(last time stamp of the weather file + average increment)
tNext = if canRepeatWeatherFile then integer(modTim/lenWea)*lenWea + lenWea else time;
end when;
calTim = if canRepeatWeatherFile then modTim - tNext + lenWea else modTim;

calTim = calTimAux;
modTimAux = modTim;
assert(canRepeatWeatherFile or noEvent((time - weaDatEndTim) < shiftSolarRad),
"In " + getInstanceName() + ": Insufficient weather data provided for the desired simulation period.
The simulation time " + String(time) +
Expand All @@ -59,6 +41,11 @@ or a multiple of it, if this is the length of the weather file.
</html>", revisions="<html>
<ul>
<li>
March 27, 2023, by Ettore Zanetti:<br/>
Updated to use partial class for conversion from simulation time to calendar time.<br/>
This is for <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1716\">IBPSA #1716</a>.
</li>
<li>
April 15, 2020, by Michael Wetter:<br/>
Added <code>noEvent</code> to assertion to remove zero crossing function in OPTIMICA.
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Buildings.BoundaryConditions.WeatherData.BaseClasses;
block EquationOfTime "Equation of time"
extends Modelica.Blocks.Icons.Block;
extends PartialConvertTime;
Modelica.Blocks.Interfaces.RealInput nDay(
quantity="Time",
unit="s")
Expand All @@ -14,19 +14,25 @@ block EquationOfTime "Equation of time"
protected
Real Bt "Intermediate variable";
equation
Bt = Modelica.Constants.pi*((nDay + 86400)/86400 - 81)/182
modTimAux = nDay;
Bt = Modelica.Constants.pi*((calTimAux + 86400)/86400 - 81)/182
"Our unit is s instead of day in (A.4.2b)";
eqnTim = 60*(9.87*Modelica.Math.sin(2*Bt) - 7.53*Modelica.Math.cos(Bt) - 1.5*
Modelica.Math.sin(Bt)) "Our unit is s instead of min in (A.4.2a)";
annotation (
defaultComponentName="eqnTim",
Documentation(info="<html>
<p>
This component computes the difference between solar noon and noon of local civic time.
This component computes the difference between solar noon and noon of local civil time.
</p>
</html>", revisions="<html>
<ul>
<li>
March 27, 2023, by Ettore Zanetti:<br/>
Updated to use partial class for conversion from simulation time to calendar time.<br/>
This is for <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1716\">IBPSA #1716</a>.
</li>
<li>
May 13, 2010, by Wangda Zuo:<br/>
First implementation.
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Buildings.BoundaryConditions.WeatherData.BaseClasses;
block LocalCivilTime "Converts the clock time to local civil time."
extends Modelica.Blocks.Icons.Block;
extends PartialConvertTime;
Modelica.Blocks.Interfaces.RealInput cloTim(
final quantity="Time",
final unit="s") "Clock time"
Expand All @@ -15,7 +15,8 @@ protected
final parameter Modelica.Units.SI.Time diff=-timZon + lon*43200/Modelica.Constants.pi
"Difference between local and clock time";
equation
locTim = cloTim + diff;
modTimAux = cloTim;
locTim = calTimAux + diff;

annotation (
defaultComponentName="locTim",
Expand All @@ -34,6 +35,11 @@ The formula is based on Michael Wetter's thesis (A4.1):
</html>", revisions="<html>
<ul>
<li>
March 27, 2023, by Ettore Zanetti:<br/>
Updated to use partial class for conversion from simulation time to calendar time.<br/>
This is for <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1716\">IBPSA #1716</a>.
</li>
<li>
November 14, 2015, by Michael Wetter:<br/>
Introduced <code>diff</code>.
</li>
Expand Down
Loading

0 comments on commit 62d7b29

Please sign in to comment.