Buildings.Controls.OBC.CDL.Utilities

Package with utility functions

Information

This package contains utility models that are used throughout the library.

Package Content

Name Description
Buildings.Controls.OBC.CDL.Utilities.Assert Assert Print a warning message when input becomes false
Buildings.Controls.OBC.CDL.Utilities.SunRiseSet SunRiseSet Next sunrise and sunset time
Buildings.Controls.OBC.CDL.Utilities.Validation Validation Collection of models that validate the utilities blocks of the CDL

Buildings.Controls.OBC.CDL.Utilities.Assert Buildings.Controls.OBC.CDL.Utilities.Assert

Print a warning message when input becomes false

Buildings.Controls.OBC.CDL.Utilities.Assert

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

TypeNameDefaultDescription
Stringmessage Message written when u becomes false

Connectors

TypeNameDescription
input BooleanInputuBoolean input that triggers assert when it becomes false

Modelica definition

block Assert "Print a warning message when input becomes false" parameter String message "Message written when u becomes false"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Boolean input that triggers assert when it becomes false"; equation assert( u, message, AssertionLevel.warning); end Assert;

Buildings.Controls.OBC.CDL.Utilities.SunRiseSet Buildings.Controls.OBC.CDL.Utilities.SunRiseSet

Next sunrise and sunset time

Buildings.Controls.OBC.CDL.Utilities.SunRiseSet

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

TypeNameDefaultDescription
Reallat Latitude [rad]
Reallon Longitude [rad]
RealtimZon Time zone [s]

Connectors

TypeNameDescription
output RealOutputnextSunRiseTime of next sunrise [s]
output RealOutputnextSunSetTime of next sunset [s]
output BooleanOutputsunUpOutput true if the sun is up

Modelica definition

block SunRiseSet "Next sunrise and sunset time" parameter Real lat( final quantity="Angle", final unit="rad", displayUnit="deg") "Latitude"; parameter Real lon( final quantity="Angle", final unit="rad", displayUnit="deg") "Longitude"; parameter Real timZon( final quantity="Time", final unit="s", displayUnit="h") "Time zone"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunRise( final quantity="Time", final unit="s", displayUnit="h") "Time of next sunrise"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunSet( final quantity="Time", final unit="s", displayUnit="h") "Time of next sunset"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput sunUp "Output true if the sun is up"; protected constant Real k1=sin( 23.45*2*Modelica.Constants.pi/360) "Intermediate constant"; constant Real k2=2*Modelica.Constants.pi/365.25 "Intermediate constant"; parameter Real staTim( final quantity="Time", final unit="s", fixed=false) "Simulation start time"; parameter Real timDifLocCiv( final quantity="Time", final unit="s", fixed=false) "Time difference between local and civil time"; Real eqnTim( final quantity="Time", final unit="s") "Equation of time"; Real timCor( final quantity="Time", final unit="s") "Time correction"; Real decAng( final quantity="Angle", final unit="rad", displayUnit="deg") "Declination angle"; Real Bt "Intermediate variable to calculate equation of time"; Real cosHou "Cosine of hour angle"; function nextHourAngle "Calculate the hour angle when the sun rises or sets next time" input Real t( final quantity="Time", final unit="s") "Current simulation time"; input Real timDifLocCiv( final quantity="Time", final unit="s") "Time difference between local and civil time"; input Real lat( final quantity="Angle", final unit="rad", displayUnit="deg") "Latitude"; output Real houAng( final quantity="Angle", final unit="rad", displayUnit="deg") "Solar hour angle"; output Real tNext( final quantity="Time", final unit="s") "Timesnap when sun rises or sets next time"; output Real timCor( final quantity="Time", final unit="s") "Time correction"; protected Integer iDay; Boolean compute "Flag, set to false when the sun rise or sets "; Real Bt "Intermediate variable to calculate equation of time"; Real eqnTim( final quantity="Time", final unit="s") "Equation of time"; Real decAng( final quantity="Angle", final unit="rad", displayUnit="deg") "Declination angle"; Real cosHou "Cosine of hour angle"; 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 "Output the next sunrise time" input Real t( final quantity="Time", final unit="s") "Current simulation time"; input Real staTim( final quantity="Time", final unit="s") "Simulation start time"; input Real timDifLocCiv( final quantity="Time", final unit="s") "Time difference between local and civil time"; input Real lat( final quantity="Angle", final unit="rad", displayUnit="deg") "Latitude"; output Real nextSunRise( final quantity="Time", final unit="s"); protected Real houAng( final quantity="Angle", final unit="rad", displayUnit="deg") "Solar hour angle"; Real tNext( final quantity="Time", final unit="s") "Timesnap when sun rises next time"; Real timCor( final quantity="Time", final unit="s") "Time correction"; Real sunRis( final quantity="Time", final unit="s") "Sunrise of the same day as input time"; Real cosHou( final quantity="Time", final unit="s") "Cosine of hour angle"; 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 simulation start time has passed the sunrise of the initial day, output //the sunrise of the next day. if staTim > sunRis then nextSunRise := sunRis+86400; else nextSunRise := sunRis; end if; end computeSunRise; function computeSunSet "Output the next sunset time" input Real t( final quantity="Time", final unit="s") "Current simulation time"; input Real staTim( final quantity="Time", final unit="s") "Simulation start time"; input Real timDifLocCiv( final quantity="Time", final unit="s") "Time difference between local and civil time"; input Real lat( final quantity="Angle", final unit="rad", displayUnit="deg") "Latitude"; output Real nextSunSet( final quantity="Time", final unit="s"); protected Real houAng( final quantity="Angle", final unit="rad", displayUnit="deg") "Solar hour angle"; Real tNext( final quantity="Time", final unit="s") "Timesnap when sun sets next time"; Real timCor( final quantity="Time", final unit="s") "Time correction"; Real sunSet( final quantity="Time", final unit="s") "Sunset of the same day as input time"; Real cosHou( final quantity="Time", final unit="s") "Cosine of hour angle"; 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 simulation start time has passed the sunset of the initial day, output //the sunset of the next day. 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); //In the polar cases where the sun is up during initialization, the next sunset //actually occurs before the next sunrise 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 passes the current sunrise/sunset, output the next sunrise/sunset 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;