Buildings.Controls.OBC.CDL.Reals.Sources

Package with blocks that generate source signals

Information

Package with blocks that generate signals.

Package Content

Name Description
Buildings.Controls.OBC.CDL.Reals.Sources.CalendarTime CalendarTime Computes the unix time stamp and calendar time from the simulation time
Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime CivilTime Civil time
Buildings.Controls.OBC.CDL.Reals.Sources.Constant Constant Output constant signal of type Real
Buildings.Controls.OBC.CDL.Reals.Sources.Pulse Pulse Generate pulse signal of type Real
Buildings.Controls.OBC.CDL.Reals.Sources.Ramp Ramp Generate ramp signal
Buildings.Controls.OBC.CDL.Reals.Sources.Sin Sin Generate sine signal
Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable TimeTable Table look-up with respect to time and linear or periodic extrapolation
Buildings.Controls.OBC.CDL.Reals.Sources.Validation Validation Collection of models that validate the continuous sources blocks of the CDL

Buildings.Controls.OBC.CDL.Reals.Sources.CalendarTime Buildings.Controls.OBC.CDL.Reals.Sources.CalendarTime

Computes the unix time stamp and calendar time from the simulation time

Buildings.Controls.OBC.CDL.Reals.Sources.CalendarTime

Information

Block that outputs minute, hour, day of the month, month, year and weekday.

Assumption and limitations

The implementation only supports date computations from year 2010 up to and including 2020. Daylight saving and time zones are not supported.

Typical use and important parameters

The user must define which time and date correspond to time = 0 using the model parameters zerTim, and, if zerTim == CDL.Types.ZeroTime.Custom, the parameter yearRef. The user can choose from new year, midnight for a number of years: 2010 to 2020 and also 1970. The latter corresponds to a unix stamp of 0. Note that when choosing the reference time equal to 0 at 1970, the actual simulation time must be within the 2010-2020 range. For example, startTime = 1262304000 corresponds to the simulation starting on the 1st of January 2010 local time when setting zerTim = CDL.Types.ZeroTime.UnixTimeStamp. This is within the 2010-2020 range and is therefore allowed.

Parameters

TypeNameDefaultDescription
ZeroTimezerTim Enumeration for choosing how reference time (time = 0) should be defined
IntegeryearRef2016Year when time = 0, used if zerTim=Custom
Advanced
Realoffset0Offset that is added to 'time', may be used for computing time in different time zone [s]

Connectors

TypeNameDescription
output IntegerOutputyearYear
output IntegerOutputmonthMonth of the year
output IntegerOutputdayDay of the month
output IntegerOutputhourHour of the day
output RealOutputminuteMinute of the hour
output IntegerOutputweekDayInteger output representing week day (monday = 1, sunday = 7)

Modelica definition

model CalendarTime "Computes the unix time stamp and calendar time from the simulation time" parameter Buildings.Controls.OBC.CDL.Types.ZeroTime zerTim "Enumeration for choosing how reference time (time = 0) should be defined"; parameter Integer yearRef( min=firstYear, max=lastYear)=2016 "Year when time = 0, used if zerTim=Custom"; parameter Real offset( final quantity="Time", final unit="s")=0 "Offset that is added to 'time', may be used for computing time in different time zone"; discrete Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput year "Year"; discrete Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput month "Month of the year"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput day( fixed=false) "Day of the month"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput hour( fixed=false) "Hour of the day"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput minute "Minute of the hour"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput weekDay( fixed=false) "Integer output representing week day (monday = 1, sunday = 7)"; protected final constant Integer firstYear=2010 "First year that is supported, i.e. the first year in timeStampsNewYear[:]"; final constant Integer lastYear=firstYear+21 "Last year that is supported (actual building automation system need to support a larger range)"; Buildings.Utilities.Time.CalendarTime calTim( final zerTim=zerTim, final yearRef=yearRef, final offset=offset) "Calendar time"; equation connect(calTim.minute,minute); connect(calTim.hour,hour); connect(calTim.day,day); connect(calTim.month,month); connect(calTim.year,year); connect(calTim.weekDay,weekDay); end CalendarTime;

Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime

Civil time

Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime

Information

Block that outputs the civil time.

Implementation

This block outputs the time of the model. In the case of a building automation system, the building automation system synchronizes time, and hence need to assign a value for the output of this block. Daylight saving time shall not be taken into account, e.g, the block always outputs civil time rather than daylight savings time.

If a simulation starts at t=-1, then this block outputs first t=-1, and its output is advanced at the same rate as the simulation time.

Note that the block has not been included in the ASHRAE Standard 231p. However, in the future versions of the ASHRAE 231 Standard, the block should be added.

Connectors

TypeNameDescription
output RealOutputyCivil time [s]

Modelica definition

block CivilTime "Civil time" Buildings.Controls.OBC.CDL.Interfaces.RealOutput y( final unit="s") "Civil time"; equation y=time; end CivilTime;

Buildings.Controls.OBC.CDL.Reals.Sources.Constant Buildings.Controls.OBC.CDL.Reals.Sources.Constant

Output constant signal of type Real

Buildings.Controls.OBC.CDL.Reals.Sources.Constant

Information

Block that outputs a constant signal y = k, where k is a real-valued parameter.

Constant.png

Parameters

TypeNameDefaultDescription
Realk Constant output value

Connectors

TypeNameDescription
output RealOutputyConnector of Real output signal

Modelica definition

block Constant "Output constant signal of type Real" parameter Real k "Constant output value"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"; equation y=k; end Constant;

Buildings.Controls.OBC.CDL.Reals.Sources.Pulse Buildings.Controls.OBC.CDL.Reals.Sources.Pulse

Generate pulse signal of type Real

Buildings.Controls.OBC.CDL.Reals.Sources.Pulse

Information

Block that outputs a pulse signal as shown below.

Pulse.png

The pulse signal is generated an infinite number of times, and aligned with time=shift.

Parameters

TypeNameDefaultDescription
Realamplitude1.0Amplitude of pulse
Realwidth0.5Width of pulse in fraction of period [1]
Realperiod Time for one period [s]
Realshift0Shift time for output [s]
Realoffset0.0Offset of output signals

Connectors

TypeNameDescription
output RealOutputyConnector of Pulse output signal

Modelica definition

block Pulse "Generate pulse signal of type Real" parameter Real amplitude=1.0 "Amplitude of pulse"; parameter Real width( final min=Constants.small, final max=1, final unit="1")=0.5 "Width of pulse in fraction of period"; parameter Real period( final quantity="Time", final unit="s", final min=Constants.small) "Time for one period"; parameter Real shift( final quantity="Time", final unit="s")=0 "Shift time for output"; parameter Real offset=0.0 "Offset of output signals"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Pulse output signal"; protected Logical.Sources.Pulse booPul( final width=width, final period=period, final shift=shift) "Boolean pulse"; Conversions.BooleanToReal booToRea( final realTrue=offset+amplitude, final realFalse=offset) "Boolean to real conversion"; equation connect(booPul.y,booToRea.u); connect(y,booToRea.y); end Pulse;

Buildings.Controls.OBC.CDL.Reals.Sources.Ramp Buildings.Controls.OBC.CDL.Reals.Sources.Ramp

Generate ramp signal

Buildings.Controls.OBC.CDL.Reals.Sources.Ramp

Information

The Real output y is a ramp signal:

Ramp.png

Parameters

TypeNameDefaultDescription
Realheight1Height of ramps
Realduration Duration of ramp (= 0.0 gives a Step) [s]
Realoffset0Offset of output signal
RealstartTime0Output = offset for time < startTime [s]

Connectors

TypeNameDescription
output RealOutputyConnector of Real output signal

Modelica definition

block Ramp "Generate ramp signal" parameter Real height=1 "Height of ramps"; parameter Real duration( final quantity="Time", final unit="s", min=Constants.small) "Duration of ramp (= 0.0 gives a Step)"; parameter Real offset=0 "Offset of output signal"; parameter Real startTime( final quantity="Time", final unit="s")=0 "Output = offset for time < startTime"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"; equation y=offset+( if time < startTime then 0 else if time <(startTime+duration) then (time-startTime)*height/duration else height); end Ramp;

Buildings.Controls.OBC.CDL.Reals.Sources.Sin Buildings.Controls.OBC.CDL.Reals.Sources.Sin

Generate sine signal

Buildings.Controls.OBC.CDL.Reals.Sources.Sin

Information

Block that outputs a sine.

Sin.png

Parameters

TypeNameDefaultDescription
Realamplitude1Amplitude of sine wave
RealfreqHz Frequency of sine wave [Hz]
Realphase0Phase of sine wave [rad]
Realoffset0Offset of output signal
RealstartTime0Output = offset for time < startTime [s]

Connectors

TypeNameDescription
output RealOutputyConnector of Real output signal

Modelica definition

block Sin "Generate sine signal" parameter Real amplitude=1 "Amplitude of sine wave"; parameter Real freqHz( final quantity="Frequency", final unit="Hz", start=1) "Frequency of sine wave"; parameter Real phase( final quantity="Angle", final unit="rad", displayUnit="deg")=0 "Phase of sine wave"; parameter Real offset=0 "Offset of output signal"; parameter Real startTime( final quantity="Time", final unit="s")=0 "Output = offset for time < startTime"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"; equation y=offset+( if time < startTime then 0 else amplitude*Modelica.Math.sin( 2*Buildings.Controls.OBC.CDL.Constants.pi*freqHz*(time-startTime)+phase)); end Sin;

Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable

Table look-up with respect to time and linear or periodic extrapolation

Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable

Information

Block that outputs values of a time table.

The block takes as a parameter a time table of a format:

table = [ 0*3600, 0;
          6*3600, 0;
          6*3600, 1;
         18*3600, 1;
         18*3600, 0;
         24*3600, 0];

where the first column is time in seconds, and the remaining column(s) are the table values. Any number of columns can be specified. The parameter smoothness determines how the table values are interpolated. The following settings are allowed:

smoothnessDescription
CDL.Types.LinearSegments Table points are linearly interpolated.
CDL.Types.ConstantSegments Table points are not interpolated, but the previous tabulated value is returned.

The parameter extrapolation determines how the table values are extrapolated. The following settings are allowed:

extrapolationDescription
CDL.Types.HoldLastPoint Hold the first or last table point outside of the table scope.
CDL.Types.LastTwoPoints Extrapolate by using the derivative at the first or last table points outside of the table scope.
CDL.Types.Periodic Repeat the table scope periodically with periodicity (max(table[:, 1]-min(table[:, 1]))*timeScale).

If extrapolation === CDL.Types.Periodic, then the above example would give a schedule with periodicity of one day. The simulation can start at any time, whether it is a multiple of a day or not, and positive or negative.

The value of the parameter offset is added to the tabulated values. The parameters timeScale is used to scale the first column of the table. For example, set timeScale = 3600 if the first column is in hour (because in CDL, the time unit is seconds).

If the table has only one row, no interpolation is performed and the table values of this row are just returned.

An interval boundary is defined by two identical time values following each other. For example

   table = [0, 0;
            1, 0;
            1, 1;
            2, 3;
            3, 5;
            3, 2;
            4, 4;
            5, 5];

defines three intervalls: 0..1, 1..3, 3..5. Within an interval the defined interpolation method is applied (so the table outputs within an interval are continuous if smoothness = CDL.Types.LinearSegments).

Example:

  table = [0, 0;
           1, 0;
           1, 1;
           2, 4;
           3, 9;
           4, 16];
  smoothness = CDL.Types.LinearSegments;

If, e.g., time = 1.0, the output y =  0.0 (before event), 1.0 (after event)
    e.g., time = 1.5, the output y =  2.5,
    e.g., time = 2.0, the output y =  4.0,
    e.g., time = 5.0, the output y = 23.0 (i.e., extrapolation via last 2 points).

Implementation

For simulation, no time events are generated within an interval in order that also intervals with many points do not reduce the simulation efficiency. If the table points are largely changing, it is adviseable to force time events by duplicating every time point (especially, if the model in which the table is present allows the variable step integrator to make large integrator steps). For example, if a sawtooth signal is defined with the table, it is more reliable to define the table as:

   table = [0, 0;
            1, 2;
            1, 2;
            2, 0;
            2, 0;
            3, 2;
            3, 2];

instead of

   table = [0, 0;
            1, 2;
            2, 0;
            3, 2];

because time events are then generated at every time point.

Building automation systems typically have discrete time semantics with fixed sampling times, and no notion of superdense time (in which a tabulated value can change without advancing time). Therefore, to implement a table with two equal time stamps, a CDL translator may parameterize a table in the building automation in such a way that the step change happens at the time indicated in the first column, whereas previous sampling times output the tabulated value at the last transition. For example,

table = [0, 0;
         1, 0;
         1, 1];
smoothness = CDL.Types.ConstantSegments;

may be converted such that a building automation system with a sampling time of 0.5 seconds outputs

  t = 0, 0.5, 1, ...
  y = 0, 0  , 1, ...

Parameters

TypeNameDefaultDescription
Realtable[:, :] Table matrix (time = first column is time in seconds, unless timeScale <> 1)
SmoothnesssmoothnessCDL.Types.Smoothness.LinearS...Smoothness of table interpolation
ExtrapolationextrapolationCDL.Types.Extrapolation.Peri...Extrapolation of data outside the definition range
Realoffset[:]fill(0, nout)Offsets of output signals as a vector with length equal to number of table matrix columns less one
RealtimeScale1Time scale of first table column. Set to 3600 if time in table is in hours [1]

Connectors

TypeNameDescription
output RealOutputy[nout]Output of the table

Modelica definition

block TimeTable "Table look-up with respect to time and linear or periodic extrapolation" parameter Real table[:,:] "Table matrix (time = first column is time in seconds, unless timeScale <> 1)"; parameter CDL.Types.Smoothness smoothness=CDL.Types.Smoothness.LinearSegments "Smoothness of table interpolation"; parameter CDL.Types.Extrapolation extrapolation=CDL.Types.Extrapolation.Periodic "Extrapolation of data outside the definition range"; parameter Real offset[:]=fill( 0, nout) "Offsets of output signals as a vector with length equal to number of table matrix columns less one"; parameter Real timeScale( final unit="1")=1 "Time scale of first table column. Set to 3600 if time in table is in hours"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nout] "Output of the table"; protected final parameter Integer nout=size( table, 2)-1 "Dimension of output vector"; parameter Real t0( final quantity="Time", final unit="s", fixed=false) "First sample time instant"; parameter Real timeRange( final quantity="Time", final unit="s")=timeScale*(table[end,1]-table[1,1]) "Range of time in table"; final parameter Integer nT=size( table, 1) "Number of time stamps"; // CDL uses different enumerations for smoothness and for extrapolation // than the Modelica Standard Library. Hence, we cast the CDL // enumeration to the MSL enumaration. Modelica.Blocks.Sources.CombiTimeTable tab( final tableOnFile=false, final table=table, final columns=2:size( tab.table, 2), final smoothness= if smoothness == CDL.Types.Smoothness.LinearSegments then Modelica.Blocks.Types.Smoothness.LinearSegments else Modelica.Blocks.Types.Smoothness.ConstantSegments, final extrapolation= if extrapolation == CDL.Types.Extrapolation.HoldLastPoint then Modelica.Blocks.Types.Extrapolation.HoldLastPoint elseif extrapolation == CDL.Types.Extrapolation.LastTwoPoints then Modelica.Blocks.Types.Extrapolation.LastTwoPoints else Modelica.Blocks.Types.Extrapolation.Periodic, final offset=offset, final startTime= if (extrapolation == Types.Extrapolation.Periodic) then t0 else 0, final timeScale=timeScale) "Time table"; initial equation // If the table has only one time stamp, then timeRange is zero. // We can then set t0 to be equal to the start of the simulation. t0= if nT == 1 then time else Buildings.Utilities.Math.Functions.round( x=integer(time/timeRange)*timeRange, n=6); equation connect(tab.y,y); end TimeTable;