Package with base classes for Buildings.BoundaryConditions.WeatherData
Information
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).
Package Content
Ensures that the ceiling height is above a lower bound
Information
This component ensures that the ceiling height is at least 0 meters.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | ceiHeiIn | Input ceiling height [m] |
output RealOutput | ceiHeiOut | Ceiling height [m] |
Modelica definition
Ensures that the interpolated pressure is between prescribed bounds
Information
This component ensures that the interpolated pressure is between 31,000 Pa and 120,000 Pa.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | PIn | Input pressure [Pa] |
output RealOutput | POut | Atmospheric pressure [Pa] |
Modelica definition
Ensure that the radiation is not smaller than 0
Information
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.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | HIn | Input radiation [W/m2] |
output RealOutput | HOut | Radiation [W/m2] |
Modelica definition
Check the validity of relative humidity
Information
This component constrains the value of relative humidity to a range of [0, 1].
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | relHumIn | Input relative humidity [1] |
output RealOutput | relHumOut | Relative humidity [1] |
Modelica definition
block CheckRelativeHumidity
"Check the validity of relative humidity"
extends Modelica.Blocks.Icons.Block;
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;
Constrains the sky cover to [0, 1]
Information
This component constrains the interpolated sky cover between 0 and 1.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | nIn | Input sky cover [0, 10] [1] |
output RealOutput | nOut | Sky cover [0, 1] [1] |
Modelica definition
block CheckSkyCover
"Constrains the sky cover to [0, 1]"
extends Modelica.Blocks.Icons.Block;
public
Modelica.Blocks.Interfaces.RealInput nIn(min=0, max=1, unit="1")
"Input sky cover [0, 10]";
Modelica.Blocks.Interfaces.RealOutput nOut(min=0, max=1, unit="1")
"Sky cover [0, 1]";
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);
end CheckSkyCover;
Check the validity of temperature data
Information
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.Icons.Block (Basic graphical layout of input/output block).
Parameters
Type | Name | Default | Description |
Temperature | TMin | 203.15 | Minimum allowed temperature [K] |
Temperature | TMax | 343.15 | Maximum allowed temperature [K] |
Connectors
Type | Name | Description |
input RealInput | TIn | Input Temperature [K] |
output RealOutput | TOut | Output temperature [K] |
Modelica definition
block CheckTemperature
"Check the validity of temperature data"
extends Modelica.Blocks.Icons.Block;
public
Modelica.Blocks.Interfaces.RealInput TIn(
final quantity="ThermodynamicTemperature",
final unit="K",
displayUnit="degC")
"Input Temperature";
Modelica.Blocks.Interfaces.RealOutput TOut(
final quantity="ThermodynamicTemperature",
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;
Constrains the wind direction to [0, 2*pi] degree
Information
This component constrains the interpolated wind direction between 0 and 360 degree.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | nIn | Input wind direction [rad] |
output RealOutput | nOut | Wind direction [rad] |
Modelica definition
block CheckWindDirection
"Constrains the wind direction to [0, 2*pi] degree"
extends Modelica.Blocks.Icons.Block;
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;
Ensures that the wind speed is non-negative
Information
This component ensures that the wind speed is non-negative.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | winSpeIn | Input wind speed [m/s] |
output RealOutput | winSpeOut | Wind speed [m/s] |
Modelica definition
block CheckWindSpeed
"Ensures that the wind speed is non-negative"
extends Modelica.Blocks.Icons.Block;
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;
Convert the unit of solar radiation received from the TMY3 data file
Information
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.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | HIn | Input radiation [W.h/m2] |
output RealOutput | HOut | Radiation [W/m2] |
Modelica definition
Convert the relative humidity from percentage to real
Information
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.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | relHumIn | Value of relative humidity in percentage [1] |
output RealOutput | relHumOut | Relative humidity between 0 and 1 [1] |
Modelica definition
Converts the simulation time to calendar time in scale of 1 year (365 days)
Information
This component converts the simulation time to calendar time in a scale of 1 year (365 days).
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Type | Name | Description |
input RealInput | modTim | Simulation time [s] |
output RealOutput | calTim | Calendar time [s] |
Modelica definition
Equation of time
Information
This component computes the difference between solar noon and noon of local civic time.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
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] |
Modelica definition
block EquationOfTime
"Equation of time"
extends Modelica.Blocks.Icons.Block;
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
"Intermediate variable";
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;
Converts the clock time to local civil time.
Information
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.Icons.Block (Basic graphical layout of input/output block).
Parameters
Type | Name | Default | Description |
Time | timZon | | Time zone [s] |
Angle | lon | | Longitude [rad] |
Connectors
Type | Name | Description |
input RealInput | cloTim | Clock time [s] |
output RealOutput | locTim | Local civil time [s] |
Modelica definition
Solar time
Information
This component computes the local solar time.
Note: To avoid events, this block does not convert solar time to a scale of 24 hours.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Connectors
Modelica definition
Gets the absolute path of a URI
Information
This function returns the absolute path of the uniform resource identifier
by searching for a file with the name
file://uri
modelica://uri
modelica://Buildings/uri
The function returns the absolute path of the first file that is found, using the above search order.
If the file is not found, then this function terminates with an assert
.
This function has been introduced to allow users to specify the name of weather data
files with a path that is relative to the library path.
This allows users to change the current working directory while still being able to read
the files.
Inputs
Type | Name | Default | Description |
String | uri | | A uri |
Outputs
Type | Name | Description |
String | path | The absolute path of the file pointed to by the URI |
Modelica definition
function getAbsolutePath "Gets the absolute path of a URI"
input String uri "A uri";
output String path "The absolute path of the file pointed to by the URI";
protected
function loadResource
input String name "Name of the resource";
output String path
"Full path of the resource, or a string of length 0 if it does not exist";
algorithm
path :=ModelicaServices.ExternalReferences.loadResource(name);
if Modelica.Utilities.Strings.length(path) > 0 then
path := Modelica.Utilities.Files.fullPathName(name=path);
end if;
end loadResource;
algorithm
// If uri does not start with file:// or modelica://, then add file:// to it.
// This is done because a data reader uses as a parameter the file name without file://
if (Modelica.Utilities.Strings.find(uri, "file://", startIndex=1, caseSensitive=false) == 0
and Modelica.Utilities.Strings.find(uri, "modelica://", startIndex=1, caseSensitive=false) == 0) then
// try file://+uri
path := loadResource("file://" + uri);
if not Modelica.Utilities.Files.exist(path) then
// try modelica://+uri
path := loadResource("modelica://" + uri);
if not Modelica.Utilities.Files.exist(path) then
// try modelica://Buildings/+uri
path := loadResource("modelica://Buildings/" + uri);
assert(Modelica.Utilities.Files.exist(path), "File '" + uri + "' does not exist.
Expected to find either 'file://" + uri + "
or 'modelica://" + uri + " +
or 'modelica://Buildings/" + uri);
end if;
end if;
else
path := ModelicaServices.ExternalReferences.loadResource(uri);
path := Modelica.Utilities.Files.fullPathName(name=path);
assert(Modelica.Utilities.Files.exist(path), "File '" + uri + "' does not exist.");
end if;
end getAbsolutePath;
Gets an element from the header of a TMY3 weather data file
Information
This function scans the weather data file for a line that starts with the string
start
where 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.
Inputs
Type | Name | Default | Description |
String | filNam | | Name of weather data file |
String | start | | Start of the string that contains the elements |
String | name | | Name of data element, used in error reporting |
Integer | position | | Position of the element on the line that contains 'start' |
Outputs
Type | Name | Description |
String | element | Element at position 'pos' of the line that starts with 'start' |
Modelica definition
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 "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 = 0 "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=getAbsolutePath(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;
Gets the latitude from a TMY3 weather data file
Information
This function returns the latitude of the TMY3 weather data file.
Inputs
Type | Name | Default | Description |
String | filNam | | Name of weather data file |
Outputs
Type | Name | Description |
Angle | lat | Latitude from the weather file [rad] |
Modelica definition
function getLatitudeTMY3
"Gets the latitude from a TMY3 weather data file"
input String filNam
"Name of weather data file";
output Modelica.SIunits.Angle lat
"Latitude 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=7);
(nexInd, lat) :=
Modelica.Utilities.Strings.Advanced.scanReal(
string=element,
startIndex=1,
unsigned=false);
assert(nexInd > 1, "Error when converting the latitude '" +
element + "' from a String to a Real.");
// Convert from degree to rad
lat :=lat*Modelica.Constants.pi/180;
// Check if latitude is valid
assert(
abs(lat) <= Modelica.Constants.pi+Modelica.Constants.eps,
"Wrong value for latitude. Received lat = " +
String(lat) + " (= " +
String(lat*180/Modelica.Constants.pi) + " degrees).");
end getLatitudeTMY3;
Gets the longitude from a TMY3 weather data file
Information
This function returns the longitude of the TMY3 weather data file.
Inputs
Type | Name | Default | Description |
String | filNam | | Name of weather data file |
Outputs
Type | Name | Description |
Angle | lon | Longitude from the weather file [rad] |
Modelica definition
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;
Gets the time zone from a TMY3 weather data file
Information
This function returns the time zone of the TMY3 weather data file.
Inputs
Type | Name | Default | Description |
String | filNam | | Name of weather data file |
Outputs
Type | Name | Description |
Time | timZon | Time zone from the weather file [s] |
Modelica definition
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;
Automatically generated Mon Jul 13 14:22:25 2015.