Supply air set point for single zone VAV system. Block that outputs the set points for the supply air temperature for
cooling, heating and economizer control, and the fan speed for a single zone VAV system.
The implementation is according to the Section 5.18.4 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints;
block Supply "Supply air set point for single zone VAV system"

  parameter Real TSup_max(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Maximum supply air temperature for heating"
  parameter Real TSup_min(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Minimum supply air temperature for cooling"
  parameter Real TSupDew_max(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Maximum supply air dew-point temperature. It's typically only needed in humid type “A” climates. A typical value is 17°C.
    For mild and dry climates, a high set point (e.g. 24°C) should be entered for maximum efficiency"
  parameter Real TSupDea_min(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=294.15
    "Minimum supply temperature when it is in deadband state"
  parameter Real TSupDea_max(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Maximum supply temperature when it is in deadband state"
  parameter Real maxHeaSpe(
    final min=0,
    final max=1,
    final unit="1")
    "Maximum fan speed for heating"
  parameter Real maxCooSpe(
    final min=0,
    final max=1,
    final unit="1")
    "Maximum fan speed for cooling"
  parameter Real minSpe(
    final min=0,
    final max=1,
    final unit="1")
    "Minimum fan speed"
  parameter Real looHys(
    final unit="1")=0.01
    "Loop output hysteresis below which the output will be seen as zero"
  parameter Real temPoiOne(
    final unit="1",
    final min=0,
    final max=1)=0.5
    "Point 1 on x-axis of control map for temperature control, when it is in heating state"
  parameter Real temPoiTwo(
    final unit="1",
    final min=0,
    final max=1)=0.25
    "Point 2 on x-axis of control map for temperature control, when it is in cooling state"
  parameter Real temPoiThr(
    final unit="1",
    final min=0,
    final max=1)=0.5
    "Point 3 on x-axis of control map for temperature control, when it is in cooling state"
  parameter Real temPoiFou(
    final unit="1",
    final min=0,
    final max=1)=0.75
    "Point 4 on x-axis of control map for temperature control, when it is in cooling state"
  parameter Real spePoiOne(
    final unit="1",
    final min=0,
    final max=1)=0.5
    "Point 1 on x-axis of control map for speed control, when it is in heating state"
  parameter Real spePoiTwo(
    final unit="1",
    final min=0,
    final max=1)=0.25
    "Point 2 on x-axis of control map for speed control, when it is in cooling state"
  parameter Real spePoiThr(
    final unit="1",
    final min=0,
    final max=1)=0.5
    "Point 3 on x-axis of control map for speed control, when it is in cooling state"
  parameter Real spePoiFou(
    final unit="1",
    final min=0,
    final max=1)=0.75
    "Point 4 on x-axis of control map for speed control, when it is in cooling state"

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "AHU operation mode status signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Outdoor air temperature"
  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 TCooSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Cooling setpoints for zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Heating setpoints for zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final min=0,
    final max=1,
    final unit="1") "Fan speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1SupFan
    "Supply fan commanded status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TSupHeaEcoSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Temperature setpoint for heating coil and for economizer"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TSupCooSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Cooling supply air temperature setpoint"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant fanOff(
    final k=0)
    "Fan off status"
  Buildings.Controls.OBC.CDL.Reals.Switch fanSpe "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.LimitSlewRate ramLim(
    final raisingSlewRate=1/600,
    final Td=60)
    "Prevent changes in fan speed of more than 10% per minute"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxDewPoi(
    final k=TSupDew_max)
    "Maximum supply air dew-point temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=-1)
    "Maximum supply dewpoint temperature minus threshold"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=-6)
    "Zone temperature minus threshold"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar2(
    final p=0.5)
    "Zone temperature plus threshold"
  Buildings.Controls.OBC.CDL.Reals.Min endPoiTwo
    "End point two for specifying medium fan speed"
  Buildings.Controls.OBC.CDL.Reals.Min endPoiOne
    "End point one for specifying medium fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minFanSpe(
    final k=minSpe)
    "Minimum fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxCooFanSpe(
    final k=maxCooSpe)
    "Maximum fan speed for cooling"
  Buildings.Controls.OBC.CDL.Reals.Line medFanSpe
    "Medium fan speed"
  Buildings.Controls.OBC.CDL.Reals.Average aveZonSet
    "Average of the zone heating and cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Limiter lim(
    final uMax=TSupDea_max,
    final uMin=TSupDea_min)
    "Limiter that outputs the dead band value for the supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(
    final k=1)
    "Constant one"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(
    final k=0)
    "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Line heaFanSpe
    "Fan speed when it is in heating state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant speOnePoi(
    final k=spePoiOne)
    "Speed control point one in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxHeaFanSpe(
    final k=maxHeaSpe)
    "Maximum fan speed for heating"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant speTwoPoi(
    final k=spePoiTwo)
    "Speed control point two in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant speThrPoi(
    final k=spePoiThr)
    "Speed control point three in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant speFouPoi(
    final k=spePoiFou)
    "Speed control point four in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Line cooFanSpe1
    "Fan speed when it is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.Line cooFanSpe2
    "Fan speed when it is in cooling mode"
  Buildings.Controls.OBC.CDL.Reals.Max spe
    "Fan speed"
  Buildings.Controls.OBC.CDL.Reals.Line heaSupTem
    "Supply air temperature when it is in heating state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant temOnePoi(
    final k=temPoiOne)
    "Temperature control point one in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSupTem(
    final k=TSup_max)
    "Highest heating supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant temTwoPoi(
    final k=temPoiTwo)
    "Temperature control point two in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Line cooSupTem
    "Supply air temperature when it is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supCooTem(
    final k=TSup_min)
    "Cooling supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar3(
    final p=-1)
    "Minimum cooling supply temperature minus threshold"
  Buildings.Controls.OBC.CDL.Reals.Line cooSupTem1
    "Supply air temperature when it is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant temThrPoi(
    final k=temPoiThr)
    "Temperature control point three in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant temFouPoi(
    final k=temPoiFou)
    "Temperature control point four in x-axis of control map"
  Buildings.Controls.OBC.CDL.Reals.Switch cooFan
    "Fan speed when it is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold heaSta(
    final t=looHys,
    final h=0.8*looHys)
    "Check if it is in heating state"
  Buildings.Controls.OBC.CDL.Reals.Switch supTemSet
    "Supply temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch supTemSet1
    "Supply temperature setpoint"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant unoMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.unoccupied)
    "Unoccupied mode index"
  Buildings.Controls.OBC.CDL.Integers.Equal isUnoMod
    "Check if it is in unoccupied mode"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Greater gre(
    final h=spePoiFou - spePoiThr)
    "Check setpoint section"

equation
  connect(unoMod.y, isUnoMod.u1)
  connect(uOpeMod, isUnoMod.u2)
  connect(isUnoMod.y, fanSpe.u2)
  connect(fanOff.y, fanSpe.u1)
  connect(fanSpe.y, ramLim.u)
  connect(maxDewPoi.y, addPar.u)
  connect(addPar.y, endPoiTwo.u1)
  connect(addPar1.y, endPoiTwo.u2)
  connect(addPar2.y, endPoiOne.u1)
  connect(maxDewPoi.y, endPoiOne.u2)
  connect(endPoiTwo.y, medFanSpe.x1)
  connect(maxCooFanSpe.y, medFanSpe.f1)
  connect(endPoiOne.y, medFanSpe.x2)
  connect(minFanSpe.y, medFanSpe.f2)
  connect(TOut, medFanSpe.u)
  connect(TCooSet, aveZonSet.u1)
  connect(THeaSet, aveZonSet.u2)
  connect(aveZonSet.y, lim.u)
  connect(uHea, heaFanSpe.u)
  connect(speTwoPoi.y, cooFanSpe1.x1)
  connect(minFanSpe.y, cooFanSpe1.f1)
  connect(speThrPoi.y, cooFanSpe1.x2)
  connect(medFanSpe.y, cooFanSpe1.f2)
  connect(uCoo, cooFanSpe1.u)
  connect(speFouPoi.y, cooFanSpe2.x1)
  connect(medFanSpe.y, cooFanSpe2.f1)
  connect(one.y, cooFanSpe2.x2)
  connect(maxCooFanSpe.y, cooFanSpe2.f2)
  connect(uCoo, cooFanSpe2.u)
  connect(heaFanSpe.y, spe.u1)
  connect(uHea, heaSupTem.u)
  connect(speOnePoi.y, heaFanSpe.x1)
  connect(minFanSpe.y, heaFanSpe.f1)
  connect(one.y, heaFanSpe.x2)
  connect(maxHeaFanSpe.y, heaFanSpe.f2)
  connect(zer.y, heaSupTem.x1)
  connect(lim.y, heaSupTem.f1)
  connect(temOnePoi.y, heaSupTem.x2)
  connect(maxSupTem.y, heaSupTem.f2)
  connect(zer.y, cooSupTem.x1)
  connect(lim.y, cooSupTem.f1)
  connect(temTwoPoi.y, cooSupTem.x2)
  connect(supCooTem.y, addPar3.u)
  connect(addPar3.y, cooSupTem.f2)
  connect(temThrPoi.y, cooSupTem1.x1)
  connect(lim.y, cooSupTem1.f1)
  connect(temFouPoi.y, cooSupTem1.x2)
  connect(supCooTem.y, cooSupTem1.f2)
  connect(cooFanSpe1.y, cooFan.u1)
  connect(cooFanSpe2.y, cooFan.u3)
  connect(cooFan.y, spe.u2)
  connect(uHea, heaSta.u)
  connect(heaSta.y, supTemSet.u2)
  connect(heaSupTem.y, supTemSet.u1)
  connect(cooSupTem.y, supTemSet.u3)
  connect(heaSta.y, supTemSet1.u2)
  connect(cooSupTem1.y, supTemSet1.u3)
  connect(heaSupTem.y, supTemSet1.u1)
  connect(spe.y, fanSpe.u3)
  connect(ramLim.y, y)
  connect(supTemSet.y, TSupHeaEcoSet)
  connect(supTemSet1.y, TSupCooSet)
  connect(uCoo, cooSupTem.u)
  connect(uCoo, cooSupTem1.u)
  connect(TZon, addPar1.u)
  connect(TZon, addPar2.u)
  connect(isUnoMod.y, not1.u)
  connect(not1.y, y1SupFan)
  connect(speFouPoi.y, gre.u1)
  connect(uCoo, gre.u2)
  connect(gre.y, cooFan.u2)
end Supply;


Validation of cooling coil model. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.CoolingCoil.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model CoolingCoil "Validation of cooling coil model"
  final parameter Real TSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=291.15
    "Supply air temperature setpoint";
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.CoolingCoil cooCoi(
    final controllerTypeCooCoi=Buildings.Controls.OBC.CDL.Types.SimpleController.P,
    final kCooCoi=1) "Cooling coil controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TSup(
    final height=4,
    final offset=TSupSet - 2,
    final duration=3600*8) "Measured supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSupSetSig(
    final k=TSupSet)
    "Supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanStatus(
    final k=true)
    "Fan is on"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse zonSta(
    final offset=2,
    final period=3600*2)
    "Zone state"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Real to integer conversion"

equation
  connect(TSup.y, cooCoi.TAirSup)
  connect(TSupSetSig.y, cooCoi.TSupCooSet)
  connect(fanStatus.y, cooCoi.u1SupFan)
  connect(zonSta.y, reaToInt.u)
  connect(reaToInt.y, cooCoi.uZonSta)
end CoolingCoil;


Validate model for implementing freeze protection. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.FreezeProtection
for air handling unit serving single zone.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model FreezeProtection
  "Validate model for implementing freeze protection"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.FreezeProtection
    frePro(final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefDamper,
      freSta=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.No_freeze_stat)
    "Freeze protection control"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos(
    final height=0.5,
    final offset=0.1,
    final duration=3600) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMin(
    final k=0.1)
    "Outdoor air damper minimum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp heaCoiPos(
    final height=0.49,
    final offset=0.5,
    final duration=3000) "Heating coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp retDamPos(
    final height=0.2,
    final offset=0.7,
    final duration=3600) "Return air damper position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse freRes(
    final width=0.95,
    final period=3600)
    "Freeze protection reset"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe(
    final height=0.2,
    final offset=0.5,
    final duration=3600) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooCoiPos(
    final height=0.2,
    final offset=0.5,
    final duration=3600) "Cooling coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTem(
    final height=-4,
    final offset=273.15 + 6,
    final duration=3600) "Supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp mixTem(
    final height=-5,
    final offset=273.15 + 8,
    final duration=3600) "Mixed air temperature"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=0.05)
    "Supply fan command on"

equation
  connect(freRes.y, not1.u)
  connect(outDamPosMin.y,frePro. uOutDamPosMin)
  connect(outDamPos.y, frePro.uOutDam)
  connect(heaCoiPos.y,frePro. uHeaCoi)
  connect(retDamPos.y, frePro.uRetDam)
  connect(supTem.y, frePro.TAirSup)
  connect(not1.y, frePro.u1SofSwiRes)
  connect(supFanSpe.y, frePro.uSupFan)
  connect(cooCoiPos.y,frePro. uCooCoi)
  connect(mixTem.y, frePro.TAirMix)
  connect(supFanSpe.y, greThr.u)
  connect(greThr.y, frePro.u1SupFan)
end FreezeProtection;


Validate model for disabling freeze protection. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.FreezeProtection
for air handling unit serving single zones, when disabling the freeze protection.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model FreezeProtection_Disable
  "Validate model for disabling freeze protection"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.FreezeProtection
    frePro(
    final have_frePro=false)
    "Freeze protection control"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos(
    final height=0.5,
    final offset=0.1,
    final duration=3600) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp heaCoiPos(
    final height=0.46,
    final offset=0.5,
    final duration=3600) "Heating coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp retDamPos(
    final height=0.2,
    final offset=0.7,
    final duration=3600) "Return air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe(
    final height=0.2,
    final offset=0.5,
    final duration=3600) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooCoiPos(
    final height=0.2,
    final offset=0.5,
    final duration=3600) "Cooling coil position"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final h=0.01)
    "Check if the supply fan is proven on"
equation
  connect(outDamPos.y, frePro.uOutDam)
  connect(heaCoiPos.y,frePro. uHeaCoi)
  connect(retDamPos.y, frePro.uRetDam)
  connect(supFanSpe.y, frePro.uSupFan)
  connect(cooCoiPos.y,frePro. uCooCoi)
  connect(supFanSpe.y, greThr.u)
  connect(greThr.y, frePro.u1SupFan)
end FreezeProtection_Disable;


Validate block for specifying zone mode and setpoints. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ModeAndSetPoints.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model ModeAndSetPoints
  "Validate block for specifying zone mode and setpoints"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ModeAndSetPoints
    modSetPoi(
    final have_winSen=false,
    final have_occSen=true,
    have_locAdj=true,
    sepAdj=true,
    ignDemLim=false) "Operating mode and temperature setpoints"

  Buildings.Controls.OBC.CDL.Reals.Sources.Sin cooSetAdj(
    final freqHz=1/28800) "Cooling setpoint adjustment"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin heaSetAdj(
    final freqHz=1/28800,
    final amplitude=0.5)
    "Heating setpoint adjustment"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant cooDemLimLev(
    final k=0)
    "Cooling demand limit level"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant heaDemLimLev(
    final k=0)
    "Heating demand limit level"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(
    final period=14400,
    final shift=1200)
    "Generate signal indicating window status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse occSta(
    final period=14400,
    final width=0.95)
    "Generate signal indicating occupancy status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerAdj(
    final k=0) "Zero adjustment"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Switch to zero adjustment when window is open"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Switch to zero adjustment when window is open"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooDowTim(
    final k=1800)
    "Cooling down time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warUpTim(
    final k=1800)
    "Warm-up time"
  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"
  Buildings.Controls.SetPoints.OccupancySchedule occSch "Occupancy schedule"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSetOcc(
    final k=293.15)
    "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TCooSetOcc(
    final k=297.15)
    "Occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSetUno(
    final k=285.15)
    "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TCooSetUno(
    final k=303.15) "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.Not winOpe "Window is open"
equation
  connect(zerAdj.y, swi2.u1)
  connect(zerAdj.y, swi1.u1)
  connect(cooSetAdj.y, swi2.u3)
  connect(heaSetAdj.y, swi1.u3)
  connect(cooDowTim.y, modSetPoi.cooDowTim)
  connect(warUpTim.y, modSetPoi.warUpTim)
  connect(ramp2.y, sin2.u)
  connect(sin2.y, gai.u)
  connect(gai.y, zonTem.u)
  connect(zonTem.y, modSetPoi.TZon)
  connect(occSch.tNexOcc, modSetPoi.tNexOcc)
  connect(occSch.occupied, modSetPoi.u1Occ)
  connect(swi2.y, modSetPoi.cooSetAdj)
  connect(swi1.y, modSetPoi.heaSetAdj)
  connect(occSta.y, modSetPoi.u1OccSen)
  connect(cooDemLimLev.y, modSetPoi.uCooDemLimLev)
  connect(heaDemLimLev.y, modSetPoi.uHeaDemLimLev)
  connect(THeaSetOcc.y,modSetPoi.TOccHeaSet)
  connect(TCooSetOcc.y,modSetPoi.TOccCooSet)
  connect(TCooSetUno.y,modSetPoi.TUnoCooSet)
  connect(THeaSetUno.y,modSetPoi.TUnoHeaSet)
  connect(winSta.y, winOpe.u)
  connect(winOpe.y, swi2.u2)
  connect(winOpe.y, swi1.u2)
end ModeAndSetPoints;


Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints;
package Validation "Collection of validation models"
end Validation;


Validate model for calculating the plant requests. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.PlantRequests
for air handling unit serving single zone.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model PlantRequests
  "Validate model for calculating the plant requests"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.PlantRequests plaReq
    "Calculate plant request"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.PlantRequests plaReq1(
    heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.None)
    "Calculate plant request"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTem(
    final height=8,
    final offset=273.15 + 15,
    final duration=3600) "Supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTemSet(
    final height=6,
    final offset=273.15 + 14.5,
    final duration=3600) "Supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooCoi(
    final height=-0.3,
    final offset=0.96,
    final duration=3600,
    startTime=1000) "Cooling coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp heaCoi(
    final height=-0.3,
    final offset=0.96,
    final duration=3600,
    startTime=1000) "Heating coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTem1(
    final height=8,
    final offset=273.15 + 12,
    final duration=3600) "Cooling supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTemSet1(
    final height=15,
    final offset=273.15 + 20,
    final duration=3600) "Supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooCoi1(
    final k=0) "Cooling coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supTem2(
    final height=7,
    final offset=273.15 + 13,
    final duration=3600) "Supply air temperature"

equation
  connect(supTem.y, plaReq1.TAirSup)
  connect(cooCoi.y, plaReq1.uCooCoi_actual)
  connect(supTem1.y, plaReq.TAirSup)
  connect(cooCoi1.y, plaReq.uCooCoi_actual)
  connect(heaCoi.y, plaReq.uHeaCoi_actual)
  connect(supTemSet1.y, plaReq.TSupCoo)
  connect(supTemSet.y, plaReq1.TSupCoo)
  connect(supTem2.y, plaReq.TSupHeaEco)
end PlantRequests;


Validation of relief damper control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefDamper.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model ReliefDamper "Validation of relief damper control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefDamper relDam(final
      relDam_min=0.1, final relDam_max=0.6) "Relief damper controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamMin(
    final height=0.1,
    final offset=0.1,
    final duration=3600)
    "Outdoor damper minimum position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse fanStatus(final width=0.8,
    final period=3600)
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDam(
    final height=0.6,
    final offset=0.2,
    final duration=3600)
    "Outdoor damper position"

equation
  connect(fanStatus.y, relDam.u1SupFan)
  connect(outDam.y, relDam.uOutDam)
  connect(outDamMin.y, relDam.uOutDam_min)
end ReliefDamper;


Validate model for controlling relief fan. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFan
for controlling relief fan that is part of AHU.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model ReliefFan "Validate model for controlling relief fan"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFan
    relFanCon(
    final k=0.5) "Open relief damper"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFan
    relFanCon1 "Turning on relief fan"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFan
    relFanCon2 "Turning off relief fan"

  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFan(final width=0.8,
      final period=3600)
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpBui(
    final height=40,
    final offset=0,
    final duration=1800) "Building static presure"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpBui1(
    final height=-15,
    final offset=20,
    final duration=1800,
    startTime=1800)
    "Building static presure"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant supFan1(
    final k=true)
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpBui2(
    final height=3,
    final offset=11,
    final duration=1800)
    "Building static presure"

equation
  connect(dpBui.y, relFanCon1.dpBui)
  connect(dpBui1.y, relFanCon2.dpBui)
  connect(supFan.y, relFanCon.u1SupFan)
  connect(supFan1.y, relFanCon1.u1SupFan)
  connect(supFan1.y, relFanCon2.u1SupFan)
  connect(dpBui2.y, relFanCon.dpBui)
end ReliefFan;


Validate model for calculating relief fans control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFanGroup
for relief fans for systems with multiple zones.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model ReliefFanGroup
  "Validate model for calculating relief fans control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFanGroup
    relFanCon(final k=0.5) "Relief damper control, with staging up fans"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFanGroup
    relFanCon1 "Relief damper control, with staging up fans and the fan alarm"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReliefFanGroup
    relFanCon2 "Relief damper control, with the staging up and down fans"

  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFan1(
    final width=1,
    final period=4000)
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpBui(
    final height=40,
    final offset=0,
    final duration=1800) "Building static presure"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFan2(
    final width=1,
    final period=4000,
    shift=600) "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr[4](
    final t=fill(0.01, 4))
    "Check if the relief fan is proven on"
  Buildings.Controls.OBC.CDL.Logical.Pre pre[4] "Return relief fan status"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1[4](
    final t=fill(0.01, 4))
    "Check if the relief fan is proven on"
  Buildings.Controls.OBC.CDL.Logical.Pre pre1[4] "Return relief fan status"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt[4](
    final k=fill(0, 4)) "Constant zero"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    final amplitude=2,
    final period=3600,
    final offset=0) "Fan 1 alarm level"
  Buildings.Controls.OBC.CDL.Discrete.ZeroOrderHold zerOrdHol[4](
    final samplePeriod=fill(20, 4))
    "Zero order hold"
  Buildings.Controls.OBC.CDL.Discrete.ZeroOrderHold zerOrdHol1[4](
    final samplePeriod=fill(20, 4))
    "Zero order hold"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2[4](
    final t=fill(0.01, 4))
    "Check if the relief fan is proven on"
  Buildings.Controls.OBC.CDL.Logical.Pre pre2[4] "Return relief fan status"
  Buildings.Controls.OBC.CDL.Discrete.ZeroOrderHold zerOrdHol2[4](
    final samplePeriod=fill(20, 4))
    "Zero order hold"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpBui1(
    final height=-15,
    final offset=20,
    final duration=1800,
    startTime=1800)
    "Building static presure"

equation
  connect(dpBui.y, relFanCon.dpBui)
  connect(dpBui.y, relFanCon1.dpBui)
  connect(greThr.y, pre.u)
  connect(supFan1.y, relFanCon.u1SupFan[1])
  connect(supFan2.y, relFanCon.u1SupFan[2])
  connect(supFan1.y, relFanCon1.u1SupFan[1])
  connect(supFan2.y, relFanCon1.u1SupFan[2])
  connect(pre.y, relFanCon.u1RelFan)
  connect(greThr1.y, pre1.u)
  connect(pre1.y, relFanCon1.u1RelFan)
  connect(conInt.y, relFanCon.uRelFanAla)
  connect(conInt[1].y, relFanCon1.uRelFanAla[2])
  connect(conInt[2].y, relFanCon1.uRelFanAla[3])
  connect(conInt[3].y, relFanCon1.uRelFanAla[4])
  connect(intPul.y, relFanCon1.uRelFanAla[1])
  connect(relFanCon.yRelFan, zerOrdHol.u)
  connect(zerOrdHol.y, greThr.u)
  connect(relFanCon1.yRelFan, zerOrdHol1.u)
  connect(zerOrdHol1.y, greThr1.u)
  connect(greThr2.y,pre2. u)
  connect(pre2.y,relFanCon2.u1RelFan)
  connect(relFanCon2.yRelFan, zerOrdHol2.u)
  connect(zerOrdHol2.y,greThr2. u)
  connect(dpBui1.y, relFanCon2.dpBui)
  connect(supFan1.y, relFanCon2.u1SupFan[1])
  connect(supFan2.y, relFanCon2.u1SupFan[2])
  connect(conInt.y, relFanCon2.uRelFanAla)
end ReliefFanGroup;


Validation of return fan control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReturnFan.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model ReturnFan "Validation of return fan control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.ReturnFan retFan
    "Cooling coil controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe(
    final height=0.7,
    final offset=0.2,
    final duration=3600) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse fanStatus(
    final period=3600)
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Multiply mul
    "Fan speed should be zero when it is disabled"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea
    "Boolean to real"

equation
  connect(fanStatus.y, retFan.u1SupFan)
  connect(fanStatus.y, booToRea.u)
  connect(booToRea.y, mul.u2)
  connect(supFanSpe.y, mul.u1)
  connect(mul.y, retFan.uSupFan_actual)
end ReturnFan;


Validation model for outdoor minus room air temperature. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
for a change in temperature difference between zone air and outdoor air.
Hence, this model validates whether the adjustment of the fan speed for medium
cooling load is correctly implemented.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model Supply_T
  "Validation model for outdoor minus room air temperature"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
    setPoiVAV(
    final TSup_max=303.15,
    final TSup_min=289.15,
    final TSupDew_max=292.15,
    final maxHeaSpe=0.7,
    final maxCooSpe=0.9,
    final minSpe=0.3)
    "Block that computes the setpoints for temperature and fan speed"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant uHea(k=0)
    "Heating control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant uCoo(k=0.6)
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TOut(
    final duration=3600,
    final height=18,
    final offset=273.15 + 10) "Outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZon(
    final k=273.15 + 22) "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Subtract dT
    "Difference zone minus outdoor temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSet(
    final k=273.15 + 24)
    "Zone cooling set point"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "AHU operation mode is occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSet(
    final k=273.15 + 20)
    "Zone heating set point"

equation
  connect(uCoo.y, setPoiVAV.uCoo)
  connect(TZon.y, setPoiVAV.TZon)
  connect(TOut.y, setPoiVAV.TOut)
  connect(uHea.y, setPoiVAV.uHea)
  connect(dT.u1, TZon.y)
  connect(dT.u2, TOut.y)
  connect(opeMod.y, setPoiVAV.uOpeMod)
  connect(TZonCooSet.y, setPoiVAV.TCooSet)
  connect(TZonHeaSet.y, setPoiVAV.THeaSet)
end Supply_T;


Validation model for temperature and fan speed. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
for different control signals.
Each controller is configured identical, but the input signal for TZon differs
in order to validate that the fan speed is increased correctly.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Validation;
model Supply_u "Validation model for temperature and fan speed"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
    setPoiVAV(
    final maxHeaSpe=0.7,
    final maxCooSpe=1,
    final minSpe=0.3,
    final TSup_max=303.15,
    final TSup_min=289.15,
    final TSupDew_max=297.15)
    "Block that computes the setpoints for temperature and fan speed"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
    setPoiVAV1(
    final maxHeaSpe=0.7,
    final maxCooSpe=1,
    final minSpe=0.3,
    final TSup_max=303.15,
    final TSup_min=289.15,
    final TSupDew_max=297.15)
    "Block that computes the setpoints for temperature and fan speed"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.SetPoints.Supply
    setPoiVAV2(
    final maxHeaSpe=0.7,
    final maxCooSpe=1,
    final minSpe=0.3,
    final TSup_max=303.15,
    final TSup_min=289.15,
    final TSupDew_max=297.15)
    "Block that computes the setpoints for temperature and fan speed"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZon(
    final k=273.15 + 28)
    "Zone air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOut(
    final k=273.15 + 22)
    "Outdoor temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uHea(
    final duration=900,
    final height=-1,
    final offset=1) "Heating control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uCoo(final duration=900,
      final startTime=2700)
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZon1(
    final k=273.15 + 23)
    "Zone air temperature"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "AHU operation mode is occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSet(final k=273.15
         + 22)
    "Zone heating set point"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSet(
    final k=273.15 + 24)
    "Zone cooling set point"

equation
  connect(TZon.y, setPoiVAV.TZon)
  connect(TOut.y, setPoiVAV.TOut)
  connect(uHea.y, setPoiVAV.uHea)
  connect(uCoo.y, setPoiVAV.uCoo)
  connect(TOut.y, setPoiVAV1.TOut)
  connect(uHea.y, setPoiVAV1.uHea)
  connect(uCoo.y, setPoiVAV1.uCoo)
  connect(TOut.y, setPoiVAV2.TOut)
  connect(uHea.y, setPoiVAV2.uHea)
  connect(uCoo.y, setPoiVAV2.uCoo)
  connect(TOut.y, setPoiVAV1.TZon)
  connect(TZon1.y, setPoiVAV2.TZon)
  connect(opeMod.y, setPoiVAV.uOpeMod)
  connect(opeMod.y, setPoiVAV1.uOpeMod)
  connect(opeMod.y, setPoiVAV2.uOpeMod)
  connect(TZonCooSet.y, setPoiVAV.TCooSet)
  connect(TZonCooSet.y, setPoiVAV1.TCooSet)
  connect(TZonCooSet.y, setPoiVAV2.TCooSet)
  connect(TZonHeaSet.y, setPoiVAV.THeaSet)
  connect(TZonHeaSet.y, setPoiVAV1.THeaSet)
  connect(TZonHeaSet.y, setPoiVAV2.THeaSet)
end Supply_u;


Validation of the top-level controller. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.Controller.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.Validation;
model Controller "Validation of the top-level controller"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV.Controller conVAV(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,

    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,

    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1A,

    final freSta=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.No_freeze_stat,

    final have_winSen=true,
    final have_CO2Sen=false,
    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefDamper,

    final VAreBreZon_flow=0.015,
    final VPopBreZon_flow=0.0075,
    final kHea=1,
    final have_occSen=true,
    final TSup_max=297.15,
    final TSup_min=285.15,
    final TSupDew_max=297.15,
    final maxHeaSpe=0.7,
    final maxCooSpe=1,
    final minSpe=0.1,
    final kMod=1,
    final VOutMin_flow=6e-3,
    final VOutDes_flow=0.25,
    final relDam_min=0.1,
    final relDam_max=0.6) "Validate the cooling case"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TZon(
    final duration=86400,
    final height=6,
    final offset=273.15 + 16)
    "Measured zone temperature"
  Buildings.Controls.SetPoints.OccupancySchedule occSch(
    final occupancy=3600*{4,20})
    "Occupancy schedule"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOut(
    final k=273.15 +17)
    "Outdoor air dry bulb temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooDowTim(
    final k=1800)
    "Cooling down time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warUpTim(
    final k=1800)
    "Warm-up time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin cooSetAdj(
    final freqHz=1/28800)
    "Cooling setpoint adjustment"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin heaSetAdj(
    final freqHz=1/28800,
    final amplitude=0.5)
    "Heating setpoint adjustment"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(
    final period=14400,
    final shift=1200)
    "Generate signal indicating window status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerAdj(
    final k=0)
    "Zero adjustment"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Switch to zero adjustment when window is open"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Switch to zero adjustment when window is open"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse occSta(
    final period=28800,
    final width=0.95)
    "Generate signal indicating occupancy status"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant demLimLev(
    final k=0)
    "Demand limit level"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse freRes(
    final width=0.95,
    final period=86400)
    "Freeze protection reset"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp mixTem(
    final height=-5,
    final offset=273.15 + 8,
    final duration=3600)
    "Mixed air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDam(
    final height=0.6,
    final offset=0.2,
    final duration=86400)
    "Outdoor damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooCoi(
    final height=-0.3,
    final offset=0.96,
    final duration=86400,
    startTime=1000) "Cooling coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaCoi(
    final k=0)
    "Heating coil position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TSup(
    final height=2,
    final duration=86400,
    final offset=273.15 + 22.5)
    "Terminal unit discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSetOcc(
    final k=293.15)
    "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TCooSetOcc(
    final k=297.15)
    "Occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSetUno(
    final k=285.15)
    "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TCooSetUno(
    final k=303.15)
    "Unoccupied cooling setpoint"

  CDL.Logical.Not                        not2 "Logical not"
equation
  connect(TZon.y, conVAV.TZon)
  connect(TOut.y, conVAV.TOut)
  connect(TSup.y, conVAV.TAirSup)
  connect(cooDowTim.y, conVAV.cooDowTim)
  connect(warUpTim.y, conVAV.warUpTim)
  connect(occSch.tNexOcc, conVAV.tNexOcc)
  connect(occSch.occupied, conVAV.u1Occ)
  connect(zerAdj.y,swi2. u1)
  connect(zerAdj.y,swi1. u1)
  connect(cooSetAdj.y,swi2. u3)
  connect(heaSetAdj.y,swi1. u3)
  connect(swi2.y, conVAV.cooSetAdj)
  connect(swi1.y, conVAV.heaSetAdj)
  connect(occSta.y, conVAV.u1OccSen)
  connect(demLimLev.y, conVAV.uCooDemLimLev)
  connect(demLimLev.y, conVAV.uHeaDemLimLev)
  connect(freRes.y, not1.u)
  connect(not1.y, conVAV.u1SofSwiRes)
  connect(mixTem.y, conVAV.TAirMix)
  connect(outDam.y, conVAV.uOutDam)
  connect(cooCoi.y, conVAV.uCooCoi_actual)
  connect(heaCoi.y, conVAV.uHeaCoi_actual)
  connect(THeaSetOcc.y,conVAV.TOccHeaSet)
  connect(TCooSetOcc.y,conVAV.TOccCooSet)
  connect(THeaSetUno.y,conVAV.TUnoHeaSet)
  connect(TCooSetUno.y,conVAV.TUnoCooSet)
  connect(conVAV.ySupFan, conVAV.uSupFan_actual)

  connect(winSta.y, not2.u)
  connect(not2.y, swi1.u2)
  connect(not2.y, swi2.u2)
  connect(not2.y, conVAV.u1Win)
end Controller;


Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.SingleZone.VAV;
package Validation "Collection of validation models"
end Validation;


Specify the economizer high liimits. This block outputs the air economizer high limits according to the energy standard,
device type and climate zone. The implementation is according to the Section 5.1.17 of ASHRAE
Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.Generic;
block AirEconomizerHighLimits "Specify the economizer high liimits"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard eneStd
    "Energy standard, ASHRAE 90.1 or Title 24";
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer ecoHigLimCon
    "Economizer high limit control device";
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Not_Specified
    "ASHRAE climate zone"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Not_Specified
    "California Title 24 climate zone"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TRet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    if (ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb
     or ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulbWithDifferentialDryBulb)
    "Return air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput hRet(
    final unit="J/kg",
    final quantity="SpecificEnergy")
    if (eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
     and ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialEnthalpyWithFixedDryBulb)
    "Return air enthalpy. For differential enthalpy use return air enthalpy measurement"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TCut(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "Outdoor air temperature high limit cutoff"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput hCut(
    final quantity="SpecificEnergy",
    final unit="J/kg")
    if (ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialEnthalpyWithFixedDryBulb
     or ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedEnthalpyWithFixedDryBulb)
    "Outdoor air enthalpy high limit cutoff"

protected
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fixDryBul(
    final k=ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb)
    "Fixed dry bulb"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant difDryBul(
    final k=ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb)
    "Differential dry bulb"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fixEntFixDryBul(
    final k=ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedEnthalpyWithFixedDryBulb)
    "Fixed enthalpy with fixed dry bulb"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant difEntFixDryBul(
    final k=ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialEnthalpyWithFixedDryBulb)
    "Differential enthalpy with fixed dry bulb"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash1A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 1A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash1B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 1B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash2A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_2A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 2A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash2B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_2B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 2B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash3A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_3A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 3A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash3B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_3B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 3B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash3C(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_3C)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 3C"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash4A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_4A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 4A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash4B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_4B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 4B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash4C(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_4C)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 4C"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash5A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_5A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 5A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash5B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_5B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 5B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash5C(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_5C)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 5C"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash6A(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_6A)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 6A"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash6B(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_6B)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 6B"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash7(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_7)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 7"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant ash8(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_8)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "ASHRAE zone 8"
  Buildings.Controls.OBC.CDL.Logical.Or or23
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1b, 2b or 3b"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 3c, 4b or 4c"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 5b, 5c or 6b"
  Buildings.Controls.OBC.CDL.Logical.Or or4
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or6
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 7 or 8"
  Buildings.Controls.OBC.CDL.Logical.Or or7
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or5
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 5a or 6a"
  Buildings.Controls.OBC.CDL.Logical.And and2
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and1
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and3
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(
    final k=273.15 + 24)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(
    final k=273.15 + 21)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con2(
    final k=273.15 + 18)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or10
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1b, 2b"
  Buildings.Controls.OBC.CDL.Logical.Or or11
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 3c, 4b"
  Buildings.Controls.OBC.CDL.Logical.Or or12
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 5a, 5b"
  Buildings.Controls.OBC.CDL.Logical.Or or13
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 6a, 6b or 7"
  Buildings.Controls.OBC.CDL.Logical.Or or14
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or15
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or8
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 2a or 3a"
  Buildings.Controls.OBC.CDL.Logical.Or or9
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1a, 2a, 3a or 4a"
  Buildings.Controls.OBC.CDL.Logical.And and4
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Warning: Differential dry bulb high-limit-control device is not allowed in climate zone 1A, 2A, 3A and 4A!")
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Warning when the wrong device being used"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con3(
    final k=273.15 + 24)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air enthalpy"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con4(
    final k=66000)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Enthalpy cutoff value, J/kg"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon1(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_1)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 1"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon2(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_2)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 2"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon3(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_3)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 3"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon4(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_4)
 if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 4"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon5(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_5)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 5"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon6(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_6)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 6"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon8(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_8)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 8"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon9(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_9)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 9"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon10(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_10)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 10"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon11(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_11)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 11"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon12(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_12)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 12"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon13(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_13)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 13"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon14(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_14)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 14"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon15(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_15)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 15"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titZon16(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_16)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Title 24, zone 16"
  Buildings.Controls.OBC.CDL.Logical.Or or16
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 1, 3"
  Buildings.Controls.OBC.CDL.Logical.Or or35
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 11, 12"
  Buildings.Controls.OBC.CDL.Logical.Or or36
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 14, 15"
  Buildings.Controls.OBC.CDL.Logical.Or or20
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 1, 3, 5, or 11 to 16"
  Buildings.Controls.OBC.CDL.Logical.And and5
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi5
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con5(
    final k=273.15 + 24)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or19
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 2, 4 or 10"
  Buildings.Controls.OBC.CDL.Logical.And and6
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi6
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con6(
    final k=273.15 + 23)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Logical.Or or21
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 6, 8 or 9"
  Buildings.Controls.OBC.CDL.Logical.And and7
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con7(
    final k=273.15 + 22)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi7
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con8(
    final k=273.15 + 21)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi8
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and8
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi9
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and9
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi10
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=-1) if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi11
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and10
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=-2)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi12
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar2(
    final p=-3)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con9(
    final k=273.15 + 24)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    final realTrue=66000)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Outdoor air enthalpy cutoff"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant titEngSta(
    final k=eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Check if Title 24 energy standard is used"
  Buildings.Controls.OBC.CDL.Logical.And and11
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Check if Title 24 energy standard is used and the device type is differential enthalpy with fixed dry bulb"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes1(
    final message="Warning: When Title 24 energy standard is used, the device type cannot be differential enthalpy with fixed dry bulb!")
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Warning when the wrong device being used"
  Buildings.Controls.OBC.CDL.Logical.Not not2
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con10(
    final k=0)
    if (eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
     and not ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialEnthalpyWithFixedDryBulb)
    "Constant 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con11(
    final k=0)
    if not (ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb
     or ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulbWithDifferentialDryBulb)
    "Constant 0"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fixDryBulDifDryBul(
    final k=ecoHigLimCon == Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulbWithDifferentialDryBulb)
    "Fixed dry bulb with differential dry bulb"
  Buildings.Controls.OBC.CDL.Logical.And and12
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Min min1
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Smaller input"
  Buildings.Controls.OBC.CDL.Reals.Switch swi13
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and13
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Min min2
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Smaller input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con12(
    final k=273.15 + 21)
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi14
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and14
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not3
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes2(
    final message="Warning: Fixed dry bulb with differential dry bulb high-limit-control device is not allowed in climate zone 1A, 2A, 3A and 4A!")
 if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Warning when the wrong device being used"
  Buildings.Controls.OBC.CDL.Logical.And and15
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi15
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Min min3
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Smaller input"
  Buildings.Controls.OBC.CDL.Logical.And and16
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Min min4
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Smaller input"
  Buildings.Controls.OBC.CDL.Reals.Switch swi16
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Logical.And and17
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Switch swi17
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Min min5
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Smaller input"
  Buildings.Controls.OBC.CDL.Reals.Switch swi18
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Cut off outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Min min6
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Smaller input"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant noAshCli(
    final k=ashCliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Not_Specified)
    "No ASHRAE climate zone"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant noTit24Cli(
    final k=tit24CliZon == Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Not_Specified)
    "No Title 24 climate zone"
  Buildings.Controls.OBC.CDL.Logical.And noCli
    "Climate zone is not specified"
  Buildings.Controls.OBC.CDL.Logical.Not not4
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes3(
    final message="Warning: Climate zone is not specified!")
    "Warning when the climate zone is not specified"
  Buildings.Controls.OBC.CDL.Logical.Or or22
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1b, 2b"
  Buildings.Controls.OBC.CDL.Logical.Or or24
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 3c, 4b"
  Buildings.Controls.OBC.CDL.Logical.Or or25
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 5b, 5c"
  Buildings.Controls.OBC.CDL.Logical.Or or26
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or27
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1b, 2b or 3b"
  Buildings.Controls.OBC.CDL.Logical.Or or28
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 3c, 4b or 4c"
  Buildings.Controls.OBC.CDL.Logical.Or or29
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 5a, 5b or 5c"
  Buildings.Controls.OBC.CDL.Logical.Or or30
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 6a, 6b or 7"
  Buildings.Controls.OBC.CDL.Logical.Or or31
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or3
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or33
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1
    "Zone 1a, 2a or 3a"
  Buildings.Controls.OBC.CDL.Logical.Or or34
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 1, 3 or 5"
  Buildings.Controls.OBC.CDL.Logical.Or or17
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 11, 12 or 13"
  Buildings.Controls.OBC.CDL.Logical.Or or18
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 14, 15 or 16"
  Buildings.Controls.OBC.CDL.Logical.Or or32
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Logical or"
  Buildings.Controls.OBC.CDL.Logical.Or or38
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 2, 4"
  Buildings.Controls.OBC.CDL.Logical.Or or39
    if eneStd == Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24
    "Zone 6, 8"
equation
  connect(or23.y, or4.u1)
  connect(or1.y, or4.u2)
  connect(ash7.y, or6.u1)
  connect(ash8.y, or6.u2)
  connect(ash5A.y, or5.u1)
  connect(ash6A.y, or5.u2)
  connect(or7.y, and2.u1)
  connect(fixDryBul.y, and2.u2)
  connect(fixDryBul.y, and1.u2)
  connect(or5.y, and1.u1)
  connect(and2.y, swi.u2)
  connect(con.y, swi.u1)
  connect(con1.y, swi1.u1)
  connect(and1.y, swi1.u2)
  connect(fixDryBul.y, swi2.u2)
  connect(con2.y, swi2.u1)
  connect(swi2.y, swi1.u3)
  connect(ash1B.y, or10.u1)
  connect(ash2B.y, or10.u2)
  connect(ash3C.y, or11.u1)
  connect(ash4B.y, or11.u2)
  connect(ash5A.y, or12.u1)
  connect(ash5B.y, or12.u2)
  connect(ash6A.y, or13.u1)
  connect(ash6B.y, or13.u2)
  connect(or15.y, and3.u1)
  connect(difDryBul.y, and3.u2)
  connect(and3.y, swi3.u2)
  connect(TRet, swi3.u1)
  connect(ash2A.y, or8.u2)
  connect(ash3A.y, or8.u1)
  connect(ash4A.y, or9.u1)
  connect(or9.y, and4.u1)
  connect(difDryBul.y, and4.u2)
  connect(and4.y, not1.u)
  connect(not1.y, assMes.u)
  connect(swi1.y, swi.u3)
  connect(swi3.y, swi2.u3)
  connect(con4.y, swi4.u1)
  connect(fixEntFixDryBul.y, swi4.u2)
  connect(hRet, swi4.u3)
  connect(swi.y, TCut)
  connect(swi4.y, hCut)
  connect(titZon1.y, or16.u1)
  connect(titZon3.y, or16.u2)
  connect(titZon11.y,or35. u1)
  connect(titZon12.y,or35. u2)
  connect(titZon14.y,or36. u1)
  connect(titZon15.y,or36. u2)
  connect(or20.y, and5.u1)
  connect(fixDryBul.y, and5.u2)
  connect(and5.y, swi5.u2)
  connect(con5.y, swi5.u1)
  connect(or19.y, and6.u1)
  connect(fixDryBul.y, and6.u2)
  connect(and6.y, swi6.u2)
  connect(con6.y, swi6.u1)
  connect(swi6.y, swi5.u3)
  connect(and7.y, swi7.u2)
  connect(con7.y, swi7.u1)
  connect(or21.y, and7.u1)
  connect(fixDryBul.y, and7.u2)
  connect(swi7.y, swi6.u3)
  connect(con8.y, swi8.u1)
  connect(fixDryBul.y, swi8.u2)
  connect(or20.y, and8.u1)
  connect(difDryBul.y, and8.u2)
  connect(and8.y, swi9.u2)
  connect(TRet, swi9.u1)
  connect(swi10.y, swi9.u3)
  connect(or19.y, and9.u1)
  connect(difDryBul.y, and9.u2)
  connect(TRet, addPar.u)
  connect(and9.y, swi10.u2)
  connect(addPar.y, swi10.u1)
  connect(and10.y, swi11.u2)
  connect(swi11.y, swi10.u3)
  connect(or21.y, and10.u1)
  connect(difDryBul.y, and10.u2)
  connect(addPar1.y, swi11.u1)
  connect(TRet, addPar1.u)
  connect(addPar2.y, swi12.u1)
  connect(swi12.y, swi11.u3)
  connect(difDryBul.y, swi12.u2)
  connect(TRet, addPar2.u)
  connect(swi8.y, swi7.u3)
  connect(swi9.y, swi8.u3)
  connect(fixEntFixDryBul.y, booToRea.u)
  connect(swi5.y, TCut)
  connect(booToRea.y, hCut)
  connect(titEngSta.y, and11.u2)
  connect(difEntFixDryBul.y, and11.u1)
  connect(not2.y, assMes1.u)
  connect(and11.y, not2.u)
  connect(con10.y, swi4.u3)
  connect(con11.y, swi3.u1)
  connect(con11.y, swi9.u1)
  connect(con11.y, addPar.u)
  connect(con11.y, addPar1.u)
  connect(con11.y, addPar2.u)
  connect(fixDryBulDifDryBul.y, and12.u2)
  connect(or7.y, and12.u1)
  connect(and12.y, swi13.u2)
  connect(con3.y, min1.u1)
  connect(TRet, min1.u2)
  connect(min1.y, swi13.u1)
  connect(swi13.y, swi3.u3)
  connect(or5.y, and13.u2)
  connect(fixDryBulDifDryBul.y, and13.u1)
  connect(con12.y, min2.u1)
  connect(TRet, min2.u2)
  connect(and13.y, swi14.u2)
  connect(min2.y, swi14.u1)
  connect(con3.y, swi14.u3)
  connect(swi14.y, swi13.u3)
  connect(and14.y, not3.u)
  connect(or9.y, and14.u2)
  connect(not3.y, assMes2.u)
  connect(fixDryBulDifDryBul.y, and14.u1)
  connect(and15.y, swi15.u2)
  connect(con5.y, min3.u1)
  connect(TRet, min3.u2)
  connect(min3.y, swi15.u1)
  connect(fixDryBulDifDryBul.y, and15.u2)
  connect(fixDryBulDifDryBul.y, and16.u2)
  connect(or20.y, and15.u1)
  connect(or19.y, and16.u1)
  connect(con6.y, min4.u2)
  connect(addPar.y, min4.u1)
  connect(min4.y, swi16.u1)
  connect(and16.y, swi16.u2)
  connect(swi16.y, swi15.u3)
  connect(con7.y, min5.u2)
  connect(addPar1.y, min5.u1)
  connect(min5.y, swi17.u1)
  connect(and17.y, swi17.u2)
  connect(or21.y, and17.u1)
  connect(fixDryBulDifDryBul.y, and17.u2)
  connect(swi17.y, swi16.u3)
  connect(fixDryBulDifDryBul.y, swi18.u2)
  connect(con8.y, min6.u2)
  connect(addPar2.y, min6.u1)
  connect(min6.y, swi18.u1)
  connect(con9.y, swi18.u3)
  connect(swi18.y, swi17.u3)
  connect(swi15.y, swi12.u3)
  connect(con11.y, min3.u2)
  connect(con11.y, min1.u2)
  connect(con11.y, min2.u2)
  connect(noAshCli.y,noCli. u1)
  connect(noTit24Cli.y,noCli. u2)
  connect(noCli.y,not4. u)
  connect(not4.y,assMes3. u)
  connect(ash1B.y, or22.u1)
  connect(ash2B.y, or22.u2)
  connect(ash3B.y, or23.u2)
  connect(or22.y, or23.u1)
  connect(ash3C.y, or24.u1)
  connect(ash4B.y, or24.u2)
  connect(or24.y, or1.u1)
  connect(ash4C.y, or1.u2)
  connect(ash5B.y, or25.u1)
  connect(ash5C.y, or25.u2)
  connect(ash6B.y, or2.u2)
  connect(or25.y, or2.u1)
  connect(or2.y, or26.u1)
  connect(or6.y, or26.u2)
  connect(or4.y, or7.u1)
  connect(or26.y, or7.u2)
  connect(or10.y, or27.u1)
  connect(ash3B.y, or27.u2)
  connect(ash4C.y, or28.u2)
  connect(or11.y, or28.u1)
  connect(ash5C.y, or29.u2)
  connect(or12.y, or29.u1)
  connect(ash7.y, or30.u2)
  connect(or13.y, or30.u1)
  connect(or27.y, or31.u1)
  connect(or28.y, or31.u2)
  connect(or29.y, or14.u1)
  connect(or30.y, or14.u2)
  connect(or31.y, or3.u1)
  connect(or14.y, or3.u2)
  connect(ash8.y, or15.u2)
  connect(or3.y, or15.u1)
  connect(or33.y, or9.u2)
  connect(or8.y, or33.u1)
  connect(ash1A.y, or33.u2)
  connect(titZon5.y, or34.u2)
  connect(or16.y, or34.u1)
  connect(titZon13.y, or17.u2)
  connect(or35.y, or17.u1)
  connect(titZon16.y, or18.u2)
  connect(or36.y, or18.u1)
  connect(or34.y, or32.u1)
  connect(or17.y, or32.u2)
  connect(or32.y, or20.u1)
  connect(or18.y, or20.u2)
  connect(titZon2.y, or38.u2)
  connect(titZon4.y, or38.u1)
  connect(titZon10.y, or19.u1)
  connect(or38.y, or19.u2)
  connect(titZon8.y, or39.u1)
  connect(titZon6.y, or39.u2)
  connect(titZon9.y, or21.u1)
  connect(or39.y, or21.u2)
end AirEconomizerHighLimits;


Generic control sequences

within Buildings.Controls.OBC.ASHRAE.G36;
package Generic "Generic control sequences"
end Generic;


Calculate a time-delay period after change in set point. This sequence checks if there is setpoint change and if the time-based suppression
has finished. The implementation is according to the Section 5.1.20 of ASHRAE
Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.Generic;
block TimeSuppression
  "Calculate a time-delay period after change in set point"

  parameter Real chaRat(final unit="s/K")=540
    "Gain factor to calculate suppression time based on the change of the setpoint, seconds per Kelvin. For cooling or heating request, it should be 540 seconds, for temperature alarms, it should be 1080 seconds"
  parameter Real maxTim(
    final unit="s",
    final quantity="Time")=1800
    "Maximum suppression time. For cooling or heating request, it should be 1800 seconds, for temperature alarms, it should be 7200 seconds"
  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time")=120
    "Sample period of component, set to the same value as the trim and respond that process static pressure reset"
  parameter Real dTHys(
    final unit="K",
    final quantity="TemperatureDifference")=0.25
    "Near zero temperature difference, below which the difference will be seen as zero"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yAftSup
    "True when there is no setpoint change, or suppression time has passed after setpoint change"

  Buildings.Controls.OBC.CDL.Reals.Min supTim
    "Calculated suppression time due to the setpoint change"
protected
  Buildings.Controls.OBC.CDL.Discrete.Sampler samSet(
    final samplePeriod=samplePeriod)
    "Sample current setpoint"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay uniDel(
    final samplePeriod=samplePeriod)
    "Delay value to record input value"
  Buildings.Controls.OBC.CDL.Reals.Abs abs1
    "Absolute change of the setpoint temperature"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam
    "New setpoint temperature"
  Buildings.Controls.OBC.CDL.Logical.Edge edg
    "Instants when input becomes true"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    "Output true when there is setpoint change and maintain the true output until the suppresiong time has passed"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1
    "Output true when the suppression time has passed"
  Buildings.Controls.OBC.CDL.Logical.Timer tim
    "Time when the setpoint is being changed"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=dTHys,
    final h=0.5*dTHys)
    "Check if there is setpoint change"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=chaRat)
    "Setpoint change rate"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate difference of previous and current setpoints"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer(
    final k=0)
    "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSupTim(
    final k=maxTim) "Maximum suppression time "
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con5(
    final k=true)
    "Constant true"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Use setpoint different value when sample period time has passed"
  Buildings.Controls.OBC.CDL.Logical.Pre pre1 "Use left-limit of signal to break algebraic loop"
  Buildings.Controls.OBC.CDL.Logical.Switch pasSupTim
    "Check if suppression time has passed"
  Buildings.Controls.OBC.CDL.Reals.Greater pasSup
    "Check if the change has been suppressed by sufficient time"
  Buildings.Controls.OBC.CDL.Reals.Subtract temDif
    "Difference between setpoint and zone temperature"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam1
    "Zone temperature at the moment when there is setpoint change"
  Buildings.Controls.OBC.CDL.Reals.Abs abs2
    "Absolute temperature difference"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel(
    final delayTime=samplePeriod,
    final delayOnInit=true)
    "Ignore the first sampling period"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    final k=true) "Constant true"

equation
  connect(TSet, samSet.u)
  connect(samSet.y, uniDel.u)
  connect(greThr.y, lat.u)
  connect(lat.y,tim. u)
  connect(lat.y,edg. u)
  connect(edg.y,lat1. clr)
  connect(sub1.y,swi. u1)
  connect(conZer.y,swi. u3)
  connect(swi.y, abs1.u)
  connect(abs1.y, greThr.u)
  connect(pre1.y, lat.clr)
  connect(gai.y,supTim. u1)
  connect(maxSupTim.y,supTim. u2)
  connect(lat.y, pasSupTim.u2)
  connect(lat1.y, pasSupTim.u1)
  connect(con5.y, pasSupTim.u3)
  connect(tim.y, pasSup.u1)
  connect(pasSup.y, lat1.u)
  connect(pasSup.y, pre1.u)
  connect(pasSupTim.y, yAftSup)
  connect(TSet, triSam.u)
  connect(TZon, triSam1.u)
  connect(triSam.y, temDif.u1)
  connect(edg.y, triSam1.trigger)
  connect(edg.y, triSam.trigger)
  connect(temDif.y, abs2.u)
  connect(abs2.y, gai.u)
  connect(supTim.y, pasSup.u2)
  connect(uniDel.y, sub1.u2)
  connect(samSet.y, sub1.u1)
  connect(triSam1.y, temDif.u2)
  connect(con1.y, truDel.u)
  connect(truDel.y, swi.u2)
end TimeSuppression;


Block to inplement trim and respond logic. This block implements the trim and respond logic according to Section 5.1.14.3
and 5.1.14.4 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.Generic;
block TrimAndRespond "Block to inplement trim and respond logic"
  parameter Boolean have_hol=false
    "Set to true to allow holding the reset, false to continuously reset when enabled"
  parameter Real iniSet  "Initial setpoint";
  parameter Real minSet  "Minimum setpoint";
  parameter Real maxSet  "Maximum setpoint";
  parameter Real delTim(
    min=100*1E-15,
    final unit="s") "Delay time";
  parameter Real samplePeriod(
    min=1E-3,
    final unit="s")
    "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)";
  parameter Real dtHol(
    min=0,
    start=0,
    final unit="s")=0
    "Minimum hold time"

  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.BooleanInput uHol if have_hol
    "Hold signal"
  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"
  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(final k=iniSet)
    "Initial setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant numIgnReqCon(final k=numIgnReq)
    "Number of ignored requests"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant triAmoCon(final k=triAmo)
    "Trim amount constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxResCon(final k=maxRes)
    "Maximum response per time interval"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSetCon(final k=maxSet)
    "Maximum setpoint constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerTri(final 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"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(final k=0) "Constant"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fal(final k=false) if not
    have_hol "Constant – Placeholder value if there is no hold signal"
  Buildings.Controls.OBC.CDL.Reals.Switch swiHol
    "Switch to zero reset until hold is released and sampler clock ticks"
  Buildings.Controls.OBC.CDL.Logical.Not notHol "Return true if hold is released"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    "True when hold is active and sampler clock ticks: enables applying the last calculated reset before freezing output"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truHol(
    final trueHoldDuration=dtHol,
    final falseHoldDuration=0) if have_hol
    "Hold true for the longer of dtHol and the time uHol remains true"
  Buildings.Controls.OBC.CDL.Logical.And notHolAndTic
    "Return true if hold is released and sampler clock ticks"
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri(
    final period=samplePeriod,
    final shift=0)
    "Generate signal matching the request sampling frequency"
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(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(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(swi1.y, netRes.u3)
  connect(minInp.y, gai.u)
  connect(gai.y, swi3.u3)
  connect(swi3.y, add2.u2)
  connect(sampler.y, difReqIgnReq.u1)

  connect(numIgnReqCon.y, difReqIgnReq.u2)
  connect(netRes.y, swiHol.u3)
  connect(swiHol.y, add1.u2)
  connect(uniDel.y, add1.u1)
  connect(zer.y, swiHol.u1)
  connect(fal.y, notHol.u)
  connect(lat.y, swiHol.u2)
  connect(swi2.y, uniDel.u)
  connect(uHol, truHol.u)
  connect(truHol.y, notHol.u)
  connect(notHol.y, notHolAndTic.u1)
  connect(notHolAndTic.y, lat.clr)
  connect(samTri.y, lat.u)
  connect(samTri.y, notHolAndTic.u2)
end TrimAndRespond;