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.ConcatenateLogical ConcatenateLogical  
Buildings.Templates.Plants.Controls.Utilities.ConcatenateParameterLogical ConcatenateParameterLogical  
Buildings.Templates.Plants.Controls.Utilities.ConcatenateSelectLogical ConcatenateSelectLogical Merge both Boolean arrays when present, otherwise return the available one
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.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.StageIndex StageIndex Evaluation of stage index from staging signals
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.ConcatenateLogical Buildings.Templates.Plants.Controls.Utilities.ConcatenateLogical


Buildings.Templates.Plants.Controls.Utilities.ConcatenateLogical

Information

This block concatenates two Boolean arrays.

When is_app = true (default), the values of u2 are appended after the values of u1.

When is_app = false, the values of u2 are prepended before the values of u1.

Parameters

TypeNameDefaultDescription
Booleanis_apptrueSet to true to append to the input array, false to prepend

Connectors

TypeNameDescription
input BooleanInputu1[nin1]Array of Boolean signals
input BooleanInputu2[nin2]Array of Boolean signals
output BooleanOutputy[nout]Concatenated array

Modelica definition

block ConcatenateLogical parameter Boolean is_app = true "Set to true to append to the input array, false to prepend"; parameter Integer nin1 = 0 "Size of input array"; parameter Integer nin2 = 0 "Size of input array"; final parameter Integer nout = nin1 + nin2 "Size of output array"; final parameter Integer idxExt1[nout] = if is_app then cat(1, {i for i in 1:nin1}, fill(1, nin2)) else cat(1, fill(1, nin2), {i for i in 1:nin1}) "Indices of first array to be extracted"; final parameter Integer idxExt2[nout] = if is_app then cat(1, fill(1, nin1), {i for i in 1:nin2}) else cat(1, {i for i in 1:nin2}, fill(1, nin1)) "Indices of second array to be extracted"; final parameter Boolean selInp[nout] = if is_app then cat(1, fill(true, nin1), fill(false, nin2)) else cat(1, fill(false, nin2), fill(true, nin1)) "Selector for first (true) or second (false) array values"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1[nin1] "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2[nin2] if have_input "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout] "Concatenated array"; Buildings.Controls.OBC.CDL.Routing.BooleanExtractSignal expInp( final nin=nin1, final nout=nout, final extract=idxExt1) if nin1 > 0 "Expand array"; Buildings.Controls.OBC.CDL.Logical.Switch logSwi[nout] "Switch between first and second array"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant con[nout](final k=selInp) "Input selector"; Buildings.Controls.OBC.CDL.Routing.BooleanExtractSignal exp2( final nin=nin2, final nout=nout, final extract=idxExt2) if nin2 > 0 "Expand array"; protected // The parameter have_input is used in ConcatenateParameterLogical parameter Boolean have_input = true "Set to true if second array provided as input, false if provided as parameter"; equation connect(u1, expInp.u); connect(logSwi.y, y); connect(con.y, logSwi.u2); connect(expInp.y, logSwi.u1); connect(exp2.y, logSwi.u3); connect(u2, exp2.u); end ConcatenateLogical;

Buildings.Templates.Plants.Controls.Utilities.ConcatenateParameterLogical Buildings.Templates.Plants.Controls.Utilities.ConcatenateParameterLogical


Buildings.Templates.Plants.Controls.Utilities.ConcatenateParameterLogical

Information

This block concatenates two Boolean arrays, one provided as an input, the other one provided as a parameter.

When is_app = true (default), the values of the parameter array are appended after the values of the input array.

When is_app = false, the values of the parameter array are prepended before the values of the input array.

A zero-sized array can be provided as a parameter. The block then is a no-op, returning the input array unchanged.

Extends from Buildings.Templates.Plants.Controls.Utilities.ConcatenateLogical.

Parameters

TypeNameDefaultDescription
Booleanis_apptrueSet to true to append to the input array, false to prepend
Booleannew[:] New array to be concatenated with the input array

Connectors

TypeNameDescription
input BooleanInputu1[nin1]Array of Boolean signals
input BooleanInputu2[nin2]Array of Boolean signals
output BooleanOutputy[nout]Concatenated array

Modelica definition

block ConcatenateParameterLogical extends Buildings.Templates.Plants.Controls.Utilities.ConcatenateLogical( final have_input=false, final nin2=nNew); parameter Boolean new[:] "New array to be concatenated with the input array"; final parameter Integer nNew = size(new, 1) "Size of new array"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant newCst[nNew](final k=new) if nin2 > 0 "New array to be concatenated"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant pla0[nout]( final k=fill(true, nout)) if nin2 == 0 "Placeholder for zero-sized array"; equation connect(newCst.y, exp2.u); connect(pla0.y, logSwi.u3); end ConcatenateParameterLogical;

Buildings.Templates.Plants.Controls.Utilities.ConcatenateSelectLogical Buildings.Templates.Plants.Controls.Utilities.ConcatenateSelectLogical

Merge both Boolean arrays when present, otherwise return the available one

Buildings.Templates.Plants.Controls.Utilities.ConcatenateSelectLogical

Information

This block concatenates two Boolean arrays if both the parameters have_u1 and have_u2 are true. Otherwise, it returns the sole available input array unchanged.

Parameters

TypeNameDefaultDescription
Booleanhave_u1 Set to true if u1 array available
Booleanhave_u2 Set to true if u2 array available

Connectors

TypeNameDescription
input BooleanInputu1[nin1]Array of Boolean signals
input BooleanInputu2[nin2]Array of Boolean signals
output BooleanOutputy[nout]Concatenated array

Modelica definition

block ConcatenateSelectLogical "Merge both Boolean arrays when present, otherwise return the available one" parameter Boolean have_u1 "Set to true if u1 array available"; parameter Boolean have_u2 "Set to true if u2 array available"; parameter Integer nin1 = 0 "Size of input array"; parameter Integer nin2 = 0 "Size of input array"; final parameter Integer nout = if have_u1 and have_u2 then nin1 + nin2 elseif have_u1 then nin1 else nin2 "Size of output array"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1[nin1] if have_u1 "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2[nin2] if have_u2 "Array of Boolean signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout] "Concatenated array"; PlaceholderLogical selAva[if have_u1 then nin1 else nin2]( each final have_inp=have_u1, each final have_inpPh=true) if not (have_u1 and have_u2) "Select available array"; ConcatenateLogical cat1(nin1=nin1, nin2=nin2) if have_u1 and have_u2 "Concatenate"; equation connect(u1, selAva.u); connect(u2, selAva.uPh); connect(u1, cat1.u1); connect(u2, cat1.u2); connect(cat1.y, y); connect(selAva.y, y); end ConcatenateSelectLogical;

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.TrueFalseHold truHol( final falseHoldDuration=0, final trueHoldDuration=dtHol) "Hold true value of input signal for given 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, 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"; Buildings.Controls.OBC.CDL.Conversions.IntegerToReal intToRea[nin] "Cast to real type"; Buildings.Controls.OBC.CDL.Reals.MultiMax mulMax(nin=nin) "Return max value"; Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt "Cast back to integer type"; equation connect(u,intToRea. u); connect(intToRea.y,mulMax. u); connect(reaToInt.y, y); connect(mulMax.y,reaToInt. 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=nin "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"; Buildings.Controls.OBC.CDL.Conversions.IntegerToReal intToRea[nin] "Cast to real type"; Buildings.Controls.OBC.CDL.Reals.MultiMin mulMin(nin=nin) "Return min value"; Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt "Cast back to integer type"; equation connect(u, intToRea.u); connect(intToRea.y, mulMin.u); connect(reaToInt.y, y); connect(mulMin.y, reaToInt.u); end MultiMinInteger;

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.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
Booleanuse_twoModfalseSet to true to apply the runtime requirement to combinations of cooling and heating stages
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
input IntegerInputuStaOppOpposite mode stage 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 Boolean use_twoMod=false "Set to true to apply the runtime requirement to combinations of cooling and heating stages"; 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"; Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uStaOpp(final min=0, final max=nSta) if use_twoMod "Opposite mode stage index"; Buildings.Controls.OBC.CDL.Integers.Change chaStaOpp if use_twoMod "True when opposite mode stage changes"; Buildings.Controls.OBC.CDL.Logical.Not notChaStaOpp "True if opposite mode stage does not change"; Buildings.Controls.OBC.CDL.Logical.And actAndNotOppModCha[nSta] "True if stage active and opposite mode stage does not change"; Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator booScaRep(final nout=nSta) "Replicate"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant fal(final k=false) if not use_twoMod "Placeholder signal"; Buildings.Controls.OBC.CDL.Logical.Pre pre "Avoid blocking stage transition if opposite mode stage changes at the same time"; Buildings.Controls.OBC.CDL.Logical.Timer timOppMod(passed(start=false), final t=dtRun) "Timer for minimum runtime of opposite mode stage"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant notTwoMod(final k=not use_twoMod) "True in single mode applications"; Buildings.Controls.OBC.CDL.Logical.MultiOr timOppModOrNotTwoMod(nin=nSta+2) "True if "; Buildings.Controls.OBC.CDL.Logical.And u1LeaClr "Clear lead unit enable if opposite mode runtime not met"; 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(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(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(u1Up, upAndEna.u[1]); connect(u1Dow, dowAndEna.u[1]); connect(higAva.y, upAndEna.u[2]); connect(lowAva.y, dowAndEna.u[2]); 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(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); connect(uStaOpp, chaStaOpp.u); connect(chaStaOpp.y, notChaStaOpp.u); connect(fal.y, notChaStaOpp.u); connect(actAndNotOppModCha.y, tim.u); connect(sta.active, actAndNotOppModCha.u1); connect(booScaRep.y, actAndNotOppModCha.u2); connect(notChaStaOpp.y, pre.u); connect(truNexHigAva.y1, sta0ToSta.condition); connect(u1LeaClr.y, booToInt.u); connect(u1LeaClr.y, upAndEna.u[3]); connect(u1LeaClr.y, notLea.u); connect(u1LeaClr.y, dowAndEna.u[3]); connect(notTwoMod.y, timOppModOrNotTwoMod.u[nSta+1]); connect(timOppMod.passed, timOppModOrNotTwoMod.u[nSta+2]); connect(sta.active, timOppModOrNotTwoMod.u[1:nSta]); connect(timOppModOrNotTwoMod.y, u1LeaClr.u2); connect(u1Lea, u1LeaClr.u1); connect(pre.y, booScaRep.u); connect(pre.y, timOppMod.u); end StageIndex;

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

This block outputs a Boolean array with true at the output positions given by the first u entries of the priority-ordered index array uIdx. The number of true elements equals u when at least u valid and distinct entries are present in uIdx, and is less otherwise.

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]Array with true at the first u priority-ordered indices

Modelica definition

block TrueArrayConditional "Output a Boolean array with a given number of true elements and a priority order" parameter Integer nin "Size of input array"; parameter Integer nout(min=0) = nin "Size of output array"; final parameter Boolean filTru[nin, nin] = {j <= i for j in 1:nin, i in 1:nin} "Lower triangular true matrix"; 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] "Array with true at the first u priority-ordered indices"; // Sequence 1: eliminate duplicates and elements outside 1..nout from uIdx Buildings.Controls.OBC.CDL.Integers.Equal equOutInp[nout, nin] "True if output position index equals input index value"; Buildings.Controls.OBC.CDL.Routing.IntegerVectorReplicator repUIdx( nin=nin, nout=nout) "Replicate input index array to nout rows for comparison with output position indices"; Buildings.Controls.OBC.CDL.Integers.Sources.Constant conOutPos[nout, nin]( k={i for _ in 1:nin, i in 1:nout}) "Output position indices 1..nout replicated nin times across columns"; FirstTrueIndex idxFirOcc[nout](each final nin=nin) "Position of first occurrence in uIdx for each output-range value"; Buildings.Controls.OBC.CDL.Routing.IntegerVectorReplicator repFirOcc( nin=nout, nout=nin) "Replicate first-occurrence positions to nin elements for input-position matching"; Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInpPos[nin, nout]( k={i for _ in 1:nout, i in 1:nin}) "Input position indices 1..nin replicated nout times across columns"; Buildings.Controls.OBC.CDL.Integers.Equal equFirInp[nin, nout] "True if first-occurrence position matches input position index"; Buildings.Controls.OBC.CDL.Logical.MultiOr mulIsUnq[nin](each final nin=nout) "True at input position j if j is the first (unique) occurrence of its value in uIdx"; // Sequence 2: count valid non-zero elements and keep those with rank <= u Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator repIsVal( nin=nin, nout=nin) "Replicate element validity flag to matrix for element-wise AND with lower-triangular mask"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant conLowTri[nin, nin]( final k=filTru) "Constant lower-triangular true matrix for masking preceding elements"; Buildings.Controls.OBC.CDL.Logical.And andValPre[nin, nin] "True at [i,j] if element j is valid and j precedes or equals i"; CountTrue couValPre[nin](each final nin=nin) "Count of valid preceding elements"; Buildings.Controls.OBC.CDL.Integers.LessEqual leqU[nin] "True if element rank is at most u (element is within the first u valid entries)"; Buildings.Controls.OBC.CDL.Routing.IntegerScalarReplicator repU(nout=nin) "Replicate maximum selection count u to all elements for rank comparison"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger intSel[nin] "Convert selection flag to integer for masking"; Buildings.Controls.OBC.CDL.Integers.Multiply mulSel[nin] "Selected indices: uIdx at selected positions, 0 elsewhere"; Buildings.Controls.OBC.CDL.Integers.Equal equOutSel[nout, nin] "True if output position index equals selected index value"; Buildings.Controls.OBC.CDL.Routing.IntegerVectorReplicator repSelIdx( nin=nin, nout=nout) "Replicate selected indices to nout rows for comparison with output position indices"; Buildings.Controls.OBC.CDL.Logical.MultiOr mulIsOut[nout](each final nin=nin) "True at output position i if any selected input index equals i"; equation connect(equOutSel.y, mulIsOut.u); connect(uIdx, mulSel.u2); connect(andValPre.y, couValPre.u1); connect(equFirInp.y, mulIsUnq.u); connect(equOutInp.y, idxFirOcc.u1); connect(repUIdx.y, equOutInp.u2); connect(conOutPos.y, equOutInp.u1); connect(uIdx, repUIdx.u); connect(idxFirOcc.y, repFirOcc.u); connect(repFirOcc.y, equFirInp.u1); connect(conInpPos.y, equFirInp.u2); connect(couValPre.y, leqU.u1); connect(u, repU.u); connect(repU.y, leqU.u2); connect(leqU.y, intSel.u); connect(intSel.y, mulSel.u1); connect(mulSel.y, repSelIdx.u); connect(mulIsOut.y, y1); connect(mulIsUnq.y, repIsVal.u); connect(conLowTri.y, andValPre.u1); connect(repIsVal.y, andValPre.u2); connect(conOutPos.y, equOutSel.u2); connect(repSelIdx.y, equOutSel.u1); end TrueArrayConditional;