Validation of model that controls series-fan powered unit with constant volume fan. This example validates

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

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanCVF.Validation;
model Controller
  "Validation of model that controls series-fan powered unit with constant volume fan"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanCVF.Controller serFanCon(
    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 controllerTypeVal=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    final staPreMul=1,
    final hotWatRes=1,
    final floHys=0.01,
    final looHys=0.01,
    final damPosHys=0.01,
    final valPosHys=0.01,
    final VOccMin_flow=0,
    final VAreMin_flow=0)
    "Series-fan powered 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.Sin parFanFlo(
    final offset=1.2,
    final amplitude=0.6,
    final freqHz=1/28800) "Parallel fan flow"
  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.Reals.Sources.Ramp oveTerFan(
    final height=2,
    final duration=5000,
    final startTime=60000) "Override terminal fan control"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt4
    "Convert real to integer"
  Buildings.Controls.OBC.CDL.Reals.Round round4(
    final n=0)
    "Round real number to given digits"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TSup(
    final offset=273.15 + 13,
    final amplitude=1,
    final freqHz=1/28800) "Supply air temperature from air handling unit"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse heaOff(
    final width=0.75,
    final period=3600)
    "Close heating valve"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant terFan(
    final k=true)
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse hotPla(
    final width=0.9,
    final period=7500)
    "Hot water plant status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse supFan(
    final width=0.75,
    final period=7500)
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSupSet(
    final k=273.15 + 13)
    "AHU supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin disFlo(
    final offset=1.3,
    final amplitude=0.6,
    final freqHz=1/28800) "Discharge airflow rate"
  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,serFanCon. TZon)
  connect(cooSet.y,serFanCon. TCooSet)
  connect(heaSet.y,serFanCon. THeaSet)
  connect(occ.y, serFanCon.u1Occ)
  connect(opeMod.y,round2. u)
  connect(round2.y,reaToInt2. u)
  connect(reaToInt2.y,serFanCon. uOpeMod)
  connect(CO2.y,serFanCon. ppmCO2)
  connect(oveFlo.y,round1. u)
  connect(round1.y,reaToInt1. u)
  connect(oveDam.y, round3.u)
  connect(round3.y,reaToInt3. u)
  connect(reaToInt1.y,serFanCon. oveFloSet)
  connect(oveTerFan.y, round4.u)
  connect(round4.y,reaToInt4. u)
  connect(disAirTem.y,serFanCon. TDis)
  connect(reaToInt3.y,serFanCon. oveDamPos)
  connect(reaToInt4.y,serFanCon. oveFan)
  connect(heaOff.y, not1.u)
  connect(not1.y,serFanCon. uHeaOff)
  connect(supFan.y, serFanCon.u1Fan)
  connect(terFan.y, serFanCon.u1TerFan)
  connect(hotPla.y, serFanCon.u1HotPla)
  connect(TSupSet.y,serFanCon. TSupSet)
  connect(TSup.y,serFanCon. TSup)
  connect(disFlo.y,serFanCon.VPri_flow)
  connect(CO2Set.y, serFanCon.ppmCO2Set)
  connect(winSta.y, not2.u)
  connect(not2.y, serFanCon.u1Win)
end Controller;


Collection of validation models

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


Controller for variable-volume series fan-powered terminal unit. Controller for variable-volume series fan-powered terminal unit according to Section 5.8 of ASHRAE
Guideline 36, May 2020. It outputs discharge airflow setpoint VSet_flow_Set,
damper position setpoint yDam, hot water valve position setpoint
yVal, terminal fan command on status y1Fan and
the airflow setpoint VFan_flow_Set, AHU cooling supply temperature
setpoint reset request yZonTemResReq, and static pressure setpoint
reset request yZonPreResReq, hot water reset request yHeaValResReq
and yHotWatPlaReq. It also outputs the alarms about the low airflow
yLowFloAla, low discharge temperature yLowTemAla,
leaking damper yLeaDamAla and valve yLeaValAla,
airflow sensor calibration alarm yFloSenAla and the terminal fan status alarm
yFanStaAla.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF;
block Controller
  "Controller for variable-volume series fan-powered terminal unit"

  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 Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Heating coil type"
  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 and valve control parameters ----------------
  parameter Real dTDisZonSetMax(unit="K")=11
    "Zone maximum discharge air temperature above heating setpoint"
  parameter Real maxRat(unit="m3/s")
    "Maximum heating-fan airflow setpoint"
  parameter CDL.Types.SimpleController controllerTypeVal=Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real kVal=0.5
    "Gain of controller for valve control"
  parameter Real TiVal(unit="s")=300
    "Time constant of integrator block for valve control"
  parameter Real TdVal(unit="s")=0.1
    "Time constant of derivative block for valve control"
  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 thrTDis_1(unit="K")=17
    "Threshold difference between discharge air temperature and its setpoint for generating 3 hot water reset requests"
  parameter Real thrTDis_2(unit="K")=8.3
    "Threshold difference between discharge air temperature and its setpoint for generating 2 hot water 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"
  parameter Real durTimDisAir(unit="s")=300
    "Duration time of discharge air temperature less than setpoint"
  // ---------------- Parameters for alarms ----------------
  parameter Real staPreMul=1
    "Importance multiplier for the zone static pressure reset control loop"
  parameter Real hotWatRes=1
    "Importance multiplier for the hot water reset control loop"
  parameter Real lowFloTim(unit="s")=300
    "Threshold time to check low flow rate"
  parameter Real lowTemTim(unit="s")=600
    "Threshold time to check low discharge temperature"
  parameter Real comChaTim(unit="s")=15
    "Threshold time after fan command change"
  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"
  parameter Real valCloTim(unit="s")=900
    "Threshold time to check valve leaking water flow"
  // ---------------- 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 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 valPosHys(unit="1")=0.005
    "Near zero valve position, below which the valve 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")
    "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 supply air temperature after heating coil"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VPri_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Measured primary airflow rate"
  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 TSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Supply air temperature setpoint from central air handler"
  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.IntegerInput oveFan
    "Index of overriding terminal fan status, 1: turn fan off; 2: turn fan on"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uHeaOff
    "Override heating valve position, true: close heating valve"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Fan
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1TerFan
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1HotPla if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Hot water plant 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 yVal(
    final min=0,
    final unit="1") "Heating valve commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VFan_flow_Set(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Terminal fan flow rate setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1Fan
    "Terminal fan command on"
  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 yHeaValResReq
    "Hot water reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotWatPlaReq
    "Request to heating hot-water plant"
  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 yFanStaAla
    "Terminal fan status alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaDamAla
    "Leaking damper alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaValAla
    "Leaking valve alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLowTemAla
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Low discharge air temperature alarms"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.ActiveAirFlow
    actAirSet(final VCooMax_flow=VCooMax_flow) "Active airflow setpoint"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.SystemRequests
    sysReq(
    final heaCoi=heaCoi,
    final thrTemDif=thrTemDif,
    final twoTemDif=twoTemDif,
    final thrTDis_1=thrTDis_1,
    final thrTDis_2=thrTDis_2,
    final durTimTem=durTimTem,
    final durTimFlo=durTimFlo,
    final durTimDisAir=durTimDisAir,
    final dTHys=dTHys,
    final floHys=floHys,
    final looHys=looHys,
    final damPosHys=damPosHys,
    final valPosHys=valPosHys,
    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.SeriesFanVVF.Subsequences.Alarms
    ala(
    final heaCoi=heaCoi,
    final staPreMul=staPreMul,
    final hotWatRes=hotWatRes,
    final VCooMax_flow=VCooMax_flow,
    final lowFloTim=lowFloTim,
    final lowTemTim=lowTemTim,
    final comChaTim=comChaTim,
    final fanOffTim=fanOffTim,
    final leaFloTim=leaFloTim,
    final valCloTim=valCloTim,
    final floHys=floHys,
    final dTHys=dTHys,
    final damPosHys=damPosHys,
    final valPosHys=valPosHys,
    final staTim=staTim)       "Generate alarms"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Overrides
    setOve "Override setpoints"
  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 have_parFanPowUni=false,
    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.SeriesFanVVF.Subsequences.DamperValves
    damVal(
    final dTDisZonSetMax=dTDisZonSetMax,
    final maxRat=maxRat,
    final VMin_flow=VMin_flow,
    final VCooMax_flow=VCooMax_flow,
    final controllerTypeVal=controllerTypeVal,
    final kVal=kVal,
    final TiVal=TiVal,
    final TdVal=TdVal,
    final controllerTypeDam=controllerTypeDam,
    final kDam=kDam,
    final TiDam=TiDam,
    final TdDam=TdDam,
    final dTHys=dTHys,
    final looHys=looHys,
    final floHys=floHys,
    final damPosHys=damPosHys,
    final iniDam=iniDam) "Damper and valve control"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea1
    "Convert boolean to real"
  Buildings.Controls.OBC.CDL.Reals.Multiply mul1
    "Paralle fan airflow setpoint"
  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, 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(VPri_flow, damVal.VPri_flow)
  connect(conLoo.yCoo, damVal.uCoo)
  connect(actAirSet.VActCooMax_flow, damVal.VActCooMax_flow)
  connect(TSup, damVal.TSup)
  connect(actAirSet.VActMin_flow, damVal.VActMin_flow)
  connect(TDis, damVal.TDis)
  connect(TSupSet, damVal.TSupSet)
  connect(THeaSet, damVal.THeaSet)
  connect(conLoo.yHea, damVal.uHea)
  connect(TZon, damVal.TZon)
  connect(uOpeMod, damVal.uOpeMod)
  connect(oveDamPos, setOve.oveDamPos)
  connect(damVal.yDam, setOve.uDam)
  connect(uHeaOff, setOve.uHeaOff)
  connect(damVal.yVal, setOve.uVal)
  connect(timSup.yAftSup, sysReq.uAftSup)
  connect(TCooSet, sysReq.TCooSet)
  connect(TZon, sysReq.TZon)
  connect(conLoo.yCoo, sysReq.uCoo)
  connect(VPri_flow,sysReq.VPri_flow)
  connect(TDis, sysReq.TDis)
  connect(VPri_flow,ala.VPri_flow)
  connect(u1Fan, ala.u1Fan)
  connect(TSup, ala.TSup)
  connect(u1HotPla, ala.u1HotPla)
  connect(TDis, ala.TDis)
  connect(setOve.yDam, yDam)
  connect(setOve.yVal, yVal)
  connect(sysReq.yZonTemResReq, yZonTemResReq)
  connect(sysReq.yZonPreResReq, yZonPreResReq)
  connect(sysReq.yHeaValResReq, yHeaValResReq)
  connect(sysReq.yHotWatPlaReq, yHotWatPlaReq)
  connect(ala.yLowFloAla, yLowFloAla)
  connect(ala.yFloSenAla, yFloSenAla)
  connect(ala.yLeaDamAla, yLeaDamAla)
  connect(ala.yLeaValAla, yLeaValAla)
  connect(ala.yLowTemAla, yLowTemAla)
  connect(setPoi.VMinOA_flow, damVal.VOAMin_flow)
  connect(damVal.THeaDisSet, sysReq.TDisSet)
  connect(setOve.oveFan, oveFan)
  connect(setOve.y1Fan, y1Fan)
  connect(ala.yFanStaAla, yFanStaAla)
  connect(damVal.y1Fan, setOve.u1Fan)
  connect(damVal.y1Fan, ala.u1FanCom)
  connect(damVal.THeaDisSet, ala.TDisSet)
  connect(damVal.VFan_flow_Set, mul1.u1)
  connect(setOve.y1Fan, booToRea1.u)
  connect(booToRea1.y, mul1.u2)
  connect(mul1.y, VFan_flow_Set)
  connect(u1TerFan, ala.u1TerFan)
  connect(ppmCO2Set, setPoi.ppmCO2Set)
  connect(minFlo.VOccZonMin_flow, actAirSet.VOccMin_flow)
  connect(minFlo.VZonAbsMin_flow, damVal.VOAMin_flow)
  connect(u1Win, minFlo.u1Win)
  connect(u1Occ, minFlo.u1Occ)
  connect(uOpeMod, minFlo.uOpeMod)
  connect(ppmCO2Set, minFlo.ppmCO2Set)
  connect(ppmCO2, minFlo.ppmCO2)
  connect(damVal.VPri_flow_Set, VSet_flow)
  connect(damVal.VPri_flow_Set, sysReq.VSet_flow)
  connect(damVal.VPri_flow_Set, ala.VActSet_flow)
  connect(oveFloSet, damVal.oveFloSet)
  connect(setPoi.VAdjPopBreZon_flow, VAdjPopBreZon_flow)
  connect(setPoi.VAdjAreBreZon_flow, VAdjAreBreZon_flow)
  connect(setPoi.VMinOA_flow, VMinOA_flow)
  connect(minFlo.VZonDesMin_flow, VZonDesMin_flow)
  connect(minFlo.VZonAbsMin_flow, VZonAbsMin_flow)
  connect(minFlo.yCO2, yCO2)
  connect(setOve.yDam, damVal.uDam)
  connect(setOve.yDam, sysReq.uDam)
  connect(setOve.yDam, ala.uDam)
  connect(setOve.yVal, sysReq.uVal)
  connect(setOve.yVal, ala.uVal)
  connect(u1Fan, damVal.u1Fan)
  connect(u1TerFan, damVal.u1TerFan)
  connect(uOpeMod, ala.uOpeMod)
end Controller;


within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits;
package SeriesFanVVF "Sequences for series fan-powered terminal unit with variable-volume fan"
end SeriesFanVVF;


Output the active airflow setpoint for variable-volume series fan-powered terminal unit. This sequence sets the active cooling maximum and minimum setpoints
for series fan-powered terminal unit with variable volume fan. The implementation
is according to the Section 5.10.4 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences;
block ActiveAirFlow
  "Output the active airflow setpoint for variable-volume series fan-powered 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"

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.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.Logical.Or or2
    "Check if it is in occupied, cooldown, or setup mode"

equation
  connect(occMod.y, ifOcc.u1)
  connect(cooDowMod.y, ifCooDow.u1)
  connect(setUpMod.y, ifSetUp.u1)
  connect(uOpeMod, ifOcc.u2)
  connect(uOpeMod, ifCooDow.u2)
  connect(uOpeMod, ifSetUp.u2)
  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(or3.y, or2.u1)
  connect(or2.y, actCooMax.u)
  connect(ifSetUp.y, or2.u2)
end ActiveAirFlow;


Generate alarms of series fan-powered terminal unit with variable-volume fan. This block outputs alarms of series fan-powered terminal unit with variable volume fan.
The implementation is according to the Section 5.10.6 of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences;
block Alarms "Generate alarms of series fan-powered terminal unit with variable-volume fan"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Heating coil type"
  parameter Real staPreMul
    "Importance multiplier for the zone static pressure reset control loop";
  parameter Real hotWatRes
    "Importance multiplier for the hot water 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 lowTemTim(
    final unit="s",
    final quantity="Time")=600
    "Threshold time to check low discharge temperature"
  parameter Real comChaTim(
    final unit="s",
    final quantity="Time")=15
    "Threshold time after fan command change"
  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 damper leaking airflow"
  parameter Real valCloTim(
    final unit="s",
    final quantity="Time")=900
    "Threshold time to check valve leaking water flow"
  parameter Real floHys(
    final quantity="VolumeFlowRate",
    final unit="m3/s")=0.05
    "Near zero flow rate, below which the flow rate or difference will be seen as zero"
  parameter Real dTHys(
    final unit="K",
    final quantity="TemperatureDifference")=0.25
    "Temperature difference hysteresis below which the temperature difference will be seen as zero"
  parameter Real damPosHys(
    final unit="1")=0.05
    "Near zero damper position, below which the damper will be seen as closed"
  parameter Real valPosHys(
    final unit="1")=0.05
    "Near zero valve position, below which the valve 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 VPri_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Measured primary 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
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1FanCom
    "Terminal fan command on"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1TerFan
    "Terminal 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.RealInput uVal(
    final min=0,
    final unit="1")
    "Actual valve position"
  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.BooleanInput u1HotPla if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Hot water plant status"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDisSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge air temperature 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 yFanStaAla
    "Fan status alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaDamAla
    "Leaking damper alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLeaValAla
    "Leaking valve alarm"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yLowTemAla
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Low discharge air temperature alarms"

  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 and4
    "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 and14
    "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 AHU 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 leaDamAla
    "Check if generating leak damper alarms"
  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.Reals.Less les1(
    final h=dTHys) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature lower than setpoint by a threshold"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=-17) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Setpoint temperature minus a threshold"
  Buildings.Controls.OBC.CDL.Reals.Less les2(
    final h=dTHys) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature lower than setpoint by a threshold"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(final p=-8.3)
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Setpoint temperature minus a threshold"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel4(
    final delayTime=lowTemTim) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the discharge temperature has been less than threshold value for threshold time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel5(
    final delayTime=lowTemTim) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the discharge temperature has been less than threshold value for threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and6 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature has been less than threshold and the hot water plant is proven on"
  Buildings.Controls.OBC.CDL.Logical.And and7 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not6 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes4(
    final message="Warning: discharge air temperature is 17 degC less than the setpoint.")
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Level 2 low discharge air temperature alarm"
  Buildings.Controls.OBC.CDL.Integers.Switch lowTemAla if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Low discharge temperature alarm"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=2) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Level 2 alarm"
  Buildings.Controls.OBC.CDL.Logical.And and8 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature has been less than threshold and the hot water plant is proven on"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt4(
    final integerTrue=3) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Convert boolean true to level 3 alarm"
  Buildings.Controls.OBC.CDL.Logical.And and9 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not7 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes5(
    final message="Warning: discharge air temperature is 8 degC less than the setpoint.")
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Level 3 low airflow alarm"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conInt3(
    final k=hotWatRes) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Importance multiplier for hot water reset control"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if the multiplier is greater than zero"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt5
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Suppress the alarm when multiplier is zero"
  Buildings.Controls.OBC.CDL.Integers.Multiply proInt1 if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Low discharge air temperature alarms"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel6(
    final delayTime=valCloTim)
    "Check if the input has been true for more than threshold time"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold cloVal(
    final t=valPosHys,
    final h=0.5*valPosHys)
    "Check if valve position is near zero"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar2(
    final p=3)
    "AHU supply temperature plus 3 degree"
  Buildings.Controls.OBC.CDL.Reals.Greater gre2(
    final h=dTHys)
    "Discharge temperature greate than AHU supply temperature by a threshold"
  Buildings.Controls.OBC.CDL.Logical.And leaValAla
    "Check if generating leak valve alarms"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt6(
    final integerTrue=4)
    "Convert boolean true to level 4 alarm"
  Buildings.Controls.OBC.CDL.Logical.Not not8 "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes6(
    final message="Warning: the valve is leaking.")
    "Level 4 leaking valve alarm"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel7(
    final delayTime=comChaTim)
    "Check if the terminal fan has been commond on for threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and11
    "Check if the fan has been commond on for threshold time and fan is still off"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    final k=2)
    "Level 2 alarm"
  Buildings.Controls.OBC.CDL.Integers.Switch fanStaAla
    "Fan status alarm"
  Buildings.Controls.OBC.CDL.Logical.Not not9
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel8(
    final delayTime=comChaTim)
    "Check if the terminal fan has been commond off for threshold time"
  Buildings.Controls.OBC.CDL.Logical.And and10
    "Check if the fan has been commond off for threshold time and fan is still on"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt7(
    final integerTrue=4)
    "Convert boolean true to level 3 alarm"
  Buildings.Controls.OBC.CDL.Logical.Not not10
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes7(
    final message="Warning: fan has been commanded ON but still OFF.")
    "Level 2 fan status alarm"
  Buildings.Controls.OBC.CDL.Logical.Not not11
    "Logical not"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMes8(
    final message="Warning: fan has been commanded OFF but still ON.")
    "Level 4 fan status alarm"
  Buildings.Controls.OBC.CDL.Logical.Not not12
    "Logical not"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel9(
    final delayTime=lowFloTim)
    "Check if the active flow setpoint has been greater than zero for the threshold time"
  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.Logical.And and12
    "True: AHU fan is enabled and the discharge flow is lower than the threshold"
  Buildings.Controls.OBC.CDL.Logical.And and13
    "True: AHU fan is enabled and the discharge flow is lower than the threshold"
  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 and3
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and15
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and16
    "Check if the fan has been commond on for threshold time and fan is still off"
  Buildings.Controls.OBC.CDL.Logical.And and17
    "Check if the fan has been commond off for threshold time and fan is still on"
  Buildings.Controls.OBC.CDL.Logical.And leaDamAla1
    "Check if generating leak damper alarms"
  Buildings.Controls.OBC.CDL.Logical.And leaValAla1
    "Check if generating leak valve alarms"
  Buildings.Controls.OBC.CDL.Logical.And and18
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical and"
  Buildings.Controls.OBC.CDL.Logical.And and19
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Logical and"
equation
  connect(VActSet_flow, gai.u)
  connect(VPri_flow, les.u1)
  connect(VActSet_flow, greThr.u)
  connect(VActSet_flow, gai1.u)
  connect(VPri_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,and4. u1)
  connect(greThr1.y,and4. u2)
  connect(and1.y, and14.u1)
  connect(greThr1.y, and14.u2)
  connect(not2.y, assMes1.u)
  connect(cooMaxFlo.y, gai2.u)
  connect(u1Fan, not3.u)
  connect(gai2.y, gre1.u2)
  connect(gre1.y, and5.u1)
  connect(not4.y, assMes2.u)
  connect(booToInt2.y, yFloSenAla)
  connect(proInt.y, yLowFloAla)
  connect(uDam, cloDam.u)
  connect(u1Fan, leaDamAla.u2)
  connect(not5.y, assMes3.u)
  connect(booToInt3.y, yLeaDamAla)
  connect(VPri_flow, gre1.u1)
  connect(TDis, les1.u1)
  connect(TDisSet, addPar.u)
  connect(addPar.y, les1.u2)
  connect(TDis, les2.u1)
  connect(TDisSet, addPar1.u)
  connect(addPar1.y, les2.u2)
  connect(conInt2.y, lowTemAla.u1)
  connect(not6.y, assMes4.u)
  connect(booToInt4.y, lowTemAla.u3)
  connect(not7.y, assMes5.u)
  connect(conInt3.y, greThr2.u)
  connect(greThr2.y, booToInt5.u)
  connect(lowTemAla.y, proInt1.u1)
  connect(booToInt5.y, proInt1.u2)
  connect(greThr2.y, and7.u2)
  connect(greThr2.y, and9.u2)
  connect(proInt1.y, yLowTemAla)
  connect(uVal, cloVal.u)
  connect(TSup, addPar2.u)
  connect(TDis, gre2.u1)
  connect(addPar2.y, gre2.u2)
  connect(u1Fan, leaValAla.u2)
  connect(not8.y, assMes6.u)
  connect(booToInt6.y, yLeaValAla)
  connect(u1FanCom, truDel7.u)
  connect(u1FanCom, not9.u)
  connect(not9.y, truDel8.u)
  connect(u1FanCom, and11.u2)
  connect(not9.y, and10.u2)
  connect(conInt4.y, fanStaAla.u1)
  connect(booToInt7.y, fanStaAla.u3)
  connect(fanStaAla.y, yFanStaAla)
  connect(not10.y, assMes7.u)
  connect(not11.y, assMes8.u)
  connect(u1TerFan, and10.u1)
  connect(u1TerFan, not12.u)
  connect(not12.y, and11.u1)
  connect(greThr.y, truDel9.u)
  connect(truDel9.y, and1.u1)
  connect(truDel9.y, and2.u2)
  connect(and5.y, truDel2.u)
  connect(truDel2.y, booToInt2.u)
  connect(truDel2.y, not4.u)
  connect(not3.y, and5.u2)
  connect(truDel3.y, booToInt3.u)
  connect(truDel3.y, not5.u)
  connect(gre1.y, leaDamAla.u1)
  connect(cloVal.y, leaValAla.u1)
  connect(truDel6.y, booToInt6.u)
  connect(truDel6.y, not8.u)
  connect(and6.y, truDel4.u)
  connect(les1.y, and6.u1)
  connect(truDel4.y, and7.u1)
  connect(and8.y, truDel5.u)
  connect(les2.y, and8.u1)
  connect(truDel5.y, and9.u1)
  connect(u1HotPla, and6.u2)
  connect(u1HotPla, and8.u2)
  connect(les.y, and13.u1)
  connect(and13.y, truDel.u)
  connect(gre.y, and12.u1)
  connect(and12.y, truDel1.u)
  connect(u1Fan, fanIni.u)
  connect(fanIni.y, and13.u2)
  connect(fanIni.y, and12.u2)
  connect(occMod.y,isOcc. u2)
  connect(uOpeMod,isOcc. u1)
  connect(gai.y, les.u2)
  connect(and4.y, and15.u1)
  connect(and15.y, lowFloAla.u2)
  connect(and15.y, not1.u)
  connect(booToInt.u, and3.y)
  connect(and3.y, not2.u)
  connect(and14.y, and3.u1)
  connect(isOcc.y, and15.u2)
  connect(isOcc.y, and3.u2)
  connect(and11.y, and16.u1)
  connect(and16.y, fanStaAla.u2)
  connect(and16.y, not10.u)
  connect(and17.y, booToInt7.u)
  connect(and17.y, not11.u)
  connect(and10.y, and17.u1)
  connect(truDel7.y, and16.u2)
  connect(truDel8.y, and17.u2)
  connect(leaDamAla.y, leaDamAla1.u1)
  connect(leaDamAla1.y, truDel3.u)
  connect(cloDam.y, leaDamAla1.u2)
  connect(leaValAla.y, leaValAla1.u1)
  connect(leaValAla1.y, truDel6.u)
  connect(gre2.y, leaValAla1.u2)
  connect(and7.y, and19.u1)
  connect(and19.y, lowTemAla.u2)
  connect(and9.y, and18.u1)
  connect(and18.y, booToInt4.u)
  connect(and19.y, not6.u)
  connect(and18.y, not7.u)
  connect(isOcc.y, and19.u2)
  connect(isOcc.y, and18.u2)
end Alarms;


Output signals for controlling variable-volume series fan-powered terminal unit. This sequence sets the series fan flow rate setpoint, damper and valve position for
variable-volume series fan-powered terminal unit.
The implementation is according to Section 5.10.5 of ASHRAE Guideline 36, May 2020. The
calculation is done following the steps below.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences;
block DamperValves
  "Output signals for controlling variable-volume series fan-powered terminal unit"

  parameter Real dTDisZonSetMax(
    final unit="K",
    final quantity="TemperatureDifference")=11
    "Zone maximum discharge air temperature above heating setpoint"
  parameter Real maxRat(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Maximum heating-fan airflow setpoint";
  parameter Real VMin_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone minimum airflow setpoint";
  parameter Real VCooMax_flow(
    final quantity="VolumeFlowRate",
    final unit="m3/s")
    "Design zone cooling maximum airflow rate";
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeVal=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real kVal(final unit="1/K")=0.5
    "Gain of controller for valve control"
  parameter Real TiVal(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for valve control"
  parameter Real TdVal(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for valve control"
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerTypeDam=
    Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real kDam(final unit="1")=0.5
    "Gain of controller for damper control"
  parameter Real TiDam(
    final unit="s",
    final quantity="Time")=300
    "Time constant of integrator block for damper control"
  parameter Real TdDam(
    final unit="s",
    final quantity="Time")=0.1
    "Time constant of derivative block for damper control"
  parameter Real dTHys(
    final unit="K",
    final quantity="TemperatureDifference")=0.25
    "Temperature difference hysteresis below which the temperature difference will be seen as zero"
  parameter Real looHys(
    final unit="1") = 0.05
    "Loop output hysteresis below which the output will be seen as zero"
  parameter Real floHys(
    final unit="m3/s") = 0.01
    "Hysteresis for checking airflow rate"
  parameter Real damPosHys(
    final unit="m3/s") = 0.05
    "Hysteresis for checking damper position"
  parameter Real iniDam(unit="1")=0.01
    "Initial damper position when the damper control is enabled"

  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.RealInput VPri_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Measured primary discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uCoo(
    final min=0,
    final max=1,
    final unit="1")
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Active cooling maximum airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput 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 TZon(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured zone temperature"
  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.BooleanInput u1Fan
    "AHU supply fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSupSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Supply air temperature setpoint from central air handler"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THeaSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uHea(
    final min=0,
    final max=1,
    final unit="1")
    "Heating control signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VOAMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1TerFan
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uDam(
    final min=0,
    final unit="1")
    "Damper position setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VPri_flow_Set(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Discharge airflow setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final max=1,
    final unit="1") "VAV damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput THeaDisSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Discharge airflow setpoint temperature for heating"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yVal(
    final min=0,
    final max=1,
    final unit="1") "Hot water valve commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VFan_flow_Set(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Series fan flow rate setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1Fan
    "Terminal fan command on status"

protected
  Buildings.Controls.OBC.CDL.Logical.And and4 "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Line lin
    "Active airflow setpoint for cooling"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Output active cooling airflow according to cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Switch swi5
    "Airflow setpoint when it is in cooling state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer(
    final k=0) "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conOne(
    final k=1) "Constant one"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1(
    final t=looHys,
    final h=0.5*looHys)
    "Check if it is cooling state"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=dTHys,
    final h=0.5*dTHys)
    "Check if supply air temperature is greater than room temperature"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    "Calculate temperature difference between AHU supply air and room "
  Buildings.Controls.OBC.CDL.Reals.Switch swi2 "Hot water valve position"
  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 VPri_flowNor
    "Normalized discharge volume flow rate"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conDam(
    final controllerType=controllerTypeDam,
    final k=kDam,
    final Ti=TiDam,
    final Td=TdDam,
    final yMax=1,
    final yMin=0,
    final y_reset=iniDam)
    "Damper position controller"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3 "Air damper position"
  Buildings.Controls.OBC.CDL.Reals.Line conTDisHeaSet
    "Discharge air temperature for heating"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=dTDisZonSetMax)
    "Maximum heating discharge temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conHal(
    final k=0.5)
    "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr2(
    final t=looHys,
    final h=0.5*looHys)
    "Check if it is heating state"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset conVal(
    final controllerType=controllerTypeVal,
    final k=kVal,
    final Ti=TiVal,
    final Td=TdVal,
    final yMax=1,
    final yMin=0,
    u_s(final unit="K", displayUnit="degC"),
    u_m(final unit="K", displayUnit="degC"))
    "Hot water valve controller"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer3(final k=0)
    "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Hot water valve position, close the valve when the zone is not in heating state"
  Buildings.Controls.OBC.CDL.Reals.Line heaFanRat
    "Parallel fan airflow setpoint when zone is in heating state"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conHal1(
    final k=0.5)
    "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conHal2(
    final k=1)
    "Constant real value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxFan(
    final k=maxRat) "Maximum fan rate"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant uno(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.unoccupied)
    "Constant signal for unoccupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal isUno
    "Output true if the operation mode is unoccupied"
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    "Fan setpoint when it is in cooling state and the supply air temperture is high"
  Buildings.Controls.OBC.CDL.Reals.Max max1
    "Larger of minimum outdoor airflow setpoint and primary discharge airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi6
    "Fan setpoint when it is in cooling state"
  Buildings.Controls.OBC.CDL.Logical.Or cooHea
    "Cooling or heating state"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "In deadband state"
  Buildings.Controls.OBC.CDL.Reals.Switch swi7
    "Fan setpoint when it is in deadband state"
  Buildings.Controls.OBC.CDL.Reals.Switch swi8
    "Fan setpoint when it is in heating state"
  Buildings.Controls.OBC.CDL.Reals.LessThreshold cloDam(
    final t=damPosHys,
    final h=damPosHys/2)
    "Check if the damper is fully closed before turning on fan"
  Buildings.Controls.OBC.CDL.Logical.Timer tim(final t=15)
    "Check if the fan has been proven on for a fixed time"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occ(
    final k=Buildings.Controls.OBC.ASHRAE.G36.Types.OperationModes.occupied)
    "Constant signal for occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal isOcc
    "Output true if the operation mode is occupied"
  Buildings.Controls.OBC.CDL.Logical.Or or3
    "Check if it is in heating, cooling state, or it is in occupied mode"
  Buildings.Controls.OBC.CDL.Logical.Edge edg
    "Rising edge"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Check if the fan can turn on"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg
    "Falling edge"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1
    "Hold fan on status"
  Buildings.Controls.OBC.CDL.Logical.Latch lat "Close damper"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    final realTrue=0,
    final realFalse=1)
    "Boolean to real"
  Buildings.Controls.OBC.CDL.Reals.Multiply mul
    "Ensure damper is fully closed before turning on the fan"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea1
    "Boolean to real"
  Buildings.Controls.OBC.CDL.Reals.Multiply mul1
    "Ensure damper is fully closed before turning on the fan"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(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 conInt1(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.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.Logical.Or or1
    "Check if the airflow setpoint should be overrided"
  Buildings.Controls.OBC.CDL.Reals.Switch swi9
    "Airflow setpoint after considering override"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(final k=3)
    "Constant 3"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Check if the airflow setpoint should be overrided"
  Buildings.Controls.OBC.CDL.Logical.Or or4
    "Check if it is in heating, cooling state, or it is in occupied mode"

equation
  connect(uCoo, lin.u)
  connect(conZer.y, lin.x1)
  connect(conOne.y, lin.x2)
  connect(VActCooMax_flow, lin.f2)
  connect(uCoo, greThr1.u)
  connect(and4.y, swi5.u2)
  connect(lin.y, swi5.u3)
  connect(swi5.y, swi.u1)
  connect(TSup, sub2.u1)
  connect(sub2.y, greThr.u)
  connect(greThr.y, and4.u2)
  connect(greThr1.y, and4.u1)
  connect(greThr1.y, swi.u2)
  connect(VActMin_flow, swi5.u1)
  connect(VActMin_flow, lin.f1)
  connect(VActMin_flow, swi.u3)
  connect(TZon, sub2.u2)
  connect(swi2.y, yVal)
  connect(nomFlow.y, VDisSet_flowNor.u2)
  connect(VDisSet_flowNor.y, conDam.u_s)
  connect(VPri_flow, VPri_flowNor.u1)
  connect(nomFlow.y, VPri_flowNor.u2)
  connect(VPri_flowNor.y, conDam.u_m)
  connect(THeaSet, addPar.u)
  connect(conZer3.y, conTDisHeaSet.x1)
  connect(TSupSet, conTDisHeaSet.f1)
  connect(uHea, conTDisHeaSet.u)
  connect(conHal.y, conTDisHeaSet.x2)
  connect(addPar.y, conTDisHeaSet.f2)
  connect(conTDisHeaSet.y, conVal.u_s)
  connect(TDis, conVal.u_m)
  connect(uHea, greThr2.u)
  connect(greThr2.y, swi1.u2)
  connect(swi1.y, swi2.u3)
  connect(conZer3.y, swi2.u1)
  connect(conTDisHeaSet.y, THeaDisSet)
  connect(conZer3.y, swi3.u1)
  connect(conHal1.y, heaFanRat.x1)
  connect(uHea, heaFanRat.u)
  connect(conHal2.y, heaFanRat.x2)
  connect(maxFan.y, heaFanRat.f2)
  connect(uno.y, isUno.u1)
  connect(isUno.y, swi2.u2)
  connect(isUno.y, swi3.u2)
  connect(greThr2.y, conVal.trigger)
  connect(conVal.y, swi1.u1)
  connect(conZer3.y, swi1.u3)
  connect(and4.y, swi4.u2)
  connect(VOAMin_flow, swi4.u1)
  connect(VOAMin_flow, max1.u2)
  connect(max1.y, swi4.u3)
  connect(swi4.y, swi6.u1)
  connect(greThr1.y, swi6.u2)
  connect(greThr1.y, cooHea.u2)
  connect(greThr2.y, cooHea.u1)
  connect(cooHea.y, not1.u)
  connect(not1.y, swi7.u2)
  connect(swi7.y, swi6.u3)
  connect(VOAMin_flow, swi7.u1)
  connect(VOAMin_flow, heaFanRat.f1)
  connect(heaFanRat.y, swi8.u1)
  connect(greThr2.y, swi8.u2)
  connect(VOAMin_flow, swi8.u3)
  connect(swi8.y, swi7.u3)
  connect(occ.y, isOcc.u1)
  connect(uOpeMod, isOcc.u2)
  connect(uOpeMod, isUno.u2)
  connect(greThr1.y, or3.u1)
  connect(greThr2.y, or3.u2)
  connect(edg.y, lat.u)
  connect(lat.y, booToRea.u)
  connect(u1TerFan, tim.u)
  connect(tim.passed, lat.clr)
  connect(uDam, cloDam.u)
  connect(cloDam.y, and2.u1)
  connect(and2.y, lat1.u)
  connect(falEdg.y, lat1.clr)
  connect(swi3.y, mul.u1)
  connect(booToRea.y, mul.u2)
  connect(mul.y, yDam)
  connect(lat1.y, y1Fan)
  connect(lat1.y, booToRea1.u)
  connect(swi6.y, mul1.u1)
  connect(booToRea1.y, mul1.u2)
  connect(mul1.y, VFan_flow_Set)
  connect(oveFloSet,forZerFlo. u1)
  connect(conInt.y,forZerFlo. u2)
  connect(oveFloSet,forCooMax. u1)
  connect(conInt1.y,forCooMax. u2)
  connect(oveFloSet,forMinFlo. u1)
  connect(forZerFlo.y,zerFlo. u)
  connect(forCooMax.y,cooMax. u)
  connect(forMinFlo.y,minFlo. u)
  connect(cooMax.y,add2. u1)
  connect(zerFlo.y,add1. u1)
  connect(forZerFlo.y,or1. u1)
  connect(forCooMax.y,or1. u2)
  connect(add1.y,swi9. u1)
  connect(add2.y,add1. u2)
  connect(minFlo.y,add2. u2)
  connect(conInt2.y,forMinFlo. u2)
  connect(swi.y, swi9.u3)
  connect(swi9.y, max1.u1)
  connect(swi9.y, VDisSet_flowNor.u1)
  connect(swi9.y, VPri_flow_Set)
  connect(u1Fan, conDam.trigger)
  connect(conDam.y, swi3.u3)
  connect(or2.y, swi9.u2)
  connect(or1.y, or2.u2)
  connect(forMinFlo.y, or2.u1)
  connect(isOcc.y, or4.u1)
  connect(or3.y, or4.u2)
  connect(or4.y, edg.u)
  connect(or4.y, and2.u2)
  connect(or4.y, falEdg.u)
end DamperValves;


Software switches to override setpoints. This block considers the overrides to the setpoints for series fan-powered unit
with variable-volume fan.
The implementation is according to the Section 5.10.7 of ASHRAE Guideline 36,
May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences;
block Overrides "Software switches to override setpoints"

  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.RealInput uDam(
    final min=0,
    final unit="1") "Damper commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uHeaOff
    "Override heating valve position, true: close heating valve"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uVal(
    final min=0,
    final unit="1") "Heating valve commanded position"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput oveFan
    "Index of overriding fan status, 1: turn fan off; 2: turn fan on"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1Fan
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDam(
    final min=0,
    final unit="1") "Damper commanded position, after considering override"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput yVal(
    final min=0,
    final unit="1")
    "Heating valve commanded position, after considering override"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1Fan
    "Fan command on, after considering override"

  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    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 conInt4(
    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 swi1
    "Damper setpoint position after considering override"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro
    "Valve position setpoint after considering override"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    final realTrue=0,
    final realFalse=1)
    "Convert boolean true to real 0"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt5(
    final k=1)
    "Constant 1"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if forcing fan to turn  off"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu2
    "Check if forcing fan to turn on"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt6(
    final k=2)
    "Constant 2"
  Buildings.Controls.OBC.CDL.Logical.Switch logSwi
    "Fan status after considering override"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false)
    "Turn fan off"
  Buildings.Controls.OBC.CDL.Logical.Switch logSwi1
    "Logical switch"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    final k=true)
    "Turn fan on"

equation
  connect(conInt3.y, intEqu3.u2)
  connect(conInt4.y,intEqu4. u2)
  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(add3.y, swi1.u1)
  connect(or2.y, swi1.u2)
  connect(uDam, swi1.u3)
  connect(swi1.y, yDam)
  connect(uHeaOff, booToRea.u)
  connect(booToRea.y, pro.u1)
  connect(uVal, pro.u2)
  connect(pro.y,yVal)
  connect(conInt5.y,intEqu1. u2)
  connect(conInt6.y,intEqu2. u2)
  connect(oveFan, intEqu2.u1)
  connect(oveFan, intEqu1.u1)
  connect(intEqu1.y, logSwi.u2)
  connect(con.y, logSwi.u1)
  connect(intEqu2.y, logSwi1.u2)
  connect(con1.y, logSwi1.u1)
  connect(u1Fan, logSwi1.u3)
  connect(logSwi1.y, logSwi.u3)
  connect(logSwi.y, y1Fan)
end Overrides;


within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF;
package Subsequences "Package of subsequences for variable-volume parallel fan-powered terminal unit"
end Subsequences;


Output system requests for series fan-powered terminal unit with variable-volume fan. This sequence outputs the system reset requests for series fan-powered terminal
unit with variable-voume fan. The implementation is according to the Section 5.10.8
of ASHRAE Guideline 36, May 2020.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences;
block SystemRequests
  "Output system requests for series fan-powered terminal unit with variable-volume fan"

  parameter Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil heaCoi=Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Heating coil type"
  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 thrTDis_1(
    final unit="K",
    final quantity="TemperatureDifference")=17
    "Threshold difference between discharge air temperature and its setpoint for generating 3 hot water reset requests"
  parameter Real thrTDis_2(
    final unit="K",
    final quantity="TemperatureDifference")=8.3
    "Threshold difference between discharge air temperature and its setpoint for generating 2 hot water reset requests"
  parameter Real durTimTem(
    final unit="s",
    final quantity="Time")=120
    "Duration time of zone temperature exceeds setpoint"
  parameter Real durTimFlo(
    final unit="s",
    final quantity="Time")=60
    "Duration time of airflow rate less than setpoint"
  parameter Real durTimDisAir(
    final unit="s",
    final quantity="Time")=300
    "Duration time of discharge air temperature 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 valPosHys(
    final unit="1")
    "Near zero valve position, below which the valve 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 VPri_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.RealInput TDisSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge airflow setpoint temperature for heating"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Measured discharge airflow temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uVal(
    final min=0,
    final max=1,
    final unit="1") if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased "Hot water valve position"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonPreResReq
    "Zone static pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaValResReq if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Hot water reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHotWatPlaReq if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Request to heating hot-water plant"

protected
  Buildings.Controls.OBC.CDL.Reals.Less les(
    final h=dTHys) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if discharge temperature is less than setpoint by a threshold"
  Buildings.Controls.OBC.CDL.Reals.Less les1(
    final h=dTHys) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if discharge temperature is less than setpoint by a threshold"
  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.Reals.AddParameter addPar(
    final p=thrTDis_1) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature plus threshold"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=thrTDis_2) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Discharge temperature plus threshold"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant thrHeaResReq(
    final k=3) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Constant 3"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant twoHeaResReq(
    final k=2) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Constant 2"
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi2
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Integers.Switch intSwi3
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim4(
    final delayTime=durTimDisAir) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if it is more than threshold time"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim5(
    final delayTime=durTimDisAir) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if it is more than threshold time"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr5(
    final t=0.95,
    final h=valPosHys) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if valve position is greater than 0.95"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt2
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Convert boolean to integer"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr6(
    final t=0.95,
    final h=0.85) if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Check if valve position is greater than 0.95"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt3
    if heaCoi==Buildings.Controls.OBC.ASHRAE.G36.Types.HeatingCoil.WaterBased
    "Convert boolean to integer"
  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(TDis,addPar. u)
  connect(TDis,addPar1. u)
  connect(tim5.y, intSwi3.u2)
  connect(tim4.y, intSwi2.u2)
  connect(addPar.y, les.u1)
  connect(TDisSet, les.u2)
  connect(les.y, tim4.u)
  connect(TDisSet, les1.u2)
  connect(addPar1.y, les1.u1)
  connect(les1.y, tim5.u)
  connect(yHeaValResReq, intSwi2.y)
  connect(thrHeaResReq.y, intSwi2.u1)
  connect(twoHeaResReq.y, intSwi3.u1)
  connect(intSwi3.y, intSwi2.u3)
  connect(uVal, greThr5.u)
  connect(greThr5.y, booToInt2.u)
  connect(booToInt2.y, intSwi3.u3)
  connect(uVal, greThr6.u)
  connect(greThr6.y, booToInt3.u)
  connect(booToInt3.y, yHotWatPlaReq)
  connect(TCooSet, sub3.u2)
  connect(TCooSet, sub2.u2)
  connect(TZon, sub2.u1)
  connect(TZon, sub3.u1)
  connect(uDam, sampler3.u)
  connect(sampler3.y, greThr3.u)
  connect(uCoo, sampler.u)
  connect(sampler.y, greThr.u)
  connect(VPri_flow, sampler1.u)
  connect(sampler1.y, greEqu.u2)
  connect(sampler1.y, greEqu1.u2)
  connect(greThr4.u, sampler2.y)
  connect(sampler2.u, VSet_flow)
  connect(sampler2.y, gai1.u)
  connect(sampler2.y, gai2.u)
end SystemRequests;


Validate the model for calculating active airflow setpoint for unit with variable volume series fans. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.ActiveAirFlow
for calculating active minimum and maximum airflow setpoint used in series fan powered terminal unit.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Validation;
model ActiveAirFlow
  "Validate the model for calculating active airflow setpoint for unit with variable volume series fans"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.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.SeriesFanVVF.Subsequences.Alarms
for generating system alarms.

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

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Alarms ala(
    final staPreMul=1,
    final hotWatRes=1,
    final VCooMax_flow=1,
    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 disAir(
    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) "AHU 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.Logical.Sources.Pulse hotPla(
    final width=0.9,
    final period=7500) "Hot water plant status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TDis(
    final duration=3600,
    final offset=273.15 + 20,
    final height=-5) "Discharge air temperature"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse terFanComOn(
    final width=0.5,
    final period=7500)
    "Terminal fan command on status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse terFanOn(
    final width=0.5,
    final period=7500,
    shift=1000) "Terminal fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp valPos(
    final duration=2000,
    final height=-0.7,
    final offset=0.7,
    final startTime=3600) "Valve position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSup(
    final k=273.15 + 13)
    "AHU supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TDisSet(
    final k=273.15 + 30)
    "Discharge airflow temperature setpoint"
  Buildings.Controls.OBC.CDL.Integers.Sources.Pulse intPul(
    amplitude=6,
    width=0.1,
    period=8500,
    offset=1)
    "Operation mode"
equation
  connect(disAirSet.y, ala.VActSet_flow)
  connect(booToRea.y, mul.u1)
  connect(damPos.y, mul.u2)
  connect(damSta.y, booToRea.u)
  connect(disAir.y,ala.VPri_flow)
  connect(supFan.y, ala.u1Fan)
  connect(terFanComOn.y, ala.u1FanCom)
  connect(terFanOn.y, ala.u1TerFan)
  connect(mul.y, ala.uDam)
  connect(valPos.y, ala.uVal)
  connect(TSup.y, ala.TSup)
  connect(hotPla.y, ala.u1HotPla)
  connect(TDis.y, ala.TDis)
  connect(TDisSet.y, ala.TDisSet)
  connect(intPul.y, ala.uOpeMod)
end Alarms;


Validate model for controlling damper and valve position. This example validates

BBuildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.DamperValves
for damper and valve control of series fan powered unit.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Validation;
model DamperValves
  "Validate model for controlling damper and valve position"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.DamperValves damValFan1(
    final maxRat=0.1,
    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=1,
    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 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.Logical.Sources.Pulse terFan(
    final width=0.75,
    final period=7200) "Terminal fan status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSupSet(
    final k=273.15 + 13)
    "AHU supply air temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uHea(
    final height=1,
    final duration=3600,
    final offset=0,
    final startTime=5500) "Heating control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAir(
    final duration=7200,
    final offset=0.01,
    final height=0.06)
    "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TSup(
    final offset=273.15 + 13,
    final amplitude=1,
    final freqHz=1/3600)
    "Supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSet(
    final k=273.15 + 20)
    "Zone heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TDis(
    final offset=273.15 + 13,
    final amplitude=1.2,
    final freqHz=1/3600) "Measured discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp opeMod(
    final offset=1,
    final height=3,
    final duration=90000) "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.Ramp damPos(
    final height=1,
    final duration=3600,
    final offset=0,
    final startTime=5500) "Damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VMinOut_flow(
    final k=0.005)
    "Minimum outdoor airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveFlo(
    final height=3,
    final duration=2000,
    final 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.Logical.Sources.Pulse booPul(
    final width=0.9,
    final period=4800,
    final shift=180)
    "AHU fan status"
equation
  connect(VActMin_flow.y, damValFan1.VActMin_flow)
  connect(TZon.y, damValFan1.TZon)
  connect(VActCooMax_flow.y, damValFan1.VActCooMax_flow)
  connect(uCoo.y, damValFan1.uCoo)
  connect(uHea.y, damValFan1.uHea)
  connect(disAir.y, damValFan1.VPri_flow)
  connect(TSupSet.y, damValFan1.TSupSet)
  connect(TSup.y, damValFan1.TSup)
  connect(THeaSet.y, damValFan1.THeaSet)
  connect(TDis.y, damValFan1.TDis)
  connect(opeMod.y,round2. u)
  connect(round2.y,reaToInt2. u)
  connect(reaToInt2.y, damValFan1.uOpeMod)
  connect(terFan.y, damValFan1.u1TerFan)
  connect(damPos.y, damValFan1.uDam)
  connect(VMinOut_flow.y, damValFan1.VOAMin_flow)
  connect(oveFlo.y,round1. u)
  connect(round1.y,reaToInt1. u)
  connect(reaToInt1.y, damValFan1.oveFloSet)
  connect(booPul.y, damValFan1.u1Fan)
end DamperValves;


Validation of model that overrides control. This example validates

Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Overrides
for overrideing controls.

within Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Validation;
model Overrides "Validation of model that overrides control"

  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.SeriesFanVVF.Subsequences.Overrides ove
    "Block outputs system requests"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp damPos(
    final duration=3600,
    final height=0.5,
    final offset=0.5) "Damper position setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveDam(
    final height=2,
    final duration=2000,
    final startTime=1000) "Override damper position"
  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 heaValPos(
    final duration=3600,
    final height=0.5,
    final offset=0.5) "Heating valve position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp oveDam1(
    final height=2,
    final duration=2000,
    final 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 heaOff(
    final width=0.75,
    final period=3600)
    "Close heating valve"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant terFan(
    final k=true)
    "Terminal fan status"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Logical not"
equation
  connect(oveDam.y, round1.u)
  connect(round1.y, reaToInt1.u)
  connect(oveDam1.y, round3.u)
  connect(round3.y,reaToInt3. u)
  connect(reaToInt1.y, ove.oveDamPos)
  connect(damPos.y, ove.uDam)
  connect(heaValPos.y, ove.uVal)
  connect(reaToInt3.y, ove.oveFan)
  connect(terFan.y, ove.u1Fan)
  connect(heaOff.y, not1.u)
  connect(not1.y, ove.uHeaOff)
end Overrides;


Collection of validation models

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