Output system requests for VAV reheat terminal unit control. This sequence outputs the system reset requests, i.e.,

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat;
block SystemRequests
  "Output system requests for VAV reheat terminal unit control"

  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";

  parameter Boolean have_heaWatCoi
    "Flag, true if there is a hot water coil";
  parameter Boolean have_heaPla "Flag, true if there is a boiler plant";

  parameter Real errTZonCoo_1(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=2.8
    "Limit value of difference between zone temperature and cooling setpoint
    for generating 3 cooling SAT reset requests";
  parameter Real errTZonCoo_2(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=1.7
    "Limit value of difference between zone temperature and cooling setpoint
    for generating 2 cooling SAT reset requests";
  parameter Real errTDis_1(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=17
    "Limit value of difference between discharge air temperature and its setpoint
    for generating 3 hot water reset requests";
  parameter Real errTDis_2(
    final unit="K",
    final displayUnit="K",
    final quantity="TemperatureDifference")=8.3
    "Limit value of 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 is less than setpoint"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonCooSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Zone cooling setpoint 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 VDis_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Measured discharge airflow rate"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput VDisSet_flow(
    final min=0,
    final unit="m3/s",
    quantity="VolumeFlowRate")
    "Discharge airflow rate setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput yDam_actual(
    final min=0,
    final max=1,
    final unit="1") "Actual damper position"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDisHeaSet(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if have_heaWatCoi
    "Discharge airflow setpoint temperature for heating"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDis(
    final unit="K",
    final displayUnit="degC",
    final quantity="ThermodynamicTemperature") if have_heaWatCoi
    "Measured discharge airflow temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput uHeaVal(
    final min=0,
    final max=1,
    final unit="1") if have_heaWatCoi "Heating valve position"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonPreResReq
    "Zone static pressure reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yZonTemResReq
    "Zone cooling supply air temperature reset request"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaValResReq if have_heaWatCoi
    "Hot water reset requests"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yHeaPlaReq if (have_heaWatCoi and have_heaPla)
    "Heating plant request"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys(
    final uLow=errTZonCoo_1 - 0.1,
    final uHigh=errTZonCoo_1 + 0.1)
    "Check if zone temperature is greater than cooling setpoint by errTZonCoo_1"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys3(
    final uLow=errTZonCoo_2 - 0.1,
    final uHigh=errTZonCoo_2 + 0.1)
    "Check if zone temperature is greater than cooling setpoint by errTZonCoo_2"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys4(
    final uLow=0.85,
    final uHigh=0.95)
    "Check if damper position is greater than 0.95"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys5(
    final uLow=0.85,
    final uHigh=0.95)
    "Check if cooling loop signal is greater than 0.95"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys7(
    final uHigh=0.01,
    final uLow=0.005)
    "Check if discharge airflow setpoint is greater than 0"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys8(
    final uLow=-0.1,
    final uHigh=0.1) if have_heaWatCoi
    "Check if discharge air temperature is errTDis_1 less than setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys9(
    final uLow=-0.1,
    final uHigh=0.1) if have_heaWatCoi
    "Check if discharge air temperature is errTDis_2 less than setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys10(
    final uLow=0.85,
    final uHigh=0.95) if have_heaWatCoi
    "Check if valve position is greater than 0.95"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys11(
    final uHigh=0.95,
    final uLow=0.1) if (have_heaWatCoi and have_heaPla)
    "Check if valve position is greater than 0.95"

protected
  Buildings.Controls.OBC.CDL.Discrete.Sampler samTZonCooSet(
    final samplePeriod=samplePeriod)
    "Sample current cooling setpoint"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay uniDel(
    final samplePeriod=samplePeriod)
    "Delay value to record input value"
  Buildings.Controls.OBC.CDL.Reals.Abs abs "Absolute change of the setpoint temperature"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam
    "Sample the setpoint changed value when there is change"
  Buildings.Controls.OBC.CDL.Logical.Edge edg "Instants when input becomes true"
  Buildings.Controls.OBC.CDL.Logical.Latch lat "Maintains an on signal until conditions changes"
  Buildings.Controls.OBC.CDL.Logical.Latch lat1 "Maintains an on signal until conditions changes"
  Buildings.Controls.OBC.CDL.Logical.Timer tim "Calculate time"
  Buildings.Controls.OBC.CDL.Reals.Greater gre1
    "Check if current model time is greater than the sample period"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys2(
    final uLow=0.05,
    final uHigh=0.15)
    "Check if there is setpoint change"
  Buildings.Controls.OBC.CDL.Reals.Min supTim "Suppression time"
  Buildings.Controls.OBC.CDL.Reals.Sources.CivilTime modTim
    "Civil time"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(final k=540)
    "Convert change of degC to change of degF and find out suppression time (5 min/degF))"
  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 sub1
    "Calculate difference of previous and current setpoints"
  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.Reals.Subtract sub6 if have_heaWatCoi
    "Calculate difference of discharge temperature (plus errTDis_1) and its setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub7 if have_heaWatCoi
    "Calculate difference of discharge temperature (plus errTDis_2) and its setpoint"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=errTDis_1) if have_heaWatCoi
    "Discharge temperature plus errTDis_1"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=errTDis_2) if have_heaWatCoi
    "Discharge temperature plus errTDis_2"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt "Convert real to integer value"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt1 "Convert real to integer value"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt2 if have_heaWatCoi
    "Convert real to integer value"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt3 if (have_heaWatCoi and
    have_heaPla)
    "Convert real to integer value"
  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.Reals.Sources.Constant con(
    final k=samplePeriod) "Sample period time"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conZer(final k=0.0)
               "Constant zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant thrCooResReq(final k=
        3.0)   "Constant 3"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant twoCooResReq(final k=
        2.0)   "Constant 2"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant oneCooResReq(final k=1.0)
               "Constant 1"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCooReq(final k=0.0)
               "Constant 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant thrPreResReq(final k=
        3.0)   "Constant 3"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant twoPreResReq(final k=
        2.0)   "Constant 2"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerPreResReq(final k=
        0.0)   "Constant 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant onePreResReq(final k=
        1.0)   "Constant 1"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant thrHeaResReq(
    final k=3) if have_heaWatCoi
    "Constant 3"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant twoHeaResReq(
    final k=2) if have_heaWatCoi
    "Constant 2"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant oneHeaResReq(final k=
        1.0)   if have_heaWatCoi
    "Constant 1"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerHeaResReq(final k=
        0.0)   if have_heaWatCoi
    "Constant 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerBoiPlaReq(final k=
        0.0)   if (have_heaWatCoi
     and have_heaPla)
    "Constant 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant oneBoiPlaReq(final k=
        1.0)   if (have_heaWatCoi and have_heaPla)
    "Constant 1"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxSupTim(k=1800)
    "Maximum suppression time 30 minutes"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con5(k=true) "Constant true"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Use setpoint different value when half sample period time has passed"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1 "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi2 "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi3 "Output 0 or 1 request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi4 "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi5 "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi6 "Output 0 or 1 request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi7 if have_heaWatCoi
    "Output 3 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi8 if have_heaWatCoi
    "Output 2 or other request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi9 if have_heaWatCoi
    "Output 0 or 1 request "
  Buildings.Controls.OBC.CDL.Reals.Switch swi10 if (have_heaWatCoi and
    have_heaPla)
    "Output 0 or 1 request "
  Buildings.Controls.OBC.CDL.Logical.Pre pre1
    "Use left-limit of signal to break algebraic loop"
  Buildings.Controls.OBC.CDL.Logical.Switch logSwi "Logical switch"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim1(delayTime=durTimTem)
    "Check if it is more than durTimTem"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim2(delayTime=durTimTem)
    "Check if it is more than durTimTem"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim3(delayTime=durTimFlo)
    "Check if it is more than durTimFlo"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim4(delayTime=durTimDisAir) if have_heaWatCoi
    "Check if it is more than durTimDisAir"
  Buildings.Controls.OBC.CDL.Logical.TrueDelay tim5(delayTime=durTimDisAir) if have_heaWatCoi
    "Check if it is more than durTimDisAir"
  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 sampler4(
    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.Reals.Greater greVDis50
    "Check if discharge airflow is less than 50% of setpoint"
  Buildings.Controls.OBC.CDL.Reals.Greater greVDis70
    "Check if discharge airflow is less than 70% of setpoint"
  Buildings.Controls.OBC.CDL.Reals.Less les
    "Check if the suppression time has not yet passed"
  Buildings.Controls.OBC.CDL.Logical.Not notLes
    "Inversion of output signal"

equation
  connect(sub2.y, hys.u)
  connect(TZonCooSet, samTZonCooSet.u)
  connect(samTZonCooSet.y, uniDel.u)
  connect(triSam.y, gai.u)
  connect(hys2.y, lat.u)
  connect(lat.y, tim.u)
  connect(edg.y, triSam.trigger)
  connect(lat.y, edg.u)
  connect(edg.y, lat1.clr)
  connect(modTim.y, gre1.u1)
  connect(con.y, gre1.u2)
  connect(gre1.y, swi.u2)
  connect(sub1.y, swi.u1)
  connect(conZer.y, swi.u3)
  connect(swi.y, abs.u)
  connect(abs.y, triSam.u)
  connect(abs.y, hys2.u)
  connect(and2.y, swi1.u2)
  connect(thrCooResReq.y, swi1.u1)
  connect(sub3.y, hys3.u)
  connect(twoCooResReq.y, swi2.u1)
  connect(swi2.y, swi1.u3)
  connect(and1.y, swi2.u2)
  connect(hys5.y, swi3.u2)
  connect(oneCooResReq.y, swi3.u1)
  connect(swi3.y, swi2.u3)
  connect(zerCooReq.y, swi3.u3)
  connect(swi1.y, reaToInt.u)
  connect(reaToInt.y, yZonTemResReq)
  connect(and3.y, swi4.u2)
  connect(thrPreResReq.y, swi4.u1)
  connect(and4.y, swi5.u2)
  connect(twoPreResReq.y, swi5.u1)
  connect(swi5.y, swi4.u3)
  connect(hys4.y, swi6.u2)
  connect(onePreResReq.y, swi6.u1)
  connect(zerPreResReq.y, swi6.u3)
  connect(swi6.y, swi5.u3)
  connect(swi4.y, reaToInt1.u)
  connect(reaToInt1.y, yZonPreResReq)
  connect(TDis, addPar.u)
  connect(addPar.y, sub6.u2)
  connect(TDisHeaSet, sub6.u1)
  connect(sub6.y, hys8.u)
  connect(addPar1.y, sub7.u2)
  connect(sub7.y, hys9.u)
  connect(hys9.y, tim5.u)
  connect(thrHeaResReq.y, swi7.u1)
  connect(twoHeaResReq.y, swi8.u1)
  connect(swi8.y, swi7.u3)
  connect(TDis, addPar1.u)
  connect(TDisHeaSet, sub7.u1)
  connect(uHeaVal, hys10.u)
  connect(hys10.y, swi9.u2)
  connect(oneHeaResReq.y, swi9.u1)
  connect(zerHeaResReq.y, swi9.u3)
  connect(swi9.y, swi8.u3)
  connect(swi7.y, reaToInt2.u)
  connect(reaToInt2.y, yHeaValResReq)
  connect(uHeaVal, hys11.u)
  connect(hys11.y, swi10.u2)
  connect(oneBoiPlaReq.y, swi10.u1)
  connect(zerBoiPlaReq.y, swi10.u3)
  connect(swi10.y, reaToInt3.u)
  connect(reaToInt3.y,yHeaPlaReq)
  connect(pre1.y, lat.clr)
  connect(lat.y, logSwi.u2)
  connect(con5.y, logSwi.u3)
  connect(lat1.y, logSwi.u1)
  connect(logSwi.y, and2.u1)
  connect(logSwi.y, and1.u1)
  connect(gai.y, supTim.u1)
  connect(maxSupTim.y, supTim.u2)
  connect(tim5.y, swi8.u2)
  connect(hys8.y, tim4.u)
  connect(tim4.y, swi7.u2)
  connect(hys7.y, tim3.u)
  connect(tim3.y, and3.u1)
  connect(tim3.y, and4.u1)
  connect(hys3.y, tim2.u)
  connect(tim2.y, and1.u2)
  connect(hys.y, tim1.u)
  connect(tim1.y, and2.u2)
  connect(sampler.u, VDisSet_flow)
  connect(sampler.y, gai1.u)
  connect(sampler.y, gai2.u)
  connect(sampler1.u, VDis_flow)
  connect(yDam_actual, sampler2.u)
  connect(sampler2.y, hys4.u)
  connect(uCoo, sampler4.u)
  connect(sampler4.y, hys5.u)
  connect(hys7.u, VDisSet_flow)
  connect(greVDis50.u1, gai1.y)
  connect(greVDis50.u2, sampler1.y)
  connect(greVDis50.y, and3.u2)
  connect(gai2.y, greVDis70.u1)
  connect(sampler1.y, greVDis70.u2)
  connect(greVDis70.y, and4.u2)
  connect(tim.y, les.u1)
  connect(supTim.y, les.u2)
  connect(notLes.y, pre1.u)
  connect(lat1.u, notLes.y)
  connect(les.y, notLes.u)
  connect(samTZonCooSet.y, sub2.u2)
  connect(TZon, sub2.u1)
  connect(TZon, sub3.u1)
  connect(samTZonCooSet.y, sub3.u2)
  connect(samTZonCooSet.y, sub1.u1)
  connect(uniDel.y, sub1.u2)
end SystemRequests;


Output the active airflow setpoint for VAV reheat terminal unit. This atomic sequence sets the active maximum and minimum setpoints VActCooMax_flow,
VActCooMin_flow, VActMin_flow, VActHeaMin_flow,
VActHeaMax_flow for VAV reheat terminal unit according to ASHRAE
Guideline 36 (G36), PART 5.E.3-5.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints;
block ActiveAirFlow
  "Output the active airflow setpoint for VAV reheat terminal unit"

  parameter Boolean have_occSen
    "Set to true if the zone has occupancy sensor"
  parameter Boolean have_winSen
    "Set to true if the zone has window status sensor"
  parameter Boolean have_CO2Sen
    "Set to true if the zone has CO2 sensor"
  parameter Real VDisCooSetMax_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Zone maximum cooling airflow setpoint"
  parameter Real VDisSetMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Zone minimum airflow setpoint"
  parameter Real VDisHeaSetMax_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "Zone maximum heating airflow setpoint"
  parameter Real VDisConMin_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")
    "VAV box controllable minimum"
  parameter Real AFlo(
    final unit="m2",
    final quantity="Area") "Area of the zone"
  parameter Real VOutPerAre_flow(
    final unit = "m3/(s.m2)")=3e-4
    "Outdoor air rate per unit area"
  parameter Real VOutPerPer_flow(
    final unit="m3/s",
    final quantity="VolumeFlowRate")=2.5e-3
    "Outdoor air rate per person"
  parameter Real CO2Set = 894 "CO2 setpoint in ppm"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput nOcc(final unit="1") if have_occSen
    "Number of occupants"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput ppmCO2 if have_CO2Sen
    "Detected CO2 conventration"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uWin if have_winSen
    "Window status, true if open, false if closed"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "Zone operation mode"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VOccDisMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Occupied minimum airflow "
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActCooMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active cooling maximum"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActCooMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active cooling minimum"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active minimum"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActHeaMin_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active heating minimum"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput VActHeaMax_flow(
    final min=0,
    final unit="m3/s",
    final quantity="VolumeFlowRate") "Active heating maximum"

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=VOutPerPer_flow) if have_occSen "Outdoor air per person"
  Buildings.Controls.OBC.CDL.Reals.Add breZon if have_occSen
    "Breathing zone airflow"
  Buildings.Controls.OBC.CDL.Reals.Line co2ConLoo if have_CO2Sen
    "Maintain CO2 concentration at setpoint, reset 0% at (setpoint-200) and 100% at setpoint"
  Buildings.Controls.OBC.CDL.Reals.Line lin1 if have_CO2Sen
    "Reset occupied minimum airflow setpoint from 0% at VDisSetMin_flow and 100% at VDisCooSetMax_flow"
  Buildings.Controls.OBC.CDL.Reals.Greater gre
    "Check if zone minimum airflow setpoint Vmin is less than the allowed controllable VDisConMin_flow"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr1
    "Check if zone minimum airflow setpoint VDisSetMin_flow is non-zero"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Reset occupied minimum airflow according to occupancy"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Reset occupied minimum airflow according to window status"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Reset occupied minimum airflow setpoint according to minimum controllable airflow"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3 if have_CO2Sen
    "Switch between zero signal and CO2 control loop signal depending on the operation mode"
  Buildings.Controls.OBC.CDL.Logical.And and1 "Logical and"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Not not2 if have_winSen "Logical not"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=0.75,
    final h=0.5) if have_occSen
    "Check if the zone becomes unpopulated"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minZonAir1(
    final k=VDisSetMin_flow) if not have_CO2Sen
    "Zone minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxZonCooAir(
    final k=VDisCooSetMax_flow) if have_CO2Sen
    "Zone maximum cooling airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant breZonAre(
    final k=VOutPerAre_flow*AFlo) if have_occSen
    "Area component of the breathing zone outdoor airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant conVolMin(
    final k=VDisConMin_flow)
    "VAV box controllable minimum"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minZonAir(
    final k=VDisSetMin_flow)
    "Zone minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant setCO1(
    final k=CO2Set - 200) if have_CO2Sen
    "CO2 setpoints minus 200"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant setCO2(
    final k=CO2Set) if have_CO2Sen
    "CO2 setpoints"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerFlo(final k=0)
    "Zero airflow when window is open"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=true) if not have_occSen "Constant true"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    final k=true) if not have_winSen "Constant true"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCon(
    final k=0) "Output zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCon1(
    final k=0) if have_CO2Sen
    "Output zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCon2(
    final k=0) if have_CO2Sen
    "Output zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCon3(
    final k=0) if not have_occSen
    "Output zero"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant oneCon(
    final k=1) if have_CO2Sen
    "Output one"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant oneCon1(
    final k=1) if have_CO2Sen "Output one"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooMaxAir(
    final k=VDisCooSetMax_flow)
    "Cooling maximum airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaMaxAir(
    final k=VDisHeaSetMax_flow)
    "Heat maximum airflow"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerCon6(
    final k=0)
    "Output zero"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.coolDown)
    "Cool down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setUp)
    "Setup mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "Warm up mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.setBack)
    "Setback mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu
    "Check if current operation mode is occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if current operation mode is cool-down mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu2
    "Check if current operation mode is setup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu3
    "Check if current operation mode is warmup mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu4
    "Check if current operation mode is setback mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    "Select cooling maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi8
    "Select heating maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi9
    "Select cooling maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi17
    "Select heating minimum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi18
    "Select heating maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi22
    "Select heating minimum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi23
    "Select heating maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi24
    "Select cooling maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi25
    "Select cooling minimum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi26
    "Select minimum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi27
    "Select heating minimum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi28
    "Select heating maximum based on operation mode"
  Buildings.Controls.OBC.CDL.Reals.Max maxInp "Find greater input"
  Buildings.Controls.OBC.CDL.Reals.Add add2 "Add real input"
  Buildings.Controls.OBC.CDL.Reals.Add actCooMaxAir
    "Active cooling maximum airflow"
  Buildings.Controls.OBC.CDL.Reals.Add add1 "Add real input"
  Buildings.Controls.OBC.CDL.Reals.Add actHeaMinAir
    "Active heating minimum airflow"
  Buildings.Controls.OBC.CDL.Reals.Add add3 "Add real input"
  Buildings.Controls.OBC.CDL.Reals.Add actHeaMaxAir1
    "Active heating maximum airflow"
  Buildings.Controls.OBC.CDL.Reals.Add add4 "Add real input"

equation
  connect(conVolMin.y, gre.u1)
  connect(setCO1.y, co2ConLoo.x1)
  connect(zerCon.y, co2ConLoo.f1)
  connect(ppmCO2, co2ConLoo.u)
  connect(setCO2.y, co2ConLoo.x2)
  connect(oneCon.y, co2ConLoo.f2)
  connect(zerCon1.y, lin1.x1)
  connect(oneCon1.y, lin1.x2)
  connect(maxZonCooAir.y, lin1.f2)
  connect(minZonAir.y, lin1.f1)
  connect(intEqu.y, swi3.u2)
  connect(co2ConLoo.y, swi3.u1)
  connect(swi3.y, lin1.u)
  connect(zerCon2.y, swi3.u3)
  connect(uOpeMod, intEqu.u2)
  connect(conInt.y, intEqu.u1)
  connect(nOcc, gai.u)
  connect(breZonAre.y, breZon.u2)
  connect(gai.y, breZon.u1)
  connect(breZon.y, swi.u3)
  connect(lin1.y, swi.u1)
  connect(minZonAir.y, greThr1.u)
  connect(minZonAir.y, gre.u2)
  connect(gre.y,and1. u2)
  connect(greThr1.y,and1. u1)
  connect(and1.y, not1.u)
  connect(not1.y, swi2.u2)
  connect(conVolMin.y, swi2.u3)
  connect(swi.y, swi2.u1)
  connect(uWin, not2.u)
  connect(not2.y, swi1.u2)
  connect(zerFlo.y, swi1.u3)
  connect(swi2.y, swi1.u1)
  connect(swi1.y, VOccDisMin_flow)
  connect(con.y, swi.u2)
  connect(minZonAir1.y, swi.u1)
  connect(con1.y, swi1.u2)
  connect(zerCon3.y, swi.u3)
  connect(intEqu.y, swi24.u2)
  connect(intEqu.y, swi25.u2)
  connect(intEqu.y, swi26.u2)
  connect(intEqu.y, swi27.u2)
  connect(intEqu.y, swi28.u2)
  connect(cooMaxAir.y, swi24.u1)
  connect(heaMaxAir.y, maxInp.u2)
  connect(maxInp.y, swi28.u1)
  connect(zerCon6.y, swi24.u3)
  connect(zerCon6.y, swi25.u3)
  connect(zerCon6.y, swi26.u3)
  connect(zerCon6.y, swi27.u3)
  connect(zerCon6.y, swi28.u3)
  connect(uOpeMod, intEqu1.u2)
  connect(uOpeMod, intEqu2.u2)
  connect(uOpeMod, intEqu4.u2)
  connect(uOpeMod, intEqu3.u2)
  connect(conInt1.y, intEqu1.u1)
  connect(conInt2.y, intEqu2.u1)
  connect(conInt4.y, intEqu4.u1)
  connect(conInt3.y, intEqu3.u1)
  connect(cooMaxAir.y, swi4.u1)
  connect(heaMaxAir.y, swi8.u1)
  connect(intEqu1.y, swi4.u2)
  connect(intEqu1.y, swi8.u2)
  connect(zerCon6.y, swi4.u3)
  connect(zerCon6.y, swi8.u3)
  connect(cooMaxAir.y, swi9.u1)
  connect(intEqu2.y, swi9.u2)
  connect(zerCon6.y, swi9.u3)
  connect(intEqu3.y, swi17.u2)
  connect(intEqu3.y, swi18.u2)
  connect(intEqu4.y, swi22.u2)
  connect(intEqu4.y, swi23.u2)
  connect(heaMaxAir.y, swi17.u1)
  connect(cooMaxAir.y, swi18.u1)
  connect(zerCon6.y, swi17.u3)
  connect(zerCon6.y, swi18.u3)
  connect(zerCon6.y, swi22.u3)
  connect(zerCon6.y, swi23.u3)
  connect(heaMaxAir.y, swi22.u1)
  connect(cooMaxAir.y, swi23.u1)
  connect(swi1.y, swi25.u1)
  connect(swi1.y, swi26.u1)
  connect(swi1.y, swi27.u1)
  connect(swi1.y, maxInp.u1)
  connect(nOcc, greThr.u)
  connect(greThr.y, swi.u2)
  connect(add2.y, actCooMaxAir.u1)
  connect(swi4.y, add2.u1)
  connect(swi9.y, add2.u2)
  connect(swi24.y, actCooMaxAir.u2)
  connect(actCooMaxAir.y, VActCooMax_flow)
  connect(swi25.y, VActCooMin_flow)
  connect(swi26.y, VActMin_flow)
  connect(swi17.y, add1.u1)
  connect(swi22.y, add1.u2)
  connect(swi27.y, actHeaMinAir.u2)
  connect(add1.y, actHeaMinAir.u1)
  connect(actHeaMinAir.y, VActHeaMin_flow)
  connect(swi8.y, add3.u1)
  connect(swi28.y, add3.u2)
  connect(swi18.y, add4.u1)
  connect(swi23.y, add4.u2)
  connect(actHeaMaxAir1.y, VActHeaMax_flow)
  connect(add3.y, actHeaMaxAir1.u1)
  connect(add4.y, actHeaMaxAir1.u2)
end ActiveAirFlow;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat;
package SetPoints "Output setpoints for terminal unit control"
end SetPoints;


Validate the model for calculating active airflow setpoint for VAV terminal unit with reheat. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints.ActiveAirFlow
for calculating active minimum and maximum airflow setpoint used in a VAV reheat
terminal unit control.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints.Validation;
model ActiveAirFlow
  "Validate the model for calculating active airflow setpoint for VAV terminal unit with reheat"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints.ActiveAirFlow
    actAirSet_RehBox(
    VDisCooSetMax_flow=0.075,
    VDisSetMin_flow=0.017,
    VDisHeaSetMax_flow=0.05,
    VDisConMin_flow=0.01,
    AFlo=40,
    have_occSen=true,
    have_winSen=true,
    have_CO2Sen=true)
    "Output the active airflow setpoint for VAV reheat terminal unit"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints.ActiveAirFlow
    actAirSet_RehBox1(
    VDisCooSetMax_flow=0.075,
    VDisSetMin_flow=0.017,
    VDisHeaSetMax_flow=0.05,
    VDisConMin_flow=0.01,
    AFlo=40,
    have_occSen=true,
    have_winSen=true,
    have_CO2Sen=true)
    "Output the active airflow setpoint for VAV reheat terminal unit"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp coCon(
    height=400,
    duration=86400,
    offset=500) "CO2 concentration"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine(
    amplitude=2,
    freqHz=1/86400,
    offset=2) "occNum"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(
    shift=0,
    width=0.2,
    period=90000)
    "Generate signal indicating window status"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(k=1) "Occupied mode index"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(k=2) "Cool-down mode index"
  Buildings.Controls.OBC.CDL.Reals.Round round1(n=0)
    "Round real number to given digits"

equation
  connect(coCon.y,actAirSet_RehBox. ppmCO2)
  connect(winSta.y,actAirSet_RehBox. uWin)
  connect(conInt.y, actAirSet_RehBox.uOpeMod)
  connect(coCon.y, actAirSet_RehBox1.ppmCO2)
  connect(conInt1.y, actAirSet_RehBox1.uOpeMod)
  connect(winSta.y, actAirSet_RehBox1.uWin)
  connect(sine.y, round1.u)
  connect(round1.y, actAirSet_RehBox.nOcc)
  connect(round1.y, actAirSet_RehBox1.nOcc)
end ActiveAirFlow;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SetPoints;
package Validation "Collection of validation models"
end Validation;


Validate model for controlling damper and valve position of VAV reheat terminal unit. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.DamperValves
for damper and valve control of VAV reheat terminal unit.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.Validation;
model DamperValves
  "Validate model for controlling damper and valve position of VAV reheat terminal unit"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.DamperValves
    damVal(kDam=1, V_flow_nominal=2)
    "Output signal for controlling VAV reheat box damper and valve position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uHea(
    duration=36000,
    height=-1,
    offset=1,
    startTime=0)
    "Heating control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uCoo(
    height=1,
    duration=36000,
    offset=0,
    startTime=50400)
    "Cooling control signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSet(k=273.15 + 20)
    "Zone heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZon(k=273.15 + 22)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSup(k=273.15 + 13)
    "AHU supply air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActMin_flow(k=0.01)
    "Active minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActHeaMin_flow(k=0.015)
    "Active heating minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActHeaMax_flow(k=0.05)
    "Active heating maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActCooMin_flow(k=0.015)
    "Active cooling minimum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant VActCooMax_flow(k=0.075)
    "Active cooling maximum airflow setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin VDis_flow(
    offset=0.015,
    amplitude=0.002,
    freqHz=1/86400) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TDis(k=273.15 + 25)
    "Discharge air temperature"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant occSig(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied signal"

equation
  connect(VDis_flow.y, damVal.VDis_flow)
  connect(TDis.y, damVal.TDis)
  connect(VActCooMax_flow.y, damVal.VActCooMax_flow)
  connect(VActCooMin_flow.y, damVal.VActCooMin_flow)
  connect(VActHeaMax_flow.y, damVal.VActHeaMax_flow)
  connect(VActHeaMin_flow.y, damVal.VActHeaMin_flow)
  connect(VActMin_flow.y, damVal.VActMin_flow)
  connect(uCoo.y, damVal.uCoo)
  connect(uHea.y, damVal.uHea)
  connect(THeaSet.y, damVal.THeaSet)
  connect(TSup.y, damVal.TSup)
  connect(TZon.y, damVal.TZon)
  connect(occSig.y, damVal.uOpeMod)
end DamperValves;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat;
package Validation "Collection of validation models"
end Validation;


Validation of model that generates system requests. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SystemRequests
for generating system requests.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.Validation;
model SystemRequests
  "Validation of model that generates system requests"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Reheat.SystemRequests
    sysReq_RehBox(have_heaPla=true, have_heaWatCoi=true)
    "Block outputs system requests"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine(freqHz=1/7200, offset=296.15)
    "Generate data for setpoint"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay TZonCooSet(samplePeriod=1800)
    "Cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TZon(
    freqHz=1/7200,
    amplitude=2,
    offset=299.15) "Zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp uCoo(
    height=0.9,
    duration=7200,
    offset=0.1) "Cooling loop signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirSet(
    height=0.9,
    duration=7200,
    offset=0.1) "Discharge airflow rate setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirRate(
    duration=7200,
    offset=0.1,
    height=0.3) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp damPos(
    duration=7200,
    height=0.7,
    offset=0.3) "Damper position"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin sine1(
    freqHz=1/7200,
    offset=305.15)
    "Generate data for setpoint"
  Buildings.Controls.OBC.CDL.Discrete.UnitDelay TDisHeaSet(
    samplePeriod=1800)
    "Discharge air setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TDis(
    freqHz=1/7200,
    amplitude=2,
    offset=293.15)
    "Discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp valPos(
    duration=7200,
    height=1,
    offset=0)
    "Hot water valve position"

equation
  connect(sine.y, TZonCooSet.u)
  connect(TZonCooSet.y, sysReq_RehBox.TZonCooSet)
  connect(TZon.y, sysReq_RehBox.TZon)
  connect(uCoo.y, sysReq_RehBox.uCoo)
  connect(disAirSet.y, sysReq_RehBox.VDisSet_flow)
  connect(disAirRate.y, sysReq_RehBox.VDis_flow)
  connect(damPos.y,sysReq_RehBox.yDam_actual)
  connect(sine1.y, TDisHeaSet.u)
  connect(TDisHeaSet.y, sysReq_RehBox.TDisHeaSet)
  connect(TDis.y, sysReq_RehBox.TDis)
  connect(valPos.y,sysReq_RehBox.uHeaVal)
end SystemRequests;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits;
package SetPoints "Generic sequences of generating setpoints for terminal units control"
end SetPoints;


Block outputs thermal zone cooling and heating setpoint. This sequence sets the thermal zone cooling and heating setpoints. The implementation
is according to the ASHRAE Guideline 36 (G36), PART 5.B.3. The calculation is done
following the steps below.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.SetPoints;
block ZoneTemperatures
  "Block outputs thermal zone cooling and heating setpoint"

  parameter Boolean have_occSen "Check if the zone has occupancy sensor"
  parameter Boolean have_winSen
    "Check if the zone has window status sensor"

  parameter Boolean cooAdj=false
    "Flag, set to true if both cooling and heating setpoint are adjustable separately"
  parameter Boolean heaAdj=false
    "Flag, set to true if heating setpoint is adjustable"
  parameter Boolean sinAdj = false
    "Flag, set to true if both cooling and heating setpoint are adjustable through a single common knob"
  parameter Boolean ignDemLim = true
    "Flag, set to true to exempt individual zone from demand limit setpoint adjustment"

  parameter Real TZonCooOnMax(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=300.15
    "Maximum cooling setpoint during on"
  parameter Real TZonCooOnMin(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=295.15
    "Minimum cooling setpoint during on"
  parameter Real TZonHeaOnMax(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=295.15
    "Maximum heating setpoint during on"
  parameter Real TZonHeaOnMin(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=291.15
    "Minimum heating setpoint during on"
  parameter Real TZonCooSetWinOpe(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=322.15
    "Cooling setpoint when window is open"
  parameter Real TZonHeaSetWinOpe(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")=277.15
    "Heating setpoint when window is open"

  parameter Real incTSetDem_1=0.56
    "Cooling setpoint increase value (degC) when cooling demand limit level 1 is imposed"
  parameter Real incTSetDem_2=1.1
    "Cooling setpoint increase value (degC) when cooling demand limit level 2 is imposed"
  parameter Real incTSetDem_3=2.2
    "Cooling setpoint increase value (degC) when cooling demand limit level 3 is imposed"
  parameter Real decTSetDem_1=0.56
    "Heating setpoint decrease value (degC) when heating demand limit level 1 is imposed"
  parameter Real decTSetDem_2=1.1
    "Heating setpoint decrease value (degC) when heating demand limit level 2 is imposed"
  parameter Real decTSetDem_3=2.2
    "Heating setpoint decrease value (degC) when heating demand limit level 3 is imposed"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonCooSetOcc(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Occupied zone cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonHeaSetOcc(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Occupied zone heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonCooSetUno(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Unoccupied zone cooling setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZonHeaSetUno(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")
    "Unoccupied zone heating setpoint"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput setAdj(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") if (cooAdj or sinAdj)
    "Setpoint adjustment value"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput heaSetAdj(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature") if heaAdj
    "Heating setpoint adjustment value"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uOpeMod
    "AHU operation mode status signal"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uCooDemLimLev
    "Cooling demand limit level"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerInput uHeaDemLimLev
    "Heating demand limit level"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uOccSen if have_occSen
    "Occupancy sensor (occupied=true, unoccupied=false)"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput uWinSta if have_winSen
    "Window status (open=true, close=false)"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TZonCooSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")  "Cooling setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TZonHeaSet(
    final unit="K",
    displayUnit="degC",
    final quantity="ThermodynamicTemperature")  "Heating setpoint temperature"
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput yAla "Alarm level"

  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Check if there is cooling/heating demand limit being imposed"
  Buildings.Controls.OBC.CDL.Logical.Edge edg "If demand limit is imposed"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler cooSetFre
    "Freeze current cooling setpoint when demand limit is imposed"
  Buildings.Controls.OBC.CDL.Logical.Not not3 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.Or or5
    "Check if demand limit should be ignored or if there is no demand limit"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or1
    "Check if cooling demand limit level is imposed"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logic not"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar3(
    final p=incTSetDem_3)
    "Increase setpoint by 2.2 degC"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar1(
    final p=incTSetDem_2)
    "Increase setpoint by 1.1 degC"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar2(
    final p=incTSetDem_1)
    "Increase setpoint by 0.56 degC"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro6
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro1
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro2
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler heaSetFre
    "Freeze current heating setpoint when demand limit is imposed"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or4 "Check if heating demand limit level is imposed"
  Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro7
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar6(
    final p=-decTSetDem_1)
    "Decrease setpoint by 0.56 degC"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar5(
    final p=-decTSetDem_2)
    "Decrease setpoint by 1.1 degC"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar4(
    final p=-decTSetDem_3)
    "Decrease setpoint by 2.2 degC"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro5
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro4
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Multiply pro3
    "Output product of the two inputs"
  Buildings.Controls.OBC.CDL.Logical.Timer tim(final t=300)
    "Check whether the zone has been unpopulated for 5 minutes continuously during occupied mode"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truHol(
    final falseHoldDuration=0, trueHoldDuration=60)
    "When the zone is unpopulated by more than 5 minute and then becomes populated, hold the change by 1 minute"
  Buildings.Controls.OBC.CDL.Logical.Edge edg1
    "Instant when the zone becomes more than 5 minutes"
  Buildings.Controls.OBC.CDL.Reals.AddParameter heaSetDec(
    final p=-1.1)
    "Heating setpoint decrease due to the 5 minutes unpopulation under occupied mode"
  Buildings.Controls.OBC.CDL.Reals.AddParameter cooSetInc(
    final p=1.1)
    "Heating setpoint increase due to the 5 minutes unpopulation under occupied mode"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler cooSetSam
    "Sample current cooling setpoint when zone becomes unpopulated by 5 minutes"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler heaSetSam
    "Sample current heating setpoint when zone becomes unpopulated by 5 minutes"
  Buildings.Controls.OBC.CDL.Reals.Add add1 "Adjust heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Add add2 "Adjust cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Limiter cooSetLim(
    final uMax=TZonCooOnMax,
    final uMin=TZonCooOnMin)
    "Limit occupied zone cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Limiter heaSetLim(
    final uMax=TZonHeaOnMax,
    final uMin=TZonHeaOnMin)
    "Limit occupied zone heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    final p=-0.56)
    "Cooling setpoint minus 0.56 degC"

protected
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu "Check if current operation mode is warm-up mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu1
    "Check if current operation mode is cool-down mode"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu2 "Check if current operation mode is occupied mode"
  Buildings.Obsolete.Controls.OBC.CDL.Logical.Or3 or3
    "Current operation mode is occupied, warm-up, or cool-down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.warmUp)
    "Warm-up mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt1(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.coolDown)
    "Cool-down mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt2(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "Occupied mode"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant cooSetAdjCon(k=(cooAdj or sinAdj))
    "Cooling setpoint adjustable"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(final k=0) "Zero adjustment"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con3(final k=0) if not (cooAdj or sinAdj)
    "Zero adjustment"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con4(final k=0) if not heaAdj
    "Zero adjustment"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant heaSetAdjCon(final k=heaAdj)
    "Heating setpoint adjustable"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(final k=0) "Zero adjustment"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant sinSetAdjCon(final k=sinAdj)
    "Single common setpoint adjustable"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con2(final k=ignDemLim)
    "Check whether the zone should exempt from setpoint adjustment due to the demand limit"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant conTru(
    final k=true) if not have_occSen
    "Constant true"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant conFal(
    final k=false) if not have_winSen
    "Constant false"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant winSenCon(final k=have_winSen)
    "Check if there is window status sensor"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant have_occSenCon(final k=have_occSen)
    "Check if there is occupancy sensor"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant cooSetWinOpe(final k=TZonCooSetWinOpe)
    "Cooling setpoint when window is open"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant heaSetWinOpe(final k=TZonHeaSetWinOpe)
    "Heating setpoint when window is open"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant alaZer(k=-0.2)
    "Alarm level 0"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant alaFou(k=3.8)
    "Alarm level 4"
  Buildings.Controls.OBC.CDL.Conversions.RealToInteger reaToInt
    "Convert real input to integer output"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea1 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea6 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea2 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea3 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea4 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea5 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea7 "Convert boolean to real value"
  Buildings.Controls.OBC.CDL.Logical.And and11
    "Check if window is open during operation modes other than occupied"
  Buildings.Controls.OBC.CDL.Logical.Not not5  "Other than occupied mode"
  Buildings.Controls.OBC.CDL.Reals.Less les
    "Check if occupied cooling setpoint is less than unoccupied one"
  Buildings.Controls.OBC.CDL.Reals.Greater gre
    "Check if occupied heating setpoint is greater than unoccupied one"
  Buildings.Controls.OBC.CDL.Reals.Greater gre2
    "Check whether heating setpoint exceeds cooling setpoint minus 0.56 degC"
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Switch between occupied and unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Switch between occupied and unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Setpoint can only be adjusted in occupied mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi3
    "Setpoint can only be adjusted in occupied mode"
  Buildings.Controls.OBC.CDL.Reals.Switch swi4
    "If there is no cooling adjustment, zero adjust"
  Buildings.Controls.OBC.CDL.Reals.Switch swi5
    "If there is no heating adjustment, zero adjust"
  Buildings.Controls.OBC.CDL.Reals.Switch swi6
    "If there is only one common adjust for both heating and cooling, use the adjust value from cooling one"
  Buildings.Controls.OBC.CDL.Reals.Switch swi7
    "Ensure heating setpoint being not higher than cooling setpoint minus 0.56 degC"
  Buildings.Controls.OBC.CDL.Reals.Switch swi8
    "Ensure unoccupied heating setppint being lower than occupied one"
  Buildings.Controls.OBC.CDL.Reals.Switch swi9
    "Ensure unoccupied cooling setppint being higher than occupied one"
  Buildings.Controls.OBC.CDL.Reals.Switch swi10
    "Switch between occupied and unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi11
    "Switch between occupied and unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Switch swi12
    "Increase cooling setpoint when the zone is unpopulated by more than 5 minutes"
  Buildings.Controls.OBC.CDL.Reals.Switch swi13
    "Decrease heating setpoint when the zone is unpopulated by more than 5 minutes"
  Buildings.Controls.OBC.CDL.Reals.Switch swi14
    "Switch to TZonCooSetWinOpe when window is open"
  Buildings.Controls.OBC.CDL.Reals.Switch swi15
    "Switch to TZonHeaSetWinOpe when window is open"
  Buildings.Controls.OBC.CDL.Reals.Switch swi16
    "Generate level 4 alarm when window is open during modes other than occupied"
  Buildings.Controls.OBC.CDL.Reals.Switch swi17
    "If it is occupied mode, cooling setpoint should be limited"
  Buildings.Controls.OBC.CDL.Reals.Switch swi18
    "If it is occupied mode, heating setpoint should be limited"
  Buildings.Controls.OBC.CDL.Reals.Switch swi19
    "If there is occupancy sensor, update heating setpoint according to the occupancy"
  Buildings.Controls.OBC.CDL.Reals.Switch swi20
    "If there is occupancy sensor, update cooling setpoint according to the occupancy"
  Buildings.Controls.OBC.CDL.Reals.Switch swi21
    "If there is window status sensor, update heating setpoint according to the window status"
  Buildings.Controls.OBC.CDL.Reals.Switch swi22
    "If there is window status sensor, update cooling setpoint according to the window status"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu7
    "Check if the heating demand limit level is level 2"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt8(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.heating3)
    "Heat demand limit level 3"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu8
    "Check if the heating demand limit level is level 3"
  Buildings.Controls.OBC.CDL.Logical.Not not4 "Logical not"
  Buildings.Controls.OBC.CDL.Logical.And and10
    "Check if the zone becomes unpopulated during occupied mode"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt6(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.heating1)
    "Heat demand limit level 1"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu6
    "Check if the heating demand limit level is level 1"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt7(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.heating2)
    "Heat demand limit level 2"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr
    "Check if cooling demand limit level is higher than level zero"
  Buildings.Controls.OBC.CDL.Integers.GreaterThreshold intGreThr1
    "Check if heating demand limit level is higher than level zero"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt3(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.cooling1)
    "Cool demand limit level 1"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu3
    "Check if the cooling demand limit level is level 1"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt4(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.cooling2)
    "Cool demand limit level 2"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu4
    "Check if the cooling demand limit level is level 2"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant conInt5(
    k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.DemandLimitLevels.cooling3)
    "Cool demand limit level 3"
  Buildings.Controls.OBC.CDL.Integers.Equal intEqu5
    "Check if the cooling demand limit level is level 3"
  Buildings.Controls.OBC.CDL.Reals.Add add3 "Add real inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add4 "Add real inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add5 "Add real inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add6 "Add real inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add7 "Add real inputs"
  Buildings.Controls.OBC.CDL.Reals.Add add8 "Add real inputs"

equation
  connect(uOpeMod, intEqu.u1)
  connect(uOpeMod, intEqu1.u1)
  connect(uOpeMod, intEqu2.u1)
  connect(conInt.y, intEqu.u2)
  connect(conInt1.y, intEqu1.u2)
  connect(conInt2.y, intEqu2.u2)
  connect(intEqu.y, or3.u1)
  connect(intEqu1.y, or3.u2)
  connect(intEqu2.y, or3.u3)
  connect(TZonCooSetOcc, swi.u1)
  connect(TZonCooSetUno, swi.u3)
  connect(TZonHeaSetOcc, swi1.u1)
  connect(TZonHeaSetUno, swi1.u3)
  connect(or3.y, swi.u2)
  connect(or3.y, swi1.u2)
  connect(cooSetAdjCon.y, swi4.u2)
  connect(setAdj, swi4.u1)
  connect(con3.y, swi4.u1)
  connect(con.y, swi4.u3)
  connect(swi4.y, add2.u2)
  connect(swi.y, add2.u1)
  connect(add2.y, swi2.u1)
  connect(swi.y, swi2.u3)
  connect(intEqu2.y, swi2.u2)
  connect(heaSetAdjCon.y, swi5.u2)
  connect(con1.y, swi5.u3)
  connect(swi5.y, swi6.u3)
  connect(sinSetAdjCon.y, swi6.u2)
  connect(swi6.y, add1.u2)
  connect(add1.y, swi3.u1)
  connect(heaSetAdj, swi5.u1)
  connect(con4.y, swi5.u1)
  connect(swi4.y, swi6.u1)
  connect(swi1.y, add1.u1)
  connect(swi1.y, swi3.u3)
  connect(intEqu2.y, swi3.u2)
  connect(uCooDemLimLev, intGreThr.u)
  connect(uHeaDemLimLev, intGreThr1.u)
  connect(intGreThr1.y, or2.u2)
  connect(intGreThr.y, or2.u1)
  connect(or2.y, edg.u)
  connect(intEqu3.y, booToRea.u)
  connect(intEqu4.y, booToRea1.u)
  connect(intEqu5.y, booToRea2.u)
  connect(uCooDemLimLev, intEqu3.u1)
  connect(uCooDemLimLev, intEqu4.u1)
  connect(uCooDemLimLev, intEqu5.u1)
  connect(conInt3.y, intEqu3.u2)
  connect(conInt4.y, intEqu4.u2)
  connect(conInt5.y, intEqu5.u2)
  connect(intEqu3.y, or1.u1)
  connect(intEqu4.y, or1.u2)
  connect(intEqu5.y, or1.u3)
  connect(or1.y, not1.u)
  connect(not1.y, booToRea6.u)
  connect(booToRea.y, pro.u2)
  connect(cooSetFre.y, addPar2.u)
  connect(cooSetFre.y, addPar1.u)
  connect(cooSetFre.y, addPar3.u)
  connect(booToRea1.y, pro1.u2)
  connect(booToRea2.y, pro2.u2)
  connect(addPar2.y, pro.u1)
  connect(cooSetFre.y, pro6.u2)
  connect(booToRea6.y, pro6.u1)
  connect(addPar1.y, pro1.u1)
  connect(addPar3.y, pro2.u1)
  connect(or2.y, not3.u)
  connect(con2.y, or5.u1)
  connect(not3.y, or5.u2)
  connect(uHeaDemLimLev, intEqu6.u1)
  connect(uHeaDemLimLev, intEqu7.u1)
  connect(uHeaDemLimLev, intEqu8.u1)
  connect(conInt6.y, intEqu6.u2)
  connect(conInt7.y, intEqu7.u2)
  connect(conInt8.y, intEqu8.u2)
  connect(intEqu6.y, booToRea3.u)
  connect(intEqu7.y, booToRea4.u)
  connect(intEqu8.y, booToRea5.u)
  connect(intEqu6.y, or4.u1)
  connect(intEqu7.y, or4.u2)
  connect(intEqu8.y, or4.u3)
  connect(or4.y, not2.u)
  connect(not2.y, booToRea7.u)
  connect(booToRea7.y, pro7.u1)
  connect(heaSetFre.y, pro7.u2)
  connect(heaSetFre.y, addPar6.u)
  connect(heaSetFre.y, addPar5.u)
  connect(heaSetFre.y, addPar4.u)
  connect(addPar6.y, pro3.u1)
  connect(addPar5.y, pro4.u1)
  connect(addPar4.y, pro5.u1)
  connect(booToRea3.y, pro3.u2)
  connect(booToRea4.y, pro4.u2)
  connect(booToRea5.y, pro5.u2)
  connect(edg.y, cooSetFre.trigger)
  connect(edg.y, heaSetFre.trigger)
  connect(or5.y, swi10.u2)
  connect(or5.y, swi11.u2)
  connect(swi2.y, cooSetFre.u)
  connect(swi2.y, swi10.u1)
  connect(swi3.y, heaSetFre.u)
  connect(swi3.y, swi11.u1)
  connect(uOccSen, not4.u)
  connect(conTru.y, not4.u)
  connect(and10.y, tim.u)
  connect(truHol.y, edg1.u)
  connect(edg1.y, cooSetSam.trigger)
  connect(edg1.y, heaSetSam.trigger)
  connect(cooSetSam.y, cooSetInc.u)
  connect(heaSetSam.y, heaSetDec.u)
  connect(cooSetInc.y, swi12.u1)
  connect(heaSetDec.y, swi13.u1)
  connect(truHol.y, swi12.u2)
  connect(truHol.y, swi13.u2)
  connect(swi11.y, swi13.u3)
  connect(swi10.y, swi12.u3)
  connect(intEqu2.y, and10.u1)
  connect(not4.y, and10.u2)
  connect(swi11.y, heaSetSam.u)
  connect(swi10.y, cooSetSam.u)
  connect(have_occSenCon.y, swi20.u2)
  connect(have_occSenCon.y, swi19.u2)
  connect(swi12.y, swi20.u1)
  connect(swi13.y, swi19.u1)
  connect(swi10.y, swi20.u3)
  connect(swi11.y, swi19.u3)
  connect(intEqu2.y, not5.u)
  connect(uWinSta, and11.u2)
  connect(not5.y, and11.u1)
  connect(and11.y, swi16.u2)
  connect(alaFou.y, swi16.u1)
  connect(alaZer.y, swi16.u3)
  connect(swi16.y, reaToInt.u)
  connect(uWinSta, swi14.u2)
  connect(uWinSta, swi15.u2)
  connect(cooSetWinOpe.y, swi14.u1)
  connect(heaSetWinOpe.y, swi15.u1)
  connect(winSenCon.y, swi22.u2)
  connect(winSenCon.y, swi21.u2)
  connect(swi19.y, swi15.u3)
  connect(swi19.y, swi21.u3)
  connect(swi20.y, swi14.u3)
  connect(swi20.y, swi22.u3)
  connect(swi14.y, swi22.u1)
  connect(swi15.y, swi21.u1)
  connect(conFal.y, and11.u2)
  connect(conFal.y, swi14.u2)
  connect(conFal.y, swi15.u2)
  connect(swi22.y, cooSetLim.u)
  connect(swi21.y, heaSetLim.u)
  connect(cooSetLim.y, swi17.u1)
  connect(heaSetLim.y, swi18.u1)
  connect(swi22.y, swi17.u3)
  connect(swi21.y, swi18.u3)
  connect(intEqu2.y, swi17.u2)
  connect(intEqu2.y, swi18.u2)
  connect(swi17.y, les.u1)
  connect(les.y, swi9.u2)
  connect(swi18.y, gre.u1)
  connect(gre.y, swi8.u2)
  connect(swi17.y, swi9.u1)
  connect(swi18.y, swi8.u1)
  connect(TZonCooSetUno, les.u2)
  connect(TZonCooSetUno, swi9.u3)
  connect(TZonHeaSetUno, gre.u2)
  connect(TZonHeaSetUno, swi8.u3)
  connect(swi9.y, addPar.u)
  connect(gre2.y, swi7.u2)
  connect(swi8.y, gre2.u1)
  connect(addPar.y, gre2.u2)
  connect(swi8.y, swi7.u3)
  connect(addPar.y, swi7.u1)
  connect(swi7.y, TZonHeaSet)
  connect(swi9.y, TZonCooSet)
  connect(reaToInt.y, yAla)
  connect(pro6.y, add3.u1)
  connect(pro.y, add3.u2)
  connect(pro1.y, add4.u1)
  connect(pro2.y, add4.u2)
  connect(add3.y, add5.u1)
  connect(add4.y, add5.u2)
  connect(add5.y, swi10.u3)
  connect(pro7.y, add6.u1)
  connect(pro3.y, add6.u2)
  connect(pro4.y, add7.u1)
  connect(pro5.y, add7.u2)
  connect(add6.y, add8.u1)
  connect(add7.y, add8.u2)
  connect(add8.y, swi11.u3)
  connect(tim.passed, truHol.u) b. As a default, the active occupied
heating setpoint shall be limited between 18 °C (65 °F) and 22 °C
(72 °F);)</li>
<li>The active heating and cooling setpoint shall be independently adjustable,
respecting the limits and anti-overlap logic described above. If zone thermostat
provides only a single setpoint adjustment, then the adjustment shall move both
the same amount, within the limits described above.</li>
<li>The adjustment shall only affect occupied setpoints in Occupied mode, and
shall have no impact on setpoints in all other modes.</li>
<li>At the onset of demand limiting, the local setpoint adjustment value shall
be frozen. Further adjustment of the setpoint by local controls shall be suspended
for the duration of the demand limit event.</li>
</ul>
<h4>Cooling demand limit setpoint adjustment</h4>
<p>The active cooling setpoints for all zones shall be increased when a demand limit
is imposed on the associated zone group. The operator shall have the ability
to exempt individual zones from this adjustment through the normal
Building Automation System (BAS) user interface. Changes due to demand limits
are not cumulative.</p>
<ul>
<li>At Demand Limit Level 1, increase setpoint by 0.56 °C (1 °F).</li>
<li>At Demand Limit Level 2, increase setpoint by 1.1 °C (2 °F).</li>
<li>At Demand Limit Level 1, increase setpoint by 2.2 °C (4 °F).</li>
</ul>
<h4>Heating demand limit setpoint adjustment</h4>
<p>The active heating setpoints for all zones shall be decreased when a demand limit
is imposed on the associated zone group. The operator shall have the ability
to exempt individual zones from this adjustment through the normal BAS user
interface. Changes due to demand limits are not cumulative.</p>
<ul>
<li>At Demand Limit Level 1, decrease setpoint by 0.56 °C (1 °F).</li>
<li>At Demand Limit Level 2, decrease setpoint by 1.1 °C (2 °F).</li>
<li>At Demand Limit Level 1, decrease setpoint by 2.2 °C (4 °F).</li>
</ul>
<h4>Window switches</h4>
<p>For zones that have operable windows with indicator switches, when the window
switch indicates the window is open, the heating setpoint shall be temporarily
set to 4.4 °C (40 °F) and the cooling setpoint shall be temporarily
set to 49 °C (120 °F). When the window switch indicates the window is
open during other than Occupied Mode, a Level 4 alarm shall be generated.</p>
<h4>h. Occupancy sensor</h4>
<ul>
<li>When the switch indicates the space has been unpopulated for 5 minutes
continuously during the Occupied Mode, the active heating setpoint shall be
decreased by 1.1 °C (2 °F) and the cooling setpoint shall be increased
by 1.1 °C (2 °F).</li>
<li>When the switch indicated that the space has been populated for 1 minute
continuously, the active heating and cooling setpoints shall be restored to
their previously values.</li>
</ul>
<p>Hierarchy of setpoint adjustments: the following adjustment restrictions
shall prevail in order from highest to lowest priority.</p>
<ul>
<li>Setpoint overlap restriction</li>
<li>Absolute limits on local setpoint adjustment</li>
<li>Window swtiches</li>
<li>Demand limit (a. Occupancy sensors; b. Local setpoint adjustment)</li>
<li>Scheduled setpoints based on zone group mode</li>
</ul>

</html>", revisions="<html>
<ul>
<li>
October 11, 2017, by Michael Wetter:<br/>
Removed wrong conditional on <code>yAla</code>.
</li>
<li>
August 17, 2017, by Jianjun Hu:<br/>
First implementation.
</li>
</ul>
</html>"));
end ZoneTemperatures;


Collection of validation models

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.SetPoints;
package Validation "Collection of validation models"
end Validation;


Validate block for zone set point. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.SetPoints.ZoneTemperatures
for a change of zone setpoint temperature.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.SetPoints.Validation;
model ZoneTemperatures "Validate block for zone set point"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.SetPoints.ZoneTemperatures
    TZonSet(
    final have_occSen=true,
    final sinAdj=false,
    final cooAdj=true,
    final have_winSen=true,
    final heaAdj=true) "Block that determines the thermal zone setpoints"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSetOcc(
    final k=297.15)
    "Occupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSetOcc(
    final k=293.15)
    "Occupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonCooSetUno(
    final k=303.15)
    "Unoccupied cooling setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TZonHeaSetUno(
    final k=287.15)
    "Unoccupied heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin cooSetAdj(
    final freqHz=1/28800)
    "Cooling setpoint adjustment"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin heaSetAdj(
    final freqHz=1/28800,
    final amplitude=0.5)
    "Heating setpoint adjustment"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant cooDemLimLev(
    final k=0)
    "Cooling demand limit level"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant heaDemLimLev(
    final k=0)
    "Heating demand limit level"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    final duration=28800)
    "Generate ramp output"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=0.75)
    "Check if input is greater than 0.75"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt(
    final integerTrue=1,
    final integerFalse=7)
    "Convert boolean input to integer output"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(
    final period=14400,
    final shift=1200)
    "Generate signal indicating window status"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse occSta(
    final period=14400,
    final width=0.95)
    "Generate signal indicating occupancy status"
  Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zerAdj(
    final k=0)
    "Zero adjustment"
  Buildings.Controls.OBC.CDL.Reals.Switch swi1
    "Switch to zero adjustment when window is open"
  Buildings.Controls.OBC.CDL.Reals.Switch swi2
    "Switch to zero adjustment when window is open"

equation
  connect(ram.y, greThr.u)
  connect(greThr.y, not1.u)
  connect(not1.y, booToInt.u)
  connect(TZonCooSetOcc.y, TZonSet.TZonCooSetOcc)
  connect(TZonHeaSetOcc.y, TZonSet.TZonHeaSetOcc)
  connect(TZonCooSetUno.y, TZonSet.TZonCooSetUno)
  connect(TZonHeaSetUno.y, TZonSet.TZonHeaSetUno)
  connect(cooDemLimLev.y, TZonSet.uCooDemLimLev)
  connect(heaDemLimLev.y, TZonSet.uHeaDemLimLev)
  connect(booToInt.y, TZonSet.uOpeMod)
  connect(winSta.y, swi2.u2)
  connect(winSta.y, swi1.u2)
  connect(zerAdj.y, swi2.u1)
  connect(zerAdj.y, swi1.u1)
  connect(cooSetAdj.y, swi2.u3)
  connect(heaSetAdj.y, swi1.u3)
  connect(swi2.y, TZonSet.setAdj)
  connect(swi1.y, TZonSet.heaSetAdj)
  connect(occSta.y, TZonSet.uOccSen)
  connect(winSta.y, TZonSet.uWinSta)
end ZoneTemperatures;


Validate model for controlling VAV terminal box with reheat. This example validates

Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Controller.

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Validation;
model Controller "Validate model for controlling VAV terminal box with reheat"

  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Controller con(
    AFlo=50,
    samplePeriod=120,
    V_flow_nominal=(50*3/3600)*6)
    "Controller for VAV terminal unit with reheat"
  Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.TerminalUnits.Controller con1(
    AFlo=50,
    samplePeriod=120,
    V_flow_nominal=(50*3/3600)*6,
    have_occSen=true,
    have_winSen=true,
    have_CO2Sen=true) "Controller for VAV terminal unit with reheat"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSetRooCoo(k=273.15 + 24)
    "Room cooling setpoint "
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp disAirFlo(
    offset=0.02,
    height=0.0168,
    duration=3600) "Discharge airflow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TZon(
    height=6,
    offset=273.15 + 17,
    duration=3600) "Measured room temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TDis(
    height=4,
    duration=3600,
    offset=273.15 + 18) "Terminal unit discharge air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TSup(
    height=4,
    duration=3600,
    offset=273.15 + 14) "AHU supply air temperature"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant opeMod(
    final k=Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types.OperationModes.occupied)
    "AHU operation mode is Occupied"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSetRooHea(k=273.15 + 20)
    "Room heating setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ppmCO2(
    duration=3600,
    height=800,
    offset=200) "CO2 concentration"
  Buildings.Controls.OBC.CDL.Logical.Sources.Pulse winSta(period=3600)
    "WIndow status"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp nOcc(
    height=5,
    duration=4800,
    offset=0) "Number of occupants"
  Buildings.Controls.OBC.CDL.Reals.Round rou(n=0) "Round the input"
  Buildings.Controls.OBC.CDL.Discrete.ZeroOrderHold zerOrdHol(
    final samplePeriod=2) "Mimic damper position"
  Buildings.Controls.OBC.CDL.Discrete.ZeroOrderHold zerOrdHol1(
    final samplePeriod=2) "Mimic damper position"

equation
  connect(TSetRooHea.y,con.TZonHeaSet)
  connect(TSetRooCoo.y, con.TZonCooSet)
  connect(disAirFlo.y, con.VDis_flow)
  connect(TZon.y, con.TZon)
  connect(TDis.y, con.TDis)
  connect(TSup.y, con.TSupAHU)
  connect(opeMod.y, con.uOpeMod)
  connect(nOcc.y, rou.u)
  connect(rou.y, con1.nOcc)
  connect(ppmCO2.y, con1.ppmCO2)
  connect(winSta.y, con1.uWin)
  connect(TSetRooHea.y,con1.TZonHeaSet)
  connect(TSetRooCoo.y, con1.TZonCooSet)
  connect(disAirFlo.y, con1.VDis_flow)
  connect(TZon.y, con1.TZon)
  connect(TDis.y, con1.TDis)
  connect(TSup.y, con1.TSupAHU)
  connect(opeMod.y, con1.uOpeMod)
  connect(con.yDam, zerOrdHol.u)
  connect(con1.yDam, zerOrdHol1.u)
  connect(zerOrdHol.y,con.yDam_actual)
  connect(zerOrdHol1.y,con1.yDam_actual)
end Controller;


Collection of validation models

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


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1;
package Types "Package with type definitions for control sequences"
end Types;


Demand limit levels

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types;
package DemandLimitLevels "Demand limit levels"
  constant Integer cooling0 = 0 "Cooling demand limit level 0";
  constant Integer cooling1 = 1 "Cooling demand limit level 1";
  constant Integer cooling2 = 2 "Cooling demand limit level 2";
  constant Integer cooling3 = 3 "Cooling demand limit level 3";
  constant Integer heating0 = 0 "Heating demand limit level 0";
  constant Integer heating1 = 1 "Heating demand limit level 1";
  constant Integer heating2 = 2 "Heating demand limit level 2";
  constant Integer heating3 = 3 "Heating demand limit level 3";
end DemandLimitLevels;


within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types;
package FreezeProtectionStages "Package with constants that indicate the freeze protection stages"
  constant Integer stage0 = 0 "Freeze protection is deactivated";
  constant Integer stage1 = 1 "First stage of freeze protection";
  constant Integer stage2 = 2 "Second stage of freeze protection";
  constant Integer stage3 = 3 "Third stage of freeze protection";
end FreezeProtectionStages;


Zone group operating modes

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types;
package OperationModes "Zone group operating modes"
  constant Integer coolDown = 2 "Cool-down";
  constant Integer freezeProtection = 6 "Freeze protection";
  constant Integer occupied = 1 "Occupied";
  constant Integer setBack = 5 "Set-back";
  constant Integer setUp =  3 "Set-up";
  constant Integer unoccupied = 7 "Unoccupied";
  constant Integer warmUp =  4 "Warm-up";
end OperationModes;


AHU Zone States

within Buildings.Obsolete.Controls.OBC.ASHRAE.G36_PR1.Types;
package ZoneStates "AHU Zone States"
  constant Integer cooling = 3 "Output of the space cooling control loop is nonzero";
  constant Integer deadband = 2 "When not in either heating or cooling";
  constant Integer heating = 1 "Output of the space heating control loop is nonzero";
end ZoneStates;


within Buildings.Obsolete.Controls.OBC;
package CDL "Package with obsolete blocks for control description language"
end CDL;


Output the sum of the two inputs. Block that outputs y as the weighted sum of the
two input signals u1 and u2,

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block Add "Output the sum of the two inputs"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real k1=+1
    "Gain for input u1";
  parameter Real k2=+1
    "Gain for input u2";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u1
    "Connector of Real input signal 1"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u2
    "Connector of Real input signal 2"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Connector of Real output signal"

equation
  y=k1*u1+k2*u2;
end Add;


Output the sum of an input plus a parameter. Block that outputs y = k u + p,
where k and p are
parameters and u is an input.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block AddParameter "Output the sum of an input plus a parameter"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real p
    "Value to be added";
  parameter Real k
    "Gain of input";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u
    "Connector of Real input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Connector of Real output signal"

equation
  y=k*u+p;
end AddParameter;


Change sign of the input. Block that outputs y = -u,
where u is an input.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block ChangeSign "Change sign of the input"
  extends Modelica.Icons.ObsoleteModel;

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"

equation
  y = -u;
end ChangeSign;


Block that approximates the derivative of the input. This blocks defines the transfer function between the
input u and the output y
as approximated derivative:

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block Derivative "Block that approximates the derivative of the input"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real k(unit="1") = 1 "Gains";
  parameter Modelica.Units.SI.Time T(min=1E-60) = 0.01
    "Time constant (T>0 required)";
  parameter Real x_start=0 "Initial or guess value of state"
  parameter Real y_start=0 "Initial value of output (= state)"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y "Connector of Real output signal"

  output Real x "State of block";

protected
  parameter Boolean zeroGain = abs(k) < 1E-17
    "= true, if gain equals to zero";
initial equation
  if zeroGain then
     x = u;
  else
     x = u - T*y_start/k;
  end if;

equation
  der(x) = if zeroGain then 0 else (u - x)/T;
  y = if zeroGain then 0 else (k/T)*(u - x);
end Derivative;


Output difference between commanded and feedback input. Block that outputs y = u1 - u2,
where
u1 and u2 are inputs.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block Feedback
  "Output difference between commanded and feedback input"
  extends Modelica.Icons.ObsoleteModel;

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u1
    "Connector of Real input signal 1"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u2
    "Connector of Real input signal 2"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Connector of Real output signal"

equation
  y=u1-u2;
end Feedback;


Output y is true, if input u1 is greater or equal than input u2. Block that outputs true if Real the input u1
is greater than or equal to the Real input u2.
Otherwise the output is false.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block GreaterEqual
  "Output y is true, if input u1 is greater or equal than input u2"
  extends Modelica.Icons.ObsoleteModel;

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u1 "Connector of first Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u2 "Connector of second Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Connector of Boolean output signal"

equation
  y = u1 >= u2;
end GreaterEqual;


Output y is true, if input u is greater or equal than threshold. Block that outputs true if the Real input is greater than or equal to
the parameter threshold.
Otherwise the output is false.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block GreaterEqualThreshold
  "Output y is true, if input u is greater or equal than threshold"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real threshold=0 "Threshold for comparison";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Connector of Boolean output signal"

equation
  y = u >= threshold;
end GreaterEqualThreshold;


Hysteresis block that optionally allows to specify a hold time. Model for a hysteresis block that optionally allows to specify a hold time.
During the hold time, the output is not allowed to switch.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block HysteresisWithHold
  "Hysteresis block that optionally allows to specify a hold time"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real uLow "if y=true and u<uLow, switch to y=false";
  parameter Real uHigh "if y=false and u>uHigh, switch to y=true";

  parameter Modelica.Units.SI.Time trueHoldDuration "true hold duration";

  parameter Modelica.Units.SI.Time falseHoldDuration=trueHoldDuration
    "false hold duration";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Boolean output signal"

protected
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hysteresis(
    final uLow=uLow,
    final uHigh=uHigh)
    "Transform Real to Boolean signal with Hysteresis"

  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol(
    final trueHoldDuration=trueHoldDuration,
    final falseHoldDuration=falseHoldDuration) "True/false hold"

equation
  connect(u, hysteresis.u)

  connect(hysteresis.y, truFalHol.u)
  connect(truFalHol.y, y)
end HysteresisWithHold;


Output y is true, if input u1 is less or equal than input u2. Block that outputs true if the Real input u1
is less than or equal to the Real input u2.
Otherwise the output is false.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block LessEqual
  "Output y is true, if input u1 is less or equal than input u2"
  extends Modelica.Icons.ObsoleteModel;

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u1 "Connector of first Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u2 "Connector of second Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Connector of Boolean output signal"

equation
  y = u1 <= u2;
end LessEqual;


Output y is true, if input u is less or equal than threshold. Block that outputs true if the Real input is less than or equal to
the parameter threshold.
Otherwise the output is false.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block LessEqualThreshold
  "Output y is true, if input u is less or equal than threshold"
  extends Modelica.Icons.ObsoleteModel;

  parameter Real threshold=0 "Threshold for comparison";

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Connector of Real input signal"

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Connector of Boolean output signal"

equation
  y = u <= threshold;
end LessEqualThreshold;


P, PI, PD, and PID controller with limited output, anti-windup compensation and setpoint weighting. PID controller in the standard form

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block LimPID
  "P, PI, PD, and PID controller with limited output, anti-windup compensation and setpoint weighting"
  extends Modelica.Icons.ObsoleteModel;

  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=
         Buildings.Controls.OBC.CDL.Types.SimpleController.PI "Type of controller";
  parameter Real k(
    min=0) = 1 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Buildings.Controls.OBC.CDL.Constants.small)=
       0.5 "Time constant of integrator block"
  parameter Modelica.Units.SI.Time Td(min=0) = 0.1
    "Time constant of derivative block"
  parameter Real yMax = 1 "Upper limit of output";
  parameter Real yMin = 0 "Lower limit of output";
  parameter Real wp(min=0) = 1 "Set-point weight for Proportional block (0..1)";
  parameter Real wd(min=0) = 0 "Set-point weight for Derivative block (0..1)"
  parameter Real Ni(min=100*Buildings.Controls.OBC.CDL.Constants.eps) = 0.9
    "Ni*Ti is time constant of anti-windup compensation"
  parameter Real Nd(min=100*Buildings.Controls.OBC.CDL.Constants.eps) = 10
    "The higher Nd, the more ideal the derivative block"

  parameter Real xi_start=0
    "Initial value of integrator state"
  parameter Real yd_start=0 "Initial value of derivative output"
  parameter Boolean reverseActing = true
    "Set to true for reverse acting, or false for direct acting control action";
  parameter Buildings.Obsolete.Controls.OBC.CDL.Types.Reset reset = Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
    "Type of controller output reset"
  parameter Real y_reset=xi_start
    "Value to which the controller output is reset if the boolean trigger has a rising edge, used if reset == CDL.Types.Reset.Parameter"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s
    "Connector of setpoint input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u_m
    "Connector of measurement input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Connector of actuator output signal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput y_reset_in
    if reset == Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Input
    "Input signal for state to which integrator is reset, enabled if reset = CDL.Types.Reset.Input"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger
    if reset <> Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
    "Resets the controller output when trigger becomes true"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback controlError
    "Control error (set point - measurement)"

  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset I(
    final k=1/Ti,
    final y_start=xi_start) if with_I "Integral term"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Derivative D(
    final k=Td,
    final T=Td/Nd,
    final y_start=yd_start)
   if with_D "Derivative term"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback errP "P error"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback errD if with_D "D error"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback errI1 if with_I
    "I error (before anti-windup compensation)"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback errI2 if with_I
    "I error (after anti-windup compensation)"

  Buildings.Controls.OBC.CDL.Reals.Limiter lim(
    final uMax=yMax,
    final uMin=yMin)
    "Limiter"
protected
  final parameter Real revAct = if reverseActing then 1 else -1
    "Switch for sign for reverse or direct acting controller";
  final parameter Boolean with_I = controllerType==Buildings.Controls.OBC.CDL.Types.SimpleController.PI or
                                   controllerType==Buildings.Controls.OBC.CDL.Types.SimpleController.PID
    "Boolean flag to enable integral action"
  final parameter Boolean with_D = controllerType==Buildings.Controls.OBC.CDL.Types.SimpleController.PD or
                                   controllerType==Buildings.Controls.OBC.CDL.Types.SimpleController.PID
    "Boolean flag to enable derivative action"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant Dzero(
    final k=0) if not with_D
    "Zero input signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant Izero(
    final k=0) if not with_I
    "Zero input signal"

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uS_revAct(final k=
        revAct) "Set point multiplied by reverse action sign"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uSetWp(final k=wp)
    "Set point multiplied by weight for proportional gain"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uMea_revAct(final k=
       revAct) "Set point multiplied by reverse action sign"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uSetWd(final k=wd)
    if with_D "Set point multiplied by weight for derivative gain"

  Buildings.Controls.OBC.CDL.Reals.Add addPD
    "Outputs P and D gains added"

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gainPID(final k=k)
    "Multiplier for control gain"

  Buildings.Controls.OBC.CDL.Reals.Add addPID
    "Outputs P, I and D gains added"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback antWinErr
    if with_I "Error for anti-windup compensation"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter antWinGai(k=1/(k*Ni))
    if with_I "Gain for anti-windup compensation"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yResSig(final k=y_reset)
   if reset == Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Parameter
    "Signal for y_reset"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter divK(final k=1/k)
    if reset <> Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
    "Division by k for integrator reset"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback addRes
   if reset <> Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
   "Adder for integrator reset"

  Buildings.Controls.OBC.CDL.Logical.Sources.Constant cheYMinMax(
    final k=yMin < yMax) "Check for values of yMin and yMax"

  Buildings.Controls.OBC.CDL.Utilities.Assert assMesYMinMax(
    message="LimPID: Limits must be yMin < yMax")
    "Assertion on yMin and yMax"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant noTri(final k=false)
    if reset == Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
    "No trigger when reset is disabled"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zer(final k=0)
 if reset == Buildings.Obsolete.Controls.OBC.CDL.Types.Reset.Disabled
    "Reset input to integrator when the reset is disabled"

equation
  connect(trigger, I.trigger)
  connect(u_s, uS_revAct.u)
  connect(uS_revAct.y, uSetWp.u)
  connect(u_m, uMea_revAct.u)
  connect(uS_revAct.y, uSetWd.u)
  connect(uSetWp.y, errP.u1)
  connect(errP.u2, uMea_revAct.y)
  connect(errD.u1, uSetWd.y)
  connect(errD.u2, uMea_revAct.y)
  connect(D.u,errD. y)
  connect(errI1.u1, uS_revAct.y)
  connect(errI1.u2, uMea_revAct.y)
  connect(addPD.u1, errP.y)
  connect(addPID.u1,addPD. y)
  connect(addPID.y, gainPID.u)
  connect(lim.u, gainPID.y)
  connect(lim.y, y)
  connect(antWinErr.y, antWinGai.u)
  connect(addPD.u2, Dzero.y)
  connect(D.y, addPD.u2)
  connect(addPID.u2, Izero.y)
  connect(addPID.u2, I.y)
  connect(divK.y, addRes.u1)
  connect(addRes.u2, addPD.y)
  connect(addRes.y, I.y_reset_in)
  connect(divK.u, yResSig.y)
  connect(divK.u, y_reset_in)
  connect(antWinErr.u1, gainPID.y)
  connect(antWinErr.u2, lim.y)
  connect(I.u, errI2.y)
  connect(errI1.y, errI2.u1)
  connect(errI2.u2,antWinGai. y)
  connect(controlError.u1, u_s)
  connect(controlError.u2, u_m)
  connect(cheYMinMax.y, assMesYMinMax.u)
  connect(noTri.y, I.trigger)
  connect(zer.y, I.y_reset_in)
end LimPID;


Outputs the number of signals that are above/below a certain threshold. Block that outputs the number of inputs that exceed a threshold.
The parameter kind is used to determine the kind of the
inequality. The table below shows the allowed settings.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous;
block NumberOfRequests
  "Outputs the number of signals that are above/below a certain threshold"
  extends Modelica.Icons.ObsoleteModel;

  parameter Integer nin "Number of inputs";
  parameter Real t=0 "Threshold";
  parameter Integer kind
    "Set to 0 for u>threShold, to 1 for >=, to 2 for <= or to 3 for <";
  Buildings.Controls.OBC.CDL.Interfaces.IntegerOutput y
    "Number of input signals that violate the threshold"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u[nin] "Input signals"
algorithm
  y := 0;
  for i in 1:nin loop
    if kind == 0 then
      if u[i] > t then
        y := y+1;
      end if;
    end if;
    if kind == 1 then
      if u[i] >= t then
        y := y+1;
      end if;
    end if;
    if kind == 2 then
      if u[i] <= t then
        y := y+1;
      end if;
    end if;
    if kind == 3 then
      if u[i] < t then
        y := y+1;
      end if;
    end if;
  end for;
end NumberOfRequests;


within Buildings.Obsolete.Controls.OBC.CDL;
package Continuous "Package with obsolete models of the Control Description Language"
  extends Modelica.Icons.Package;
end Continuous;


Validation model for the add block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.Add.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model Add
  "Validation model for the add block"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Add add1
    "Block that outputs the sum of the two inputs"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    height=2,
    duration=1,
    offset=-1)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,add1.u1)
  connect(ramp2.y,add1.u2)
end Add;


Validation model for the AddParameter block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.AddParameter.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model AddParameter "Validation model for the AddParameter block"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.AddParameter addPar(
    p=0.5,
    k=1.0)
    "Block that outputs the sum of an input plus a parameter"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,addPar.u)
end AddParameter;


Validation model for the ChangeSign block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.ChangeSign.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model ChangeSign "Validation model for the ChangeSign block"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.ChangeSign changSign
    "Block that change sign of the input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-1.5,
    height=3.0) "Block that generates ramp signal"
equation
  connect(ramp1.y, changSign.u)
end ChangeSign;


Validation model for the Derivative block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.Derivative.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model Derivative "Validation model for the Derivative block"
  Buildings.Controls.OBC.CDL.Reals.Cos cos1
    "Block that outputs the cosine of the input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=5,
    offset=0,
    height=6.283*5) "Block that generates ramp signal"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Derivative der1(
    y_start=-10) "Approximate the derivative of the input"

equation
  connect(ramp1.y, cos1.u)
  connect(cos1.y, der1.u)
end Derivative;


Validation model for the Feedback block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model Feedback "Validation model for the Feedback block"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.Feedback feedback1
    "Block that outputs difference between commanded and feedback input"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-1,
    height=4)
    "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    height=2,
    duration=1,
    offset=-1)
    "Block that generates ramp signal"

equation
  connect(ramp1.y,feedback1.u1)
  connect(ramp2.y,feedback1.u2)
end Feedback;


Validation model for the GreaterEqual block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.GreaterEqual.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model GreaterEqual "Validation model for the GreaterEqual block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)  "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=2) "Block that generates ramp signal"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.GreaterEqual greEqu
    "Check if the first input is greater than or equal to the second input"

equation
  connect(ramp1.y, greEqu.u1)
  connect(ramp2.y, greEqu.u2)
end GreaterEqual;


Validation model for the GreaterEqualThreshold block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.GreaterEqualThreshold.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model GreaterEqualThreshold  "Validation model for the GreaterEqualThreshold block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=2) "Block that generates ramp signal"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.GreaterEqualThreshold greEquThr
    "Check if the input is greater than or equal to the threshold"

equation
  connect(ramp2.y, greEquThr.u)
end GreaterEqualThreshold;


Validation model for the HysteresisWithHold block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.HysteresisWithHold.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model HysteresisWithHold "Validation model for the HysteresisWithHold block"
  Modelica.Blocks.Sources.Sine pulse1(amplitude=0.2, f=1/360)
    "Generate sine wave signal"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.HysteresisWithHold noHold(
    trueHoldDuration =  0,
    falseHoldDuration = 0,
    uLow =      0.05,
    uHigh =     0.15) "No true/false hold"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.HysteresisWithHold onHold_30s(
    trueHoldDuration =  30,
    falseHoldDuration = 30,
    uLow =      0.05,
    uHigh =     0.15)
    "On/off signal are hold for short period"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.HysteresisWithHold offHold_300s(
    trueHoldDuration =  30,
    falseHoldDuration = 300,
    uLow =      0.05,
    uHigh =     0.15)
    "Off signal being hold even when it should be on"
  Buildings.Obsolete.Controls.OBC.CDL.Continuous.HysteresisWithHold onHold_150s(
    trueHoldDuration =  150,
    falseHoldDuration = 30,
    uLow =      0.05,
    uHigh =     0.15)
    "On signal being hold even when it should be off."

equation
  connect(pulse1.y, onHold_150s.u)
  connect(pulse1.y, noHold.u)
  connect(pulse1.y, offHold_300s.u)
  connect(pulse1.y, onHold_30s.u)
end HysteresisWithHold;


Validation model for the LessEqual block. Validation test for the block

Buildings.Obsolete.Controls.OBC.CDL.Continuous.LessEqual.

within Buildings.Obsolete.Controls.OBC.CDL.Continuous.Validation;
model LessEqual "Validation model for the LessEqual block"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp1(
    duration=1,
    offset=-2,
    height=4)  "Block that generates ramp signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ramp2(
    duration=1,
    offset=-1,
    height=2) "Block that generates ramp signal"

  Buildings.Obsolete.Controls.OBC.CDL.Continuous.LessEqual lesEqu
    "Check if the first input is less than or equal to the second input"

equation
  connect(ramp1.y, lesEqu.u1)
  connect(ramp2.y, lesEqu.u2)
end LessEqual;