Switch between two integer signals. Block that outputs one of two integer input signals based on a boolean input signal.

within Buildings.Controls.OBC.CDL.Integers;
block Switch
  "Switch between two integer signals"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u1
    "Integer input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Boolean switch input signal, if true, y=u1, else y=u3"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u3
    "Integer input signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y
    "Integer output signal"

equation
  y=if u2 then
      u1
    else
      u3;
end Switch;


Output constant signal of type Integer. Block that outputs a constant signal y = k,
where k is an Integer-valued parameter.

within Buildings.Controls.OBC.CDL.Integers.Sources;
block Constant
  "Output constant signal of type Integer"
  parameter Integer k
    "Constant output value";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y
    "Connector of Integer output signal"

equation
  y=k;
end Constant;


within Buildings.Controls.OBC.CDL.Integers;
package Sources "Package with blocks that generate source signals"
end Sources;


Generate pulse signal of type Integer. Block that outputs a pulse signal as shown below.

within Buildings.Controls.OBC.CDL.Integers.Sources;
block Pulse
  "Generate pulse signal of type Integer"
  parameter Integer amplitude=1
    "Amplitude of pulse";
  parameter Real width(
    final min=Constants.small,
    final max=1,
    final unit="1")=0.5
    "Width of pulse in fraction of period";
  parameter Real period(
    final quantity="Time",
    final unit="s",
    final min=Constants.small)
    "Time for one period";
  parameter Real shift(
    final quantity="Time",
    final unit="s")=0
    "Shift time for output";
  parameter Integer offset=0
    "Offset of output signals";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y
    "Connector of Pulse output signal"

protected
  Logical.Sources.Pulse booPul(
    final width=width,
    final period=period,
    final shift=shift)
    "Boolean pulse"
  Conversions.BooleanToInteger booToInt(
    final integerTrue=offset+amplitude,
    final integerFalse=offset)
    "Boolean to integer conversion"

equation
  connect(booPul.y,booToInt.u)
  connect(booToInt.y,y)
end Pulse;


Table look-up with respect to time with constant segments. Block that outputs Integer time table values.

within Buildings.Controls.OBC.CDL.Integers.Sources;
block TimeTable
  "Table look-up with respect to time with constant segments"
  parameter Real table[:,:]
    "Table matrix with time as a first table column (in seconds, unless timeScale is not 1) and Integers in all other columns";
  parameter Real timeScale(
    final unit="1")=1
    "Time scale of first table column. Set to 3600 if time in table is in hours";
  parameter Real period(
    final quantity="Time",
    final unit="s",
    min=1E-6)
    "Periodicity of table";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y[nout]
    "Output of the table"

protected
  final parameter Integer nout=size(
    table,
    2)-1
    "Dimension of output vector";
  final parameter Integer nT=size(
    table,
    1)
    "Number of time stamps";
  parameter Real t0(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "First sample time instant";
  final parameter Real timeStamps[:](
    each final quantity="Time",
    each final unit="s")=timeScale*table[1:end,1]
    "Time stamps";
  final parameter Integer val[:,:]=integer(
    table[1:end,2:end]+ones(
      nT,
      nout)*Constants.small)
    "Table values as Integer";
  Integer idx(
    fixed=false)
    "Index for table lookup";
  function getIndex
    "Function to get the index for the table look-up"
    input Real t(
      final quantity="Time",
      final unit="s")
      "Current time";
    input Real period(
      final quantity="Time",
      final unit="s")
      "Time period";
    input Real x[:](
      each final quantity="Time",
      each final unit="s")
      "Time stamps";
    output Integer k
      "Index in table";

  protected
    Real tS(
      final quantity="Time",
      final unit="s")
      "Time shifted so it is within the period";

  algorithm
    tS := mod(
      t,
      period);
    k :=-1;
    for i in size(
      x,
      1):-1:1 loop
      if tS >= x[i]-1E-6 then
        k := i;
        break;
      end if;
    end for;
  end getIndex;

initial equation
  t0=Buildings.Utilities.Math.Functions.round(
    x=integer(time/period)*period,
    n=6);
  assert(
    nT > 0,
    "No table values defined.");
  // Check that all values in the second column are Integer values
  for i in 1:nT loop
    for j in 2:size(
      table,
      2) loop
      assert(
        abs(
          table[i,j]-integer(
            table[i,j])) < Constants.small,
        "In "+getInstanceName()+": Table value table["+String(i)+", "+String(j)+"] = "+String(
          table[i,j])+" is not an Integer.");
    end for;
  end for;
  assert(
    abs(
      table[1,1]) < Constants.small,
    "In "+getInstanceName()+": First time stamp must be zero as otherwise no data is defined for the start of the table.");
  assert(
    period-table[1,end] > Constants.small,
    "In "+getInstanceName()+": Last time stamp in table must be smaller than period.");
  idx=getIndex(
    time,
    period,
    timeStamps);
  y[:]=val[idx,:];

equation
  when {sample(t0+timeStamps[i],period) for i in 1:nT} then
    idx=getIndex(
      time,
      period,
      timeStamps);
    y[:]=val[idx,:];
  end when;
end TimeTable;


Validate the Constant block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Sources.Constant.

within Buildings.Controls.OBC.CDL.Integers.Sources.Validation;
model Constant
  "Validate the Constant block"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant con(
    k=5)
    "Block output integer constant value"
end Constant;


within Buildings.Controls.OBC.CDL.Integers.Sources;
package Validation "Collection of models that validate the logical sources blocks of the CDL"
end Validation;


Validation model for the Integer Pulse block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Sources.Pulse.

within Buildings.Controls.OBC.CDL.Integers.Sources.Validation;
model Pulse
  "Validation model for the Integer Pulse block"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse pul3(
    amplitude=1,
    width=0.5,
    period=1,
    offset=3)
    "Block that generates pulse signal of type Integer at simulation start time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse pul1(
    amplitude=2,
    width=0.5,
    period=1,
    offset=1,
    shift=1.75)
    "Block that generates pulse signal of type Integer starting from after the simulation start time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse pul2(
    amplitude=3,
    width=0.5,
    period=1,
    offset=-2,
    shift=-1.25)
    "Block that generates pulse signal of type Integer starting from before the simulation start time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse pul(
    width=0.5,
    period=1)
    "Block that generates pulse signal of type Integer at simulation start time and has infinite number of periods"
end Pulse;


Validation model for TimeTable block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable.

within Buildings.Controls.OBC.CDL.Integers.Sources.Validation;
model TimeTable
  "Validation model for TimeTable block"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable intTimTab(
    table=[
      0,1,4;
      1.3,2,2;
      2.9,0,-1;
      4,3,7],
    period=5)
    "Integer time table"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable intTimTab1(
    table=[
      0,-1,-2;
      6,1,4;
      7.3,2,2;
      8.9,0,-1;
      10,3,7],
    period=11)
    "Integer time table"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable tabOneRow(
    table=[
      0,-1],
    period=2)
    "Time table with only one row of data"
end TimeTable;


Validation model for TimeTable block with negative start time.

within Buildings.Controls.OBC.CDL.Integers.Sources.Validation;
model TimeTableNegativeStartTime
  "Validation model for TimeTable block with negative start time"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable intTimTab(
    table=[
      0,1,4;
      1.3,2,2;
      2.9,0,-1;
      4,3,7],
    period=5)
    "Integer time table"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable intTimTab1(
    table=[
      0,-1,-2;
      6,1,4;
      7.3,2,2;
      8.9,0,-1;
      10,3,7],
    period=11)
    "Integer time table"
  Buildings.Controls.OBC.CDL.Integers.Sources.TimeTable tabOneRow(
    table=[
      0,-1],
    period=2)
    "Time table with only one row of data"
end TimeTableNegativeStartTime;


Validation model for the absolute block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Abs.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Abs
  "Validation model for the absolute block"
  Buildings.Controls.OBC.CDL.Integers.Abs abs1
    "Block that outputs the absolute value of the input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,abs1.u)
end Abs;


Validation model for the Add block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Add.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Add
  "Validation model for the Add block"
  Buildings.Controls.OBC.CDL.Integers.Add add1
    "Block that outputs the sum of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-0.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(ramp2.y,round2.u)
  connect(round2.y,reaToInt1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,add1.u1)
  connect(reaToInt1.y,add1.u2)
end Add;


Validation model for the AddParameter block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.AddParameter.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model AddParameter "Validation model for the AddParameter block"
  Buildings.Controls.OBC.CDL.Integers.AddParameter addPar(p=5)
    "Block that outputs the sum of an input plus a parameter"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger  reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y, addPar.u)
end AddParameter;


Validation model for the Change block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Change.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Change
  "Validation model for the Change block"
  Buildings.Controls.OBC.CDL.Integers.Change cha
    "Check if the integer input changes value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    offset=0,
    height=20,
    duration=1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler changeSampler
    "Triggered sampler"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,-1;
      0.3,0.5;
      0.5,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler increaseSampler
    "Increase sampler"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler decreaseSampler
    "Decrease sampler"

equation
  connect(ramp2.y,changeSampler.u)
  connect(timTabLin.y[1],reaToInt.u)
  connect(reaToInt.y,cha.u)
  connect(ramp2.y,increaseSampler.u)
  connect(ramp2.y,decreaseSampler.u)
  connect(cha.up,increaseSampler.trigger)
  connect(cha.y,changeSampler.trigger)
  connect(cha.down,decreaseSampler.trigger)
end Change;


Validation model for the Equal block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Equal.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Equal
  "Validation model for the Equal block"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Block output true if input 1 is equal to input 2"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,0;
      0.3,1;
      0.5,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin1(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,0;
      0.35,1;
      0.55,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"

equation
  connect(reaToInt.y,intEqu.u1)
  connect(reaToInt1.y,intEqu.u2)
  connect(timTabLin.y[1],reaToInt.u)
  connect(timTabLin1.y[1],reaToInt1.u)
end Equal;


Validation model for the Greater block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Greater.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Greater
  "Validation model for the Greater block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1.5,
    height=5.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.Greater intGre
    "Block output true if input 1 is greater than input 2"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(ramp2.y,round2.u)
  connect(round1.y,reaToInt.u)
  connect(round2.y,reaToInt1.u)
  connect(reaToInt.y,intGre.u1)
  connect(reaToInt1.y,intGre.u2)
end Greater;


Validation model for the GreaterEqual block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.GreaterEqual.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model GreaterEqual
  "Validation model for the GreaterEqual block"
  Buildings.Controls.OBC.CDL.Integers.GreaterEqual intGreEqu
    "Block output true if input 1 is greater or equal to input 2"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,-1;
      0.3,0.5;
      0.5,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin1(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,0;
      0.35,1;
      0.55,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"

equation
  connect(reaToInt.y,intGreEqu.u1)
  connect(reaToInt1.y,intGreEqu.u2)
  connect(timTabLin.y[1],reaToInt.u)
  connect(timTabLin1.y[1],reaToInt1.u)
end GreaterEqual;


Validation model for the GreaterEqualThreshold block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.GreaterEqualThreshold.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model GreaterEqualThreshold
  "Validation model for the GreaterEqualThreshold block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.GreaterEqualThreshold intGreEquThr(
    t=2)
    "Block output true if input is greater or equal to threshold value"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,intGreEquThr.u)
end GreaterEqualThreshold;


Validation model for the GreaterThreshold block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.GreaterThreshold.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model GreaterThreshold
  "Validation model for the GreaterThreshold block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr(
    t=2)
    "Block output true if input is greater than threshold value"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,intGreThr.u)
end GreaterThreshold;


Validation model for the Less block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Less.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Less
  "Validation model for the Less block"
  Buildings.Controls.OBC.CDL.Integers.Less intLes
    "Block output true if input 1 is less than input 2"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,-1;
      0.3,0.5;
      0.5,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin1(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,0;
      0.35,1;
      0.55,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"

equation
  connect(reaToInt1.y,intLes.u2)
  connect(reaToInt.y,intLes.u1)
  connect(timTabLin.y[1],reaToInt.u)
  connect(timTabLin1.y[1],reaToInt1.u)
end Less;


Validation model for the LessEqual block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.LessEqual.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model LessEqual
  "Validation model for the LessEqual block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1.5,
    height=5.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.LessEqual intLesEqu
    "Block output true if input 1 is less or equal to input 2"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(ramp2.y,round2.u)
  connect(round1.y,reaToInt.u)
  connect(round2.y,reaToInt1.u)
  connect(reaToInt1.y,intLesEqu.u2)
  connect(reaToInt.y,intLesEqu.u1)
end LessEqual;


Validation model for the LessEqualThreshold block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.LessEqualThreshold.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model LessEqualThreshold
  "Validation model for the LessEqualThreshold block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.LessEqualThreshold intLesEquThr(
    t=2)
    "Block output true if input is less or equal to threshold value"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,intLesEquThr.u)
end LessEqualThreshold;


Validation model for the LessThreshold block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.LessThreshold.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model LessThreshold
  "Validation model for the LessThreshold block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Integers.LessThreshold intLesThr(
    t=2)
    "Block output true if input is less than threshold value"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,intLesThr.u)
end LessThreshold;


Validation model for the Max block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Max.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Max
  "Validation model for the Max block"
  Buildings.Controls.OBC.CDL.Integers.Max max1
    "Block that outputs the largest inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1.5,
    height=5.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(ramp2.y,round2.u)
  connect(round2.y,reaToInt1.u)
  connect(reaToInt1.y,max1.u2)
  connect(reaToInt.y,max1.u1)
end Max;


Validation model for the Min block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Min.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Min
  "Validation model for the Min block"
  Buildings.Controls.OBC.CDL.Integers.Min min1
    "Block that outputs the smallest inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=10.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1.5,
    height=5.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,min1.u1)
  connect(ramp2.y,round2.u)
  connect(round2.y,reaToInt1.u)
  connect(reaToInt1.y,min1.u2)
end Min;


Validation model for the Multiply block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Multiply.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Multiply "Validation model for the Multiply block"
  Buildings.Controls.OBC.CDL.Integers.Multiply product
    "Block that outputs the product of the two inputs"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,-1;
      0.3,0.5;
      0.5,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"
  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable timTabLin1(
    smoothness=Buildings.Controls.OBC.CDL.Types.Smoothness.ConstantSegments,
    table=[
      0,0;
      0.35,1;
      0.55,0;
      0.7,1;
      1,0])
    "Time table with smoothness method of constant segments"

equation
  connect(reaToInt1.y,product.u1)
  connect(reaToInt2.y,product.u2)
  connect(timTabLin.y[1],reaToInt1.u)
  connect(timTabLin1.y[1],reaToInt2.u)
end Multiply;


Validation model for the block to find sum of multiple inputs. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.MultiSum.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model MultiSum
  "Validation model for the block to find sum of multiple inputs"
  Buildings.Controls.OBC.CDL.Integers.MultiSum add1(
    nin=3)
    "Block that outputs the sum of the inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-0.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp3(
    duration=1,
    height=7.0,
    offset=-1.5)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round3(
    n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(ramp2.y,round2.u)
  connect(ramp3.y,round3.u)
  connect(round3.y,reaToInt2.u)
  connect(round2.y,reaToInt1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y,add1.u[1])
  connect(reaToInt1.y,add1.u[2])
  connect(reaToInt2.y,add1.u[3])
end MultiSum;


Validation model for the OnCounter block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.OnCounter.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model OnCounter
  "Validation model for the OnCounter block"
  Buildings.Controls.OBC.CDL.Integers.OnCounter onCounter
    "Block that outputs increment if the input switches to true"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=0.1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse reset(
    width=0.5,
    period=1.0)
    "Block that outputs cyclic on and off"

equation
  connect(reset.y,onCounter.reset)
  connect(booPul.y,onCounter.trigger)
end OnCounter;


within Buildings.Controls.OBC.CDL.Integers;
package Validation "Collection of models that validate the integer blocks of the CDL"
end Validation;


Validation model for the block to find the total number of enabled stages. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Stage.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Stage
  "Validation model for the block to find the total number of enabled stages"

  Buildings.Controls.OBC.CDL.Integers.Stage sta(
    final n=4,
    final holdDuration=5)
    "Total number of enabled stages, with a hold duration of 5 seconds"
  Buildings.Controls.OBC.CDL.Integers.Stage zerHolTim(
    final n=4,
    final holdDuration=0)
    "Total number of enabled stages, without any hold duration"
  Buildings.Controls.OBC.CDL.Integers.Stage sta1(
    final n=4,
    final holdDuration=2)
    "Total number of enabled stages, with a hold duration of 2 seconds"
  Buildings.Controls.OBC.CDL.Integers.Stage lesHolTim(
    final n=4,
    final holdDuration=1)
    "Total number of enabled stages, with a hold duration of 1 second"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    final duration=10,
    final height=1,
    final startTime=1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sin(
    final amplitude=0.5,
    final freqHz=1/5,
    final offset=0.5)
    "Block that generates sine signal"

equation
  connect(ramp1.y, sta.u)
  connect(ramp1.y,zerHolTim. u)
  connect(sin.y, sta1.u)
  connect(sin.y, lesHolTim.u)
end Stage;


Validation model for the Subtract block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Subtract.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Subtract "Validation model for the Subtract block"
  Buildings.Controls.OBC.CDL.Integers.Subtract sub
    "Block that outputs the difference of the two inputs"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-3.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-0.5,
    height=7.0)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Round round1(n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"

equation
  connect(ramp1.y,round1.u)
  connect(ramp2.y,round2.u)
  connect(round2.y,reaToInt1.u)
  connect(round1.y,reaToInt.u)
  connect(reaToInt.y, sub.u1)
  connect(reaToInt1.y, sub.u2)
end Subtract;


Validation model for the Switch block. Validation test for the block

Buildings.Controls.OBC.CDL.Integers.Switch.

within Buildings.Controls.OBC.CDL.Integers.Validation;
model Switch "Validation model for the Switch block"
  Buildings.Controls.OBC.CDL.Integers.Switch integerSwitch
    "Integer switch"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.7,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=3)
    "Block that outputs cyclic on and off: switch between u1 and u3"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul3(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    k=5)
    "Integer constant"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    k=2)
    "Integer constant"

protected
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt
    "Type converter"
  Buildings.Controls.OBC.CDL.Integers.Multiply proInt "Product"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1
    "Type converter"
  Buildings.Controls.OBC.CDL.Integers.Multiply proInt1 "Product"

equation
  connect(booPul2.y,integerSwitch.u2)
  connect(booPul1.y,booToInt.u)
  connect(booPul3.y,booToInt1.u)
  connect(conInt.y,proInt.u1)
  connect(booToInt.y,proInt.u2)
  connect(conInt1.y,proInt1.u1)
  connect(booToInt1.y,proInt1.u2)
  connect(proInt.y,integerSwitch.u1)
  connect(proInt1.y,integerSwitch.u3)
end Switch;


within Buildings.Controls.OBC.CDL;
package Interfaces "Package with connectors for input and output signals"
end Interfaces;


Logical 'and': y = u1 and u2. Block that outputs true if all inputs are true.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block And
  "Logical 'and': y = u1 and u2"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Connector of first Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Connector of second Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=u1 and u2;
end And;


Output y is true, if the input u has a rising or falling edge (y = change(u)). Block that outputs true if the Boolean input has either a rising edge
from false to true or a falling edge from
true to false.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Change
  "Output y is true, if the input u has a rising or falling edge (y = change(u))"
  parameter Boolean pre_u_start=false
    "Start value of pre(u) at initial time";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

initial equation
  pre(u)=pre_u_start;

equation
  y=change(u);
end Change;


Output y is true, if the input u has a rising edge (y = edge(u)). Block that outputs true if the Boolean input has a rising edge
from false to true.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Edge
  "Output y is true, if the input u has a rising edge (y = edge(u))"
  parameter Boolean pre_u_start=false
    "Start value of pre(u) at initial time";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

initial equation
  pre(u)=pre_u_start;

equation
  y=edge(u);
end Edge;


Output y is true, if the input u has a falling edge (y = edge(not u)). Block that outputs  true if the Boolean input has a falling edge
from true to false.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block FallingEdge
  "Output y is true, if the input u has a falling edge (y = edge(not u))"
  parameter Boolean pre_u_start=false
    "Start value of pre(u) at initial time";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  Boolean not_u=not u
    "Boolean not of the input";

initial equation
  pre(not_u)=not pre_u_start;

equation
  y=edge(not_u);
end FallingEdge;


Maintains a true signal until cleared. Block that generates a true output when the latch input u
rises from false to true, provided that the clear input
clr is false or also became at the same time false.
The output remains true until the clear input clr rises
from false to true.

within Buildings.Controls.OBC.CDL.Logical;
block Latch
  "Maintains a true signal until cleared"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Latch input"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput clr
    "Clear input"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Output signal"
equation
  when initial() then
    y=not clr and u;
  elsewhen {clr, u} then
    y=not clr and u;
  end when;
end Latch;


Logical MultiAnd, y = u[1] and u[2] and u[3] and .... Block that outputs y = true if and only if
all elements of the input vector u are true.
If no connection to the input connector u is present,
the output is y=false.

within Buildings.Controls.OBC.CDL.Logical;
block MultiAnd
  "Logical MultiAnd, y = u[1] and u[2] and u[3] and ..."
  parameter Integer nin(
    min=0)=0
    "Number of input connections"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Connector of Boolean input signals"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  Boolean uTemp[nin]
    "Temporary variable";

equation
  if size(
    u,
    1) > 1 then
    uTemp[1]=u[1];
    for i in 2:size(
      u,
      1) loop
      uTemp[i]=u[i] and uTemp[i-1];
    end for;
    y=uTemp[nin];
  elseif
        (size(
    u,
    1) == 1) then
    uTemp[1]=u[1];
    y=uTemp[1];
  else
    y=false;
  end if;
end MultiAnd;


Logical MultiOr, y = u[1] or u[2] or u[3] or .... Block that outputs y = true if any element in the input
vector u is true.
If no connection to the input connector u is present,
the output is y=false.

within Buildings.Controls.OBC.CDL.Logical;
block MultiOr
  "Logical MultiOr, y = u[1] or u[2] or u[3] or ..."
  parameter Integer nin(
    min=0)=0
    "Number of input connections"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Connector of Boolean input signals"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  Boolean uTemp[nin]
    "Temporary variable";

equation
  if size(
    u,
    1) > 1 then
    uTemp[1]=u[1];
    for i in 2:size(
      u,
      1) loop
      uTemp[i]=u[i] or uTemp[i-1];
    end for;
    y=uTemp[nin];
  elseif
        (size(
    u,
    1) == 1) then
    uTemp[1]=u[1];
    y=uTemp[1];
  else
    y=false;
  end if;
end MultiOr;


Logical 'nand': y = not (u1 and u2). Block that outputs true if at least
one input is false.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Nand
  "Logical 'nand': y = not (u1 and u2)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Connector of first Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Connector of second Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=not
       (u1 and u2);
end Nand;


Logical 'nor': y = not (u1 or u2). Block that outputs true if none of the inputs is true.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Nor
  "Logical 'nor': y = not (u1 or u2)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Connector of first Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Connector of second Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=not
       (u1 or u2);
end Nor;


Logical not. Block that outputs true if the input is false,
and false if the input is true.

within Buildings.Controls.OBC.CDL.Logical;
block Not
  "Logical not"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=not u;
end Not;


Logical 'or': y = u1 or u2. Block that outputs true if at least one input
is true.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Or
  "Logical 'or': y = u1 or u2"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Connector of first Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Connector of second Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=u1 or u2;
end Or;


Package with logical blocks

within Buildings.Controls.OBC.CDL;
package Logical "Package with logical blocks"
end Logical;


Breaks algebraic loops by an infinitesimal small time delay (y = pre(u): event iteration continues until u = pre(u)). This block delays the Boolean input by an infinitesimal small time delay and
therefore breaks algebraic loops. In a network of logical blocks, in every
<i>closed connection loop</i>, at least one logical block must have a delay,
since algebraic systems of Boolean equations are not solvable.

within Buildings.Controls.OBC.CDL.Logical;
block Pre
  "Breaks algebraic loops by an infinitesimal small time delay (y = pre(u): event iteration continues until u = pre(u))"
  parameter Boolean pre_u_start=false
    "Start value of pre(u) at initial time";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

initial equation
  pre(u)=pre_u_start;

equation
  y=pre(u);
end Pre;


Verify two boolean inputs. Block that compares a boolean set point u_s with
a measured signal u_m and produces two outputs
that may be used to raise alarms about malfunctioning equipment.

within Buildings.Controls.OBC.CDL.Logical;
block Proof "Verify two boolean inputs"
  parameter Real debounce(
    final quantity="Time",
    final unit="s")
    "Time during which input must remain unchanged for signal to considered valid and used in checks";
  parameter Real feedbackDelay(
    final quantity="Time",
    final unit="s")
    "Delay after which the two inputs are checked for equality once they become valid";

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u_s
    "Commanded status setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u_m
    "Measured status"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yLocFal
    "True: measured input is locked to false even after the setpoint has changed to true"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yLocTru
    "True: measured input is locked to true even after the setpoint has changed to false"

protected
  Buildings.Controls.OBC.CDL.Logical.Or valInp
    "Output true if the input becomes stable after the delay time"
  Buildings.Controls.OBC.CDL.Logical.And invInp
    "Output true if debounce time has passed and there is still no stable input"
  Buildings.Controls.OBC.CDL.Logical.Or pasDel
    "Output true if the feedback checking time has passed"
  Buildings.Controls.OBC.CDL.Logical.Or cheDif
    "Output true if the measured input is stable, or the feedback checking time has passed"
  Buildings.Controls.OBC.CDL.Logical.And botTru
    "Output true if both valid measured input and the setpoint input are true"
  Buildings.Controls.OBC.CDL.Logical.And truFal
    "Output true if the setpoint input is true but the valid measured input is false"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay valTru(
    final delayTime=debounce) "Valid measured input change from false to true"
  Buildings.Controls.OBC.CDL.Logical.Switch valFal
    "Output false if measured input is stable and changed from true to false"
  Buildings.Controls.OBC.CDL.Logical.Switch cheDif1
    "Output the difference check result if the difference check condition is satisfied"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel1(
    final delayTime=debounce)
    "Delay a rising edge, to check if the false input is valid"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not notBotFal "Not both false inputs"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.And falTru
    "Output true if the setpoint input is false but the valid measured input is true"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay delChe1(
    final delayTime=feedbackDelay + debounce)
    "Delay the difference check"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt
    "Convert boolean input to integer output"
  Buildings.Controls.OBC.CDL.Integers.Equal equSta
    "Output true if both inputs are same"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1
    "Convert boolean input to integer output"
  Buildings.Controls.OBC.CDL.Logical.And botFal
    "Output true if both valid measured input and the setpoint input are false"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant conTru(
    final k=true)
    "True constant"
  Buildings.Controls.OBC.CDL.Logical.Not not3
    "Input is invalid"
  Buildings.Controls.OBC.CDL.Logical.Switch cheStaMea
    "Output true if there is no stable measured input"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay delChe2(
    final delayTime=feedbackDelay + debounce)
    "Delay the difference check"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant conFal(
    final k=false)
    "False constant"
  Buildings.Controls.OBC.CDL.Logical.Not notBotTru
    "Not both true inputs"
  Buildings.Controls.OBC.CDL.Logical.Switch cheDif2
    "Output the difference check result if the difference check condition is satisfied"
  Buildings.Controls.OBC.CDL.Logical.Switch cheStaMea1
    "Output true if there is no stable measured input"
  Buildings.Controls.OBC.CDL.Logical.Timer pasDeb(
    final t=feedbackDelay + debounce)
    "Check if the debounce time has passed"
  Buildings.Controls.OBC.CDL.Logical.Latch holTru
    "Hold the true output when the input changes to true"
  Buildings.Controls.OBC.CDL.Logical.Latch holTru1
    "Hold the true output when the input changes to true"
  Buildings.Controls.OBC.CDL.Logical.Or equInp
    "Output true if the measured input equal to the set point"
  Buildings.Controls.OBC.CDL.Logical.Edge samInpEdg
    "Output a rising edge when both inputs are same"
  Buildings.Controls.OBC.CDL.Logical.And valEqu
    "Output true if the measured input is valid and equal to the set point"

initial equation
  assert(
    feedbackDelay >= debounce,
    "In " + getInstanceName() + ": Require feedbackDelay >= debounce, setting feedbackDelay = debounce.",
    level=AssertionLevel.warning);

equation
  connect(u_m, valTru.u)
  connect(u_m, not1.u)
  connect(not1.y, truDel1.u)
  connect(valTru.y, valInp.u1)
  connect(truDel1.y, valInp.u2)
  connect(truDel1.y, valFal.u2)
  connect(u_m, valFal.u1)
  connect(conTru.y, valFal.u3)
  connect(valInp.y, not3.u)
  connect(not3.y, invInp.u1)
  connect(conTru.y, cheStaMea.u1)
  connect(u_s, not2.u)
  connect(not2.y, delChe1.u)
  connect(u_s, delChe2.u)
  connect(delChe2.y, pasDel.u1)
  connect(delChe1.y, pasDel.u2)
  connect(valInp.y, cheDif.u2)
  connect(pasDel.y, cheDif.u1)
  connect(cheDif.y, cheDif1.u2)
  connect(botTru.y, notBotTru.u)
  connect(notBotTru.y, truFal.u1)
  connect(valTru.y, botTru.u1)
  connect(u_s, truFal.u2)
  connect(u_s, booToInt1.u)
  connect(valFal.y, booToInt.u)
  connect(booToInt.y, equSta.u1)
  connect(booToInt1.y, equSta.u2)
  connect(not2.y, botFal.u1)
  connect(equSta.y, botFal.u2)
  connect(botFal.y, notBotFal.u)
  connect(notBotFal.y, falTru.u1)
  connect(not2.y, falTru.u2)
  connect(cheDif1.y, cheStaMea.u3)
  connect(cheDif.y, cheDif2.u2)
  connect(cheDif2.y, cheStaMea1.u3)
  connect(conTru.y, cheStaMea1.u1)
  connect(conFal.y, cheDif1.u3)
  connect(conFal.y, cheDif2.u3)
  connect(falTru.y, cheDif2.u1)
  connect(truFal.y, cheDif1.u1)
  connect(u_s, botTru.u2)
  connect(cheStaMea.y, holTru.u)
  connect(cheStaMea1.y, holTru1.u)
  connect(holTru.y, yLocFal)
  connect(holTru1.y, yLocTru)
  connect(botTru.y, equInp.u1)
  connect(equSta.y, equInp.u2)
  connect(samInpEdg.y, holTru.clr)
  connect(samInpEdg.y, holTru1.clr)
  connect(invInp.y, cheStaMea.u2)
  connect(invInp.y, cheStaMea1.u2)
  connect(not3.y, pasDeb.u)
  connect(pasDeb.passed, invInp.u2)
  connect(equInp.y, valEqu.u1)
  connect(valEqu.y, samInpEdg.u)
  connect(valInp.y, valEqu.u2)
end Proof;


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

within Buildings.Controls.OBC.CDL.Logical;
block Switch
  "Switch between two boolean signals"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Boolean switch input signal, if true, y=u1, else y=u3"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u3
    "Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Booelan output signal"

equation
  y=if u2 then
      u1
    else
      u3;
end Switch;


Timer measuring the time from the time instant where the Boolean input became true. If the Boolean input u is true,
the output y is the time that has elapsed since u became true.
Otherwise, y is 0.
If the output y becomes greater than the threshold time t,
the output passed is true.
Otherwise it is false.

within Buildings.Controls.OBC.CDL.Logical;
block Timer
  "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.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 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
          (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 Timer;


Accumulating timer that can be reset. Timer that accumulates time until it is reset by an input signal.

within Buildings.Controls.OBC.CDL.Logical;
block TimerAccumulating
  "Accumulating timer that can be reset"
  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
    "Connector for signal that sets timer to zero if it switches to true"
  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";
  discrete Real yAcc(
    final quantity="Time",
    final unit="s")
    "Accumulated time up to last change to true";

initial equation
  pre(u)=false;
  pre(reset)=false;
  pre(entryTime)=time;
  pre(passed)=t <= 0;
  yAcc=0;

equation
  // The when constructs below are identical to the ones in Buildings.Controls.OBC.CDL.Logical.Timer
  when reset then
    entryTime=time;
    passed=t <= 0;
    yAcc=0;
  elsewhen u 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 <= yAcc;
    yAcc=pre(yAcc);
  elsewhen u and time >= t+pre(entryTime)-pre(yAcc) then
    passed=true;
    entryTime=pre(entryTime);
    yAcc=pre(yAcc);
  elsewhen not u then
    passed=pre(passed);
    //time  >= t_internal + pre(entryTime);
    entryTime=pre(entryTime);
    yAcc=pre(y);
  end when;
  y=if u then
      yAcc+time-entryTime
    else
      yAcc;
end TimerAccumulating;


Toggles output value whenever its input turns true. Block that generates a true output when toggle input u
rises from false to true, provided that the clear input
clr is false or also became at the same time
false. The output remains true until

within Buildings.Controls.OBC.CDL.Logical;
block Toggle
  "Toggles output value whenever its input turns true"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Toggle input"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput clr
    "Clear input"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Output signal"

initial equation
  pre(y)=false;
  pre(u)=false;
  pre(clr)=false;

equation
  when initial() then
    //scenario = 1
    y=if clr then
        false
      else
        u;
  elsewhen
          (not clr) and change(u) and
                                     (pre(u) == false) and
                                                          (pre(y) == false) then
    //scenario = 2
    y=true;
  elsewhen
          (not clr) and change(u) and
                                     (pre(u) == false) and
                                                          (pre(y) == true) then
    //scenario = 3
    y=false;
  elsewhen
          (not clr) and change(u) and
                                     (pre(u) == true) then
    //scenario = 4
    y=pre(y);
  elsewhen clr then
    //scenario = 5
    y=false;
  end when;
end Toggle;


Delay a rising edge of the input, but do not delay a falling edge.. Block that delays a signal when it becomes true.

within Buildings.Controls.OBC.CDL.Logical;
block TrueDelay
  "Delay a rising edge of the input, but do not delay a falling edge."
  parameter Real delayTime(
    final quantity="Time",
    final unit="s")
    "Delay time";
  parameter Boolean delayOnInit=false
    "Set to true to delay initial true input";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  parameter Real t_past(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "Time before simulation started";
  Real t_next(
    final quantity="Time",
    final unit="s")
    "Next event time";

initial equation
  t_past=time-1000;
  pre(u)=false;
  pre(t_next)=time-1000;

equation
  when initial() then
    t_next=
      if not delayOnInit then
        t_past
      else
        time+delayTime;
    y=if not
            (delayOnInit and delayTime > 0) then
        u
      else
        false;
  elsewhen u then
    t_next=time+delayTime;
    y=if delayTime > 0 then
        false
      else
        true;
  elsewhen not u then
    t_next=t_past;
    y=false;
  elsewhen time >= pre(t_next) then
    t_next=t_past;
    y=u;
  end when;
end TrueDelay;


Block that holds an output signal for at least a specified duration. Block that holds a true or false signal for at least a defined time period.

within Buildings.Controls.OBC.CDL.Logical;
block TrueFalseHold
  "Block that holds an output signal for at least a specified duration"
  parameter Real trueHoldDuration(
    final quantity="Time",
    final unit="s")
    "true hold duration"
  parameter Real falseHoldDuration(
    final quantity="Time",
    final unit="s")=trueHoldDuration
    "false hold duration"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Boolean output signal"
protected
  /* The following parameter is required solely as a warkaround for a bug in OCT [Modelon - 1263].
  Both Dymola and OMC can handle the initial equation pre(u)=u, which complies with MLS. */
  parameter Boolean pre_u_start=false
    "Value of pre(u) at initial time"
  Boolean not_u = not u
    "Opposite of u";
  Boolean not_y = not y
    "Opposite of y";
  discrete Real entryTimeTrue(
    final quantity="Time",
    final unit="s")
    "Time instant when true hold started";
  discrete Real entryTimeFalse(
    final quantity="Time",
    final unit="s")
    "Time instant when false hold started";
initial equation
  pre(entryTimeTrue) = -Modelica.Constants.inf;
  pre(entryTimeFalse) = -Modelica.Constants.inf;
  pre(u) = pre_u_start;
  pre(not_u) = not pre_u_start;
  pre(y) = u;
  pre(not_y) = not u;
equation
  when initial() then
    y = u;
    entryTimeTrue = if y then time else pre(entryTimeTrue);
    entryTimeFalse = if not y then time else pre(entryTimeFalse);
  /*
  The two elsewhen clauses below are kept separate to address an issue
  with event handling in the CVODE solver.
  */
  elsewhen {edge(u), edge(not_u)} then
    y = if time >= pre(entryTimeFalse) + falseHoldDuration and
      time >= pre(entryTimeTrue) + trueHoldDuration then u
      else pre(y);
    entryTimeTrue = if edge(y) then time else pre(entryTimeTrue);
    entryTimeFalse = if edge(not_y) then time else pre(entryTimeFalse);
  elsewhen time >= pre(entryTimeFalse) + falseHoldDuration and
    time >= pre(entryTimeTrue) + trueHoldDuration then
    y = u;
    entryTimeTrue = if edge(y) then time else pre(entryTimeTrue);
    entryTimeFalse = if edge(not_y) then time else pre(entryTimeFalse);
  end when;
end TrueFalseHold;


Generate boolean pulse with the width specified by input. Block that outputs a boolean pulse.

within Buildings.Controls.OBC.CDL.Logical;
block VariablePulse "Generate boolean pulse with the width specified by input"

  parameter Real period(
    final quantity="Time",
    final unit="s")
    "Time for one pulse period";

  parameter Real deltaU(
    min = 0.001,
    max = 0.5,
    final unit="1") = 0.01 "Increment of u that triggers recomputation of output";

  parameter Real minTruFalHol(
    final quantity="Time",
    final unit="s",
    final min=Constants.small)=0.01*period
    "Minimum time to hold true or false";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final min=0,
    final max=1,
    final unit="1")
    "Ratio of the period that the output should be true"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Boolean pulse when the input is greater than zero"

protected
  parameter Real adjustedPeriod(
    final quantity="Time",
    final unit="s") = max(period, minTruFalHol*2.02)
    "Time for one pulse period";

  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam
    "Sample the input when there is value change"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Output the difference before and after sampling"
  Buildings.Controls.OBC.CDL.Reals.Abs abs1
    "Output the absolute value change"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=deltaU,
    final h=0)
    "Check if there is a sufficiently large change in input value"
  Buildings.Controls.OBC.CDL.Logical.Edge edg2
    "Rising edge when there is a width change"
  Buildings.Controls.OBC.CDL.Logical.Pre preBre
    "Break loop"
  Cycle cycOut(
    final period=adjustedPeriod,
    final minTruFalHol=minTruFalHol)
    "Produce boolean pulse output"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol(
    final trueHoldDuration=minTruFalHol,
    final falseHoldDuration=minTruFalHol)
    "Ensure the minimum holding time"

  block Cycle
    "Generate boolean pulse with the width specified by the input"
    parameter Real period(
      final quantity="Time",
      final unit="s",
      final min=Constants.small)
      "Time for one pulse period";
    parameter Real minTruFalHol(
      final quantity="Time",
      final unit="s",
      final min=Constants.small)
      "Minimum time to hold true or false";

    Buildings.Controls.OBC.CDL.Interfaces.BooleanInput go
      "True: cycle the output"
    Buildings.Controls.OBC.CDL.Interfaces.RealInput u
      "Ratio of the period that the output should be true"
    Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
      "Cycling boolean output"

    discrete Real t0(
      final quantity="Time",
      final unit="s",
      fixed=false)
      "Time instant when output begins cycling";
    Real t_sta(
      final quantity="Time",
      final unit="s",
      fixed=false)
      "Begin time instant of one period";
    Real t_end(
      final quantity="Time",
      final unit="s",
      fixed=false)
      "End time instant of one period";

  initial equation
    pre(t0)=time;

  equation
    when go then
      t0 = time;
    end when;

    t_sta = t0 + Buildings.Utilities.Math.Functions.round(
      x=integer((time-t0)/period)*period,
      n=6);
    t_end = t_sta + u*period;

    y = ((time>=t_sta) and (time<t_end));
  end Cycle;

initial equation
  assert(period >= minTruFalHol*2,
      "In " + getInstanceName() + ": The pulse period must be greater than 2 times of the minimum true and false holding time. Increasing period to " + String(adjustedPeriod) + ".",
      level = AssertionLevel.warning);

equation
  connect(u, triSam.u)
  connect(triSam.y, sub.u1)
  connect(u, sub.u2)
  connect(sub.y, abs1.u)
  connect(greThr.y, edg2.u)
  connect(greThr.y, preBre.u)
  connect(preBre.y, triSam.trigger)
  connect(u, cycOut.u)
  connect(cycOut.y, truFalHol.u)
  connect(truFalHol.y, y)
  connect(abs1.y, greThr.u)
  connect(edg2.y, cycOut.go)
end VariablePulse;


Logical 'xor': y = u1 xor u2. Block that outputs true if exactly one input is true.
Otherwise the output is false.

within Buildings.Controls.OBC.CDL.Logical;
block Xor
  "Logical 'xor': y = u1 xor u2"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1
    "Connector of first Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2
    "Connector of second Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=not
       ((u1 and u2) or
                      (not u1 and not u2));
end Xor;


Output constant signal of type Boolean. Block that outputs a constant signal y = k,
where k is a Boolean-valued parameter.

within Buildings.Controls.OBC.CDL.Logical.Sources;
block Constant
  "Output constant signal of type Boolean"
  parameter Boolean k
    "Constant output value";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

equation
  y=k;
end Constant;


within Buildings.Controls.OBC.CDL.Logical;
package Sources "Package with blocks that generate source signals"
end Sources;


Generate pulse signal of type Boolean. Block that outputs a pulse signal as shown below.

within Buildings.Controls.OBC.CDL.Logical.Sources;
block Pulse
  "Generate pulse signal of type Boolean"
  parameter Real width(
    final min=Constants.small,
    final max=1,
    final unit="1")=0.5
    "Width of pulse in fraction of period";
  parameter Real period(
    final quantity="Time",
    final unit="s",
    final min=Constants.small)
    "Time for one period";
  parameter Real shift(
    final quantity="Time",
    final unit="s")=0
    "Shift time for output";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  parameter Real t0(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "First sample time instant";
  parameter Real t1(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "First end of amplitude";

initial algorithm
  t0 := Buildings.Utilities.Math.Functions.round(
    x=integer((time)/period)*period+mod(shift,period),
    n=6);
  t1 := t0+width*period;
  // Make sure t0 and t1 are within time + period.
  if time+period < t1 then
    t0 := t0-period;
    t1 := t1-period;
  end if;
  // Make sure time is between t0 and t1, or t1 and t0
  // Now, t0 < t1
  if time >= t1 then
    t0 := t0+period;
  elseif time < t0 then
    t1 := t1-period;
  end if;
  // Assert that t0 <= t < t1 or t1 <= t < t0
  if
    (t0 < t1) then
    assert(
      t0 <= time and time < t1,
      getInstanceName()+": Implementation error in initial time calculation: t0 = "+String(t0)+", t1 = "+String(t1)+",  period = "+String(period)+", time = "+String(time));
    y := time >= t0 and time < t1;
  else
    assert(
      t1 <= time and time < t0,
      getInstanceName()+": Implementation error in initial time calculation: t0 = "+String(t0)+", t1 = "+String(t1)+",  period = "+String(period)+", time = "+String(time));
    y := not
            (time >= t1 and time < t0);
  end if;

equation
  when sample(
    t0,
    period) then
    y=true;
  elsewhen sample(
    t1,
    period) then
    y=false;
  end when;
end Pulse;


Generate sample trigger signal. The Boolean output y is a trigger signal that is only true
at sample times (defined by parameter period) and is otherwise
false.

within Buildings.Controls.OBC.CDL.Logical.Sources;
block SampleTrigger
  "Generate sample trigger signal"
  parameter Real period(
    final quantity="Time",
    final unit="s",
    final min=Constants.small)
    "Sample period";
  parameter Real shift(
    final quantity="Time",
    final unit="s")=0
    "Shift time for output";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Connector of Boolean output signal"

protected
  parameter Real t0(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "First sample time instant";

initial equation
  t0=Buildings.Utilities.Math.Functions.round(
    x=integer((time)/period)*period+mod(shift,period),
    n=6);

equation
  y=sample(
    t0,
    period);
end SampleTrigger;


Table look-up with respect to time with constant segments. Block that outputs true/false time table values.

within Buildings.Controls.OBC.CDL.Logical.Sources;
block TimeTable
  "Table look-up with respect to time with constant segments"
  parameter Real table[:,:]
    "Table matrix with time as a first column (in seconds, unless timeScale is not 1) and 0 for False or 1 for True in all other columns";
  parameter Real timeScale(
    final unit="1")=1
    "Time scale of first table column. Set to 3600 if time in table is in hours";
  parameter Real period(
    final quantity="Time",
    final unit="s")
    "Periodicity of table";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout]
    "Output of the table"

protected
  final parameter Integer nout=size(
    table,
    2)-1
    "Dimension of output vector";
  final parameter Integer nT=size(
    table,
    1)
    "Number of table points";
  Integers.Sources.TimeTable intTimTab(
    final table=table,
    final timeScale=timeScale,
    final period=period)
    "Time table"
  Integers.GreaterThreshold intGreThr[nout](
    each t=0)
    "Converts to boolean"

initial equation
  // Check that all values in the second column are Integer values
  for i in 1:nT loop
    for j in 2:size(
      table,
      2) loop
      assert(
        (abs(
          table[i,j]) < Constants.small) or
                                           (abs(
          table[i,j]-1.0) < Constants.small),
        "Table value table["+String(i)+", "+String(j)+"] = "+String(
          table[i,j])+" does not equal either 0 or 1.");
    end for;
  end for;

equation
  connect(intTimTab.y,intGreThr.u)
  connect(intGreThr.y,y)
end TimeTable;


Validate the Constant block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.Constant.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model Constant
  "Validate the Constant block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    k=true)
    "Block output boolean constant value"
end Constant;


within Buildings.Controls.OBC.CDL.Logical.Sources;
package Validation "Collection of models that validate the logical sources blocks of the CDL"
end Validation;


Validation model for the Boolean Pulse block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.Pulse.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model Pulse
  "Validation model for the Boolean Pulse block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a1(
    width=0.2,
    period=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b1(
    width=0.2,
    period=2,
    shift=0.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c1(
    width=0.2,
    period=2,
    shift=0.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a2(
    width=0.2,
    period=2,
    shift=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b2(
    width=0.2,
    period=2,
    shift=2.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c2(
    width=0.2,
    period=2,
    shift=2.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a3(
    width=0.2,
    period=2,
    shift=4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b3(
    width=0.2,
    period=2,
    shift=4.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c3(
    width=0.2,
    period=2,
    shift=4.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a4(
    width=0.2,
    period=2,
    shift=-2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b4(
    width=0.2,
    period=2,
    shift=-1.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c4(
    width=0.2,
    period=2,
    shift=-1.4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a5(
    width=0.2,
    period=2,
    shift=-4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b5(
    width=0.2,
    period=2,
    shift=-3.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c5(
    width=0.2,
    period=2,
    shift=-3.4)
    "Boolean pulse signal"
end Pulse;


Validation model for the Boolean Pulse block with negative start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.Pulse.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model PulseNegativeStartTime
  "Validation model for the Boolean Pulse block with negative start time"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a1(
    width=0.2,
    period=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b1(
    width=0.2,
    period=2,
    shift=0.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c1(
    width=0.2,
    period=2,
    shift=0.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a2(
    width=0.2,
    period=2,
    shift=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b2(
    width=0.2,
    period=2,
    shift=2.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c2(
    width=0.2,
    period=2,
    shift=2.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a3(
    width=0.2,
    period=2,
    shift=4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b3(
    width=0.2,
    period=2,
    shift=4.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c3(
    width=0.2,
    period=2,
    shift=4.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a4(
    width=0.2,
    period=2,
    shift=-2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b4(
    width=0.2,
    period=2,
    shift=-1.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c4(
    width=0.2,
    period=2,
    shift=-1.4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a5(
    width=0.2,
    period=2,
    shift=-4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b5(
    width=0.2,
    period=2,
    shift=-3.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c5(
    width=0.2,
    period=2,
    shift=-3.4)
    "Boolean pulse signal"
end PulseNegativeStartTime;


Validation model for the Boolean Pulse block with positive, non-zero start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.Pulse.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model PulsePositiveStartTime
  "Validation model for the Boolean Pulse block with positive, non-zero start time"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a1(
    width=0.2,
    period=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b1(
    width=0.2,
    period=2,
    shift=0.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c1(
    width=0.2,
    period=2,
    shift=0.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a2(
    width=0.2,
    period=2,
    shift=2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b2(
    width=0.2,
    period=2,
    shift=2.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c2(
    width=0.2,
    period=2,
    shift=2.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a3(
    width=0.2,
    period=2,
    shift=4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b3(
    width=0.2,
    period=2,
    shift=4.1)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c3(
    width=0.2,
    period=2,
    shift=4.6)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a4(
    width=0.2,
    period=2,
    shift=-2)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b4(
    width=0.2,
    period=2,
    shift=-1.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c4(
    width=0.2,
    period=2,
    shift=-1.4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_a5(
    width=0.2,
    period=2,
    shift=-4)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_b5(
    width=0.2,
    period=2,
    shift=-3.9)
    "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul_c5(
    width=0.2,
    period=2,
    shift=-3.4)
    "Boolean pulse signal"
end PulsePositiveStartTime;


Validation model for the SampleTrigger block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger.
The instances samTri and samTri1 use a different value for the parameter shift.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model SampleTrigger
  "Validation model for the SampleTrigger block"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri(
    period=0.5)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp(
    duration=5,
    offset=0,
    height=20)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Triggered sampler"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri1(
    period=0.5,
    shift=1.3)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler1
    "Triggered sampler"

equation
  connect(ramp.y,triggeredSampler.u)
  connect(samTri.y,triggeredSampler.trigger)
  connect(samTri1.y,triggeredSampler1.trigger)
  connect(triggeredSampler1.u,ramp.y)
end SampleTrigger;


Validation model for the SampleTrigger block with a negative start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger
with negative start time.
The instances samTri and samTri1 use a different value for the parameter shift.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model SampleTriggerNegativeStartTime
  "Validation model for the SampleTrigger block with a negative start time"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri(
    period=0.5)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp(
    duration=5,
    offset=0,
    height=20,
    startTime=-2)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Triggered sampler"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri1(
    period=0.5,
    shift=3.2)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler1
    "Triggered sampler"

equation
  connect(ramp.y,triggeredSampler.u)
  connect(samTri.y,triggeredSampler.trigger)
  connect(samTri1.y,triggeredSampler1.trigger)
  connect(triggeredSampler1.u,ramp.y)
end SampleTriggerNegativeStartTime;


Validation model for the SampleTrigger block with a positive start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger
with positive start time.
The instances samTri and samTri1 use a different value for the parameter shift.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model SampleTriggerPositiveStartTime
  "Validation model for the SampleTrigger block with a positive start time"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri(
    period=0.5)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp(
    duration=5,
    offset=0,
    height=20,
    startTime=1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Triggered sampler"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri1(
    period=0.5,
    shift=0.3)
    "Block that generates sample trigger signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler1(
    y_start=-2)
    "Triggered sampler"

equation
  connect(ramp.y,triggeredSampler.u)
  connect(samTri.y,triggeredSampler.trigger)
  connect(samTri1.y,triggeredSampler1.trigger)
  connect(triggeredSampler1.u,ramp.y)
end SampleTriggerPositiveStartTime;


Validation model for TimeTable block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model TimeTable
  "Validation model for TimeTable block"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTab(
    table=[
      0,1,0;
      1.3,1,1;
      2.9,0,0;
      4,1,0],
    period=5)
    "Time table with boolean output"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTabOneRow(
    table=[
      0,1,0],
    period=1)
    "Time table with boolean output for a single table row"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTabTwi(
    table=[
      0,1,0;
      1.3,1,1;
      2.9,0,0;
      4,1,0],
    period=10,
    timeScale=2)
    "Time table with boolean output, periodic repetition, and doubled time"
end TimeTable;


Validation model for TimeTable block with negative start time.

within Buildings.Controls.OBC.CDL.Logical.Sources.Validation;
model TimeTableNegativeStartTime
  "Validation model for TimeTable block with negative start time"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTab(
    table=[
      0,1,0;
      1.3,1,1;
      2.9,0,0;
      4,1,0],
    period=5)
    "Time table with boolean output"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTabOneRow(
    table=[
      0,1,0],
    period=1)
    "Time table with boolean output for a single table row"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable booTimTabTwi(
    table=[
      0,1,0;
      1.3,1,1;
      2.9,0,0;
      4,1,0],
    period=10,
    timeScale=2)
    "Time table with boolean output, periodic repetition, and doubled time"
end TimeTableNegativeStartTime;


Validation model for the And block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.And.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model And
  "Validation model for the And block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "Logical and"

equation
  connect(booPul2.y,and1.u2)
  connect(booPul1.y,and1.u1)
end And;


Validation model for the Change block.. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Change.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Change
  "Validation model for the Change block."
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=1.0)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Change change
    "Outputs true if the input changes"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=5,
    offset=0,
    height=20)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Triggered sampler"

equation
  connect(booPul.y,change.u)
  connect(ramp2.y,triggeredSampler.u)
  connect(change.y,triggeredSampler.trigger)
end Change;


Validation model for the Edge block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Edge.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Edge
  "Validation model for the Edge block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=1.0)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Edge edge1
    "Outputs true if the input has a rising edge"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=5,
    offset=0,
    height=20)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Triggered sampler"

equation
  connect(booPul.y,edge1.u)
  connect(edge1.y,triggeredSampler.trigger)
  connect(ramp2.y,triggeredSampler.u)
end Edge;


Validation model for the falling edge block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.FallingEdge.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model FallingEdge
  "Validation model for the falling edge block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=1.0)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg
    "Output true when input changes from true to false"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=5,
    offset=0,
    height=20)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triggeredSampler
    "Trigger sampling of continuous signal"

equation
  connect(booPul.y,falEdg.u)
  connect(ramp2.y,triggeredSampler.u)
  connect(falEdg.y,triggeredSampler.trigger)
end FallingEdge;


Validation model for the Latch block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Latch. Following tests are implemented:

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Latch
  "Validation model for the Latch block"
  Buildings.Controls.OBC.CDL.Logical.Latch falCleTruIni
    "Latch block with clear input being contantly false and true initial latch input"
  Buildings.Controls.OBC.CDL.Logical.Latch truCleTruIni
    "Latch block with clear input being contantly true and true initial latch input"
  Buildings.Controls.OBC.CDL.Logical.Latch falCleFalIni
    "Latch block with clear input being contantly false and false initial latch input"
  Buildings.Controls.OBC.CDL.Logical.Latch truCleFalIni
    "Latch block with clear input being contantly true and false initial latch input"
  Buildings.Controls.OBC.CDL.Logical.Latch swiCleInp
    "Initial false output, with clear input switch between false and true"
  Buildings.Controls.OBC.CDL.Logical.Latch swiCleInp1
    "Initial false output, with clear input switch between false and true"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse cleInp(
    final width=0.5,
    final period=6)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logcal not"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fal(
    final k=false)
    "False clear input"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp(
    final width=0.5,
    final period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant tru(
    final k=true)
    "True clear input"
  Buildings.Controls.OBC.CDL.Logical.Not not2
    "Logical not"

equation
  connect(cleInp.y,swiCleInp.clr)
  connect(not1.u,cleInp.y)
  connect(not1.y,swiCleInp1.clr)
  connect(fal.y,falCleTruIni.clr)
  connect(latInp.y,falCleTruIni.u)
  connect(tru.y,truCleTruIni.clr)
  connect(latInp.y,truCleTruIni.u)
  connect(latInp.y,swiCleInp.u)
  connect(latInp.y,swiCleInp1.u)
  connect(latInp.y,not2.u)
  connect(not2.y,falCleFalIni.u)
  connect(fal.y,falCleFalIni.clr)
  connect(tru.y,truCleFalIni.clr)
  connect(not2.y,truCleFalIni.u)
end Latch;


Model to validate the application of MultiAnd block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.MultiAnd.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model MultiAnd
  "Model to validate the application of MultiAnd block"
  Buildings.Controls.OBC.CDL.Logical.MultiAnd mulAnd0
    "Logical and with multiple inputs: 0 input"
  Buildings.Controls.OBC.CDL.Logical.MultiAnd mulAnd1(
    nin=1)
    "Logical 'MultiAnd': 1 input connection y=u"
  Buildings.Controls.OBC.CDL.Logical.MultiAnd mulAnd2(
    nin=2)
    "Logical 'MultiAnd': 2 input connections y=and(u1, u2)"
  Buildings.Controls.OBC.CDL.Logical.MultiAnd mulAnd5(
    nin=5)
    "Logical 'MultiAnd': 5 input connections y=and(u1, u2, ..., u5)"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul3(
    width=0.5,
    period=3)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul4(
    width=0.5,
    period=4)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul5(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"

equation
  connect(booPul1.y,mulAnd5.u[1])
  connect(booPul2.y,mulAnd5.u[2])
  connect(booPul3.y,mulAnd5.u[3])
  connect(booPul4.y,mulAnd5.u[4])
  connect(booPul5.y,mulAnd5.u[5])
  connect(booPul1.y,mulAnd2.u[1])
  connect(booPul2.y,mulAnd2.u[2])
  connect(booPul1.y,mulAnd1.u[1])
end MultiAnd;


Model to validate the application of MultiOr block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.MultiOr.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model MultiOr
  "Model to validate the application of MultiOr block"
  Buildings.Controls.OBC.CDL.Logical.MultiOr mulOr0
    "Logical 'MultiOr': 1 input connection y=u"
  Buildings.Controls.OBC.CDL.Logical.MultiOr mulOr1(
    nin=1)
    "Logical 'MultiOr': 1 input connection y=u"
  Buildings.Controls.OBC.CDL.Logical.MultiOr mulOr2(
    nin=2)
    "Logical 'MultiOr': 2 input connections y=and(u1, u2)"
  Buildings.Controls.OBC.CDL.Logical.MultiOr mulOr5(
    nin=5)
    "Logical 'MultiOr': 5 input connections y=and(u1, u2, ..., u5)"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul3(
    width=0.5,
    period=3)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul4(
    width=0.5,
    period=4)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul5(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"

equation
  connect(booPul1.y,mulOr5.u[1])
  connect(booPul2.y,mulOr5.u[2])
  connect(booPul3.y,mulOr5.u[3])
  connect(booPul4.y,mulOr5.u[4])
  connect(booPul5.y,mulOr5.u[5])
  connect(booPul1.y,mulOr2.u[1])
  connect(booPul2.y,mulOr2.u[2])
  connect(booPul1.y,mulOr1.u[1])
end MultiOr;


Validation model for the Nand block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Nand.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Nand
  "Validation model for the Nand block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Nand nand1
    "Outputs true if at least one input is false"

equation
  connect(booPul2.y,nand1.u2)
  connect(booPul1.y,nand1.u1)
end Nand;


Validation model for the Nor block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Nor.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Nor
  "Validation model for the Nor block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Nor nor1
    "Outputs true if none of the inputs is true, otherwise outputs false"

equation
  connect(booPul2.y,nor1.u2)
  connect(booPul1.y,nor1.u1)
end Nor;


Validation model for the Not block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Not.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Not
  "Validation model for the Not block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Output true when input is false and output false when input is true"

equation
  connect(booPul.y,not1.u)
end Not;


Validation model for the Or block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Or.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Or
  "Validation model for the Or block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.5,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=3)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "Output true if at least one input is true"

equation
  connect(booPul2.y,or1.u2)
  connect(booPul1.y,or1.u1)
end Or;


within Buildings.Controls.OBC.CDL.Logical;
package Validation "Collection of models that validate the logical blocks of the CDL"
end Validation;


Validation model for the Proof block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Proof. The following tests are implemented:

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Proof "Validation model for the Proof block"
  Buildings.Controls.OBC.CDL.Logical.Proof pro(
    debounce=0.5,
    feedbackDelay=0.75) "Both inputs change at the same time"
  Buildings.Controls.OBC.CDL.Logical.Proof pro1(
    debounce=0.5,
    feedbackDelay=0.75)
    "Commanded input changes from true to false earlier than measured input"
  Buildings.Controls.OBC.CDL.Logical.Proof pro2(
    debounce=0.5,
    feedbackDelay=0.75)
    "Measured input changes from true to false earlier than commanded input"
  Buildings.Controls.OBC.CDL.Logical.Proof pro3(
    debounce=0.5,
    feedbackDelay=0.5)
    "Shorter delay to valid input"
  Buildings.Controls.OBC.CDL.Logical.Proof pro4(
    debounce=0.5,
    feedbackDelay=0.5)
    "Shorter delay to valid input"
  Buildings.Controls.OBC.CDL.Logical.Proof pro5(
    debounce=2,
    feedbackDelay=2)
    "Both inputs change at the same time"

  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp(
    width=0.2,
    period=10,
    shift=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp1(
    width=0.2,
    period=10,
    shift=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp2(
    width=0.1,
    period=10,
    shift=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp3(
    width=0.5,
    period=2,
    shift=1)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse latInp4(
    width=0.9,
    period=12,
    shift=0.5)
    "Block that outputs cyclic on and off"
equation
  connect(latInp1.y, pro.u_s)
  connect(latInp2.y, pro1.u_s)
  connect(latInp1.y, pro2.u_s)
  connect(latInp2.y, pro4.u_s)
  connect(latInp1.y, pro3.u_s)
  connect(latInp.y, pro.u_m)
  connect(latInp1.y, pro4.u_m)
  connect(latInp2.y, pro3.u_m)
  connect(latInp2.y, pro2.u_m)
  connect(latInp1.y, pro1.u_m)
  connect(latInp3.y, pro5.u_m)
  connect(latInp4.y, pro5.u_s)
end Proof;


Validation model for the Switch block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Switch.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Switch "Validation model for the Switch block"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    width=0.7,
    period=1.5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    width=0.5,
    period=3)
    "Block that outputs cyclic on and off: switch between u1 and u3"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul3(
    width=0.5,
    period=5)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Switch logicalSwitch
    "Switch between two boolean inputs"

equation
  connect(booPul2.y,logicalSwitch.u2)
  connect(booPul1.y,logicalSwitch.u1)
  connect(booPul3.y,logicalSwitch.u3)
end Switch;


Validation model for the Timer block. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Timer.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model Timer
  "Validation model for the Timer block"
  Buildings.Controls.OBC.CDL.Logical.Timer noThr
    "Timer that do not compare threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer thrTim(
    final t=0.3)
    "Timer that compares threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer thrTim1(
    final t=0.3)
    "Timer that compares threshold"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.7,
    final period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    final width=0.7,
    final period=2,
    final shift=-1)
    "Block that outputs cyclic on and off"

equation
  connect(booPul.y,noThr.u)
  connect(booPul.y,thrTim.u)
  connect(booPul1.y,thrTim1.u)
end Timer;


Validation model for the timer that accumulates the time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.TimerAccumulating.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model TimerAccumulating
  "Validation model for the timer that accumulates the time"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating noThr
    "Accumulating timer that do not compare threshold"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating thrTim(
    final t=1)
    "Accumulating timer that compares threshold"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating noThrWitRes
    "Accumulating timer that could reset the output"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating thrTimWitRes(
    final t=1)
    "Accumulating timer that could reset the output and the output compares with threshold"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.5,
    final period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Constant false"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse resTim(
    final width=0.5,
    final period=3.5)
    "Block that outputs cyclic on and off, for resetting timer"

equation
  connect(booPul.y,noThr.u)
  connect(booPul.y,thrTim.u)
  connect(con.y,noThr.reset)
  connect(con.y,thrTim.reset)
  connect(booPul.y,noThrWitRes.u)
  connect(booPul.y,thrTimWitRes.u)
  connect(resTim.y,noThrWitRes.reset)
  connect(resTim.y,thrTimWitRes.reset)
end TimerAccumulating;


Validation model for the timer that accumulates the time, with a negative start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.TimerAccumulating.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model TimerAccumulatingNegativeStartTime
  "Validation model for the timer that accumulates the time, with a negative start time"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating noThr
    "Accumulating timer that do not compare threshold"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating thrTim(
    final t=1)
    "Accumulating timer that compares threshold"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating noThrWitRes
    "Accumulating timer that could reset the output"
  Buildings.Controls.OBC.CDL.Logical.TimerAccumulating thrTimWitRes(
    final t=1)
    "Accumulating timer that could reset the output and the output compares with threshold"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.5,
    final period=4,
    shift=-11)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Constant false"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse resTim(
    final width=0.5,
    final period=3.5,
    shift=-5)
    "Block that outputs cyclic on and off, for resetting timer"

equation
  connect(booPul.y,noThr.u)
  connect(booPul.y,thrTim.u)
  connect(con.y,noThr.reset)
  connect(con.y,thrTim.reset)
  connect(booPul.y,noThrWitRes.u)
  connect(booPul.y,thrTimWitRes.u)
  connect(resTim.y,noThrWitRes.reset)
  connect(resTim.y,thrTimWitRes.reset)
end TimerAccumulatingNegativeStartTime;


Validation model for the Timer block with a negative start time. Validation test for the block

Buildings.Controls.OBC.CDL.Logical.Timer.

within Buildings.Controls.OBC.CDL.Logical.Validation;
model TimerNegativeStartTime
  "Validation model for the Timer block with a negative start time"
  Buildings.Controls.OBC.CDL.Logical.Timer noThr
    "Timer that do not compare threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer thrTim(
    final t=0.3)
    "Timer that compares threshold"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.7,
    final period=2,
    shift=-5)
    "Block that outputs cyclic on and off"

equation
  connect(booPul.y,noThr.u)
  connect(booPul.y,thrTim.u)
end TimerNegativeStartTime;