Package with utility functions
Information
This package contains utility models
that are used throughout the library.
Package Content
Name |
Description |
Assert
|
Print a warning message when input becomes false |
SunRiseSet
|
Next sunrise and sunset time |
Validation
|
Collection of models that validate the utilities blocks of the CDL |
Print a warning message when input becomes false
Information
Block that writes a warning if the input becomes false
.
Tools or control systems are expected to write message
together
with a time stamp to an output device and/or a log file.
Parameters
Type | Name | Default | Description |
String | message | | Message written when u becomes false |
Connectors
Type | Name | Description |
input BooleanInput | u | Boolean input that triggers assert when it becomes false |
Modelica definition
Next sunrise and sunset time
Information
This block outputs the next sunrise and sunset time.
The sunrise time keeps constant until the model time reaches the next sunrise,
at which time the output gets updated.
Similarly, the output for the next sunset is updated at each sunset.
The time zone parameter is based on UTC time; for instance, Eastern Standard Time is -5h.
Note that daylight savings time is not considered in this component.
Validation
A validation can be found at
Buildings.Controls.OBC.CDL.Utilities.Validation.SunRiseSet.
Parameters
Type | Name | Default | Description |
Angle | lat | lat(displayUnit="deg") | Latitude [rad] |
Angle | lon | lon(displayUnit="deg") | Longitude [rad] |
Time | timZon | timZon(displayUnit="h") | Time zone [s] |
Connectors
Type | Name | Description |
output RealOutput | nextSunRise | Time of next sunrise [s] |
output RealOutput | nextSunSet | Time of next sunset [s] |
output BooleanOutput | sunUp | Output true if the sun is up |
Modelica definition
block SunRiseSet
parameter Modelica.SIunits.Angle lat(displayUnit="deg") ;
parameter Modelica.SIunits.Angle lon(displayUnit="deg") ;
parameter Modelica.SIunits.Time timZon(displayUnit="h") ;
Interfaces.RealOutput nextSunRise(
final quantity="Time",
final unit="s",
displayUnit="h") ;
Interfaces.RealOutput nextSunSet(
final quantity="Time",
final unit="s",
displayUnit="h") ;
Interfaces.BooleanOutput sunUp ;
protected
constant Real k1 =
sin(23.45*2*Modelica.Constants.pi/360) ;
constant Real k2 = 2*Modelica.Constants.pi/365.25 ;
parameter Modelica.SIunits.Time staTim(fixed=false) ;
Modelica.SIunits.Time eqnTim ;
Modelica.SIunits.Time timDif ;
Modelica.SIunits.Time timCor ;
Modelica.SIunits.Angle decAng ;
Real Bt ;
Real cosHou ;
function nextHourAngle
input Modelica.SIunits.Time t ;
input Modelica.SIunits.Angle lat ;
output Modelica.SIunits.Angle houAng ;
output Modelica.SIunits.Time tNext ;
output Modelica.SIunits.Time timCor ;
protected
Integer iDay;
Boolean compute ;
Real Bt ;
Modelica.SIunits.Time eqnTim ;
Modelica.SIunits.Time timDif ;
Modelica.SIunits.Angle decAng ;
Real cosHou ;
algorithm
iDay := 1;
compute := true;
while compute
loop
tNext := t+iDay*86400;
Bt := Modelica.Constants.pi*((tNext + 86400)/86400 - 81)/182;
eqnTim := 60*(9.87*
Modelica.Math.sin(2*Bt) - 7.53*
Modelica.Math.cos(Bt) -
1.5*
Modelica.Math.sin(Bt));
timCor := eqnTim + timDif;
decAng :=
Modelica.Math.asin(-k1*
Modelica.Math.cos((tNext/86400 + 10)*k2));
cosHou := -
Modelica.Math.tan(lat)*
Modelica.Math.tan(decAng);
compute :=
abs(cosHou) > 1;
iDay := iDay + 1;
end while;
houAng :=
Modelica.Math.acos(cosHou);
end nextHourAngle;
function sunRise
input Modelica.SIunits.Time t ;
input Modelica.SIunits.Time staTim ;
input Modelica.SIunits.Angle lat ;
output Modelica.SIunits.Time nextSunRise;
protected
Modelica.SIunits.Angle houAng ;
Modelica.SIunits.Time tNext ;
Modelica.SIunits.Time timCor ;
Modelica.SIunits.Time sunRise ;
Real cosHou ;
algorithm
(houAng,tNext,timCor) :=
nextHourAngle(t, lat);
sunRise :=(12 - houAng*24/(2*Modelica.Constants.pi) - timCor/3600)*3600 +
floor(tNext/86400)*86400;
if staTim > sunRise
then
nextSunRise := sunRise + 86400;
else
nextSunRise := sunRise;
end if;
end sunRise;
function sunSet
input Modelica.SIunits.Time t ;
input Modelica.SIunits.Time staTim ;
input Modelica.SIunits.Angle lat ;
output Modelica.SIunits.Time nextSunSet;
protected
Modelica.SIunits.Angle houAng ;
Modelica.SIunits.Time tNext ;
Modelica.SIunits.Time timCor ;
Modelica.SIunits.Time sunSet ;
Real cosHou ;
algorithm
(houAng,tNext,timCor) :=
nextHourAngle(t, lat);
sunSet :=(12 + houAng*24/(2*Modelica.Constants.pi) - timCor/3600)*3600 +
floor(tNext/86400)*86400;
if staTim > sunSet
then
nextSunSet := sunSet + 86400;
else
nextSunSet := sunSet;
end if;
end sunSet;
initial equation
staTim = time;
nextSunRise =
sunRise(time-86400,staTim,lat);
if cosHou < -1
then
nextSunSet =
sunSet(time-86400,staTim,lat) - 86400;
else
nextSunSet =
sunSet(time-86400,staTim,lat);
end if;
equation
Bt = Modelica.Constants.pi*((time + 86400)/86400 - 81)/182;
eqnTim = 60*(9.87*
Modelica.Math.sin(2*Bt) - 7.53*
Modelica.Math.cos(Bt) - 1.5*
Modelica.Math.sin(Bt));
timDif = lon*43200/Modelica.Constants.pi - timZon;
timCor = eqnTim + timDif;
decAng =
Modelica.Math.asin(-k1*
Modelica.Math.cos((time/86400 + 10)*k2));
cosHou = -
Modelica.Math.tan(lat)*
Modelica.Math.tan(decAng);
when time >=
pre(nextSunRise)
then
nextSunRise =
sunRise(time,staTim,lat);
end when;
when time >=
pre(nextSunSet)
then
nextSunSet =
sunSet(time,staTim,lat);
end when;
sunUp = nextSunSet < nextSunRise;
end SunRiseSet;