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 |
CheckRadiation | Ensure that the radiation is not smaller than 0 |
CheckRelativeHumidity | Check the validity of relative humidity |
CheckPressure | Ensures that the interpolated pressure is between prescribed bounds |
CheckSkyCover | Constrains the sky cover to [0, 1] |
CheckTemperature | Check the validity of temperature data |
CheckWindDirection | Constrains the wind direction to [0, 2*pi] degree |
CheckWindSpeed | Ensures that the wind speed is non-negative |
ConvertRadiation | Convert the unit of solar radiation received from the TMY3 data file |
ConvertRelativeHumidity | Convert the relative humidity from percentage to real |
ConvertTime | Converts the simulation time to calendar time in scale of 1 year (365 days) |
EquationOfTime | Equation of time |
LocalCivilTime | Converts the clock time to local civil time. |
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 radiation is not smaller than 0. Modelica Table will interpolate data when it reads the data from a file. Thus, it is possible to generate negative value due to the interpolation.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | HIn | Input radiation [W/m2] |
output RealOutput | HOut | Radiation [W/m2] |
block CheckRadiation "Ensure that the radiation is not smaller than 0" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput HIn(final quantity= "RadiantEnergyFluenceRate", final unit="W/m2") "Input radiation"; Modelica.Blocks.Interfaces.RealOutput HOut(final quantity= "RadiantEnergyFluenceRate", final unit="W/m2") "Radiation"; constant Modelica.SIunits.RadiantEnergyFluenceRate HMin=0.0001 "Minimum value for radiation"; equation HOut = Buildings.Utilities.Math.Functions.smoothMax( x1=HIn, x2=HMin, deltaX=HMin/10);end CheckRadiation;
This component constrains the value of relative humidity to a range of [0, 1].
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | relHumIn | Input relative humidity [1] |
output RealOutput | relHumOut | Relative humidity [1] |
block CheckRelativeHumidity "Check the validity of relative humidity" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput relHumIn(final unit="1") "Input relative humidity"; Modelica.Blocks.Interfaces.RealOutput relHumOut(final unit="1") "Relative humidity"; 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, relHumMin, relHumMax, delta/10);end CheckRelativeHumidity;
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 = " + String(PIn)); assert(PIn < PMax, "Pressure out of bounds.\n" + " PIn = " + String(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 checks the value of temperature.
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 | Default | Description |
---|---|---|---|
Temperature | TMin | 203.15 | Minimum allowed temperature [K] |
Temperature | TMax | 343.15 | Maximum allowed temperature [K] |
Type | Name | Description |
---|---|---|
input RealInput | TIn | Input Temperature [K] |
output RealOutput | TOut | Output temperature [K] |
block CheckTemperature "Check the validity of temperature data" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput TIn( final quantity="Temperature", final unit="K", displayUnit="degC") "Input Temperature"; Modelica.Blocks.Interfaces.RealOutput TOut( final quantity="Temperature", final unit="K", displayUnit="degC") "Output temperature"; parameter Modelica.SIunits.Temperature TMin(displayUnit="degC") = 203.15 "Minimum allowed temperature"; parameter Modelica.SIunits.Temperature TMax(displayUnit="degC") = 343.15 "Maximum allowed temperature"; equation TOut = TIn; assert(TOut > TMin, "Temperature out of bounds.\n" + " TOut = " + String( TOut)); assert(TOut < TMax, "Temperature out of bounds.\n" + " TOut = " + String( TOut));end CheckTemperature;
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 [rad] |
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="rad", 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, 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;
The TMY3 data for solar radiation is the radiation accumulated in one hour. Thus, it used a unit of Wh/m2
.
This component converts Wh/m2
to W/m2
that is the standard unit in Modelica.
Extends from Modelica.Blocks.Interfaces.BlockIcon (Basic graphical layout of input/output block).
Type | Name | Description |
---|---|---|
input RealInput | HIn | Input radiation [W.h/m2] |
output RealOutput | HOut | Radiation [W/m2] |
block ConvertRadiation "Convert the unit of solar radiation received from the TMY3 data file" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput HIn(final unit="W.h/m2") "Input radiation"; Modelica.Blocks.Interfaces.RealOutput HOut(final quantity= "RadiantEnergyFluenceRate", final unit="W/m2") "Radiation"; protected constant Modelica.SIunits.Time Hou=3600 "1 hour"; equation HOut = HIn/Modelica.SIunits.Conversions.to_hour(Hou);end ConvertRadiation;
This component converts the relative humidity from percentage to real. 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 | Value of relative humidity in percentage [1] |
output RealOutput | relHumOut | Relative humidity between 0 and 1 [1] |
block ConvertRelativeHumidity "Convert the relative humidity from percentage to real" extends Modelica.Blocks.Interfaces.BlockIcon;public Modelica.Blocks.Interfaces.RealInput relHumIn(unit="1") "Value of relative humidity in percentage"; Modelica.Blocks.Interfaces.RealOutput relHumOut(unit="1") "Relative humidity between 0 and 1"; equation relHumOut = relHumIn/100;end ConvertRelativeHumidity;
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"; protected constant Modelica.SIunits.Time year=31536000 "Number of seconds in a year"; discrete Modelica.SIunits.Time tStart "Start time of period"; //Integer count "Period count"; initial algorithm tStart := integer(simTim/year)*year; equation when simTim - pre(tStart) > year then tStart = integer(simTim/year)*year; end when; calTim = simTim - tStart;end ConvertTime;
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 computes the local solar time. (Note: To avoid events, it does not convert solar time in a scale of 24 hours.)
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 = " + String(lon) + " (= " + String(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 = " + String(timZon) + " (= " + String(timZon/3600) + " hours).");end getTimeZoneTMY3;