Buildings.Templates.Plants.Controls.Utilities

Package with utility blocks

Information

This package contains utility blocks that are used to implement the control sequences within Buildings.Templates.Plants.Controls.

Package Content

Name Description
Buildings.Templates.Plants.Controls.Utilities.CountTrue CountTrue Output the number of true elements in a Boolean array
Buildings.Templates.Plants.Controls.Utilities.FirstTrueIndex FirstTrueIndex  
Buildings.Templates.Plants.Controls.Utilities.HoldReal HoldReal Hold value of real signal based on timer and Boolean signal
Buildings.Templates.Plants.Controls.Utilities.LastTrueIndex LastTrueIndex  
Buildings.Templates.Plants.Controls.Utilities.MultiMaxInteger MultiMaxInteger Output the maximum element of the input vector
Buildings.Templates.Plants.Controls.Utilities.MultiMinInteger MultiMinInteger Output the minimum element of the input vector
Buildings.Templates.Plants.Controls.Utilities.PIDWithEnable PIDWithEnable PID controller with enable signal
Buildings.Templates.Plants.Controls.Utilities.PlaceholderInteger PlaceholderInteger Output a placeholder signal
Buildings.Templates.Plants.Controls.Utilities.PlaceholderLogical PlaceholderLogical Output a placeholder signal
Buildings.Templates.Plants.Controls.Utilities.PlaceholderReal PlaceholderReal Output a placeholder signal
Buildings.Templates.Plants.Controls.Utilities.SortWithIndices SortWithIndices Sort elements of input vector in ascending or descending order
Buildings.Templates.Plants.Controls.Utilities.StageIndex StageIndex Evaluation of stage index from staging signals
Buildings.Templates.Plants.Controls.Utilities.TimerWithReset TimerWithReset Timer measuring the time from the time instant where the Boolean input became true
Buildings.Templates.Plants.Controls.Utilities.TrueArrayConditional TrueArrayConditional Output a Boolean array with a given number of true elements and a priority order
Buildings.Templates.Plants.Controls.Utilities.Validation Validation Collection of validation models

Buildings.Templates.Plants.Controls.Utilities.CountTrue Buildings.Templates.Plants.Controls.Utilities.CountTrue

Output the number of true elements in a Boolean array

Buildings.Templates.Plants.Controls.Utilities.CountTrue

Information

Counts the number of true elements in the Boolean input vector.

Connectors

TypeNameDescription
input BooleanInputu1[nin]Array of Boolean signals
output IntegerOutputyIndex of first element being true

Modelica definition

block CountTrue "Output the number of true elements in a Boolean array" parameter Integer nin( min=0)=0 "Size of input array"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1[nin] "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Index of first element being true"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt[nin]( each final integerTrue=1, each final integerFalse=0) "Cast to integer"; Buildings.Controls.OBC.CDL.Integers.MultiSum sumMul( final nin=nin) "Sum over array elements"; equation connect(u1, booToInt.u); connect(sumMul.y, y); connect(booToInt.y, sumMul.u); end CountTrue;

Buildings.Templates.Plants.Controls.Utilities.FirstTrueIndex Buildings.Templates.Plants.Controls.Utilities.FirstTrueIndex


Buildings.Templates.Plants.Controls.Utilities.FirstTrueIndex

Information

Returns the index of the first true element of the Boolean input vector. If no element is true, the block returns 0.

Connectors

TypeNameDescription
input BooleanInputu1[nin]Array of Boolean signals
output IntegerOutputyIndex of first element being true

Modelica definition

block FirstTrueIndex parameter Integer nin( min=0)=0 "Size of input array"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1[nin] "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Index of first element being true"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt[nin]( final integerTrue={i for i in 1:nin}, each final integerFalse=nin + 1) "Return index if element is true, 0 otherwise"; MultiMinInteger mulMin(nin=nin) "Return minimum index"; Buildings.Controls.OBC.CDL.Integers.Equal intEqu; Buildings.Controls.OBC.CDL.Integers.Switch intSwi; Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt( k=nin + 1); Buildings.Controls.OBC.CDL.Integers.Sources.Constant zer( k=0); equation connect(booToInt.y, mulMin.u); connect(u1, booToInt.u); connect(conInt.y, intEqu.u2); connect(mulMin.y, intSwi.u3); connect(intEqu.y, intSwi.u2); connect(zer.y, intSwi.u1); connect(mulMin.y, intEqu.u1); connect(intSwi.y, y); end FirstTrueIndex;

Buildings.Templates.Plants.Controls.Utilities.HoldReal Buildings.Templates.Plants.Controls.Utilities.HoldReal

Hold value of real signal based on timer and Boolean signal

Buildings.Templates.Plants.Controls.Utilities.HoldReal

Information

Holds input value fixed at its last value while the Boolean signal u1 is true, and for at least the hold time dtHol.

Parameters

TypeNameDefaultDescription
RealdtHol0Hold time [s]

Connectors

TypeNameDescription
input BooleanInputu1Boolean signal that triggers fixed output value
input RealInputuInput signal
output RealOutputyOutput signal

Modelica definition

block HoldReal "Hold value of real signal based on timer and Boolean signal" parameter Real dtHol( final unit="s")=0 "Hold time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Boolean signal that triggers fixed output value"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Input signal"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Output signal"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam "Sample signal when the Boolean input switches to true"; Buildings.Controls.OBC.CDL.Reals.Switch swi "Switch between actual and fixed value"; Buildings.Controls.OBC.CDL.Logical.TrueHold truHol( final duration=dtHol) if dtHol > 0 "Hold true value of input signal for given time"; PlaceholderLogical ph(have_inp=dtHol > 0, final have_inpPh=true) "Placeholder signal in case of zero minimum hold time"; equation connect(u, triSam.u); connect(swi.y, y); connect(u1, triSam.trigger); connect(u1, truHol.u); connect(triSam.y, swi.u1); connect(u, swi.u3); connect(truHol.y, ph.u); connect(u1, ph.uPh); connect(ph.y, swi.u2); end HoldReal;

Buildings.Templates.Plants.Controls.Utilities.LastTrueIndex Buildings.Templates.Plants.Controls.Utilities.LastTrueIndex


Buildings.Templates.Plants.Controls.Utilities.LastTrueIndex

Information

Returns the index of the last true element of the Boolean input vector. If no element is true, the block returns 0.

Connectors

TypeNameDescription
input BooleanInputu1[nin]Array of Boolean signals
output IntegerOutputyIndex of first element being true

Modelica definition

block LastTrueIndex parameter Integer nin( min=0)=0 "Size of input array"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1[nin] "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Index of first element being true"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt[nin]( final integerTrue={i for i in 1:nin}, each final integerFalse=0) "Return index if element is true, 0 otherwise"; Buildings.Templates.Plants.Controls.Utilities.MultiMaxInteger mulMax(nin=nin) "Return minimum index"; equation connect(booToInt.y, mulMax.u); connect(u1, booToInt.u); connect(mulMax.y, y); end LastTrueIndex;

Buildings.Templates.Plants.Controls.Utilities.MultiMaxInteger Buildings.Templates.Plants.Controls.Utilities.MultiMaxInteger

Output the maximum element of the input vector

Buildings.Templates.Plants.Controls.Utilities.MultiMaxInteger

Information

Outputs the maximum element of the input vector.

Connectors

TypeNameDescription
input IntegerInputu[nin]Integer input signal
output IntegerOutputyInteger output signal

Modelica definition

block MultiMaxInteger "Output the maximum element of the input vector" parameter Integer nin( min=0)=0 "Size of input array"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin] "Integer input signal"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Integer output signal"; equation y=max(u); end MultiMaxInteger;

Buildings.Templates.Plants.Controls.Utilities.MultiMinInteger Buildings.Templates.Plants.Controls.Utilities.MultiMinInteger

Output the minimum element of the input vector

Buildings.Templates.Plants.Controls.Utilities.MultiMinInteger

Information

Outputs the minimum element of the input vector.

Connectors

TypeNameDescription
input IntegerInputu[nin]Integer input signal
output IntegerOutputyInteger output signal

Modelica definition

block MultiMinInteger "Output the minimum element of the input vector" parameter Integer nin( min=0)=0 "Size of input array"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin] "Integer input signal"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Integer output signal"; equation y=min(u); end MultiMinInteger;

Buildings.Templates.Plants.Controls.Utilities.PIDWithEnable Buildings.Templates.Plants.Controls.Utilities.PIDWithEnable

PID controller with enable signal

Buildings.Templates.Plants.Controls.Utilities.PIDWithEnable

Information

This is an update of Buildings.Controls.OBC.CDL.Reals.PIDWithReset with an additional enable signal provided as a Boolean input.

Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).

Parameters

TypeNameDefaultDescription
SimpleControllercontrollerTypeBuildings.Controls.OBC.CDL.T...Type of controller
Realk1Gain of controller
TimeTi0.5Time constant of integrator block [s]
TimeTd0.1Time constant of derivative block [s]
Realr1Typical range of control error, used for scaling the control error
RealyMin0Lower limit of output
RealyMax1Upper limit of output
BooleanreverseActingtrueSet to true for reverse acting, or false for direct acting control action
Realy_resetyMinValue to which the controller output is reset if the boolean trigger has a rising edge
Realy_neutraly_resetValue to which the controller output is reset when the controller is disabled

Connectors

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

Modelica definition

block PIDWithEnable "PID controller with enable signal" extends Modelica.Blocks.Icons.Block; parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType= Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"; parameter Real k( min=0)=1 "Gain of controller"; parameter Modelica.Units.SI.Time Ti( min=Buildings.Controls.OBC.CDL.Constants.small)=0.5 "Time constant of integrator block"; parameter Modelica.Units.SI.Time Td( min=0)=0.1 "Time constant of derivative block"; parameter Real r( min=100 * Modelica.Constants.eps)=1 "Typical range of control error, used for scaling the control error"; parameter Real yMin=0 "Lower limit of output"; parameter Real yMax=1 "Upper limit of output"; parameter Boolean reverseActing=true "Set to true for reverse acting, or false for direct acting control action"; parameter Real y_reset=yMin "Value to which the controller output is reset if the boolean trigger has a rising edge"; parameter Real y_neutral=y_reset "Value to which the controller output is reset when the controller is disabled"; 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 uEna "Enable signal"; Buildings.Controls.OBC.CDL.Reals.PIDWithReset conPID( final k=k, final Ti=Ti, final Td=Td, final r=r, final controllerType=controllerType, final yMin=yMin, final yMax=yMax, final reverseActing=reverseActing, final y_reset=y_reset); Buildings.Controls.OBC.CDL.Reals.Switch swi; Buildings.Controls.OBC.CDL.Reals.Switch swi1; Buildings.Controls.OBC.CDL.Reals.Sources.Constant valDis( final k=y_neutral) "Value when disabled"; equation connect(conPID.u_s, swi.y); connect(uEna, swi.u2); connect(u_s, swi.u1); connect(u_m, swi.u3); connect(uEna, conPID.trigger); connect(u_m, conPID.u_m); connect(conPID.y, swi1.u1); connect(swi1.y, y); connect(uEna, swi1.u2); connect(valDis.y, swi1.u3); end PIDWithEnable;

Buildings.Templates.Plants.Controls.Utilities.PlaceholderInteger Buildings.Templates.Plants.Controls.Utilities.PlaceholderInteger

Output a placeholder signal

Buildings.Templates.Plants.Controls.Utilities.PlaceholderInteger

Information

This block enables replacing a variable that is conditionally removed with either a parameter or another input variable.

Parameters

TypeNameDefaultDescription
Booleanhave_inptrueSet to true if input signal is available
Booleanhave_inpPhfalseSet to true if placeholder value is provided with input signal
Integeru_internal Placeholder value if input signal is not available

Connectors

TypeNameDescription
input IntegerInputuInput
input IntegerInputuPhInput
output IntegerOutputyOutput

Modelica definition

block PlaceholderInteger "Output a placeholder signal" parameter Boolean have_inp=true "Set to true if input signal is available"; parameter Boolean have_inpPh=false "Set to true if placeholder value is provided with input signal"; parameter Integer u_internal( start=0) "Placeholder value if input signal is not available"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u if have_inp "Input"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uPh if not have_inp and have_inpPh "Input"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Output"; Buildings.Controls.OBC.CDL.Integers.Sources.Constant ph(final k=u_internal) if not have_inp and not have_inpPh "Placeholder signal if input signal is not available"; equation connect(u, y); connect(uPh, y); connect(ph.y, y); end PlaceholderInteger;

Buildings.Templates.Plants.Controls.Utilities.PlaceholderLogical Buildings.Templates.Plants.Controls.Utilities.PlaceholderLogical

Output a placeholder signal

Buildings.Templates.Plants.Controls.Utilities.PlaceholderLogical

Information

This block enables replacing a variable that is conditionally removed with either a parameter or another input variable.

Parameters

TypeNameDefaultDescription
Booleanhave_inptrueSet to true if input signal is available
Booleanhave_inpPhfalseSet to true if placeholder value is provided with input signal
Booleanu_internal Placeholder value if input signal is not available

Connectors

TypeNameDescription
input BooleanInputuInput
input BooleanInputuPhInput
output BooleanOutputyOutput

Modelica definition

block PlaceholderLogical "Output a placeholder signal" parameter Boolean have_inp=true "Set to true if input signal is available"; parameter Boolean have_inpPh=false "Set to true if placeholder value is provided with input signal"; parameter Boolean u_internal(start=true) "Placeholder value if input signal is not available"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u if have_inp "Input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uPh if not have_inp and have_inpPh "Input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant ph(final k=u_internal) if not have_inp and not have_inpPh "Placeholder signal if input signal is not available"; equation connect(u, y); connect(ph.y, y); connect(uPh, y); end PlaceholderLogical;

Buildings.Templates.Plants.Controls.Utilities.PlaceholderReal Buildings.Templates.Plants.Controls.Utilities.PlaceholderReal

Output a placeholder signal

Buildings.Templates.Plants.Controls.Utilities.PlaceholderReal

Information

This block enables replacing a variable that is conditionally removed with either a parameter or another input variable.

Parameters

TypeNameDefaultDescription
Booleanhave_inptrueSet to true if input signal is available
Booleanhave_inpPhfalseSet to true if placeholder value is provided with input signal
Realu_internal Placeholder value if input signal is not available

Connectors

TypeNameDescription
input RealInputuInput
input RealInputuPhInput
output RealOutputyOutput

Modelica definition

block PlaceholderReal "Output a placeholder signal" parameter Boolean have_inp=true "Set to true if input signal is available"; parameter Boolean have_inpPh=false "Set to true if placeholder value is provided with input signal"; parameter Real u_internal( start=0) "Placeholder value if input signal is not available"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u if have_inp "Input"; Buildings.Controls.OBC.CDL.Interfaces.RealInput uPh if not have_inp and have_inpPh "Input"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Output"; Buildings.Controls.OBC.CDL.Reals.Sources.Constant ph(final k=u_internal) if not have_inp and not have_inpPh "Placeholder signal if input signal is not available"; equation connect(u, y); connect(ph.y, y); connect(uPh, y); end PlaceholderReal;

Buildings.Templates.Plants.Controls.Utilities.SortWithIndices Buildings.Templates.Plants.Controls.Utilities.SortWithIndices

Sort elements of input vector in ascending or descending order

Buildings.Templates.Plants.Controls.Utilities.SortWithIndices

Information

Block that sorts the elements of the input signal u. If the parameter ascending = true, then the output signal y satisfies yi <= yi+1 for all i ∈ {1, ..., n-1}. Otherwise, it satisfies yi >= yi+1 for all i ∈ {1, ..., n-1}. The output signal yIdx contains the indices of the sorted elements, with respect to the input vector u.

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]Sorted vector
output IntegerOutputyIdx[nin]Indices of the sorted vector with respect to the original vector

Modelica definition

block SortWithIndices "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"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin] "Connector of Real input signals"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nin] "Sorted vector"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yIdx[nin] "Indices of the sorted vector with respect to the original vector"; equation (y, yIdx)=Modelica.Math.Vectors.sort(u, ascending=ascending); end SortWithIndices;

Buildings.Templates.Plants.Controls.Utilities.StageIndex Buildings.Templates.Plants.Controls.Utilities.StageIndex

Evaluation of stage index from staging signals

Buildings.Templates.Plants.Controls.Utilities.StageIndex

Information

This block is used to compute the stage index for a group of multiple equipment such as CHW pumps or chillers.

Unavailable stages are handled by the following requirements.

Caveats

The only way to transition to stage 0 is by disabling the lead unit (u1Lea = false). The stage down command u1Dow cannot be used to transition below stage 1.

When the current stage becomes unavailable, the transition to the next higher available stage is triggered. However, it can happen that equipment that is enabled at the current stage is no longer available while the current stage is not deemed unavailable – for example if a lead/lag alternate equipment remains available. In this case, the equipment rotation logic must stage on the lead/lag alternate equipment to replace the faulty equipment.

Parameters

TypeNameDefaultDescription
Booleanhave_inpAvatrueSet to true if stage availability is provided with input signal, false for stages always available
IntegernSta Number of stages
RealdtRun0Minimum runtime of each stage [s]

Connectors

TypeNameDescription
input BooleanInputu1LeaLead unit enable signal
input BooleanInputu1UpStage up command
input BooleanInputu1DowStage down command
input BooleanInputu1AvaSta[nSta]Stage available signal
output IntegerOutputyStage index

Modelica definition

block StageIndex "Evaluation of stage index from staging signals" parameter Boolean have_inpAva=true "Set to true if stage availability is provided with input signal, false for stages always available"; parameter Integer nSta( start=1, final min=1) "Number of stages"; parameter Real dtRun( final unit="s", final min=0, displayUnit="min")=0 "Minimum runtime of each stage"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Lea "Lead unit enable signal"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Up "Stage up command"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Dow "Stage down command"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1AvaSta[nSta] if have_inpAva "Stage available signal"; Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y "Stage index"; Modelica.StateGraph.InitialStepWithSignal sta0( final nOut=nSta, final nIn=nSta) "Stage 0 – All units disabled"; Modelica.StateGraph.StepWithSignal sta[nSta]( each final nIn=nSta + 1, each final nOut=nSta + 1) "Stage i>0"; Modelica.StateGraph.TransitionWithSignal sta0ToSta[nSta]( each final enableTimer=false) "Transition from stage 0 to stage i>0"; inner Modelica.StateGraph.StateGraphRoot stateGraphRoot "State graph root"; Modelica.StateGraph.TransitionWithSignal staToSta[nSta, nSta]( each final enableTimer=false) "Transition to higher or lower stage"; Buildings.Controls.OBC.CDL.Logical.And runAndTrn[nSta] "Runtime condition met AND stage transition command"; Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator rep( final nout=nSta) "Replicate"; Modelica.StateGraph.TransitionWithSignal staToSta0[nSta]( each final enableTimer=false) "Transition from stage i>0 to stage 0"; Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator rep2( final nout=nSta) "Replicate"; Buildings.Controls.OBC.CDL.Logical.Not notLea "True if lead unit is disabled"; Buildings.Controls.OBC.CDL.Logical.MultiAnd upAndEna( nin=3) "Stage up and lead unit enabled and higher stage available"; Utilities.FirstTrueIndex idxFirAct( nin=nSta) "Return index of first active stage"; Buildings.Controls.OBC.CDL.Logical.Not una[nSta] "True if stage is not available"; Buildings.Controls.OBC.CDL.Logical.And runAndEna[nSta] "Runtime condition met AND lead enable signal false"; Buildings.Controls.OBC.CDL.Routing.BooleanExtractor staUna( final nin=nSta) "Return true if current stage is unavailable"; Buildings.Controls.OBC.CDL.Integers.Max maxInt "Maximum between current stage index and 1"; Buildings.Controls.OBC.CDL.Integers.Sources.Constant one( final k=1) "Constant"; PlaceholderLogical pas[nSta](each final have_inp=dtRun > 0, each final have_inpPh=true) "Direct pass-through when no minimum runtime"; FirstTrueIndex idxFirAva( nin=nSta) "Return index of first available stage"; LastTrueIndex idxLasAva( nin=nSta) "Return index of last available stage"; Buildings.Controls.OBC.CDL.Integers.Greater higAva "Return true if there is any higher stage available"; Buildings.Controls.OBC.CDL.Integers.Less lowAva "Return true if there is any lower stage available"; Buildings.Controls.OBC.CDL.Logical.Timer tim[nSta]( passed( each start=false), each final t=dtRun) if dtRun > 0 "Timer for minimum runtime"; PlaceholderLogical phAvaSta[nSta]( each final have_inp=have_inpAva, each final have_inpPh=false, each final u_internal=true) "Placeholder value if signal is not available"; Buildings.Controls.OBC.CDL.Logical.MultiAnd dowAndEna( nin=3) "Stage down and lead unit enabled and lower stage available"; Buildings.Controls.OBC.CDL.Logical.Or upOrDow "Stage up or down"; Buildings.Controls.OBC.CDL.Integers.Switch idxNex "Return index of next stage to be enabled"; Buildings.Controls.OBC.CDL.Integers.Less intLesEqu[nSta] "Return true if index less or equal to active stage index minus one"; Buildings.Controls.OBC.CDL.Integers.Sources.Constant idxStaAll[nSta]( final k={i for i in 1:nSta}) "Stage indices"; Buildings.Controls.OBC.CDL.Routing.IntegerScalarReplicator intScaRep( nout=nSta) "Replicate signal"; Buildings.Controls.OBC.CDL.Logical.And andAva[nSta] "True if previous condition met and stage available"; LastTrueIndex idxNexLowAva( final nin=nSta) "Return index of next lower available stage"; FirstTrueIndex idxNexHigAva( final nin=nSta) "Return index of next higher available stage"; Buildings.Controls.OBC.CDL.Integers.Greater intGreEqu[nSta] "Return true if index greater or equal to active stage index plus one"; Buildings.Controls.OBC.CDL.Logical.And andAva1[nSta] "True if previous condition met and stage available"; Buildings.Controls.OBC.CDL.Logical.Or upOrActUna "Stage up command or active stage unavailable"; TrueArrayConditional truIdxNex( final nout=nSta, nin=1) "Generate array with true value at index of next stage to be enabled"; Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator repVec( final nin=nSta, final nout=nSta) "Replicate vector"; Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator rep3[nSta]( each final nout=nSta) "Replicate signal"; Buildings.Controls.OBC.CDL.Logical.And matTrn[nSta, nSta] "Generate matrix with a maximum of one true element where transition must fire"; Buildings.Controls.OBC.CDL.Logical.And actUnaHigAva "Active stage unavailable and higher stage available"; Buildings.Controls.OBC.CDL.Logical.Or upOrDowOrActUna[nSta] "Stage up or down command or active stage unavailable (not subject to runtime requirement)"; Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator rep1( final nout=nSta) "Replicate"; TrueArrayConditional truNexHigAva( final nout=nSta, nin=1) "Generate array with true element at index of next higher available stage (if any, otherwise all false)"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt( final integerTrue=1, final integerFalse=0) "Cast to integer"; equation for i in 1:nSta loop for j in 1:nSta loop connect(staToSta[i, j].outPort, sta[j].inPort[i]); connect(sta[i].outPort[j], staToSta[i, j].inPort); end for; end for; // Transitio to/from stage 0 – All units disabled. connect(sta.outPort[nSta + 1], staToSta0.inPort); connect(sta0ToSta.outPort, sta.inPort[nSta + 1]); connect(staToSta0.outPort, sta0.inPort); connect(sta0.outPort, sta0ToSta.inPort); connect(u1Lea, notLea.u); connect(runAndEna.y, staToSta0.condition); connect(sta.active, idxFirAct.u1); connect(maxInt.y, staUna.index); connect(una.y, staUna.u); connect(idxFirAct.y, y); connect(idxLasAva.y, higAva.u1); connect(idxFirAva.y, lowAva.u1); connect(idxFirAct.y, higAva.u2); connect(idxFirAct.y, lowAva.u2); connect(one.y, maxInt.u1); connect(idxFirAct.y, maxInt.u2); connect(sta.active, tim.u); connect(tim.passed, pas.u); connect(sta.active, pas.uPh); connect(u1AvaSta, phAvaSta.u); connect(phAvaSta.y, una.u); connect(phAvaSta.y, idxLasAva.u1); connect(phAvaSta.y, idxFirAva.u1); connect(u1Lea, upAndEna.u[1]); connect(u1Lea, dowAndEna.u[1]); connect(u1Up, upAndEna.u[2]); connect(u1Dow, dowAndEna.u[2]); connect(higAva.y, upAndEna.u[3]); connect(lowAva.y, dowAndEna.u[3]); connect(upOrDow.y, rep.u); connect(pas.y, runAndTrn.u1); connect(rep.y, runAndTrn.u2); connect(intScaRep.y, intLesEqu.u2); connect(idxStaAll.y, intLesEqu.u1); connect(intLesEqu.y, andAva.u1); connect(phAvaSta.y, andAva.u2); connect(andAva.y, idxNexLowAva.u1); connect(idxStaAll.y, intGreEqu.u1); connect(intGreEqu.y, andAva1.u1); connect(phAvaSta.y, andAva1.u2); connect(andAva1.y, idxNexHigAva.u1); connect(u1Up, upOrActUna.u1); connect(staUna.y, upOrActUna.u2); connect(upOrActUna.y, idxNex.u2); connect(andAva1.y, idxNexHigAva.u1); connect(idxNexHigAva.y, idxNex.u1); connect(idxNexLowAva.y, idxNex.u3); connect(one.y, truIdxNex.u); connect(truIdxNex.y1, repVec.u); connect(rep3.y, matTrn.u1); connect(repVec.y, matTrn.u2); connect(matTrn.y, staToSta.condition); connect(dowAndEna.y, upOrDow.u2); connect(staUna.y, actUnaHigAva.u2); connect(higAva.y, actUnaHigAva.u1); connect(actUnaHigAva.y, rep1.u); connect(rep1.y, upOrDowOrActUna.u2); connect(idxNex.y, truIdxNex.uIdx[1]); connect(truNexHigAva.y1, sta0ToSta.condition); connect(u1Lea, booToInt.u); connect(booToInt.y, truNexHigAva.u); connect(idxFirAva.y, truNexHigAva.uIdx[1]); connect(upAndEna.y, upOrDow.u1); connect(notLea.y, rep2.u); connect(runAndTrn.y, upOrDowOrActUna.u1); connect(upOrDowOrActUna.y, rep3.u); connect(rep2.y, runAndEna.u1); connect(pas.y, runAndEna.u2); connect(idxFirAct.y, intScaRep.u); connect(intScaRep.y, intGreEqu.u2); end StageIndex;

Buildings.Templates.Plants.Controls.Utilities.TimerWithReset Buildings.Templates.Plants.Controls.Utilities.TimerWithReset

Timer measuring the time from the time instant where the Boolean input became true

Buildings.Templates.Plants.Controls.Utilities.TimerWithReset

Information

This block is similar to Buildings.Controls.OBC.CDL.Logical.Timer, but introduces an additional Boolean input signal reset, which resets the timer. When reset becomes true: y=0 and passed=false.

Parameters

TypeNameDefaultDescription
Realt0Threshold time for comparison [s]

Connectors

TypeNameDescription
input BooleanInputuInput that switches timer on if true, and off if false
input BooleanInputresetReset signal
output RealOutputyElapsed time [s]
output BooleanOutputpassedTrue if the elapsed time is greater than threshold

Modelica definition

block TimerWithReset "Timer measuring the time from the time instant where the Boolean input became true" parameter Real t( final quantity="Time", final unit="s")=0 "Threshold time for comparison"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input that switches timer on if true, and off if false"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput reset "Reset signal"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y( final quantity="Time", final unit="s") "Elapsed time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput passed "True if the elapsed time is greater than threshold"; protected discrete Real entryTime( final quantity="Time", final unit="s") "Time instant when u became true"; initial equation pre(entryTime)=time; pre(passed)=t <= 0; equation when u and not reset then entryTime=time; // When u becomes true, and t=0, we want passed to be true // at the first step (in superdense time). passed=t <= 0; elsewhen reset then entryTime=time; passed=false; elsewhen(u and time >= t + pre(entryTime)) then passed=true; entryTime=pre(entryTime); elsewhen not u then // Set passed to false. // This is the behavior a timer would have if the threshold test is done with a greater block connected to the output of the timer passed=false; entryTime=pre(entryTime); end when; y=if u then time - entryTime else 0.0; end TimerWithReset;

Buildings.Templates.Plants.Controls.Utilities.TrueArrayConditional Buildings.Templates.Plants.Controls.Utilities.TrueArrayConditional

Output a Boolean array with a given number of true elements and a priority order

Buildings.Templates.Plants.Controls.Utilities.TrueArrayConditional

Information

Accepts indices of true elements that may not be within the range of indices of the output vector. In this, the number of true elements will not be met.

Parameters

TypeNameDefaultDescription
IntegernoutninSize of output array

Connectors

TypeNameDescription
input IntegerInputuNumber of true elements
input IntegerInputuIdx[nin]Array of indices by order of priority to be true
output BooleanOutputy1[nout]Output

Modelica definition

block TrueArrayConditional "Output a Boolean array with a given number of true elements and a priority order" parameter Integer nin( min=0)=0 "Size of input array"; parameter Integer nout( min=0)=nin "Size of output array"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u "Number of true elements"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uIdx[nin] "Array of indices by order of priority to be true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1[nout] "Output"; protected Integer iTru "Iteration variable - Count number of true elements"; Integer iIdx "Iteration variable - Count number of indices in input vector"; initial equation pre(u)=0; algorithm iTru := 0; iIdx := 1; y1 := fill(false, nout); while (iTru < u) and (iIdx <= nin) loop if (uIdx[iIdx] >= 1) and (uIdx[iIdx] <= nout) then y1[uIdx[iIdx]] := true; iTru := iTru + 1; end if; iIdx := iIdx + 1; end while; end TrueArrayConditional;