Multi zone VAV AHU economizer control sequence. Multi zone VAV AHU economizer control sequence that calculates
outdoor and return air damper positions based on ASHRAE
Guidline 36, PART 5 sections: N.2.c, N.5, N.6.c, N.7, A.17, N.12.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers;
block Controller "Multi zone VAV AHU economizer control sequence"

  parameter Boolean use_enthalpy=false
    "Set to true if enthalpy measurement is used in addition to temperature measurement";
  parameter Boolean use_TMix=true
    "Set to true if mixed air temperature measurement is enabled";
  parameter Boolean use_G36FrePro=false
    "Set to true to use G36 freeze protection";
  parameter Real delTOutHis(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=1
    "Delta between the temperature hysteresis high and low limit"
  parameter Real delEntHis(
    final unit="J/kg",
    final quantity="SpecificEnergy")=1000
    "Delta between the enthalpy hysteresis high and low limits"
  parameter Real retDamFulOpeTim(
    final unit="s",
    final quantity="Time")=180
    "Time period to keep RA damper fully open before releasing it for minimum outdoor airflow control at disable to avoid pressure fluctuations"
  parameter Real disDel(
    final unit="s",
    final quantity="Time")=15
    "Short time delay before closing the OA damper at disable to avoid pressure fluctuations"

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

  parameter Real kMinOut(final unit="1")=0.05
    "Gain of controller for minimum outdoor air"
  parameter Real TiMinOut(
    final unit="s",
    final quantity="Time")=120
    "Time constant of controller for minimum outdoor air intake"
  parameter Real TdMinOut(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for minimum outdoor air intake"

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

  parameter Real TFreSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")= 279.15
    "Lower limit for mixed air temperature for freeze protection, used if use_TMix=true"
  parameter Real kFre(final unit="1/K") = 0.1
    "Gain for mixed air temperature tracking for freeze protection, used if use_TMix=true"

  parameter Real TiFre(
    final unit="s",
    final quantity="Time",
    final max=TiMinOut)=120
    "Time constant of controller for mixed air temperature tracking for freeze protection. Require TiFre <= TiMinOut"

  parameter Real TdFre(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for freeze protection"

  parameter Real delta(
    final unit="s",
    final quantity="Time")=5
    "Time horizon over which the outdoor air flow measurment is averaged";
  parameter Real uHeaMax=-0.25
    "Lower limit of controller input when outdoor damper opens for modulation control. Require -1 < uHeaMax < uCooMin < 1."
  parameter Real uCooMin=+0.25
    "Upper limit of controller input when return damper is closed for modulation control. Require -1 < uHeaMax < uCooMin < 1."

  parameter Real uOutDamMax(
    final min=-1,
    final max=1,
    final unit="1") = (uHeaMax + uCooMin)/2
    "Maximum loop signal for the OA damper to be fully open. Require -1 < uHeaMax < uOutDamMax <= uRetDamMin < uCooMin < 1."
  parameter Real uRetDamMin(
    final min=-1,
    final max=1,
    final unit="1") = (uHeaMax + uCooMin)/2
    "Minimum loop signal for the RA damper to be fully open. Require -1 < uHeaMax < uOutDamMax <= uRetDamMin < uCooMin < 1."

  parameter Real uRetDamMinLim(
    final min=0,
    final max=1,
    final unit="1") = 0.5
    "Loop signal value to start decreasing the maximum return air damper position"

  parameter Real retDamPhyPosMax(
    final min=0,
    final max=1,
    final unit="1") = 1
    "Physically fixed maximum position of the return air damper"
  parameter Real retDamPhyPosMin(
    final min=0,
    final max=1,
    final unit="1") = 0
    "Physically fixed minimum position of the return air damper"
  parameter Real outDamPhyPosMax(
    final min=0,
    final max=1,
    final unit="1") = 1
    "Physically fixed maximum position of the outdoor air damper"
  parameter Real outDamPhyPosMin(
    final min=0,
    final max=1,
    final unit="1") = 0
    "Physically fixed minimum position of the outdoor air damper"

  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 TOut(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") "Outdoor air (OA) temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TOutCut(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "OA temperature high limit cutoff. For differential dry bulb temeprature condition use return air temperature measurement"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput hOut(
    final unit="J/kg",
    final quantity="SpecificEnergy") if use_enthalpy "Outdoor air enthalpy"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput hOutCut(
    final unit="J/kg",
    final quantity="SpecificEnergy") if use_enthalpy
    "OA enthalpy high limit cutoff. For differential enthalpy use return air enthalpy measurement"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TMix(
    final unit="K",
    final displayUnit="degC",
    final quantity = "ThermodynamicTemperature") if use_TMix
    "Measured mixed air temperature, used for freeze protection"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOut_flow_normalized(
    final unit="1")
    "Measured outdoor volumetric airflow rate, normalized by design minimum outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOutMinSet_flow_normalized(
    final unit="1")
    "Effective minimum outdoor airflow setpoint, normalized by design minimum outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uFreProSta if use_G36FrePro
    "Freeze protection status"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "AHU operation mode status signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPos(
    final min=0,
    final max=1,
    final unit="1") "Return air damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDamPos(
    final min=0,
    final max=1,
    final unit="1") "Outdoor air damper position"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
    enaDis(
    final use_enthalpy=use_enthalpy,
    final delTOutHis=delTOutHis,
    final delEntHis=delEntHis,
    final retDamFulOpeTim=retDamFulOpeTim,
    final disDel=disDel)
    "Multi zone VAV AHU economizer enable/disable sequence"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
    damLim(
    final retDamPhyPosMax=retDamPhyPosMax,
    final retDamPhyPosMin=retDamPhyPosMin,
    final outDamPhyPosMax=outDamPhyPosMax,
    final outDamPhyPosMin=outDamPhyPosMin,
    final k=kMinOut,
    final Ti=TiMinOut,
    final Td=TdMinOut,
    final uRetDamMin=uRetDamMinLim,
    final controllerType=controllerTypeMinOut)
    "Multi zone VAV AHU economizer minimum outdoor air requirement damper limit sequence"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulation
    mod(
    final uRetDamMin=uRetDamMin,
    final uMin=uHeaMax,
    final uMax=uCooMin,
    final uOutDamMax=uOutDamMax)
    "Multi zone VAV AHU economizer damper modulation sequence"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.FreezeProtectionMixedAir
    freProTMix(
    final controllerType=controllerTypeFre,
    final TFreSet=TFreSet,
    final k=kFre,
    final Ti=TiFre,
    final Td=TdFre) if use_TMix
    "Block that tracks TMix against a freeze protection setpoint"

protected
  Buildings.Controls.OBC.CDL.Reals.MovingAverage movAve(final delta=delta)
    "Moving average of outdoor air flow measurement, normalized by design minimum outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Min outDamMaxFre
    "Maximum control signal for outdoor air damper due to freeze protection"
  Buildings.Controls.OBC.CDL.Reals.Max retDamMinFre
    "Minimum position for return air damper due to freeze protection"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant noTMix(k=0) if not use_TMix
    "Ignore max evaluation if there is no mixed air temperature sensor"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant noTMix1(k=1) if not use_TMix
    "Ignore min evaluation if there is no mixed air temperature sensor"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0)
                                                                                if not use_G36FrePro
    "Freeze protection status is 0. Use if G36 freeze protection is not implemented"

equation
  connect(uSupFan, enaDis.uSupFan)
  connect(uFreProSta, enaDis.uFreProSta)
  connect(hOutCut, enaDis.hOutCut)
  connect(hOut, enaDis.hOut)
  connect(TOutCut, enaDis.TOutCut)
  connect(TOut, enaDis.TOut)
  connect(VOutMinSet_flow_normalized, damLim.VOutMinSet_flow_normalized)
  connect(uSupFan, damLim.uSupFan)
  connect(uOpeMod, damLim.uOpeMod)
  connect(uFreProSta, damLim.uFreProSta)
  connect(damLim.yOutDamPosMax, enaDis.uOutDamPosMax)
  connect(damLim.yOutDamPosMin, enaDis.uOutDamPosMin)
  connect(damLim.yRetDamPosMin, enaDis.uRetDamPosMin)
  connect(damLim.yRetDamPhyPosMax, enaDis.uRetDamPhyPosMax)
  connect(damLim.yRetDamPosMax, enaDis.uRetDamPosMax)
  connect(enaDis.yOutDamPosMax, mod.uOutDamPosMax)
  connect(enaDis.yRetDamPosMax, mod.uRetDamPosMax)
  connect(damLim.yOutDamPosMin, mod.uOutDamPosMin)
  connect(enaDis.yRetDamPosMin, mod.uRetDamPosMin)
  connect(uTSup, mod.uTSup)
  connect(VOut_flow_normalized, movAve.u)
  connect(movAve.y, damLim.VOut_flow_normalized)
  connect(retDamMinFre.y, yRetDamPos)
  connect(mod.yOutDamPos, outDamMaxFre.u1)
  connect(outDamMaxFre.y, yOutDamPos)
  connect(outDamMaxFre.u2, noTMix1.y)
  connect(mod.yRetDamPos, retDamMinFre.u2)
  connect(retDamMinFre.u1, noTMix.y)
  connect(TMix, freProTMix.TMix)
  connect(freProTMix.yFrePro, retDamMinFre.u1)
  connect(freProTMix.yFreProInv, outDamMaxFre.u2)
  connect(freProSta.y, damLim.uFreProSta)
  connect(freProSta.y, enaDis.uFreProSta)
end Controller;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV;
package Economizers "Economizer control of multi zone VAV AHU"
end Economizers;


Multi zone VAV AHU economizer enable/disable switch. This is a multi zone VAV AHU economizer enable/disable sequence
based on ASHRAE G36 PART 5.N.7 and PART 5.A.17. Additional
conditions included in the sequence are: freeze protection (freeze protection
stage 0-3, see PART 5.N.12), supply fan status (on or off, see PART 5.N.5).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences;
block Enable
  "Multi zone VAV AHU economizer enable/disable switch"

  parameter Boolean use_enthalpy = true
    "Set to true to evaluate outdoor air enthalpy in addition to temperature"
  parameter Real delTOutHis(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=1
    "Delta between the temperature hysteresis high and low limit"
  parameter Real delEntHis(
    final unit="J/kg",
    final quantity="SpecificEnergy")=1000
    "Delta between the enthalpy hysteresis high and low limits"
  parameter Real retDamFulOpeTim(
    final unit="s",
    final quantity="Time")=180
    "Time period to keep RA damper fully open before releasing it for minimum outdoor airflow control
    at disable to avoid pressure fluctuations"
  parameter Real disDel(
    final unit="s",
    final quantity="Time")=15
    "Short time delay before closing the OA damper at disable to avoid pressure fluctuations"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TOut(
    final unit="K",
    final displayUnit="degC",
    final quantity = "ThermodynamicTemperature")
    "Outdoor air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput hOut(
    final unit="J/kg",
    final quantity="SpecificEnergy") if use_enthalpy
    "Outdoor air enthalpy"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TOutCut(
    final unit="K",
    final displayUnit="degC",
    final quantity = "ThermodynamicTemperature")
    "OA temperature high limit cutoff. For differential dry bulb temeprature condition use return air temperature measurement"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput hOutCut(
    final unit="J/kg",
    final quantity="SpecificEnergy") if use_enthalpy
    "OA enthalpy high limit cutoff. For differential enthalpy use return air enthalpy measurement"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDamPosMin(
    final unit="1",
    final min=0,
    final max=1)
    "Minimum outdoor air damper position, output from damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutDamPosMax(
    final unit="1",
    final min=0,
    final max=1)
    "Maximum outdoor air damper position, output from damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDamPosMax(
    final unit="1",
    final min=0,
    final max=1)
    "Maximum return air damper position, output from damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDamPosMin(
    final unit="1",
    final min=0,
    final max=1)
    "Minimum return air damper position, output from damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDamPhyPosMax(
    final unit="1",
    final min=0,
    final max=1)
    "Physical maximum return air damper position, output from damper position limits sequence"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan on/off status signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uFreProSta "Freeze protection stage status signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDamPosMax(
    final unit="1",
    final min=0,
    final max=1) "Maximum outdoor air damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPosMin(
    final unit="1",
    final min=0,
    final max=1) "Minimum return air damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPosMax(
    final unit="1",
    final min=0,
    final max=1) "Maximum return air damper position"

  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol(
    trueHoldDuration=600) "10 min on/off delay"
  Buildings.Controls.OBC.CDL.Logical.And andEnaDis
    "Logical and that checks freeze protection stage and zone state"

protected
  final parameter Real TOutHigLimCutHig(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")= 0
    "Hysteresis high limit cutoff";
  final parameter Real TOutHigLimCutLow = TOutHigLimCutHig - delTOutHis
    "Hysteresis low limit cutoff";
  final parameter Real hOutHigLimCutHig(
    final unit="J/kg",
    final quantity="SpecificEnergy")= 0
    "Hysteresis block high limit cutoff";
  final parameter Real hOutHigLimCutLow = hOutHigLimCutHig - delEntHis
    "Hysteresis block low limit cutoff";

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant entSubst(
    final k=false) if not use_enthalpy
    "Deactivates outdoor air enthalpy condition if there is no enthalpy sensor"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    if use_enthalpy "Add block determines difference between hOut and hOutCut"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Add block determines difference between TOut and TOutCut"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hysOutTem(
    final uLow=TOutHigLimCutLow,
    final uHigh=TOutHigLimCutHig)
    "Outdoor air temperature hysteresis for both fixed and differential dry bulb temperature cutoff conditions"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hysOutEnt(
    final uLow=hOutHigLimCutLow,
    final uHigh=hOutHigLimCutHig) if use_enthalpy
    "Outdoor air enthalpy hysteresis for both fixed and differential enthalpy cutoff conditions"
  Buildings.Controls.OBC.CDL.Reals.Switch outDamSwitch
    "Set maximum OA damper position to minimum at disable (after a given time delay)"
  Buildings.Controls.OBC.CDL.Reals.Switch retDamSwitch "Set minimum RA damper position to maximum at disable"
  Buildings.Controls.OBC.CDL.Reals.Switch maxRetDamSwitch
    "Keep maximum RA damper position at physical maximum for a short time period after disable signal"
  Buildings.Controls.OBC.CDL.Reals.Switch minRetDamSwitch
    "Keep minimum RA damper position at physical maximum for a short time period after disable"
  Buildings.Controls.OBC.CDL.Logical.Nor nor1 "Logical nor"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not that starts the timer at disable signal "
  Buildings.Controls.OBC.CDL.Logical.And  and2 "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and1 "Logical and checks supply fan status"
  Buildings.Controls.OBC.CDL.Logical.And and3 "Logical and which checks supply fan status"

  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Logical block to check if the freeze protection is deactivated"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay delOutDamOsc(
    final delayTime=disDel)
    "Small delay before closing the outdoor air damper to avoid pressure fluctuations"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay delRetDam(
    final delayTime=retDamFulOpeTim)
    "Keep return damper open to its physical maximum for a short period of time before closing the outdoor air damper and resuming the maximum return air damper position, per G36 Part N7"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0)
    "Integer constant, stage 0"

equation
  connect(TOut, sub1.u1)
  connect(TOutCut, sub1.u2)
  connect(sub1.y, hysOutTem.u)
  connect(hOut, sub2.u1)
  connect(hOutCut, sub2.u2)
  connect(sub2.y, hysOutEnt.u)
  connect(hysOutTem.y, nor1.u1)
  connect(hysOutEnt.y, nor1.u2)
  connect(entSubst.y, nor1.u2)
  connect(uOutDamPosMin, outDamSwitch.u1)
  connect(uOutDamPosMax, outDamSwitch.u3)
  connect(uRetDamPhyPosMax, maxRetDamSwitch.u1)
  connect(uRetDamPosMax, maxRetDamSwitch.u3)
  connect(nor1.y, truFalHol.u)
  connect(andEnaDis.y, not2.u)
  connect(maxRetDamSwitch.y, yRetDamPosMax)
  connect(and2.y, maxRetDamSwitch.u2)
  connect(and2.y, minRetDamSwitch.u2)
  connect(not2.y, retDamSwitch.u2)
  connect(uRetDamPosMax, retDamSwitch.u1)
  connect(uRetDamPosMin, retDamSwitch.u3)
  connect(retDamSwitch.y, minRetDamSwitch.u3)
  connect(uRetDamPhyPosMax, minRetDamSwitch.u1)
  connect(truFalHol.y, and1.u1)
  connect(and1.y, andEnaDis.u1)
  connect(uSupFan, and1.u2)
  connect(outDamSwitch.u2, and3.y)
  connect(not2.y, and3.u1)
  connect(and2.u1, not2.y)
  connect(and3.u2, delOutDamOsc.y)
  connect(delOutDamOsc.u, not2.y)
  connect(not2.y, delRetDam.u)
  connect(delRetDam.y, not1.u)
  connect(not1.y, and2.u2)
  connect(uFreProSta, intEqu.u1)
  connect(conInt.y, intEqu.u2)
  connect(intEqu.y, andEnaDis.u2)
  connect(outDamSwitch.y, yOutDamPosMax)
  connect(minRetDamSwitch.y, yRetDamPosMin)
end Enable;


Multi zone VAV AHU minimum outdoor air control - damper position limits. This block models the multi zone VAV AHU minimum outdoor air control with a single
common damper for minimum outdoor air and economizer functions based on outdoor airflow
measurement, designed in line with ASHRAE Guidline 36 (G36), PART 5.N.6.c.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences;
block Limits
  "Multi zone VAV AHU minimum outdoor air control - damper position limits"

  parameter Real uRetDamMin(
    final min=yMin,
    final max=yMax,
    final unit="1") = 0.5
    "Loop signal value to start decreasing the maximum return air damper position"

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

  parameter Real k(
    final unit="1")=0.05 "Gain of damper limit controller"

  parameter Real Ti(
    final unit="s",
    final quantity="Time")=120
    "Time constant of damper limit controller integrator block"

  parameter Real Td(
    final unit="s",
    final quantity="Time")=0.1
  "Time constant of damper limit controller derivative block"

  parameter Real retDamPhyPosMax(
    final min=0,
    final max=1,
    final unit="1") = 1 "Physically fixed maximum position of the return air damper"
  parameter Real retDamPhyPosMin(
    final min=0,
    final max=1,
    final unit="1") = 0
    "Physically fixed minimum position of the return air damper"
  parameter Real outDamPhyPosMax(
    final min=0,
    final max=1,
    final unit="1") = 1
    "Physically fixed maximum position of the outdoor air damper"
  parameter Real outDamPhyPosMin(
    final min=0,
    final max=1,
    final unit="1") = 0
    "Physically fixed minimum position of the outdoor air damper"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOut_flow_normalized(
   final unit="1")
    "Measured outdoor volumetric airflow rate, normalized by design minimum outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOutMinSet_flow_normalized(
    final unit="1")
    "Effective minimum outdoor airflow setpoint, normalized by design minimum outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "AHU operation mode status signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uFreProSta
    "Freeze protection status signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan status signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDamPosMin(
    final min=outDamPhyPosMin,
    final max=outDamPhyPosMax,
    final unit="1") "Minimum outdoor air damper position limit"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yOutDamPosMax(
    final min=outDamPhyPosMin,
    final max=outDamPhyPosMax,
    final unit="1") "Maximum outdoor air damper position limit"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPosMin(
    final min=retDamPhyPosMin,
    final max=retDamPhyPosMax,
    final unit="1") "Minimum return air damper position limit"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPosMax(
    final min=retDamPhyPosMin,
    final max=retDamPhyPosMax,
    final unit="1") "Maximum return air damper position limit"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPhyPosMax(
    final min=0,
    final max=1,
    final unit="1")
    "Physical maximum return air damper position limit. Required as an input for the economizer enable disable sequence"

  Buildings.Controls.OBC.CDL.Reals.PIDWithReset damLimCon(
    final controllerType=controllerType,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final yMax=yMax,
    final yMin=yMin)
    "Damper position limit controller"

protected
  parameter Real yMin=0 "Lower limit of control loop signal";
  parameter Real yMax=1 "Upper limit of control loop signal";
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPhyPosMinSig(
    final k=outDamPhyPosMin)
    "Physically fixed minimum position of the outdoor air damper. This is the initial position of the economizer damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPhyPosMaxSig(
    final k=outDamPhyPosMax)
    "Physically fixed maximum position of the outdoor air damper."
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPhyPosMinSig(
    final k=retDamPhyPosMin)
    "Physically fixed minimum position of the return air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPhyPosMaxSig(
    final k=retDamPhyPosMax)
    "Physically fixed maximum position of the return air damper. This is the initial condition of the return air damper"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minSigLim(
    final k=yMin)
    "Equals minimum controller output signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSigLim(
    final k=yMax)
    "Equals maximum controller output signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant sigFraForOutDam(
    final k=uRetDamMin) "Equals the fraction of the control loop signal below which the outdoor air damper
    limit gets modulated and above which the return air damper limit gets modulated"
  Buildings.Controls.OBC.CDL.Reals.Line minOutDam(
    final limitBelow=true,
    final limitAbove=true)
    "Linear mapping of the outdoor air damper position to the control signal"
  Buildings.Controls.OBC.CDL.Reals.Line minRetDam(
    final limitBelow=true,
    final limitAbove=true)
    "Linear mapping of the return air damper position to the control signal"
  Buildings.Controls.OBC.CDL.Reals.Switch retDamPosMinSwitch
    "A switch to deactivate the return air damper minimal outdoor airflow control"
  Buildings.Controls.OBC.CDL.Reals.Switch outDamPosMaxSwitch
    "A switch to deactivate the outdoor air damper minimal outdoor airflow control"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not block"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage1)
    "Freeze protection stage 1"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode index"
  Buildings.Controls.OBC.CDL.Integers.LessEqual intLesEqu
    "Check if freeze protection stage is stage 0"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Check if operation mode is occupied"
  Buildings.Controls.OBC.CDL.Logical.And and2 "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and3 "Logical and"

equation
  connect(minRetDam.y, yRetDamPosMax)
  connect(retDamPosMinSwitch.y, minRetDam.f2)
  connect(sigFraForOutDam.y, minRetDam.x1)
  connect(maxSigLim.y, minRetDam.x2)
  connect(VOut_flow_normalized, damLimCon.u_m)
  connect(VOutMinSet_flow_normalized, damLimCon.u_s)
  connect(damLimCon.y, minRetDam.u)
  connect(outDamPosMaxSwitch.y, minOutDam.f2)
  connect(minSigLim.y, minOutDam.x1)
  connect(sigFraForOutDam.y, minOutDam.x2)
  connect(damLimCon.y, minOutDam.u)
  connect(outDamPosMaxSwitch.y, yOutDamPosMax)
  connect(minOutDam.y, yOutDamPosMin)
  connect(retDamPhyPosMaxSig.y, retDamPosMinSwitch.u1)
  connect(retDamPhyPosMaxSig.y, minRetDam.f1)
  connect(retDamPhyPosMinSig.y, retDamPosMinSwitch.u3)
  connect(outDamPhyPosMaxSig.y, outDamPosMaxSwitch.u3)
  connect(outDamPhyPosMinSig.y, outDamPosMaxSwitch.u1)
  connect(outDamPhyPosMinSig.y, minOutDam.f1)
  connect(not1.y, retDamPosMinSwitch.u2)
  connect(not1.y, outDamPosMaxSwitch.u2)
  connect(retDamPosMinSwitch.y, yRetDamPosMin)
  connect(retDamPhyPosMaxSig.y, yRetDamPhyPosMax)
  connect(uOpeMod, intEqu.u1)
  connect(conInt1.y, intEqu.u2)
  connect(conInt.y, intLesEqu.u2)
  connect(uFreProSta, intLesEqu.u1)
  connect(damLimCon.trigger, uSupFan)
  connect(uSupFan, and2.u1)
  connect(intLesEqu.y, and2.u2)
  connect(and2.y, and3.u1)
  connect(and3.y, not1.u)
  connect(intEqu.y, and3.u2)
end Limits;


Outdoor and return air damper position modulation sequence for multi zone VAV AHU. 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. The implementation is in line with ASHRAE
Guidline 36 (G36), PART 5.N.2.c. Damper positions are linearly mapped to
the supply air control loop signal. This is a final sequence in the
composite multi zone VAV AHU economizer control sequence. Damper position
limits, which are the inputs to the sequence, are the outputs of

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits and

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
sequences.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences;
block Modulation
  "Outdoor and return air damper position modulation sequence for multi zone VAV AHU"

  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 uOutDamPosMin(
    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 uOutDamPosMax(
    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 uOutDamPosMin"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uRetDamPosMin(
    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 uRetDamPosMax(
    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 yOutDamPos(
    final min=0,
    final max=1,
    final unit="1") "Economizer damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yRetDamPos(
    final min=0,
    final max=1,
    final unit="1") "Return air damper 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, uOutDamPosMin)
  connect(outDamPos.f2, uOutDamPosMax)
  connect(retDamPos.x2, retDamMaxLimSig.y)
  connect(retDamPos.x1, retDamConMinLimSig.y)
  connect(retDamPos.f1, uRetDamPosMax)
  connect(retDamPos.f2, uRetDamPosMin)
  connect(min.u2, uOutDamPosMax)
  connect(min.u1, outDamPos.y)
  connect(max.u1, retDamPos.y)
  connect(uRetDamPosMin, max.u2)
  connect(uTSup, retDamPos.u)
  connect(uTSup, outDamPos.u)

  connect(yOutDamPos, min.y)
  connect(max.y, yRetDamPos)
end Modulation;


Subsequences for economizer control

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers;
package Subsequences "Subsequences for economizer control"
end Subsequences;


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

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

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0,
    integerFalse=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.uOutDamPosMin)
  connect(outDamPosMax.y, enaDis.uOutDamPosMax)
  connect(retDamPosMin.y, enaDis.uRetDamPosMin)
  connect(retDamPosMax.y, enaDis.uRetDamPosMax)
  connect(retDamPhyPosMax.y, enaDis.uRetDamPhyPosMax)
  connect(supFanSta.y, enaDis.uSupFan)
  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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
for the following control signals: TOut, TOutCut,
hOut, hOutCut.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.CDL.Logical.TriggeredTrapezoid TOut(
    final rising=1000,
    final falling=800,
    final amplitude=4,
    final offset=TOutCutoff - 2) "Outoor air temperature"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.TriggeredTrapezoid hOut(
    final amplitude=4000,
    final offset=hOutCutoff - 2200,
    final rising=1000,
    final falling=800) "Outdoor air enthalpy"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
    enaDis "Multi zone VAV AHU economizer enable disable sequence"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
    enaDis1 "Multi zone VAV AHU economizer enable disable sequence"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Enable
    enaDis2(final use_enthalpy=false)
    "Multi zone VAV AHU economizer enable disable sequence"

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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0)
    "Freeze Protection Status - Disabled"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant supFanSta(
    final k=true) "Supply fan status signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final shift=10,
    final period=2000) "Boolean pulse signal"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul1(
    final shift=10,
    final period=2000) "Boolean pulse signal"

equation
  connect(TOutCut.y, enaDis.TOutCut)
  connect(hOutCut.y, enaDis.hOutCut)
  connect(freProSta.y, enaDis.uFreProSta)
  connect(outDamPosMax.y, enaDis.uOutDamPosMax)
  connect(outDamPosMin.y, enaDis.uOutDamPosMin)
  connect(retDamPhyPosMax.y, enaDis.uRetDamPhyPosMax)
  connect(retDamPosMax.y, enaDis.uRetDamPosMax)
  connect(retDamPosMin.y, enaDis.uRetDamPosMin)
  connect(TOutCut1.y, enaDis1.TOutCut)
  connect(hOutCut1.y, enaDis1.hOutCut)
  connect(hOutBelowCutoff.y, enaDis.hOut)
  connect(TOutBelowCutoff.y, enaDis1.TOut)
  connect(booPul.y, TOut.u)
  connect(TOut.y, enaDis.TOut)
  connect(booPul1.y, hOut.u)
  connect(hOut.y, enaDis1.hOut)
  connect(freProSta.y, enaDis1.uFreProSta)
  connect(outDamPosMax.y, enaDis1.uOutDamPosMax)
  connect(outDamPosMin.y, enaDis1.uOutDamPosMin)
  connect(retDamPhyPosMax.y, enaDis1.uRetDamPhyPosMax)
  connect(retDamPosMax.y, enaDis1.uRetDamPosMax)
  connect(retDamPosMin.y, enaDis1.uRetDamPosMin)
  connect(TOut.y, enaDis2.TOut)
  connect(TOutCut.y, enaDis2.TOutCut)
  connect(freProSta.y, enaDis2.uFreProSta)
  connect(outDamPosMax.y, enaDis2.uOutDamPosMax)
  connect(outDamPosMin.y, enaDis2.uOutDamPosMin)
  connect(retDamPhyPosMax.y, enaDis2.uRetDamPhyPosMax)
  connect(retDamPosMax.y, enaDis2.uRetDamPosMax)
  connect(retDamPosMin.y, enaDis2.uRetDamPosMin)
  connect(supFanSta.y, enaDis.uSupFan)
  connect(supFanSta.y, enaDis1.uSupFan)
  connect(supFanSta.y, enaDis2.uSupFan)
end Enable_TOut_hOut;


Validation model for the multi zone VAV AHU minimum outdoor air control - damper position limits. This example validates enable/disable conditions for

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
for the following input signals: uSupFan, uFreProSta, uOpeMod.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Validation;
model Limits_LoopDisable
  "Validation model for the multi zone VAV AHU minimum outdoor air control - damper position limits"

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

  // Fan Status
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanSta(final k=false) "Fan is off"

  // Operation Mode
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod1(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "AHU operation mode is NOT Occupied"

  // Freeze Protection Stage
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta2(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage2)
    "Freeze protection stage is 2"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut_flow(
    final duration=1800,
    final offset=minVOutSet_flow,
    final height=incVOutSet_flow)
    "Measured outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut1_flow(
    final duration=1800,
    final offset=minVOutSet_flow,
    final height=incVOutSet_flow)
    "Measured outdoor airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp VOut2_flow(
    final duration=1800,
    final offset=minVOutSet_flow,
    final height=incVOutSet_flow)
    "Measured outdoor airflow rate"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
    damLim
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
    damLim1
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
    damLim2
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"

protected
  final parameter Real VOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.71
    "Example volumetric airflow setpoint, 15cfm/occupant, 100 occupants";
  final parameter Real minVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.61
    "Volumetric airflow sensor output, minimum value in the example";
  final parameter Real incVOutSet_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=0.2
    "Maximum increase in airflow volume during the example simulation";

  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage1)
    "Freeze protection stage is 1"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "AHU operation mode is Occupied"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanStatus1(
    final k=true) "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta1(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage1)
    "Freeze protection stage is 1"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant fanStatus2(
    final k=true) "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod2(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "AHU operation mode is Occupied"

equation
  connect(VOut_flow.y, damLim.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, damLim.VOutMinSet_flow_normalized)
  connect(fanSta.y, damLim.uSupFan)
  connect(freProSta.y, damLim.uFreProSta)
  connect(VOut1_flow.y, damLim1.VOut_flow_normalized)
  connect(VOutMinSet1_flow.y, damLim1.VOutMinSet_flow_normalized)
  connect(fanStatus1.y, damLim1.uSupFan)
  connect(freProSta1.y, damLim1.uFreProSta)
  connect(VOut2_flow.y, damLim2.VOut_flow_normalized)
  connect(VOutMinSet2_flow.y, damLim2.VOutMinSet_flow_normalized)
  connect(fanStatus2.y, damLim2.uSupFan)
  connect(freProSta2.y, damLim2.uFreProSta)
  connect(opeMod.y, damLim.uOpeMod)
  connect(opeMod1.y, damLim1.uOpeMod)
  connect(opeMod2.y, damLim2.uOpeMod)
end Limits_LoopDisable;


Validation model for the multi zone VAV AHU minimum outdoor air control - damper position limits. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
for the following control signals: VOut_flow, VOutMinSet_flow. The control loop is always enabled in this
example.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Validation;
model Limits_VOut_flow
  "Validation model for the multi zone VAV AHU minimum outdoor air control - damper position limits"

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

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Limits
    damLim
    "Multi zone VAV AHU minimum outdoor air control - damper position limits"

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(k=true) "Fan is on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0)
    "Freeze protection status 0 - disabled"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant operationMode(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Operation mode is Occupied"

equation
  connect(VOut_flow.y, damLim.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, damLim.VOutMinSet_flow_normalized)
  connect(fanStatus.y, damLim.uSupFan)
  connect(freProSta.y, damLim.uFreProSta)
  connect(operationMode.y, damLim.uOpeMod)
end Limits_VOut_flow;


Validation model for multi zone VAV AHU outdoor and return air damper position modulation sequence. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulation
for a varying supply air temperature control loop signal.
The instance mod is in normal operation, whereas
for the instance modFre, the damper limits are
as if the mixed air temperature were below its freezing set point.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Validation;
model Modulation_TSup
  "Validation model for multi zone VAV AHU outdoor and return air damper position modulation sequence"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulation
    mod "Economizer modulation sequence"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uTSup(
    final duration=900,
    final height=2,
    final offset=-1)
    "Control signal for supply air temperature loop"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMin(
    final k=0.1) "Outdoor air damper minimum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMax(final k=0.8)
    "Outdoor air damper maximum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMin(final k=0.2)
    "Return air damper minimum position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMax(final k=0.6)
    "Return air damper maximum position"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulation
    modFre
    "Economizer modulation sequence if the dampers positions prevent freezing at the mixed air"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant outDamPosMaxFre(final k=0)
    "Outdoor damper if freeze protection is on"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retDamPosMinFre(final k=1)
    "Return damper position if freeze protection is on"

equation
  connect(retDamPosMax.y, mod.uRetDamPosMax)
  connect(retDamPosMin.y, mod.uRetDamPosMin)
  connect(outDamPosMax.y, mod.uOutDamPosMax)
  connect(outDamPosMin.y, mod.uOutDamPosMin)
  connect(uTSup.y, mod.uTSup)
  connect(retDamPosMax.y, modFre.uRetDamPosMax)
  connect(outDamPosMin.y, modFre.uOutDamPosMin)
  connect(uTSup.y, modFre.uTSup)
  connect(outDamPosMaxFre.y, modFre.uOutDamPosMax)
  connect(retDamPosMinFre.y, modFre.uRetDamPosMin)
end Modulation_TSup;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
for control signals which disable modulation control loop only (economizer block)
and both minimum outdoor airflow and modulation control loops (economizer1 block).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
    economizer(
    final use_enthalpy=true,
    final retDamPhyPosMax=1,
    final retDamPhyPosMin=0,
    final outDamPhyPosMax=1,
    final outDamPhyPosMin=0,
    final use_TMix=false,
    final use_G36FrePro=true) "Multi zone VAV AHU economizer "
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
    economizer1(
    final use_enthalpy=true,
    final retDamPhyPosMax=1,
    final retDamPhyPosMin=0,
    final outDamPhyPosMax=1,
    final outDamPhyPosMin=0,
    final use_TMix=false,
    final use_G36FrePro=true) "Multi zone VAV AHU economizer"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
    economizer2(
    final retDamPhyPosMax=1,
    final retDamPhyPosMin=0,
    final outDamPhyPosMax=1,
    final outDamPhyPosMin=0,
    final use_TMix=true,
    final use_G36FrePro=false,
    final use_enthalpy=false)
    "Multi zone VAV AHU economizer with TMix freeze protection"

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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage1)
    "Freeze protection status is 0"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant freProSta2(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage2)
    "Freeze protection stage is 2"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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 hOutCut(
    final k=hOutCutoff) "Outdoor air enthalpy 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 TOutCut1(
    final k=TOutCutoff) "Outdoor air temperature 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=1,
    final offset=0) "Supply air temperature control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sin1(
    amplitude=20,
    freqHz=1/1800,
    offset=272.15,
    startTime=0) "Mixed air temerature"

equation
  connect(fanSta.y, economizer.uSupFan)
  connect(freProSta.y, economizer.uFreProSta)
  connect(TOutBelowCutoff.y, economizer.TOut)
  connect(TOutCut1.y, economizer.TOutCut)
  connect(hOutBelowCutoff.y, economizer.hOut)
  connect(hOutCut.y, economizer.hOutCut)
  connect(VOut_flow.y, economizer.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, economizer.VOutMinSet_flow_normalized)
  connect(TOutCut1.y, economizer1.TOutCut)
  connect(TOutBelowCutoff.y, economizer1.TOut)
  connect(hOutCut.y, economizer1.hOutCut)
  connect(hOutBelowCutoff.y, economizer1.hOut)
  connect(VOut_flow.y, economizer1.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, economizer1.VOutMinSet_flow_normalized)
  connect(fanSta.y, economizer1.uSupFan)
  connect(freProSta2.y, economizer1.uFreProSta)
  connect(opeMod.y, economizer.uOpeMod)
  connect(opeMod.y, economizer1.uOpeMod)
  connect(uTSup.y, economizer.uTSup)
  connect(uTSup.y, economizer1.uTSup)
  connect(TOutBelowCutoff.y, economizer2.TOut)
  connect(TOutCut1.y, economizer2.TOutCut)
  connect(VOut_flow.y, economizer2.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, economizer2.VOutMinSet_flow_normalized)
  connect(uTSup.y, economizer2.uTSup)
  connect(fanSta.y, economizer2.uSupFan)
  connect(opeMod.y, economizer2.uOpeMod)
  connect(sin1.y, economizer2.TMix)
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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller control loops:
minimum outdoor air damper position limits control loop (economizer block) and modulation
control loop (economizer1 block) for VOut_flow and TSup control signals.
Both control loops are enabled during the validation test.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
    economizer(
    final use_TMix=true,
    final use_enthalpy=true,
    final use_G36FrePro=true) "Multi zone VAV AHU economizer"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.Economizers.Controller
    economizer1(
    final use_enthalpy=false,
    final use_TMix=true,
    final use_G36FrePro=true) "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.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.FreezeProtectionStages.stage0)
    "Freeze protection status is 0"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "AHU operation mode is Occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant hOutBelowCutoff(
    final k=hOutCutoff - 10000) "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 TOutBelowCutoff(
    final k=TOutCutoff - 5) "Outdoor air temperature is slightly below the cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOutCut1(
    final k=TOutCutoff) "OA temperature high limit cutoff"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TMixMea(
    final k=303.15)
    "Measured mixed air temperature above 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=900,
    final height=incVOutSet_flow) "Measured outdoor air volumetric airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uTSup(
    final duration=1800,
    final height=1,
    final offset=0) "Supply air temperature control signal"

equation
  connect(fanSta.y, economizer.uSupFan)
  connect(freProSta.y, economizer.uFreProSta)
  connect(opeMod.y, economizer.uOpeMod)
  connect(TOutBelowCutoff.y, economizer.TOut)
  connect(TOutCut1.y, economizer.TOutCut)
  connect(VOut_flow.y, economizer.VOut_flow_normalized)
  connect(VOutMinSet_flow.y, economizer.VOutMinSet_flow_normalized)
  connect(TOutBelowCutoff.y, economizer1.TOut)
  connect(TOutCut1.y, economizer1.TOutCut)
  connect(VOutMinSet_flow.y, economizer1.VOutMinSet_flow_normalized)
  connect(fanSta.y, economizer1.uSupFan)
  connect(freProSta.y, economizer1.uFreProSta)
  connect(opeMod.y, economizer1.uOpeMod)
  connect(uTSup.y, economizer.uTSup)
  connect(uTSup.y, economizer1.uTSup)
  connect(economizer1.TMix, TMixMea.y)
  connect(hOutCut.y, economizer.hOutCut)
  connect(hOutBelowCutoff.y, economizer.hOut)
  connect(TMixMea.y, economizer.TMix)
  connect(VOut_flow.y, economizer1.VOut_flow_normalized)
end Controller_Mod_DamLim;


Collection of validation models

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


Control of actuated exhaust air dampers without fans. Control sequence for actuated exhaust damper yExhDamPos
without fans. It is implemented according to ASHRAE Guidline 36 (G36), PART 5.N.8.
(for multi zone VAV AHU), PART 5.P.6 and PART3.2B.3 (for single zone VAV AHU).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
block ExhaustDamper
  "Control of actuated exhaust air dampers without fans"

  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 uSupFan "Supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yExhDamPos(
     final unit="1",
     min=0,
     max=1)
    "Exhaust damper control signal (0: closed, 1: open)"

  Buildings.Controls.OBC.CDL.Reals.MovingAverage movMea(delta=300)
    "Average building static pressure measurement"
  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 r=dpBuiSet)
    "Building static pressure controller"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Check if exhaust damper should be activated"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerDam(
    final k=0)
    "Close damper when disabled"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant dpBuiSetPoi1(
    final k=dpBuiSet)
    "Building pressure setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer1(
    final k=0)
    "Zero constant"

equation
  connect(uSupFan, swi.u2)
  connect(zerDam.y, swi.u3)
  connect(swi.y, yExhDamPos)
  connect(dpBui, movMea.u)
  connect(movMea.y, conErr.u1)
  connect(zer1.y, conP.u_m)
  connect(conP.y, swi.u1)
  connect(conErr.y, conP.u_s)
  connect(dpBuiSetPoi1.y, conErr.u2)
end ExhaustDamper;


Output setpoints for AHU control

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


Return fan control with direct building pressure control. Setpoint for return fan discharge pressure and exhaust air damper
for a multi zone VAV AHU according to ASHRAE guideline G36,
PART 5.N.10 (return fan control with direct building pressure).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
block ReturnFanDirectPressure
  "Return fan control with direct building pressure control"

  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 dpDisMin(
    final unit="Pa",
    final quantity="PressureDifference",
    final min=0,
    final max=1000) = 2.4
    "Minimum return fan discharge static pressure difference setpoint";
  parameter Real dpDisMax(
    final unit="Pa",
    final quantity="PressureDifference",
    final min=0,
    final max=1000) = 40
    "Maximum return fan discharge static pressure setpoint";
  parameter Real k(final unit="1") = 1
    "Gain, normalized using 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 uFan
    "Fan on/off signal, true if fan is on"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput dpDisSet(
     final unit="Pa",
     displayUnit="Pa",
     min=0)
    "Return fan discharge static pressure setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yExhDam(
     final unit="1",
     min=0,
     max=1)
    "Exhaust damper control signal (0: closed, 1: open)"

  Buildings.Controls.OBC.CDL.Reals.MovingAverage movMea(delta=300)
    "Average building static pressure measurement"

  Buildings.Controls.OBC.CDL.Reals.PID conP(
    final controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P,
    final k=k,
    r=dpBuiSet,
    reverseActing=false) "Building static pressure controller"
  Buildings.Controls.OBC.CDL.Reals.Line linExhAirDam
    "Exhaust air damper position"
  Buildings.Controls.OBC.CDL.Reals.Line linRetFanStaPre
    "Return fan static pressure setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Exhaust air damper position"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Return fan discharge static pressure setpoint"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant dpBuiSetPoi(
    final k=dpBuiSet) "Building pressure setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retFanDisPreMin(
    final k=dpDisMin) "Return fan discharge static pressure minimum setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant retFanDisPreMax(
    final k=dpDisMax) "Return fan discharge static pressure maximum setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(final k=0)
    "Zero fan control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer1(final k=0)
    "Zero constant"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(final k=0.5)
    "Constant 0.5"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(final k=1)
    "Constant one"

equation
  connect(movMea.u, dpBui)
  connect(swi.u2, uFan)
  connect(swi.u3, zer.y)
  connect(zer1.y, linExhAirDam.x1)
  connect(zer1.y, linExhAirDam.f1)
  connect(con.y, linExhAirDam.x2)
  connect(one.y, linExhAirDam.f2)
  connect(con.y, linRetFanStaPre.x1)
  connect(one.y, linRetFanStaPre.x2)
  connect(retFanDisPreMin.y, linRetFanStaPre.f1)
  connect(retFanDisPreMax.y, linRetFanStaPre.f2)
  connect(linRetFanStaPre.y, swi.u1)
  connect(uFan, swi1.u2)
  connect(linExhAirDam.y, swi1.u1)
  connect(swi1.y, yExhDam)
  connect(zer1.y, swi1.u3)
  connect(swi.y, dpDisSet)
  connect(conP.y, linExhAirDam.u)
  connect(conP.y, linRetFanStaPre.u)

  connect(dpBuiSetPoi.y, conP.u_s)
  connect(movMea.y, conP.u_m)
end ReturnFanDirectPressure;


Block to control multi zone VAV AHU supply fan. Supply fan control for a multi zone VAV AHU according to
ASHRAE guideline G36, PART 5.N.1 (Supply fan control).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
block SupplyFan  "Block to control multi zone VAV AHU supply fan"

  parameter Boolean have_perZonRehBox = false
    "Check if there is any VAV-reheat boxes on perimeter zones"
  parameter Boolean have_duaDucBox = false
    "Check if the AHU serves dual duct boxes"
  parameter Boolean have_airFloMeaSta = false
    "Check if the AHU has AFMS (Airflow measurement station)"
  parameter Real iniSet(
    final unit="Pa",
    final quantity="PressureDifference") = 120
    "Initial setpoint"
  parameter Real minSet(
    final unit="Pa",
    final quantity="PressureDifference") = 25
    "Minimum setpoint"
  parameter Real maxSet(
    final unit="Pa",
    final quantity="PressureDifference")
    "Maximum setpoint"
  parameter Real delTim(
    final unit="s",
    final quantity="Time")= 600
   "Delay time after which trim and respond is activated"
  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time") = 120  "Sample period"
  parameter Integer numIgnReq = 2
    "Number of ignored requests"
  parameter Real triAmo(
    final unit="Pa",
    final quantity="PressureDifference") = -12.0
    "Trim amount"
  parameter Real resAmo(
    final unit="Pa",
    final quantity="PressureDifference") = 15
    "Respond amount (must be opposite in to triAmo)"
  parameter Real maxRes(
    final unit="Pa",
    final quantity="PressureDifference") = 32
    "Maximum response per time interval (same sign as resAmo)"
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"
  parameter Real k(final unit="1")=0.1
    "Gain of controller, normalized using maxSet"
  parameter Real Ti(
    final unit="s",
    final quantity="Time",
    min=0)=60
    "Time constant of integrator block"
  parameter Real Td(
    final unit="s",
    final quantity="Time",
    final min=0) = 0.1
    "Time constant of derivative block"
  parameter Real yFanMax(min=0.1, max=1, unit="1") = 1
    "Maximum allowed fan speed"
  parameter Real yFanMin(min=0.1, max=1, unit="1") = 0.1
    "Lowest allowed fan speed if fan is on"

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
   "System operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ducStaPre(
    final unit="Pa",
    quantity="PressureDifference")
    "Measured duct static pressure"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uZonPreResReq
    "Zone static pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput ySupFan "Supply fan on status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput ySupFanSpe(
    min=0,
    max=1,
    final unit="1") "Supply fan speed"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond
    staPreSetRes(
    final iniSet=iniSet,
    final minSet=minSet,
    final maxSet=maxSet,
    final delTim=delTim,
    final samplePeriod=samplePeriod,
    final numIgnReq=numIgnReq,
    final triAmo=triAmo,
    final resAmo=resAmo,
    final maxRes=maxRes)
    "Static pressure setpoint reset using trim and respond logic"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conSpe(
    final controllerType=controllerType,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    r=maxSet,
    final yMax=yFanMax,
    final yMin=yFanMin,
    y_reset=yFanMin) "Supply fan speed control"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerSpe(k=0)
    "Zero fan speed when it becomes OFF"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "If fan is OFF, fan speed outputs to zero"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "Check whether supply fan should be ON"
  Buildings.Controls.OBC.CDL.Logical.Or or2 if have_perZonRehBox
    "Setback or warmup mode"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or3
    "Cool-down or setup or occupied mode"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    k=false) if not have_perZonRehBox
    "Constant true"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.coolDown)
    "Cool down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "Warm-up mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setUp)
    "Set up mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setBack)
    "Set back mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Check if current operation mode is cool-down mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if current operation mode is setup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu2
    "Check if current operation mode is occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu3
    "Check if current operation mode is setback mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu4
    "Check if current operation mode is warmup mode"
  Buildings.Controls.OBC.CDL.Discrete.FirstOrderHold firOrdHol(
    final samplePeriod=samplePeriod)
    "Extrapolation through the values of the last two sampled input signals"

equation
  connect(or2.y, or1.u2)
  connect(or1.y, ySupFan)
  connect(or1.y, staPreSetRes.uDevSta)
  connect(or1.y, swi.u2)
  connect(conSpe.y, swi.u1)
  connect(zerSpe.y, swi.u3)
  connect(swi.y, ySupFanSpe)
  connect(uZonPreResReq, staPreSetRes.numOfReq)
  connect(con.y, or1.u2)
  connect(intEqu.y, or3.u1)
  connect(intEqu2.y, or3.u3)
  connect(intEqu1.y, or3.u2)
  connect(conInt.y, intEqu.u2)
  connect(conInt1.y, intEqu1.u2)
  connect(conInt2.y, intEqu2.u2)
  connect(conInt3.y, intEqu3.u2)
  connect(conInt4.y, intEqu4.u2)
  connect(uOpeMod, intEqu.u1)
  connect(uOpeMod, intEqu1.u1)
  connect(uOpeMod, intEqu2.u1)
  connect(uOpeMod, intEqu3.u1)
  connect(uOpeMod, intEqu4.u1)
  connect(or3.y, or1.u1)
  connect(intEqu3.y, or2.u1)
  connect(intEqu4.y, or2.u2)
  connect(staPreSetRes.y, firOrdHol.u)
  connect(conSpe.trigger, or1.y)

  connect(ducStaPre, conSpe.u_m)
  connect(firOrdHol.y, conSpe.u_s)
end SupplyFan;


Multizone VAV AHU coil valve positions. Block that outputs the supply temperature control loop signal,
and the coil valve postions for VAV system with multiple zones,
implemented according to the ASHRAE Guideline G36, PART 5.N.2
(Supply air temperature control).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
block SupplySignals "Multizone VAV AHU coil valve positions"

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=
      Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller for supply air temperature signal";
  parameter Real kTSup=0.05
    "Gain of controller for supply air temperature signal";
  parameter Real TiTSup(
    final unit="s",
    final quantity="Time")=600
    "Time constant of integrator block for supply temperature control signal"

  parameter Real TdTSup(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for supply temperature control signal"

  parameter Real uHeaMax(
    final min=-0.9,
    final unit="1")=-0.25
    "Upper limit of controller signal when heating coil is off. Require -1 < uHeaMax < uCooMin < 1.";
  parameter Real uCooMin(
    final max=0.9,
    final unit="1")=0.25
    "Lower limit of controller signal when cooling coil is off. Require -1 < uHeaMax < uCooMin < 1.";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSup(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Setpoint for supply air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yHea(
    final min=0,
    final max=1,
    final unit="1")
    "Control signal for heating"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCoo(
    final min=0,
    final max=1,
    final unit="1")
    "Control signal for cooling"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput uTSup(
    final max=1,
    final unit="1",
    final min=-1)
    "Supply temperature control signal"

protected
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conTSup(
    final controllerType=controllerType,
    final k=kTSup,
    final Ti=TiTSup,
    final Td=TdTSup,
    final yMax=1,
    final yMin=-1,
    final y_reset=0,
    final reverseActing=false)
    "Controller for supply air temperature control signal (to be used by heating coil, cooling coil and economizer)"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Switch to select supply temperature control signal based on status of supply fan"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant uHeaMaxCon(
    final k=uHeaMax)
    "Constant signal to map control action"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant negOne(final k=-1)
    "Negative unity signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant uCooMinCon(
    final k=uCooMin)
    "Constant signal to map control action"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(final k=0)
    "Zero control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(final k=1)
    "Unity signal"
  Buildings.Controls.OBC.CDL.Reals.Line conSigCoo(
    final limitBelow=true,
    final limitAbove=false)
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Line conSigHea(
    final limitBelow=false,
    final limitAbove=true)
    "Heating control signal"

equation
  connect(zer.y,swi. u3)
  connect(TSup,conTSup. u_m)
  connect(negOne.y,conSigHea. x1)
  connect(one.y,conSigHea. f1)
  connect(swi.y,conSigHea. u)
  connect(swi.y,conSigCoo. u)
  connect(uHeaMaxCon.y,conSigHea. x2)
  connect(zer.y,conSigHea. f2)
  connect(uCooMinCon.y,conSigCoo. x1)
  connect(zer.y,conSigCoo. f1)
  connect(one.y,conSigCoo. x2)
  connect(one.y,conSigCoo. f2)
  connect(conSigHea.y,yHea)
  connect(conSigCoo.y,yCoo)
  connect(swi.y,uTSup)
  connect(TSupSet, conTSup.u_s)
  connect(uSupFan, swi.u2)
  connect(conTSup.y, swi.u1)
  connect(uSupFan, conTSup.trigger)
end SupplySignals;


Supply air temperature setpoint for multi zone system. Block that outputs the supply air temperature setpoint and the coil valve control
inputs for VAV system with multiple zones, implemented according to the ASHRAE
Guideline G36, PART 5.N.2 (Supply air temperature control).

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
block SupplyTemperature
  "Supply air temperature setpoint for multi zone system"

  parameter Real TSupSetDes(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = 285.15
    "Design coil leaving air temperature"
  parameter Real TSupSetMin(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = 285.15
    "Lowest cooling supply air temperature setpoint when the outdoor air temperature is at the
    higher value of the reset range and above. This should not be lower than the design coil leaving air temperature"
  parameter Real TSupSetMax(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = 291.15
    "Highest cooling supply air temperature setpoint. It is typically 18 degC (65 degF)
    in mild and dry climates, 16 degC (60 degF) or lower in humid climates"
  parameter Real TOutMin(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = 289.15
    "Lower value of the outdoor air temperature reset range. Typically value is 16 degC (60 degF)"
  parameter Real TOutMax(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = 294.15
    "Higher value of the outdoor air temperature reset range. Typically value is 21 degC (70 degF)"
  parameter Real TSupWarUpSetBac(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")=308.15
    "Supply temperature in warm up and set back mode"
  parameter Real delTim(
    final unit="s",
    final quantity="Time") = 600
    "Delay timer"
  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time",
    final min=1E-3) = 120
    "Sample period of component"
  parameter Integer numIgnReq = 2
    "Number of ignorable requests for TrimResponse logic"
  parameter Real triAmo(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference") = 0.1
    "Trim amount"
  parameter Real resAmo(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference") = -0.2
    "Response amount"
  parameter Real maxRes(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference") = -0.6
    "Maximum response per time interval"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TOut(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Outdoor air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonSetAve(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Average of heating and cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "System operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Setpoint for supply air temperature"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Generic.SetPoints.TrimAndRespond
    maxSupTemRes(
    final delTim=delTim,
    final iniSet=iniSet,
    final minSet=minSet,
    final maxSet=maxSet,
    final samplePeriod=samplePeriod,
    final numIgnReq=numIgnReq,
    final triAmo=triAmo,
    final resAmo=resAmo,
    final maxRes=maxRes) "Maximum cooling supply temperature reset"

protected
  parameter Real iniSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = maxSet
    "Initial setpoint"
  parameter Real maxSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = TSupSetMax
    "Maximum setpoint"
  parameter Real minSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") = TSupSetDes
    "Minimum setpoint"

  Buildings.Controls.OBC.CDL.Reals.Line lin
    "Supply temperature distributes linearly between minimum and maximum supply
    air temperature, according to outdoor temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minOutTem(k=TOutMin)
    "Lower value of the outdoor air temperature reset range"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxOutTem(k=TOutMax)
    "Higher value of the outdoor air temperature reset range"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minSupTem(k=TSupSetMin)
    "Lowest cooling supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Check if it is in Setup or Cool-down mode"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "Check if it is in Warmup or Setback mode"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant supTemWarUpSetBac(k=
        TSupWarUpSetBac)
    "Supply temperature setpoint under warm-up and setback mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "If operation mode is setup or cool-down, setpoint shall be 35 degC"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "If operation mode is setup or cool-down, setpoint shall be TSupSetMin"
  Buildings.Controls.OBC.CDL.Reals.Limiter TDea(
    uMax(
      final unit="K",
      displayUnit="degC") = 297.15,
    uMin(
      final unit="K",
      displayUnit="degC") = 294.15)
    "Limiter that outputs the dead band value for the supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3
    "Check output regarding supply fan status"
  Buildings.Controls.OBC.CDL.Integers.LessThreshold intLesThr(t=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "Check if operation mode index is less than warm-up mode index (4)"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr(t=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Check if operation mode index is greater than occupied mode index (1)"
  Buildings.Controls.OBC.CDL.Integers.LessThreshold intLesThr1(t=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.unoccupied)
    "Check if operation mode index is less than unoccupied mode index (7)"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr1(t=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setUp)
    "Check if operation mode index is greater than set up mode index (3)"

equation
  connect(minOutTem.y, lin.x1)
  connect(TOut, lin.u)
  connect(maxOutTem.y, lin.x2)
  connect(minSupTem.y, lin.f2)
  connect(and1.y, swi1.u2)
  connect(supTemWarUpSetBac.y, swi1.u1)
  connect(and2.y, swi2.u2)
  connect(minSupTem.y, swi2.u1)
  connect(swi2.y, swi1.u3)
  connect(TZonSetAve, TDea.u)
  connect(uSupFan, swi3.u2)
  connect(swi1.y, swi3.u1)
  connect(TDea.y, swi3.u3)
  connect(intLesThr1.y, and1.u1)
  connect(intGreThr1.y, and1.u2)
  connect(intLesThr.y, and2.u1)
  connect(intGreThr.y, and2.u2)
  connect(uOpeMod, intLesThr.u)
  connect(uOpeMod, intGreThr.u)
  connect(uOpeMod, intLesThr1.u)
  connect(uOpeMod, intGreThr1.u)
  connect(lin.y, swi2.u3)
  connect(uZonTemResReq, maxSupTemRes.numOfReq)
  connect(uSupFan, maxSupTemRes.uDevSta)
  connect(maxSupTemRes.y, lin.f1)
  connect(swi3.y, TSupSet)
end SupplyTemperature;


Output outdoor airflow related calculations at the AHU level. This sequence outputs AHU level design minimum outdoor airflow rate
VDesOutAir_flow and effective minimum outdoor airflow rate
VEffOutAir_flow.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints.OutdoorAirFlow;
block AHU "Output outdoor airflow related calculations at the AHU level"

  parameter Real VPriSysMax_flow(unit="m3/s")
    "Maximum expected system primary airflow at design stage"

  parameter Real peaSysPop(final unit="1")
    "Peak system population"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput sumDesZonPop(
    final min=0,
    final unit="1")
    "Sum of the design population of the zones in the group"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VSumDesPopBreZon_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Sum of the population component design breathing zone flow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VSumDesAreBreZon_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Sum of the area component design breathing zone flow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDesSysVenEff(
    final min=0,
    final unit="1")
    "Design system ventilation efficiency, equals to the minimum of all zones ventilation efficiency"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VSumUncOutAir_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Sum of all zones required uncorrected outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VSumSysPriAir_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "System primary airflow rate, equals to the sum of the measured discharged flow rate of all terminal units"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uOutAirFra_max(
    final min=0,
    final unit="1")
    "Maximum zone outdoor air fraction, equals to the maximum of primary outdoor air fraction of all zones"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uSupFan
    "Supply fan status, true if on, false if off"

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "AHU operation mode status signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VDesUncOutAir_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Design uncorrected minimum outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yAveOutAirFraPlu(
    final min=0,
    final unit="1")
    "Average outdoor air flow fraction plus 1"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VDesOutAir_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Design minimum outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VEffOutAir_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Effective minimum outdoor airflow setpoint"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput effOutAir_normalized(
    final unit="1")
    "Effective minimum outdoor airflow setpoint, normalized by VDesOutMin_flow_nominal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yReqOutAir
    "True if the AHU supply fan is on and the zone is in occupied mode"

protected
  Buildings.Controls.OBC.CDL.Reals.Divide outAirFra
    "System outdoor air fraction"

  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=1)
    "System outdoor air flow fraction plus 1"

  Buildings.Controls.OBC.CDL.Reals.Subtract sysVenEff
    "Current system ventilation efficiency"

  Buildings.Controls.OBC.CDL.Reals.Divide effMinOutAirInt
    "Effective minimum outdoor air setpoint"

  Buildings.Controls.OBC.CDL.Reals.Divide occDivFra
    "Occupant diversity fraction"

  Buildings.Controls.OBC.CDL.Reals.Add unCorOutAirInk
    "Uncorrected outdoor air intake"

  Buildings.Controls.OBC.CDL.Reals.Multiply pro "Product of inputs"

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter aveOutAirFra(
    final k=1/VPriSysMax_flow) "Average outdoor air fraction"

  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=1)
    "Average outdoor air flow fraction plus 1"

  Buildings.Controls.OBC.CDL.Reals.Divide desOutAirInt
    "Design system outdoor air intake"

  Buildings.Controls.OBC.CDL.Reals.Min min
    "Minimum outdoor airflow rate should not be more than designed outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Reals.Min sysUncOutAir
    "Uncorrected outdoor air rate should not be higher than its design value"

  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occMod(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode index"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant peaSysPopulation(
    final k=peaSysPop)
    "Peak system population"

  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if operation mode is occupied"

  Buildings.Controls.OBC.CDL.Logical.And and1 "Logical and"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant smaSysEff(
    final k=1E-4)
    "Set system ventilation efficiency to small value to avoid division by zero"

  Buildings.Controls.OBC.CDL.Reals.Divide norVOutMin
    "Normalization for minimum outdoor air flow rate"

  Buildings.Controls.OBC.CDL.Reals.Max sysVenEffNonZero
    "Current system ventilation efficiency, bounded away from zero"

equation
  connect(peaSysPopulation.y, occDivFra.u1)
  connect(pro.y, unCorOutAirInk.u1)
  connect(aveOutAirFra.y, addPar1.u)
  connect(unCorOutAirInk.y, desOutAirInt.u1)
  connect(sysUncOutAir.y, effMinOutAirInt.u1)
  connect(sysUncOutAir.y, outAirFra.u1)
  connect(unCorOutAirInk.y, sysUncOutAir.u1)
  connect(desOutAirInt.y, min.u1)
  connect(unCorOutAirInk.y, VDesUncOutAir_flow)
  connect(desOutAirInt.y, VDesOutAir_flow)
  connect(occDivFra.y, pro.u1)
  connect(uOpeMod, intEqu1.u1)
  connect(occMod.y, intEqu1.u2)
  connect(intEqu1.y, and1.u2)
  connect(outAirFra.y, addPar.u)
  connect(addPar.y, sysVenEff.u1)
  connect(VEffOutAir_flow, min.y)
  connect(effMinOutAirInt.y, min.u2)
  connect(norVOutMin.u1, min.y)
  connect(desOutAirInt.y, norVOutMin.u2)
  connect(norVOutMin.y, effOutAir_normalized)
  connect(uSupFan, and1.u1)
  connect(addPar1.y, yAveOutAirFraPlu)
  connect(occDivFra.u2, sumDesZonPop)
  connect(pro.u2, VSumDesPopBreZon_flow)
  connect(unCorOutAirInk.u2, VSumDesAreBreZon_flow)
  connect(desOutAirInt.u2, uDesSysVenEff)
  connect(sysUncOutAir.u2, VSumUncOutAir_flow)
  connect(outAirFra.u2, VSumSysPriAir_flow)
  connect(sysVenEff.u2, uOutAirFra_max)
  connect(and1.y, yReqOutAir)
  connect(aveOutAirFra.u, unCorOutAirInk.y)
  connect(sysVenEff.y, sysVenEffNonZero.u1)
  connect(smaSysEff.y, sysVenEffNonZero.u2)
  connect(sysVenEffNonZero.y, effMinOutAirInt.u2)
end AHU;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints;
package OutdoorAirFlow "Package of sequences for calculating minimum outdoor airflow rate"
end OutdoorAirFlow;


Output the sum, maximum and minimum from the zone level calculation. This sequence sums up the zone level minimum outdoor airflow setpoints, finds the
maximum zone outdoor air fraction and the minimum zone ventilation efficiency. It
collects zone level outputs and prepares inputs for specifying AHU level minimum
outdoor air setpoint.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.AHUs.MultiZone.VAV.SetPoints.OutdoorAirFlow;
block SumZone
  "Output the sum, maximum and minimum from the zone level calculation"

  parameter Integer numZon(min=2)
    "Total number of zones that the system serves";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDesZonPeaOcc[numZon](
    final min = fill(0, numZon),
    final unit = fill("1", numZon))
    "Design zone peak occupancy"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDesPopBreZon_flow[numZon](
    final min = fill(0, numZon),
    final unit = fill("m3/s", numZon),
    final quantity=fill("VolumeFlowRate", numZon))
    "Population component breathing zone design outdoor airflow"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDesAreBreZon_flow[numZon](
    final min = fill(0, numZon),
    final unit = fill("m3/s", numZon),
    final quantity=fill("VolumeFlowRate", numZon))
    "Area component breathing zone design outdoor airflow"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput yAveOutAirFraPlu(
    final min = 0,
    final unit = "1")
    "Average system outdoor air flow fraction plus 1"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDesPriOutAirFra[numZon](
    final min = fill(0, numZon),
    final max = fill(1, numZon),
    final unit = fill("1", numZon))
    "Design zone primary outdoor air fraction"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VUncOutAir_flow[numZon](
    final min = fill(0, numZon),
    final unit = fill("m3/s", numZon),
    final quantity=fill("VolumeFlowRate", numZon))
    "Uncorrected outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput uPriOutAirFra[numZon](
    final min = fill(0, numZon),
    final max = fill(1, numZon),
    final unit = fill("1", numZon))
    "Primary outdoor air fraction"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VPriAir_flow[numZon](
    final min = fill(0, numZon),
    final unit = fill("m3/s", numZon),
    final quantity=fill("VolumeFlowRate", numZon))
    "Primary airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput ySumDesZonPop(
    final min = 0,
    final unit = "1")
    "Sum of the design population of the zones in the group"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSumDesPopBreZon_flow(
    final min = 0,
    final unit = "m3/s",
    final quantity="VolumeFlowRate")
    "Sum of the population component design breathing zone flow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSumDesAreBreZon_flow(
    final min = 0,
    final unit = "m3/s",
    final quantity="VolumeFlowRate")
    "Sum of the area component design breathing zone flow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDesSysVenEff(
    final min = 0,
    final unit = "1")
    "Design system ventilation efficiency, equals to the minimum of all zones ventilation efficiency"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSumUncOutAir_flow(
    final min = 0,
    final unit = "m3/s",
    final quantity="VolumeFlowRate")
    "Sum of the required uncorrected outdoor airflow rate"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput uOutAirFra_max(
    final min = 0,
    final max = 1,
    final unit = "1")
    "Maximum zone outdoor air fraction, equals to the maximum of primary outdoor air fraction of all zones"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSumSysPriAir_flow(
    final min = 0,
    final unit = "m3/s",
    final quantity="VolumeFlowRate")
    "AHU level primary airflow rate, equals to the sum of the measured discharged flow rate of all terminal units"

protected
  Buildings.Controls.OBC.CDL.Reals.MultiSum sysUncOutAir(
    final nin=numZon)
    "Uncorrected outdoor airflow"

  Buildings.Controls.OBC.CDL.Reals.MultiSum sysPriAirRate(
    final nin=numZon)
    "System primary airflow rate"

  Buildings.Controls.OBC.CDL.Reals.MultiSum sumDesZonPop(
    final nin=numZon)
    "Sum of the design zone population for all zones"

  Buildings.Controls.OBC.CDL.Reals.MultiSum sumDesBreZonPop(
    final nin=numZon)
    "Sum of the design breathing zone flow rate for population component"

  Buildings.Controls.OBC.CDL.Reals.MultiSum sumDesBreZonAre(
    final nin=numZon)
    "Sum of the design breathing zone flow rate for area component"

  Buildings.Controls.OBC.CDL.Reals.Subtract zonVenEff[numZon]
    "Zone ventilation efficiency"

  Buildings.Controls.OBC.CDL.Reals.MultiMin desSysVenEff(
    final nin=numZon)
    "Design system ventilation efficiency"

  Buildings.Controls.OBC.CDL.Reals.MultiMax maxPriOutAirFra(
    final nin=numZon)
    "Maximum zone outdoor air fraction"

  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(
    final nout=numZon)
    "Replicate Real input signal"

equation
  connect(zonVenEff.y, desSysVenEff.u)
  connect(reaRep.y, zonVenEff.u1)
  connect(sumDesZonPop.y, ySumDesZonPop)
  connect(sumDesBreZonPop.y, VSumDesPopBreZon_flow)
  connect(sumDesBreZonAre.y, VSumDesAreBreZon_flow)
  connect(desSysVenEff.y, yDesSysVenEff)
  connect(sysUncOutAir.y, VSumUncOutAir_flow)
  connect(sysPriAirRate.y, VSumSysPriAir_flow)
  connect(maxPriOutAirFra.y, uOutAirFra_max)
  connect(yAveOutAirFraPlu, reaRep.u)
  connect(uDesZonPeaOcc, sumDesZonPop.u)
  connect(VDesPopBreZon_flow, sumDesBreZonPop.u)
  connect(VDesAreBreZon_flow, sumDesBreZonAre.u)
  connect(uDesPriOutAirFra, zonVenEff.u2)
  connect(VUncOutAir_flow, sysUncOutAir.u)
  connect(VPriAir_flow, sysPriAirRate.u)
  connect(uPriOutAirFra, maxPriOutAirFra.u)
end SumZone;