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")
;
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 Real staTim(
final quantity="Time",
final unit="s",
fixed=false)
;
Real eqnTim(
final quantity="Time",
final unit="s")
;
Real timDif(
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 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 timDif(
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+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 Real t(
final quantity="Time",
final unit="s")
;
input Real staTim(
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 sunRise(
final quantity="Time",
final unit="s")
;
Real cosHou(
final quantity="Time",
final unit="s")
;
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 Real t(
final quantity="Time",
final unit="s")
;
input Real staTim(
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,
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;