Block that outputs the operation mode. This block outputs VAV system operating mode. It is implemented according to
ASHRAE guideline G36, section 5.4.3, section 5.4.4, section 5.4.5 and section 5.4.6.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints;
block OperationMode "Block that outputs the operation mode"

  parameter Integer numZon(min=1) "Number of zones";
  parameter Real preWarCooTim(
    final unit="s",
    final quantity="Time") = 10800
    "Maximum cool-down or warm-up time";
  parameter Real TZonFreProOn(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=277.15
    "Threshold temperature to activate the freeze protection mode";
  parameter Real TZonFreProOff(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=280.15
    "Threshold temperature to end the freeze protection mode";

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uOcc
    "Zone occupancy status: true=occupied, false=unoccupied"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput tNexOcc(
    final unit="s",
    final quantity="Time")
    "Time to next occupied period"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput maxCooDowTim(
    final unit="s",
    final quantity="Time") "Maximum cool-down time among all the zones"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uHigOccCoo
    "True when there is zone with the temperature being higher than the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput maxWarUpTim(
    final unit="s",
    final quantity="Time") "Maximum warm-up time among all the zones"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uOccHeaHig
    "True when there is zone with the temperature being lower than the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeWin
    "Total number of zones with opening window"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput totColZon
    "Total number of cold zone"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSetBac
    "True when the average zone temperature falls below the average unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uEndSetBac
    "True when the setback mode could end"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonMin(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Minimum zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput totHotZon
    "Total number of hot zone"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSetUp
    "True when the average zone temperature rises above the average unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uEndSetUp
    "True when the setup mode could end"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yOpeMod
    "Operation mode"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant occModInd(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode "
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant unoPerInd(final k=0.0)
    "Index to indicate unoccupied period"
  Buildings.Controls.OBC.CDL.Reals.Switch corCooDowTim "Corrected cool down period"
  Buildings.Controls.OBC.CDL.Reals.Switch corWarUpTim "Corrected warm-up period"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr(
    final t=4) "Check if the number of cold zones is not less than than 5"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    "If all zone temperature are higher than unoccupied heating setpoint by a given limit, then the setback mode should be off"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1
    "If all zone temperature are higher than threshold temperature of ending freeze protection, then freeze protection setback mode should be off"
  Buildings.Controls.OBC.CDL.Logical.Latch lat2
    "If all zone temperature are lower than unoccupied cooling setpoint by a given limit, then the setup mode should be off"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys2(
    final pre_y_start=true,
    final uHigh=0,
    final uLow=-60)
    "Hysteresis that outputs if the maximum cool-down time is more than the allowed cool-down time"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys3(
    final pre_y_start=true,
    final uHigh=0,
    final uLow=-60)
    "Hysteresis that outputs if the maximum warm-up time is more than allowed warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub5
    "Calculate differential between time-to-next-occupancy and the cool-down time"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys4(
    final pre_y_start=false,
    final uHigh=0,
    final uLow=-60)
    "Hysteresis to check if the cooldown mode could be activated"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys5(
    final pre_y_start=false,
    final uHigh=0,
    final uLow=-60)
    "Hysteresis to activate the warm-up model"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub6
    "Calculate differential between time-to-next-occupancy and the warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys9(
    final pre_y_start=false,
    final uLow=-0.1,
    final uHigh=0.1)
    "Hysteresis that outputs if any zone temperature is lower than freeze protection threshold temperature"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys10(
    final pre_y_start=false,
    final uLow=-0.1,
    final uHigh=0.1)
    "Hysteresis that outputs if all zone temperature are higher than threshold temperature of ending freeze protection"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxWarCooTime(
    final k=preWarCooTim)
    "Allowed maximum warm-up or cool-down time"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr2(
    final t=4) "Check if the number of hot zones is not less than than 5"
  Buildings.Controls.OBC.CDL.Integers.Add addInt "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Integers.Add addInt1 "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Integers.Add addInt2 "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Integers.Add addInt3 "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Integers.Add addInt4 "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Integers.Add addInt5 "Sum of two integer inputs"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger occMod
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger setBacMod
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger freProSetBacMod
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger setUpMod
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Logical.Edge edg
    "Get the moment when the warm up time starts "
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol(
    final trueHoldDuration=preWarCooTim)
    "Hold the start time true signal"
  Buildings.Controls.OBC.CDL.Logical.Edge edg1
    "Get the moment when cool down time starts"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol1(
    final trueHoldDuration=preWarCooTim)
    "Hold the start time true signal"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea1(
    final realTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "Convert Boolean to Integer number"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    final realTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.coolDown)
    "Convert Boolean to Integer number"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt3(
    final integerTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.unoccupied)
    "Convert Boolean to Integer "
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea6(
    final realTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setUp)
    "Convert Boolean to Real "
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea4(
    final realTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.freezeProtection)
    "Convert Boolean to Real "
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea3(
    final realTrue=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setBack)
    "Convert Boolean to Real "
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Level 3 alarm: freeze protection setback")
    "Generate alarm message"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.And and1 "Warm-up period"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Get the start of the cool-down time"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "Check if the number of cold zone is more than 5 or all zones are cold"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or3
    "Check if it is in occupied, cooldown, or warm-up mode"
  Buildings.Controls.OBC.CDL.Logical.Or or4
    "Check if the number of hot zone is more than 5 or all zones are hot"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or5
    "Check if it is in Setback, Setback_freezeProtection, or Setup mode"
  Buildings.Controls.OBC.CDL.Logical.Or or6
    "Check if it is in any of the 6 modes except unoccupied mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Switch between occupied mode index and unoccupied period index"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3
    "If the Cool-down, warm-up, or Occupied mode is on, then setback mode should not be activated."
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    "If the Cool-down, warm-up, or Occupied mode is on, then freeze protection setback mode should not be activated."
  Buildings.Controls.OBC.CDL.Reals.Switch swi5
    "If the Cool-down, warm-up, or Occupied mode is on, then setup mode should not be activated."
  Buildings.Controls.OBC.CDL.Logical.Not not5 "Logical not"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold notOcc(
    final t=1)
    "Check if the operation mode is other than occupied mode"
  Buildings.Controls.OBC.CDL.Logical.And and3
    "True if window open during modes other than occupied mode"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert winOpe(
    final message="Level 4 alarm: window open during modes other than occupied mode")
    "Generate alarm message when window open during modes other than occupied mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "If occupied mode is on, then cool down mode should not be activated"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger setBacMod1
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "If occupied mode is on, then warm-up mode should not be activated."
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger setBacMod2
    "Convert Real number to Integer number"
  Buildings.Controls.OBC.CDL.Logical.And and4 "Cool-down period"
  Buildings.Controls.OBC.CDL.Logical.And and5
    "Get the start of the warm-up time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant totZon(
    final k=numZon) "Total number of zones"
  Buildings.Controls.OBC.CDL.Integers.Equal allCol
    "Check if all zones are cold zone"
  Buildings.Controls.OBC.CDL.Integers.Equal allHot
    "Check if all zones are hot zone"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant actFreProTem(
    final k=TZonFreProOn)
    "Threshold temperature to activate the freeze protection mode"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant endFreProTem(
    final k=TZonFreProOff)
    "Threshold temperature to end the freeze protection mode"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Calculate differential between minimum zone temperature and freeze protection threshold temperature"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate differential between maximum zone temperature and threshold temperature of ending freeze protection"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Enough cold zone or the low average zone temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or7
    "Enough hot zone or the high average zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub3
    "Calculate the difference between maximum cool down time and the allowed maximum cool down time"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub4
    "Calculate the differential between maximum warm-up time and the allowed maximum warm-up time"
  Buildings.Controls.OBC.CDL.Logical.Edge endSetBac
    "End setback mode when the input becomes true"
  Buildings.Controls.OBC.CDL.Logical.Edge endSetUp
    "End setup mode when the input becomes true"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr1(
    final t=1) "Check if there is any zone with opening window"
  Buildings.Controls.OBC.CDL.Integers.Add addInt6
    "Total cold zone and zones with opening window"
  Buildings.Controls.OBC.CDL.Integers.Add addInt7
    "Total hot zone and zones with opening window"

equation
  connect(swi.y, occMod.u)
  connect(occModInd.y, swi.u1)
  connect(unoPerInd.y, swi.u3)
  connect(intGreThr.y, or1.u1)
  connect(lat.y, booToRea3.u)
  connect(unoPerInd.y, swi3.u1)
  connect(or3.y, swi3.u2)
  connect(lat1.y, booToRea4.u)
  connect(or3.y, swi4.u2)
  connect(unoPerInd.y, swi4.u1)
  connect(lat2.y, booToRea6.u)
  connect(or3.y, swi5.u2)
  connect(unoPerInd.y, swi5.u1)
  connect(swi3.y, setBacMod.u)
  connect(swi4.y, freProSetBacMod.u)
  connect(swi5.y, setUpMod.u)
  connect(or5.y, or6.u1)
  connect(or6.y, not2.u)
  connect(not2.y,booToInt3. u)
  connect(and1.y,booToRea1. u)
  connect(and1.y, or3.u1)
  connect(uOcc, swi.u2)
  connect(uOcc, or3.u3)
  connect(hys2.y, corCooDowTim.u2)
  connect(hys3.y, corWarUpTim.u2)
  connect(sub5.y, hys4.u)
  connect(sub6.y, hys5.u)
  connect(hys9.y, lat1.u)
  connect(hys10.y, lat1.clr)
  connect(maxWarCooTime.y, corCooDowTim.u3)
  connect(maxWarCooTime.y, corWarUpTim.u3)
  connect(booToRea3.y, swi3.u3)
  connect(booToRea4.y, swi4.u3)
  connect(booToRea6.y, swi5.u3)
  connect(lat1.y, not5.u)
  connect(not5.y, assMes.u)
  connect(maxCooDowTim, corCooDowTim.u1)
  connect(maxWarUpTim, corWarUpTim.u1)
  connect(totColZon, intGreThr.u)
  connect(totHotZon, intGreThr2.u)
  connect(intGreThr2.y, or4.u1)
  connect(setBacMod.y, addInt2.u1)
  connect(freProSetBacMod.y, addInt2.u2)
  connect(setUpMod.y, addInt3.u2)
  connect(addInt2.y, addInt3.u1)
  connect(addInt3.y, addInt4.u1)
  connect(booToInt3.y, addInt4.u2)
  connect(addInt5.y, yOpeMod)
  connect(notOcc.y, and3.u2)
  connect(and3.y, not1.u)
  connect(addInt5.y, notOcc.u)
  connect(not1.y, winOpe.u)
  connect(booToRea.y, swi1.u3)
  connect(uOcc, swi1.u2)
  connect(swi1.y, setBacMod1.u)
  connect(setBacMod1.y, addInt.u1)
  connect(addInt.y, addInt1.u2)
  connect(occMod.y, addInt1.u1)
  connect(addInt1.y, addInt5.u1)
  connect(addInt4.y, addInt5.u2)
  connect(booToRea1.y, swi2.u3)
  connect(unoPerInd.y, swi1.u1)
  connect(unoPerInd.y, swi2.u1)
  connect(swi2.y, setBacMod2.u)
  connect(setBacMod2.y, addInt.u2)
  connect(and4.y, booToRea.u)
  connect(and4.y, or3.u2)
  connect(hys4.y, and2.u1)
  connect(uOccHeaHig, and5.u2)
  connect(hys5.y, and5.u1)
  connect(truFalHol1.u, edg.y)
  connect(and5.y, edg.u)
  connect(and2.y, edg1.u)
  connect(edg1.y, truFalHol.u)
  connect(lat2.y, or5.u1)
  connect(lat1.y, or5.u2)
  connect(lat.y, or5.u3)
  connect(or3.y, or6.u2)
  connect(allCol.y, or1.u2)
  connect(allHot.y, or4.u2)
  connect(totZon.y, allCol.u2)
  connect(totZon.y, allHot.u2)
  connect(sub.y, hys9.u)
  connect(sub1.y, hys10.u)
  connect(TZonMin, sub1.u1)
  connect(endFreProTem.y, sub1.u2)
  connect(or1.y, or2.u1)
  connect(or2.y, lat.u)
  connect(uSetBac, or2.u2)
  connect(or4.y, or7.u1)
  connect(or7.y, lat2.u)
  connect(uSetUp, or7.u2)
  connect(uOcc, swi2.u2)
  connect(truFalHol.y, and4.u2)
  connect(hys4.y, and4.u1)
  connect(truFalHol1.y, and1.u2)
  connect(hys5.y, and1.u1)
  connect(uHigOccCoo, and2.u2)
  connect(maxWarCooTime.y, sub4.u1)
  connect(maxWarUpTim, sub4.u2)
  connect(sub3.y, hys2.u)
  connect(sub4.y, hys3.u)
  connect(uEndSetBac, endSetBac.u)
  connect(endSetBac.y, lat.clr)
  connect(uEndSetUp, endSetUp.u)
  connect(endSetUp.y, lat2.clr)
  connect(uOpeWin, intGreThr1.u)
  connect(intGreThr1.y, and3.u1)
  connect(totColZon, addInt6.u2)
  connect(uOpeWin, addInt6.u1)
  connect(addInt6.y, allCol.u1)
  connect(totHotZon, addInt7.u2)
  connect(uOpeWin, addInt7.u1)
  connect(addInt7.y, allHot.u1)
  connect(maxCooDowTim, sub3.u2)
  connect(maxWarCooTime.y, sub3.u1)
  connect(corCooDowTim.y, sub5.u1)
  connect(tNexOcc, sub5.u2)
  connect(corWarUpTim.y, sub6.u1)
  connect(tNexOcc, sub6.u2)
  connect(actFreProTem.y, sub.u1)
  connect(TZonMin, sub.u2)
end OperationMode;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic;
package SetPoints "Package with sequences that output control setpoints"
end SetPoints;


Block to inplement trim and respond logic. This block implements the trim and respond logic according to ASHRAE guideline G36,
PART 5.A.15 (trim and respond setpoint reset logic).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints;
block TrimAndRespond "Block to inplement trim and respond logic"
  parameter Real iniSet  "Initial setpoint";
  parameter Real minSet  "Minimum setpoint";
  parameter Real maxSet  "Maximum setpoint";
  parameter Real delTim(
    final unit="s",
    final quantity="Time",
    final min=100*1E-15)  "Delay time";
  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time",
    final min=1E-3)
    "Sample period of component";
  parameter Integer numIgnReq  "Number of ignored requests";
  parameter Real triAmo  "Trim amount";
  parameter Real resAmo  "Respond amount (must have opposite sign of triAmo)";
  parameter Real maxRes  "Maximum response per time interval (must have same sign as resAmo)";

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput numOfReq
    "Number of requests from zones/systems"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uDevSta
    "On/Off status of the associated device"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Setpoint that have been reset"

  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim(
    final delayTime=delTim + samplePeriod,
    final delayOnInit=true)
    "Send an on signal after some delay time"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr
    "Check if the real requests is more than ignored requests setting"
  Buildings.Controls.OBC.CDL.Reals.Switch netRes "Net setpoint reset value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant resAmoCon(
    final k=resAmo)
    "Respond amount constant"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro
    "Products of net requests and respond amount value"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro1
    "Product of trim and respond amount"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro2
    "Product of respond and maximum amount"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay uniDel(
    final samplePeriod=samplePeriod,
    final y_start=iniSet)
    "Output the input signal with a unit delay"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Switch between initial setpoint and reseted setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Before instant (device ON + delTim + samplePeriod), the setpoint should not be trimmed"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Reinitialize setpoint to initial setting when device become OFF"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3 "Logical switch"
  Buildings.Controls.OBC.CDL.Discrete.Sampler sampler(
    final samplePeriod=samplePeriod)
    "Sample number of requests"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr1
    "Check if trim and response amount have same sign"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2
    "Check if trim and response amount have opposite sign"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1
    "Check if response amount have positive sign"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(final k=-1)
    "Convert results back to negative"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant iniSetCon(k=iniSet)
    "Initial setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant numIgnReqCon(k=numIgnReq)
    "Number of ignored requests"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant triAmoCon(k=triAmo)
    "Trim amount constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxResCon(k=maxRes)
    "Maximum response per time interval"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSetCon(k=maxSet)
    "Maximum setpoint constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerTri(k=0)
    "Zero reset amount during time range from (device ON) to (device ON + delTim + timSet)"
  Buildings.Controls.OBC.CDL.Conversions.IntegerToReal intToRea
    "Convert integer input to real output"
  Buildings.Controls.OBC.CDL.Reals.Subtract difReqIgnReq
    "Difference between ignored request number and the real request number"
  Buildings.Controls.OBC.CDL.Reals.Add add1
    "Increase setpoint by amount of value defined from reset logic"
  Buildings.Controls.OBC.CDL.Reals.Add add2 "Net reset value"
  Buildings.Controls.OBC.CDL.Reals.Min minInp
    "Total response should not be more than maximum response"
  Buildings.Controls.OBC.CDL.Reals.Min min1
    "Reset setpoint should not be higher than the maximum setpoint"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "After (device ON + delTim + timSta), when request number becomes more than ignored requests number"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical Not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minSetCon(k=minSet)
    "Minimum setpoint constant"
  Buildings.Controls.OBC.CDL.Reals.Max maxInp
    "Reset setpoint should not be lower than the minimum setpoint"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Trim amount 'triAmo' and respond amount 'resAmo' must have opposite signs.")
    "Generate alarm message"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes2(
    final message="Respond amount 'resAmo' and maximum respond amount 'maxRes' must have same sign.")
    "Generate alarm message"
  Buildings.Controls.OBC.CDL.Reals.Abs abs "Absolute value of real input"
  Buildings.Controls.OBC.CDL.Reals.Abs abs1 "Absolute value of real input"

equation
  connect(difReqIgnReq.y, greThr.u)
  connect(pro.y, minInp.u1)
  connect(triAmoCon.y, add2.u1)
  connect(add2.y, netRes.u1)
  connect(iniSetCon.y, swi.u3)
  connect(swi.y, y)
  connect(maxSetCon.y, min1.u2)
  connect(add1.y, min1.u1)
  connect(uniDel.y, add1.u1)
  connect(triAmoCon.y, swi1.u1)
  connect(zerTri.y, swi1.u3)
  connect(greThr.y, and2.u2)
  connect(and2.y, netRes.u2)
  connect(iniSetCon.y, swi2.u1)
  connect(swi2.y, swi.u1)
  connect(swi2.y, uniDel.u)
  connect(uDevSta, not1.u)
  connect(not1.y, swi2.u2)
  connect(min1.y, maxInp.u1)
  connect(minSetCon.y, maxInp.u2)
  connect(numOfReq, intToRea.u)
  connect(intToRea.y, sampler.u)
  connect(difReqIgnReq.y, pro.u1)
  connect(uDevSta, tim.u)
  connect(tim.y, swi.u2)
  connect(tim.y, swi1.u2)
  connect(and2.u1, tim.y)
  connect(maxInp.y, swi2.u3)
  connect(triAmoCon.y, pro1.u1)
  connect(resAmoCon.y, pro1.u2)
  connect(pro1.y, lesThr1.u)
  connect(lesThr1.y, assMes.u)
  connect(resAmoCon.y, pro2.u1)
  connect(maxResCon.y, pro2.u2)
  connect(pro2.y, greThr2.u)
  connect(greThr2.y, assMes2.u)
  connect(resAmoCon.y, abs.u)
  connect(abs.y, pro.u2)
  connect(maxResCon.y, abs1.u)
  connect(abs1.y, minInp.u2)
  connect(minInp.y, swi3.u1)
  connect(resAmoCon.y, greThr1.u)
  connect(greThr1.y, swi3.u2)
  connect(netRes.y, add1.u2)
  connect(swi1.y, netRes.u3)
  connect(minInp.y, gai.u)
  connect(gai.y, swi3.u3)
  connect(swi3.y, add2.u2)
  connect(numIgnReqCon.y, difReqIgnReq.u2)
  connect(sampler.y, difReqIgnReq.u1)
end TrimAndRespond;


Block that outputs zone temperature status. This block outputs single zone status. It includes outputs as following:

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints;
block ZoneStatus "Block that outputs zone temperature status"

  parameter Real THeaSetOcc(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=293.15
    "Occupied heating setpoint";
  parameter Real THeaSetUno(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=285.15
    "Unoccupied heating setpoint";
  parameter Real TCooSetOcc(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Occupied cooling setpoint";
  parameter Real TCooSetUno(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=303.15
    "Unoccupied cooling setpoint";
  parameter Real bouLim(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference",
    final min=0.5) = 1
    "Threshold of temperature difference for indicating the end of setback or setup mode";
  parameter Boolean have_winSen=false
    "Check if the zone has window status sensor";
  parameter Real uLow=-0.1
    "Low limit of the hysteresis for checking temperature difference"
  parameter Real uHigh=0.1
    "High limit of the hysteresis for checking temperature difference"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput cooDowTim(
    final unit="s",
    final quantity="Time")
    "Cool-down time retrieved from optimal cool-down block"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput warUpTim(
    final unit="s",
    final quantity="Time")
    "Warm-up time retrieved from optimal warm-up block"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uWin if have_winSen
    "Window status: true=open, false=close"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Single zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCooTim(
    final unit="s",
    final quantity="Time") "Cool-down time"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yWarTim(
    final unit="s",
    final quantity="Time") "Warm-up time"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput THeaSetOn(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yOccHeaHig
    "True when the zone temperature is lower than the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TCooSetOn(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Occupied cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yHigOccCoo
    "True when the zone temperature is higher than the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput THeaSetOff(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yUnoHeaHig
    "True when the zone temperature is lower than the unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yEndSetBac
    "True when the zone could end setback mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TCooSetOff(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yHigUnoCoo
    "True when the zone temperature is higher than the unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yEndSetUp
    "True when the zone could end setup mode"

protected
  Buildings.Controls.OBC.CDL.Reals.Multiply pro "Decide if the cool down time of one zone should be ignored: if window is open,
    then output zero, otherwise, output cool-down time from optimal cool-down block"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro1 "Decide if the warm-up time of one zone should be ignored: if window is open,
    then output zero, otherwise, output warm-up time from optimal warm-up block"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Calculate difference between zone temperature and the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys(
    final uLow=uLow,
    final uHigh=uHigh)
    "Hysteresis that outputs if the system should run in warm-up mode"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate difference between zone temperature and the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys1(
    final uLow=uLow,
    final uHigh=uHigh)
    "Hysteresis that outputs if the system should run in cool-down mode"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    "Calculate zone temperature difference to unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys2(
    final uLow=uLow,
    final uHigh=uHigh)
    "Hysteresis that outputs if the zone temperature is lower than unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub5
    "Calculate zone temperature difference to unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys5(
    final uLow=uLow,
    final uHigh=uHigh)
    "Hysteresis that outputs if the zone temperature is higher than unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea "Convert Boolean to Real number"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false) if not have_winSen
    "Constant false"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant occHeaSet(
    final k=THeaSetOcc)
    "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant unoHeaSet(
    final k=THeaSetUno)
    "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant occCooSet(
    final k=TCooSetOcc)
    "Occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant unoCooSet(
    final k=TCooSetUno)
    "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub3
    "Calculate zone temperature difference to unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys3(
    final uLow=0,
    final uHigh=bouLim)
    "Hysteresis that outputs if the zone temperature is higher than its unoccupied heating setpoint by a given limit"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub4
    "Calculate zone temperature difference to unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys4(
    final uLow=0,
    final uHigh=bouLim)
    "Hysteresis that outputs if the zone temperature is lower than its unoccupied cooling setpoint by a given limit"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "When window is open, it should output false"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "When window is open, it should output false"
  Buildings.Controls.OBC.CDL.Logical.And and3
    "When window is open, it should output false"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "When window is open, it should output true"
  Buildings.Controls.OBC.CDL.Logical.And and5
    "When window is open, it should output false"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "When window is open, it should output true"

equation
  connect(cooDowTim, pro.u1)
  connect(warUpTim, pro1.u1)
  connect(booToRea.y, pro.u2)
  connect(booToRea.y, pro1.u2)
  connect(sub.y, hys.u)
  connect(sub1.y, hys1.u)
  connect(uWin, not1.u)
  connect(sub2.y, hys2.u)
  connect(sub5.y, hys5.u)
  connect(not1.y, booToRea.u)
  connect(pro.y, yCooTim)
  connect(pro1.y, yWarTim)
  connect(con.y, not1.u)
  connect(TZon,sub. u2)
  connect(unoCooSet.y, TCooSetOff)
  connect(unoHeaSet.y, THeaSetOff)
  connect(occHeaSet.y, THeaSetOn)
  connect(occCooSet.y, TCooSetOn)
  connect(unoHeaSet.y, sub2.u1)
  connect(unoHeaSet.y, sub3.u2)
  connect(sub3.y, hys3.u)
  connect(sub4.y, hys4.u)
  connect(occHeaSet.y,sub. u1)
  connect(TZon, sub2.u2)
  connect(TZon, sub3.u1)
  connect(and2.y, yOccHeaHig)
  connect(hys.y, and2.u1)
  connect(hys1.y, and1.u1)
  connect(hys2.y, and3.u1)
  connect(hys3.y, or2.u1)
  connect(hys5.y, and5.u1)
  connect(hys4.y, or1.u1)
  connect(not1.y, and2.u2)
  connect(not1.y, and1.u2)
  connect(and1.y, yHigOccCoo)
  connect(and3.y, yUnoHeaHig)
  connect(or2.y, yEndSetBac)
  connect(and5.y, yHigUnoCoo)
  connect(or1.y, yEndSetUp)
  connect(uWin, or2.u2)
  connect(uWin, or1.u2)
  connect(con.y, or2.u2)
  connect(con.y, or1.u2)
  connect(not1.y, and3.u2)
  connect(not1.y, and5.u2)
  connect(TZon, sub1.u1)
  connect(occCooSet.y, sub1.u2)
  connect(TZon, sub5.u1)
  connect(unoCooSet.y, sub5.u2)
  connect(unoCooSet.y, sub4.u1)
  connect(TZon, sub4.u2)
end ZoneStatus;


Duplicate zone status output. This block duplicates the signals of nZon by converting the
input vector-valued signals of dimension nZon to a matrix-valued
output of dimension [nGro, nZon].

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints;
block ZoneStatusDuplicator "Duplicate zone status output"

  parameter Integer nZon(final min=1)=1 "Number of zones in input";
  parameter Integer nGro(final min=1)=1 "Number of groups in output";

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput zonOcc[nZon]
    "True when the zone is set to be occupied due to the override"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uOcc[nZon]
    "True when the zone is occupied according to the occupancy schedule"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput tNexOcc[nZon](
    final unit=fill("s", nZon),
    final quantity=fill("Time", nZon))
    "Time to next occupied period"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCooTim[nZon](
    final unit=fill("s", nZon),
    final quantity=fill("Time", nZon))
    "Cool down time"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uWarTim[nZon](
    final unit=fill("s", nZon),
    final quantity=fill("Time", nZon))
    "Warm-up time"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uOccHeaHig[nZon]
    "True when the zone temperature is lower than the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uHigOccCoo[nZon]
    "True when the zone temperature is higher than the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uUnoHeaHig[nZon]
    "True when the zone temperature is lower than the unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSetOff[nZon](
    final unit=fill("K", nZon),
    displayUnit=fill("degC", nZon),
    final quantity=fill("ThermodynamicTemperature", nZon))
    "Zone unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uEndSetBac[nZon]
    "True when the zone could end the setback mode"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uHigUnoCoo[nZon]
    "True when the zone temperature is higher than its unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TCooSetOff[nZon](
    final unit=fill("K", nZon),
    displayUnit=fill("degC", nZon),
    final quantity=fill("ThermodynamicTemperature", nZon))
    "Zone unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uEndSetUp[nZon]
    "True when the zone could end the setup mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon[nZon](
    final unit=fill("K", nZon),
    displayUnit=fill("degC", nZon),
    final quantity=fill("ThermodynamicTemperature", nZon)) "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uWin[nZon]
    "True when the window is open, false when the window is close or the zone does not have window status sensor"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yzonOcc[nGro, nZon]
    "True when the zone is set to be occupied due to the override"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yOcc[nGro,nZon]
    "True when the zone is occupied according to the occupancy schedule"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput ytNexOcc[nGro, nZon](
    final unit=fill("s", nGro, nZon),
    final quantity=fill("Time", nGro, nZon)) "Time to next occupied period"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCooTim[nGro,nZon](
    final unit=fill("s", nGro, nZon),
    final quantity=fill("Time", nGro, nZon)) "Cool down time"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yWarTim[nGro,nZon](
    final unit=fill("s", nGro, nZon),
    final quantity=fill("Time", nGro, nZon)) "Warm-up time"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yOccHeaHig[nGro,nZon]
    "True when the zone temperature is lower than the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yHigOccCoo[nGro,nZon]
    "True when the zone temperature is higher than the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yUnoHeaHig[nGro,nZon]
    "True when the zone temperature is lower than the unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yTHeaSetOff[nGro, nZon](
    final unit=fill("K", nGro, nZon),
    displayUnit=fill("degC", nGro, nZon),
    final quantity=fill("ThermodynamicTemperature", nGro, nZon))
    "Zone unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yEndSetBac[nGro,nZon]
    "True when the zone could end the setback mode"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yHigUnoCoo[nGro,nZon]
    "True when the zone temperature is higher than its unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yTCooSetOff[nGro, nZon](
    final unit=fill("K", nGro, nZon),
    displayUnit=fill("degC", nGro, nZon),
    final quantity=fill("ThermodynamicTemperature", nGro, nZon))
    "Zone unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yEndSetUp[nGro,nZon]
    "True when the zone could end the setup mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yTZon[nGro, nZon](
    final unit=fill("K", nGro, nZon),
    displayUnit=fill("degC", nGro, nZon),
    final quantity=fill("ThermodynamicTemperature", nGro, nZon)) "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yWin[nGro,nZon]
    "True when the window is open, false when the window is close or the zone does not have window status sensor"

protected
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator zonOccDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uOccDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator tNexOccDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator uCooTimDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator uWarTimDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uOccHeaHigDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uHigOccCooDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uUnoHeaHigDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator THeaSetOffDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uEndSetBacDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uHigUnoCooDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator TCooSetOffDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uEndSetUpDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.RealVectorReplicator TZonDup(
    final nin=nZon,
    final nout=nGro) "Duplicator"
  Buildings.Controls.OBC.CDL.Routing.BooleanVectorReplicator uWinDup(
    final nin=nZon,
    final nout=nGro)
    "Duplicator"

equation
  connect(zonOcc, zonOccDup.u)
  connect(uOcc,uOccDup. u)
  connect(tNexOcc, tNexOccDup.u)
  connect(uCooTim, uCooTimDup.u)
  connect(uWarTim, uWarTimDup.u)
  connect(uOccHeaHig, uOccHeaHigDup.u)
  connect(uHigOccCoo, uHigOccCooDup.u)
  connect(uUnoHeaHig, uUnoHeaHigDup.u)
  connect(THeaSetOff, THeaSetOffDup.u)
  connect(uEndSetBac, uEndSetBacDup.u)
  connect(uHigUnoCoo, uHigUnoCooDup.u)
  connect(TCooSetOff, TCooSetOffDup.u)
  connect(uEndSetUp, uEndSetUpDup.u)
  connect(TZon, TZonDup.u)
  connect(uWin, uWinDup.u)
  connect(zonOccDup.y, yzonOcc)
  connect(uOccDup.y, yOcc)
  connect(ytNexOcc, tNexOccDup.y)
  connect(yCooTim, uCooTimDup.y)
  connect(uWarTimDup.y, yWarTim)
  connect(uOccHeaHigDup.y, yOccHeaHig)
  connect(uHigOccCooDup.y, yHigOccCoo)
  connect(uUnoHeaHigDup.y, yUnoHeaHig)
  connect(THeaSetOffDup.y, yTHeaSetOff)
  connect(uEndSetBacDup.y, yEndSetBac)
  connect(uHigUnoCooDup.y, yHigUnoCoo)
  connect(TCooSetOffDup.y, yTCooSetOff)
  connect(uEndSetUpDup.y, yEndSetUp)
  connect(TZonDup.y, yTZon)
  connect(uWinDup.y, yWin)
end ZoneStatusDuplicator;


Validate block for checking temperatures in the group. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.GroupStatus
for checking group temperature status.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.Validation;
model GroupStatus
  "Validate block for checking temperatures in the group"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.GroupStatus zonGroSta(
    final numZon=3,
    numZonGro=2,
    zonGroMsk={true,false,true}) "Calculate zone group status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warUpTim[3](
    final k={1800,1700,1900})
    "Warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooDowTim[3](
    final k={1600,1700,1800})
    "Cooling down time"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta[3](
    final width={0.3,0.2,0.1},
    final period=fill(3600, 3),
    final shift={150,130,120})
    "Window status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    final offset=0,
    final height=6.2831852,
    final duration=24*3600) "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sin sin2
    "Block that outputs the sine of the input"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=6)
    "Current zone temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter zonTem(
    final p=273.15 + 22.5)
    "Current zone temperature"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant uOccOve[3](
    final k=fill(false,3))
    "Occupancy local override"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse zonOcc1(
    final width=0.8,
    final period=7200,
    shift=1800)
    "Zone 1 occupied status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse zonOcc3(
    final width=0.8,
    final period=7200,
    shift=2100) "Zone 3 occupied status"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not not3 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Timer tim1 "Time after input becomes true"
  Buildings.Controls.OBC.CDL.Logical.Timer tim3 "Time after input becomes true"
  Buildings.Controls.OBC.CDL.Reals.Subtract addPar1
    "Time to occupied period"
  Buildings.Controls.OBC.CDL.Reals.Subtract addPar3
    "Time to occupied period"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse lowOccHea[3](
    final width=fill(0.5, 3),
    final period=fill(3600, 3),
    final shift=fill(1000, 3)) "Lower than occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant higOccCoo[3](
    final k=fill(false, 3))
    "Higher than occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.And and2[3]
    "Lower than occupied heating setpoint when it is not occupied"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse lowUnoHea1[3](
    final width=fill(0.1, 3),
    final period=fill(3600, 3))
    "Lower than unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaSetOff[3](
    final k={285.15,282.15,283.15})
    "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse endSetBac[3](
    final width=fill(0.8, 3),
    final period=fill(3600, 3),
    final shift=fill(900, 3)) "End setback"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant higUnoCoo[3](
    final k=fill(false, 3))
    "HIgher than unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooSetOff[3](
    final k={303.15,304.15,305.15})
    "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant endSetUp[3](
    final k=fill(false,3))
    "End setup mode"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse zonTem3(
    final amplitude=7,
    final period=600,
    final offset=273.15 + 19) "Zone 3 temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zonTem2(
    final k=273.15 + 20)
    "Zone 2 temperature"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant zonOcc2(
    final k=true)
    "Zone 2 occupied status"
  Buildings.Controls.OBC.CDL.Logical.Not not2
    "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant tNexOcc2(
    final k=0) "Zone 2 next occupancy time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(
    final k=1800)
    "Constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(
    final k=2100)
    "Constant"

equation
  connect(ramp2.y,sin2. u)
  connect(not1.y, tim1.u)
  connect(not3.y,tim3. u)
  connect(uOccOve.y, zonGroSta.zonOcc)
  connect(zonOcc1.y, not1.u)
  connect(zonOcc3.y,not3. u)
  connect(zonOcc1.y, zonGroSta.uOcc[1])
  connect(zonOcc3.y, zonGroSta.uOcc[3])
  connect(addPar1.y, zonGroSta.tNexOcc[1])
  connect(addPar3.y, zonGroSta.tNexOcc[3])
  connect(cooDowTim.y, zonGroSta.uCooTim)
  connect(warUpTim.y, zonGroSta.uWarTim)
  connect(not1.y, and2[1].u2)
  connect(not3.y, and2[3].u2)
  connect(lowOccHea.y, and2.u1)
  connect(and2.y, zonGroSta.uOccHeaHig)
  connect(higOccCoo.y, zonGroSta.uHigOccCoo)
  connect(lowUnoHea1.y, zonGroSta.uUnoHeaHig)
  connect(heaSetOff.y, zonGroSta.THeaSetOff)
  connect(endSetBac.y, zonGroSta.uEndSetBac)
  connect(higUnoCoo.y, zonGroSta.uHigUnoCoo)
  connect(cooSetOff.y, zonGroSta.TCooSetOff)
  connect(endSetUp.y, zonGroSta.uEndSetUp)
  connect(zonTem.y, zonGroSta.TZon[1])
  connect(zonTem3.y, zonGroSta.TZon[3])
  connect(winSta.y, zonGroSta.uWin)
  connect(zonTem2.y, zonGroSta.TZon[2])
  connect(zonOcc2.y, not2.u)
  connect(not2.y, and2[2].u2)
  connect(zonOcc2.y, zonGroSta.uOcc[2])
  connect(tNexOcc2.y, zonGroSta.tNexOcc[2])
  connect(con.y, addPar1.u1)
  connect(tim1.y, addPar1.u2)
  connect(con1.y, addPar3.u1)
  connect(tim3.y, addPar3.u2)
  connect(sin2.y, gai.u)
  connect(gai.y, zonTem.u)
end GroupStatus;


Validate block for selecting operation mode. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.OperationMode
for a change of zone temperature and occupancy schedule.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.Validation;
model OperationMode "Validate block for selecting operation mode"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.OperationMode
    opeModSel(final numZon=1) "Operation mode selection"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    final height=6.2831852,
    final duration=172800)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sin sin1
    "Block that outputs the sine of the input"
  Buildings.Controls.OBC.CDL.Reals.AddParameter zonTem(
    final p=295.65) "Zone temperarure"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=14.5) "Gain factor"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSetUno(
    final k=285.15)  "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSetUno(
    final k=303.15)  "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSetOcc(
    final k=293.15)  "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSetOcc(
    final k=297.15)  "Occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warUpTim(
    final k=1800) "Warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooDowTim(
    final k=1800) "Cooling down time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant cloWin(
    final k=0) "No window is open"
  Buildings.Controls.OBC.CDL.Reals.Greater lowThaHeaSet
    "True when the zone temperature is lower than the occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Greater higThaCooSet
    "True when the zone temperature is higher than the occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Greater greEqu2
    "True when the zone temperature is lower than unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt "Convert boolean to integer"
  Buildings.Controls.OBC.CDL.Reals.Greater greEqu3
    "True when the zone temperature is lower than unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1 "Convert boolean to integer"
  Buildings.Controls.SetPoints.OccupancySchedule occSch "Occupancy schedule"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub3
    "Calculate zone temperature difference to unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys3(
    final uLow=-0.5,
    final uHigh=0.5)
    "Hysteresis that outputs if the zone temperature is higher than its unoccupied heating setpoint by a given limit"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate zone temperature difference to unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys1(
    final uLow=-0.5,
    final uHigh=0.5)
    "Hysteresis that outputs if the zone temperature is lower than its unoccupied cooling setpoint by a given limit"

equation
  connect(ramp1.y, sin1.u)
  connect(cooDowTim.y, opeModSel.maxCooDowTim)
  connect(warUpTim.y, opeModSel.maxWarUpTim)
  connect(TZonHeaSetOcc.y, lowThaHeaSet.u1)
  connect(zonTem.y, lowThaHeaSet.u2)
  connect(zonTem.y, higThaCooSet.u1)
  connect(TZonCooSetOcc.y, higThaCooSet.u2)
  connect(TZonHeaSetUno.y, greEqu2.u1)
  connect(zonTem.y, greEqu2.u2)
  connect(greEqu2.y, booToInt.u)
  connect(booToInt.y, opeModSel.totColZon)
  connect(zonTem.y, opeModSel.TZonMin)
  connect(zonTem.y, greEqu3.u1)
  connect(TZonCooSetUno.y, greEqu3.u2)
  connect(greEqu3.y, booToInt1.u)
  connect(booToInt1.y, opeModSel.totHotZon)
  connect(occSch.occupied, opeModSel.uOcc)
  connect(occSch.tNexOcc, opeModSel.tNexOcc)
  connect(higThaCooSet.y, opeModSel.uHigOccCoo)
  connect(lowThaHeaSet.y, opeModSel.uOccHeaHig)
  connect(cloWin.y, opeModSel.uOpeWin)
  connect(greEqu2.y, opeModSel.uSetBac)
  connect(greEqu3.y, opeModSel.uSetUp)
  connect(zonTem.y, sub3.u1)
  connect(TZonHeaSetUno.y, sub3.u2)
  connect(sub3.y, hys3.u)
  connect(hys3.y, opeModSel.uEndSetBac)
  connect(sub1.y, hys1.u)
  connect(hys1.y, opeModSel.uEndSetUp)
  connect(zonTem.y, sub1.u2)
  connect(TZonCooSetUno.y, sub1.u1)
  connect(sin1.y, gai.u)
  connect(gai.y, zonTem.u)
  connect(zonTem.y, sub1.u2)
  connect(TZonCooSetUno.y, sub1.u1)
end OperationMode;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints;
package Validation "Collection of validation models"
end Validation;


Model validates the trim and respond block. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.Validation;
model TrimAndRespond "Model validates the trim and respond block"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond
    trimRespondLogic(
    final iniSet=120,
    final minSet=37,
    final maxSet=370,
    final delTim=300,
    final samplePeriod=120,
    final numIgnReq=2,
    final triAmo=-10,
    final resAmo=15,
    final maxRes=37) "Block implementing trim and respond logic"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond
    trimRespondLogic1(
    final iniSet=120,
    final minSet=37,
    final maxSet=370,
    final delTim=300,
    final samplePeriod=120,
    final numIgnReq=2,
    final triAmo=10,
    final resAmo=-15,
    final maxRes=-37) "Block implementing trim and respond logic"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond
    trimRespondLogic2(
    final iniSet=120,
    final minSet=37,
    final maxSet=370,
    final delTim=300,
    final samplePeriod=120,
    final numIgnReq=2,
    final triAmo=-10,
    final resAmo=15,
    final maxRes=37) "Block implementing trim and respond logic"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=true) "Logic true indicating device ON"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine(
    final amplitude=6,
    final freqHz=1/5400) "Block generates sine signal"
  Buildings.Controls.OBC.CDL.Reals.Abs abs
    "Block generates absolute value of input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine1(
    final amplitude=6,
    freqHz=1/5400) "Block generates sine signal"
  Buildings.Controls.OBC.CDL.Reals.Abs abs1
    "Block generates absolute value of input"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final period=3600,
    final width=0.18333333) "Generate pulse signal of type Boolean"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Switch swi "Switch between two Real signals"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(final k=0)
    "Zero request when device is OFF"
  Buildings.Controls.OBC.CDL.Reals.Round round2(final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round1(final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"

equation
  connect(con.y, trimRespondLogic.uDevSta)
  connect(sine.y, abs.u)
  connect(not1.y,trimRespondLogic2. uDevSta)
  connect(con1.y, swi.u1)
  connect(sine1.y, swi.u3)
  connect(swi.y, abs1.u)
  connect(booPul.y, swi.u2)
  connect(booPul.y, not1.u)
  connect(abs.y, round2.u)
  connect(round2.y, reaToInt1.u)
  connect(reaToInt1.y, trimRespondLogic.numOfReq)
  connect(abs1.y, round1.u)
  connect(round1.y, reaToInt2.u)
  connect(reaToInt2.y,trimRespondLogic2. numOfReq)
  connect(con.y,trimRespondLogic1. uDevSta)
  connect(reaToInt1.y,trimRespondLogic1. numOfReq)
end TrimAndRespond;


Validate block for checking temperatures in the zone. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.ZoneStatus
for checking zone temperature status.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.Validation;
model ZoneStatus
  "Validate block for checking temperatures in the zone"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.ZoneStatus noWinZonSta(final
      have_winSen=false)
    "Status of zone when there is no window operation sensor"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.ZoneStatus witWinZonSta(final
      have_winSen=true) "Status of zone when there is window operation sensor"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warUpTim(
    final k=1800) "Warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooDowTim(
    final k=1800) "Cooling down time"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse uWinSta(
    final width=0.3,
    final period=43200,
    final shift=1800)
    "Window on/off status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    final offset=0,
    final height=6.2831852,
    final duration=24*3600) "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sin sin2
    "Block that outputs the sine of the input"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=12.5)
    "Gain factor"
  Buildings.Controls.OBC.CDL.Reals.AddParameter zonTem(
    final p=273.15 + 22.5)
    "Current zone temperature"

equation
  connect(cooDowTim.y, noWinZonSta.cooDowTim)
  connect(warUpTim.y, noWinZonSta.warUpTim)
  connect(ramp2.y,sin2. u)
  connect(zonTem.y, noWinZonSta.TZon)
  connect(cooDowTim.y, witWinZonSta.cooDowTim)
  connect(warUpTim.y, witWinZonSta.warUpTim)
  connect(zonTem.y, witWinZonSta.TZon)
  connect(uWinSta.y, witWinZonSta.uWin)
  connect(sin2.y, gai.u)
  connect(gai.y, zonTem.u)
end ZoneStatus;


Validate block for duplicating zone status. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.ZoneStatusDuplicator
for duplicating zone status.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.Validation;
model ZoneStatusDuplicator
  "Validate block for duplicating zone status"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.ZoneStatusDuplicator
    zonStaDup(final nZon=5, final nGro=2) "Zone status duplicator"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant reaInp[6,5](
    final k=fill({1,2,3,4,5}, 6))
    "Real inputs"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant booInp[9,5](
    final k=fill({true,true,false,true,false},9))
    "Boolean inputs"

equation
  connect(reaInp[1, :].y, zonStaDup.tNexOcc)
  connect(reaInp[2, :].y, zonStaDup.uCooTim)
  connect(reaInp[3, :].y, zonStaDup.uWarTim)
  connect(reaInp[4, :].y, zonStaDup.THeaSetOff)
  connect(reaInp[5, :].y, zonStaDup.TCooSetOff)
  connect(reaInp[6, :].y, zonStaDup.TZon)
  connect(booInp[1, :].y, zonStaDup.zonOcc)
  connect(booInp[2, :].y, zonStaDup.uOcc)
  connect(booInp[3, :].y, zonStaDup.uOccHeaHig)
  connect(booInp[4, :].y, zonStaDup.uHigOccCoo)
  connect(booInp[5, :].y, zonStaDup.uUnoHeaHig)
  connect(booInp[6, :].y, zonStaDup.uEndSetBac)
  connect(booInp[7, :].y, zonStaDup.uHigUnoCoo)
  connect(booInp[8, :].y, zonStaDup.uEndSetUp)
  connect(booInp[9, :].y, zonStaDup.uWin)
end ZoneStatusDuplicator;


Validation model for the mixed air temperature based freeze protection block. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.FreezeProtectionMixedAir
for mixed air temperature TMix signal.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.Validation;
model FreezeProtectionMixedAir
  "Validation model for the mixed air temperature based freeze protection block"

  parameter Real TFreSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")= 273.15 + 4
    "Freeze protection set point temperature";

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.FreezeProtectionMixedAir
    freProTMix(final TFreSet=TFreSet)
    "Freeze protection signal based on mixed air temperature"

  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sin1(
    amplitude=20,
    freqHz=1/1800,
    startTime=0,
    offset=TFreSet - 1) "Sine shaped mixed air temperature input signal"

equation
  connect(sin1.y, freProTMix.TMix)
end FreezeProtectionMixedAir;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic;
package Validation "Collection of validation models"
end Validation;


Controller for room VAV box. Controller for terminal box of VAV system with reheat according to ASHRAE
Guideline 36, Part 5.E. It outputs damper position yDam,
hot water valve position yVal, AHU cooling supply temperature
setpoint reset request yZonTemResReq, and static pressure setpoint
reset request yZonPreResReq.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits;
block Controller "Controller for room VAV box"

  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time")
    "Sample period of component, set to the same value as the trim and respond that process yPreSetReq";
  parameter Real V_flow_nominal(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Volume flow rate of this thermal zone";
  parameter Real AFlo(
    final unit="m2",
    final quantity="Area") "Area of the zone";

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeCoo=
     Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"

  parameter Real kCoo(final unit="1/K") = 0.1
    "Gain for cooling control loop signal"

  parameter Real TiCoo(
    final unit="s",
    final quantity="Time")=900
    "Time constant of integrator block for cooling control loop signal"

  parameter Real TdCoo(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for cooling control loop signal"

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeHea=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real kHea(final unit="1/K")=0.1
    "Gain for heating control loop signal"

  parameter Real TiHea(
    final unit="s",
    final quantity="Time")=900
    "Time constant of integrator block for heating control loop signal"

  parameter Real TdHea(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for heating control loop signal"

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeVal=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"

  parameter Real kVal=0.5
    "Gain of controller for valve control"

  parameter Real TiVal(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for valve control"

  parameter Real TdVal(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for valve control"

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeDam=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"

  parameter Real kDam(final unit="1")=0.5
    "Gain of controller for damper control"

  parameter Real TiDam(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for damper control"

  parameter Real TdDam(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for damper control"

  parameter Boolean have_occSen=false
    "Set to true if the zone has occupancy sensor"
  parameter Boolean have_winSen=false
    "Set to true if the zone has window status sensor"
  parameter Boolean have_CO2Sen=false
    "Set to true if the zone has CO2 sensor"
  parameter Real VDisCooSetMax_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=V_flow_nominal
    "Zone maximum cooling airflow setpoint"
  parameter Real VDisSetMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.15*V_flow_nominal
    "Zone minimum airflow setpoint"
  parameter Real VDisHeaSetMax_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.3*V_flow_nominal
    "Zone maximum heating airflow setpoint"
  parameter Real VDisConMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.1*V_flow_nominal
    "VAV box controllable minimum"
  parameter Real VOutPerAre_flow(final unit = "m3/(s.m2)")=3e-4
    "Outdoor air rate per unit area"
  parameter Real VOutPerPer_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=2.5e-3
    "Outdoor air rate per person"
  parameter Real CO2Set=894 "CO2 setpoint in ppm"
  parameter Real dTDisZonSetMax(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference")=11
    "Zone maximum discharge air temperature above heating setpoint"
  parameter Real TDisMin(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")=283.15
    "Lowest discharge air temperature"
  parameter Boolean have_heaWatCoi=true
    "Flag, true if there is a hot water coil"
  parameter Boolean have_heaPla=false
    "Flag, true if there is a boiler plant"
  parameter Real errTZonCoo_1(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference")=2.8
    "Limit value of difference between zone temperature and cooling setpoint
    for generating 3 cooling SAT reset requests"
  parameter Real errTZonCoo_2(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference")=1.7
    "Limit value of difference between zone temperature and cooling setpoint
    for generating 2 cooling SAT reset requests"
  parameter Real errTDis_1(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference")=17
    "Limit value of difference between discharge air temperature and its setpoint
    for generating 3 hot water reset requests"
  parameter Real errTDis_2(
    final unit="K",
    displayUnit="K",
    final quantity="TemperatureDifference")=8.3
    "Limit value of difference between discharge air temperature and its setpoint
    for generating 2 hot water reset requests"
  parameter Real durTimTem(
    final unit="s",
    final quantity="Time")=120
    "Duration time of zone temperature exceeds setpoint"
  parameter Real durTimFlo(
    final unit="s",
    final quantity="Time")=60
    "Duration time of airflow rate less than setpoint"
  parameter Real durTimDisAir(
    final unit="s",
    final quantity="Time")=300
    "Duration time of discharge air temperature is less than setpoint"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonHeaSet(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")
    "Setpoint temperature for room for heating"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonCooSet(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")
    "Setpoint temperature for room for cooling"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")
    "Measured room temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")
    "Measured supply air temperature after heating coil"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSupAHU(
    final quantity="ThermodynamicTemperature",
    final unit = "K",
    displayUnit = "degC")
    "AHU supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2 if have_CO2Sen
    "Measured CO2 concentration"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput nOcc if have_occSen
    "Number of occupants"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uWin if have_winSen
    "Window status, true if open, false if closed"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput yDam_actual
    "Actual VAV damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yVal(
    final min=0,
    final max=1,
    final unit="1")
    "Signal for heating coil valve"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final max=1,
    final unit="1")
    "Signal for VAV damper"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonPreResReq
    "Zone static pressure reset requests"

  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaValResReq if have_heaWatCoi
    "Hot water temperature reset requests"

  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaPlaReq if (have_heaWatCoi and have_heaPla)
    "Heating plant request"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints.ActiveAirFlow
    actAirSet(
    final AFlo=AFlo,
    final have_occSen=have_occSen,
    final have_winSen=have_winSen,
    final have_CO2Sen=have_CO2Sen,
    final VDisCooSetMax_flow=VDisCooSetMax_flow,
    final VDisSetMin_flow=VDisSetMin_flow,
    final VDisHeaSetMax_flow=VDisHeaSetMax_flow,
    final VDisConMin_flow=VDisConMin_flow,
    final VOutPerAre_flow=VOutPerAre_flow,
    final VOutPerPer_flow=VOutPerPer_flow,
    final CO2Set=CO2Set) "Active airflow rate setpoint"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.DamperValves
    damVal(
    final controllerTypeVal=controllerTypeVal,
    final kVal=kVal,
    final TiVal=TiVal,
    final TdVal=TdVal,
    final controllerTypeDam=controllerTypeDam,
    final kDam=kDam,
    final TiDam=TiDam,
    final TdDam=TdDam,
    final dTDisZonSetMax=dTDisZonSetMax,
    final TDisMin=TDisMin,
    V_flow_nominal=max(VDisCooSetMax_flow, VDisHeaSetMax_flow))
    "Damper and valve controller"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SystemRequests
    sysReq(
    final samplePeriod=samplePeriod,
    final have_heaWatCoi=have_heaWatCoi,
    final have_heaPla=have_heaPla,
    final errTZonCoo_1=errTZonCoo_1,
    final errTZonCoo_2=errTZonCoo_2,
    final errTDis_1=errTDis_1,
    final errTDis_2=errTDis_2,
    final durTimTem=durTimTem,
    final durTimFlo=durTimFlo,
    final durTimDisAir=durTimDisAir) "Number of system requests"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conHeaLoo(
    final controllerType=controllerTypeHea,
    final k=kHea,
    final Ti=TiHea,
    final Td=TdHea,
    final yMax=1,
    final yMin=0) "Heating loop signal"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conCooLoo(
    final controllerType=controllerTypeCoo,
    final k=kCoo,
    final Ti=TiCoo,
    final Td=TdCoo,
    final yMax=1,
    final yMin=0,
    reverseActing=false) "Cooling loop signal"

protected
  Buildings.Controls.OBC.CDL.Integers.Equal isUnOcc
    "Output true if unoccupied"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conIntUn(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.unoccupied)
    "Constant signal for unoccupied mode"
  Buildings.Controls.OBC.CDL.Logical.Not isNotUn
  "Output true if not unoccupied"

equation
  connect(sysReq.TZonCooSet, TZonCooSet)
  connect(sysReq.TZon, TZon)
  connect(sysReq.VDisSet_flow, damVal.VDisSet_flow)
  connect(sysReq.VDis_flow, VDis_flow)
  connect(sysReq.TDisHeaSet, damVal.TDisHeaSet)
  connect(damVal.yDam, yDam)
  connect(damVal.yHeaVal, yVal)
  connect(damVal.VDis_flow, VDis_flow)
  connect(damVal.TDis, TDis)
  connect(sysReq.TDis, TDis)
  connect(damVal.yHeaVal, sysReq.uHeaVal)
  connect(TZon, damVal.TZon)
  connect(damVal.TSup, TSupAHU)
  connect(actAirSet.VActCooMax_flow, damVal.VActCooMax_flow)
  connect(actAirSet.VActCooMin_flow, damVal.VActCooMin_flow)
  connect(actAirSet.VActMin_flow, damVal.VActMin_flow)
  connect(actAirSet.VActHeaMin_flow, damVal.VActHeaMin_flow)
  connect(actAirSet.VActHeaMax_flow, damVal.VActHeaMax_flow)
  connect(damVal.THeaSet, TZonHeaSet)
  connect(actAirSet.VActCooMax_flow, damVal.VActCooMax_flow)
  connect(actAirSet.VActCooMin_flow, damVal.VActCooMin_flow)
  connect(actAirSet.VActMin_flow, damVal.VActMin_flow)
  connect(actAirSet.VActHeaMin_flow, damVal.VActHeaMin_flow)
  connect(actAirSet.VActHeaMax_flow, damVal.VActHeaMax_flow)
  connect(actAirSet.uOpeMod, uOpeMod)
  connect(sysReq.yZonTemResReq, yZonTemResReq)
  connect(sysReq.yZonPreResReq, yZonPreResReq)
  connect(actAirSet.ppmCO2, ppmCO2)
  connect(actAirSet.nOcc, nOcc)
  connect(actAirSet.uWin, uWin)
  connect(TZonHeaSet, conHeaLoo.u_s)
  connect(TZonCooSet, conCooLoo.u_s)
  connect(TZon, conHeaLoo.u_m)
  connect(TZon, conCooLoo.u_m)
  connect(conCooLoo.y, damVal.uCoo)
  connect(conHeaLoo.y, damVal.uHea)
  connect(conCooLoo.y, sysReq.uCoo)
  connect(damVal.uOpeMod, uOpeMod)
  connect(conIntUn.y, isUnOcc.u1)
  connect(uOpeMod, isUnOcc.u2)
  connect(isUnOcc.y, isNotUn.u)
  connect(isNotUn.y, conCooLoo.trigger)
  connect(isNotUn.y, conHeaLoo.trigger)
  connect(sysReq.yDam_actual,yDam_actual)

  connect(sysReq.yHeaValResReq, yHeaValResReq)
  connect(sysReq.yHeaPlaReq, yHeaPlaReq)
end Controller;


Control sequences for terminal units

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1;
package TerminalUnits "Control sequences for terminal units"
end TerminalUnits;


Output signals for controlling VAV reheat box damper and valve position. This sequence sets the damper and valve position for VAV reheat terminal unit.
The implementation is according to ASHRAE Guideline 36 (G36), PART 5.E.6. The
calculation is done following the steps below.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat;
block DamperValves
  "Output signals for controlling VAV reheat box damper and valve position"

  parameter Real dTDisZonSetMax(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=11
    "Zone maximum discharge air temperature above heating setpoint";
  parameter Real TDisMin(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=283.15
    "Lowest discharge air temperature";

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeVal=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"

  parameter Real kVal(final unit="1/K")=0.5
    "Gain of controller for valve control"

  parameter Real TiVal(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for valve control"

  parameter Real TdVal(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for valve control"

  parameter Boolean have_pressureIndependentDamper = true
    "True: the VAV damper is pressure independent (with built-in flow controller)"

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeDam=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"

  parameter Real kDam(final unit="1")=0.5
    "Gain of controller for damper control"

  parameter Real TiDam(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for damper control"

  parameter Real TdDam(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for damper control"

  parameter Real V_flow_nominal(
    final unit="m3/s",
    final quantity="VolumeFlowRate",
    final min=1E-10)
    "Nominal volume flow rate, used to normalize control error"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uHea(
    final min=0,
    final max=1,
    final unit="1")
    "Heating control signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCoo(
    final min=0,
    final max=1,
    final unit="1")
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active cooling maximum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActCooMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active cooling minimum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active minimum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActHeaMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active heating minimum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActHeaMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active heating maximum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") if not have_pressureIndependentDamper
    "Measured discharge airflow rate airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSup(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Supply air temperature from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final max=1,
    final unit="1") "Signal for VAV damper"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yHeaVal(
    final min=0,
    final max=1,
    final unit="1")
    "Reheater valve position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VDisSet_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Discharge airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TDisHeaSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Discharge airflow setpoint temperature for heating"

  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not not4 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Check if current zone state is deadband"
  Buildings.Controls.OBC.CDL.Logical.And and4 "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Line lin
    "Active airflow setpoint for cooling"
  Buildings.Controls.OBC.CDL.Reals.Line conTDisHeaSet
    "Discharge air temperature for heating"
  Buildings.Controls.OBC.CDL.Reals.Line lin3
    "Active airflow setpoint for heating"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conVal(
    final controllerType=controllerTypeVal,
    final k=kVal,
    final Ti=TiVal,
    final Td=TdVal,
    final yMax=1,
    final yMin=0,
    u_s(final unit="K", displayUnit="degC"),
    u_m(final unit="K", displayUnit="degC"))
    "Hot water valve controller"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conDam(
    final controllerType=controllerTypeDam,
    final k=kDam,
    final Ti=TiDam,
    final Td=TdDam,
    final yMax=1,
    final yMin=0,
    final y_reset=0) if not have_pressureIndependentDamper
    "Damper position controller"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Output active cooling airflow according to cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1 "Output active airflow when it is in deadband state"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2 "Acitive heating airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    "Output active heating airflow according to heating control signal"
  Buildings.Controls.OBC.CDL.Reals.Switch swi5 "Output active cooling airflow "

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer1(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer2(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer3(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer6(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conOne(
    final k=1) "Constant one"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conOne2(
    final k=1) "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conHal(
    final k=0.5) "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conHal1(
    final k=0.5) "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=dTDisZonSetMax)
    "Maximum heating discharge temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=2.8)
    "Zone temperature pluTZonSets 2.8 degC"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys2(
    final uHigh=0.05,
    final uLow=0.01)
    "Check if cooling control signal is greater than zero"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys3(
    final uHigh=0.05,
    final uLow=0.01)
    "Check if heating control signal is greater than 0"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys4(
    final uLow=TDisMin - 0.1,
    final uHigh=TDisMin + 0.1)
    "Check if discharge air temperature is greater than lowest discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys6(
    final uLow=-0.1,
    final uHigh=0.1)
    "Check if supply air temperature is greater than room temperature"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys7(
    final uLow=-0.1,
    final uHigh=0.1)
    "Check if discharge air temperature is greater than room temperature plus 2.8 degC"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate temperature difference between discharge air and room plus 2.8 degC"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    "Calculate temperature difference between AHU supply air and room "
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truHol2(
    final falseHoldDuration=0, trueHoldDuration=600)
    "Check if the true input holds for certain time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel3(delayTime=600)
    "Check if the true input holds for certain time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel4(delayTime=600)
    "Check if the true input holds for certain time"
  Buildings.Controls.OBC.CDL.Integers.Equal isUno "Output true if the operation mode is unoccupied"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant unOcc(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.unoccupied)
    "Constant signal for unoccupied mode"
  Buildings.Controls.OBC.CDL.Reals.Switch watValPosUno "Output hot water valve position"
  Buildings.Controls.OBC.CDL.Reals.Switch damPosUno "Output damper position"
  Buildings.Controls.OBC.CDL.Logical.Not not5 "Negation of input signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant lowDisAirTem(
    final k=TDisMin)
    "Lowest allowed discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi6
    "Output hot water valve position in case of low discharge air temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or2 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not not3 "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3
    "Output hot water valve position in case of low discharge air temperature"
  Buildings.Controls.OBC.CDL.Logical.Not not6 "Negation of input signal"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "Check if it is not in heating mode and the discharge temperature is not too low"
  Buildings.Controls.OBC.CDL.Reals.Add add3 "Active airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Add add4 "Active airflow set point"
  Buildings.Controls.OBC.CDL.Reals.Divide VDis_flowNor
    if not have_pressureIndependentDamper
    "Normalized discharge volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant nomFlow(
    final k=V_flow_nominal)
    "Nominal volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.Divide VDisSet_flowNor
    "Normalized setpoint for discharge volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(final k=1)
    if have_pressureIndependentDamper
    "Block that can be disabled so remove the connection"

equation
  connect(uCoo, lin.u)
  connect(conZer.y, lin.x1)
  connect(VActCooMin_flow, lin.f1)
  connect(conOne.y, lin.x2)
  connect(VActCooMax_flow, lin.f2)
  connect(uCoo, hys2.u)
  connect(conZer1.y, swi.u3)
  connect(VActMin_flow, swi1.u1)
  connect(and2.y, swi1.u2)
  connect(conZer2.y, swi1.u3)
  connect(uHea, hys3.u)
  connect(conZer3.y, conTDisHeaSet.x1)
  connect(TSup, conTDisHeaSet.f1)
  connect(uHea, conTDisHeaSet.u)
  connect(conHal.y, conTDisHeaSet.x2)
  connect(addPar.y, conTDisHeaSet.f2)
  connect(THeaSet, addPar.u)
  connect(uHea, lin3.u)
  connect(conHal1.y, lin3.x1)
  connect(conOne2.y, lin3.x2)
  connect(VActHeaMax_flow, lin3.f2)
  connect(VActHeaMin_flow, lin3.f1)
  connect(TZon, addPar1.u)
  connect(lin3.y, swi2.u1)
  connect(VActHeaMin_flow, swi2.u3)
  connect(TDis, hys4.u)
  connect(swi2.y, swi4.u1)
  connect(conZer6.y, swi4.u3)
  connect(VActMin_flow, swi5.u1)
  connect(and4.y, swi5.u2)
  connect(lin.y, swi5.u3)
  connect(swi5.y, swi.u1)
  connect(hys4.y, not4.u)
  connect(TSup, sub2.u1)
  connect(TZon, sub2.u2)
  connect(sub2.y, hys6.u)
  connect(hys6.y, and4.u2)
  connect(conTDisHeaSet.y, sub1.u1)
  connect(addPar1.y, sub1.u2)
  connect(sub1.y, hys7.u)
  connect(conTDisHeaSet.y, TDisHeaSet)
  connect(hys3.y, truHol2.u)
  connect(truHol2.y, swi4.u2)
  connect(hys2.y, truDel4.u)
  connect(truDel4.y, and4.u1)
  connect(truDel4.y, swi.u2)
  connect(truHol2.y, not2.u)
  connect(truDel4.y, not1.u)
  connect(not1.y, and2.u1)
  connect(not2.y, and2.u2)
  connect(conVal.u_m, TDis)
  connect(hys7.y, swi2.u2)
  connect(unOcc.y, isUno.u1)
  connect(isUno.u2, uOpeMod)
  connect(isUno.y, watValPosUno.u2)
  connect(conZer2.y, watValPosUno.u1)
  connect(watValPosUno.y, yHeaVal)
  connect(conZer2.y, damPosUno.u1)
  connect(conDam.y, damPosUno.u3)
  connect(damPosUno.y, yDam)
  connect(isUno.y, damPosUno.u2)
  connect(isUno.y, not5.u)
  connect(not5.y, conDam.trigger)
  connect(truHol2.y, or2.u2)
  connect(truDel3.y, not3.u)
  connect(not3.y, or2.u1)
  connect(or2.y, swi6.u2)
  connect(conTDisHeaSet.y, swi6.u1)
  connect(swi6.u3, lowDisAirTem.y)
  connect(swi3.y, watValPosUno.u3)
  connect(truHol2.y, not6.u)
  connect(not6.y, and1.u2)
  connect(and1.y, swi3.u2)
  connect(conVal.y, swi3.u3)
  connect(swi3.u1, conZer2.y)
  connect(not3.y, and1.u1)
  connect(not4.y, truDel3.u)
  connect(not5.y, conVal.trigger)
  connect(swi6.y, conVal.u_s)
  connect(swi1.y, add4.u1)
  connect(swi4.y, add4.u2)
  connect(swi.y, add3.u1)
  connect(add4.y, add3.u2)
  connect(add3.y, VDisSet_flow)
  connect(VDis_flow, VDis_flowNor.u1)
  connect(nomFlow.y, VDis_flowNor.u2)
  connect(VDis_flowNor.y, conDam.u_m)
  connect(nomFlow.y, VDisSet_flowNor.u2)
  connect(add3.y, VDisSet_flowNor.u1)
  connect(VDisSet_flowNor.y, conDam.u_s)
  connect(VDisSet_flowNor.y, gai.u)
  connect(gai.y, damPosUno.u3)
end DamperValves;


Sequences for VAV reheat terminal unit

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits;
package Reheat "Sequences for VAV reheat terminal unit"
end Reheat;