Buildings.Controls.OBC.CDL.Reals

Package with blocks for continuous variables

Information

Package with blocks for elementary mathematical functions for continuous variables.

Package Content

Name Description
Buildings.Controls.OBC.CDL.Reals.Abs Abs Output the absolute value of the input
Buildings.Controls.OBC.CDL.Reals.Acos Acos Output the arc cosine of the input
Buildings.Controls.OBC.CDL.Reals.Add Add Output the sum of the two inputs
Buildings.Controls.OBC.CDL.Reals.AddParameter AddParameter Output the sum of an input plus a parameter
Buildings.Controls.OBC.CDL.Reals.Asin Asin Output the arc sine of the input
Buildings.Controls.OBC.CDL.Reals.Atan Atan Output the arc tangent of the input
Buildings.Controls.OBC.CDL.Reals.Atan2 Atan2 Output atan(u1/u2) of the inputs u1 and u2
Buildings.Controls.OBC.CDL.Reals.Average Average Output the average of its two inputs
Buildings.Controls.OBC.CDL.Reals.Cos Cos Output the cosine of the input
Buildings.Controls.OBC.CDL.Reals.Derivative Derivative Block that approximates the derivative of the input
Buildings.Controls.OBC.CDL.Reals.Divide Divide Output first input divided by second input
Buildings.Controls.OBC.CDL.Reals.Exp Exp Output the exponential (base e) of the input
Buildings.Controls.OBC.CDL.Reals.Greater Greater Output y is true, if input u1 is greater than input u2
Buildings.Controls.OBC.CDL.Reals.GreaterThreshold GreaterThreshold Output y is true, if input u is greater than threshold
Buildings.Controls.OBC.CDL.Reals.Hysteresis Hysteresis Transform Real to Boolean signal with Hysteresis
Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset IntegratorWithReset Output the integral of the input signal
Buildings.Controls.OBC.CDL.Reals.Less Less Output y is true, if input u1 is less than input u2
Buildings.Controls.OBC.CDL.Reals.LessThreshold LessThreshold Output y is true, if input u is less than threshold
Buildings.Controls.OBC.CDL.Reals.LimitSlewRate LimitSlewRate Limit the increase or decrease rate of input
Buildings.Controls.OBC.CDL.Reals.Limiter Limiter Limit the range of a signal
Buildings.Controls.OBC.CDL.Reals.Line Line Output the value of the input x along a line specified by two points
Buildings.Controls.OBC.CDL.Reals.Log Log Output the natural (base e) logarithm of the input (input > 0 required)
Buildings.Controls.OBC.CDL.Reals.Log10 Log10 Output the base 10 logarithm of the input (input > 0 required)
Buildings.Controls.OBC.CDL.Reals.MatrixGain MatrixGain Output the product of a gain matrix with the input signal vector
Buildings.Controls.OBC.CDL.Reals.MatrixMax MatrixMax Output vector of row- or column-wise maximum of the input matrix
Buildings.Controls.OBC.CDL.Reals.MatrixMin MatrixMin Output vector of row- or column-wise minimum values
Buildings.Controls.OBC.CDL.Reals.Max Max Pass through the largest signal
Buildings.Controls.OBC.CDL.Reals.Min Min Pass through the smallest signal
Buildings.Controls.OBC.CDL.Reals.Modulo Modulo Output the remainder of first input divided by second input (~=0)
Buildings.Controls.OBC.CDL.Reals.MovingAverage MovingAverage Block to output moving average
Buildings.Controls.OBC.CDL.Reals.MultiMax MultiMax Output the maximum element of the input vector
Buildings.Controls.OBC.CDL.Reals.MultiMin MultiMin Output the minimum element of the input vector
Buildings.Controls.OBC.CDL.Reals.MultiSum MultiSum Sum of Reals, y = k[1]*u[1] + k[2]*u[2] + ... + k[n]*u[n]
Buildings.Controls.OBC.CDL.Reals.Multiply Multiply Output product of the two inputs
Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter MultiplyByParameter Output the product of a gain value with the input signal
Buildings.Controls.OBC.CDL.Reals.PID PID P, PI, PD, and PID controller
Buildings.Controls.OBC.CDL.Reals.PIDWithReset PIDWithReset P, PI, PD, and PID controller with output reset
Buildings.Controls.OBC.CDL.Reals.Ramp Ramp Limit the changing rate of the input
Buildings.Controls.OBC.CDL.Reals.Round Round Round real number to given digits
Buildings.Controls.OBC.CDL.Reals.Sin Sin Output the sine of the input
Buildings.Controls.OBC.CDL.Reals.Sort Sort Sort elements of input vector in ascending or descending order
Buildings.Controls.OBC.CDL.Reals.Sqrt Sqrt Output the square root of the input (input >= 0 required)
Buildings.Controls.OBC.CDL.Reals.Subtract Subtract Output the difference of the two inputs
Buildings.Controls.OBC.CDL.Reals.Switch Switch Switch between two Real signals
Buildings.Controls.OBC.CDL.Reals.Tan Tan Output the tangent of the input
Buildings.Controls.OBC.CDL.Reals.Sources Sources Package with blocks that generate source signals
Buildings.Controls.OBC.CDL.Reals.Validation Validation Collection of models that validate the continuous blocks of the CDL

Buildings.Controls.OBC.CDL.Reals.Abs Buildings.Controls.OBC.CDL.Reals.Abs

Output the absolute value of the input

Buildings.Controls.OBC.CDL.Reals.Abs

Information

Block that outputs y = abs(u), where u is an input.

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Abs "Output the absolute value of the input" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=abs(u); end Abs;

Buildings.Controls.OBC.CDL.Reals.Acos Buildings.Controls.OBC.CDL.Reals.Acos

Output the arc cosine of the input

Buildings.Controls.OBC.CDL.Reals.Acos

Information

Block that outputs y = acos(u), where u is an input.

acos.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal [rad]

Modelica definition

block Acos "Output the arc cosine of the input" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y(unit="rad") "Connector of Real output signal"; equation y = Modelica.Math.acos(u); end Acos;

Buildings.Controls.OBC.CDL.Reals.Add Buildings.Controls.OBC.CDL.Reals.Add

Output the sum of the two inputs

Buildings.Controls.OBC.CDL.Reals.Add

Information

Block that outputs y as the sum of the two input signals u1 and u2,

    y = u1 + u2.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Add "Output the sum of the two inputs" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=u1+u2; end Add;

Buildings.Controls.OBC.CDL.Reals.AddParameter Buildings.Controls.OBC.CDL.Reals.AddParameter

Output the sum of an input plus a parameter

Buildings.Controls.OBC.CDL.Reals.AddParameter

Information

Block that outputs y = u + p, where p is parameter and u is an input.

Parameters

TypeNameDefaultDescription
Realp Value to be added

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block AddParameter "Output the sum of an input plus a parameter" parameter Real p "Value to be added"; Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=u+p; end AddParameter;

Buildings.Controls.OBC.CDL.Reals.Asin Buildings.Controls.OBC.CDL.Reals.Asin

Output the arc sine of the input

Buildings.Controls.OBC.CDL.Reals.Asin

Information

Block that outputs y = asin(u), where u is an input.

asin.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal [rad]

Modelica definition

block Asin "Output the arc sine of the input" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y(unit="rad") "Connector of Real output signal"; equation y = Modelica.Math.asin(u); end Asin;

Buildings.Controls.OBC.CDL.Reals.Atan Buildings.Controls.OBC.CDL.Reals.Atan

Output the arc tangent of the input

Buildings.Controls.OBC.CDL.Reals.Atan

Information

Block that outputs y = atan(u), where u is an input.

atan.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal [rad]

Modelica definition

block Atan "Output the arc tangent of the input" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y(unit="rad") "Connector of Real output signal"; equation y=Modelica.Math.atan(u); end Atan;

Buildings.Controls.OBC.CDL.Reals.Atan2 Buildings.Controls.OBC.CDL.Reals.Atan2

Output atan(u1/u2) of the inputs u1 and u2

Buildings.Controls.OBC.CDL.Reals.Atan2

Information

Block that outputs the tangent-inverse y = atan2(u1, u2) of the input u1 divided by the input u2.

u1 and u2 shall not be zero at the same time instant. Atan2 uses the sign of u1 and u2 in order to construct the solution in the range -π ≤ y ≤ π, whereas Buildings.Controls.OBC.CDL.Reals.Atan gives a solution in the range -π/2 ≤ y ≤ π/2.

atan2.png

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal [rad]

Modelica definition

block Atan2 "Output atan(u1/u2) of the inputs u1 and u2" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y(unit="rad") "Connector of Real output signal"; equation y=Modelica.Math.atan2( u1, u2); end Atan2;

Buildings.Controls.OBC.CDL.Reals.Average Buildings.Controls.OBC.CDL.Reals.Average

Output the average of its two inputs

Buildings.Controls.OBC.CDL.Reals.Average

Information

Block that outputs y = (u1 + u2) / 2, where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Average "Output the average of its two inputs" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=0.5*(u1+u2); end Average;

Buildings.Controls.OBC.CDL.Reals.Cos Buildings.Controls.OBC.CDL.Reals.Cos

Output the cosine of the input

Buildings.Controls.OBC.CDL.Reals.Cos

Information

Block that outputs y = cos(u), where u is an input.

cos.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal [rad]
output RealOutputyConnector of Real output signal

Modelica definition

block Cos "Output the cosine of the input" Interfaces.RealInput u(unit="rad") "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.cos(u); end Cos;

Buildings.Controls.OBC.CDL.Reals.Derivative Buildings.Controls.OBC.CDL.Reals.Derivative

Block that approximates the derivative of the input

Buildings.Controls.OBC.CDL.Reals.Derivative

Information

This blocks defines the transfer function between the input u and the output y as approximated derivative:

                s
  y = k * ------------ * u
            T * s + 1

If k=0, the block reduces to y=0.

Parameters

TypeNameDefaultDescription
Initialization
Realy_start0Initial value of output (= state)

Connectors

TypeNameDescription
input RealInputkConnector for gain signal
input RealInputTTime constant (T>0 required; T=0 is ideal derivative block) [s]
input RealInputuInput to be differentiated
output RealOutputyApproximation of derivative du/dt

Modelica definition

block Derivative "Block that approximates the derivative of the input" parameter Real y_start=0 "Initial value of output (= state)"; Buildings.Controls.OBC.CDL.Interfaces.RealInput k "Connector for gain signal"; Buildings.Controls.OBC.CDL.Interfaces.RealInput T( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps) "Time constant (T>0 required; T=0 is ideal derivative block)"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Input to be differentiated"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Approximation of derivative du/dt"; protected Real T_nonZero(final unit="s") "Non-zero value for T"; output Real x "State of block"; initial equation x= if abs(k) < Buildings.Controls.OBC.CDL.Constants.eps then u else u - T*y_start/k; equation T_nonZero = max(T, 100*Buildings.Controls.OBC.CDL.Constants.eps); der(x) = (u-x)/T_nonZero; y = (k/T_nonZero)*(u-x); end Derivative;

Buildings.Controls.OBC.CDL.Reals.Divide Buildings.Controls.OBC.CDL.Reals.Divide

Output first input divided by second input

Buildings.Controls.OBC.CDL.Reals.Divide

Information

Block that outputs y = u1 / u2, where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector for dividend
input RealInputu2Connector for divisor
output RealOutputyConnector for quotient

Modelica definition

block Divide "Output first input divided by second input" Interfaces.RealInput u1 "Connector for dividend"; Interfaces.RealInput u2 "Connector for divisor"; Interfaces.RealOutput y "Connector for quotient"; equation y=u1/u2; end Divide;

Buildings.Controls.OBC.CDL.Reals.Exp Buildings.Controls.OBC.CDL.Reals.Exp

Output the exponential (base e) of the input

Buildings.Controls.OBC.CDL.Reals.Exp

Information

Block that outputs y = exp(u), where u is an input and exp() is the base-e exponential function.

exp.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Exp "Output the exponential (base e) of the input" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.exp(u); end Exp;

Buildings.Controls.OBC.CDL.Reals.Greater Buildings.Controls.OBC.CDL.Reals.Greater

Output y is true, if input u1 is greater than input u2

Buildings.Controls.OBC.CDL.Reals.Greater

Information

Block that outputs true if the Real input u1 is greater than the Real input u2, optionally within a hysteresis h.

The parameter h ≥ 0 is used to specify a hysteresis. For any h ≥ 0, the output switches to true if u1 > u2, and it switches to false if u1 ≤ u2 - h. Note that in the special case of h = 0, this produces the output y=u1 > u2.

To disable hysteresis, set h=0.

Usage

Enabling hysteresis can avoid frequent switching.
In simulation, adding hysteresis is recommended to guard against numerical noise. Otherwise, numerical noise from a nonlinear solver or from an implicit time integration algorithm may cause the simulation to stall. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system.
In real controllers, adding hysteresis is recommended to guard against measurement noise. Otherwise, measurement noise may cause the output to change frequently.

Parameters

TypeNameDefaultDescription
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block Greater "Output y is true, if input u1 is greater than input u2" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; protected final parameter Boolean have_hysteresis=h >= 1E-10 "True if the block has no hysteresis"; GreaterWithHysteresis greHys( final h=h, final pre_y_start=pre_y_start) if have_hysteresis "Block with hysteresis"; GreaterNoHysteresis greNoHys if not have_hysteresis "Block without hysteresis"; block GreaterNoHysteresis "Greater block without hysteresis" Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; equation y=u1 > u2; end GreaterNoHysteresis; block GreaterWithHysteresis "Greater block without hysteresis" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u1 > u2 or pre(y) and u1 > u2-h); end GreaterWithHysteresis; equation connect(u1,greHys.u1); connect(u2,greHys.u2); connect(greHys.y,y); connect(u1,greNoHys.u1); connect(u2,greNoHys.u2); connect(greNoHys.y,y); end Greater;

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold Buildings.Controls.OBC.CDL.Reals.GreaterThreshold

Output y is true, if input u is greater than threshold

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold

Information

Block that outputs true if the Real input u is greater than a threshold t, optionally within a hysteresis h.

The parameter h ≥ 0 is used to specify a hysteresis. For any h ≥ 0, the output switches to true if u > t, where t is the threshold, and it switches to false if u ≤ t - h. Note that in the special case of h = 0, this produces the output y=u > t.

To disable hysteresis, set h=0.

Usage

Enabling hysteresis can avoid frequent switching.
In simulation, adding hysteresis is recommended to guard against numerical noise. Otherwise, numerical noise from a nonlinear solver or from an implicit time integration algorithm may cause the simulation to stall. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system.
In real controllers, adding hysteresis is recommended to guard against measurement noise. Otherwise, measurement noise may cause the output to change frequently.

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputuInput
output BooleanOutputyOutput

Modelica definition

block GreaterThreshold "Output y is true, if input u is greater than threshold" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input"; Interfaces.BooleanOutput y "Output"; protected final parameter Boolean have_hysteresis=h >= 1E-10 "True if the block has no hysteresis"; GreaterWithHysteresis greHys( final h=h, final t=t, final pre_y_start=pre_y_start) if have_hysteresis "Block with hysteresis"; GreaterNoHysteresis greNoHys( final t=t) if not have_hysteresis "Block without hysteresis"; block GreaterNoHysteresis "Greater block without hysteresis" parameter Real t=0 "Threshold for comparison"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; equation y=u > t; end GreaterNoHysteresis; block GreaterWithHysteresis "Greater block without hysteresis" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u > t or pre(y) and u > t-h); end GreaterWithHysteresis; equation connect(u,greHys.u); connect(greHys.y,y); connect(u,greNoHys.u); connect(greNoHys.y,y); end GreaterThreshold;

Buildings.Controls.OBC.CDL.Reals.Hysteresis Buildings.Controls.OBC.CDL.Reals.Hysteresis

Transform Real to Boolean signal with Hysteresis

Buildings.Controls.OBC.CDL.Reals.Hysteresis

Information

Block that transforms a Real input signal into a Boolean output signal:

The start value of the output is defined via parameter pre_y_start (= value of pre(y) at initial time). The default value of this parameter is false.

Hysteresis.png

Parameters

TypeNameDefaultDescription
RealuLow if y=true and u<uLow, switch to y=false
RealuHigh if y=false and u>uHigh, switch to y=true
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputuReal input signal
output BooleanOutputyBoolean output signal

Modelica definition

block Hysteresis "Transform Real to Boolean signal with Hysteresis" parameter Real uLow "if y=true and u<uLow, switch to y=false"; parameter Real uHigh "if y=false and u>uHigh, switch to y=true"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Real input signal"; Interfaces.BooleanOutput y "Boolean output signal"; initial equation assert( uHigh > uLow, "Hysteresis limits wrong. uHigh must be larger than uLow"); pre(y)=pre_y_start; equation y=not pre(y) and u > uHigh or pre(y) and u >= uLow; end Hysteresis;

Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset

Output the integral of the input signal

Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset

Information

Block that outputs

y(t) = ystart + ∫t0t u(s) ds.

Whenever the input signal trigger changes from false to true, the integrator is reset by setting ystart to the value of the input signal y_reset_in.

Parameters

TypeNameDefaultDescription
Realk1Integrator gain
Initialization
Realy_start0Initial or guess value of output (= state)

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
input RealInputy_reset_inInput signal for state to which integrator is reset
input BooleanInputtriggerResets the integrator output when trigger becomes true
output RealOutputyConnector of Real output signal

Modelica definition

block IntegratorWithReset "Output the integral of the input signal" parameter Real k=1 "Integrator gain"; parameter Real y_start=0 "Initial or guess value of output (= state)"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealInput y_reset_in "Input signal for state to which integrator is reset"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger "Resets the integrator output when trigger becomes true"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"; initial equation y=y_start; equation der(y)=k*u; when trigger then reinit( y, y_reset_in); end when; end IntegratorWithReset;

Buildings.Controls.OBC.CDL.Reals.Less Buildings.Controls.OBC.CDL.Reals.Less

Output y is true, if input u1 is less than input u2

Buildings.Controls.OBC.CDL.Reals.Less

Information

Block that outputs true if the Real input u1 is less than the Real input u2, optionally within a hysteresis h.

The parameter h ≥ 0 is used to specify a hysteresis. For any h ≥ 0, the output switches to true if u1 < u2, and it switches to false if u1 ≥ u2 + h. Note that in the special case of h = 0, this produces the output y=u1 < u2.

To disable hysteresis, set h=0.

Usage

Enabling hysteresis can avoid frequent switching.
In simulation, adding hysteresis is recommended to guard against numerical noise. Otherwise, numerical noise from a nonlinear solver or from an implicit time integration algorithm may cause the simulation to stall. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system.
In real controllers, adding hysteresis is recommended to guard against measurement noise. Otherwise, measurement noise may cause the output to change frequently.

Parameters

TypeNameDefaultDescription
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block Less "Output y is true, if input u1 is less than input u2" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; protected final parameter Boolean have_hysteresis=h >= 1E-10 "True if the block has no hysteresis"; LessWithHysteresis lesHys( final h=h, final pre_y_start=pre_y_start) if have_hysteresis "Block with hysteresis"; LessNoHysteresis lesNoHys if not have_hysteresis "Block without hysteresis"; block LessNoHysteresis "Less block without hysteresis" Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; equation y=u1 < u2; end LessNoHysteresis; block LessWithHysteresis "Less block without hysteresis" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u1 < u2 or pre(y) and u1 < u2+h); end LessWithHysteresis; equation connect(u1,lesHys.u1); connect(u2,lesHys.u2); connect(lesHys.y,y); connect(u1,lesNoHys.u1); connect(u2,lesNoHys.u2); connect(lesNoHys.y,y); end Less;

Buildings.Controls.OBC.CDL.Reals.LessThreshold Buildings.Controls.OBC.CDL.Reals.LessThreshold

Output y is true, if input u is less than threshold

Buildings.Controls.OBC.CDL.Reals.LessThreshold

Information

Block that outputs true if the Real input u is less than a threshold t, optionally within a hysteresis h.

The parameter h ≥ 0 is used to specify a hysteresis. For any h ≥ 0, the output switches to true if u < t, where t is the threshold, and it switches to false if u ≥ t + h. Note that in the special case of h = 0, this produces the output y=u < t.

Usage

Enabling hysteresis can avoid frequent switching. Adding hysteresis is recommended in real controllers to guard against sensor noise, and in simulation to guard against numerical noise. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system. To disable hysteresis, set h=0.

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputuInput
output BooleanOutputyOutput

Modelica definition

block LessThreshold "Output y is true, if input u is less than threshold" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input"; Interfaces.BooleanOutput y "Output"; protected final parameter Boolean have_hysteresis=h >= 1E-10 "True if the block has no hysteresis"; LessWithHysteresis lesHys( final h=h, final t=t, final pre_y_start=pre_y_start) if have_hysteresis "Block with hysteresis"; LessNoHysteresis lesNoHys( final t=t) if not have_hysteresis "Block without hysteresis"; block LessNoHysteresis "Less block without hysteresis" parameter Real t=0 "Threshold for comparison"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; equation y=u < t; end LessNoHysteresis; block LessWithHysteresis "Less block without hysteresis" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u < t or pre(y) and u < t+h); end LessWithHysteresis; equation connect(u,lesHys.u); connect(lesHys.y,y); connect(u,lesNoHys.u); connect(lesNoHys.y,y); end LessThreshold;

Buildings.Controls.OBC.CDL.Reals.LimitSlewRate Buildings.Controls.OBC.CDL.Reals.LimitSlewRate

Limit the increase or decrease rate of input

Buildings.Controls.OBC.CDL.Reals.LimitSlewRate

Information

The block limits the rate of change of the input by a ramp.

This block computes a threshold for the rate of change between input u and output y as thr = (u-y)/Td, where Td > 0 is parameter. The output y is computed as follows:

Implementation

For the block to work with arbitrary inputs and in order to produce a differentiable output, the input is numerically differentiated with derivative time constant Td. Smaller time constant Td means nearer ideal derivative.

Parameters

TypeNameDefaultDescription
RealraisingSlewRate Speed with which to increase the output [1/s]
RealfallingSlewRate-raisingSlewRateSpeed with which to decrease the output [1/s]
RealTdraisingSlewRate*10Derivative time constant [s]
BooleanenabletrueSet to false to disable rate limiter

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block LimitSlewRate "Limit the increase or decrease rate of input" parameter Real raisingSlewRate( min=Constants.small, unit="1/s") "Speed with which to increase the output"; parameter Real fallingSlewRate( max=-Constants.small, unit="1/s")=-raisingSlewRate "Speed with which to decrease the output"; parameter Real Td( final quantity="Time", final unit="s", min=Constants.eps)=raisingSlewRate*10 "Derivative time constant"; parameter Boolean enable=true "Set to false to disable rate limiter"; Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; protected Real thr=(u-y)/Td "Approximation to derivative between input and output"; initial equation assert( raisingSlewRate > 0, "raisingSlewRate must be larger than zero."); assert( fallingSlewRate < 0, "fallingSlewRate must be less than zero."); y=u; equation if enable then der(y)=smooth( 1, noEvent( if thr < fallingSlewRate then fallingSlewRate else if thr > raisingSlewRate then raisingSlewRate else thr)); else y=u; end if; end LimitSlewRate;

Buildings.Controls.OBC.CDL.Reals.Limiter Buildings.Controls.OBC.CDL.Reals.Limiter

Limit the range of a signal

Buildings.Controls.OBC.CDL.Reals.Limiter

Information

Block that outputs y = min(uMax, max(uMin, u)), where u is an input and uMax and uMin are parameters.

If uMax < uMin, an error occurs and no output is produced.

Parameters

TypeNameDefaultDescription
RealuMax Upper limit of input signal
RealuMin Lower limit of input signal

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Limiter "Limit the range of a signal" parameter Real uMax "Upper limit of input signal"; parameter Real uMin "Lower limit of input signal"; Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; initial equation assert( uMin < uMax, "uMin must be smaller than uMax. Check parameters."); equation y=homotopy( actual=smooth(0,noEvent( if u > uMax then uMax else if u < uMin then uMin else u)), simplified=u); end Limiter;

Buildings.Controls.OBC.CDL.Reals.Line Buildings.Controls.OBC.CDL.Reals.Line

Output the value of the input x along a line specified by two points

Buildings.Controls.OBC.CDL.Reals.Line

Information

Block that outputs y = a + b u, where u is an input and the coefficients a and b are determined so that the line intercepts the two input points specified by the two points x1 and f1, and x2 and f2.

The parameters limitBelow and limitAbove determine whether x1 and x2 are also used to limit the input u.

If the limits are used, then this block requires x1 < x2.

Parameters

TypeNameDefaultDescription
BooleanlimitBelowtrueIf true, limit input u to be no smaller than x1
BooleanlimitAbovetrueIf true, limit input u to be no larger than x2

Connectors

TypeNameDescription
input RealInputx1Support point x1, with x1 < x2
input RealInputf1Support point f(x1)
input RealInputx2Support point x2, with x2 > x1
input RealInputf2Support point f(x2)
input RealInputuIndependent variable
output RealOutputyf(x) along the line specified by (x1, f1) and (x2, f2)

Modelica definition

block Line "Output the value of the input x along a line specified by two points" parameter Boolean limitBelow=true "If true, limit input u to be no smaller than x1"; parameter Boolean limitAbove=true "If true, limit input u to be no larger than x2"; Interfaces.RealInput x1 "Support point x1, with x1 < x2"; Interfaces.RealInput f1 "Support point f(x1)"; Interfaces.RealInput x2 "Support point x2, with x2 > x1"; Interfaces.RealInput f2 "Support point f(x2)"; Interfaces.RealInput u "Independent variable"; Interfaces.RealOutput y "f(x) along the line specified by (x1, f1) and (x2, f2)"; protected Real a "Intercept"; Real b "Slope"; Real xLim "Input value after applying the limits"; equation if limitBelow or limitAbove then assert( x2 > x1, "x2 must be bigger than x1 in "+getInstanceName(), AssertionLevel.warning); end if; b=(f2-f1)/(x2-x1); a=f2-b*x2; if limitBelow and limitAbove then xLim=min( x2, max( x1, u)); elseif limitBelow then xLim=max( x1, u); elseif limitAbove then xLim=min( x2, u); else xLim=u; end if; y=a+b*xLim; end Line;

Buildings.Controls.OBC.CDL.Reals.Log Buildings.Controls.OBC.CDL.Reals.Log

Output the natural (base e) logarithm of the input (input > 0 required)

Buildings.Controls.OBC.CDL.Reals.Log

Information

Block that outputs y = log(u), where u is an input and log() is the natural logarithm (base-e) function.

An error occurs if the input u is zero or negative.

log.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Log "Output the natural (base e) logarithm of the input (input > 0 required)" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.log(u); end Log;

Buildings.Controls.OBC.CDL.Reals.Log10 Buildings.Controls.OBC.CDL.Reals.Log10

Output the base 10 logarithm of the input (input > 0 required)

Buildings.Controls.OBC.CDL.Reals.Log10

Information

Block that outputs y = log10(u), where u is an input and log10() is the logarithm (base-10) function.

An error occurs if the input u is zero or negative.

log10.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Log10 "Output the base 10 logarithm of the input (input > 0 required)" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.log10(u); end Log10;

Buildings.Controls.OBC.CDL.Reals.MatrixGain Buildings.Controls.OBC.CDL.Reals.MatrixGain

Output the product of a gain matrix with the input signal vector

Buildings.Controls.OBC.CDL.Reals.MatrixGain

Information

This blocks computes output vector y as the product of the gain matrix K with the input signal vector u as y = K u. For example,

   parameter Real K[:,:] = [0.12 2; 3 1.5];

results in

     | y[1] |     | 0.12  2.00 |   | u[1] |
     |      |  =  |            | * |      |
     | y[2] |     | 3.00  1.50 |   | u[2] |

Parameters

TypeNameDefaultDescription
RealK[:, :][1, 0; 0, 1]Gain matrix which is multiplied with the input

Connectors

TypeNameDescription
input RealInputu[nin]Connector of Real input signals
output RealOutputy[nout]Connector of Real output signals

Modelica definition

block MatrixGain "Output the product of a gain matrix with the input signal vector" parameter Real K[:,:]=[ 1,0; 0,1] "Gain matrix which is multiplied with the input"; Interfaces.RealInput u[nin] "Connector of Real input signals"; Interfaces.RealOutput y[nout] "Connector of Real output signals"; protected parameter Integer nin=size( K, 2) "Number of inputs"; parameter Integer nout=size( K, 1) "Number of outputs"; equation y=K*u; end MatrixGain;

Buildings.Controls.OBC.CDL.Reals.MatrixMax Buildings.Controls.OBC.CDL.Reals.MatrixMax

Output vector of row- or column-wise maximum of the input matrix

Buildings.Controls.OBC.CDL.Reals.MatrixMax

Information

If rowMax = true, this block outputs the row-wise maximum of the input matrix u, otherwise it outputs the column-wise maximum of the input matrix u.

Parameters

TypeNameDefaultDescription
BooleanrowMaxtrueIf true, outputs row-wise maximum, otherwise column-wise
IntegernRow Number of rows in input matrix
IntegernCol Number of columns in input matrix

Connectors

TypeNameDescription
input RealInputu[nRow, nCol]Connector of Real input signals
output RealOutputy[if rowMax then size(u, 1) else size(u, 2)]Connector of Real output signals

Modelica definition

block MatrixMax "Output vector of row- or column-wise maximum of the input matrix" parameter Boolean rowMax=true "If true, outputs row-wise maximum, otherwise column-wise"; parameter Integer nRow( final min=1) "Number of rows in input matrix"; parameter Integer nCol( final min=1) "Number of columns in input matrix"; Interfaces.RealInput u[nRow,nCol] "Connector of Real input signals"; Interfaces.RealOutput y[ if rowMax then size( u, 1) else size( u, 2)] "Connector of Real output signals"; equation if rowMax then y={max(u[i,:]) for i in 1:size(u,1)}; else y={max(u[:,i]) for i in 1:size(u,2)}; end if; end MatrixMax;

Buildings.Controls.OBC.CDL.Reals.MatrixMin Buildings.Controls.OBC.CDL.Reals.MatrixMin

Output vector of row- or column-wise minimum values

Buildings.Controls.OBC.CDL.Reals.MatrixMin

Information

If rowMin = true, this block outputs the row-wise minimum of the input matrix u, otherwise it outputs the column-wise minimum of the input matrix u.

Parameters

TypeNameDefaultDescription
BooleanrowMintrueIf true, outputs row-wise minimum, otherwise column-wise
IntegernRow Number of rows in input matrix
IntegernCol Number of columns in input matrix

Connectors

TypeNameDescription
input RealInputu[nRow, nCol]Connector of Real input signals
output RealOutputy[if rowMin then size(u, 1) else size(u, 2)]Connector of Real output signals

Modelica definition

block MatrixMin "Output vector of row- or column-wise minimum values" parameter Boolean rowMin=true "If true, outputs row-wise minimum, otherwise column-wise"; parameter Integer nRow( final min=1) "Number of rows in input matrix"; parameter Integer nCol( final min=1) "Number of columns in input matrix"; Interfaces.RealInput u[nRow,nCol] "Connector of Real input signals"; Interfaces.RealOutput y[ if rowMin then size( u, 1) else size( u, 2)] "Connector of Real output signals"; equation if rowMin then y={min(u[i,:]) for i in 1:size(u,1)}; else y={min(u[:,i]) for i in 1:size(u,2)}; end if; end MatrixMin;

Buildings.Controls.OBC.CDL.Reals.Max Buildings.Controls.OBC.CDL.Reals.Max

Pass through the largest signal

Buildings.Controls.OBC.CDL.Reals.Max

Information

Block that outputs y = max(u1, u2), where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Max "Pass through the largest signal" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=max( u1, u2); end Max;

Buildings.Controls.OBC.CDL.Reals.Min Buildings.Controls.OBC.CDL.Reals.Min

Pass through the smallest signal

Buildings.Controls.OBC.CDL.Reals.Min

Information

Block that outputs y = min(u1, u2), where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Min "Pass through the smallest signal" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=min( u1, u2); end Min;

Buildings.Controls.OBC.CDL.Reals.Modulo Buildings.Controls.OBC.CDL.Reals.Modulo

Output the remainder of first input divided by second input (~=0)

Buildings.Controls.OBC.CDL.Reals.Modulo

Information

Block that outputs y = mod(u1/u2), where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Modulo "Output the remainder of first input divided by second input (~=0)" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=mod( u1, u2); end Modulo;

Buildings.Controls.OBC.CDL.Reals.MovingAverage Buildings.Controls.OBC.CDL.Reals.MovingAverage

Block to output moving average

Buildings.Controls.OBC.CDL.Reals.MovingAverage

Information

This block outputs the mean value of its input signal as

      1  t
y =   -  ∫   u(s) ds
      δ  t-δ

where δ is a parameter that determines the time window over which the input is averaged. For t < δ seconds, it outputs

           1      t
y =   --------    ∫   u(s) ds
      t-t0+10-10   t0

where t0 is the initial time.

This block can for example be used to output the moving average of a noisy measurement signal.

See Buildings.Controls.OBC.CDL.Reals.Validation.MovingAverage and Buildings.Controls.OBC.CDL.Reals.Validation.MovingAverage_nonZeroStart for example.

Parameters

TypeNameDefaultDescription
Realdelta Time horizon over which the input is averaged [s]

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block MovingAverage "Block to output moving average" parameter Real delta( final quantity="Time", final unit="s", min=1E-5) "Time horizon over which the input is averaged"; Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; protected parameter Real tStart( final quantity="Time", final unit="s", fixed=false) "Start time"; Real mu "Internal integrator variable"; Real muDel "Internal integrator variable with delay"; Boolean mode( start=false, fixed=true) "Calculation mode"; initial equation tStart=time; mu=0; equation u=der(mu); muDel=delay( mu, delta); // Compute the mode so that Dymola generates // time and not state events as it would with // an if-then construct when time >= tStart+delta then mode=true; end when; if mode then y=(mu-muDel)/delta; else y=(mu-muDel)/(time-tStart+1E-3); end if; end MovingAverage;

Buildings.Controls.OBC.CDL.Reals.MultiMax Buildings.Controls.OBC.CDL.Reals.MultiMax

Output the maximum element of the input vector

Buildings.Controls.OBC.CDL.Reals.MultiMax

Information

Outputs the maximum element of the input vector.

Connectors

TypeNameDescription
input RealInputu[nin]Connector of Real input signals
output RealOutputyConnector of Real output signals

Modelica definition

block MultiMax "Output the maximum element of the input vector" parameter Integer nin( min=0)=0 "Number of input connections"; Interfaces.RealInput u[nin] "Connector of Real input signals"; Interfaces.RealOutput y "Connector of Real output signals"; equation y=max(u); end MultiMax;

Buildings.Controls.OBC.CDL.Reals.MultiMin Buildings.Controls.OBC.CDL.Reals.MultiMin

Output the minimum element of the input vector

Buildings.Controls.OBC.CDL.Reals.MultiMin

Information

Outputs the minimum element of the input vector.

Connectors

TypeNameDescription
input RealInputu[nin]Connector of Real input signals
output RealOutputyConnector of Real output signals

Modelica definition

block MultiMin "Output the minimum element of the input vector" parameter Integer nin( min=0)=0 "Number of input connections"; Interfaces.RealInput u[nin] "Connector of Real input signals"; Interfaces.RealOutput y "Connector of Real output signals"; equation y=min(u); end MultiMin;

Buildings.Controls.OBC.CDL.Reals.MultiSum Buildings.Controls.OBC.CDL.Reals.MultiSum

Sum of Reals, y = k[1]*u[1] + k[2]*u[2] + ... + k[n]*u[n]

Buildings.Controls.OBC.CDL.Reals.MultiSum

Information

Block that outputs

y = ∑i=1n ki   ui,

where k is a parameter with n elements and u is an input of the same length. The dimension of u can be enlarged by drawing an additional connection line. The connection is automatically connected to this new free index.

If no connection to the input connector u is present, the output is y=0.

See Buildings.Controls.OBC.CDL.Reals.Validation.MultiSum for an example.

Parameters

TypeNameDefaultDescription
Realk[nin]fill(1, nin)Input gains

Connectors

TypeNameDescription
input RealInputu[nin]Connector of Real input signals
output RealOutputyConnector of Real output signal

Modelica definition

block MultiSum "Sum of Reals, y = k[1]*u[1] + k[2]*u[2] + ... + k[n]*u[n]" parameter Integer nin( min=0)=0 "Number of input connections"; parameter Real k[nin]=fill( 1, nin) "Input gains"; Interfaces.RealInput u[nin] "Connector of Real input signals"; Interfaces.RealOutput y "Connector of Real output signal"; equation if size( u, 1) > 0 then y=k*u; else y=0; end if; end MultiSum;

Buildings.Controls.OBC.CDL.Reals.Multiply Buildings.Controls.OBC.CDL.Reals.Multiply

Output product of the two inputs

Buildings.Controls.OBC.CDL.Reals.Multiply

Information

Block that outputs y = u1 * u2, where u1 and u2 are inputs.

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Multiply "Output product of the two inputs" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=u1*u2; end Multiply;

Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter

Output the product of a gain value with the input signal

Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter

Information

Block that outputs y = k * u, where k is a parameter and u is an input.

Parameters

TypeNameDefaultDescription
Realk Gain value multiplied with input signal

Connectors

TypeNameDescription
input RealInputuInput signal connector
output RealOutputyOutput signal connector

Modelica definition

block MultiplyByParameter "Output the product of a gain value with the input signal" parameter Real k "Gain value multiplied with input signal"; Interfaces.RealInput u "Input signal connector"; Interfaces.RealOutput y "Output signal connector"; equation y=k*u; end MultiplyByParameter;

Buildings.Controls.OBC.CDL.Reals.PID Buildings.Controls.OBC.CDL.Reals.PID

P, PI, PD, and PID controller

Buildings.Controls.OBC.CDL.Reals.PID

Information

PID controller in the standard form

yu = k/r   (e(t) + 1 ⁄ Ti   ∫ e(τ) dτ + Td d⁄dt e(t)),

where yu is the control signal before output limitation, e(t) = us(t) - um(t) is the control error, with us being the set point and um being the measured quantity, k is the gain, Ti is the time constant of the integral term, Td is the time constant of the derivative term, and r is a scaling factor, with default r=1. The scaling factor should be set to the typical order of magnitude of the range of the error e. For example, you may set r=100 to r=1000 if the control input is a pressure of a heating water circulation pump in units of Pascal, or leave r=1 if the control input is a room temperature.

Note that the units of k are the inverse of the units of the control error, while the units of Ti and Td are seconds.

The actual control output is

y = min( ymax, max( ymin, y)),

where ymin and ymax are limits for the control signal.

P, PI, PD, or PID action

Through the parameter controllerType, the controller can be configured as P, PI, PD or PID controller. The default configuration is PI.

Reverse or direct action

Through the parameter reverseActing, the controller can be configured to be reverse or direct acting. The above standard form is reverse acting, which is the default configuration. For a reverse acting controller, for a constant set point, an increase in measurement signal u_m decreases the control output signal y (Montgomery and McDowall, 2008). Thus,

If reverseAction=false, then the error e above is multiplied by -1.

Anti-windup compensation

The controller anti-windup compensation is as follows: Instead of the above basic control law, the implementation is

yu = k   (e(t) ⁄ r + 1 ⁄ Ti   ∫ (-Δy + e(τ) ⁄ r) dτ + Td ⁄ r d⁄dt e(t)),

where the anti-windup compensation Δy is

Δy = (yu - y) ⁄ (k Ni),

where Ni > 0 is the time constant for the anti-windup compensation. To accelerate the anti-windup, decrease Ni.

Note that the anti-windup term (-Δy + e(τ) ⁄ r) shows that the range of the typical control error r should be set to a reasonable value so that

e(τ) ⁄ r = (us(τ) - um(τ)) ⁄ r

has order of magnitude one, and hence the anti-windup compensation should work well.

Reset of the controller output

Note that this controller implements an integrator anti-windup. Therefore, for most applications, the controller output does not need to be reset. However, if the controller is used in conjuction with equipment that is being switched on, better control performance may be achieved by resetting the controller output when the equipment is switched on. This is in particular the case in situations where the equipment control input should continuously increase as the equipment is switched on, such as a light dimmer that may slowly increase the luminance, or a variable speed drive of a motor that should continuously increase the speed. In this case, the controller Buildings.Controls.OBC.CDL.Reals.PIDWithReset that can reset the output should be used.

Approximation of the derivative term

The derivative of the control error d ⁄ dt e(t) is approximated using

d⁄dt x(t) = (e(t)-x(t)) Nd ⁄ Td,

and

d⁄dt e(t) ≈ Nd (e(t)-x(t)),

where x(t) is an internal state.

Guidance for tuning the control gains

The parameters of the controller can be manually adjusted by performing closed loop tests (= controller + plant connected together) and using the following strategy:

  1. Set very large limits, e.g., set ymax = 1000.
  2. Select a P-controller and manually enlarge the parameter k (the total gain of the controller) until the closed-loop response cannot be improved any more.
  3. Select a PI-controller and manually adjust the parameters k and Ti (the time constant of the integrator). The first value of Ti can be selected such that it is in the order of the time constant of the oscillations occurring with the P-controller. If, e.g., oscillations in the order of 100 seconds occur in the previous step, start with Ti=1/100 seconds.
  4. If you want to make the reaction of the control loop faster (but probably less robust against disturbances and measurement noise) select a PID-controller and manually adjust parameters k, Ti, Td (time constant of derivative block).
  5. Set the limits yMax and yMin according to your specification.
  6. Perform simulations such that the output of the PID controller goes in its limits. Tune Ni (Ni Ti is the time constant of the anti-windup compensation) such that the input to the limiter block (= lim.u) goes quickly enough back to its limits. If Ni is decreased, this happens faster. If Ni is very large, the anti-windup compensation is not effective and the controller works bad.

References

R. Montgomery and R. McDowall (2008). "Fundamentals of HVAC Control Systems." American Society of Heating Refrigerating and Air-Conditioning Engineers Inc. Atlanta, GA.

Parameters

TypeNameDefaultDescription
SimpleControllercontrollerTypeBuildings.Controls.OBC.CDL.T...Type of controller
Realr1Typical range of control error, used for scaling the control error
BooleanreverseActingtrueSet to true for reverse acting, or false for direct acting control action
Control gains
Realk1Gain of controller
RealTi0.5Time constant of integrator block [s]
RealTd0.1Time constant of derivative block [s]
Limits
RealyMax1Upper limit of output
RealyMin0Lower limit of output
Advanced
Integrator anti-windup
RealNi0.9Ni*Ti is time constant of anti-windup compensation
Derivative block
RealNd10The higher Nd, the more ideal the derivative block
Initialization
Realxi_start0Initial value of integrator state
Realyd_start0Initial value of derivative output

Connectors

TypeNameDescription
input RealInputu_sConnector of setpoint input signal
input RealInputu_mConnector of measurement input signal
output RealOutputyConnector of actuator output signal

Modelica definition

block PID "P, PI, PD, and PID controller" parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"; parameter Real k( min=100*Constants.eps)=1 "Gain of controller"; parameter Real Ti( final quantity="Time", final unit="s", min=100*Constants.eps)=0.5 "Time constant of integrator block"; parameter Real Td( final quantity="Time", final unit="s", min=100*Constants.eps)=0.1 "Time constant of derivative block"; parameter Real r( min=100*Constants.eps)=1 "Typical range of control error, used for scaling the control error"; parameter Real yMax=1 "Upper limit of output"; parameter Real yMin=0 "Lower limit of output"; parameter Real Ni( min=100*Constants.eps)=0.9 "Ni*Ti is time constant of anti-windup compensation"; parameter Real Nd( min=100*Constants.eps)=10 "The higher Nd, the more ideal the derivative block"; parameter Real xi_start=0 "Initial value of integrator state"; parameter Real yd_start=0 "Initial value of derivative output"; parameter Boolean reverseActing=true "Set to true for reverse acting, or false for direct acting control action"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s "Connector of setpoint input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_m "Connector of measurement input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of actuator output signal"; Buildings.Controls.OBC.CDL.Reals.Subtract controlError "Control error (set point - measurement)"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter P(final k=k) "Gain for proportional control action"; Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset I( final k=k/Ti, final y_start=xi_start) if with_I "Integral term"; Buildings.Controls.OBC.CDL.Reals.Derivative D( final y_start=yd_start) if with_D "Derivative term"; Buildings.Controls.OBC.CDL.Reals.Subtract errP "P error"; Buildings.Controls.OBC.CDL.Reals.Subtract errD if with_D "D error"; Buildings.Controls.OBC.CDL.Reals.Subtract errI1 if with_I "I error (before anti-windup compensation)"; Buildings.Controls.OBC.CDL.Reals.Subtract errI2 if with_I "I error (after anti-windup compensation)"; Buildings.Controls.OBC.CDL.Reals.Limiter lim( final uMax=yMax, final uMin=yMin) "Limiter"; protected final parameter Real revAct= if reverseActing then 1 else -1 "Switch for sign for reverse or direct acting controller"; final parameter Boolean with_I=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PI or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Boolean flag to enable integral action"; final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PD or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Boolean flag to enable derivative action"; Sources.Constant kDer(k=k*Td) if with_D "Gain for derivative block"; Sources.Constant TDer(k=Td/Nd) if with_D "Time constant for approximation in derivative block"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant Dzero( final k=0) if not with_D "Zero input signal"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uS_revAct( final k=revAct/r) "Set point multiplied by reverse action sign"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uMea_revAct( final k=revAct/r) "Set point multiplied by reverse action sign"; Buildings.Controls.OBC.CDL.Reals.Add addPD "Outputs P and D gains added"; Buildings.Controls.OBC.CDL.Reals.Add addPID "Outputs P, I and D gains added"; Buildings.Controls.OBC.CDL.Reals.Subtract antWinErr if with_I "Error for anti-windup compensation"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter antWinGai(k=1/(k*Ni)) if with_I "Gain for anti-windup compensation"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant cheYMinMax( final k=yMin < yMax) "Check for values of yMin and yMax"; Buildings.Controls.OBC.CDL.Utilities.Assert assMesYMinMax( message="LimPID: Limits must be yMin < yMax") "Assertion on yMin and yMax"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant Izero( final k=0) if not with_I "Zero input signal"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant con( final k=0) if with_I "Constant zero"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1( final k=false) if with_I "Constant false"; equation connect(u_s,uS_revAct.u); connect(u_m,uMea_revAct.u); connect(D.u,errD.y); connect(errI1.u1,uS_revAct.y); connect(addPID.u1,addPD.y); connect(lim.y,y); connect(antWinErr.y,antWinGai.u); connect(addPD.u2,Dzero.y); connect(D.y,addPD.u2); connect(addPID.u2,I.y); connect(antWinErr.u2,lim.y); connect(I.u,errI2.y); connect(errI1.y,errI2.u1); connect(cheYMinMax.y,assMesYMinMax.u); connect(Izero.y,addPID.u2); connect(con.y,I.y_reset_in); connect(con1.y,I.trigger); connect(uS_revAct.y,errP.u1); connect(errD.u1,uS_revAct.y); connect(addPD.u1, P.y); connect(P.u, errP.y); connect(addPID.y, lim.u); connect(addPID.y, antWinErr.u1); connect(u_s, controlError.u1); connect(u_m, controlError.u2); connect(uMea_revAct.y, errP.u2); connect(uMea_revAct.y, errD.u2); connect(uMea_revAct.y, errI1.u2); connect(antWinGai.y, errI2.u2); connect(kDer.y, D.k); connect(TDer.y, D.T); end PID;

Buildings.Controls.OBC.CDL.Reals.PIDWithReset Buildings.Controls.OBC.CDL.Reals.PIDWithReset

P, PI, PD, and PID controller with output reset

Buildings.Controls.OBC.CDL.Reals.PIDWithReset

Information

PID controller in the standard form

yu = k/r   (e(t) + 1 ⁄ Ti   ∫ e(τ) dτ + Td d⁄dt e(t)),

with output reset, where yu is the control signal before output limitation, e(t) = us(t) - um(t) is the control error, with us being the set point and um being the measured quantity, k is the gain, Ti is the time constant of the integral term, Td is the time constant of the derivative term, and r is a scaling factor, with default r=1. The scaling factor should be set to the typical order of magnitude of the range of the error e. For example, you may set r=100 to r=1000 if the control input is a pressure of a heating water circulation pump in units of Pascal, or leave r=1 if the control input is a room temperature.

Note that the units of k are the inverse of the units of the control error, while the units of Ti and Td are seconds.

The actual control output is

y = min( ymax, max( ymin, y)),

where ymin and ymax are limits for the control signal.

P, PI, PD, or PID action

Through the parameter controllerType, the controller can be configured as P, PI, PD or PID controller. The default configuration is PI.

Reverse or direct action

Through the parameter reverseActing, the controller can be configured to be reverse or direct acting. The above standard form is reverse acting, which is the default configuration. For a reverse acting controller, for a constant set point, an increase in measurement signal u_m decreases the control output signal y (Montgomery and McDowall, 2008). Thus,

If reverseAction=false, then the error e above is multiplied by -1.

Anti-windup compensation

The controller anti-windup compensation is as follows: Instead of the above basic control law, the implementation is

yu = k   (e(t) ⁄ r + 1 ⁄ Ti   ∫ (-Δy + e(τ) ⁄ r) dτ + Td ⁄ r d⁄dt e(t)),

where the anti-windup compensation Δy is

Δy = (yu - y) ⁄ (k Ni),

where Ni > 0 is the time constant for the anti-windup compensation. To accelerate the anti-windup, decrease Ni.

Note that the anti-windup term (-Δy + e(τ) ⁄ r) shows that the range of the typical control error r should be set to a reasonable value so that

e(τ) ⁄ r = (us(τ) - um(τ)) ⁄ r

has order of magnitude one, and hence the anti-windup compensation should work well.

Reset of the controller output

Whenever the value of boolean input signal trigger changes from false to true, the controller output is reset by setting y to the value of the parameter y_reset.

Approximation of the derivative term

The derivative of the control error d ⁄ dt e(t) is approximated using

d⁄dt x(t) = (e(t)-x(t)) Nd ⁄ Td,

and

d⁄dt e(t) ≈ Nd (e(t)-x(t)),

where x(t) is an internal state.

Guidance for tuning the control gains

The parameters of the controller can be manually adjusted by performing closed loop tests (= controller + plant connected together) and using the following strategy:

  1. Set very large limits, e.g., set ymax = 1000.
  2. Select a P-controller and manually enlarge the parameter k (the total gain of the controller) until the closed-loop response cannot be improved any more.
  3. Select a PI-controller and manually adjust the parameters k and Ti (the time constant of the integrator). The first value of Ti can be selected such that it is in the order of the time constant of the oscillations occurring with the P-controller. If, e.g., oscillations in the order of 100 seconds occur in the previous step, start with Ti=1/100 seconds.
  4. If you want to make the reaction of the control loop faster (but probably less robust against disturbances and measurement noise) select a PID-controller and manually adjust parameters k, Ti, Td (time constant of derivative block).
  5. Set the limits yMax and yMin according to your specification.
  6. Perform simulations such that the output of the PID controller goes in its limits. Tune Ni (Ni Ti is the time constant of the anti-windup compensation) such that the input to the limiter block (= lim.u) goes quickly enough back to its limits. If Ni is decreased, this happens faster. If Ni is very large, the anti-windup compensation is not effective and the controller works bad.

References

R. Montgomery and R. McDowall (2008). "Fundamentals of HVAC Control Systems." American Society of Heating Refrigerating and Air-Conditioning Engineers Inc. Atlanta, GA.

Parameters

TypeNameDefaultDescription
SimpleControllercontrollerTypeBuildings.Controls.OBC.CDL.T...Type of controller
Realr1Typical range of control error, used for scaling the control error
BooleanreverseActingtrueSet to true for reverse acting, or false for direct acting control action
Control gains
Realk1Gain of controller
RealTi0.5Time constant of integrator block [s]
RealTd0.1Time constant of derivative block [s]
Limits
RealyMax1Upper limit of output
RealyMin0Lower limit of output
Integrator reset
Realy_resetxi_startValue to which the controller output is reset if the boolean trigger has a rising edge
Advanced
Integrator anti-windup
RealNi0.9Ni*Ti is time constant of anti-windup compensation
Derivative block
RealNd10The higher Nd, the more ideal the derivative block
Initialization
Realxi_start0Initial value of integrator state
Realyd_start0Initial value of derivative output

Connectors

TypeNameDescription
input RealInputu_sConnector of setpoint input signal
input RealInputu_mConnector of measurement input signal
output RealOutputyConnector of actuator output signal
input BooleanInputtriggerResets the controller output when trigger becomes true

Modelica definition

block PIDWithReset "P, PI, PD, and PID controller with output reset" parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"; parameter Real k( min=100*Constants.eps)=1 "Gain of controller"; parameter Real Ti( final quantity="Time", final unit="s", min=100*Constants.eps)=0.5 "Time constant of integrator block"; parameter Real Td( final quantity="Time", final unit="s", min=100*Constants.eps)=0.1 "Time constant of derivative block"; parameter Real r( min=100*Constants.eps)=1 "Typical range of control error, used for scaling the control error"; parameter Real yMax=1 "Upper limit of output"; parameter Real yMin=0 "Lower limit of output"; parameter Real Ni( min=100*Constants.eps)=0.9 "Ni*Ti is time constant of anti-windup compensation"; parameter Real Nd( min=100*Constants.eps)=10 "The higher Nd, the more ideal the derivative block"; parameter Real xi_start=0 "Initial value of integrator state"; parameter Real yd_start=0 "Initial value of derivative output"; parameter Boolean reverseActing=true "Set to true for reverse acting, or false for direct acting control action"; parameter Real y_reset=xi_start "Value to which the controller output is reset if the boolean trigger has a rising edge"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s "Connector of setpoint input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u_m "Connector of measurement input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of actuator output signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger "Resets the controller output when trigger becomes true"; Buildings.Controls.OBC.CDL.Reals.Subtract controlError "Control error (set point - measurement)"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter P(final k=k) "Proportional action"; Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset I( final k=k/Ti, final y_start=xi_start) if with_I "Integral term"; Buildings.Controls.OBC.CDL.Reals.Derivative D( final y_start=yd_start) if with_D "Derivative term"; Buildings.Controls.OBC.CDL.Reals.Subtract errP "P error"; Buildings.Controls.OBC.CDL.Reals.Subtract errD if with_D "D error"; Buildings.Controls.OBC.CDL.Reals.Subtract errI1 if with_I "I error (before anti-windup compensation)"; Buildings.Controls.OBC.CDL.Reals.Subtract errI2 if with_I "I error (after anti-windup compensation)"; Buildings.Controls.OBC.CDL.Reals.Limiter lim( final uMax=yMax, final uMin=yMin) "Limiter"; protected final parameter Real revAct= if reverseActing then 1 else -1 "Switch for sign for reverse or direct acting controller"; final parameter Boolean with_I=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PI or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Boolean flag to enable integral action"; final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PD or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Boolean flag to enable derivative action"; Sources.Constant kDer(k=k*Td) if with_D "Gain for derivative block"; Sources.Constant TDer(k=Td/Nd) if with_D "Time constant for approximation in derivative block"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant Dzero( final k=0) if not with_D "Zero input signal"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant Izero( final k=0) if not with_I "Zero input signal"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uS_revAct( final k=revAct/r) "Set point multiplied by reverse action sign"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uMea_revAct( final k=revAct/r) "Set point multiplied by reverse action sign"; Buildings.Controls.OBC.CDL.Reals.Add addPD "Outputs P and D gains added"; Buildings.Controls.OBC.CDL.Reals.Add addPID "Outputs P, I and D gains added"; Buildings.Controls.OBC.CDL.Reals.Subtract antWinErr if with_I "Error for anti-windup compensation"; Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter antWinGai( k=1/(k*Ni)) if with_I "Gain for anti-windup compensation"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant yResSig( final k=y_reset) if with_I "Signal for y_reset"; Buildings.Controls.OBC.CDL.Reals.Subtract addRes if with_I "Adder for integrator reset"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant cheYMinMax( final k=yMin < yMax) "Check for values of yMin and yMax"; Buildings.Controls.OBC.CDL.Utilities.Assert assMesYMinMax( message="LimPID: Limits must be yMin < yMax") "Assertion on yMin and yMax"; equation connect(trigger,I.trigger); connect(u_s,uS_revAct.u); connect(u_m,uMea_revAct.u); connect(errD.u2,uMea_revAct.y); connect(D.u,errD.y); connect(errI1.u1,uS_revAct.y); connect(addPID.u1,addPD.y); connect(lim.y,y); connect(antWinErr.y,antWinGai.u); connect(addPD.u2,Dzero.y); connect(D.y,addPD.u2); connect(addPID.u2,I.y); connect(addRes.y,I.y_reset_in); connect(antWinErr.u2,lim.y); connect(I.u,errI2.y); connect(errI1.y,errI2.u1); connect(controlError.u1,u_s); connect(cheYMinMax.y,assMesYMinMax.u); connect(Izero.y,addPID.u2); connect(errP.u1,uS_revAct.y); connect(errD.u1,uS_revAct.y); connect(addPD.u1, P.y); connect(P.u, errP.y); connect(addPID.y, lim.u); connect(addPID.y, antWinErr.u1); connect(addRes.u1, yResSig.y); connect(u_m, controlError.u2); connect(uMea_revAct.y, errP.u2); connect(uMea_revAct.y, errI1.u2); connect(antWinGai.y, errI2.u2); connect(addPD.y, addRes.u2); connect(kDer.y, D.k); connect(TDer.y, D.T); end PIDWithReset;

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

Limit the changing rate of the input

Buildings.Controls.OBC.CDL.Reals.Ramp

Information

Block that limits the rate of change of the input u by a ramp if the boolean input active is true, otherwise the block outputs y = u.

This block computes a threshold for the rate of change between input u and output y as thr = (u-y)/Td, where Td > 0 is a parameter. The output y is computed as follows:

A smaller time constant Td means a higher accuracy for the derivative approximation.

Note that when the input activate switches to false, the output y can have a discontinuity.

Implementation

For the block to work with arbitrary inputs and in order to produce a differentiable output, the input is numerically differentiated with derivative time constant Td.

Parameters

TypeNameDefaultDescription
RealraisingSlewRate Maximum speed with which to increase the output [1/s]
RealfallingSlewRate-raisingSlewRateMaximum speed with which to decrease the output [1/s]
RealTdraisingSlewRate*0.001Derivative time constant [s]

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
input BooleanInputactiveSet to true to enable rate limiter
output RealOutputyConnector of Real output signal

Modelica definition

block Ramp "Limit the changing rate of the input" parameter Real raisingSlewRate( min=Constants.small, unit="1/s") "Maximum speed with which to increase the output"; parameter Real fallingSlewRate( max=-Constants.small, unit="1/s")=-raisingSlewRate "Maximum speed with which to decrease the output"; parameter Real Td( final quantity="Time", final unit="s", min=Constants.eps)=raisingSlewRate*0.001 "Derivative time constant"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput active "Set to true to enable rate limiter"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"; protected Real thr=(u-y)/Td "Approximation to derivative between input and output"; Real y_internal "Internal variable to track the slew limited value"; initial equation assert( raisingSlewRate > 0, "raisingSlewRate must be larger than zero."); assert( fallingSlewRate < 0, "fallingSlewRate must be less than zero."); y_internal = u; equation when active then reinit(y_internal, u); end when; der(y_internal)=smooth(1, noEvent( if thr < fallingSlewRate then fallingSlewRate else if thr > raisingSlewRate then raisingSlewRate else thr)); y = if active then y_internal else u; end Ramp;

Buildings.Controls.OBC.CDL.Reals.Round Buildings.Controls.OBC.CDL.Reals.Round

Round real number to given digits

Buildings.Controls.OBC.CDL.Reals.Round

Information

Block that outputs the input after rounding it to n digits.

For example,

Hence, the block outputs

    y = floor(u*(10^n) + 0.5)/(10^n)  for  u > 0,
    y = ceil(u*(10^n) - 0.5)/(10^n)   for  u < 0.

Parameters

TypeNameDefaultDescription
Integern Number of digits being round to

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Round "Round real number to given digits" parameter Integer n "Number of digits being round to"; Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; protected parameter Real fac=10^n "Factor used for rounding"; equation y=if (u > 0) then floor( u*fac+0.5)/fac else ceil( u*fac-0.5)/fac; end Round;

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

Output the sine of the input

Buildings.Controls.OBC.CDL.Reals.Sin

Information

Block that outputs y = sin(u), where u is an input.

sin.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal [rad]
output RealOutputyConnector of Real output signal

Modelica definition

block Sin "Output the sine of the input" Interfaces.RealInput u(unit="rad") "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.sin(u); end Sin;

Buildings.Controls.OBC.CDL.Reals.Sort Buildings.Controls.OBC.CDL.Reals.Sort

Sort elements of input vector in ascending or descending order

Buildings.Controls.OBC.CDL.Reals.Sort

Information

Block that sorts the elements of the input signal u. If the parameter ascending = true, then the output signal satisfies yi <= yi+1 for all i ∈ {1, ..., n-1}. Otherwise, it satisfies yi >= yi+1 for all i ∈ {1, ..., n-1}.

Usage

Note that this block shall only be used for input signals u that are time sampled.
Otherwise, in simulation, numerical noise from a nonlinear solver or from an implicit time integration algorithm may cause the simulation to stall. Numerical noise can be present if an input depends on a state variable or a quantity that requires an iterative solution, such as a temperature or a mass flow rate of an HVAC system.
In real controllers, measurement noise may cause the output to change frequently.

This block may for example be used in a variable air volume flow controller to access the position of the dampers that are most open.

Parameters

TypeNameDefaultDescription
BooleanascendingtrueSet to true if ascending order, otherwise order is descending

Connectors

TypeNameDescription
input RealInputu[nin]Connector of Real input signals
output RealOutputy[nin]Connector of Real output signals

Modelica definition

block Sort "Sort elements of input vector in ascending or descending order" parameter Integer nin( final min=0)=0 "Number of input connections"; parameter Boolean ascending=true "Set to true if ascending order, otherwise order is descending"; Interfaces.RealInput u[nin] "Connector of Real input signals"; Interfaces.RealOutput y[nin] "Connector of Real output signals"; equation y=Modelica.Math.Vectors.sort( u, ascending=ascending); end Sort;

Buildings.Controls.OBC.CDL.Reals.Sqrt Buildings.Controls.OBC.CDL.Reals.Sqrt

Output the square root of the input (input >= 0 required)

Buildings.Controls.OBC.CDL.Reals.Sqrt

Information

Block that outputs square root of the input y = sqrt(u), where u is an input. All elements of the input vector shall be non-negative.

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

block Sqrt "Output the square root of the input (input >= 0 required)" Interfaces.RealInput u "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=sqrt(u); end Sqrt;

Buildings.Controls.OBC.CDL.Reals.Subtract Buildings.Controls.OBC.CDL.Reals.Subtract

Output the difference of the two inputs

Buildings.Controls.OBC.CDL.Reals.Subtract

Information

Block that outputs y as the difference of the two input signals u1 and u2,

    y = u1 - u2

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block Subtract "Output the difference of the two inputs" Interfaces.RealInput u1 "Connector of Real input signal 1"; Interfaces.RealInput u2 "Connector of Real input signal 2"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=u1-u2; end Subtract;

Buildings.Controls.OBC.CDL.Reals.Switch Buildings.Controls.OBC.CDL.Reals.Switch

Switch between two Real signals

Buildings.Controls.OBC.CDL.Reals.Switch

Information

Block that outputs one of two real input signals based on a boolean input signal.

If the input signal u2 is true, the block outputs y = u1. Otherwise, it outputs y = u3.

Connectors

TypeNameDescription
input RealInputu1Real input signal
input BooleanInputu2Boolean switch input signal, if true, y=u1, else y=u3
input RealInputu3Real input signal
output RealOutputyReal output signal

Modelica definition

block Switch "Switch between two Real signals" Interfaces.RealInput u1 "Real input signal"; Interfaces.BooleanInput u2 "Boolean switch input signal, if true, y=u1, else y=u3"; Interfaces.RealInput u3 "Real input signal"; Interfaces.RealOutput y "Real output signal"; equation y=smooth(0, if u2 then u1 else u3); end Switch;

Buildings.Controls.OBC.CDL.Reals.Tan Buildings.Controls.OBC.CDL.Reals.Tan

Output the tangent of the input

Buildings.Controls.OBC.CDL.Reals.Tan

Information

Block that outputs y = tan(u), where u is an input.

tan.png

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal [rad]
output RealOutputyConnector of Real output signal

Modelica definition

block Tan "Output the tangent of the input" Interfaces.RealInput u(unit="rad") "Connector of Real input signal"; Interfaces.RealOutput y "Connector of Real output signal"; equation y=Modelica.Math.tan(u); end Tan;

Buildings.Controls.OBC.CDL.Reals.Greater.GreaterWithHysteresis Buildings.Controls.OBC.CDL.Reals.Greater.GreaterWithHysteresis

Greater block without hysteresis

Buildings.Controls.OBC.CDL.Reals.Greater.GreaterWithHysteresis

Parameters

TypeNameDefaultDescription
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block GreaterWithHysteresis "Greater block without hysteresis" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u1 > u2 or pre(y) and u1 > u2-h); end GreaterWithHysteresis;

Buildings.Controls.OBC.CDL.Reals.Greater.GreaterNoHysteresis Buildings.Controls.OBC.CDL.Reals.Greater.GreaterNoHysteresis

Greater block without hysteresis

Buildings.Controls.OBC.CDL.Reals.Greater.GreaterNoHysteresis

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block GreaterNoHysteresis "Greater block without hysteresis" Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; equation y=u1 > u2; end GreaterNoHysteresis;

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterWithHysteresis Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterWithHysteresis

Greater block without hysteresis

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterWithHysteresis

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputuInput u
output BooleanOutputyOutput y

Modelica definition

block GreaterWithHysteresis "Greater block without hysteresis" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u > t or pre(y) and u > t-h); end GreaterWithHysteresis;

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterNoHysteresis Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterNoHysteresis

Greater block without hysteresis

Buildings.Controls.OBC.CDL.Reals.GreaterThreshold.GreaterNoHysteresis

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison

Connectors

TypeNameDescription
input RealInputuInput u
output BooleanOutputyOutput y

Modelica definition

block GreaterNoHysteresis "Greater block without hysteresis" parameter Real t=0 "Threshold for comparison"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; equation y=u > t; end GreaterNoHysteresis;

Buildings.Controls.OBC.CDL.Reals.Less.LessWithHysteresis Buildings.Controls.OBC.CDL.Reals.Less.LessWithHysteresis

Less block without hysteresis

Buildings.Controls.OBC.CDL.Reals.Less.LessWithHysteresis

Parameters

TypeNameDefaultDescription
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block LessWithHysteresis "Less block without hysteresis" parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u1 < u2 or pre(y) and u1 < u2+h); end LessWithHysteresis;

Buildings.Controls.OBC.CDL.Reals.Less.LessNoHysteresis Buildings.Controls.OBC.CDL.Reals.Less.LessNoHysteresis

Less block without hysteresis

Buildings.Controls.OBC.CDL.Reals.Less.LessNoHysteresis

Connectors

TypeNameDescription
input RealInputu1Input u1
input RealInputu2Input u2
output BooleanOutputyOutput y

Modelica definition

block LessNoHysteresis "Less block without hysteresis" Interfaces.RealInput u1 "Input u1"; Interfaces.RealInput u2 "Input u2"; Interfaces.BooleanOutput y "Output y"; equation y=u1 < u2; end LessNoHysteresis;

Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessWithHysteresis Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessWithHysteresis

Less block without hysteresis

Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessWithHysteresis

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison
Realh0Hysteresis
Advanced
Booleanpre_y_startfalseValue of pre(y) at initial time

Connectors

TypeNameDescription
input RealInputuInput u
output BooleanOutputyOutput y

Modelica definition

block LessWithHysteresis "Less block without hysteresis" parameter Real t=0 "Threshold for comparison"; parameter Real h( final min=0)=0 "Hysteresis"; parameter Boolean pre_y_start=false "Value of pre(y) at initial time"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; initial equation assert( h >= 0, "Hysteresis must not be negative"); pre(y)=pre_y_start; equation y=(not pre(y) and u < t or pre(y) and u < t+h); end LessWithHysteresis;

Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessNoHysteresis Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessNoHysteresis

Less block without hysteresis

Buildings.Controls.OBC.CDL.Reals.LessThreshold.LessNoHysteresis

Parameters

TypeNameDefaultDescription
Realt0Threshold for comparison

Connectors

TypeNameDescription
input RealInputuInput u
output BooleanOutputyOutput y

Modelica definition

block LessNoHysteresis "Less block without hysteresis" parameter Real t=0 "Threshold for comparison"; Interfaces.RealInput u "Input u"; Interfaces.BooleanOutput y "Output y"; equation y=u < t; end LessNoHysteresis;