This package contains utility models
that are used throughout the library.
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 |
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.
block SunRiseSet
parameter Real lat(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
parameter Real lon(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
parameter Real timZon(
final quantity="Time",
final unit="s",
displayUnit="h")
;
Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunRise(
final quantity="Time",
final unit="s",
displayUnit="h")
;
Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunSet(
final quantity="Time",
final unit="s",
displayUnit="h")
;
Buildings.Controls.OBC.CDL.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 Real staTim(
final quantity="Time",
final unit="s",
fixed=false)
;
parameter Real timDifLocCiv(
final quantity="Time",
final unit="s",
fixed=false)
;
Real eqnTim(
final quantity="Time",
final unit="s")
;
Real timCor(
final quantity="Time",
final unit="s")
;
Real decAng(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
Real Bt
;
Real cosHou
;
function nextHourAngle
input Real t(
final quantity="Time",
final unit="s")
;
input Real timDifLocCiv(
final quantity="Time",
final unit="s")
;
input Real lat(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
output Real houAng(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
output Real tNext(
final quantity="Time",
final unit="s")
;
output Real timCor(
final quantity="Time",
final unit="s")
;
protected
Integer iDay;
Boolean compute
;
Real Bt
;
Real eqnTim(
final quantity="Time",
final unit="s")
;
Real decAng(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
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+timDifLocCiv;
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 computeSunRise
input Real t(
final quantity="Time",
final unit="s")
;
input Real staTim(
final quantity="Time",
final unit="s")
;
input Real timDifLocCiv(
final quantity="Time",
final unit="s")
;
input Real lat(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
output Real nextSunRise(
final quantity="Time",
final unit="s");
protected
Real houAng(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
Real tNext(
final quantity="Time",
final unit="s")
;
Real timCor(
final quantity="Time",
final unit="s")
;
Real sunRis(
final quantity="Time",
final unit="s")
;
Real cosHou(
final quantity="Time",
final unit="s")
;
algorithm
(houAng,tNext,timCor) :=
nextHourAngle(
t=t,
timDifLocCiv=timDifLocCiv,
lat=lat);
sunRis :=(12-houAng*24/(2*Modelica.Constants.pi)-timCor/3600)*3600+
floor(
tNext/86400)*86400;
if staTim > sunRis
then
nextSunRise := sunRis+86400;
else
nextSunRise := sunRis;
end if;
end computeSunRise;
function computeSunSet
input Real t(
final quantity="Time",
final unit="s")
;
input Real staTim(
final quantity="Time",
final unit="s")
;
input Real timDifLocCiv(
final quantity="Time",
final unit="s")
;
input Real lat(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
output Real nextSunSet(
final quantity="Time",
final unit="s");
protected
Real houAng(
final quantity="Angle",
final unit="rad",
displayUnit="deg")
;
Real tNext(
final quantity="Time",
final unit="s")
;
Real timCor(
final quantity="Time",
final unit="s")
;
Real sunSet(
final quantity="Time",
final unit="s")
;
Real cosHou(
final quantity="Time",
final unit="s")
;
algorithm
(houAng,tNext,timCor) :=
nextHourAngle(
t=t,
timDifLocCiv=timDifLocCiv,
lat=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 computeSunSet;
initial equation
staTim=time;
timDifLocCiv=lon*43200/Modelica.Constants.pi-timZon;
nextSunRise=
computeSunRise(
t=time-86400,
staTim=staTim,
timDifLocCiv=timDifLocCiv,
lat=lat);
if cosHou <-1
then
nextSunSet=
computeSunSet(
t=time-86400,
staTim=staTim,
timDifLocCiv=timDifLocCiv,
lat=lat)-86400;
else
nextSunSet=
computeSunSet(
t=time-86400,
staTim=staTim,
timDifLocCiv=timDifLocCiv,
lat=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));
timCor=eqnTim+timDifLocCiv;
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=
computeSunRise(
t=time,
staTim=staTim,
timDifLocCiv=timDifLocCiv,
lat=lat);
end when;
when time >=
pre(nextSunSet)
then
nextSunSet=
computeSunSet(
t=time,
staTim=staTim,
timDifLocCiv=timDifLocCiv,
lat=lat);
end when;
sunUp=nextSunSet < nextSunRise;
end SunRiseSet;