This package contains base classes that are used to construct the models in Buildings.BoundaryConditions.WeatherData.
Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).
Name | Description |
---|---|
CheckCeilingHeight | Ensures that the ceiling height is above a lower bound |
CheckPressure | Ensures that the interpolated pressure is between prescribed bounds |
CheckSkyCover | Constrains the sky cover to [0, 1] |
CheckWindDirection | Constrains the wind direction to [0, 2*pi] degree |
CheckWindSpeed | Ensures that the wind speed is non-negative |
ConvertRadiation | Converts the units and ensures that the radiation is not smaller than 0 |
ConvertRelativeHumidity | Converts the relative humidity from percentage to [0, 1] and constrains it to [0, 1] |
ConvertTemperature | Converts the temperature unit from Celsius to Kelvin and checks the validity of data |
EquationOfTime | Equation of time |
LocalCivilTime | Converts the clock time to local civil time. |
ConvertTime | Converts the simulation time to calendar time in scale of 1 year (365 days) |
SolarTime | Solar time |
getHeaderElementTMY3 | Gets an element from the header of a TMY3 weather data file |
getLongitudeTMY3 | Gets the longitude from a TMY3 weather data file |
getTimeZoneTMY3 | Gets the time zone from a TMY3 weather data file |
Examples | Collection of models that illustrate model use and test models |
This component ensures that the ceiling height is at least 0 meters.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | ceiHeiIn | Input ceiling height [m] |
output RealOutput | ceiHeiOut | Ceiling height [m] |
block CheckCeilingHeight "Ensures that the ceiling height is above a lower bound" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput ceiHeiIn(final quantity="Height", final unit= "m") "Input ceiling height"; Modelica.Blocks.Interfaces.RealOutput ceiHeiOut(final quantity="Height", final unit="m") "Ceiling height"; constant Modelica.SIunits.Height ceiHeiMin=0 "Minimum allowed ceiling height"; equation ceiHeiOut = Buildings.Utilities.Math.Functions.smoothMax( ceiHeiIn, ceiHeiMin, 0.1);end CheckCeilingHeight;
This component ensures that the interpolated pressure is between 31,000 Pa and 120,000 Pa.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | PIn | Input pressure [Pa] |
output RealOutput | POut | Atmospheric pressure [Pa] |
block CheckPressure "Ensures that the interpolated pressure is between prescribed bounds" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput PIn(final quantity="Pressure", final unit= "Pa") "Input pressure"; Modelica.Blocks.Interfaces.RealOutput POut(final quantity="Pressure", final unit= "Pa") "Atmospheric pressure"; constant Modelica.SIunits.Pressure PMin=3100 "Minimum allowed pressure"; constant Modelica.SIunits.Pressure PMax=120000 "Maximum allowed pressure"; equation assert(PIn > PMin, "Pressure out of bounds.\n" + " PIn = " + realString(PIn)); assert(PIn < PMax, "Pressure out of bounds.\n" + " PIn = " + realString(PIn)); POut = PIn;end CheckPressure;
This component constrains the interpolated sky cover between 0 and 10.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | nIn | Input sky cover [0, 10] |
output RealOutput | nOut | Sky cover [0, 10] [1] |
block CheckSkyCover "Constrains the sky cover to [0, 1]" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput nIn "Input sky cover [0, 10]"; Modelica.Blocks.Interfaces.RealOutput nOut(unit="1") "Sky cover [0, 10]"; constant Real delta=0.01 "Smoothing parameter"; protected constant Real nMin=delta "Lower bound"; constant Real nMax=10 - delta "Upper bound"; equation nOut = Buildings.Utilities.Math.Functions.smoothLimit( nIn, nMin, nMax, delta/10)/10;end CheckSkyCover;
This component constrains the interpolated wind direction between 0 and 360 degree.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | nIn | Input wind direction [deg] |
output RealOutput | nOut | Wind direction [rad] |
block CheckWindDirection "Constrains the wind direction to [0, 2*pi] degree" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput nIn( final quantity="Angle", final unit="deg", displayUnit="deg") "Input wind direction"; Modelica.Blocks.Interfaces.RealOutput nOut( final quantity="Angle", final unit="rad", displayUnit="deg") "Wind direction"; constant Real delta=0.01 "Smoothing parameter"; protected constant Real nMin=0 "Lower bound"; constant Real nMax=2*Modelica.Constants.pi "Upper bound"; equation nOut = Buildings.Utilities.Math.Functions.smoothLimit( nIn/360*nMax, nMin, nMax, delta/10);end CheckWindDirection;
This component ensures that the wind speed is non-negative.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | winSpeIn | Input wind speed [m/s] |
output RealOutput | winSpeOut | Wind speed [m/s] |
block CheckWindSpeed "Ensures that the wind speed is non-negative" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput winSpeIn(final quantity="Velocity", final unit="m/s") "Input wind speed"; Modelica.Blocks.Interfaces.RealOutput winSpeOut(final quantity="Velocity", final unit="m/s") "Wind speed"; constant Modelica.SIunits.Velocity winSpeMin=1e-6 "Minimum allowed wind speed"; equation // Modelica Table will interpolate data when it reads the weather data file. // It can generate negative values due to the interpolation. winSpeOut = Buildings.Utilities.Math.Functions.smoothMax( x1=winSpeIn, x2=winSpeMin, deltaX=winSpeMin/10);end CheckWindSpeed;
This component ensures that the radiation is not smaller than 0.
It also converts the weather data from Wh/m2
,
which is the unit used in the Typical Meteorological Year weather format,
to W/m2
.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | HIn | Input radiation (Wh/m2) [W.h/m2] |
output RealOutput | HOut | Radiation [W/m2] |
block ConvertRadiation "Converts the units and ensures that the radiation is not smaller than 0" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput HIn(final unit="W.h/m2") "Input radiation (Wh/m2)"; Modelica.Blocks.Interfaces.RealOutput HOut(final quantity= "RadiantEnergyFluenceRate", final unit="W/m2") "Radiation"; constant Modelica.SIunits.HeatFlux HMin=0.0001 "Minimum value for radiation"; equation // Modelica Table will interpolate data when it reads the weather data file. // It can generate negative value due to the interpolation. HOut = Buildings.Utilities.Math.Functions.smoothMax( x1=HIn, x2=HMin, deltaX=HMin/10);end ConvertRadiation;
This component converts the relative humidity from percentage to a range of [0, 1]. Input is the relative humidity in percentage, as this is the data format that is used in the Typical Meteorological Year weather data.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | relHumIn | Input relative humidity data in percentage [1] |
output RealOutput | relHumOut | Relative humidity in (0, 1) [1] |
block ConvertRelativeHumidity "Converts the relative humidity from percentage to [0, 1] and constrains it to [0, 1]" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput relHumIn(unit="1") "Input relative humidity data in percentage"; Modelica.Blocks.Interfaces.RealOutput relHumOut(unit="1") "Relative humidity in (0, 1)"; constant Real delta=0.01 "Smoothing parameter"; protected constant Real relHumMin=delta "Lower bound"; constant Real relHumMax=1 - delta "Upper bound"; equation relHumOut = Buildings.Utilities.Math.Functions.smoothLimit( relHumIn/100, relHumMin, relHumMax, delta/10);end ConvertRelativeHumidity;
This component converts the temperature from Celsius to Kelvin.
If the temperature is outside TMin
and TMax
,
the simulation will stop with an error.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | TemC | Temperature in Celsius [degC] |
output RealOutput | TemK | Temperature in Kelvin [K] |
block ConvertTemperature "Converts the temperature unit from Celsius to Kelvin and checks the validity of data" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput TemC( final quantity="Temperature", final unit="degC", displayUnit="degC") "Temperature in Celsius"; Modelica.Blocks.Interfaces.RealOutput TemK( final quantity="Temperature", final unit="K", displayUnit="degC") "Temperature in Kelvin"; constant Modelica.SIunits.Temperature TMin=273.15 - 70 "Minimum allowed temperature"; constant Modelica.SIunits.Temperature TMax=273.15 + 70 "Maximum allowed temperature"; equation TemK = TemC - Modelica.Constants.T_zero; assert(TemK > TMin, "Temperature out of bounds.\n" + " TemK = " + realString(TemK)); assert(TemK < TMax, "Temperature out of bounds.\n" + " TemK = " + realString(TemK));end ConvertTemperature;
This component computes the difference between solar noon and noon of local civic time.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | nDay | Zero-based day number in seconds (January 1=0, January 2=86400) [s] |
output RealOutput | eqnTim | Equation of time [s] |
block EquationOfTime "Equation of time" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput nDay(quantity="Time", unit="s") "Zero-based day number in seconds (January 1=0, January 2=86400)"; Modelica.Blocks.Interfaces.RealOutput eqnTim( final quantity="Time", final unit="s", displayUnit="min") "Equation of time"; protected Real Bt; equation Bt = Modelica.Constants.pi*((nDay + 86400)/86400 - 81)/182 "Our unit is s instead of day in (A.4.2b)"; eqnTim = 60*(9.87*Modelica.Math.sin(2*Bt) - 7.53*Modelica.Math.cos(Bt) - 1.5* Modelica.Math.sin(Bt)) "Our unit is s instead of min in (A.4.2a)";end EquationOfTime;
This component converts the clock time to local civil time.
The parameter timZon
represents the time zone of the facility (relative to Greenwich Mean Time or the 0th meridian). Time zones west of GMT (e.g. North America) are represented as negative;
east of GMT as positive. Fraction of hours are represented in decimals (e.g. for 6:30, use 6.5).
The formula is based on Michael Wetter's thesis (A4.1):
locTim = greTim + (lon*180/pi)*86400/360 = cloTim - timZon + lon*43200/pi
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Default | Description |
---|---|---|---|
Time | timZon | Time zone [s] | |
Angle | lon | Longitude [rad] |
Type | Name | Description |
---|---|---|
input RealInput | cloTim | Clock time [s] |
output RealOutput | locTim | Local civil time [s] |
block LocalCivilTime "Converts the clock time to local civil time." extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput cloTim(final quantity="Time", final unit= "s") "Clock time"; parameter Modelica.SIunits.Time timZon(displayUnit="h") "Time zone"; parameter Modelica.SIunits.Angle lon(displayUnit="deg") "Longitude";Modelica.Blocks.Interfaces.RealOutput locTim(final quantity="Time", final unit= "s") "Local civil time"; equation locTim = cloTim - timZon + lon*43200/Modelica.Constants.pi;end LocalCivilTime;
This component converts the simulation time to calendar time in a scale of 1 year (365 days).
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | simTim | Simulation time [s] |
output RealOutput | calTim | Calendar time [s] |
block ConvertTime "Converts the simulation time to calendar time in scale of 1 year (365 days)" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput simTim(final quantity="Time", final unit= "s") "Simulation time"; Modelica.Blocks.Interfaces.RealOutput calTim(final quantity="Time", final unit= "s") "Calendar time"; equation calTim = simTim - integer(simTim/31536000)*31536000;end ConvertTime;
This component computes the local solar time.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | locTim | Local time [s] |
input RealInput | equTim | Equation of time [s] |
output RealOutput | solTim | Solar time [s] |
block SolarTime "Solar time" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput locTim(quantity="Time", unit="s") "Local time"; Modelica.Blocks.Interfaces.RealInput equTim(quantity="Time", unit="s") "Equation of time"; Modelica.Blocks.Interfaces.RealOutput solTim( final quantity="Time", final unit="s", displayUnit="s") "Solar time"; algorithm solTim := locTim + equTim "Our unit is s in stead of h in (A.4.3)";end SolarTime;
startwhere
start
is a parameter.
When this line is found, the function returns the element at the position number
position
, where position
is a parameter.
A comma is used as the delimiter of the elements.
Type | Name | Default | Description |
---|---|---|---|
String | filNam | Name of weather data file | |
String | start | Start of the string that contains the elements | |
String | name | "longitude" | Name of data element, used in error reporting |
Integer | position | Position of the element on the line that contains 'start' |
Type | Name | Description |
---|---|---|
String | element | Element at position 'pos' of the line that starts with 'start' |
function getHeaderElementTMY3 "Gets an element from the header of a TMY3 weather data file" input String filNam "Name of weather data file"; input String start "Start of the string that contains the elements"; input String name = "longitude" "Name of data element, used in error reporting"; input Integer position(min=1) "Position of the element on the line that contains 'start'"; output String element "Element at position 'pos' of the line that starts with 'start'"; protected String lin "Line that is used in parser"; Integer iLin "Line number"; Integer index "Index of string #LOCATION"; Integer staInd "Start index used when parsing a real number"; Integer nexInd "Next index used when parsing a real number"; Boolean found "Flag, true if #LOCATION has been found"; Boolean EOF "Flag, true if EOF has been reached"; String fouDel "Found delimiter"; algorithm // Get line that starts with 'start' iLin :=0; EOF :=false; while (not EOF) and (index == 0) loop iLin:=iLin + 1; (lin, EOF) :=Modelica.Utilities.Streams.readLine(fileName=filNam, lineNumber=iLin); index :=Modelica.Utilities.Strings.find( string=lin, searchString=start, startIndex=1, caseSensitive=false); end while; assert(not EOF, "Error: Did not find '" + start + "' when scanning the weather file." + "\n Check for correct weather file syntax."); // Loop over the tokens until the position is reached nexInd :=1; for i in 1:position-1 loop nexInd :=Modelica.Utilities.Strings.find( string=lin, searchString= ",", startIndex=nexInd+1); assert(nexInd > 0, "Error when scanning weather file. Not enough tokens to find " + name + "." + "\n Check for correct file syntax." + "\n The scanned line is '" + lin + "'."); end for; staInd := nexInd; // Find the next delimiter nexInd :=Modelica.Utilities.Strings.find( string=lin, searchString= ",", startIndex=nexInd+1); assert(nexInd > 0, "Error when scanning weather file. Not enough tokens to find " + name + "." + "\n Check for correct file syntax." + "\n The scanned line is '" + lin + "'."); // Get the element element :=Modelica.Utilities.Strings.substring(lin, startIndex=staInd+1, endIndex=nexInd-1);end getHeaderElementTMY3;
Type | Name | Default | Description |
---|---|---|---|
String | filNam | Name of weather data file |
Type | Name | Description |
---|---|---|
Angle | lon | Longitude from the weather file [rad] |
function getLongitudeTMY3 "Gets the longitude from a TMY3 weather data file" input String filNam "Name of weather data file"; output Modelica.SIunits.Angle lon "Longitude from the weather file"; protected Integer nexInd "Next index, used for error handling"; String element "String representation of the returned element"; algorithm element := Buildings.BoundaryConditions.WeatherData.BaseClasses.getHeaderElementTMY3( filNam=filNam, start="#LOCATION", name= "longitude", position=8); (nexInd, lon) :=Modelica.Utilities.Strings.Advanced.scanReal( string=element, startIndex=1, unsigned=false); assert(nexInd > 1, "Error when converting the longitude '" + element + "' from a String to a Real."); // Convert from degree to rad lon :=lon*Modelica.Constants.pi/180; // Check if longitude is valid assert(abs(lon) < 2*Modelica.Constants.pi, "Wrong value for longitude. Received lon = " + realString(lon) + " (= " + realString(lon*180/Modelica.Constants.pi) + " degrees).");end getLongitudeTMY3;
Type | Name | Default | Description |
---|---|---|---|
String | filNam | Name of weather data file |
Type | Name | Description |
---|---|---|
Time | timZon | Time zone from the weather file [s] |
function getTimeZoneTMY3 "Gets the time zone from a TMY3 weather data file" input String filNam "Name of weather data file"; output Modelica.SIunits.Time timZon "Time zone from the weather file"; protected Integer nexInd "Next index, used for error handling"; String element "String representation of the returned element"; algorithm element := Buildings.BoundaryConditions.WeatherData.BaseClasses.getHeaderElementTMY3( filNam=filNam, start="#LOCATION", name= "longitude", position=9); (nexInd, timZon) :=Modelica.Utilities.Strings.Advanced.scanReal( string=element, startIndex=1, unsigned=false); assert(nexInd > 1, "Error when converting the time zone '" + element + "' from a String to a Real."); timZon :=timZon*3600; // Check if time zone is valid assert(abs(timZon) < 24*3600, "Wrong value for time zone. Received timZon = " + realString(timZon) + " (= " + realString(timZon/3600) + " hours).");end getTimeZoneTMY3;