Model validates the block for specifying air economizer high limits. This example validates

Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits.

within Buildings.Controls.OBC.ASHRAE.G36.Generic.Validation;
model AirEconomizerHighLimits
  "Model validates the block for specifying air economizer high limits"

  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1B)
    "ASHRAE standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim1(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_1)
    "Title 24 standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim2(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_5A)
    "ASHRAE standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim3(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1A)
    "ASHRAE standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim4(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1B)
    "ASHRAE standard, with differential dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim5(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedEnthalpyWithFixedDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1B)
    "ASHRAE standard, with fixed enthalpy and fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim6(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialEnthalpyWithFixedDryBulb,
    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_1B)
    "ASHRAE standard, with differential enthalpy and fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim7(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_2)
    "Title 24 standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim8(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_6)
    "Title 24 standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim9(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_7)
    "Title 24 standard, with fixed dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim10(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_1)
    "Title 24 standard, with differential dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim11(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_2)
    "Title 24 standard, with differential dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim12(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_6)
    "Title 24 standard, with differential dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim13(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.DifferentialDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_7)
    "Title 24 standard, with differential dry bulb device"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.AirEconomizerHighLimits ecoHigLim14(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.California_Title_24,
    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedEnthalpyWithFixedDryBulb,
    final tit24CliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.Title24ClimateZone.Zone_1)
    "Title 24 standard, with fixed enthalpy and fixed dry bulb device"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp retAirEnt(
    final height=5000,
    final duration=10,
    final offset=65000) "Return air enthalpy"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp retAirTem(
    final height=5,
    final duration=10,
    final offset=295.15) "Return air temperature"

equation
  connect(retAirTem.y, ecoHigLim4.TRet)
  connect(retAirTem.y, ecoHigLim10.TRet)
  connect(retAirTem.y, ecoHigLim11.TRet)
  connect(retAirTem.y, ecoHigLim12.TRet)
  connect(retAirTem.y, ecoHigLim13.TRet)
  connect(retAirEnt.y, ecoHigLim6.hRet)
end AirEconomizerHighLimits;


Collection of validation models

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


Model validates the block for suppresing changes due to the setpoint change with a negative start time
  . This example validates

Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression.

within Buildings.Controls.OBC.ASHRAE.G36.Generic.Validation;
model TimeSuppressionNegativeStartTime
  "Model validates the block for suppresing changes due to the setpoint change with a negative start time
  "

  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupCooReq
    "Time suppression for generating cooling request"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupAla(
    final chaRat=1080,
    final maxTim=7200) "Time suppression for temperature alarm"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin zonTem(
    final amplitude=2,
    final freqHz=1/7200,
    final offset=298.15)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooSet(
    final height=5,
    final duration=600,
    final offset=295.15,
    final startTime=900) "Cooling setpoint"

equation
  connect(cooSet.y, timSupCooReq.TSet)
  connect(cooSet.y, timSupAla.TSet)
  connect(zonTem.y, timSupCooReq.TZon)
  connect(zonTem.y, timSupAla.TZon)
end TimeSuppressionNegativeStartTime;


Model validates the block for suppresing changes due to the setpoint change with a positive start time. This example validates

Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression.

within Buildings.Controls.OBC.ASHRAE.G36.Generic.Validation;
model TimeSuppressionPositiveStartTime
  "Model validates the block for suppresing changes due to the setpoint change with a positive start time"

  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupCooReq
    "Time suppression for generating cooling request"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupAla(
    final chaRat=1080,
    final maxTim=7200) "Time suppression for temperature alarm"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin zonTem(
    final amplitude=2,
    final freqHz=1/7200,
    final offset=298.15)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp cooSet(
    final height=5,
    final duration=600,
    final offset=295.15,
    final startTime=900) "Cooling setpoint"

equation
  connect(cooSet.y, timSupCooReq.TSet)
  connect(cooSet.y, timSupAla.TSet)
  connect(zonTem.y, timSupCooReq.TZon)
  connect(zonTem.y, timSupAla.TZon)
end TimeSuppressionPositiveStartTime;


Model validates the trim and respond block. This example validates

Buildings.Controls.OBC.ASHRAE.G36.Generic.TrimAndRespond.

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

  CDL.Logical.Sources.TimeTable
                            hol(
    table=[0,0; 5,1; 10,0; 15,1; 16,0],
    timeScale=100,
    final period=2000)
               "Source for hold signal"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TrimAndRespond trimRespondLogicHold(
    have_hol=true,
    final iniSet=120,
    final minSet=37,
    final maxSet=370,
    final delTim=300,
    final samplePeriod=120,
    final numIgnReq=2,
    final triAmo=-10,
    final resAmo=15,
    final maxRes=37,
    dtHol=300)
    "Block implementing trim and respond logic – Case with hold signal"
equation
  connect(con.y, trimRespondLogic.uDevSta)
  connect(sine.y, abs.u)
  connect(not1.y,trimRespondLogic2. uDevSta)
  connect(con1.y, swi.u1)
  connect(sine1.y, swi.u3)
  connect(swi.y, abs1.u)
  connect(booPul.y, swi.u2)
  connect(booPul.y, not1.u)
  connect(abs.y, round2.u)
  connect(round2.y, reaToInt1.u)
  connect(reaToInt1.y, trimRespondLogic.numOfReq)
  connect(abs1.y, round1.u)
  connect(round1.y, reaToInt2.u)
  connect(reaToInt2.y,trimRespondLogic2. numOfReq)
  connect(con.y,trimRespondLogic1. uDevSta)
  connect(reaToInt1.y,trimRespondLogic1. numOfReq)

  connect(con.y, trimRespondLogicHold.uDevSta)
  connect(reaToInt1.y, trimRespondLogicHold.numOfReq)
  connect(hol.y[1], trimRespondLogicHold.uHol)
end TrimAndRespond;


Control sequences for terminal units

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


Controller for cooling only VAV box. Controller for cooling only terminal box according to Section 5.5 of ASHRAE
Guideline 36, May 2020. It outputs discharge airflow setpoint VSet_flow,
damper position setpoint yDam, AHU cooling supply temperature
setpoint reset request yZonTemResReq, and static pressure setpoint
reset request yZonPreResReq. It also outputs the alarms about the low airflow
yLowFloAla, leaking damper yLeaDamAla, and
airflow sensor calibration alarm yFloSenAla.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly;
block Controller "Controller for cooling only VAV box"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard venStd
    "Ventilation standard, ASHRAE 62.1 or Title 24";
  parameter Boolean have_winSen=true
    "True: the zone has window sensor"
  parameter Boolean have_occSen=true
    "True: the zone has occupancy sensor"
  parameter Boolean have_CO2Sen=true
    "True: the zone has CO2 sensor"
  parameter Boolean permit_occStandby=true
    "True: occupied-standby mode is permitted"
  parameter Real VOccMin_flow(unit="m3/s")
    "Zone minimum outdoor airflow for occupants"
  parameter Real VAreMin_flow(unit="m3/s")
    "Zone minimum outdoor airflow for building area"
  // ---------------- Design parameters ----------------
  parameter Real VAreBreZon_flow(unit="m3/s")
    "Design area component of the breathing zone outdoor airflow"
  parameter Real VPopBreZon_flow(unit="m3/s")
    "Design population component of the breathing zone outdoor airflow"
  parameter Real VMin_flow(unit="m3/s")
    "Design zone minimum airflow setpoint"
  parameter Real VCooMax_flow(unit="m3/s")
    "Design zone cooling maximum airflow rate"
  // ---------------- Control loop parameters ----------------
  parameter Real kCooCon=0.1
    "Gain of controller for cooling control loop"
  parameter Real TiCooCon(unit="s")=900
    "Time constant of integrator block for cooling control loop"
  parameter Real kHeaCon=0.1
    "Gain of controller for heating control loop"
  parameter Real TiHeaCon(unit="s")=900
    "Time constant of integrator block for heating control loop"
  // ---------------- Damper control parameters ----------------
  parameter CDL.Types.SimpleController damCon=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"
  parameter Real kDam=0.5
    "Gain of controller for damper control"
  parameter Real TiDam(unit="s")=300
    "Time constant of integrator block for damper control"
  parameter Real TdDam(unit="s")=0.1
    "Time constant of derivative block for damper control"
// ---------------- System request parameters ----------------
  parameter Real thrTemDif(unit="K")=3
    "Threshold difference between zone temperature and cooling setpoint for generating 3 cooling SAT reset requests"
  parameter Real twoTemDif(unit="K")=2
    "Threshold difference between zone temperature and cooling setpoint for generating 2 cooling SAT reset requests"
  parameter Real durTimTem(unit="s")=120
    "Duration time of zone temperature exceeds setpoint"
  parameter Real durTimFlo(unit="s")=60
    "Duration time of airflow rate less than setpoint"
// ---------------- Parameters for alarms ----------------
  parameter Real staPreMul=1
    "Importance multiplier for the zone static pressure reset control loop"
  parameter Real lowFloTim(unit="s")=300
    "Threshold time to check low flow rate"
  parameter Real fanOffTim(unit="s")=600
    "Threshold time to check fan off"
  parameter Real leaFloTim(unit="s")=600
    "Threshold time to check damper leaking airflow"
  // ---------------- Parameters for time-based suppression ----------------
  parameter Real samplePeriod(unit="s")=120
    "Sample period of component, set to the same value as the trim and respond that process static pressure reset"
  parameter Real chaRat(final unit="s/K")=540
    "Gain factor to calculate suppression time based on the change of the setpoint, seconds per Kelvin"
  parameter Real maxSupTim(unit="s")=1800
    "Maximum suppression time"
  // ---------------- Advanced parameters ----------------
  parameter Real dTHys(unit="K")=0.25
    "Near zero temperature difference, below which the difference will be seen as zero"
  parameter Real floHys(unit="m3/s")=0.01*VMin_flow
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"
  parameter Real looHys(unit="1")=0.01
    "Loop output hysteresis below which the output will be seen as zero"
  parameter Real damPosHys(unit="1")=0.005
    "Near zero damper position, below which the damper will be seen as closed"
  parameter Real staTim(
    final unit="s",
    final quantity="Time")=1800
    "Delay triggering alarms after enabling AHU supply fan"
  parameter Real iniDam(unit="1")=0.01
    "Initial damper position when the damper control is enabled"
  parameter Real timChe(unit="s")=30
    "Threshold time to check the zone temperature status"
  parameter Real zonDisEff_cool(unit="1")=1.0
    "Zone cooling air distribution effectiveness"
  parameter Real zonDisEff_heat(unit="1")=0.8
    "Zone heating air distribution effectiveness"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Measured room temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TCooSet(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Zone cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSet(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Zone heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Win if have_winSen
    "Window status, normally closed (true), when windows open, it becomes false"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Occ if have_occSen
    "True: the zone is populated"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2Set if have_CO2Sen
    "CO2 concentration setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2 if have_CO2Sen
    "Detected CO2 concentration"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSup(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Temperature of the air supplied from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured primary discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveFloSet
    "Index of overriding flow setpoint, 1: set to zero; 2: set to cooling maximum; 3: set to minimum flow; 4: set to heating maximum"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveDamPos
    "Index of overriding damper position, 1: set to close; 2: set to open"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Fan
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSet_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Discharge airflow setpoint after considering override"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final unit="1") "Damper commanded position, or commanded flow rate ratio"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VAdjPopBreZon_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Adjusted population component breathing zone flow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VAdjAreBreZon_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Adjusted area component breathing zone flow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VMinOA_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VZonAbsMin_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Zone absolute minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VZonDesMin_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Zone design minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCO2(
    final unit="1") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "CO2 control loop signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonPreResReq
    "Zone static pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLowFloAla
    "Low airflow alarms"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yFloSenAla
    "Airflow sensor calibration alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaDamAla
    "Leaking damper alarm"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.ActiveAirFlow actAirSet(
    final VCooMax_flow=VCooMax_flow) "Active airflow setpoint"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.SystemRequests sysReq(
    final thrTemDif=thrTemDif,
    final twoTemDif=twoTemDif,
    final durTimTem=durTimTem,
    final durTimFlo=durTimFlo,
    final dTHys=dTHys,
    final floHys=floHys,
    final looHys=looHys,
    final damPosHys=damPosHys,
    final samplePeriod=samplePeriod) "Specify system requests "
  Buildings.Controls.OBC.ASHRAE.G36.ThermalZones.ControlLoops conLoo(
    final kCooCon=kCooCon,
    final TiCooCon=TiCooCon,
    final kHeaCon=kHeaCon,
    final TiHeaCon=TiHeaCon,
    final timChe=timChe,
    final dTHys=dTHys,
    final looHys=looHys) "Heating and cooling control loop"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Alarms ala(
    final staPreMul=staPreMul,
    final VCooMax_flow=VCooMax_flow,
    final lowFloTim=lowFloTim,
    final fanOffTim=fanOffTim,
    final leaFloTim=leaFloTim,
    final floHys=floHys,
    final damPosHys=damPosHys,
    final staTim=staTim)       "Generate alarms"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSup(
    final samplePeriod=samplePeriod,
    final chaRat=chaRat,
    final maxTim=maxSupTim,
    final dTHys=dTHys)
    "Specify suppresion time due to the setpoint change and check if it has passed the suppresion period"
  Buildings.Controls.OBC.ASHRAE.G36.VentilationZones.ASHRAE62_1.Setpoints setPoi(
    final have_winSen=have_winSen,
    final have_occSen=have_occSen,
    final have_CO2Sen=have_CO2Sen,
    final have_typTerUni=true,
    final permit_occStandby=permit_occStandby,
    final VAreBreZon_flow=VAreBreZon_flow,
    final VPopBreZon_flow=VPopBreZon_flow,
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow,
    final zonDisEff_cool=zonDisEff_cool,
    final zonDisEff_heat=zonDisEff_heat,
    final dTHys=dTHys) if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Output the minimum outdoor airflow rate setpoint, when using ASHRAE 62.1"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Dampers
    dam(
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow,
    final damCon=damCon,
    final kDam=kDam,
    final TiDam=TiDam,
    final TdDam=TdDam,
    final dTHys=dTHys) "Damper control"
  Buildings.Controls.OBC.ASHRAE.G36.ThermalZones.ZoneStates zonSta
    "Check if the zone is in cooling state"
  Buildings.Controls.OBC.ASHRAE.G36.VentilationZones.Title24.Setpoints minFlo(
    final have_winSen=have_winSen,
    final have_occSen=have_occSen,
    final have_CO2Sen=have_CO2Sen,
    final have_typTerUni=true,
    final have_parFanPowUni=false,
    final VOccMin_flow=VOccMin_flow,
    final VAreMin_flow=VAreMin_flow,
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow)
    if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Output the minimum outdoor airflow rate setpoint, when using Title 24"
equation
  connect(TZon, timSup.TZon)
  connect(TCooSet, timSup.TSet)
  connect(TCooSet, conLoo.TCooSet)
  connect(TZon, conLoo.TZon)
  connect(THeaSet, conLoo.THeaSet)
  connect(u1Win, setPoi.u1Win)
  connect(u1Occ, setPoi.u1Occ)
  connect(uOpeMod, setPoi.uOpeMod)
  connect(ppmCO2, setPoi.ppmCO2)
  connect(TZon, setPoi.TZon)
  connect(TDis, setPoi.TDis)
  connect(uOpeMod, actAirSet.uOpeMod)
  connect(setPoi.VOccZonMin_flow, actAirSet.VOccMin_flow)
  connect(VDis_flow, dam.VDis_flow)
  connect(conLoo.yCoo, dam.uCoo)
  connect(actAirSet.VActCooMax_flow, dam.VActCooMax_flow)
  connect(TSup, dam.TSup)
  connect(actAirSet.VActMin_flow, dam.VActMin_flow)
  connect(TZon, dam.TZon)
  connect(timSup.yAftSup, sysReq.uAftSup)
  connect(TCooSet, sysReq.TCooSet)
  connect(TZon, sysReq.TZon)
  connect(conLoo.yCoo, sysReq.uCoo)
  connect(VDis_flow, sysReq.VDis_flow)
  connect(VDis_flow, ala.VDis_flow)
  connect(u1Fan, ala.u1Fan)
  connect(sysReq.yZonTemResReq, yZonTemResReq)
  connect(sysReq.yZonPreResReq, yZonPreResReq)
  connect(ala.yLowFloAla, yLowFloAla)
  connect(ala.yFloSenAla, yFloSenAla)
  connect(ala.yLeaDamAla, yLeaDamAla)
  connect(conLoo.yHea, zonSta.uHea)
  connect(conLoo.yCoo, zonSta.uCoo)
  connect(zonSta.yZonSta, dam.uZonSta)
  connect(ppmCO2Set, setPoi.ppmCO2Set)
  connect(u1Win, minFlo.u1Win)
  connect(u1Occ, minFlo.u1Occ)
  connect(uOpeMod, minFlo.uOpeMod)
  connect(ppmCO2Set, minFlo.ppmCO2Set)
  connect(ppmCO2, minFlo.ppmCO2)
  connect(minFlo.VOccZonMin_flow, actAirSet.VOccMin_flow)
  connect(dam.VSet_flow, sysReq.VSet_flow)
  connect(dam.VSet_flow, ala.VActSet_flow)
  connect(oveFloSet, dam.oveFloSet)
  connect(oveDamPos, dam.oveDamPos)
  connect(dam.VSet_flow, VSet_flow)
  connect(dam.yDam, yDam)
  connect(setPoi.VAdjPopBreZon_flow, VAdjPopBreZon_flow)
  connect(setPoi.VAdjAreBreZon_flow, VAdjAreBreZon_flow)
  connect(setPoi.VMinOA_flow, VMinOA_flow)
  connect(minFlo.VZonAbsMin_flow, VZonAbsMin_flow)
  connect(minFlo.VZonDesMin_flow, VZonDesMin_flow)
  connect(minFlo.yCO2, yCO2)
  connect(dam.yDam, sysReq.uDam)
  connect(dam.yDam, ala.uDam)
  connect(u1Fan, dam.u1Fan)
  connect(uOpeMod, ala.uOpeMod)
end Controller;


within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits;
package CoolingOnly "Sequences for VAV cooling only terminal unit"
end CoolingOnly;


Active maximum and minimum setpoints for cooling only terminal unit. This block outputs the active maximum and minimum airflow setpoint for cooling only
terminal unit. The implementation is according to the Section 5.5.4 of ASHRAE
Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences;
block ActiveAirFlow
  "Active maximum and minimum setpoints for cooling only terminal unit"

  parameter Real VCooMax_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone cooling maximum airflow rate";

  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOccMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Occupied minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActHeaMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active heating maximum airflow"

protected
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal actCooMax(
    final realTrue=VCooMax_flow)
    "Active cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Logical.Or or3
    "Check if it is in occupied, cooldown, or setup mode"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    final realTrue=1)
    "Convert boolean to real"
  Buildings.Controls.OBC.CDL.Reals.Multiply actMin
    "Active minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Check if current operation mode is occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant cooDowMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.coolDown)
    "Cool down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant setUpMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.setUp)
    "Setup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu2
    "Check if current operation mode is setup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if current operation mode is cool-down mode"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Check if it is in occupied, cooldown, or setup mode"

equation
  connect(occMod.y, intEqu.u1)
  connect(intEqu2.u1, setUpMod.y)
  connect(cooDowMod.y, intEqu1.u1)
  connect(uOpeMod, intEqu.u2)
  connect(uOpeMod, intEqu1.u2)
  connect(uOpeMod, intEqu2.u2)
  connect(intEqu.y, or3.u1)
  connect(intEqu1.y, or3.u2)
  connect(intEqu.y, booToRea.u)
  connect(booToRea.y, actMin.u1)
  connect(VOccMin_flow, actMin.u2)
  connect(actCooMax.y, VActCooMax_flow)
  connect(actMin.y, VActHeaMax_flow)
  connect(actMin.y, VActMin_flow)
  connect(or3.y, or2.u1)
  connect(intEqu2.y, or2.u2)
  connect(or2.y, actCooMax.u)
end ActiveAirFlow;


Generate alarms of cooling only terminal unit. This block outputs alarms of cooling only terminal unit. The implementation is according
to the Section 5.5.6 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences;
block Alarms "Generate alarms of cooling only terminal unit"

  parameter Real staPreMul
    "Importance multiplier for the zone static pressure reset control loop";
  parameter Real VCooMax_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone cooling maximum airflow rate";
  parameter Real lowFloTim(
    final unit="s",
    final quantity="Time")=300
    "Threshold time to check low flow rate"
  parameter Real fanOffTim(
    final unit="s",
    final quantity="Time")=600
    "Threshold time to check fan off"
  parameter Real leaFloTim(
    final unit="s",
    final quantity="Time")=600
    "Threshold time to check leaking flow"
  parameter Real floHys(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"
  parameter Real damPosHys(
    final unit="1")
    "Near zero damper position, below which the damper will be seen as closed"
  parameter Real staTim(
    final unit="s",
    final quantity="Time")=1800
    "Delay triggering alarms after enabling AHU supply fan"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Measured discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActSet_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Fan
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDam(
    final min=0,
    final unit="1")
    "Damper position setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLowFloAla
    "Low airflow alarms"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yFloSenAla
    "Airflow sensor calibration alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaDamAla
    "Leaking damper alarm"

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=0.5)
    "Percentage of the setpoint"
  Buildings.Controls.OBC.CDL.Reals.Less les(
    final h=floHys)
    "Check if measured airflow is less than threshold"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel(
    final delayTime=lowFloTim)
    "Check if the measured airflow has been less than threshold value for threshold time"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=floHys,
    final h=0.5*floHys)
    "Check if setpoint airflow is greater than zero"
  Buildings.Controls.OBC.CDL.Reals.Greater gre(
    final h=floHys)
    "Check if measured airflow is less than threshold"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(
    final k=0.7)
    "Percentage of the setpoint"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel1(
    final delayTime=lowFloTim)
    "Check if the measured airflow has been less than threshold value for threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Measured airflow has been less than threshold value for sufficient time"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "Measured airflow has been less than threshold value for sufficient time"
  Buildings.Controls.OBC.CDL.Integers.Switch lowFloAla
    "Low airflow alarm"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=2)
    "Level 2 alarm"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt(
    final integerTrue=3)
    "Convert boolean true to level 3 alarm"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conInt1(
    final k=staPreMul)
    "Importance multiplier for zone static pressure reset"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1
    "Check if the multiplier is greater than zero"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1
    "Suppress the alarm when multiplier is zero"
  Buildings.Controls.OBC.CDL.Integers.Multiply proInt
    "Low flow alarms"
  Buildings.Controls.OBC.CDL.Logical.And and8
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Warning: airflow is less than 50% of the setpoint.")
    "Level 2 low airflow alarm"
  Buildings.Controls.OBC.CDL.Logical.And and4
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not2
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes1(
    final message="Warning: airflow is less than 70% of the setpoint.")
    "Level 3 low airflow alarm"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooMaxFlo(
    final k=VCooMax_flow)
    "Cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai2(
    final k=0.1)
    "Percentage of the setpoint"
  Buildings.Controls.OBC.CDL.Logical.Not not3
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel2(
    final delayTime=fanOffTim)
    "Check if the input has been true for more than threshold time"
  Buildings.Controls.OBC.CDL.Reals.Greater gre1(
    final h=floHys)
    "Check if measured airflow is greater than threshold"
  Buildings.Controls.OBC.CDL.Logical.And and5
    "Check if the measured airflow is greater than the threshold and the supply fan is OFF"
  Buildings.Controls.OBC.CDL.Logical.Not not4
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes2(
    final message="Warning: airflow sensor should be calibrated.")
    "Level 3 airflow sensor alarm"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt2(
    final integerTrue=3)
    "Convert boolean true to level 3 alarm"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel3(
    final delayTime=leaFloTim)
    "Check if the input has been true for more than threshold time"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold cloDam(
    final t=damPosHys,
    final h=0.5*damPosHys)
    "Check if damper position is near zero"
  Buildings.Controls.OBC.CDL.Logical.And leaDamAla1
    "Check if generating leak damper alarms, one of two stacked And blocks"
  Buildings.Controls.OBC.CDL.Logical.And leaDamAla2
    "Check if generating leak damper alarms, one of two stacked And blocks"
  Buildings.Controls.OBC.CDL.Logical.Not not5 "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes3(
    final message="Warning: the damper is leaking.")
    "Level 4 leaking damper alarm"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt3(
    final integerTrue=4)
    "Convert boolean true to level 4 alarm"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel4(
    final delayTime=lowFloTim)
    "Check if the active flow setpoint has been greater than zero for the threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and11
    "True: AHU fan is enabled and the discharge flow is lower than the threshold"
  Buildings.Controls.OBC.CDL.Logical.And and10
    "True: AHU fan is enabled and the discharge flow is lower than the threshold"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay fanIni(
    final delayTime=staTim)
    "Check if the AHU supply fan has been enabled for threshold time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal isOcc
    "Check if current operation mode is occupied mode"
  Buildings.Controls.OBC.CDL.Logical.And  and6
    "Check if the measured airflow is greater than the threshold and the supply fan is OFF"
  Buildings.Controls.OBC.CDL.Logical.And and7
    "Measured airflow has been less than threshold value for sufficient time"
  Buildings.Controls.OBC.CDL.Logical.And and3
    "Measured airflow has been less than threshold value for sufficient time"
equation
  connect(VActSet_flow, gai.u)
  connect(VDis_flow, les.u1)
  connect(VActSet_flow, greThr.u)
  connect(VActSet_flow, gai1.u)
  connect(VDis_flow, gre.u2)
  connect(gai1.y, gre.u1)
  connect(truDel.y, and2.u1)
  connect(truDel1.y, and1.u2)
  connect(conInt.y, lowFloAla.u1)
  connect(booToInt.y, lowFloAla.u3)
  connect(conInt1.y, greThr1.u)
  connect(greThr1.y, booToInt1.u)
  connect(lowFloAla.y, proInt.u1)
  connect(booToInt1.y, proInt.u2)
  connect(not1.y, assMes.u)
  connect(and2.y,and8. u1)
  connect(greThr1.y,and8. u2)
  connect(and1.y, and4.u1)
  connect(greThr1.y, and4.u2)
  connect(not2.y, assMes1.u)
  connect(cooMaxFlo.y, gai2.u)
  connect(u1Fan, not3.u)
  connect(gai2.y, gre1.u2)
  connect(VDis_flow, gre1.u1)
  connect(not4.y, assMes2.u)
  connect(booToInt2.y, yFloSenAla)
  connect(proInt.y, yLowFloAla)
  connect(uDam, cloDam.u)
  connect(not5.y, assMes3.u)
  connect(booToInt3.y, yLeaDamAla)
  connect(greThr.y, truDel4.u)
  connect(truDel4.y, and1.u1)
  connect(truDel4.y, and2.u2)
  connect(and5.y, truDel2.u)
  connect(gre1.y, and5.u1)
  connect(not3.y, and5.u2)
  connect(truDel3.y, booToInt3.u)
  connect(truDel3.y, not5.u)
  connect(les.y, and10.u1)
  connect(and10.y, truDel.u)
  connect(gre.y, and11.u1)
  connect(and11.y, truDel1.u)
  connect(u1Fan, fanIni.u)
  connect(fanIni.y, and11.u2)
  connect(fanIni.y, and10.u2)
  connect(occMod.y,isOcc. u2)
  connect(uOpeMod,isOcc. u1)
  connect(and6.y, booToInt2.u)
  connect(and6.y, not4.u)
  connect(truDel2.y, and6.u1)
  connect(isOcc.y, and6.u2)
  connect(gai.y, les.u2)
  connect(and8.y, and7.u1)
  connect(and7.y, lowFloAla.u2)
  connect(and7.y, not1.u)
  connect(and3.y, booToInt.u)
  connect(and3.y, not2.u)
  connect(and4.y, and3.u1)
  connect(isOcc.y, and7.u2)
  connect(isOcc.y, and3.u2)
  connect(u1Fan, leaDamAla1.u1)
  connect(cloDam.y, leaDamAla1.u2)
  connect(leaDamAla1.y, leaDamAla2.u1)
  connect(gre1.y, leaDamAla2.u2)
  connect(leaDamAla2.y, truDel3.u)
end Alarms;


Output signals for controlling VAV cooling only box damper position. This sequence sets the damper position for VAV cooling only terminal unit. The
implementation is according to Section 5.5.5 and 5.5.7 of ASHRAE Guideline 36 (G36), May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences;
block Dampers
  "Output signals for controlling VAV cooling only box damper position"

  parameter Real VMin_flow(unit="m3/s")
    "Design zone minimum airflow setpoint";
  parameter Real VCooMax_flow(unit="m3/s")
    "Design zone cooling maximum airflow rate";
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController damCon=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real kDam(unit="1")=0.5
    "Gain of controller for damper control"
  parameter Real TiDam(unit="s")=300
    "Time constant of integrator block for damper control"
  parameter Real TdDam(unit="s")=0.1
    "Time constant of derivative block for damper control"
  parameter Real dTHys(unit="K")=0.25
    "Delta between the temperature hysteresis high and low limit"
  parameter Real iniDam(unit="1")=0.01
    "Initial damper position when the damper control is enabled"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active minimum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSup(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Temperature of the air supplied from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC") "Measured zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCoo(
    final min=0,
    final max=1,
    final unit="1") "Cooling loop signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active cooling maximum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uZonSta
    "Current zone state"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveFloSet
    "Index of overriding flow setpoint, 1: set to zero; 2: set to cooling maximum; 3: set to minimum flow"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Fan
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured primary discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveDamPos
    "Index of overriding damper position, 1: set to close; 2: set to open"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSet_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Airflow setpoint after considering override"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final unit="1")
    "Commanded damper position after considering override"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(
    final k=1) "Constant one"
  Buildings.Controls.OBC.CDL.Reals.Line lin
    "Map cooling loop output to the active airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Greater gre(
    final h=dTHys)
    "Check if supplyair temperature from the air handler is greater than room temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Select active airfow setpoint based on difference between supply and zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch actFlo
    "Specify active flow setpoint based on the zone status"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conPID(
    final controllerType=damCon,
    final k=kDam,
    final Ti=TiDam,
    final Td=TdDam,
    final y_reset=iniDam)
    "Damper controller"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.ZoneStates.cooling)
    "Cooling state value"
  Buildings.Controls.OBC.CDL.Integers.Equal cooSta
    "Check if zone is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant nomFlow(
    final k=VCooMax_flow)
    "Nominal volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.Divide VDisSet_flowNor
    "Normalized setpoint for discharge volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.Divide VDis_flowNor
    "Normalized discharge volume flow rate"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    final k=1)
    "Constant 1"
  Buildings.Controls.OBC.CDL.Integers.Equal forZerFlo
    "Check if forcing zone airflow setpoint to zero"
  Buildings.Controls.OBC.CDL.Integers.Equal forCooMax
    "Check if forcing zone airflow setpoint to cooling maximum"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Integers.Equal forMinFlo
    "Check if forcing zone airflow setpoint to minimum flow"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    final k=3)
    "Constant 3"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal zerFlo(
    final realTrue=0)
    "Force zone airflow setpoint to zero"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal cooMax(
    final realTrue=VCooMax_flow)
    "Force zone airflow setpoint to cooling maximum"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal minFlo(
    final realTrue=VMin_flow)
    "Force zone airflow setpoint to zone minimum flow"
  Buildings.Controls.OBC.CDL.Reals.Add add2
    "Add up two inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add1
    "Add up inputs"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Airflow setpoint after considering override"
  Buildings.Controls.OBC.CDL.Logical.Or or3
    "Check if the airflow setpoint should be overrided"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    final k=1)
    "Constant 1"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu3
    "Check if forcing damper to full close"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu4
    "Check if forcing damper to full open"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt5(final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal cloDam(
    final realTrue=0)
    "Full closed damper position"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal opeDam(
    final realTrue=1)
    "Full open damper position"
  Buildings.Controls.OBC.CDL.Reals.Add add3
    "Add up inputs"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Check if the damper setpoint position should be overrided"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Damper setpoint position after considering override"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "Check if the airflow setpoint should be overrided"

equation
  connect(conInt.y, cooSta.u1)
  connect(uZonSta, cooSta.u2)
  connect(con.y, lin.x1)
  connect(con1.y, lin.x2)
  connect(uCoo, lin.u)
  connect(TSup, gre.u1)
  connect(TZon, gre.u2)
  connect(gre.y, swi.u2)
  connect(lin.y, swi.u3)
  connect(VActMin_flow, lin.f1)
  connect(VActMin_flow, swi.u1)
  connect(VActCooMax_flow, lin.f2)
  connect(cooSta.y, actFlo.u2)
  connect(VActMin_flow, actFlo.u3)
  connect(swi.y, actFlo.u1)
  connect(nomFlow.y, VDisSet_flowNor.u2)
  connect(nomFlow.y, VDis_flowNor.u2)
  connect(VDis_flow, VDis_flowNor.u1)
  connect(VDisSet_flowNor.y, conPID.u_s)
  connect(VDis_flowNor.y, conPID.u_m)
  connect(oveFloSet,forZerFlo. u1)
  connect(conInt1.y, forZerFlo.u2)
  connect(oveFloSet,forCooMax. u1)
  connect(conInt2.y,forCooMax. u2)
  connect(oveFloSet,forMinFlo. u1)
  connect(conInt3.y,forMinFlo. u2)
  connect(forZerFlo.y,zerFlo. u)
  connect(forCooMax.y,cooMax. u)
  connect(forMinFlo.y,minFlo. u)
  connect(cooMax.y,add2. u1)
  connect(minFlo.y,add2. u2)
  connect(zerFlo.y,add1. u1)
  connect(add2.y,add1. u2)
  connect(add1.y, swi1.u1)
  connect(swi1.y, VSet_flow)
  connect(actFlo.y, swi1.u3)
  connect(swi1.y, VDisSet_flowNor.u1)
  connect(oveDamPos,intEqu3. u1)
  connect(oveDamPos,intEqu4. u1)
  connect(intEqu3.y,cloDam. u)
  connect(intEqu4.y,opeDam. u)
  connect(cloDam.y,add3. u1)
  connect(opeDam.y,add3. u2)
  connect(intEqu3.y,or2. u1)
  connect(intEqu4.y,or2. u2)
  connect(or2.y,swi2. u2)
  connect(swi2.y, yDam)
  connect(conPID.y, swi2.u3)
  connect(conInt5.y, intEqu4.u2)
  connect(conInt4.y, intEqu3.u2)
  connect(add3.y, swi2.u1)
  connect(u1Fan, conPID.trigger)
  connect(or1.y, swi1.u2)
  connect(or3.y, or1.u2)
  connect(forMinFlo.y, or1.u1)
  connect(forCooMax.y, or3.u1)
  connect(forZerFlo.y, or3.u2)
end Dampers;


within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly;
package Subsequences "Package of subsequences for cooling only box control"
end Subsequences;


Output system requests for VAV cooling only terminal unit. This sequence outputs the system reset requests for cooling only terminal unit. The
implementation is according to the Section 5.5.8 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences;
block SystemRequests
  "Output system requests for VAV cooling only terminal unit"

  parameter Real thrTemDif(
    final unit="K",
    final quantity="TemperatureDifference")=3
    "Threshold difference between zone temperature and cooling setpoint for generating 3 cooling SAT reset requests"
  parameter Real twoTemDif(
    final unit="K",
    final quantity="TemperatureDifference")=2
    "Threshold difference between zone temperature and cooling setpoint for generating 2 cooling SAT reset requests"
  parameter Real durTimTem(
    final unit="s",
    final quantity="Time")=120
    "Duration time of zone temperature exceeds setpoint"
  parameter Real durTimFlo(
    final unit="s",
    final quantity="Time")=60
    "Duration time of airflow rate less than setpoint"
  parameter Real dTHys(
    final unit="K",
    final quantity="TemperatureDifference")=0.25
    "Near zero temperature difference, below which the difference will be seen as zero"
  parameter Real floHys(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"
  parameter Real looHys(unit="1")
    "Loop output hysteresis below which the output will be seen as zero"
  parameter Real damPosHys(
    final unit="1")
    "Near zero damper position, below which the damper will be seen as closed"
  parameter Real samplePeriod(
    final unit="s",
    final quantity="Time")=120
    "Sample period of component, set to the same value as the trim and respond that process yPreSetReq"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uAftSup
    "After suppression period due to the setpoint change"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TCooSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCoo(
    final min=0,
    final max=1,
    final unit="1")
    "Cooling loop signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VSet_flow(
    final min=0,
    final unit="m3/s",
    quantity="VolumeFlowRate")
    "Discharge airflow rate setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDam(
    final min=0,
    final max=1,
    final unit="1")
    "Damper position setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonPreResReq
    "Zone static pressure reset requests"

protected
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1(
    final t=thrTemDif,
    final h=dTHys)
    "Check if zone temperature is greater than cooling setpoint by threshold"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2(
    final t=twoTemDif,
    final h=dTHys)
    "Check if zone temperature is greater than cooling setpoint by threshold"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr3(
    final t=0.95,
    final h=damPosHys)
    "Check if damper position is greater than 0.95"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=0.95, final h=looHys)
    "Check if cooling loop signal is greater than 0.95"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr4(
    final t=floHys,
    final h=0.5*floHys)
    "Check if discharge airflow setpoint is greater than 0"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt
    "Convert boolean to integer"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1
    "Convert boolean to integer"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(
    final k=0.5)
    "50% of setpoint"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai2(
    final k=0.7)
    "70% of setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    "Calculate difference between zone temperature and cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub3
    "Calculate difference between zone temperature and cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.And and1
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and3
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and4
    "Logical and"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant thrCooResReq(
    final k=3)
    "Constant 3"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant twoCooResReq(
    final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant thrPreResReq(
    final k=3)
    "Constant 3"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant twoPreResReq(
    final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi
    "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi1
    "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Integers.Switch swi4
    "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Integers.Switch swi5
    "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim1(
    final delayTime=durTimTem) "Check if it is more than threshold time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim2(
    final delayTime=durTimTem) "Check if it is more than threshold time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim3(
    final delayTime=durTimFlo) "Check if it is more than threshold time"
  Buildings.Controls.OBC.CDL.Reals.Greater greEqu(final h=floHys)
    "Check if discharge airflow is less than 50% of setpoint"
  Buildings.Controls.OBC.CDL.Reals.Greater greEqu1(final h=floHys)
    "Check if discharge airflow is less than 70% of setpoint"
  Buildings.Controls.OBC.CDL.Logical.And and5
    "Logical and"
  Buildings.Controls.OBC.CDL.Discrete.Sampler sampler(
    final samplePeriod=samplePeriod)
    "Sample input signal, as the output signal will go to the trim and respond which also samples at samplePeriod"
  Buildings.Controls.OBC.CDL.Discrete.Sampler sampler1(
    final samplePeriod=samplePeriod)
    "Sample input signal, as the output signal will go to the trim and respond which also samples at samplePeriod"
  Buildings.Controls.OBC.CDL.Discrete.Sampler sampler2(
    final samplePeriod=samplePeriod)
    "Sample input signal, as the output signal will go to the trim and respond which also samples at samplePeriod"
  Buildings.Controls.OBC.CDL.Discrete.Sampler sampler3(
    final samplePeriod=samplePeriod)
    "Sample input signal, as the output signal will go to the trim and respond which also samples at samplePeriod"

equation
  connect(sub2.y, greThr1.u)
  connect(and2.y, intSwi.u2)
  connect(sub3.y, greThr2.u)
  connect(and1.y, intSwi1.u2)
  connect(and3.y, swi4.u2)
  connect(and4.y, swi5.u2)
  connect(greThr2.y, tim2.u)
  connect(tim2.y, and1.u2)
  connect(greThr1.y, tim1.u)
  connect(tim1.y, and2.u2)
  connect(greEqu.u1, gai1.y)
  connect(greEqu.y, and3.u2)
  connect(gai2.y, greEqu1.u1)
  connect(greEqu1.y, and4.u2)
  connect(uAftSup, and2.u1)
  connect(uAftSup, and1.u1)
  connect(thrCooResReq.y, intSwi.u1)
  connect(twoCooResReq.y, intSwi1.u1)
  connect(intSwi1.y, intSwi.u3)
  connect(intSwi.y, yZonTemResReq)
  connect(greThr.y, booToInt.u)
  connect(booToInt.y, intSwi1.u3)
  connect(greThr3.y, tim3.u)
  connect(greThr4.y, and5.u1)
  connect(tim3.y, and5.u2)
  connect(and5.y, and3.u1)
  connect(and5.y, and4.u1)
  connect(greThr3.y, booToInt1.u)
  connect(booToInt1.y, swi5.u3)
  connect(twoPreResReq.y, swi5.u1)
  connect(thrPreResReq.y, swi4.u1)
  connect(swi5.y, swi4.u3)
  connect(swi4.y, yZonPreResReq)
  connect(TCooSet, sub2.u2)
  connect(TCooSet, sub3.u2)
  connect(TZon, sub2.u1)
  connect(TZon, sub3.u1)
  connect(uCoo, sampler.u)
  connect(sampler.y, greThr.u)
  connect(uDam, sampler1.u)
  connect(sampler1.y, greThr3.u)
  connect(VDis_flow, sampler2.u)
  connect(sampler2.y, greEqu.u2)
  connect(sampler2.y, greEqu1.u2)
  connect(greThr4.u, sampler3.y)
  connect(sampler3.u, VSet_flow)
  connect(sampler3.y, gai1.u)
  connect(sampler3.y, gai2.u)
end SystemRequests;


Validate the model for calculating active airflow setpoint for VAV cooling only unit. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.ActiveAirFlow
for calculating active minimum and maximum airflow setpoint used in cooling only unit control.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Validation;
model ActiveAirFlow
  "Validate the model for calculating active airflow setpoint for VAV cooling only unit"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.ActiveAirFlow actAirSet(final
      VCooMax_flow=0.5) "Output the active airflow setpoint for terminal unit"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin minFlo(
    final amplitude=0.3,
    final freqHz=1/3600,
    final offset=0.2) "Occupied zone minimum flow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp opeMod(
    final offset=1,
    final height=5,
    final duration=3600)
    "Operation mode"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(final n=0)
    "Round real number to given digits"

equation
  connect(opeMod.y,round2. u)
  connect(round2.y,reaToInt2. u)
  connect(reaToInt2.y, actAirSet.uOpeMod)
  connect(minFlo.y, actAirSet.VOccMin_flow)
end ActiveAirFlow;


Validation of model that generates alarms. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Alarms
for generating system alarms.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Validation;
model Alarms "Validation of model that generates alarms"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Alarms ala(
    final staPreMul=1,
    final VCooMax_flow=0.5,
    final floHys=0.01,
    final damPosHys=0.01) "Block outputs system alarms"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirSet(
    final height=0.9,
    final duration=7200,
    final offset=0.1) "Discharge airflow rate setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirRate(
    final duration=7200,
    final offset=0.1,
    final height=0.3) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp damPos(
    final duration=7200,
    final height=0.7,
    final offset=0.3) "Damper position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFan(
    final width=0.75, final period=7500) "Supply fan status"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea
    "Convert boolean input to real output"
  Buildings.Controls.OBC.CDL.Reals.Multiply mul
    "Damper position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse damSta(
    final width=0.5,
    final period=7500)
    "Damper open and close status"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    amplitude=6,
    width=0.1,
    period=8500,
    offset=1)
    "Operation mode"
equation
  connect(disAirRate.y, ala.VDis_flow)
  connect(disAirSet.y, ala.VActSet_flow)
  connect(supFan.y, ala.u1Fan)
  connect(booToRea.y, mul.u1)
  connect(damPos.y, mul.u2)
  connect(mul.y, ala.uDam)
  connect(damSta.y, booToRea.u)
  connect(intPul.y, ala.uOpeMod)
end Alarms;


Validate model for controlling damper position of cooling  only terminal unit. This example validates

BBuildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Dampers
for damper control of VAV cooling only terminal unit.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Validation;
model Dampers
  "Validate model for controlling damper position of cooling  only terminal unit"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Dampers dam1(
    final VMin_flow=0.01,
    final VCooMax_flow=0.09,
    final kDam=1) "Output signal for controlling damper position"

  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uCoo(
    final height=1,
    final duration=3600,
    final offset=0,
    final startTime=900)
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZon(
    final k=273.15 + 22)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSup(
    final k=273.15 + 13)
    "AHU supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActMin_flow(
    final k=0.01)
    "Active minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActCooMax_flow(
    final k=0.075)
    "Active cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin VDis_flow(
    final offset=0.015,
    final amplitude=0.002,
    final freqHz=1/3600)  "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp zonSta(
    final offset=3,
    final height=-2,
    final duration=1000,
    startTime=1800) "Zone state"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveFlo(
    final height=3,
    final duration=2000,
    startTime=1000) "Override flow setpoint"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round1(final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveDam(
    final height=2,
    final duration=2000,
    startTime=1000) "Override damper position"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt3
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round3(final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.9,
    final period=4800,
    final shift=180) "AHU fan status"
equation
  connect(zonSta.y,round2. u)
  connect(round2.y,reaToInt2. u)
  connect(VActMin_flow.y, dam1.VActMin_flow)
  connect(TSup.y, dam1.TSup)
  connect(TZon.y, dam1.TZon)
  connect(VActCooMax_flow.y, dam1.VActCooMax_flow)
  connect(reaToInt2.y, dam1.uZonSta)
  connect(VDis_flow.y, dam1.VDis_flow)
  connect(uCoo.y, dam1.uCoo)
  connect(oveFlo.y,round1. u)
  connect(round1.y,reaToInt1. u)
  connect(oveDam.y,round3. u)
  connect(round3.y,reaToInt3. u)
  connect(reaToInt1.y, dam1.oveFloSet)
  connect(reaToInt3.y, dam1.oveDamPos)
  connect(booPul.y, dam1.u1Fan)
end Dampers;


Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences;
package Validation "Collection of validation models"
end Validation;


Validation of model that generates system requests. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.SystemRequests
for generating system requests.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.Validation;
model SystemRequests
  "Validation of model that generates system requests"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Subsequences.SystemRequests sysReq(
    final floHys=0.01,
    final looHys=0.01,
    final damPosHys=0.01) "Block outputs system requests"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine(
    final freqHz=1/7200,
    final offset=296.15) "Generate data for setpoint"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay TZonCooSet(
    final samplePeriod=1800)
    "Cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TZon(
    final freqHz=1/7200,
    final amplitude=2,
    final offset=299.15) "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uCoo(
    final height=0.9,
    final duration=7200,
    final offset=0.1) "Cooling loop signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirSet(
    final height=0.9,
    final duration=7200,
    final offset=0.1) "Discharge airflow rate setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirRate(
    final duration=7200,
    final offset=0.1,
    final height=0.3) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp damPos(
    final duration=7200,
    final height=0.7,
    final offset=0.3) "Damper position"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse booPul(
    final width=0.1,
    final period=7200)
    "After suppression"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"

equation
  connect(sine.y, TZonCooSet.u)
  connect(TZonCooSet.y, sysReq.TCooSet)
  connect(TZon.y, sysReq.TZon)
  connect(uCoo.y, sysReq.uCoo)
  connect(disAirRate.y, sysReq.VDis_flow)
  connect(disAirSet.y, sysReq.VSet_flow)
  connect(damPos.y, sysReq.uDam)
  connect(booPul.y, not1.u)
  connect(not1.y, sysReq.uAftSup)
end SystemRequests;


Validation of model that controls cooling only unit. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Controller.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Validation;
model Controller
  "Validation of model that controls cooling only unit"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly.Controller cooBoxCon(
    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,
    final VAreBreZon_flow=0.006,
    final VPopBreZon_flow=0.005,
    final VMin_flow=0.5,
    final VCooMax_flow=1.5,
    final staPreMul=1,
    final floHys=0.01,
    final looHys=0.01,
    final damPosHys=0.01,
    final VOccMin_flow=0,
    final VAreMin_flow=0) "Cooling only unit controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TZon(
    final freqHz=1/86400,
    final amplitude=4,
    final offset=299.15)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirTem(
    final height=2,
    final duration=43200,
    final offset=273.15 + 15,
    final startTime=28800)
    "Discharge airflow temperture"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(
    final width=0.05,
    final period=43200,
    final shift=43200)
    "Window opening status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooSet(
    final k=273.15 + 24)
    "Zone cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaSet(
    final k=273.15 + 20)
    "Zone heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse occ(
    final width=0.75,
    final period=43200,
    final shift=28800) "Occupancy status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp opeMod(
    final offset=1,
    final height=2,
    final duration=28800,
    final startTime=28800)
    "Operation mode"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round2(
    final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin CO2(
    final amplitude=400,
    final freqHz=1/28800,
    final offset=600) "CO2 concentration"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp supAirTem(
    final height=2,
    final duration=43200,
    final offset=273.15 + 14)
    "Supply air temperature from air handling unit"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin VDis_flow(
    final offset=1.2,
    final amplitude=0.6,
    final freqHz=1/28800) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveFlo(
    final height=2,
    final duration=10000,
    final startTime=35000)
    "Override flow setpoint"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round1(
    final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveDam(
    final height=2,
    final duration=5000,
    startTime=60000) "Override damper position"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt3
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round3(
    final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFanSta(
    final width=0.9,
    final period=73200,
    final shift=18800) "Supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant CO2Set(final k=894)
    "CO2 concentration setpoint"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"
equation
  connect(TZon.y, cooBoxCon.TZon)
  connect(cooSet.y, cooBoxCon.TCooSet)
  connect(heaSet.y, cooBoxCon.THeaSet)
  connect(occ.y, cooBoxCon.u1Occ)
  connect(opeMod.y,round2. u)
  connect(round2.y,reaToInt2. u)
  connect(reaToInt2.y, cooBoxCon.uOpeMod)
  connect(CO2.y, cooBoxCon.ppmCO2)
  connect(disAirTem.y, cooBoxCon.TDis)
  connect(supAirTem.y, cooBoxCon.TSup)
  connect(VDis_flow.y, cooBoxCon.VDis_flow)
  connect(oveFlo.y,round1. u)
  connect(round1.y,reaToInt1. u)
  connect(oveDam.y, round3.u)
  connect(round3.y,reaToInt3. u)
  connect(reaToInt1.y, cooBoxCon.oveFloSet)
  connect(reaToInt3.y, cooBoxCon.oveDamPos)
  connect(supFanSta.y, cooBoxCon.u1Fan)
  connect(CO2Set.y, cooBoxCon.ppmCO2Set)
  connect(winSta.y, not2.u)
  connect(not2.y, cooBoxCon.u1Win)
end Controller;


Collection of validation models

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.CoolingOnly;
package Validation "Collection of validation models"
end Validation;


Controller for dual-duct terminal unit with cold-duct minimum control. Controller for dual-duct terminal unit with cold-duct minimum control
according to Section 5.14 of ASHRAE
Guideline 36, May 2020. It outputs discharge airflow setpoint VSet_flow,
cold and hot duct dampers position setpoint (yCooDam, yHeaDam),
cooling supply temperature setpoint reset request yZonCooTemResReq,
heating supply temperature setpoint reset request yZonHeaTemResReq,
cold-duct static pressure setpoint reset request yColDucPreResReq,
hot-duct static pressure setpoint reset request yHotDucPreResReq,
heating fan request yHeaFanReq.
It also outputs the alarms about the low airflow yLowFloAla,
leaking dampers, and airflow sensor(s) calibration alarm.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin;
block Controller "Controller for dual-duct terminal unit with cold-duct minimum control"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard venStd
    "Ventilation standard, ASHRAE 62.1 or Title 24";
  parameter Boolean have_winSen=true
    "True: the zone has window sensor"
  parameter Boolean have_occSen=true
    "True: the zone has occupancy sensor"
  parameter Boolean have_CO2Sen=true
    "True: the zone has CO2 sensor"
  parameter Boolean permit_occStandby=true
    "True: occupied-standby mode is permitted"
  parameter Real VOccMin_flow(unit="m3/s")
    "Zone minimum outdoor airflow for occupants"
  parameter Real VAreMin_flow(unit="m3/s")
    "Zone minimum outdoor airflow for building area"
  // ---------------- Design parameters ----------------
  parameter Real VAreBreZon_flow(unit="m3/s")
    "Design area component of the breathing zone outdoor airflow"
  parameter Real VPopBreZon_flow(unit="m3/s")
    "Design population component of the breathing zone outdoor airflow"
  parameter Real VMin_flow(unit="m3/s")
    "Design zone minimum airflow setpoint"
  parameter Real VCooMax_flow(unit="m3/s")
    "Design zone cooling maximum airflow rate"
  parameter Real VHeaMax_flow(unit="m3/s")
    "Design zone heating maximum airflow rate"
  // ---------------- Control loop parameters ----------------
  parameter Real kCooCon=0.1
    "Gain of controller for cooling control loop"
  parameter Real TiCooCon(unit="s")=900
    "Time constant of integrator block for cooling control loop"
  parameter Real kHeaCon=0.1
    "Gain of controller for heating control loop"
  parameter Real TiHeaCon(unit="s")=900
    "Time constant of integrator block for heating control loop"
  // ---------------- Dampers control parameters ----------------
  parameter CDL.Types.SimpleController controllerTypeDam=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller"
  parameter Real kDam=0.5
    "Gain of controller for damper control"
  parameter Real TiDam(unit="s")=300
    "Time constant of integrator block for damper control"
  parameter Real TdDam(unit="s")=0.1
    "Time constant of derivative block for damper control"
  // ---------------- System request parameters ----------------
  parameter Real thrTemDif(unit="K")=3
    "Threshold difference between zone temperature and cooling setpoint for generating 3 cooling SAT reset requests"
  parameter Real twoTemDif(unit="K")=2
    "Threshold difference between zone temperature and cooling setpoint for generating 2 cooling SAT reset requests"
  parameter Real durTimTem(unit="s")=120
    "Duration time of zone temperature exceeds setpoint"
  parameter Real durTimFlo(unit="s")=60
    "Duration time of airflow rate less than setpoint"
  // ---------------- Parameters for alarms ----------------
  parameter Real staPreMul=1
    "Importance multiplier for the zone static pressure reset control loop"
  parameter Real lowFloTim(unit="s")=300
    "Threshold time to check low flow rate"
  parameter Real fanOffTim(unit="s")=600
    "Threshold time to check fan off"
  parameter Real leaFloTim(unit="s")=600
    "Threshold time to check damper leaking airflow"
  // ---------------- Parameters for time-based suppression ----------------
  parameter Real chaRat(final unit="s/K")=540
    "Gain factor to calculate suppression time based on the change of the setpoint, seconds per Kelvin"
  parameter Real maxSupTim(unit="s")=1800
    "Maximum suppression time"
  // ---------------- Advanced parameters ----------------
  parameter Real dTHys(unit="K")=0.25
    "Near zero temperature difference, below which the difference will be seen as zero"
  parameter Real looHys(unit="1")=0.01
    "Loop output hysteresis below which the output will be seen as zero"
  parameter Real floHys(unit="m3/s")=0.01*VMin_flow
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"
  parameter Real damPosHys(unit="1")=0.005
    "Near zero damper position, below which the damper will be seen as closed"
  parameter Real staTim(
    final unit="s",
    final quantity="Time")=1800
    "Delay triggering alarms after enabling AHU supply fan"
  parameter Real iniDam(unit="1")=0.01
    "Initial damper position when the damper control is enabled"
  parameter Real timChe(unit="s")=30
    "Threshold time to check the zone temperature status"
  parameter Real zonDisEff_cool(unit="1")=1.0
    "Zone cooling air distribution effectiveness"
  parameter Real zonDisEff_heat(unit="1")=0.8
    "Zone heating air distribution effectiveness"
  parameter Real samplePeriod(unit="s")=120
    "Sample period of component, set to the same value as the trim and respond that process static pressure reset"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Measured room temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TCooSet(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC") "Setpoint temperature for room for cooling"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSet(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC") "Setpoint temperature for room for heating"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Win if have_winSen
    "Window status, normally closed (true), when windows open, it becomes false"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Occ if have_occSen
    "True: the zone is populated"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2Set if have_CO2Sen
    "CO2 concentration setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2 if have_CO2Sen
    "Detected CO2 concentration"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC") "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TColSup(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Cold duct supply air temperature from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VColDucDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured cold-duct discharge airflow rate airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1CooAHU
    "Cooling air handler status"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THotSup(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    final displayUnit="degC")
    "Hot duct supply air temperature from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VHotDucDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured hot-duct discharge airflow rate airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1HeaAHU
    "Heating air handler status"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveFloSet
    "Index of overriding flow setpoint, 1: set to zero; 2: set to cooling maximum; 3: set to minimum flow; 4: set to heating maximum"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveCooDamPos
    "Index of overriding cooling damper position, 1: set to close; 2: set to open"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveHeaDamPos
    "Index of overriding heating damper position, 1: set to close; 2: set to open"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VSet_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Airflow setpoint after considering override"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCooDam(
    final min=0,
    final max=1,
    final unit="1")
    "Cooling damper commanded position, or commanded flow rate ratio"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yHeaDam(
    final min=0,
    final max=1,
    final unit="1")
    "Heating damper commanded position, or commanded flow rate ratio"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VAdjPopBreZon_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Adjusted population component breathing zone flow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VAdjAreBreZon_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Adjusted area component breathing zone flow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VMinOA_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VZonAbsMin_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Zone absolute minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VZonDesMin_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Zone design minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yCO2(
    final unit="1") if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "CO2 control loop signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonCooTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yColDucPreResReq
    "Cold duct pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonHeaTemResReq
    "Zone heating supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotDucPreResReq
    "Hot duct pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaFanReq
    "Heating fan request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLowFloAla
    "Low airflow alarms"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yColFloSenAla
    "Cold-duct airflow sensor calibration alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yColLeaDamAla
    "Leaking cold-duct damper alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotFloSenAla
    "Hot-duct airflow sensor calibration alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotLeaDamAla
    "Leaking hot-duct damper alarm"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences.ActiveAirFlow
    actAirSet(
    final VCooMax_flow=VCooMax_flow,
    final VHeaMax_flow=VHeaMax_flow,
    final floHys=floHys) "Active airflow setpoint"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences.SystemRequests
    sysReq(
    final thrTemDif=thrTemDif,
    final twoTemDif=twoTemDif,
    final durTimTem=durTimTem,
    final durTimFlo=durTimFlo,
    final dTHys=dTHys,
    final floHys=floHys,
    final looHys=looHys,
    final damPosHys=damPosHys) "Specify system requests "
  Buildings.Controls.OBC.ASHRAE.G36.ThermalZones.ControlLoops conLoo(
    final kCooCon=kCooCon,
    final TiCooCon=TiCooCon,
    final kHeaCon=kHeaCon,
    final TiHeaCon=TiHeaCon,
    final timChe=timChe,
    final dTHys=dTHys,
    final looHys=looHys) "Heating and cooling control loop"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences.Alarms
    ala(
    final staPreMul=staPreMul,
    final VCooMax_flow=VCooMax_flow,
    final VHeaMax_flow=VHeaMax_flow,
    final lowFloTim=lowFloTim,
    final fanOffTim=fanOffTim,
    final leaFloTim=leaFloTim,
    final floHys=floHys,
    final damPosHys=damPosHys,
    final staTim=staTim)       "Generate alarms"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences.Overrides
    setOve(
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow,
    final VHeaMax_flow=VHeaMax_flow) "Override setpoints"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupCoo(
    final samplePeriod=samplePeriod,
    final chaRat=chaRat,
    final maxTim=maxSupTim,
    final dTHys=dTHys)
    "Specify suppresion time due to the zone cooling setpoint change and check if it has passed the suppresion period"
  Buildings.Controls.OBC.ASHRAE.G36.VentilationZones.ASHRAE62_1.Setpoints setPoi(
    final have_winSen=have_winSen,
    final have_occSen=have_occSen,
    final have_CO2Sen=have_CO2Sen,
    final have_typTerUni=true,
    final permit_occStandby=permit_occStandby,
    final VAreBreZon_flow=VAreBreZon_flow,
    final VPopBreZon_flow=VPopBreZon_flow,
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow,
    final zonDisEff_cool=zonDisEff_cool,
    final zonDisEff_heat=zonDisEff_heat,
    final dTHys=dTHys) if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1
    "Output the minimum outdoor airflow rate setpoint, when using ASHRAE 62.1"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences.Dampers
    damDuaSen(
    final VCooMax_flow=VCooMax_flow,
    final VHeaMax_flow=VHeaMax_flow,
    final controllerTypeDam=controllerTypeDam,
    final kDam=kDam,
    final TiDam=TiDam,
    final TdDam=TdDam,
    final dTHys=dTHys,
    final looHys=looHys,
    final iniDam=iniDam)
    "Dampers control when the unit has single dual airflow sensor"
  Buildings.Controls.OBC.ASHRAE.G36.Generic.TimeSuppression timSupHea(
    final samplePeriod=samplePeriod,
    final chaRat=chaRat,
    final maxTim=maxSupTim,
    final dTHys=dTHys)
    "Specify suppresion time due to the zone heating setpoint change and check if it has passed the suppresion period"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooMax(
    final k=VCooMax_flow)
    "Cooling maximum flow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaMax(
    final k=VHeaMax_flow)
    "Heating maximum flow"
  Buildings.Controls.OBC.CDL.Reals.Add add2
    "Sum of minimum flow and cooling maximum flow"
  Buildings.Controls.OBC.CDL.Reals.Greater gre(
    final h=floHys)
    "Check if cooling maximum is greater than the sum of minimum and heating maximum flow"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Warning: the sum of minimum flow and heating maximum flow is greater than the cooling maximum flow.")
    "Generate warning when the cooling maximum is less than the sum of heating maximum and the minimum flow"
  Buildings.Controls.OBC.ASHRAE.G36.VentilationZones.Title24.Setpoints minFlo(
    final have_winSen=have_winSen,
    final have_occSen=have_occSen,
    final have_CO2Sen=have_CO2Sen,
    final have_typTerUni=true,
    final VOccMin_flow=VOccMin_flow,
    final VAreMin_flow=VAreMin_flow,
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow)
    if venStd == Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.California_Title_24
    "Output the minimum outdoor airflow rate setpoint, when using Title 24"
equation
  connect(TZon, timSupCoo.TZon)
  connect(TZon, timSupHea.TZon)
  connect(TCooSet, timSupCoo.TSet)
  connect(THeaSet, timSupHea.TSet)
  connect(TCooSet, conLoo.TCooSet)
  connect(TZon, conLoo.TZon)
  connect(THeaSet, conLoo.THeaSet)
  connect(u1Win, setPoi.u1Win)
  connect(u1Occ, setPoi.u1Occ)
  connect(uOpeMod, setPoi.uOpeMod)
  connect(ppmCO2, setPoi.ppmCO2)
  connect(TZon, setPoi.TZon)
  connect(TDis, setPoi.TDis)
  connect(uOpeMod, actAirSet.uOpeMod)
  connect(setPoi.VOccZonMin_flow, actAirSet.VOccMin_flow)
  connect(conLoo.yCoo, damDuaSen.uCoo)
  connect(actAirSet.VActCooMax_flow, damDuaSen.VActCooMax_flow)
  connect(VColDucDis_flow, damDuaSen.VColDucDis_flow)
  connect(u1CooAHU, damDuaSen.u1CooAHU)
  connect(actAirSet.VActMin_flow, damDuaSen.VActMin_flow)
  connect(TZon, damDuaSen.TZon)
  connect(conLoo.yHea, damDuaSen.uHea)
  connect(actAirSet.VActHeaMax_flow, damDuaSen.VActHeaMax_flow)
  connect(VHotDucDis_flow, damDuaSen.VHotDucDis_flow)
  connect(u1HeaAHU, damDuaSen.u1HeaAHU)
  connect(oveFloSet, setOve.oveFloSet)
  connect(oveCooDamPos, setOve.oveCooDamPos)
  connect(oveHeaDamPos, setOve.oveHeaDamPos)
  connect(damDuaSen.yCooDam, setOve.uCooDam)
  connect(damDuaSen.yHeaDam, setOve.uHeaDam)
  connect(damDuaSen.VDis_flow_Set, setOve.VActSet_flow)
  connect(setOve.VSet_flow, VSet_flow)
  connect(setOve.yCooDam, yCooDam)
  connect(setOve.yHeaDam, yHeaDam)
  connect(sysReq.yZonCooTemResReq, yZonCooTemResReq)
  connect(sysReq.yColDucPreResReq, yColDucPreResReq)
  connect(sysReq.yZonHeaTemResReq, yZonHeaTemResReq)
  connect(sysReq.yHotDucPreResReq, yHotDucPreResReq)
  connect(sysReq.yHeaFanReq, yHeaFanReq)
  connect(ala.yColFloSenAla, yColFloSenAla)
  connect(ala.yColLeaDamAla, yColLeaDamAla)
  connect(ala.yHotFloSenAla, yHotFloSenAla)
  connect(timSupCoo.yAftSup, sysReq.uAftSupCoo)
  connect(TCooSet, sysReq.TCooSet)
  connect(TDis, sysReq.TZon)
  connect(conLoo.yCoo, sysReq.uCoo)
  connect(damDuaSen.VColDucDis_flow_Set, sysReq.VColDuc_flow_Set)
  connect(VColDucDis_flow, sysReq.VColDucDis_flow)
  connect(timSupHea.yAftSup, sysReq.uAftSupHea)
  connect(THeaSet, sysReq.THeaSet)
  connect(conLoo.yHea, sysReq.uHea)
  connect(damDuaSen.VHotDucDis_flow_Set, sysReq.VHotDuc_flow_Set)
  connect(VHotDucDis_flow, sysReq.VHotDucDis_flow)
  connect(setOve.VSet_flow, ala.VActSet_flow)
  connect(VColDucDis_flow, ala.VColDucDis_flow)
  connect(u1CooAHU, ala.u1CooFan)
  connect(VHotDucDis_flow, ala.VHotDucDis_flow)
  connect(u1HeaAHU, ala.u1HeaFan)
  connect(ala.yLowFloAla, yLowFloAla)
  connect(ala.yHotLeaDamAla, yHotLeaDamAla)
  connect(TColSup, damDuaSen.TColSup)
  connect(THotSup, damDuaSen.THotSup)
  connect(heaMax.y, add2.u1)
  connect(setPoi.VOccZonMin_flow, add2.u2)
  connect(cooMax.y, gre.u1)
  connect(add2.y, gre.u2)
  connect(gre.y, assMes.u)
  connect(ppmCO2Set, setPoi.ppmCO2Set)
  connect(u1Win, minFlo.u1Win)
  connect(u1Occ, minFlo.u1Occ)
  connect(uOpeMod, minFlo.uOpeMod)
  connect(ppmCO2Set, minFlo.ppmCO2Set)
  connect(ppmCO2, minFlo.ppmCO2)
  connect(minFlo.VOccZonMin_flow, actAirSet.VOccMin_flow)
  connect(minFlo.VOccZonMin_flow, add2.u2)
  connect(setPoi.VAdjPopBreZon_flow, VAdjPopBreZon_flow)
  connect(setPoi.VAdjAreBreZon_flow, VAdjAreBreZon_flow)
  connect(setPoi.VMinOA_flow, VMinOA_flow)
  connect(minFlo.VZonAbsMin_flow, VZonAbsMin_flow)
  connect(minFlo.VZonDesMin_flow, VZonDesMin_flow)
  connect(minFlo.yCO2, yCO2)
  connect(setOve.yCooDam, sysReq.uCooDam)
  connect(setOve.yCooDam, ala.uCooDam)
  connect(setOve.yHeaDam, sysReq.uHeaDam)
  connect(setOve.yHeaDam, ala.uHeaDam)
  connect(uOpeMod, ala.uOpeMod)
end Controller;


within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits;
package DualDuctColdDuctMin "Sequences for dual duct terminal unit with cold duct minimum control"
end DualDuctColdDuctMin;


Output the active airflow setpoint for dual-duct terminal unit with cold-duct minimum control. This sequence sets the active cooling and heating maximum and the active minimum setpoints
for dual-duct terminal unit with cold-duct minimum control.
The implementation is according to the Section 5.14.4 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.DualDuctColdDuctMin.Subsequences;
block ActiveAirFlow
  "Output the active airflow setpoint for dual-duct terminal unit with cold-duct minimum control"

  parameter Real VCooMax_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone cooling maximum airflow rate";
  parameter Real VHeaMax_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone heating maximum airflow rate";
  parameter Real floHys(unit="m3/s")
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOccMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Occupied minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActHeaMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active heating maximum airflow setpoint"

protected
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant cooDowMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.coolDown)
    "Cool down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant setUpMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.setUp)
    "Setup mode"
  Buildings.Controls.OBC.CDL.Logical.Or or3
    "Check if it is in occupied, cooldown, or setup mode"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal actCooMax(
    final realTrue=VCooMax_flow)
    "Active cooling maximum flow"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal occModInd(
    final realTrue=1)
    "If in occupied mode, output 1"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro
    "Active cooling minimum, minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal heaMaxFlo(
    final realTrue=VHeaMax_flow)
    "Heating maximum flow when input is true"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant setBacMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.setBack)
    "Setback mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant warUpMod(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.warmUp)
    "Warm up mode"
  Buildings.Controls.OBC.CDL.Integers.Equal ifOcc
    "Check if current operation mode is occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal ifCooDow
    "Check if current operation mode is cooldown mode"
  Buildings.Controls.OBC.CDL.Integers.Equal ifSetUp
    "Check if current operation mode is setup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal ifWarUp
    "Check if current operation mode is warm-up mode"
  Buildings.Controls.OBC.CDL.Integers.Equal ifSetBac
    "Check if current operation mode is setback mode"
  Buildings.Controls.OBC.CDL.Logical.Or or1
    "Check if it is in occupied, warm-up, or setback mode"
  Buildings.Controls.OBC.CDL.Reals.Add add2
    "Sum of minimum flow and cooling maximum flow"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes(
    final message="Warning: the sum of minimum flow and heating maximum flow is greater than the cooling maximum flow.")
    "Generate warning when the cooling maximum is less than the sum of heating maximum and the minimum flow"
  Buildings.Controls.OBC.CDL.Reals.Greater gre(
    final h=floHys)
    "Check if cooling maximum is greater than the sum of minimum and heating maximum flow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaMax(
    final k=VHeaMax_flow)
    "Heating maximum flow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooMax(
    final k=VCooMax_flow)
    "Cooling maximum flow"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Check if it is in occupied, cooldown, or setup mode"
  Buildings.Controls.OBC.CDL.Logical.Or or4
    "Check if it is in occupied, warm-up, or setback mode"

equation
  connect(occMod.y, ifOcc.u1)
  connect(cooDowMod.y, ifCooDow.u1)
  connect(setUpMod.y, ifSetUp.u1)
  connect(warUpMod.y, ifWarUp.u1)
  connect(uOpeMod, ifOcc.u2)
  connect(uOpeMod, ifCooDow.u2)
  connect(uOpeMod, ifSetUp.u2)
  connect(uOpeMod, ifWarUp.u2)
  connect(uOpeMod, ifSetBac.u2)
  connect(setBacMod.y, ifSetBac.u1)
  connect(ifOcc.y, or3.u1)
  connect(ifCooDow.y, or3.u2)
  connect(ifOcc.y, occModInd.u)
  connect(VOccMin_flow, pro.u2)
  connect(occModInd.y, pro.u1)
  connect(actCooMax.y, VActCooMax_flow)
  connect(pro.y, VActMin_flow)
  connect(ifOcc.y, or1.u1)
  connect(ifWarUp.y, or1.u2)
  connect(heaMaxFlo.y, VActHeaMax_flow)
  connect(heaMax.y, add2.u2)
  connect(cooMax.y, gre.u1)
  connect(add2.y, gre.u2)
  connect(gre.y, assMes.u)
  connect(VOccMin_flow, add2.u1)
  connect(or3.y, or2.u1)
  connect(or2.y, actCooMax.u)
  connect(ifSetUp.y, or2.u2)
  connect(or4.y, heaMaxFlo.u)
  connect(or1.y, or4.u1)
  connect(ifSetBac.y, or4.u2)
end ActiveAirFlow;