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
Anglelatlat(displayUnit="deg")Latitude [rad]
Anglelonlon(displayUnit="deg")Longitude [rad]
TimetimZontimZon(displayUnit="h")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 Modelica.SIunits.Angle lat(displayUnit="deg") "Latitude"; parameter Modelica.SIunits.Angle lon(displayUnit="deg") "Longitude"; parameter Modelica.SIunits.Time timZon(displayUnit="h") "Time zone"; Interfaces.RealOutput nextSunRise( final quantity="Time", final unit="s", displayUnit="h") "Time of next sunrise"; Interfaces.RealOutput nextSunSet( final quantity="Time", final unit="s", displayUnit="h") "Time of next sunset"; 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 Modelica.SIunits.Time staTim(fixed=false) "Simulation start time"; Modelica.SIunits.Time eqnTim "Equation of time"; Modelica.SIunits.Time timDif "Time difference between local and civil time"; Modelica.SIunits.Time timCor "Time correction"; Modelica.SIunits.Angle decAng "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 Modelica.SIunits.Time t "Current simulation time"; input Modelica.SIunits.Angle lat "Latitude"; output Modelica.SIunits.Angle houAng "Solar hour angle"; output Modelica.SIunits.Time tNext "Timesnap when sun rises or sets next time"; output Modelica.SIunits.Time timCor "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"; Modelica.SIunits.Time eqnTim "Equation of time"; Modelica.SIunits.Time timDif "Time difference"; Modelica.SIunits.Angle decAng "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 + 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 "Output the next sunrise time" input Modelica.SIunits.Time t "Current simulation time"; input Modelica.SIunits.Time staTim "Simulation start time"; input Modelica.SIunits.Angle lat "Latitude"; output Modelica.SIunits.Time nextSunRise; protected Modelica.SIunits.Angle houAng "Solar hour angle"; Modelica.SIunits.Time tNext "Timesnap when sun rises next time"; Modelica.SIunits.Time timCor "Time correction"; Modelica.SIunits.Time sunRise "Sunrise of the same day as input time"; Real cosHou "Cosine of hour angle"; algorithm (houAng,tNext,timCor) := nextHourAngle(t, lat); sunRise :=(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 > sunRise then nextSunRise := sunRise + 86400; else nextSunRise := sunRise; end if; end sunRise; function sunSet "Output the next sunset time" input Modelica.SIunits.Time t "Current simulation time"; input Modelica.SIunits.Time staTim "Simulation start time"; input Modelica.SIunits.Angle lat "Latitude"; output Modelica.SIunits.Time nextSunSet; protected Modelica.SIunits.Angle houAng "Solar hour angle"; Modelica.SIunits.Time tNext "Timesnap when sun sets next time"; Modelica.SIunits.Time timCor "Time correction"; Modelica.SIunits.Time sunSet "Sunset of the same day as input time"; Real cosHou "Cosine of hour angle"; algorithm (houAng,tNext,timCor) := nextHourAngle(t, 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 sunSet; initial equation staTim = time; nextSunRise = sunRise(time-86400,staTim,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 = 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 passes the current sunrise/sunset, output the next sunrise/sunset 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;