Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits;
package Validation "Collection of validation models"
end Validation;


Validation model for the minimum outdoor air control - damper position limits for the units with separated outdoor air control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithAFMS
for the following control signals: VOut_flow, VOutMinSet_flow.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.Validation;
model SeparateWithAFMS
  "Validation model for the minimum outdoor air control - damper position limits for the units with separated outdoor air control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithAFMS disMinCon(
    final minSpe=0.1)
    "Disable the minimum outdoor air control due to that the supply fan is not proven on"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithAFMS disMinCon1(
    final minSpe=0.1)
    "Disable the minimum outdoor air control due to that it is not in occupied mode"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithAFMS minCon(
    final minSpe=0.1)
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow(
    final k=minVOutSet_flow)
    "Outdoor volumetric airflow rate setpoint, 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow(
    final duration=1800,
    final offset=VOutMin_flow,
    final height=incVOutSet_flow)
    "Measured outdoor airflow rate"

protected
  parameter Real minVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.71
    "Example volumetric airflow setpoint, 15cfm/occupant, 100 occupants";
  parameter Real VOutMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.61
    "Minimal measured volumetric airflow";
  parameter Real incVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=(minVOutSet_flow-VOutMin_flow)*2
    "Maximum volumetric airflow increase during the example simulation";

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanStatus(
    final k=true) "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant operationMode(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Operation mode is Occupied"
  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.Integers.Sources.Constant opeMod1(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.warmUp)
    "AHU operation mode is Occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow1(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta(
    final k=false)
    "Fan is off"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow1(
    final duration=1800,
    final offset=minVOutSet_flow,
    final height=incVOutSet_flow)
    "Measured outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supFanSpe(
    final k=0) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow2(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta1(
    final k=true)
    "Fan is on"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow2(
    final duration=1800,
    final offset=minVOutSet_flow,
    final height=incVOutSet_flow) "Measured outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos1(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supFanSpe1(
    final k=0.2) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos2(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe2(
    final height=0.5,
    final duration=1800,
    final offset=0.1)
    "Supply fan speed"

equation
  connect(VOut_flow.y,minCon. VOut_flow_normalized)
  connect(VOutMinSet_flow.y,minCon. VOutMinSet_flow_normalized)
  connect(fanStatus.y, minCon.u1SupFan)
  connect(operationMode.y,minCon. uOpeMod)
  connect(VOutMinSet_flow1.y, disMinCon.VOutMinSet_flow_normalized)
  connect(VOut_flow1.y, disMinCon.VOut_flow_normalized)
  connect(fanSta.y, disMinCon.u1SupFan)
  connect(opeMod.y, disMinCon.uOpeMod)
  connect(outDamPos.y, disMinCon.uOutDam)
  connect(supFanSpe.y, disMinCon.uSupFan)
  connect(VOutMinSet_flow2.y, disMinCon1.VOutMinSet_flow_normalized)
  connect(VOut_flow2.y, disMinCon1.VOut_flow_normalized)
  connect(fanSta1.y, disMinCon1.u1SupFan)
  connect(opeMod1.y, disMinCon1.uOpeMod)
  connect(outDamPos1.y, disMinCon1.uOutDam)
  connect(supFanSpe1.y, disMinCon1.uSupFan)
  connect(outDamPos2.y, minCon.uOutDam)
  connect(supFanSpe2.y, minCon.uSupFan)
end SeparateWithAFMS;


Validation model for the minimum outdoor air control - damper position limits for the units with separated outdoor air control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithDP
for the following control signals: VOut_flow, VOutMinSet_flow.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.Validation;
model SeparateWithDP
  "Validation model for the minimum outdoor air control - damper position limits for the units with separated outdoor air control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithDP disMinCon(
    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,
    final dpDesMinOutDam=300,
    final minSpe=0.1)
    "Disable the minimum outdoor air control due to that the supply fan is not proven on"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithDP disMinCon1(
    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,
    final dpDesMinOutDam=300,
    final minSpe=0.1)
    "Disable the minimum outdoor air control due to that it is not in occupied mode"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits.SeparateWithDP minCon(
    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,
    final dpDesMinOutDam=300,
    final minSpe=0.1)
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow(
    final k=minVOutSet_flow)
    "Outdoor volumetric airflow rate setpoint, 15cfm/occupant and 100 occupants"

protected
  parameter Real minVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.71
    "Example volumetric airflow setpoint, 15cfm/occupant, 100 occupants";
  parameter Real VOutMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.61
    "Minimal measured volumetric airflow";
  parameter Real incVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=(minVOutSet_flow-VOutMin_flow)*2
    "Maximum volumetric airflow increase during the example simulation";

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanStatus(
    final k=true) "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant operationMode(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Operation mode is Occupied"
  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.Integers.Sources.Constant opeMod1(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.warmUp)
    "AHU operation mode is Occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow1(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta(
    final k=false)
    "Fan is off"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supFanSpe(
    final k=0) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow2(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta1(
    final k=true)
    "Fan is on"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos1(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supFanSpe1(
    final k=0.2) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp outDamPos2(
    final duration=1800,
    final offset=0.1,
    final height=0.5) "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe2(
    final height=0.5,
    final duration=1800,
    final offset=0.1)
    "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpDam(
    final duration=1800,
    final offset=250,
    final height=100) "Pressure accross outdoor air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpDam1(
    final duration=1800,
    final offset=250,
    final height=100) "Pressure accross outdoor air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpDam2(
    final duration=1800,
    final offset=120,
    final height=52)  "Pressure accross outdoor air damper"
equation
  connect(VOutMinSet_flow.y,minCon. VOutMinSet_flow_normalized)
  connect(fanStatus.y, minCon.u1SupFan)
  connect(operationMode.y,minCon. uOpeMod)
  connect(VOutMinSet_flow1.y, disMinCon.VOutMinSet_flow_normalized)
  connect(fanSta.y, disMinCon.u1SupFan)
  connect(opeMod.y, disMinCon.uOpeMod)
  connect(outDamPos.y, disMinCon.uOutDam)
  connect(supFanSpe.y, disMinCon.uSupFan)
  connect(VOutMinSet_flow2.y, disMinCon1.VOutMinSet_flow_normalized)
  connect(fanSta1.y, disMinCon1.u1SupFan)
  connect(opeMod1.y, disMinCon1.uOpeMod)
  connect(outDamPos1.y, disMinCon1.uOutDam)
  connect(supFanSpe1.y, disMinCon1.uSupFan)
  connect(outDamPos2.y, minCon.uOutDam)
  connect(supFanSpe2.y, minCon.uSupFan)
  connect(dpDam.y, disMinCon.dpMinOutDam)
  connect(dpDam1.y, disMinCon1.dpMinOutDam)
  connect(dpDam2.y, minCon.dpMinOutDam)
end SeparateWithDP;


within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences;
package Modulations "Package of sequences to modulate economizer dampers"
end Modulations;


Modulates dampers of economizer in buildings using relief damper or fan to control the pressure. This is a multi zone VAV AHU economizer modulation block. It calculates
the outdoor and return air damper positions based on the supply air temperature
control loop signal. It is implemented according to Section 5.16.2.3.d,
Figure 5.16.2.3-1 of ASHRAE Guideline 36, May 2020.
Damper positions are linearly mapped to
the supply air control loop signal.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations;
block Reliefs
  "Modulates dampers of economizer in buildings using relief damper or fan to control the pressure"

  parameter Real uMin(
    final max=0,
    final unit="1")=-0.25
    "Lower limit of controller input when outdoor damper opens (see diagram)"
  parameter Real uMax(
    final min=0,
    final unit="1")=+0.25
    "Upper limit of controller input when return damper is closed (see diagram)"
  parameter Real uOutDamMax(
    final min=-1,
    final max=1,
    final unit="1") = (uMin + uMax)/2
    "Maximum loop signal for the OA damper to be fully open"
  parameter Real uRetDamMin(
    final min=-1,
    final max=1,
    final unit="1") = (uMin + uMax)/2
    "Minimum loop signal for the RA damper to be fully open"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uTSup(final unit="1")
    "Signal for supply air temperature control (T Sup Control Loop Signal in diagram)"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDam_min(
    final min=0,
    final max=1,
    final unit="1")
    "Minimum economizer damper position limit as returned by the damper position limits  sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDam_max(
    final min=0,
    final max=1,
    final unit="1") "Maximum economizer damper position limit as returned by the economizer enable-disable sequence.
    If the economizer is disabled, this value equals uOutDam_min"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDam_min(
    final min=0,
    final max=1,
    final unit="1")
    "Minimum return air damper position limit as returned by the economizer enable-disable sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDam_max(
    final min=0,
    final max=1,
    final unit="1")
    "Maximum return air damper position limit as returned by the economizer enable-disable sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDam(
    final min=0,
    final max=1,
    final unit="1")
    "Economizer damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDam(
    final min=0,
    final max=1,
    final unit="1")
    "Return air damper commanded position"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamMinLimSig(
    final k=uMin) "Minimal control loop signal for the outdoor air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamMaxLimSig(
    final k=uOutDamMax) "Maximum control loop signal for the outdoor air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamConMinLimSig(
    final k=uRetDamMin)
    "Minimal control loop signal for the return air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamMaxLimSig(
    final k=uMax) "Maximal control loop signal for the return air damper"
  Buildings.Controls.OBC.CDL.Reals.Line outDamPos(
    final limitBelow=true,
    final limitAbove=true)
    "Damper position is linearly proportional to the control signal between signal limits"
  Buildings.Controls.OBC.CDL.Reals.Line retDamPos(
    final limitBelow=true,
    final limitAbove=true)
    "Damper position is linearly proportional to the control signal between signal limits"
  Buildings.Controls.OBC.CDL.Reals.Min min "Overwrite due to freeze protection"
  Buildings.Controls.OBC.CDL.Reals.Max max "Overwrite due to freeze protection"

equation
  connect(outDamPos.x2, outDamMaxLimSig.y)
  connect(outDamPos.x1, outDamMinLimSig.y)
  connect(outDamPos.f1, uOutDam_min)
  connect(outDamPos.f2, uOutDam_max)
  connect(retDamPos.x2, retDamMaxLimSig.y)
  connect(retDamPos.x1, retDamConMinLimSig.y)
  connect(retDamPos.f1, uRetDam_max)
  connect(retDamPos.f2, uRetDam_min)
  connect(min.u2, uOutDam_max)
  connect(min.u1, outDamPos.y)
  connect(max.u1, retDamPos.y)
  connect(uRetDam_min, max.u2)
  connect(uTSup, retDamPos.u)
  connect(uTSup, outDamPos.u)
  connect(max.y, yRetDam)
  connect(min.y, yOutDam)
end Reliefs;


Modulates dampers of economizer in buildings using return fan to control the pressure. Block modulates the damper of economizers of buildings with pressure controlled by
return fan and airflow tracking. It is implemented according to Section 5.16.2.3.d,
Figure 5.16.2.3-2 and Figure 5.16.2.3-3 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations;
block ReturnFan
  "Modulates dampers of economizer in buildings using return fan to control the pressure"

  parameter Boolean have_dirCon=true
    "True: the building have direct pressure control"
  parameter Real uMin(
    final max=0,
    final unit="1")=-0.25
    "Lower limit of controller input when outdoor damper opens (see diagram)"
  parameter Real uMax(
    final min=0,
    final unit="1")=+0.25
    "Upper limit of controller input when return damper is closed (see diagram)"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uTSup(
    final unit="1")
    "Supply air temperature control loop signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDam_max(
    final min=0,
    final max=1,
    final unit="1")
    "Maximum return air damper position limit as returned by the economizer enable-disable sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDam_min(
    final min=0,
    final max=1,
    final unit="1")
    "Minimum return air damper position limit as returned by the economizer enable-disable sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDam(
    final min=0,
    final max=1,
    final unit="1") "Return air damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRelDam(
    final min=0,
    final max=1,
    final unit="1") if not have_dirCon
    "Relief air damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDam(
    final min=0,
    final max=1,
    final unit="1") "Outdoor air damper position"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant damMinLimSig(
    final k=uMin)
    "Minimal control loop signal for the relief and return air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant damMaxLimSig(
    final k=uMax)
    "Maximal control loop signal for the return and exhast air damper"
  Buildings.Controls.OBC.CDL.Reals.Line retDamPos(
    final limitBelow=true,
    final limitAbove=true) "Return air damper position"
  Buildings.Controls.OBC.CDL.Reals.Line relDamPos(
    final limitBelow=true,
    final limitAbove=true) if not have_dirCon
    "Relief air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(
    final k=0) if not have_dirCon
    "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(
    final k=1) "Constant one"

equation
  connect(damMinLimSig.y, retDamPos.x1)
  connect(uRetDam_max, retDamPos.f1)
  connect(damMaxLimSig.y, retDamPos.x2)
  connect(uRetDam_min, retDamPos.f2)
  connect(damMinLimSig.y, relDamPos.x1)
  connect(zer.y, relDamPos.f1)
  connect(damMaxLimSig.y, relDamPos.x2)
  connect(one.y, relDamPos.f2)
  connect(uTSup, retDamPos.u)
  connect(uTSup, relDamPos.u)
  connect(one.y, yOutDam)
  connect(retDamPos.y, yRetDam)
  connect(relDamPos.y, yRelDam)
end ReturnFan;


Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations;
package Validation "Collection of validation models"
end Validation;


Validation model for modulating dampers of units with relief damper control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.Reliefs.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.Validation;
model Reliefs
  "Validation model for modulating dampers of units with relief damper control"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.Reliefs mod1
    "Multi zone VAV AHU minimum outdoor air control - damper modulation"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxRetDam(
    final k=0.9)
    "Return damper maximum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp temLoo(
    final duration=1800,
    final offset=-1,
    final height=2) "Temperature control loop output"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxOutDam(
    final k=1)
    "Outdoor air damper maximum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minRetDam(
    final k=0.1)
    "Return damper minimum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minOutDam(
    final k=0)
    "Outdoor air damper minimum position"

equation
  connect(temLoo.y, mod1.uTSup)
  connect(maxRetDam.y, mod1.uRetDam_max)
  connect(minRetDam.y, mod1.uRetDam_min)
  connect(maxOutDam.y, mod1.uOutDam_max)
  connect(minOutDam.y, mod1.uOutDam_min)
end Reliefs;


Validation model for modulating dampers of units with return fan. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.ReturnFan.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.Validation;
model ReturnFan
  "Validation model for modulating dampers of units with return fan"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.ReturnFan ecoMod
    "Multi zone VAV AHU minimum outdoor air control - damper modulation"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.ReturnFan ecoMod1(
    final have_dirCon=false)
    "Multi zone VAV AHU minimum outdoor air control - damper modulation, the unit does not have direct pressure control"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxRetDam(
    final k=0.9)
    "Return damper maximum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp temLoo(
    final duration=1800,
    final offset=-1,
    final height=2) "Temperature control loop output"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minRetDam(
    final k=0.1)
    "Return damper minimum position"

equation
  connect(temLoo.y, ecoMod.uTSup)
  connect(maxRetDam.y, ecoMod.uRetDam_max)
  connect(minRetDam.y, ecoMod.uRetDam_min)
  connect(temLoo.y, ecoMod1.uTSup)
  connect(maxRetDam.y, ecoMod1.uRetDam_max)
  connect(minRetDam.y, ecoMod1.uRetDam_min)
end ReturnFan;


Model validates economizer disable for heating zone state and activated freeze protection. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
for the following control signals: zone state, freeze protection stage.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Validation;
model Enable_FreProSta
  "Model validates economizer disable for heating zone state and activated freeze protection"
  parameter Real TOutCutoff(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Outdoor temperature high limit cutoff";
  parameter Real hOutCutoff(
    final unit="J/kg",
    final quantity="SpecificEnergy")=65100
    "Outdoor air enthalpy high limit cutoff";

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable enaDis
    "Multi zone VAV AHU enable disable sequence"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutBelowCutoff(
    final k=TOutCutoff - 2)
    "Outdoor air temperature is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutCut(
    final k=TOutCutoff) "OA temperature high limit cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutBelowCutoff(
    final k=hOutCutoff - 1000)
    "Outdoor air enthalpy is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutCut(
    final k=hOutCutoff) "Outdoor air enthalpy cutoff"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMax(
    final k=0.9) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMin(
    final k=0.1) "Minimal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPhyPosMax(
    final k=1) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMax(
    final k=0.8) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMin(
    final k=0) "Minimal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant supFanSta(k=true)
    "Supply fan status"

  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(period=1800)
    "Boolean pulse for generating freeze protection stage"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger freProSta1(
    integerTrue=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage0,
    integerFalse=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage1)
    "Freeze protection stage changes from stage 0 to stage 1"

equation
  connect(TOutCut.y, enaDis.TOutCut)
  connect(TOutBelowCutoff.y, enaDis.TOut)
  connect(hOutBelowCutoff.y, enaDis.hOut)
  connect(hOutCut.y, enaDis.hOutCut)
  connect(outDamPosMin.y, enaDis.uOutDam_min)
  connect(outDamPosMax.y, enaDis.uOutDam_max)
  connect(retDamPosMin.y, enaDis.uRetDam_min)
  connect(retDamPosMax.y, enaDis.uRetDam_max)
  connect(retDamPhyPosMax.y, enaDis.uRetDamPhy_max)
  connect(supFanSta.y, enaDis.u1SupFan)
  connect(booPul1.y, freProSta1.u)
  connect(freProSta1.y, enaDis.uFreProSta)
end Enable_FreProSta;


Model validates economizer disable in case outdoor air conditions are above cutoff. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
for the following control signals: TOut, TOutCut,
hOut, hOutCut.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Validation;
model Enable_TOut_hOut
  "Model validates economizer disable in case outdoor air conditions are above cutoff"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutCut(
    final k=TOutCutoff) "Outdoor air temperature cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutCut1(
    final k=hOutCutoff) "Outdoor air enthalpy cutoff"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable enaDis
    "Multi zone VAV AHU economizer enable disable sequence"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable enaDis1
    "Multi zone VAV AHU economizer enable disable sequence"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable enaDis2(
    final use_enthalpy=false)
    "Multi zone VAV AHU economizer enable disable sequence"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TOut(
    final amplitude=4,
    final freqHz=1/3600,
    final offset=TOutCutoff - 2,
    final startTime=10) "Outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin hOut(
    final amplitude=4000,
    final freqHz=1/3600,
    final offset=hOutCutoff - 2200,
    final startTime=10) "Outdoor air enthalpy"
protected
  final parameter Real TOutCutoff(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Outdoor temperature high limit cutoff";
  final parameter Real hOutCutoff(
    final unit="J/kg",
    final quantity="SpecificEnergy")=65100
    "Outdoor air enthalpy high limit cutoff";

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutCut(
    final k=hOutCutoff) "Outdoor air enthalpy cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutCut1(
    final k=TOutCutoff) "Outdoor air temperature cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutBelowCutoff(
    final k=hOutCutoff - 1000)
    "Outdoor air enthalpy is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutBelowCutoff(
    final k=TOutCutoff - 2)
    "Outdoor air temperature is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMax(
    final k=0.9) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMin(
    final k=0.1) "Minimal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMax(
    final k=0.8) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMin(
    final k=0) "Minimal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPhyPosMax(
    final k=1) "Maximal allowed economizer damper position"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage0)
    "Freeze Protection Status - Disabled"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant supFanSta(
    final k=true) "Supply fan status signal"

equation
  connect(TOutCut.y, enaDis.TOutCut)
  connect(hOutCut.y, enaDis.hOutCut)
  connect(freProSta.y, enaDis.uFreProSta)
  connect(outDamPosMax.y, enaDis.uOutDam_max)
  connect(outDamPosMin.y, enaDis.uOutDam_min)
  connect(retDamPhyPosMax.y, enaDis.uRetDamPhy_max)
  connect(retDamPosMax.y, enaDis.uRetDam_max)
  connect(retDamPosMin.y, enaDis.uRetDam_min)
  connect(TOutCut1.y, enaDis1.TOutCut)
  connect(hOutCut1.y, enaDis1.hOutCut)
  connect(hOutBelowCutoff.y, enaDis.hOut)
  connect(TOutBelowCutoff.y, enaDis1.TOut)
  connect(freProSta.y, enaDis1.uFreProSta)
  connect(outDamPosMax.y, enaDis1.uOutDam_max)
  connect(outDamPosMin.y, enaDis1.uOutDam_min)
  connect(retDamPhyPosMax.y, enaDis1.uRetDamPhy_max)
  connect(retDamPosMax.y, enaDis1.uRetDam_max)
  connect(retDamPosMin.y, enaDis1.uRetDam_min)
  connect(TOutCut.y, enaDis2.TOutCut)
  connect(freProSta.y, enaDis2.uFreProSta)
  connect(outDamPosMax.y, enaDis2.uOutDam_max)
  connect(outDamPosMin.y, enaDis2.uOutDam_min)
  connect(retDamPhyPosMax.y, enaDis2.uRetDamPhy_max)
  connect(retDamPosMax.y, enaDis2.uRetDam_max)
  connect(retDamPosMin.y, enaDis2.uRetDam_min)
  connect(supFanSta.y, enaDis.u1SupFan)
  connect(supFanSta.y, enaDis1.u1SupFan)
  connect(supFanSta.y, enaDis2.u1SupFan)
  connect(TOut.y, enaDis.TOut)
  connect(TOut.y, enaDis2.TOut)
  connect(hOut.y, enaDis1.hOut)
end Enable_TOut_hOut;


Collection of validation models

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


Validation model for disabling the multi zone VAV AHU economizer modulation and damper position limit control loops. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller
for control signals which disable modulation control loop only (eco block)
and both minimum outdoor airflow and modulation control loops (eco1 block).

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Validation;
model Controller_Disable
  "Validation model for disabling the multi zone VAV AHU economizer modulation and damper position limit control loops"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller
    eco(
    final minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.SingleDamper,

    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefDamper,

    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

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

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

    final minOAConTyp=Buildings.Controls.OBC.CDL.Types.SimpleController.PI)
    "Multi zone VAV AHU economizer "

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller
    eco1(
    final minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.SingleDamper,

    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefDamper,

    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

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

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

    final minOAConTyp=Buildings.Controls.OBC.CDL.Types.SimpleController.PI)
    "Multi zone VAV AHU economizer"

protected
  final parameter Real TOutCutoff(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Outdoor temperature high limit cutoff";
  final parameter Real hOutCutoff(
    final unit="J/kg",
    final quantity="SpecificEnergy")=65100
    "Outdoor air enthalpy high limit cutoff";
  final parameter Real minVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.71
    "Example volumetric airflow setpoint, 15cfm/occupant, 100 occupants";
  final parameter Real VOutMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.61
    "Minimal measured volumetric airflow";
  final parameter Real incVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=(minVOutSet_flow - VOutMin_flow)*2.2
    "Maximum volumetric airflow increase during the example simulation";

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta(final k=true)
    "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage0)
    "Freeze protection status is 0"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta2(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage2)
    "Freeze protection stage is 2"
  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 hOutBelowCutoff(
    final k=hOutCutoff - 40000) "Outdoor air enthalpy is below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutBelowCutoff(
    final k=TOutCutoff - 30) "Outdoor air temperature is below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, example assumes 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow(
    final height=incVOutSet_flow,
    final offset=VOutMin_flow,
    final duration=1800) "Measured outdoor air volumetric airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uTSup(
    final duration=1800,
    final height=2,
    final offset=-1)
                    "Supply air temperature control signal"

equation
  connect(fanSta.y, eco.u1SupFan)
  connect(freProSta.y, eco.uFreProSta)
  connect(TOutBelowCutoff.y, eco.TOut)
  connect(VOut_flow.y, eco.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, eco.VOutMinSet_flow_normalized)
  connect(TOutBelowCutoff.y, eco1.TOut)
  connect(VOut_flow.y, eco1.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, eco1.VOutMinSet_flow_normalized)
  connect(fanSta.y, eco1.u1SupFan)
  connect(opeMod.y, eco.uOpeMod)
  connect(opeMod.y, eco1.uOpeMod)
  connect(uTSup.y, eco.uTSup)
  connect(uTSup.y, eco1.uTSup)
  connect(freProSta2.y, eco1.uFreProSta)
  connect(hOutBelowCutoff.y, eco1.hAirOut)
end Controller_Disable;


Validation model for multi zone VAV AHU economizer operation: damper modulation and minimum ooutdoor air requirement damper position limits. This example validates

Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller control loops:
minimum outdoor air damper position limits control loop (eco block) and modulation
control loop (eco1 block) for VOut_flow and TSup control signals.
Both control loops are enabled during the validation test.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Validation;
model Controller_Mod_DamLim
  "Validation model for multi zone VAV AHU economizer operation: damper modulation and minimum ooutdoor air requirement damper position limits"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller
    eco(
    final minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow,

    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan,

    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

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

    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1A)
    "Multi zone VAV AHU economizer"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Controller
    eco1(
    final minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure,

    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir,

    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

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

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

    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1)
    "Multi zone VAV AHU economizer"

protected
  final parameter Real TOutCutoff(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=297.15
    "Outdoor temperature high limit cutoff";

  final parameter Real minVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.71
    "Example volumetric airflow setpoint, 15cfm/occupant, 100 occupants";
  final parameter Real VOutMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.61
    "Minimal measured volumetric airflow";
  final parameter Real incVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=(minVOutSet_flow - VOutMin_flow)*2.2
    "Maximum volumetric airflow increase during the example simulation";

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta(final k=true)
    "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeProtectionStages.stage0)
    "Freeze protection status is 0"
  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 TOutBelowCutoff(
    final k=TOutCutoff - 5) "Outdoor air temperature is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VOutMinSet_flow(
    final k=minVOutSet_flow)
    "Outdoor airflow rate setpoint, example assumes 15cfm/occupant and 100 occupants"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow(
    final offset=VOutMin_flow,
    final duration=1800,
    final height=incVOutSet_flow) "Measured outdoor air volumetric airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uTSup(
    final duration=1800,
    final height=2,
    final offset=-1)
    "Supply air temperature control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supFanSpe(
    final duration=1800,
    final height=0.5,
    final offset=0.2) "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp dpDam2(
    final duration=1800,
    final offset=120,
    final height=52)  "Pressure accross outdoor air damper"

equation
  connect(fanSta.y, eco.u1SupFan)
  connect(freProSta.y, eco.uFreProSta)
  connect(opeMod.y, eco.uOpeMod)
  connect(TOutBelowCutoff.y, eco.TOut)
  connect(VOut_flow.y, eco.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, eco.VOutMinSet_flow_normalized)
  connect(TOutBelowCutoff.y, eco1.TOut)
  connect(VOutMinSet_flow.y, eco1.VOutMinSet_flow_normalized)
  connect(fanSta.y, eco1.u1SupFan)
  connect(freProSta.y, eco1.uFreProSta)
  connect(opeMod.y, eco1.uOpeMod)
  connect(uTSup.y, eco.uTSup)
  connect(uTSup.y, eco1.uTSup)
  connect(supFanSpe.y, eco.uSupFan)
  connect(supFanSpe.y, eco1.uSupFan)
  connect(dpDam2.y, eco1.dpMinOutDam)
end Controller_Mod_DamLim;


Collection of validation models

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


Freeze protection sequence for multizone air handling unit. Freeze protection sequence for multizone AHU system. It is developed based on Section
5.16.12 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.SetPoints;
block FreezeProtection
  "Freeze protection sequence for multizone air handling unit"

  parameter Boolean have_frePro=true
    "True: enable freeze protection"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl buiPreCon=
      Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefDamper
    "Type of building pressure control system"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
    "Design of minimum outdoor air and economizer function"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat freSta=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.No_freeze_stat
    "Type of freeze stat"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Heating coil type"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil cooCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Cooling coil type"
  parameter Integer minHotWatReq=2
    "Minimum heating hot-water plant request to active the heating plant"
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController heaCoiCon=Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Heating coil controller"
  parameter Real k(unit="1")=1
    "Gain of coil controller"
  parameter Real Ti(unit="s")=0.5
    "Time constant of integrator block"
  parameter Real Td(unit="s")=0.1
    "Time constant of derivative block"
  parameter Real yMax=1
    "Upper limit of output"
  parameter Real yMin=0
    "Lower limit of output"
  parameter Real Thys(unit="K")=0.25
    "Hysteresis for checking temperature difference"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDamPosMin(
    final min=0,
    final max=1,
    final unit="1") if have_frePro
    "Minimum economizer damper position limit as returned by the damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDam(
    final min=0,
    final max=1,
    final unit="1") "Economizer outdoor air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uHeaCoi(
    final min=0,
    final max=1,
    final unit="1")
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric)
    "Heating coil commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uMinOutDam(
    final min=0,
    final max=1,
    final unit="1")
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
    "Minimum outdoor air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1MinOutDam
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
    "Minimum outdoor air damper command on position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDam(
    final min=0,
    final max=1,
    final unit="1") "Economizer return air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TAirSup(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if have_frePro
    "Measured supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1FreSta if freSta ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_BAS and
    have_frePro
    "Freeze protection stat signal. The stat is normally close (the input is normally true), when enabling freeze protection, the input becomes false"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1SofSwiRes if (freSta ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.No_freeze_stat or freSta ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Freeze protection reset signal from software switch"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1SupFan
    "Supply fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uSupFan(
    final min=0,
    final max=1,
    final unit="1")
    "Supply fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1RetFan if (buiPreCon ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
    "Return fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetFan(
    final min=0,
    final max=1,
    final unit="1") if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
    "Return fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1RelFan if buiPreCon ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "Relief fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRelFan(
    final min=0,
    final max=1,
    final unit="1")
    if buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "Relief fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCooCoi(
    final min=0,
    final max=1,
    final unit="1")
    if (cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
     or cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.DXCoil)
    "Cooling coil commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TAirMix(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric)
        and have_frePro
    "Measured mixed air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yFreProSta
    "Freeze protection stage index"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1EneCHWPum
    if have_frePro
    "Commanded on to energize chilled water pump"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDam(
    final min=0,
    final max=1,
    final unit="1")
    "Return air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDam(
    final min=0,
    final max=1,
    final unit="1")
    "Outdoor air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yMinOutDam(
    final min=0,
    final max=1,
    final unit="1")
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
    "Minimum outdoor air damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1MinOutDam
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
    "Minimum outdoor air damper command on position"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1SupFan
    "Supply fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput ySupFan(
    final min=0,
    final max=1,
    final unit="1")
    "Supply fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RetFan if (buiPreCon ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
    "Return fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetFan(
    final min=0,
    final max=1,
    final unit="1")
    if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
        or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
    "Return fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RelFan if buiPreCon ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "Relief fan commanded on"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RelDam if buiPreCon ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "True: 2-position relief damper is commanded open"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRelFan(
    final min=0,
    final max=1,
    final unit="1")
    if buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "Relief fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCooCoi(
    final min=0,
    final max=1,
    final unit="1")
    if (cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
     or cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.DXCoil)
    "Cooling coil commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yHeaCoi(
    final min=0,
    final max=1,
    final unit="1")
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric)
    "Heating coil commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotWatPlaReq
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Request to heating hot-water plant"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yAla if have_frePro
    "Alarm level"

protected
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr(
    final t=273.15 + 4.4,
    final h=Thys) if have_frePro
    "Check if supply air temperature is less than threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer tim(
    final t=300) if have_frePro
    "Check if the supply air temperature has been lower than threshold value for sufficient long time"
  Buildings.Controls.OBC.CDL.Integers.Switch hotWatPlaReq if heaCoi ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased and
    have_frePro
    "Hot water plant request in stage 1 mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=minHotWatReq)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased and have_frePro
    "Minimum hot-water plant requests"
  Buildings.Controls.OBC.CDL.Reals.Switch minVen if have_frePro
    "Minimum ventilation when in stage 1 mode"
  Buildings.Controls.OBC.CDL.Reals.PID heaCoiCon1(
    final controllerType=heaCoiCon,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final yMax=yMax,
    final yMin=yMin)
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Heating coil control in stage 1 mode"
  Buildings.Controls.OBC.CDL.Reals.Switch heaCoi1
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Heating coil position"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=273.15 + 7,
    final h=Thys) if have_frePro
    "Check if supply air temperature is greater than threshold"
  Buildings.Controls.OBC.CDL.Logical.Latch lat if have_frePro
    "Stay in stage 1 freeze protection mode"
  Buildings.Controls.OBC.CDL.Logical.Timer tim1(
    final t=300) if have_frePro
    "Check if the supply air temperature has been lower than threshold value for sufficient long time"
  Buildings.Controls.OBC.CDL.Logical.Edge endStaOne if have_frePro
    "Clear the latch to end the stage 1 freeze protection"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr1(
    final t=273.15 + 3.3,
    final h=Thys) if have_frePro
    "Check if supply air temperature is less than threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer tim2(
    final t=300) if have_frePro
    "Check if the supply air temperature has been lower than threshold value for sufficient long time"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold holSta2(
    final trueHoldDuration=3600,
    final falseHoldDuration=0) if have_frePro
    "Stage in stage 2 freeze protection mode"
  Buildings.Controls.OBC.CDL.Reals.Switch outDam2 if have_frePro
    "Outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(
    final k=0) if have_frePro
    "Fully closed damper position"
  Buildings.Controls.OBC.CDL.Reals.Switch minOutDam2 if minOADes ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
     and have_frePro
    "Minimum outdoor air damper position"
  Buildings.Controls.OBC.CDL.Reals.Switch retDam2 if have_frePro
    "Return air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(
    final k=1) if have_frePro
    "Fully open damper or valve position"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi1 if have_frePro
    "Alarm when it is in stage 2 mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    final k=3) if have_frePro
    "Level 3 alarm"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=0) if heaCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
     and have_frePro
    "Zero request"
  Buildings.Controls.OBC.CDL.Logical.Timer tim3(
    final t=900) if have_frePro
    "Check if the supply air temperature has been lower than threshold value for sufficient long time"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr2(
    final t=273.15 + 1,
    final h=Thys) if have_frePro
    "Check if supply air temperature is less than threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer tim4(
    final t=300) if have_frePro
    "Check if the supply air temperature has been lower than threshold value for sufficient long time"
  Buildings.Controls.OBC.CDL.Logical.Or or8 if have_frePro
    "Check if it should be in stage 3 mode"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con2(
    final k=false) if not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_BAS
     and have_frePro
    "Constant false"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1 if have_frePro
    "Stay in stage 3 freeze protection mode"
  Buildings.Controls.OBC.CDL.Reals.Switch supFan if (not freSta ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Supply fan speed"
  Buildings.Controls.OBC.CDL.Reals.Switch retFan
     if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
     and (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Return fan speed"
  Buildings.Controls.OBC.CDL.Reals.Switch relFan if buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
     and (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Relief fan speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con3(
    final k=0) if have_frePro
    "Zero constant"
  Buildings.Controls.OBC.CDL.Reals.Switch outDam if (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Outdoor air damper"
  Buildings.Controls.OBC.CDL.Reals.Switch cooCoiVal if (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro and (cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
     or cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.DXCoil)
    "Cooling coil position"
  Buildings.Controls.OBC.CDL.Integers.Switch hotWatPlaReq3
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased and have_frePro
    "Hot water plant request in stage 3 mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    final k=minHotWatReq) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased and have_frePro
    "Minimum hot-water plant requests"
  Buildings.Controls.OBC.CDL.Reals.Max max1
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
       or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Higher of supply air and mixed air temperature"
  Buildings.Controls.OBC.CDL.Reals.PID heaCoiMod(
    final controllerType=heaCoiCon,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final yMax=yMax,
    final yMin=yMin)
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Heating coil control when it is in stage 3 mode"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con4(
    final k=273.15 + 27)
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch heaCoiPos
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and (
           not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
        and have_frePro
    "Heating coil position"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi3 if have_frePro
    "Alarm level"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    final k=2) if have_frePro
    "Level 2 alarm"
  Buildings.Controls.OBC.CDL.Utilities.Assert shuDowWar(
    final message="Warning: the unit is shut down by freeze protection!")
    if have_frePro
    "Unit shut down warning"
  Buildings.Controls.OBC.CDL.Logical.Not not1 if have_frePro
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert disMinVenWar(
    final message="Warning: minimum ventilation was interrupted by freeze protection!")
    if have_frePro
    "Warning of disabling minimum ventilation "
  Buildings.Controls.OBC.CDL.Logical.Not not2 if have_frePro
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Timer tim5(
    final t=3600) if have_frePro
    "Check if it has been in stage 2 for sufficient long time"
  Buildings.Controls.OBC.CDL.Reals.Switch minOutDam if minOADes ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
     and (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Minimum outdoor air damper position"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt5(
    final k=0) if have_frePro
    "Level 0 alarm"
  Buildings.Controls.OBC.CDL.Logical.Latch lat2 if have_frePro
    "Stay in stage 2 freeze protection mode"
  Buildings.Controls.OBC.CDL.Logical.Edge endStaTwo if have_frePro
    "Clear the latch to end the stage 2 freeze protection"
  Buildings.Controls.OBC.CDL.Logical.Or or2 if have_frePro
    "Start stage 1 freeze protection mode"
  Buildings.Controls.OBC.CDL.Reals.Switch retDam
    if (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
        and have_frePro
    "Return air damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supTemSet(
    final k=273.15+ 6)
    if (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
        or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric) and have_frePro
    "Supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi2 if have_frePro
    "Alarm level"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi4 if have_frePro
    "Alarm level"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt6(
    final k=2) if have_frePro
    "Stage 2 freeze protection"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi5 if have_frePro
    "Alarm level"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt7(
    final k=1) if have_frePro
    "Stage 1 freeze protection"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt8(
    final k=0) if have_frePro
    "Stage 0 freeze protection"
  Buildings.Controls.OBC.CDL.Logical.Switch minOutDam3
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
     and have_frePro
    "Minimum outdoor air damper command on position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con5(
    final k=false)
    if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
       and have_frePro
    "False"
  Buildings.Controls.OBC.CDL.Logical.Switch minOutDam1 if (minOADes ==
    Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
     and not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Minimum outdoor air damper command on position"
  Buildings.Controls.OBC.CDL.Logical.Not norFal
    if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_BAS
     and have_frePro
    "The output is normally false"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_BAS
     and have_frePro
    "Reset the freeze protection by the physical reset switch in freeze stat"
  Buildings.Controls.OBC.CDL.Logical.And and1
    if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
     and (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Disable return fan when in stage 3"
  Buildings.Controls.OBC.CDL.Logical.Not norSta3
    if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
     and have_frePro
    "Not in stage 3"
  Buildings.Controls.OBC.CDL.Logical.Not norSta1 if have_frePro
    "Not in stage 3"
  Buildings.Controls.OBC.CDL.Logical.And and2
    if (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Disable supply fan when in stage 3"
  Buildings.Controls.OBC.CDL.Logical.Not norSta2 if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan)
     and have_frePro
    "Not in stage 3"
  Buildings.Controls.OBC.CDL.Logical.And and3 if buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
     and (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Disable relief fan when in stage 3"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=1)
    if ((heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
      or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric)
      and freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(
    final k=1) if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment
     and have_frePro and (cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
     or cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.DXCoil)
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai2(
    final k=1) if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
     and freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Logical.Or or1 if buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
     and (not ((not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro))
    "Dummy block for enabling and disabling conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai3(
    final k=1) if ((buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
     and freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Logical.Or or4 if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
     and not ((not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro)
    "Dummy block for enabling and disabling conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai4(
    final k=1) if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai5(
    final k=1) if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai6(
    final k=1) if (minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
     and freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Logical.Or or5 if minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersPressure
     and (not (not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment
     and have_frePro))
    "Dummy block for enabling and disabling conditional connection"
  Buildings.Controls.OBC.CDL.Logical.Or or6 if not ((not freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment)
     and have_frePro)
    "Dummy block for enabling and disabling conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai7(
    final k=1) if freSta == Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.Hardwired_to_equipment
     and have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai8(final k=1)
    if not have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt9(final k=0)
    if not have_frePro "Dummy constant"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai9(final k=1)
    if not have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai10(final k=1) if (not
    have_frePro) and minOADes == Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.DedicatedDampersAirflow
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai11(final k=1)
    if not have_frePro
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai12(final k=1) if (not
    have_frePro) and (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai13(final k=1) if (not
    have_frePro) and buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReliefFan
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai14(final k=1) if (not
    have_frePro) and (cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
     or cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.DXCoil)
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai15(final k=1)
    if (not have_frePro) and (heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
                              or heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.Electric)
    "Dummy block for enabling and disabling the conditional connection"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt10(final k=0)
    if (not have_frePro) and heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Dummy constant"
  Buildings.Controls.OBC.CDL.Logical.Or or7 if have_frePro
    "Check if it should be in stage 3 mode"

equation
  connect(lesThr.y, tim.u)
  connect(TAirSup, lesThr.u)
  connect(conInt.y, hotWatPlaReq.u1)
  connect(uOutDamPosMin, minVen.u1)
  connect(supTemSet.y, heaCoiCon1.u_s)
  connect(TAirSup, heaCoiCon1.u_m)
  connect(heaCoiCon1.y, heaCoi1.u1)
  connect(TAirSup, greThr.u)
  connect(greThr.y, tim1.u)
  connect(tim1.passed, endStaOne.u)
  connect(endStaOne.y, lat.clr)
  connect(lat.y, hotWatPlaReq.u2)
  connect(lat.y, minVen.u2)
  connect(lat.y, heaCoi1.u2)
  connect(TAirSup, lesThr1.u)
  connect(lesThr1.y, tim2.u)
  connect(tim2.passed, holSta2.u)
  connect(con.y, outDam2.u1)
  connect(con.y, minOutDam2.u1)
  connect(con1.y, retDam2.u1)
  connect(uRetDam, retDam2.u3)
  connect(conInt1.y, intSwi1.u1)
  connect(lesThr1.y, tim3.u)
  connect(lesThr2.y, tim4.u)
  connect(TAirSup, lesThr2.u)
  connect(u1SofSwiRes, lat1.clr)
  connect(lat1.y, supFan.u2)
  connect(lat1.y, retFan.u2)
  connect(lat1.y, relFan.u2)
  connect(con3.y, supFan.u1)
  connect(con3.y, retFan.u1)
  connect(con3.y, relFan.u1)
  connect(uSupFan, supFan.u3)
  connect(uRetFan, retFan.u3)
  connect(uRelFan, relFan.u3)
  connect(supFan.y, ySupFan)
  connect(relFan.y, yRelFan)
  connect(retFan.y, yRetFan)
  connect(con3.y, outDam.u1)
  connect(lat1.y, outDam.u2)
  connect(uCooCoi, cooCoiVal.u3)
  connect(lat1.y, cooCoiVal.u2)
  connect(con1.y, cooCoiVal.u1)
  connect(conInt3.y, hotWatPlaReq3.u1)
  connect(lat1.y, hotWatPlaReq3.u2)
  connect(TAirMix, max1.u2)
  connect(TAirSup, max1.u1)
  connect(max1.y, heaCoiMod.u_m)
  connect(con4.y, heaCoiMod.u_s)
  connect(heaCoiMod.y, heaCoiPos.u1)
  connect(lat1.y, heaCoiPos.u2)
  connect(lat1.y, intSwi3.u2)
  connect(conInt4.y, intSwi3.u1)
  connect(lat1.y, not1.u)
  connect(not1.y, shuDowWar.u)
  connect(not2.y, disMinVenWar.u)
  connect(holSta2.y, tim5.u)
  connect(lat1.y, minOutDam.u2)
  connect(con3.y, minOutDam.u1)
  connect(uOutDam, minVen.u3)
  connect(minVen.y, outDam2.u3)
  connect(outDam2.y, outDam.u3)
  connect(conInt2.y, hotWatPlaReq.u3)
  connect(conInt5.y, intSwi1.u3)
  connect(intSwi1.y, intSwi3.u3)
  connect(intSwi3.y, yAla)
  connect(hotWatPlaReq.y, hotWatPlaReq3.u3)
  connect(hotWatPlaReq3.y, yHotWatPlaReq)
  connect(minOutDam2.y, minOutDam.u3)
  connect(minOutDam.y, yMinOutDam)
  connect(uMinOutDam, minOutDam2.u3)
  connect(uHeaCoi, heaCoi1.u3)
  connect(heaCoi1.y, heaCoiPos.u3)
  connect(heaCoiPos.y, yHeaCoi)
  connect(holSta2.y, lat2.u)
  connect(tim5.passed, endStaTwo.u)
  connect(endStaTwo.y, lat2.clr)
  connect(lat2.y, outDam2.u2)
  connect(lat2.y, minOutDam2.u2)
  connect(lat2.y, not2.u)
  connect(lat2.y, retDam2.u2)
  connect(lat2.y, intSwi1.u2)
  connect(tim.passed, or2.u1)
  connect(or2.y, lat.u)
  connect(lat1.y, retDam.u2)
  connect(con3.y, retDam.u1)
  connect(retDam2.y, retDam.u3)
  connect(retDam.y, yRetDam)
  connect(lat1.y, y1EneCHWPum)
  connect(outDam.y, yOutDam)
  connect(cooCoiVal.y, yCooCoi)
  connect(conInt1.y, intSwi2.u1)
  connect(lat1.y, intSwi2.u2)
  connect(lat2.y, intSwi4.u2)
  connect(conInt6.y, intSwi4.u1)
  connect(intSwi4.y, intSwi2.u3)
  connect(lat.y, intSwi5.u2)
  connect(intSwi5.y, intSwi4.u3)
  connect(conInt7.y, intSwi5.u1)
  connect(intSwi2.y, yFreProSta)
  connect(conInt8.y, intSwi5.u3)
  connect(endStaTwo.y, or2.u2)
  connect(u1MinOutDam, minOutDam3.u3)
  connect(lat2.y, minOutDam3.u2)
  connect(con5.y, minOutDam3.u1)
  connect(lat1.y, minOutDam1.u2)
  connect(minOutDam1.y, y1MinOutDam)
  connect(minOutDam3.y, minOutDam1.u3)
  connect(con5.y, minOutDam1.u1)
  connect(u1FreSta,norFal. u)
  connect(or8.y, lat1.u)
  connect(falEdg.y, lat1.clr)
  connect(u1RetFan, and1.u1)
  connect(and1.y, y1RetFan)
  connect(norSta3.y, and1.u2)
  connect(lat1.y, norSta3.u)
  connect(u1SupFan, and2.u1)
  connect(and2.y, y1SupFan)
  connect(norSta1.y, and2.u2)
  connect(lat1.y, norSta1.u)
  connect(u1RelFan, and3.u1)
  connect(and3.y, y1RelFan)
  connect(norSta2.y,and3. u2)
  connect(lat1.y, norSta2.u)
  connect(uHeaCoi, gai.u)
  connect(gai.y, yHeaCoi)
  connect(uCooCoi, gai1.u)
  connect(gai1.y, yCooCoi)
  connect(uRelFan, gai2.u)
  connect(gai2.y, yRelFan)
  connect(u1RelFan, or1.u1)
  connect(u1RelFan, or1.u2)
  connect(or1.y, y1RelFan)
  connect(uRetFan, gai3.u)
  connect(gai3.y, yRetFan)
  connect(u1RetFan, or4.u1)
  connect(u1RetFan, or4.u2)
  connect(or4.y, y1RetFan)
  connect(uRetDam, gai4.u)
  connect(gai4.y, yRetDam)
  connect(uOutDam, gai5.u)
  connect(gai5.y, yOutDam)
  connect(uMinOutDam, gai6.u)
  connect(gai6.y, yMinOutDam)
  connect(u1MinOutDam, or5.u1)
  connect(u1MinOutDam, or5.u2)
  connect(or5.y, y1MinOutDam)
  connect(u1SupFan, or6.u1)
  connect(u1SupFan, or6.u2)
  connect(or6.y, y1SupFan)
  connect(uSupFan, gai7.u)
  connect(gai7.y, ySupFan)
  connect(norFal.y, falEdg.u)
  connect(conInt9.y, yFreProSta)
  connect(gai8.y, yRetDam)
  connect(gai9.y, yOutDam)
  connect(uRetDam, gai8.u)
  connect(uOutDam, gai9.u)
  connect(gai10.y, yMinOutDam)
  connect(uMinOutDam, gai10.u)
  connect(gai11.y, ySupFan)
  connect(uSupFan, gai11.u)
  connect(uRetFan, gai12.u)
  connect(gai12.y, yRetFan)
  connect(uRelFan, gai13.u)
  connect(gai13.y, yRelFan)
  connect(uCooCoi, gai14.u)
  connect(gai14.y, yCooCoi)
  connect(gai15.y, yHeaCoi)
  connect(uHeaCoi, gai15.u)
  connect(conInt10.y, yHotWatPlaReq)
  connect(or1.y, y1RelDam)
  connect(and3.y, y1RelDam)
  connect(tim3.passed, or7.u1)
  connect(tim4.passed, or7.u2)
  connect(or7.y, or8.u1)
  connect(norFal.y, or8.u2)
  connect(con2.y, or8.u2)
end FreezeProtection;


Output setpoints for AHU control

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV;
package SetPoints "Output setpoints for AHU control"
end SetPoints;


Output plant requests for multizone air handling unit. This sequence outputs the system reset requests for multiple zone air handling unit. The
implementation is according to the Section 5.16.16 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.SetPoints;
block PlantRequests "Output plant requests for multizone air handling unit"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Heating coil type"
  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil cooCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Cooling coil type"
  parameter Real Thys = 0.1
    "Hysteresis for checking temperature difference"
  parameter Real posHys = 0.05
    "Hysteresis for checking valve position difference"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TAirSup(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TAirSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Setpoint for supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCooCoiSet(
    final unit="1",
    final min=0,
    final max=1)
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Commanded ooling coil valve position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uHeaCoiSet(
    final unit="1",
    final min=0,
    final max=1) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Commanded heating coil valve position"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yChiWatResReq
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Chilled water reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yChiPlaReq
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Chiller plant request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotWatResReq
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Hot water reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotWatPlaReq
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Hot water plant request"

protected
  Buildings.Controls.OBC.CDL.Reals.Subtract cooSupTemDif
    "Find the cooling supply temperature difference to the setpoint"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=3,
    final h=Thys)
    "Check if the supply temperature is greater than the setpoint by a threshold value"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1(
    final t=2,
    final h=Thys)
    "Check if the supply temperature is greater than the setpoint by a threshold value"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel(
    final delayTime=120)
    "Check if the input has been true for a certain time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel1(
    final delayTime=120)
    "Check if the input has been true for a certain time"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2(
    final t=0.95,
    final h=posHys)
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Check if the chilled water valve position is greater than a threshold value"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant thr(
    final k=3) "Constant 3"
  Buildings.Controls.OBC.CDL.Integers.Switch chiWatRes3
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Send 3 chilled water reset request"
  Buildings.Controls.OBC.CDL.Integers.Switch chiWatRes2
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Send 2 chilled water reset request"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant two(
    final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr(
    final t=0.85,
    final h=posHys)
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Check if the chilled water valve position is less than a threshold value"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Keep true signal until other condition becomes true"
  Buildings.Controls.OBC.CDL.Integers.Switch chiWatRes1
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Send 1 chilled water reset request"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant one(
    final k=1) "Constant 1"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant zer(
    final k=0) "Constant 0"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Keep true signal until other condition becomes true"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr1(
    final t=0.1,
    final h=posHys)
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Check if the chilled water valve position is less than a threshold value"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi3
    if cooCoi == Buildings.Controls.OBC.ASHRAE.G36.Types.CoolingCoil.WaterBased
    "Send 1 chiller plant request"
  Buildings.Controls.OBC.CDL.Reals.Subtract heaSupTemDif
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Find the heating supply temperature difference to the setpoint"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr3(
    final t=17,
    final h=Thys)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the supply temperature is less than the setpoint by a threshold value"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr4(
    final t=8,
    final h=Thys)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the supply temperature is less than the setpoint by a threshold value"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel2(
    final delayTime=300) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the input has been true for a certain time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel3(
    final delayTime=300) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the input has been true for a certain time"
  Buildings.Controls.OBC.CDL.Integers.Switch hotWatRes3
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Send 3 hot water reset request"
  Buildings.Controls.OBC.CDL.Integers.Switch hotWatRes2
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Send 2 hot water reset request"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr2(
    final t=0.85,
    final h=posHys)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the hot water valve position is less than a threshold value"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr5(
    final t=0.95,
    final h=posHys)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the hot water valve position is greater than a threshold value"
  Buildings.Controls.OBC.CDL.Logical.Latch lat2
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Keep true signal until other condition becomes true"
  Buildings.Controls.OBC.CDL.Integers.Switch hotWatRes1
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Send 1 hot water reset request"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr3(
    final t=0.1,
    final h=posHys)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the hot water valve position is less than a threshold value"
  Buildings.Controls.OBC.CDL.Logical.Latch lat3
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Keep true signal until other condition becomes true"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi1
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Send 1 hot water plant request"

equation
  connect(TAirSup, cooSupTemDif.u1)
  connect(TAirSupSet, cooSupTemDif.u2)
  connect(cooSupTemDif.y, greThr.u)
  connect(greThr.y, truDel.u)
  connect(greThr1.y, truDel1.u)
  connect(cooSupTemDif.y, greThr1.u)
  connect(uCooCoiSet, greThr2.u)
  connect(truDel.y, chiWatRes3.u2)
  connect(thr.y, chiWatRes3.u1)
  connect(truDel1.y, chiWatRes2.u2)
  connect(two.y, chiWatRes2.u1)
  connect(greThr2.y, lat.u)
  connect(uCooCoiSet, lesThr.u)
  connect(lesThr.y, lat.clr)
  connect(one.y, chiWatRes1.u1)
  connect(lat.y, chiWatRes1.u2)
  connect(chiWatRes1.y, chiWatRes2.u3)
  connect(chiWatRes2.y, chiWatRes3.u3)
  connect(zer.y, chiWatRes1.u3)
  connect(chiWatRes3.y, yChiWatResReq)
  connect(greThr2.y, lat1.u)
  connect(uCooCoiSet, lesThr1.u)
  connect(lesThr1.y, lat1.clr)
  connect(lat1.y, intSwi3.u2)
  connect(one.y, intSwi3.u1)
  connect(zer.y, intSwi3.u3)
  connect(intSwi3.y, yChiPlaReq)
  connect(TAirSupSet, heaSupTemDif.u1)
  connect(TAirSup, heaSupTemDif.u2)
  connect(greThr3.y, truDel2.u)
  connect(greThr4.y, truDel3.u)
  connect(heaSupTemDif.y, greThr3.u)
  connect(heaSupTemDif.y, greThr4.u)
  connect(truDel2.y, hotWatRes3.u2)
  connect(thr.y, hotWatRes3.u1)
  connect(hotWatRes2.y, hotWatRes3.u3)
  connect(two.y, hotWatRes2.u1)
  connect(truDel3.y, hotWatRes2.u2)
  connect(hotWatRes3.y, yHotWatResReq)
  connect(uHeaCoiSet, greThr5.u)
  connect(greThr5.y, lat2.u)
  connect(uHeaCoiSet, lesThr2.u)
  connect(lesThr2.y, lat2.clr)
  connect(lat2.y, hotWatRes1.u2)
  connect(one.y, hotWatRes1.u1)
  connect(zer.y, hotWatRes1.u3)
  connect(hotWatRes1.y, hotWatRes2.u3)
  connect(uHeaCoiSet, lesThr3.u)
  connect(lesThr3.y, lat3.clr)
  connect(greThr5.y, lat3.u)
  connect(lat3.y, intSwi1.u2)
  connect(one.y, intSwi1.u1)
  connect(zer.y, intSwi1.u3)
  connect(intSwi1.y, yHotWatPlaReq)
end PlantRequests;


Relief damper control for AHUs using actuated dampers without fan. Sequence for controlling actuated relief damper yRelDam for AHUs using
actuated relief damper without a fan.
It is implemented according to Section 5.16.8 of ASHRAE Guideline G36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.SetPoints;
block ReliefDamper
  "Relief damper control for AHUs using actuated dampers without fan"
  parameter Real dpBuiSet(
    final unit="Pa",
    final quantity="PressureDifference",
    max=30) = 12
    "Building static pressure difference relative to ambient (positive to pressurize the building)"
  parameter Real k(min=0, unit="1") = 0.5
    "Gain, applied to building pressure control error normalized with dpBuiSet"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput dpBui(
    final unit="Pa",
    displayUnit="Pa")
    "Building static pressure difference, relative to ambient (positive if pressurized)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1SupFan
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRelDam(
    final unit="1",
    final min=0,
    final max=1) "Relief damper commanded position"

protected
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Check if relief damper should be enabled"
  Buildings.Controls.OBC.CDL.Reals.Subtract conErr(
    u1(final unit="Pa", displayUnit="Pa"),
    u2(final unit="Pa", displayUnit="Pa"),
    y(final unit="Pa", displayUnit="Pa"))
    "Control error"
  Buildings.Controls.OBC.CDL.Reals.PID conP(
    final controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P,
    final k=k,
    final reverseActing=false)
    "Building static pressure controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerDam(
    final k=0)
    "Close damper when disabled"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant dpBuiSetPoi(
    final k=dpBuiSet) "Building pressure setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(
    final k=0)
    "Zero constant"

equation
  connect(u1SupFan, swi.u2)
  connect(dpBuiSetPoi.y, conErr.u2)
  connect(conErr.y, conP.u_m)
  connect(zer.y, conP.u_s)
  connect(conP.y, swi.u1)
  connect(zerDam.y, swi.u3)
  connect(dpBui, conErr.u1)
  connect(swi.y, yRelDam)
end ReliefDamper;


Sequence for control of relief fan in AHU. Sequence for controling relief fan that is part of AHU. It is developed based on
Section 5.16.9 of ASHRAE Guideline 36, May 2020, with the modification to accommodate
the single relief fan control.

within Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.SetPoints;
block ReliefFan "Sequence for control of relief fan in AHU"

  parameter Real relFanSpe_min(
    final min=0,
    final max=1)= 0.1
    "Relief fan minimum speed"
  parameter Real dpBuiSet(
    final unit="Pa",
    final quantity="PressureDifference",
    final max=30) = 12
    "Building static pressure difference relative to ambient (positive to pressurize the building)"
  parameter Real k(
    final unit="1") = 1
    "Gain, normalized using dpBuiSet"
  parameter Real hys = 0.005
    "Hysteresis for checking the controller output value"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput dpBui(
    final unit="Pa",
    displayUnit="Pa",
    final quantity="PressureDifference")
    "Building static pressure difference, relative to ambient (positive if pressurized)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1SupFan
    "AHU supply fan proven on status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDpBui(
    final unit="Pa",
    displayUnit="Pa",
    final quantity="PressureDifference")
    "Building static pressure difference, relative to ambient (positive if pressurized)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RelDam
    "True: 2-position relief damper commanded open"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRelFan(
    final unit="1",
    final max=1)
    "Relief fan commanded speed"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RelFan
    "Relief fan commanded on"

  Buildings.Controls.OBC.CDL.Reals.MovingAverage movMea(
    final delta=300)
    "Average building static pressure measurement"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant dpBuiSetPoi(
    final k=dpBuiSet)
    "Building pressure setpoint"
  Buildings.Controls.OBC.CDL.Reals.Divide div1
    "Normalized the control error"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conOne(
    final k=1)
    "Constant one"
  Buildings.Controls.OBC.CDL.Reals.PID conP(
    final controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P,
    final k=k,
    final reverseActing=false)
    "Building static pressure controller"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=0.05,
    final h=hys)
    "Check if the controller output is greater than threshold"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr(
    final t=0.005,
    final h=hys)
    "Check if the controller output is near zero"
  Buildings.Controls.OBC.CDL.Logical.Timer tim(
    final t=300)
    "Check if the controller output has been near zero for threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Check if the controller output is greater than threshold and the relief system has been enabled"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    "Enable damper"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2(
    final t=relFanSpe_min + 0.15,
    final h=hys)
    "Check if the controller output is greater than minimum speed plus threshold"
  Buildings.Controls.OBC.CDL.Logical.Timer upTim(
    final t=420)
    "Check if the controller output has been greater than threshold for sufficient long time"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold lesThr3(
    final t=relFanSpe_min,
    final h=hys)
    "Check if the controller output is less than minimum speed"
  Buildings.Controls.OBC.CDL.Logical.Timer dowTim(
    final t=300)
    "Check if the controller output has been less than threshold for sufficient long time"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1
    "Stage down lag fan"
  Buildings.Controls.OBC.CDL.Logical.Or relDam
    "Open relief damper"
  Buildings.Controls.OBC.CDL.Logical.And relFan
    "Turn on relief fan"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea2
    "Convert boolean to real"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro1 "Relief fan speed"

equation
  connect(dpBui, movMea.u)
  connect(dpBuiSetPoi.y, div1.u2)
  connect(movMea.y, div1.u1)
  connect(div1.y, conP.u_m)
  connect(conOne.y, conP.u_s)
  connect(conP.y, greThr.u)
  connect(greThr.y, and2.u1)
  connect(conP.y, lesThr.u)
  connect(lesThr.y, tim.u)
  connect(tim.passed, lat.clr)
  connect(and2.y, lat.u)
  connect(u1SupFan, and2.u2)
  connect(conP.y, greThr2.u)
  connect(greThr2.y, upTim.u)
  connect(conP.y, lesThr3.u)
  connect(lesThr3.y, dowTim.u)
  connect(upTim.passed, lat1.u)
  connect(dowTim.passed, lat1.clr)
  connect(lat.y, relDam.u1)
  connect(u1SupFan, relFan.u1)
  connect(lat1.y, relFan.u2)
  connect(relFan.y, relDam.u2)
  connect(relFan.y, booToRea2.u)
  connect(booToRea2.y, pro1.u2)
  connect(conP.y, pro1.u1)
  connect(movMea.y, yDpBui)
  connect(pro1.y, yRelFan)
  connect(relFan.y, y1RelFan)
  connect(relDam.y, y1RelDam)
end ReliefFan;