Validation model for the Limiter block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Limiter
  "Validation model for the Limiter block"
  Buildings.Controls.OBC.CDL.Reals.Limiter limiter1(
    uMax=2.5,
    uMin=1.2)
    "Block that limit the range of a signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=0,
    height=4)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,limiter1.u)
end Limiter;


Validation model for the LimitSlewRate block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model LimitSlewRate "Validation model for the LimitSlewRate block"
  Buildings.Controls.OBC.CDL.Reals.LimitSlewRate sleRatLim(
    raisingSlewRate=1/30)
    "Block that limit the increase or decrease rate of input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    offset=0,
    height=1.5,
    duration=20,
    startTime=10)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    offset=0,
    height=-1.5,
    startTime=60,
    duration=20)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Add add
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp3(
    offset=0,
    height=-1.5,
    duration=30,
    startTime=120+60)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp4(
    offset=0,
    height=1.5,
    duration=30,
    startTime=120)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp5(
    offset=0,
    height=-1.5,
    startTime=240+60,
    duration=40)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp6(
    offset=0,
    height=1.5,
    startTime=240,
    duration=40)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Add add1
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Add add2
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp7(
    offset=0,
    height=-1.5,
    duration=50,
    startTime=360+60)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp8(
    offset=0,
    height=1.5,
    duration=50,
    startTime=360)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Add add3
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Add add4
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Add add5
    "Signal adder"
  Buildings.Controls.OBC.CDL.Reals.Add add6
    "Signal adder"

equation
  connect(ramp1.y,add.u1)
  connect(ramp2.y,add.u2)
  connect(ramp4.y,add1.u1)
  connect(ramp3.y,add1.u2)
  connect(ramp6.y,add2.u1)
  connect(ramp5.y,add2.u2)
  connect(ramp8.y,add3.u1)
  connect(ramp7.y,add3.u2)
  connect(add.y,add4.u1)
  connect(add1.y,add4.u2)
  connect(add2.y,add5.u1)
  connect(add3.y,add5.u2)
  connect(add4.y,add6.u1)
  connect(add5.y,add6.u2)
  connect(sleRatLim.u,add6.y)
end LimitSlewRate;


Validation model for the Line block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Line
  "Validation model for the Line block"
  Buildings.Controls.OBC.CDL.Reals.Line line1
    "Block that out the value of the input x along a line specified by two points"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant x1(
    k=1.0)
    "Block that generate x1"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant f1(
    k=0.5)
    "Block that generate f(x1)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant x2(
    k=2.0)
    "Block that generate x2"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant f2(
    k=1.5)
    "Block that generate f(x2)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    offset=0,
    duration=0.5,
    startTime=0.25,
    height=3)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Line line2(
    limitAbove=true,
    limitBelow=false)
    "Block that out the value of the input x along a line specified by two points"
  Buildings.Controls.OBC.CDL.Reals.Line line3(
    limitBelow=true,
    limitAbove=false)
    "Block that out the value of the input x along a line specified by two points"

equation
  connect(ramp1.y,line1.u)
  connect(f1.y,line1.f1)
  connect(x1.y,line1.x1)
  connect(x2.y,line1.x2)
  connect(f2.y,line1.f2)
  connect(ramp1.y,line2.u)
  connect(f1.y,line2.f1)
  connect(x1.y,line2.x1)
  connect(x2.y,line2.x2)
  connect(f2.y,line2.f2)
  connect(ramp1.y,line3.u)
  connect(f1.y,line3.f1)
  connect(x1.y,line3.x1)
  connect(x2.y,line3.x2)
  connect(f2.y,line3.f2)
end Line;


Validation model for the Log block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Log
  "Validation model for the Log block"
  Buildings.Controls.OBC.CDL.Reals.Log log1
    "Block that outputs the natural (base e) logarithm of the input (input > 0 required)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=1,
    height=5)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,log1.u)
end Log;


Validation model for the Log10 block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Log10
  "Validation model for the Log10 block"
  Buildings.Controls.OBC.CDL.Reals.Log10 log10_1
    "Block that outputs the base 10 logarithm of the input (input > 0 required)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=1,
    height=9)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,log10_1.u)
end Log10;


Validation model for the MatrixGain block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MatrixGain
  "Validation model for the MatrixGain block"
  Buildings.Controls.OBC.CDL.Reals.MatrixGain matGai(
    K=[
      1,0;
      1,1;
      1,2])
    "Block that outputs the product of a matrix gain value with the input signal"
  Buildings.Controls.OBC.CDL.Reals.MatrixGain matGai1(
    K=[
      1,2;
      3,4])
    "Block that outputs the product of a matrix gain value with the input signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp(
    duration=1,
    offset=0,
    height=2)
    "Block that generates ramp signal"
  Reals.Sources.Ramp ramp1(
    duration=1,
    offset=0,
    height=1)
    "Block that generates ramp signal"
  Reals.Sources.Ramp ramp2(
    duration=1,
    offset=0,
    height=2)
    "Block that generates ramp signal"

equation
  connect(ramp2.y,matGai1.u[2])
  connect(ramp1.y,matGai1.u[1])
  connect(ramp.y,matGai.u[1])
  connect(ramp.y,matGai.u[2])
end MatrixGain;


Validation model for the MatrixMax block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MatrixMax
  "Validation model for the MatrixMax block"
  Reals.Sources.Constant con[3,3](
    k={{1,2,3},{6,4,2},{3,9,6}})
    "Block that generates ramp signal"
  Reals.Sources.Constant con1[2,3](
    k={{1,4,3},{2,2,6}})
    "Block that generates ramp signal"
  Reals.Sources.Constant con2[2,3](
    k={{1,2,3},{6,4,2}})
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.MatrixMax matMax(
    rowMax=false,
    nRow=3,
    nCol=3)
    "Matrix maximum"
  Buildings.Controls.OBC.CDL.Reals.MatrixMax matMax1(
    nCol=3,
    nRow=2)
    "Matrix maximum"
  Buildings.Controls.OBC.CDL.Reals.MatrixMax matMax2(
    nCol=3,
    nRow=2)
    "Matrix maximum"

equation
  connect(con.y,matMax.u)
  connect(con1.y,matMax1.u)
  connect(con2.y,matMax2.u)
end MatrixMax;


Validation model for the MatrixMin block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MatrixMin
  "Validation model for the MatrixMin block"
  Reals.Sources.Constant con[3,3](
    k={{-1,-2,-3},{-6,-4,-2},{-3,-9,-6}})
    "Block that generates ramp signal"
  Reals.Sources.Constant con1[2,3](
    k={{-1,-4,-3},{-2,-2,-6}})
    "Block that generates ramp signal"
  Reals.Sources.Constant con2[2,3](
    k={{-1,-2,-3},{-6,-4,-2}})
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.MatrixMin matMin(
    nRow=3,
    nCol=3,
    rowMin=false)
    "Matrix minimum"
  Buildings.Controls.OBC.CDL.Reals.MatrixMin matMin1(
    nCol=3,
    rowMin=false,
    nRow=2)
    "Matrix minimum"
  Buildings.Controls.OBC.CDL.Reals.MatrixMin matMin2(
    nCol=3,
    rowMin=true,
    nRow=2)
    "Matrix minimum"

equation
  connect(con.y,matMin.u)
  connect(con1.y,matMin1.u)
  connect(con2.y,matMin2.u)
end MatrixMin;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Max
  "Validation model for the Max block"
  Buildings.Controls.OBC.CDL.Reals.Max max1
    "Block that pass through the largest signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=2)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,max1.u1)
  connect(ramp2.y,max1.u2)
end Max;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Min
  "Validation model for the Min block"
  Buildings.Controls.OBC.CDL.Reals.Min min1
    "Block that pass through the smallest signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=2)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,min1.u1)
  connect(ramp2.y,min1.u2)
end Min;


Validation model for the Modulo block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Modulo
  "Validation model for the Modulo block"
  Buildings.Controls.OBC.CDL.Reals.Modulo mod1
    "Block that outputs the remainder of first input divided by second input (~=0)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=6)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=1.5,
    height=3.0)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,mod1.u1)
  connect(ramp2.y,mod1.u2)
end Modulo;


Validation model for the MovingAverage block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MovingAverage "Validation model for the MovingAverage block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sinInpNoDel(
    freqHz=1/80) "Start from zero second"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve1(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve2(delta=200)
    "Moving average with 200 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve3(delta=300)
    "Moving average with 300 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve4(delta=400)
    "Moving average with 400 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve5(delta=500)
    "Moving average with 500 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sinInp50sDel(
    freqHz=1/80,
    startTime=50)
    "Start from 50 seconds"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve6(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve7(delta=200)
    "Moving average with 200 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sinInp100sDel(
    freqHz=1/80,
    startTime=100)
    "Start from 100 seconds"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve8(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve9(delta=200)
    "Moving average with 200 s sliding window"

equation
  connect(sinInpNoDel.y,movAve3.u)
  connect(sinInpNoDel.y,movAve1.u)
  connect(sinInpNoDel.y,movAve2.u)
  connect(sinInpNoDel.y,movAve5.u)
  connect(sinInpNoDel.y,movAve4.u)
  connect(sinInp50sDel.y,movAve6.u)
  connect(sinInp50sDel.y,movAve7.u)
  connect(sinInp100sDel.y,movAve9.u)
  connect(sinInp100sDel.y,movAve8.u)
end MovingAverage;


within Buildings.Controls.OBC.CDL.Reals.Validation;
model MovingAverage_nonZeroStart
  "Validation model for the MovingAverage block"
  Modelica.Blocks.Sources.Sine sinInpNoDel(f=1/80) "Start from zero second"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve1(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve2(delta=200)
    "Moving average with 200 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve3(delta=300)
    "Moving average with 300 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve4(delta=400)
    "Moving average with 400 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve5(delta=500)
    "Moving average with 500 s sliding window"
  Modelica.Blocks.Sources.Sine sinInp50sDel(f=1/80, startTime=50)
    "Start from 50 seconds"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve6(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve7(delta=200)
    "Moving average with 200 s sliding window"
  Modelica.Blocks.Sources.Sine sinInp100sDel(f=1/80, startTime=100)
    "Start from 100 seconds"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve8(delta=100)
    "Moving average with 100 s sliding window"
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve9(delta=200)
    "Moving average with 200 s sliding window"

equation
  connect(sinInpNoDel.y,movAve3.u)
  connect(sinInpNoDel.y,movAve1.u)
  connect(sinInpNoDel.y,movAve2.u)
  connect(sinInpNoDel.y,movAve5.u)
  connect(sinInpNoDel.y,movAve4.u)
  connect(sinInp50sDel.y,movAve6.u)
  connect(sinInp50sDel.y,movAve7.u)
  connect(sinInp100sDel.y,movAve9.u)
  connect(sinInp100sDel.y,movAve8.u)
end MovingAverage_nonZeroStart;


Validation model for the MultiMax block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MultiMax
  "Validation model for the MultiMax block"
  parameter Integer sizOfVec=5
    "Size of the input vector";
  Buildings.Controls.OBC.CDL.Reals.MultiMax maxVal(
    nin=sizOfVec)
    "Block that outputs the maximum element of the input vector"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con[sizOfVec](
    k={1,2,3,4,5})
    "Block that generates ramp signal"

equation
  connect(con.y,maxVal.u)
end MultiMax;


Validation model for the MultiMin block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MultiMin
  "Validation model for the MultiMin block"
  parameter Integer sizOfVec=5
    "Size of the input vector";
  Buildings.Controls.OBC.CDL.Reals.MultiMin minVal(
    nin=sizOfVec)
    "Block that outputs the minimum element of the input vector"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con[sizOfVec](
    k={1,2,3,4,5})
    "Block that generates ramp signal"

equation
  for i in 1:sizOfVec loop
    connect(con[i].y,minVal.u[i])
  end for;
end MultiMin;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Multiply "Validation model for the Multiply block"
  Buildings.Controls.OBC.CDL.Reals.Multiply product1
    "Block that outputs product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=3)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,product1.u1)
  connect(ramp2.y,product1.u2)
end Multiply;


Validation model for the Gain block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MultiplyByParameter "Validation model for the Gain block"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gain1(k=2.5)
    "Block that outputs the product of a gain value with the input signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=0,
    height=2)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,gain1.u)
end MultiplyByParameter;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model MultiSum
  "Model to validate the application of MultiSum block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    height=2,
    duration=1,
    offset=-1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp3(
    height=3,
    duration=1,
    offset=-1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp4(
    height=3,
    duration=1,
    offset=-2)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp5(
    height=3,
    duration=1,
    offset=-3)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.MultiSum mulSum_5(
    nin=5,
    k={1,0.5,0.1,1,2})
    "Sum of Reals, y = k[1]*u[1] + k[2]*u[2] + ... + k[5]*u[5]"
  Buildings.Controls.OBC.CDL.Reals.MultiSum mulSum_2(
    nin=2,
    k={1,0.5})
    "Sum of Reals, y = k[1]*u[1] + k[2]*u[2]"
  Buildings.Controls.OBC.CDL.Reals.MultiSum mulSum_1(
    nin=1,
    k={1})
    "Sum of Reals, y = k[1]*u[1]"
  Buildings.Controls.OBC.CDL.Reals.MultiSum mulSum_3(
    nin=3)
    "Sum of Reals, y = k[1]*u[1] + k[2]*u[2]"

equation
  connect(ramp1.y,mulSum_5.u[1])
  connect(ramp2.y,mulSum_5.u[2])
  connect(ramp3.y,mulSum_5.u[3])
  connect(ramp4.y,mulSum_5.u[4])
  connect(ramp5.y,mulSum_5.u[5])
  connect(ramp1.y,mulSum_1.u[1])
  connect(ramp1.y,mulSum_2.u[1])
  connect(ramp2.y,mulSum_2.u[2])
  connect(ramp4.y,mulSum_3.u[1])
  connect(ramp5.y,mulSum_3.u[2])
  connect(ramp5.y,mulSum_3.u[3])
end MultiSum;


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


Test model for PID controller. Validation test for the block

Buildings.Controls.OBC.CDL.Reals.PID.
This tests the different settings for the controller types.

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PID
  "Test model for PID controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pulse(
    period=0.25)
    "Setpoint"
  Buildings.Controls.OBC.CDL.Reals.PID limPID(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    Ti=1,
    Td=1,
    yMin=-1)
    "PID controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant const(
    k=0.5)
    "Measurement data"
  Buildings.Controls.OBC.CDL.Reals.PID limPI(
    Ti=1,
    Td=1,
    yMin=-1,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI)
    "PI controller"
  Buildings.Controls.OBC.CDL.Reals.PID limPD(
    Ti=1,
    Td=1,
    yMin=-1,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PD)
    "PD controller"
  Buildings.Controls.OBC.CDL.Reals.PID limP(
    Ti=1,
    Td=1,
    yMin=-1,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P)
    "P controller"
  Buildings.Controls.OBC.CDL.Reals.PID noLimPID(
    Ti=1,
    Td=1,
    yMax=1e15,
    yMin=-1e15,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID)
    "PID controller with no output limit"

equation
  connect(pulse.y,limPID.u_s)
  connect(const.y,limPID.u_m)
  connect(const.y,limPI.u_m)
  connect(const.y,limPD.u_m)
  connect(pulse.y,limPI.u_s)
  connect(pulse.y,limPD.u_s)
  connect(pulse.y,limP.u_s)
  connect(pulse.y,noLimPID.u_s)
  connect(const.y,limP.u_m)
  connect(const.y,noLimPID.u_m)
end PID;


Test model for LimPID controller with initial output of the derivative term specified. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PIDInitialDerivativeOutput
  "Test model for LimPID controller with initial output of the derivative term specified"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant ySet(
    k=0.75)
    "Set point"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yMea(
    k=0.75)
    "Measured value"
  Buildings.Controls.OBC.CDL.Reals.PID limPID(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=3,
    yd_start=0.2)
    "PID controller"
  Buildings.Controls.OBC.CDL.Reals.PID limPD(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PD,
    k=3,
    yd_start=0.2)
    "PD controller"

equation
  connect(ySet.y,limPID.u_s)
  connect(ySet.y,limPD.u_s)
  connect(yMea.y,limPID.u_m)
  connect(yMea.y,limPD.u_m)
end PIDInitialDerivativeOutput;


Test model for LimPID controller with initial state specified. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PIDInitialState
  "Test model for LimPID controller with initial state specified"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant ySet(
    k=0.75)
    "Set point"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yMea(
    k=0.5)
    "Measured value"
  Buildings.Controls.OBC.CDL.Reals.PID limPID(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=3,
    xi_start=0.25)
    "PID controller"
  Buildings.Controls.OBC.CDL.Reals.PID limPI(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=3,
    xi_start=0.25)
    "PI controller"

equation
  connect(ySet.y,limPID.u_s)
  connect(ySet.y,limPI.u_s)
  connect(yMea.y,limPID.u_m)
  connect(yMea.y,limPI.u_m)
end PIDInitialState;


Test model for PID controller with scaling of the control error. Validation test for the block

Buildings.Controls.OBC.CDL.Reals.PID
with and without setting of the parameter that scales the control error.

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PIDScale
  "Test model for PID controller with scaling of the control error"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pulse(
    amplitude=1000,
    period=50)
    "Setpoint"
  Buildings.Controls.OBC.CDL.Reals.PID pidSca(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=2,
    Ti=1,
    Td=2,
    r=1000,
    yMin=-1)
    "PID controller with scaling of control input"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset pla1(
    k=1000)
    "Plant model"
  Reals.Sources.Constant resVal(
    k=0)
    "Reset value"
  Logical.Sources.Constant resSig(
    k=false)
    "Reset signal"
  Buildings.Controls.OBC.CDL.Reals.PID pidNoSca(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=2,
    Ti=1,
    Td=2,
    yMin=-1)
    "PID controller without scaling of control input"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=1/1000)
    "Gain to scale setpoint"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(k=1/1000)
    "Gain to scale measured value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset pla2(
    k=1000)
    "Plant model"

equation
  connect(pulse.y,pidSca.u_s)
  connect(pla1.u,pidSca.y)
  connect(pla1.y,pidSca.u_m)
  connect(resVal.y,pla1.y_reset_in)
  connect(resSig.y,pla1.trigger)
  connect(gai.y,pidNoSca.u_s)
  connect(gai.u,pulse.y)
  connect(pidNoSca.y,pla2.u)
  connect(pla2.y,gai1.u)
  connect(gai1.y,pidNoSca.u_m)
  connect(pla2.y_reset_in,resVal.y)
  connect(resSig.y,pla2.trigger)
end PIDScale;


Test model for LimPID controller with reset trigger. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PIDWithReset
  "Test model for LimPID controller with reset trigger"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal setPoi
    "Set point"
  Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime modTim
    "Civil time"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greEquThr(
    t=1)
    "Outputs true after t=1"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset limPIDPar(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=1,
    Ti=1,
    Td=1,
    yMin=-1,
    y_reset=0.5)
    "Controller, reset to parameter value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset intWitRes1
    "Integrator whose output should be brought to the set point"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset limPIDInp(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=1,
    Ti=1,
    Td=1,
    yMin=-1,
    y_reset=0.75)
    "Controller, reset to input value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset intWitRes2
    "Integrator whose output should be brought to the set point"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant resVal(
    k=0)
    "Reset value"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset limPIPar(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=1,
    Ti=1,
    Td=1,
    yMin=-1,
    y_reset=0.5)
    "Controller, reset to parameter value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset intWitRes3
    "Integrator whose output should be brought to the set point"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset limPIInp(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=1,
    Ti=1,
    Td=1,
    yMin=-1,
    y_reset=0.75)
    "Controller, reset to input value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset intWitRes4
    "Integrator whose output should be brought to the set point"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Constant false"

equation
  connect(limPIDPar.u_s,setPoi.y)
  connect(intWitRes1.u,limPIDPar.y)
  connect(intWitRes1.y,limPIDPar.u_m)
  connect(modTim.y,greEquThr.u)
  connect(greEquThr.y,setPoi.u)
  connect(greEquThr.y,limPIDPar.trigger)
  connect(intWitRes2.u,limPIDInp.y)
  connect(intWitRes2.y,limPIDInp.u_m)
  connect(limPIDInp.u_s,setPoi.y)
  connect(limPIPar.u_s,setPoi.y)
  connect(intWitRes3.u,limPIPar.y)
  connect(intWitRes3.y,limPIPar.u_m)
  connect(greEquThr.y,limPIPar.trigger)
  connect(intWitRes4.u,limPIInp.y)
  connect(intWitRes4.y,limPIInp.u_m)
  connect(limPIInp.u_s,setPoi.y)
  connect(greEquThr.y,limPIInp.trigger)
  connect(limPIDInp.trigger,greEquThr.y)
  connect(resVal.y,intWitRes1.y_reset_in)
  connect(resVal.y,intWitRes2.y_reset_in)
  connect(resVal.y,intWitRes3.y_reset_in)
  connect(resVal.y,intWitRes4.y_reset_in)
  connect(con.y,intWitRes1.trigger)
  connect(con.y,intWitRes2.trigger)
  connect(con.y,intWitRes3.trigger)
  connect(con.y,intWitRes4.trigger)
end PIDWithReset;


Test model for PID controller with reset and scaling of the control error. Validation test for the block

Buildings.Controls.OBC.CDL.Reals.PIDWithReset
with and without setting of the parameter that scales the control error.

within Buildings.Controls.OBC.CDL.Reals.Validation;
model PIDWithResetScale
  "Test model for PID controller with reset and scaling of the control error"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pulse(
    amplitude=1000,
    period=50)
    "Setpoint"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset pidSca(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=2,
    Ti=1,
    Td=2,
    r=1000,
    yMin=-1,
    y_reset=0)
    "PID controller with scaling of control input"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset pla1(
    k=1000)
    "Plant model"
  Reals.Sources.Constant resVal(
    k=0)
    "Reset value"
  Logical.Sources.Constant resSig(
    k=false)
    "Reset signal"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset pidNoSca(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID,
    k=2,
    Ti=1,
    Td=2,
    yMin=-1,
    y_reset=0)
    "PID controller without scaling of control input"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=1/1000)
    "Gain to scale setpoint"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(k=1/1000)
    "Gain to scale measured value"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset pla2(
    k=1000)
    "Plant model"
  Logical.Sources.Pulse booPul(
    period=30)
    "Pulse for controller reset"

equation
  connect(pulse.y,pidSca.u_s)
  connect(pla1.u,pidSca.y)
  connect(pla1.y,pidSca.u_m)
  connect(resVal.y,pla1.y_reset_in)
  connect(resSig.y,pla1.trigger)
  connect(gai.y,pidNoSca.u_s)
  connect(gai.u,pulse.y)
  connect(pidNoSca.y,pla2.u)
  connect(pla2.y,gai1.u)
  connect(gai1.y,pidNoSca.u_m)
  connect(pla2.y_reset_in,resVal.y)
  connect(resSig.y,pla2.trigger)
  connect(booPul.y,pidSca.trigger)
  connect(booPul.y,pidNoSca.trigger)
end PIDWithResetScale;


Validation model for the Ramp block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Ramp "Validation model for the Ramp block"

  Buildings.Controls.OBC.CDL.Reals.Ramp ramUp(
    final raisingSlewRate=1/20)
    "Ramp the input increasing"
  Buildings.Controls.OBC.CDL.Reals.Ramp ramUp1(
    final raisingSlewRate=1/10)
    "Ramp the input increasing in different speed"
  Buildings.Controls.OBC.CDL.Reals.Ramp ramUpDow(
    final raisingSlewRate=1/5)
    "Limit the increase and decrease of the input if the active is true"
  Buildings.Controls.OBC.CDL.Reals.Ramp ramUpDow1(
    final raisingSlewRate=1/5,
    final fallingSlewRate=-1/2)
    "Different increase and decrease slew rate limits"

  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    final width=0.9,
    final period=12,
    final shift=1)
    "Boolean pulse"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul(
    final width=0.8,
    final period=12.0,
    final shift=2.0)
    "Boolean pulse"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul2(
    final width=0.9,
    final period=12,
    final shift=2)
    "Boolean pulse"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul1(
    final width=0.2,
    final period=12.0,
    final shift=1.5)
    "Boolean pulse"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul2(
    final width=0.3,
    final period=12.0,
    final shift=3.0)
    "Boolean pulse"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul5(
    final width=0.9,
    final period=12,
    final shift=1)
    "Boolean pulse"
equation
  connect(booPul2.y, ramUpDow.active)
  connect(booPul5.y, ramUpDow1.active)
  connect(pul.y, ramUp.u)
  connect(pul.y, ramUp1.u)
  connect(booPul1.y, ramUp.active)
  connect(booPul1.y, ramUp1.active)
  connect(pul1.y, ramUpDow.u)
  connect(pul2.y, ramUpDow1.u)
end Ramp;


Validation model for the Round block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Round
  "Validation model for the Round block"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    n=0)
    "Round real number to given digits"
  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 round2(
    n=1)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Round round3(
    n=-1)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=0.1) "Gain"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(k=10) "Gain"

equation
  connect(ramp1.y,round1.u)
  connect(ramp1.y,gai.u)
  connect(round2.u,gai.y)
  connect(ramp1.y,gai1.u)
  connect(round3.u,gai1.y)
end Round;


Validation model for the Sin block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Sin
  "Validation model for the Sin block"
  Buildings.Controls.OBC.CDL.Reals.Sin sin1
    "Block that outputs the sine of the input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=0,
    height=6.2831852)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,sin1.u)
end Sin;


Validation model for the Sort block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Sort
  "Validation model for the Sort block"
  Buildings.Controls.OBC.CDL.Reals.Sort sorAsc(
    nin=5)
    "Block that sorts signals in ascending order"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=3)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp3(
    duration=1,
    offset=2,
    height=-4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp4(
    duration=1,
    offset=3,
    height=-1)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp5(
    duration=1,
    offset=0,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sort sorDes(
    nin=5,
    ascending=false)
    "Block that sorts signals in ascending order"

equation
  connect(ramp1.y,sorAsc.u[1])
  connect(ramp2.y,sorAsc.u[2])
  connect(ramp3.y,sorAsc.u[3])
  connect(ramp4.y,sorAsc.u[4])
  connect(ramp5.y,sorAsc.u[5])
  connect(ramp1.y,sorDes.u[1])
  connect(ramp2.y,sorDes.u[2])
  connect(ramp3.y,sorDes.u[3])
  connect(ramp4.y,sorDes.u[4])
  connect(ramp5.y,sorDes.u[5])
end Sort;


Validation model for the Sqrt block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Sqrt
  "Validation model for the Sqrt block"
  Buildings.Controls.OBC.CDL.Reals.Sqrt sqrt1
    "Block that outputs the square root of the input (input >= 0 required)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=0,
    height=9)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,sqrt1.u)
end Sqrt;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Subtract "Validation model for the Subtract block"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Block that outputs the difference of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    height=2,
    duration=1,
    offset=-0.5)
    "Block that generates ramp signal"

equation
  connect(ramp1.y, sub.u1)
  connect(ramp2.y, sub.u2)
end Subtract;


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

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Switch "Validation model for the Switch block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=5,
    offset=-1,
    height=6)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=5,
    offset=-1,
    height=2)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    width=0.5,
    period=2)
    "Block that outputs cyclic on and off"
  Buildings.Controls.OBC.CDL.Reals.Switch switch1
    "Switch between two real inputs"

equation
  connect(booPul.y,switch1.u2)
  connect(ramp2.y,switch1.u3)
  connect(ramp1.y,switch1.u1)
end Switch;


Validation model for the Tan block. Validation test for the block

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

within Buildings.Controls.OBC.CDL.Reals.Validation;
model Tan
  "Validation model for the Tan block"
  Buildings.Controls.OBC.CDL.Reals.Tan tan1
    "Block that outputs the sine of the input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-1.5,
    height=3.0)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,tan1.u)
end Tan;


Extract scalar signal out of boolean signal vector dependent on integer input index. Block that returns

within Buildings.Controls.OBC.CDL.Routing;
block BooleanExtractor
  "Extract scalar signal out of boolean signal vector dependent on integer input index"
  parameter Integer nin=1
    "Number of inputs";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput index
    "Index of input vector element to be extracted out"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Boolean input signals"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y
    "Boolean signal extracted from input vector, u[index]"

equation
  assert(
     index > 0 and index <= nin,
     "In " + getInstanceName() + ": The extract index is out of the range.",
     AssertionLevel.warning);
  y = u[min(nin, max(1, index))];
end BooleanExtractor;


Extract signals from a boolean input signal vector. Extract signals from the vector-valued boolean input signal and transfer them
to the vector-valued boolean output signal.

within Buildings.Controls.OBC.CDL.Routing;
block BooleanExtractSignal
  "Extract signals from a boolean input signal vector"
  parameter Integer nin=1
    "Number of inputs";
  parameter Integer nout=1
    "Number of outputs";
  parameter Integer extract[nout]=1:nout
    "Extracting vector";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Boolean input signals"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout]
    "Boolean signals extracted from the input vector with the extraction scheme specified by the integer vector"

initial equation
  assert(
    Modelica.Math.BooleanVectors.andTrue({(extract[i] > 0 and extract[i] <= nin) for i in 1:nout}),
    "In " + getInstanceName() + ": The element of the extracting vector has out of range value.",
    AssertionLevel.error);

equation
  for i in 1:nout loop
    y[i]=u[extract[i]];
  end for;
end BooleanExtractSignal;


Boolean signal replicator. This block replicates the Boolean input signal to an array of nout
identical Boolean output signals.

within Buildings.Controls.OBC.CDL.Routing;
block BooleanScalarReplicator
  "Boolean signal replicator"
  parameter Integer nout=1
    "Number of outputs";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout]
    "Connector of Boolean output signals"

equation
  y=fill(
    u,
    nout);
end BooleanScalarReplicator;


Filter a boolean vector based on a boolean mask. This block filters a Boolean vector of size nin to
a vector of size nout given a Boolean mask
msk.

within Buildings.Controls.OBC.CDL.Routing;
block BooleanVectorFilter
  "Filter a boolean vector based on a boolean mask"
  parameter Integer nin "Size of input vector";
  parameter Integer nout "Size of output vector";
  parameter Boolean msk[nin]=fill(true,nin) "Array mask";

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Connector of Boolean input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout]
    "Connector of Boolean output signals"

protected
  parameter Integer mskId[nout] = Modelica.Math.BooleanVectors.index(msk)
    "Indices of included element in input vector";

initial equation
  assert(nout==sum({if msk[i] then 1 else 0 for i in 1:nin}),
    "In " + getInstanceName() + ": The size of the output vector does not
    match the size of included elements in the mask.");
equation
  y = u[mskId];
end BooleanVectorFilter;


Boolean vector signal replicator. This block replicates a Boolean vector input signal of size nin,
to a matrix with nout rows and nin columns,
where each row is duplicating the input vector.

within Buildings.Controls.OBC.CDL.Routing;
block BooleanVectorReplicator "Boolean vector signal replicator"
  parameter Integer nin=1 "Size of input vector";
  parameter Integer nout=1 "Number of row in output";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin]
    "Connector of Boolean vector input signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y[nout, nin]
    "Connector of Boolean matrix output signals"

equation
  y=fill(u, nout);
end BooleanVectorReplicator;


Extract scalar signal out of integer signal vector dependent on integer input index. Block that returns

within Buildings.Controls.OBC.CDL.Routing;
block IntegerExtractor
  "Extract scalar signal out of integer signal vector dependent on integer input index"
  parameter Integer nin=1
    "Number of inputs";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput index
    "Index of input vector element to be extracted out"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin]
    "Integer input signals"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y
    "Integer signal extracted from input vector, u[index]"

equation
  assert(
     index > 0 and index <= nin,
     "In " + getInstanceName() + ": The extract index is out of the range.",
     AssertionLevel.warning);
  y = u[min(nin, max(1, index))];
end IntegerExtractor;


Extract signals from an integer input signal vector. Extract signals from the vector-valued integer input signal and transfer them
to the vector-valued integer output signal.

within Buildings.Controls.OBC.CDL.Routing;
block IntegerExtractSignal
  "Extract signals from an integer input signal vector"
  parameter Integer nin=1
    "Number of inputs";
  parameter Integer nout=1
    "Number of outputs";
  parameter Integer extract[nout]=1:nout
    "Extracting vector";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin]
    "Integer input signals"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y[nout]
    "Integer signals extracted from the input vector with the extraction scheme specified by the integer vector"

initial equation
  assert(
    Modelica.Math.BooleanVectors.andTrue({(extract[i] > 0 and extract[i] <= nin) for i in 1:nout}),
    "In " + getInstanceName() + ": The element of the extracting vector has out of range value.",
    AssertionLevel.error);

equation
  for i in 1:nout loop
    y[i]=u[extract[i]];
  end for;
end IntegerExtractSignal;


Integer signal replicator. This block replicates the Integer input signal to an array of nout
identical Integer output signals.

within Buildings.Controls.OBC.CDL.Routing;
block IntegerScalarReplicator
  "Integer signal replicator"
  parameter Integer nout=1
    "Number of outputs";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u
    "Connector of Integer input signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y[nout]
    "Connector of Integer output signals"

equation
  y=fill(
    u,
    nout);
end IntegerScalarReplicator;


Filter an integer vector based on a boolean mask. This block filters a Integer vector of size nin to
a vector of size nout given a Boolean mask
msk.

within Buildings.Controls.OBC.CDL.Routing;
block IntegerVectorFilter
  "Filter an integer vector based on a boolean mask"
  parameter Integer nin "Size of input vector";
  parameter Integer nout "Size of output vector";
  parameter Boolean msk[nin]=fill(true,nin) "Array mask";

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin]
    "Connector of Integer input signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y[nout]
    "Connector of Integer output signals"

protected
  parameter Integer mskId[nout] = Modelica.Math.BooleanVectors.index(msk)
    "Indices of included element in input vector";

initial equation
  assert(nout==sum({if msk[i] then 1 else 0 for i in 1:nin}),
    "The size of the output vector does not match the
    size of included elements in the mask.");
equation
  y = u[mskId];
end IntegerVectorFilter;


Integer vector signal replicator. This block replicates an Integer vector input signal of size nin,
to a matrix with nout rows and nin columns,
where each row is duplicating the input vector.

within Buildings.Controls.OBC.CDL.Routing;
block IntegerVectorReplicator "Integer vector signal replicator"
  parameter Integer nin=1 "Size of input vector";
  parameter Integer nout=1 "Number of row in output";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput u[nin]
    "Connector of Integer vector input signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y[nout, nin]
    "Connector of Integer matrix output signals"

equation
  y=fill(u, nout);
end IntegerVectorReplicator;


within Buildings.Controls.OBC.CDL;
package Routing "Package with blocks that combine and extract signals"
end Routing;


Extract scalar signal out of real signal vector dependent on integer input index. Block that returns

within Buildings.Controls.OBC.CDL.Routing;
block RealExtractor
  "Extract scalar signal out of real signal vector dependent on integer input index"
  parameter Integer nin=1
    "Number of inputs";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput index
    "Index of input vector element to be extracted out"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin]
    "Real input signals"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Real signal extracted from input vector, u[index]"

algorithm
  assert(
     index > 0 and index <= nin,
     "In " + getInstanceName() + ": The extract index is out of the range.",
     AssertionLevel.warning);
  y := u[min(nin, max(1, index))];
end RealExtractor;


Extract signals from a real input signal vector. Extract signals from the vector-valued real input signal and transfer them
to the vector-valued real output signal.

within Buildings.Controls.OBC.CDL.Routing;
block RealExtractSignal
  "Extract signals from a real input signal vector"
  parameter Integer nin=1
    "Number of inputs";
  parameter Integer nout=1
    "Number of outputs";
  parameter Integer extract[nout]=1:nout
    "Extracting vector";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin]
    "Real input signals"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nout]
    "Real signals extracted from the input vector with the extraction scheme specified by the integer vector"

initial equation
  assert(
    Modelica.Math.BooleanVectors.andTrue({(extract[i] > 0 and extract[i] <= nin) for i in 1:nout}),
    "In " + getInstanceName() + ": The element of the extracting vector has out of range value.",
    AssertionLevel.error);

equation
  for i in 1:nout loop
    y[i]=u[extract[i]];
  end for;
end RealExtractSignal;


Real signal replicator. This block replicates the Real input signal to an array of nout
identical Real output signals.

within Buildings.Controls.OBC.CDL.Routing;
block RealScalarReplicator
  "Real signal replicator"
  parameter Integer nout=1
    "Number of outputs";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u
    "Connector of Real input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nout]
    "Connector of Real output signal"

equation
  y=fill(
    u,
    nout);
end RealScalarReplicator;


Filter a real vector of based on a boolean mask. This block filters a Real vector of size nin to
a vector of size nout given a boolean mask
msk.

within Buildings.Controls.OBC.CDL.Routing;
block RealVectorFilter
  "Filter a real vector of based on a boolean mask"
  parameter Integer nin "Size of input vector";
  parameter Integer nout "Size of output vector";
  parameter Boolean msk[nin]=fill(true,nin) "Array mask";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin]
    "Connector of Real input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nout]
    "Connector of Real output signals"

protected
  parameter Integer mskId[nout] = Modelica.Math.BooleanVectors.index(msk)
    "Indices of included element in input vector";

initial equation
  assert(nout==sum({if msk[i] then 1 else 0 for i in 1:nin}),
    "The size of the output vector does not match the
    size of included elements in the mask.");
equation
  y = u[mskId];
end RealVectorFilter;


Real vector signal replicator. This block replicates an Real vector input signal of size nin,
to a matrix with nout rows and nin columns,
where each row is duplicating the input vector.

within Buildings.Controls.OBC.CDL.Routing;
block RealVectorReplicator "Real vector signal replicator"
  parameter Integer nin=1 "Size of input vector";
  parameter Integer nout=1 "Number of row in output";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin]
    "Connector of Real vector input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y[nout, nin]
    "Connector of Real matrix output signals"

equation
  y=fill(u, nout);
end RealVectorReplicator;


Validation model for the boolean extractor block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.BooleanExtractor.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model BooleanExtractor
  "Validation model for the boolean extractor block"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractor extIndBoo(
    final nin=4) "Extracts signal from an input signal vector"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractor extIndBoo1(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index is out of the upper range"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractor extIndBoo2(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index is out of the lower range"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractor extIndBoo3(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index changes from within range to out of range"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractor extIndBoo4(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index changes from out of range to within range"

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    final k=true)
    "Block that outputs true signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Block that outputs false signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final period=0.2) "Generate pulse signal of type boolean"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    final period=0.3)
    "Generate pulse signal of type boolean"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=2)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    k=6)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    k=0)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    final amplitude=3,
    final period=1,
    final offset=-1)
    "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul1(
    final amplitude=-3,
    final period=1,
    final offset=3)
    "Generate pulse signal of type Integer"

equation
  connect(conInt.y, extIndBoo.index)
  connect(conInt1.y, extIndBoo1.index)
  connect(con1.y, extIndBoo.u[1])
  connect(booPul.y, extIndBoo.u[2])
  connect(booPul1.y, extIndBoo.u[3])
  connect(con.y, extIndBoo.u[4])
  connect(con1.y, extIndBoo1.u[1])
  connect(booPul.y, extIndBoo1.u[2])
  connect(booPul1.y, extIndBoo1.u[3])
  connect(con.y, extIndBoo1.u[4])
  connect(con1.y, extIndBoo2.u[1])
  connect(booPul.y, extIndBoo2.u[2])
  connect(booPul1.y, extIndBoo2.u[3])
  connect(con.y, extIndBoo2.u[4])
  connect(conInt2.y, extIndBoo2.index)
  connect(con1.y, extIndBoo3.u[1])
  connect(booPul.y, extIndBoo3.u[2])
  connect(booPul1.y, extIndBoo3.u[3])
  connect(con.y, extIndBoo3.u[4])
  connect(intPul.y, extIndBoo3.index)
  connect(intPul1.y, extIndBoo4.index)
  connect(con1.y, extIndBoo4.u[1])
  connect(booPul.y, extIndBoo4.u[2])
  connect(booPul1.y, extIndBoo4.u[3])
  connect(con.y, extIndBoo4.u[4])
end BooleanExtractor;


Validation model for extracting boolean signals. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.BooleanExtractSignal.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model BooleanExtractSignal
  "Validation model for extracting boolean signals"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractSignal extBooSig(
    final nin=4,
    final nout=3,
    final extract={3,2,4})
    "Block that extracts signal from a boolean input signal vector"
  Buildings.Controls.OBC.CDL.Routing.BooleanExtractSignal extBooSig1(
    final nin=4,
    final nout=5,
    final extract={3,2,4,1,1})
    "Block that extracts signal from a boolean input signal vector"

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    final k=true)
    "Block that outputs true signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Block that outputs false signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final period=0.2) "Generate pulse signal of type boolean"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    final period=0.3)
    "Generate pulse signal of type boolean"

equation
  connect(con1.y, extBooSig.u[1])
  connect(booPul.y, extBooSig.u[2])
  connect(booPul1.y, extBooSig.u[3])
  connect(con.y, extBooSig.u[4])
  connect(con1.y, extBooSig1.u[1])
  connect(booPul.y, extBooSig1.u[2])
  connect(booPul1.y, extBooSig1.u[3])
  connect(con.y, extBooSig1.u[4])
end BooleanExtractSignal;


Validation model for the BooleanScalarReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model BooleanScalarReplicator
  "Validation model for the BooleanScalarReplicator block"
  Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator booRep(
    nout=3)
    "Block that outputs the array replicating input value"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    period=0.2)
    "Block that outputs boolean pulse"

equation
  connect(booPul.y,booRep.u)
end BooleanScalarReplicator;


Validation model for the BooleanVectorFilter block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.BooleanVectorFilter.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model BooleanVectorFilter
  "Validation model for the BooleanVectorFilter block"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorFilter
    booFil(nin=3, nout=2, msk={true,false,true})
    "Block that filter the input vector"

  Logical.Sources.Constant booInp[3](k={true,true,false}) "Boolean inputs"
equation
  connect(booInp.y, booFil.u)
end BooleanVectorFilter;


Validation model for the BooleanVectorReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model BooleanVectorReplicator
  "Validation model for the BooleanVectorReplicator block"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator booRep(nin=2, nout=3)
    "Block that outputs the vector replicating input value"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul[2](period=fill(0.2,2))
    "Block that outputs boolean pulse"

equation
  connect(booPul.y, booRep.u)
end BooleanVectorReplicator;


Validation model for the integer extractor block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.IntegerExtractor.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model IntegerExtractor
  "Validation model for the integer extractor block"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractor extIndInt(
    final nin=4) "Extracts signal from an input signal vector"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractor extIndInt1(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index is out of the upper range"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractor extIndInt2(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index is out of the lower range"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractor extIndInt3(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index changes from within range to out of range"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractor extIndInt4(
    final nin=4)
    "Extracts signal from an input signal vector when the extract index changes from out of range to within range"

  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=0)
    "Block that outputs integer constant"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    final k=4)
    "Block that outputs integer constant"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    final amplitude=1,
    final period=0.2) "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul1(
    final period=0.3,
    final amplitude=2,
    final offset=-1)   "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=2)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(k=6)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(k=0)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul2(
    final period=1,
    final amplitude=3,
    final offset=-1)
    "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul3(
    final period=1,
    final amplitude=-3,
    final offset=3)
    "Generate pulse signal of type Integer"

equation
  connect(conInt1.y, extIndInt1.index)
  connect(conInt2.y, extIndInt.u[1])
  connect(intPul.y, extIndInt.u[2])
  connect(intPul1.y, extIndInt.u[3])
  connect(conInt3.y, extIndInt.u[4])
  connect(conInt2.y, extIndInt1.u[1])
  connect(intPul.y, extIndInt1.u[2])
  connect(intPul1.y, extIndInt1.u[3])
  connect(conInt3.y, extIndInt1.u[4])
  connect(conInt.y, extIndInt.index)
  connect(conInt4.y, extIndInt2.index)
  connect(conInt2.y, extIndInt2.u[1])
  connect(intPul.y, extIndInt2.u[2])
  connect(intPul1.y, extIndInt2.u[3])
  connect(conInt3.y, extIndInt2.u[4])
  connect(conInt2.y, extIndInt3.u[1])
  connect(intPul.y, extIndInt3.u[2])
  connect(intPul1.y, extIndInt3.u[3])
  connect(conInt3.y, extIndInt3.u[4])
  connect(intPul2.y, extIndInt3.index)
  connect(intPul3.y, extIndInt4.index)
  connect(conInt2.y, extIndInt4.u[1])
  connect(intPul.y, extIndInt4.u[2])
  connect(intPul1.y, extIndInt4.u[3])
  connect(conInt3.y, extIndInt4.u[4])
end IntegerExtractor;


Validation model for extracting integer signals. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.IntegerExtractSignal.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model IntegerExtractSignal
  "Validation model for extracting integer signals"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractSignal extIntSig(
    final nin=4,
    final nout=3,
    final extract={3,2,4})
    "Block that extracts signal from an integer input signal vector"
  Buildings.Controls.OBC.CDL.Routing.IntegerExtractSignal extIntSig1(
    final nin=4,
    final nout=5,
    final extract={3,2,4,2,3})
    "Block that extracts signal from an integer input signal vector"

  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=1)
    "Block that outputs integer constant"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    final amplitude=1,
    final period=0.2)
    "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul1(
    final period=0.3,
    final amplitude=2,
    final offset=-1)
    "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    final k=4)
    "Block that outputs integer constant"

equation
  connect(conInt2.y,extIntSig. u[1])
  connect(intPul.y,extIntSig. u[2])
  connect(intPul1.y,extIntSig. u[3])
  connect(conInt3.y,extIntSig. u[4])
  connect(conInt2.y, extIntSig1.u[1])
  connect(intPul.y, extIntSig1.u[2])
  connect(intPul1.y, extIntSig1.u[3])
  connect(conInt3.y, extIntSig1.u[4])
end IntegerExtractSignal;


Validation model for the IntegerScalarReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.IntegerScalarReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model IntegerScalarReplicator
  "Validation model for the IntegerScalarReplicator block"
  Buildings.Controls.OBC.CDL.Routing.IntegerScalarReplicator intRep(
    nout=3)
    "Block that outputs the array replicating input value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    height=5,
    duration=1,
    offset=-2)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert Real input to Integer output"

equation
  connect(ram.y,reaToInt.u)
  connect(reaToInt.y,intRep.u)
end IntegerScalarReplicator;


Validation model for the IntegerVectorFilter block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.IntegerVectorFilter.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model IntegerVectorFilter
  "Validation model for the IntegerVectorFilter block"
  Buildings.Controls.OBC.CDL.Routing.IntegerVectorFilter
    intFil(nin=3, nout=2, msk={true,false,true})
    "Block that filter the input vector"

  Integers.Sources.Constant IntInp[3](k={1,2,3}) "Integer inputs"
equation
  connect(IntInp.y, intFil.u)
end IntegerVectorFilter;


Validation model for the IntegerVectorReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.IntegerVectorReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model IntegerVectorReplicator
  "Validation model for the IntegerVectorReplicator block"
  Buildings.Controls.OBC.CDL.Routing.IntegerVectorReplicator
    intRep(nin=2, nout=3)
    "Block that outputs the vector replicating input value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram[2](
    height=fill(5,2),
    duration=fill(1,2),
    offset=fill(-2,2)) "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt[2]
    "Convert Real input to Integer output"

equation
  connect(ram.y,reaToInt.u)
  connect(reaToInt.y,intRep.u)
end IntegerVectorReplicator;


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


Validation model for the extractor block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.RealExtractor.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model RealExtractor
  "Validation model for the extractor block"
  Buildings.Controls.OBC.CDL.Routing.RealExtractor extIndSig(
    final nin=5) "Extracts signal from an input signal vector"
  Buildings.Controls.OBC.CDL.Routing.RealExtractor extIndSig1(
    final nin=5)
    "Extracts signal from an input signal vector when the extract index is out of the upper range"
  Buildings.Controls.OBC.CDL.Routing.RealExtractor extIndSig2(
    final nin=5)
    "Extracts signal from an input signal vector when the extract index is out of the lower range"
  Buildings.Controls.OBC.CDL.Routing.RealExtractor extIndSig3(
    final nin=5)
    "Extracts signal from an input signal vector when the extract index changes from within range to out of range"
  Buildings.Controls.OBC.CDL.Routing.RealExtractor extIndSig4(
    final nin=5)
    "Extracts signal from an input signal vector when the extract index changes from out of range to within range"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    final height=5,
    final duration=1,
    final offset=-2)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram1(
    final duration=1,
    final height=4,
    final offset=-1)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram2(
    final duration=1,
    final height=3,
    final offset=-2)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul(
    final amplitude=0.5,
    final period=0.2)
    "Generate pulse signal of type Real"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul1(
    final period=0.2,
    final amplitude=1.5,
    final offset=-0.2)
    "Generate pulse signal of type Real"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=2)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(k=6)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(k=0)
    "Index to extract input signal"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    final amplitude=3,
    final period=1,
    final offset=-1)
    "Generate pulse signal of type Integer"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul1(
    final amplitude=-3,
    final period=1,
    final offset=3)
    "Generate pulse signal of type Integer"
equation
  connect(ram.y,extIndSig.u[1])
  connect(pul.y,extIndSig.u[2])
  connect(pul1.y,extIndSig.u[3])
  connect(ram1.y,extIndSig.u[4])
  connect(ram2.y,extIndSig.u[5])
  connect(conInt.y,extIndSig.index)
  connect(conInt1.y,extIndSig1.index)
  connect(ram.y,extIndSig1.u[1])
  connect(pul.y,extIndSig1.u[2])
  connect(pul1.y,extIndSig1.u[3])
  connect(ram1.y,extIndSig1.u[4])
  connect(ram2.y,extIndSig1.u[5])
  connect(conInt2.y, extIndSig2.index)
  connect(ram.y, extIndSig2.u[1])
  connect(pul.y, extIndSig2.u[2])
  connect(pul1.y, extIndSig2.u[3])
  connect(ram1.y, extIndSig2.u[4])
  connect(ram2.y, extIndSig2.u[5])
  connect(ram.y, extIndSig3.u[1])
  connect(pul.y, extIndSig3.u[2])
  connect(pul1.y, extIndSig3.u[3])
  connect(ram1.y, extIndSig3.u[4])
  connect(ram2.y, extIndSig3.u[5])
  connect(ram.y, extIndSig4.u[1])
  connect(pul.y, extIndSig4.u[2])
  connect(pul1.y, extIndSig4.u[3])
  connect(ram1.y, extIndSig4.u[4])
  connect(ram2.y, extIndSig4.u[5])
  connect(intPul.y, extIndSig3.index)
  connect(intPul1.y, extIndSig4.index)
end RealExtractor;


Validation model for the extract signal block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.RealExtractSignal.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model RealExtractSignal
  "Validation model for the extract signal block"
  Buildings.Controls.OBC.CDL.Routing.RealExtractSignal extSig(
    final nin=5,
    final nout=3,
    final extract={1,2,5})
    "Block that extracts signals from an input signal vector"
  Buildings.Controls.OBC.CDL.Routing.RealExtractSignal extSig1(
    final nin=5,
    final nout=6,
    final extract={1,2,5,3,4,2})
    "Block that extracts signals from an input signal vector"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    final height=5,
    final duration=1,
    final offset=-2)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram1(
    final duration=1,
    final height=4,
    final offset=-1)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram2(
    final duration=1,
    final height=3,
    final offset=-2)
    "Block that outputs ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul(
    final amplitude=0.5,
    final period=0.2)
    "Generate pulse signal of type Real"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse pul1(
    final period=0.2,
    final amplitude=1.5,
    final offset=-0.2)
    "Generate pulse signal of type Real"

equation
  connect(ram.y,extSig.u[1])
  connect(pul.y,extSig.u[2])
  connect(pul1.y,extSig.u[3])
  connect(ram1.y,extSig.u[4])
  connect(ram2.y,extSig.u[5])
  connect(ram.y, extSig1.u[1])
  connect(pul.y, extSig1.u[2])
  connect(pul1.y, extSig1.u[3])
  connect(ram1.y, extSig1.u[4])
  connect(ram2.y, extSig1.u[5])
end RealExtractSignal;


Validation model for the RealScalarReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model RealScalarReplicator
  "Validation model for the RealScalarReplicator block"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(
    nout=3)
    "Block that outputs the array replicating input value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    height=5,
    duration=1,
    offset=-2)
    "Block that outputs ramp signal"

equation
  connect(ram.y,reaRep.u)
end RealScalarReplicator;


Validation model for the RealVectorFilter block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.RealVectorFilter.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model RealVectorFilter
  "Validation model for the RealVectorFilter block"
  Buildings.Controls.OBC.CDL.Routing.RealVectorFilter
    reaFil(nin=3, nout=2, msk={true,false,true})
    "Block that filter the input vector"

  Reals.Sources.Constant ReaInp[3](k={1,2,3}) "Real inputs"
equation
  connect(ReaInp.y, reaFil.u)
end RealVectorFilter;


Validation model for the RealVectorReplicator block. Validation test for the block

Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator.

within Buildings.Controls.OBC.CDL.Routing.Validation;
model RealVectorReplicator
  "Validation model for the RealVectorReplicator block"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator
    reaRep(nin=2, nout=3)
    "Block that outputs the vector replicating input value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram[2](
    height=fill(5,2),
    duration=fill(1,2),
    offset=fill(-2,2)) "Block that outputs ramp signal"

equation
  connect(ram.y,reaRep.u)
end RealVectorReplicator;


Package with type definitions

within Buildings.Controls.OBC.CDL;
package Types "Package with type definitions"
end Types;


Thu, 01 Jan 1970 00:00:00 local time. Type for choosing how to set the reference time in

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

within Buildings.Controls.OBC.CDL.Types;
type ZeroTime = enumeration(
    UnixTimeStamp "Thu, 01 Jan 1970 00:00:00 local time",
    UnixTimeStampGMT "Thu, 01 Jan 1970 00:00:00 GMT",
    Custom "User specified local time",
    NY2010 "New year 2010, 00:00:00 local time",
    NY2011 "New year 2011, 00:00:00 local time",
    NY2012 "New year 2012, 00:00:00 local time",
    NY2013 "New year 2013, 00:00:00 local time",
    NY2014 "New year 2014, 00:00:00 local time",
    NY2015 "New year 2015, 00:00:00 local time",
    NY2016 "New year 2016, 00:00:00 local time",
    NY2017 "New year 2017, 00:00:00 local time",
    NY2018 "New year 2018, 00:00:00 local time",
    NY2019 "New year 2019, 00:00:00 local time",
    NY2020 "New year 2020, 00:00:00 local time",
    NY2021 "New year 2021, 00:00:00 local time",
    NY2022 "New year 2022, 00:00:00 local time",
    NY2023 "New year 2023, 00:00:00 local time",
    NY2024 "New year 2024, 00:00:00 local time",
    NY2025 "New year 2025, 00:00:00 local time",
    NY2026 "New year 2026, 00:00:00 local time",
    NY2027 "New year 2027, 00:00:00 local time",
    NY2028 "New year 2028, 00:00:00 local time",
    NY2029 "New year 2029, 00:00:00 local time",
    NY2030 "New year 2030, 00:00:00 local time",
    NY2031 "New year 2031, 00:00:00 local time",
    NY2032 "New year 2032, 00:00:00 local time",
    NY2033 "New year 2033, 00:00:00 local time",
    NY2034 "New year 2034, 00:00:00 local time",
    NY2035 "New year 2035, 00:00:00 local time",
    NY2036 "New year 2036, 00:00:00 local time",
    NY2037 "New year 2037, 00:00:00 local time",
    NY2038 "New year 2038, 00:00:00 local time",
    NY2039 "New year 2039, 00:00:00 local time",
    NY2040 "New year 2040, 00:00:00 local time",
    NY2041 "New year 2041, 00:00:00 local time",
    NY2042 "New year 2042, 00:00:00 local time",
    NY2043 "New year 2043, 00:00:00 local time",
    NY2044 "New year 2044, 00:00:00 local time",
    NY2045 "New year 2045, 00:00:00 local time",
    NY2046 "New year 2046, 00:00:00 local time",
    NY2047 "New year 2047, 00:00:00 local time",
    NY2048 "New year 2048, 00:00:00 local time",
    NY2049 "New year 2049, 00:00:00 local time",
    NY2050 "New year 2050, 00:00:00 local time")
  "Use this to set the date corresponding to time = 0"


Print a warning message when input becomes false. Block that writes a warning if the input becomes false.

within Buildings.Controls.OBC.CDL.Utilities;
block Assert
  "Print a warning message when input becomes false"
  parameter String message
    "Message written when u becomes false";
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u
    "Boolean input that triggers assert when it becomes false"

equation
  assert(
    u,
    message,
    AssertionLevel.warning);
end Assert;


Package with utility functions

within Buildings.Controls.OBC.CDL;
package Utilities "Package with utility functions"
end Utilities;


Next sunrise and sunset time. This block outputs the next sunrise and sunset time.
The sunrise time keeps constant until the model time reaches the next sunrise,
at which time the output gets updated.
Similarly, the output for the next sunset is updated at each sunset.

within Buildings.Controls.OBC.CDL.Utilities;
block SunRiseSet
  "Next sunrise and sunset time"
  parameter Real lat(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Latitude";
  parameter Real lon(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Longitude";
  parameter Real timZon(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time zone";
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunRise(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time of next sunrise"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput nextSunSet(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time of next sunset"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput sunUp
    "Output true if the sun is up"

protected
  constant Real k1=sin(
    23.45*2*Modelica.Constants.pi/360)
    "Intermediate constant";
  constant Real k2=2*Modelica.Constants.pi/365.25
    "Intermediate constant";
  parameter Real staTim(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "Simulation start time";
  parameter Real timDifLocCiv(
    final quantity="Time",
    final unit="s",
    fixed=false)
    "Time difference between local and civil time";

  Real eqnTim(
    final quantity="Time",
    final unit="s")
    "Equation of time";
  Real timCor(
    final quantity="Time",
    final unit="s")
    "Time correction";
  Real decAng(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Declination angle";
  Real Bt
    "Intermediate variable to calculate equation of time";
  Real cosHou
    "Cosine of hour angle";

  function nextHourAngle
    "Calculate the hour angle when the sun rises or sets next time"
    input Real t(
      final quantity="Time",
      final unit="s")
      "Current simulation time";
    input Real timDifLocCiv(
    final quantity="Time",
    final unit="s")
    "Time difference between local and civil time";
    input Real lat(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Latitude";
    output Real houAng(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Solar hour angle";
    output Real tNext(
      final quantity="Time",
      final unit="s")
      "Timesnap when sun rises or sets next time";
    output Real timCor(
      final quantity="Time",
      final unit="s")
      "Time correction";

  protected
    Integer iDay;
    Boolean compute
      "Flag, set to false when the sun rise or sets ";
    Real Bt
      "Intermediate variable to calculate equation of time";
    Real eqnTim(
      final quantity="Time",
      final unit="s")
      "Equation of time";
    Real decAng(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Declination angle";
    Real cosHou
      "Cosine of hour angle";

  algorithm
    iDay := 1;
    compute := true;
    while compute loop
      tNext := t+iDay*86400;
      Bt := Modelica.Constants.pi*((tNext+86400)/86400-81)/182;
      eqnTim := 60*(9.87*Modelica.Math.sin(
        2*Bt)-7.53*Modelica.Math.cos(Bt)-1.5*Modelica.Math.sin(Bt));
      timCor := eqnTim+timDifLocCiv;
      decAng := Modelica.Math.asin(
        -k1*Modelica.Math.cos(
          (tNext/86400+10)*k2));
      cosHou :=-Modelica.Math.tan(lat)*Modelica.Math.tan(decAng);
      compute := abs(cosHou) > 1;
      iDay := iDay+1;
    end while;
    houAng := Modelica.Math.acos(cosHou);
  end nextHourAngle;

  function computeSunRise
    "Output the next sunrise time"
    input Real t(
      final quantity="Time",
      final unit="s")
      "Current simulation time";
    input Real staTim(
      final quantity="Time",
      final unit="s")
      "Simulation start time";
    input Real timDifLocCiv(
      final quantity="Time",
      final unit="s")
      "Time difference between local and civil time";
    input Real lat(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Latitude";
    output Real nextSunRise(
      final quantity="Time",
      final unit="s");

  protected
    Real houAng(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Solar hour angle";
    Real tNext(
      final quantity="Time",
      final unit="s")
      "Timesnap when sun rises next time";
    Real timCor(
      final quantity="Time",
      final unit="s")
      "Time correction";
    Real sunRis(
      final quantity="Time",
      final unit="s")
      "Sunrise of the same day as input time";
    Real cosHou(
      final quantity="Time",
      final unit="s")
      "Cosine of hour angle";

  algorithm
    (houAng,tNext,timCor) := nextHourAngle(
      t=t,
      timDifLocCiv=timDifLocCiv,
      lat=lat);
    sunRis :=(12-houAng*24/(2*Modelica.Constants.pi)-timCor/3600)*3600+floor(
      tNext/86400)*86400;
    //If simulation start time has passed the sunrise of the initial day, output
    //the sunrise of the next day.
    if staTim > sunRis then
      nextSunRise := sunRis+86400;
    else
      nextSunRise := sunRis;
    end if;
  end computeSunRise;

  function computeSunSet
    "Output the next sunset time"
    input Real t(
      final quantity="Time",
      final unit="s")
      "Current simulation time";
    input Real staTim(
      final quantity="Time",
      final unit="s")
      "Simulation start time";
    input Real timDifLocCiv(
      final quantity="Time",
      final unit="s")
      "Time difference between local and civil time";
    input Real lat(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Latitude";
    output Real nextSunSet(
      final quantity="Time",
      final unit="s");

  protected
    Real houAng(
      final quantity="Angle",
      final unit="rad",
      displayUnit="deg")
      "Solar hour angle";
    Real tNext(
      final quantity="Time",
      final unit="s")
      "Timesnap when sun sets next time";
    Real timCor(
      final quantity="Time",
      final unit="s")
      "Time correction";
    Real sunSet(
      final quantity="Time",
      final unit="s")
      "Sunset of the same day as input time";
    Real cosHou(
      final quantity="Time",
      final unit="s")
      "Cosine of hour angle";

  algorithm
    (houAng,tNext,timCor) := nextHourAngle(
      t=t,
      timDifLocCiv=timDifLocCiv,
      lat=lat);
    sunSet :=(12+houAng*24/(2*Modelica.Constants.pi)-timCor/3600)*3600+floor(
      tNext/86400)*86400;
    //If simulation start time has passed the sunset of the initial day, output
    //the sunset of the next day.
    if staTim > sunSet then
      nextSunSet := sunSet+86400;
    else
      nextSunSet := sunSet;
    end if;
  end computeSunSet;

initial equation
  staTim=time;
  timDifLocCiv=lon*43200/Modelica.Constants.pi-timZon;
  nextSunRise=computeSunRise(
    t=time-86400,
    staTim=staTim,
    timDifLocCiv=timDifLocCiv,
    lat=lat);

  //In the polar cases where the sun is up during initialization, the next sunset
  //actually occurs before the next sunrise
  if cosHou <-1 then
    nextSunSet=computeSunSet(
      t=time-86400,
      staTim=staTim,
      timDifLocCiv=timDifLocCiv,
      lat=lat)-86400;
  else
    nextSunSet=computeSunSet(
      t=time-86400,
      staTim=staTim,
      timDifLocCiv=timDifLocCiv,
      lat=lat);
  end if;

equation
  Bt=Modelica.Constants.pi*((time+86400)/86400-81)/182;
  eqnTim=60*(9.87*Modelica.Math.sin(
    2*Bt)-7.53*Modelica.Math.cos(Bt)-1.5*Modelica.Math.sin(Bt));
  timCor=eqnTim+timDifLocCiv;
  decAng=Modelica.Math.asin(
    -k1*Modelica.Math.cos(
      (time/86400+10)*k2));
  cosHou=-Modelica.Math.tan(lat)*Modelica.Math.tan(decAng);
  //When time passes the current sunrise/sunset, output the next sunrise/sunset
  when time >= pre(nextSunRise) then
    nextSunRise=computeSunRise(
      t=time,
      staTim=staTim,
      timDifLocCiv=timDifLocCiv,
      lat=lat);
  end when;
  when time >= pre(nextSunSet) then
    nextSunSet=computeSunSet(
      t=time,
      staTim=staTim,
      timDifLocCiv=timDifLocCiv,
      lat=lat);
  end when;
  sunUp=nextSunSet < nextSunRise;
end SunRiseSet;


Validate the Assert block. Validation test for the block

Buildings.Controls.OBC.CDL.Utilities.Assert.

within Buildings.Controls.OBC.CDL.Utilities.Validation;
model Assert
  "Validate the Assert block"
  Buildings.Controls.OBC.CDL.Utilities.Assert assert(
    message="input became false")
    "Trigger warning and print warning message"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    period=0.5)
    "Output boolean pulse"

equation
  connect(booPul.y,assert.u)
end Assert;


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


Test model for the block SunRiseSet. This example includes four instances of the

Buildings.Controls.OBC.CDL.Utilities.SunRiseSet block:
Two normal cases, an arctic and antarctic case.
The normal cases are represented by San Francisco and Sydney,
where there is a sunrise and sunset every day.

within Buildings.Controls.OBC.CDL.Utilities.Validation;
model SunRiseSet
  "Test model for the block SunRiseSet"

  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetArctic(
    lat=1.2566370614359,
    lon=-1.2566370614359,
    timZon=-18000)
    "Arctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSf(
    lat=0.6457718232379,
    lon=-2.1293016874331,
    timZon=-28800)
    "San Francisco as an example in the northen hemisphere"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetAntarctic(
    lat=-1.3089969389957,
    lon=0.99483767363677,
    timZon=14400)
    "Antarctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSyd(
    lat=-0.59341194567807,
    lon=2.6354471705114,
    timZon=36000)
    "Sydney as an example in the southern hemisphere"
end SunRiseSet;


Test model for the block SunRiseSet with negative start time. This example includes 4 tests for the
Buildings.Controls.OBC.CDL.Utilities.SunRiseSet block: 2 normal cases, an arctic and antarctic case.
The normal cases are represented by San Francisco and Sydney, where there is a sunrise and sunset every day.

within Buildings.Controls.OBC.CDL.Utilities.Validation;
model SunRiseSetNegativeStartTime
  "Test model for the block SunRiseSet with negative start time"

  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetArctic(
    lat=1.2566370614359,
    lon=-1.2566370614359,
    timZon=-18000)
    "Arctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSf(
    lat=0.6457718232379,
    lon=-2.1293016874331,
    timZon=-28800)
    "San Francisco as a test example in the northen hemisphere"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetAntarctic(
    lat=-1.3089969389957,
    lon=0.99483767363677,
    timZon=14400)
    "Antarctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSyd(
    lat=-0.59341194567807,
    lon=2.6354471705114,
    timZon=36000)
    "Sydney as a test example in the southern hemisphere"
end SunRiseSetNegativeStartTime;


Test model for the block SunRiseSet with positive start time. This example includes 4 tests for the
Buildings.Controls.OBC.CDL.Utilities.SunRiseSet block: 2 normal cases, an arctic and antarctic case.
The normal cases are represented by San Francisco and Sydney, where there is a sunrise and sunset every day.

within Buildings.Controls.OBC.CDL.Utilities.Validation;
model SunRiseSetPositiveStartTime
  "Test model for the block SunRiseSet with positive start time"

  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetArctic(
    lat=1.2566370614359,
    lon=-1.2566370614359,
    timZon=-18000)
    "Arctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSf(
    lat=0.6457718232379,
    lon=-2.1293016874331,
    timZon=-28800)
    "San Francisco as a test example in the northen hemisphere"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetAntarctic(
    lat=-1.3089969389957,
    lon=0.99483767363677,
    timZon=14400)
    "Antarctic circle case"
  Buildings.Controls.OBC.CDL.Utilities.SunRiseSet sunRiseSetSyd(
    lat=-0.59341194567807,
    lon=2.6354471705114,
    timZon=36000)
    "Sydney as a test example in the southern hemisphere"
end SunRiseSetPositiveStartTime;


Controlling the outdoor lighting based on whether the sun is up. This block outputs on/off control signals for outdoor lighting devices based on
daylight time.
The outdoor lights will be automatically turned off during daylight hours,
and turned on when there is no daylight.

within Buildings.Controls.OBC.OutdoorLights;
block DaylightControlled
  "Controlling the outdoor lighting based on whether the sun is up"
  parameter Real lat(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Latitude";
  parameter Real lon(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Longitude";
  parameter Real timZon(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time zone of location";
  CDL.Interfaces.RealOutput y(
    final min=0,
    final max=1,
    unit="1")
    "Output true if lights should be on"

protected
  CDL.Utilities.SunRiseSet sunRiseSet(
    final lat=lat,
    final lon=lon,
    final timZon=timZon)
    "Output next sunrise and sunset time, and whether the sun is up"
  CDL.Logical.Not not1
    "Logical not"
  CDL.Conversions.BooleanToReal booToRea
    "Boolean to real converter"

equation
  connect(sunRiseSet.sunUp,not1.u)
  connect(not1.y,booToRea.u)
  connect(booToRea.y,y)
end DaylightControlled;


within Buildings.Controls.OBC;
package OutdoorLights "Package with controllers for outdoor lights"
  extends Modelica.Icons.Package;
end OutdoorLights;


Validation model for the outdoor lighting control based on daylight. This example validates the block

Buildings.Controls.OBC.OutdoorLights.DaylightControlled.
The parameters are selected for the location of San Francisco.

within Buildings.Controls.OBC.OutdoorLights.Validation;
model DaylightControlled
  "Validation model for the outdoor lighting control based on daylight"
  extends Modelica.Icons.Example;
  Buildings.Controls.OBC.OutdoorLights.DaylightControlled dayCon(
    lat=0.6457718232379,
    lon=-2.1293016874331,
    timZon=-28800)
    "Controlling the outdoor lighting based on daylight time"
end DaylightControlled;


within Buildings.Controls.OBC.OutdoorLights;
package Validation "Collection of models that validate the outdoor lighting controllers"
end Validation;


within Buildings.Controls.OBC;
package RadiantSystems "Package with controllers for radiant heating and cooling systems"
  extends Modelica.Icons.Package;
end RadiantSystems;


Controller for radiant cooling that controls the room temperature using constant mass flow and variable supply temperature. Controller for a radiant cooling system.

within Buildings.Controls.OBC.RadiantSystems.Cooling;
block HighMassSupplyTemperature_TRoomRelHum
  "Controller for radiant cooling that controls the room temperature using constant mass flow and variable supply temperature"

  parameter Real TSupSet_max(
    final unit="K",
    displayUnit="degC") = 297.15 "Maximum cooling supply water temperature";

  parameter Real TSupSet_min(
    final unit="K",
    displayUnit="degC") "Minimum cooling supply water temperature";

  parameter Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P
    "Type of controller"

  parameter Real k(
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=2
    "Gain of controller"

  parameter Real Ti(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=3600
    "Time constant of integrator block"

  parameter Real Td(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.1
    "Time constant of derivative block"

  Controls.OBC.CDL.Interfaces.RealInput TRooSet(
    final unit="K",
    displayUnit="degC")
    "Set point for room air temperature"

  Controls.OBC.CDL.Interfaces.RealInput TRoo(
    final unit="K",
    displayUnit="degC") "Measured room air temperature"

  Controls.OBC.CDL.Interfaces.RealInput phiRoo(
    final unit="1") "Measured room air relative humidity"

  Controls.OBC.CDL.Interfaces.RealOutput TSupSet(
    final unit="K",
    displayUnit="degC") "Set point for cooling supply water temperature"

  Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit="1",
    final min=0,
    final max=1)
    "Control signal for heating system from P controller"

  Controls.OBC.CDL.Interfaces.BooleanOutput on
    "Outputs true if the system is demanded on"

  Controls.OBC.CDL.Interfaces.RealOutput yPum(
    final unit="1",
    final min=0,
    final max=1)
    "Pump speed control signal"

  CDL.Psychrometrics.DewPoint_TDryBulPhi dewPoi
    "Dew point temperature, used to avoid condensation"
  CDL.Reals.Hysteresis hysCoo(
    uLow=0.1,
    uHigh=0.2)
    "Hysteresis to switch system on and off"
  CDL.Reals.PID conCoo(
    final controllerType=controllerType,
    final k=k,
    final Ti = Ti,
    final Td = Td,
    final yMax=1,
    final yMin=0,
    reverseActing=false)
    "Controller for cooling"

protected
  CDL.Reals.Sources.Constant TSupMin(
    final k(
      final unit="K",
      displayUnit="degC") = TSupSet_min,
      y(final unit="K", displayUnit="degC"))
    "Minimum cooling supply water temperature"
  CDL.Reals.Sources.Constant TSupMax(
    final k(
      final unit="K",
      displayUnit="degC") = TSupSet_max,
    y(final unit="K", displayUnit="degC"))
    "Maximum cooling supply water temperature"

  CDL.Reals.Sources.Constant one(final k=1) "Outputs one"
  CDL.Reals.Sources.Constant zero(final k=0) "Outputs zero"

  CDL.Reals.Line TSupNoDewPoi(
    limitBelow=false,
    limitAbove=false,
    y(final unit="K", displayUnit="degC"))
    "Set point for supply water temperature without consideration of dew point"
  CDL.Reals.Max TSupCoo
    "Cooling water supply temperature"
  CDL.Conversions.BooleanToReal booToRea(
    final realFalse=0,
    final realTrue=1)
    "Pump control signal as a Real number (either 0 or 1)"

equation
  connect(hysCoo.y,booToRea.u)
  connect(conCoo.y,hysCoo.u)
  connect(TSupCoo.u2,dewPoi.TDewPoi)
  connect(TSupCoo.y, TSupSet)
  connect(conCoo.y, y)
  connect(conCoo.u_s, TRooSet)
  connect(dewPoi.phi, phiRoo)
  connect(booToRea.y, yPum)
  connect(hysCoo.y, on)
  connect(TSupNoDewPoi.x1, zero.y)
  connect(TSupNoDewPoi.f1, TSupMax.y)
  connect(TSupNoDewPoi.x2, one.y)
  connect(TSupNoDewPoi.f2, TSupMin.y)
  connect(conCoo.y, TSupNoDewPoi.u)
  connect(TSupNoDewPoi.y, TSupCoo.u1)
  connect(TRoo, conCoo.u_m)
  connect(TRoo, dewPoi.TDryBul)
end HighMassSupplyTemperature_TRoomRelHum;


Controller for radiant cooling that controls the surface temperature using constant mass flow and variable supply temperature. Controller for a radiant cooling system.

within Buildings.Controls.OBC.RadiantSystems.Cooling;
block HighMassSupplyTemperature_TSurRelHum
  "Controller for radiant cooling that controls the surface temperature using constant mass flow and variable supply temperature"

  parameter Real TSupSet_max(
    final unit="K",
    displayUnit="degC") = 297.15 "Maximum cooling supply water temperature";

  parameter Real TSupSet_min(
    final unit="K",
    displayUnit="degC") "Minimum cooling supply water temperature";

  parameter Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P
    "Type of controller"

  parameter Real k(
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=2
    "Gain of controller"

  parameter Real Ti(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=3600
    "Time constant of integrator block"

  parameter Real Td(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.1
    "Time constant of derivative block"

  Controls.OBC.CDL.Interfaces.RealInput TSurSet(
    final unit="K",
    displayUnit="degC")
    "Set point for room air temperature"

  Controls.OBC.CDL.Interfaces.RealInput TRoo(
    final unit="K",
    displayUnit="degC") "Measured room air temperature"

  Controls.OBC.CDL.Interfaces.RealInput phiRoo(
    final unit="1") "Measured room air relative humidity"

  Controls.OBC.CDL.Interfaces.RealInput TSur(
    final unit="K",
    displayUnit="degC") "Measured room air temperature"

  Controls.OBC.CDL.Interfaces.RealOutput TSupSet(
    final unit="K",
    displayUnit="degC") "Set point for cooling supply water temperature"

  Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit="1",
    final min=0,
    final max=1)
    "Control signal for heating system from P controller"

  Controls.OBC.CDL.Interfaces.BooleanOutput on
    "Outputs true if the system is demanded on"

  Controls.OBC.CDL.Interfaces.RealOutput yPum(
    final unit="1",
    final min=0,
    final max=1)
    "Pump speed control signal"

  CDL.Psychrometrics.DewPoint_TDryBulPhi dewPoi
    "Dew point temperature, used to avoid condensation"
  CDL.Reals.Hysteresis hysCoo(
    uLow=0.1,
    uHigh=0.2)
    "Hysteresis to switch system on and off"
  CDL.Reals.PID conCoo(
    final controllerType=controllerType,
    final k=k,
    final Ti = Ti,
    final Td = Td,
    final yMax=1,
    final yMin=0,
    reverseActing=false)
    "Controller for cooling"

protected
  CDL.Reals.Sources.Constant TSupMin(
    final k(
      final unit="K",
      displayUnit="degC") = TSupSet_min,
      y(final unit="K", displayUnit="degC"))
    "Minimum cooling supply water temperature"
  CDL.Reals.Sources.Constant TSupMax(
    final k(
      final unit="K",
      displayUnit="degC") = TSupSet_max,
    y(final unit="K", displayUnit="degC"))
    "Maximum cooling supply water temperature"

  CDL.Reals.Sources.Constant one(final k=1) "Outputs one"
  CDL.Reals.Sources.Constant zero(final k=0) "Outputs zero"

  CDL.Reals.Line TSupNoDewPoi(
    limitBelow=false,
    limitAbove=false,
    y(final unit="K", displayUnit="degC"))
    "Set point for supply water temperature without consideration of dew point"
  CDL.Reals.Max TSupCoo
    "Cooling water supply temperature"
  CDL.Conversions.BooleanToReal booToRea(
    final realFalse=0,
    final realTrue=1)
    "Pump control signal as a Real number (either 0 or 1)"

  CDL.Reals.Max TSurConMin
    "Minimum allowed supply air temperature to avoid condensation"
equation
  connect(hysCoo.y,booToRea.u)
  connect(conCoo.y,hysCoo.u)
  connect(TSupCoo.y, TSupSet)
  connect(conCoo.y, y)
  connect(dewPoi.phi, phiRoo)
  connect(booToRea.y, yPum)
  connect(hysCoo.y, on)
  connect(TSupNoDewPoi.x1, zero.y)
  connect(TSupNoDewPoi.f1, TSupMax.y)
  connect(TSupNoDewPoi.x2, one.y)
  connect(TSupNoDewPoi.f2, TSupMin.y)
  connect(conCoo.y, TSupNoDewPoi.u)
  connect(TSupNoDewPoi.y, TSupCoo.u1)
  connect(TRoo, dewPoi.TDryBul)
  connect(conCoo.u_m, TSur)
  connect(dewPoi.TDewPoi, TSurConMin.u2)
  connect(TSurSet, TSurConMin.u1)
  connect(TSurConMin.y, conCoo.u_s)
  connect(dewPoi.TDewPoi, TSupCoo.u2)
end HighMassSupplyTemperature_TSurRelHum;


within Buildings.Controls.OBC.RadiantSystems;
package Cooling "Package with control sequences for radiant cooling systems"
  extends Modelica.Icons.Package;
end Cooling;


Validation model for the room temperature controller that takes the room temperature set point as an input. This example validates the room temperature controller

Buildings.Controls.OBC.RadiantSystems.Cooling.HighMassSupplyTemperature_TRoomRelHum
for the radiant system.
The validation model applies a tabulated signal to the controller input for the measured room air temperature.
The model also calculates the dew point temperature to verify that the supply water temperature is never below the dew point.

within Buildings.Controls.OBC.RadiantSystems.Cooling.Validation;
model HighMassSupplyTemperature_TRoomRelHum
  "Validation model for the room temperature controller that takes the room temperature set point as an input"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable TPhiRooMea(
    table=[0.0, 18, 0.5;
           0.5, 28, 0.5;
           1.0, 18, 0.5;
           1.0, 18, 0.9;
           1.5, 28, 0.9;
           2.0, 18, 0.9],
    extrapolation=Buildings.Controls.OBC.CDL.Types.Extrapolation.HoldLastPoint,
    offset={273.15, 0},
    timeScale=3600) "Measured room temperature and relative humidity"

  Controls.OBC.RadiantSystems.Cooling.HighMassSupplyTemperature_TRoomRelHum conCoo(
      TSupSet_min=291.15) "Controller"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TRooSet(final k(
      final unit="K",
      displayUnit="degC") = 297.15) "Set point temperature for room"

  CDL.Psychrometrics.DewPoint_TDryBulPhi dewPoi "Dew point temperature"
equation
  connect(TRooSet.y, conCoo.TRooSet)
  connect(TPhiRooMea.y[1], conCoo.TRoo)
  connect(TPhiRooMea.y[2], conCoo.phiRoo)
  connect(dewPoi.TDryBul, TPhiRooMea.y[1])
  connect(dewPoi.phi, TPhiRooMea.y[2])
end HighMassSupplyTemperature_TRoomRelHum;