Controller for mixed and injection circuits . Simple controller for admix and injection circuit. The controlled
  variable is the outflow temperature T_fwrd_out and controlled by a
  PID controller. The pump is always on and has a constant frequency.

within AixLib.Systems.HydraulicModules.Controller;
block CtrMix "Controller for mixed and injection circuits "
  //Boolean choice;

  parameter Boolean useExternalTset = false "If True, set temperature can be given externally";
  parameter Modelica.Units.SI.Temperature TflowSet=289.15
    "Flow temperature set point of consumer";
  parameter Real k(min=0, unit="1") = 0.025 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 130
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump(min=0) = 2000
    "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if heating system, and false for cooling system";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Interfaces.RealInput Tset if useExternalTset
    "Connector of second Real input signal"
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    final reverseActing=reverseAction)
  Modelica.Blocks.Sources.Constant constRpmPump(final k=rpm_pump)

  Modelica.Blocks.Sources.Constant constTflowSet(final k=TflowSet) if not useExternalTset
  Modelica.Blocks.Sources.BooleanConstant booleanConstant
equation

public
  BaseClasses.HydraulicBus  hydraulicBus
equation
    connect(PID.u_s, Tset)
    connect(constTflowSet.y, PID.u_s)

  connect(PID.y, hydraulicBus.valveSet)
  connect(PID.u_m, hydraulicBus.TFwrdOutMea)
  connect(constRpmPump.y, hydraulicBus.pumpBus.rpmSet)
  connect(booleanConstant.y, hydraulicBus.pumpBus.onSet)
end CtrMix;


controller for pump circuit. Simple controller for unmixed circuit. Only the pump frequency has to
  be set. The pump is always on.

within AixLib.Systems.HydraulicModules.Controller;
block CtrPump "controller for pump circuit"
  //Boolean choice;

  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump(min=0) = 2000
    "Rpm of the Pump";

  Modelica.Blocks.Sources.Constant constRpmPump(final k=rpm_pump)
  Modelica.Blocks.Sources.BooleanConstant booleanConstant
  BaseClasses.HydraulicBus hydraulicBus
equation
  connect(constRpmPump.y, hydraulicBus.pumpBus.rpmSet)
  connect(booleanConstant.y, hydraulicBus.pumpBus.onSet)
end CtrPump;


Volume Flow Set Point Controller for variable Speed pumps. Simple controller for Throttle and ThrottlePump circuit that is based
  on a PID controller. The controlled variable needs to be connected to
  vFlowAct.

within AixLib.Systems.HydraulicModules.Controller;
block CtrPumpVFlow
  "Volume Flow Set Point Controller for variable Speed pumps"
         Modelica.Blocks.Interfaces.RealInput vFlowAct
    "Connector of measurement input signal"
  Modelica.Blocks.Interfaces.RealInput vFlowSet
                                            if useExternalVset
    "Connector of second Real input signal"
public
  BaseClasses.HydraulicBus  hydraulicBus
          parameter Boolean useExternalVset = false "If True, set Volume Flow can be given externally";
  parameter Modelica.Units.SI.VolumeFlowRate vFlowSetCon=0.01
    "Volume Flow in m³/s set point of consumer";
  parameter Real k(min=0, unit="1") = 100 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 30
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump_max(min=0) = 2000
    "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if heating system, and false for cooling system";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Sources.Constant constVflowSet(final k=vFlowSetCon) if not useExternalVset
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=rpm_pump_max,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    final reverseActing=reverseAction)

  Modelica.Blocks.Logical.GreaterThreshold
                                        pumpSwitchOff(final threshold=0)
  Modelica.Blocks.Sources.Constant constValvSet(final k=1)         if not useExternalVset
equation

    connect(PID.u_s,vFlowSet)
    connect(constVflowSet.y, PID.u_s)

  connect(PID.u_m,vFlowAct)
  connect(PID.y,pumpSwitchOff. u)
  connect(pumpSwitchOff.y, hydraulicBus.pumpBus.onSet)
  connect(PID.y, hydraulicBus.pumpBus.rpmSet)
  connect(constValvSet.y, hydraulicBus.valveSet)
end CtrPumpVFlow;


Controller for unmixed circuit with valve. Simple controller for Throttle and ThrottlePump circuit that is based
  on a PID controller. The controlled variable needs to be connected to
  Tact.

within AixLib.Systems.HydraulicModules.Controller;
block CtrThrottle "Controller for unmixed circuit with valve"
  //Boolean choice;

  parameter Boolean useExternalTset = false "If True, set temperature can be given externally";
  parameter Modelica.Units.SI.Temperature TflowSet=289.15
    "Flow temperature set point of consumer";
  parameter Real k(min=0, unit="1") = 0.025 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 130
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump(min=0) = 2000
    "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if heating system, and false for cooling system";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Interfaces.RealInput Tact
                "Connector of measurement input signal"
  Modelica.Blocks.Interfaces.RealInput Tset if useExternalTset
    "Connector of second Real input signal"
  Modelica.Blocks.Sources.Constant constTflowSet(final k=TflowSet) if not useExternalTset
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    reverseActing=reverseAction)
  Modelica.Blocks.Sources.Constant constRpmPump(final k=rpm_pump)

  Modelica.Blocks.Logical.GreaterThreshold
                                        pumpSwitchOff(final threshold=0)
equation

public
  BaseClasses.HydraulicBus  hydraulicBus
equation
    connect(PID.u_s, Tset)
    connect(constTflowSet.y, PID.u_s)

  connect(PID.y, hydraulicBus.valveSet)
  connect(PID.u_m, Tact)
  connect(PID.y,pumpSwitchOff. u)
  connect(constRpmPump.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpSwitchOff.y, hydraulicBus.pumpBus.onSet)
end CtrThrottle;


Volume Flow Set Point Controller for Throttles. Simple controller for Throttle and ThrottlePump circuit that is based
  on a PID controller. The controlled variable needs to be connected to
  QFlowAct. The set point can be passed externally or as parameter.

within AixLib.Systems.HydraulicModules.Controller;
block CtrThrottleQFlow
  "Volume Flow Set Point Controller for Throttles"
         Modelica.Blocks.Interfaces.RealInput Q_flowMea
    "Connector of measurement input signal"
  Modelica.Blocks.Interfaces.RealInput Q_flowSet
                                            if useExternalQset
    "Connector of second Real input signal"
  BaseClasses.HydraulicBus  hydraulicBus

  parameter Boolean useExternalQset = false "If True, set Volume Flow can be given externally";
  parameter Modelica.Units.SI.Power Q_flowSetCon=0
    "Power set point of consumer in W";
  parameter Real k(min=0, unit="1") = 0.025 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 130
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump(min=0) = 2000
    "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if heating system, and false for cooling system";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Sources.Constant constQ_flowSet(final k=Q_flowSetCon)
                                                                      if not useExternalQset
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    final reverseActing=reverseAction)

  Modelica.Blocks.Logical.GreaterThreshold
                                        pumpSwitchOff(final threshold=0)
  Modelica.Blocks.Sources.Constant constPumpSet(final k=rpm_pump)
equation

  connect(PID.u_s, Q_flowSet)
  connect(constQ_flowSet.y, PID.u_s)

  connect(PID.u_m, Q_flowMea)
  connect(PID.y,pumpSwitchOff. u)
  connect(pumpSwitchOff.y, hydraulicBus.pumpBus.onSet)
  connect(constPumpSet.y, hydraulicBus.pumpBus.rpmSet)
  connect(PID.y, hydraulicBus.valveSet)
end CtrThrottleQFlow;


Volume Flow Set Point Controller for Throttles. Simple controller for Throttle and ThrottlePump circuit that is based
  on a PID controller. The controlled variable needs to be connected to
  vFlowAct.

within AixLib.Systems.HydraulicModules.Controller;
block CtrThrottleVFlow
  "Volume Flow Set Point Controller for Throttles"
         Modelica.Blocks.Interfaces.RealInput vFlowAct
    "Connector of measurement input signal"
  Modelica.Blocks.Interfaces.RealInput vFlowSet
                                            if useExternalVset
    "Connector of second Real input signal"
public
  BaseClasses.HydraulicBus  hydraulicBus
          parameter Boolean useExternalVset = false "If True, set Volume Flow can be given externally";
  parameter Modelica.Units.SI.VolumeFlowRate vFlowSetCon=0.01
    "Volume Flow in m³/s set point of consumer";
  parameter Real k(min=0, unit="1") = 0.025 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 130
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Modelica.Units.NonSI.AngularVelocity_rpm rpm_pump(min=0) = 2000
    "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if heating system, and false for cooling system";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Sources.Constant constVflowSet(final k=vFlowSetCon) if not useExternalVset
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    final reverseActing=reverseAction)

  Modelica.Blocks.Logical.GreaterThreshold
                                        pumpSwitchOff(final threshold=0)
  Modelica.Blocks.Sources.Constant constPumpSet(final k=rpm_pump)  if not useExternalVset
equation

    connect(PID.u_s,vFlowSet)
    connect(constVflowSet.y, PID.u_s)

  connect(PID.u_m,vFlowAct)
  connect(PID.y,pumpSwitchOff. u)
  connect(pumpSwitchOff.y, hydraulicBus.pumpBus.onSet)
  connect(constPumpSet.y, hydraulicBus.pumpBus.rpmSet)
  connect(PID.y, hydraulicBus.valveSet)
end CtrThrottleVFlow;


Controller for hydraulic circuits

within AixLib.Systems.HydraulicModules;
package Controller "Controller for hydraulic circuits"
  extends Modelica.Icons.VariantsPackage;
end Controller;


Test for admix circuit

within AixLib.Systems.HydraulicModules.Example;
model Admix "Test for admix circuit"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.Admix Admix(
    parameterPipe=DataBase.Pipes.Copper.Copper_35x1_5(),
    valveCharacteristic=Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=0.1,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    length=1,
    Kv=10,
    T_amb=293.15)

  AixLib.Fluid.Sources.Boundary_pT   boundary(
    nPorts=1,
    T=323.15,
    redeclare package Medium = Medium)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    nPorts=1,
    T=323.15,
    redeclare package Medium = Medium)

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow_nominal=8*996/3600,
    dp_nominal=8000,
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  Modelica.Blocks.Sources.Ramp valveOpening(              duration=500,
      startTime=180)
  Modelica.Blocks.Sources.Constant RPM(k=2000)
  BaseClasses.HydraulicBus hydraulicBus
  Modelica.Blocks.Sources.BooleanConstant pumpOn
equation

  connect(Admix.port_b1, hydRes.port_a)
  connect(Admix.port_a2, hydRes.port_b)
  connect(Admix.port_a1, boundary.ports[1])
  connect(Admix.port_b2, boundary1.ports[1])
  connect(Admix.hydraulicBus, hydraulicBus)
  connect(valveOpening.y, hydraulicBus.valveSet)
  connect(RPM.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpOn.y, hydraulicBus.pumpBus.onSet)
end Admix;


within AixLib.Systems.HydraulicModules.Example;
model ERC_ExperimentalHall_CoolingCircuit
  "Cooling circuit of the new ERC experimental hall"
  extends Modelica.Icons.Example;
  package Medium = AixLib.Media.Water
    "Medium within the system simulation"
  parameter Modelica.Units.SI.Temperature T_amb=293.15 "Ambient temperature";

  AixLib.Fluid.Sources.Boundary_pT bou(nPorts=1, redeclare package Medium =
        Medium)
  AixLib.Fluid.HeatExchangers.ConstantEffectiveness hex(
    m1_flow_nominal=0.1,
    m2_flow_nominal=0.1,
    dp1_nominal=10,
    dp2_nominal=10,
    redeclare package Medium1 = Medium,
    redeclare package Medium2 = Medium)
  AixLib.Fluid.Sources.MassFlowSource_T boundary(
    nPorts=1,
    m_flow=4,
    redeclare package Medium = Medium,
    T=280.15)

  SimpleConsumer simpleConsumer(
    kA=2000,
    T_fixed=303.15,
    m_flow_nominal=1,
    redeclare package Medium = Medium,
    functionality="T_fixed",
    T_start=293.15)
  SimpleConsumer simpleConsumer1(
    kA=20000,
    T_fixed=303.15,
    m_flow_nominal=1,
    redeclare package Medium = Medium,
    functionality="T_fixed",
    T_start=293.15)
  SimpleConsumer simpleConsumer2(
    T_fixed=303.15,
    m_flow_nominal=1,
    redeclare package Medium = Medium,
    functionality="T_fixed",
    kA=10000,
    T_start=293.15)
  Controller.CtrMix ctrMix(
    Td=0,
    Ti=180,
    k=0.12,
    xi_start=0.5,
    initType=Modelica.Blocks.Types.Init.InitialState,
    reverseAction=false)
  Controller.CtrThrottle ctrUnmixedThrottle(
    initType=Modelica.Blocks.Types.Init.InitialState,
    reverseAction=false,
    Td=0,
    rpm_pump=3000,
    TflowSet=291.15,
    k=0.2,
    Ti=60)
  Controller.CtrPump ctrUnmixedSimple
  AixLib.Fluid.Sources.Boundary_pT bou1(
    nPorts=1,
    redeclare package Medium = Medium,
    p=200000)
  AixLib.Systems.HydraulicModules.Pump unmixed(
    parameterPipe=DataBase.Pipes.Copper.Copper_35x1(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    T_amb=T_amb,
    pipe1(length=2),
    pipe2(length=2),
    pipe3(length=4),
    energyDynamics=admix.energyDynamics,
    length=2)
  AixLib.Systems.HydraulicModules.ThrottlePump unmixedThrottle(
    parameterPipe=DataBase.Pipes.Copper.Copper_42x1_2(),
    valve(flowCharacteristics=AixLib.Fluid.Actuators.Valves.Data.Linear()),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    T_amb=T_amb,
    pipe1(length=1),
    pipe2(length=1),
    pipe3(length=1),
    energyDynamics=admix.energyDynamics,
    length=2,
    Kv=6.3,
    pipe4(length=2))
  AixLib.Systems.HydraulicModules.Admix admix(
    parameterPipe=DataBase.Pipes.Copper.Copper_35x1_5(),
    valveCharacteristic=Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    T_amb=T_amb,
    pipe1(length=1),
    pipe2(length=1),
    pipe3(length=4),
    pipe4(length=5),
    pipe5(length=1),
    pipe6(length=1),
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    length=1,
    Kv=10)
  BaseClasses.HydraulicBus hydraulicBus
equation
  connect(bou.ports[1],hex. port_a1)
  connect(boundary.ports[1],hex. port_b1)
  connect(bou1.ports[1], hex.port_b2)
  connect(unmixed.port_b1, simpleConsumer1.port_a)
  connect(unmixed.port_a2, simpleConsumer1.port_b)
  connect(unmixedThrottle.port_b1, simpleConsumer2.port_a)
  connect(unmixedThrottle.port_a2, simpleConsumer2.port_b)
  connect(simpleConsumer.port_a,admix.port_b1)
  connect(simpleConsumer.port_b,admix.port_a2)
  connect(ctrMix.hydraulicBus, admix.hydraulicBus)
  connect(ctrUnmixedSimple.hydraulicBus, unmixed.hydraulicBus)
  connect(ctrUnmixedThrottle.hydraulicBus, unmixedThrottle.hydraulicBus)
  connect(admix.port_a1, hex.port_a2)
  connect(unmixed.port_a1, hex.port_a2)
  connect(unmixedThrottle.port_a1, hex.port_a2)
  connect(unmixedThrottle.port_b2, hex.port_b2)
  connect(unmixed.port_b2, hex.port_b2)
  connect(admix.port_b2, hex.port_b2)
  connect(ctrUnmixedThrottle.hydraulicBus, hydraulicBus)
  connect(ctrUnmixedThrottle.Tact, hydraulicBus.TRtrnInMea)
end ERC_ExperimentalHall_CoolingCircuit;


Test for injection circuit

within AixLib.Systems.HydraulicModules.Example;
model Injection "Test for injection circuit"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.Injection Injection(
    parameterPipe=DataBase.Pipes.Copper.Copper_35x1_5(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    valveCharacteristic=Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
    pipe8(length=0.5),
    length=1,
    Kv=10,
    pipe9(length=0.5),
    T_amb=293.15)

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow_nominal=8*996/3600,
    dp_nominal=8000,
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  Modelica.Blocks.Sources.Ramp valveOpening(              duration=500,
      startTime=180)
  Modelica.Blocks.Sources.Constant RPM(k=2000)
  BaseClasses.HydraulicBus hydraulicBus
  AixLib.Fluid.Sources.Boundary_pT   boundary(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  Modelica.Blocks.Sources.BooleanConstant pumpOn
equation

  connect(hydraulicBus,Injection. hydraulicBus)
  connect(hydRes.port_b, Injection.port_a2)
  connect(hydRes.port_a, Injection.port_b1)
  connect(boundary.ports[1], Injection.port_a1)
  connect(boundary1.ports[1], Injection.port_b2)
  connect(valveOpening.y, hydraulicBus.valveSet)
  connect(RPM.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpOn.y, hydraulicBus.pumpBus.onSet)
end Injection;


within AixLib.Systems.HydraulicModules.Example;
model Injection2WayValve "Test for injection circuit with a 2 way valve"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.Injection2WayValve Injection(
    parameterPipe=DataBase.Pipes.Copper.Copper_28x1(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    pipe7(length=0.5),
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    length=1,
    Kv=10,
    T_amb=293.15)

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow_nominal=8*996/3600,
    dp_nominal=8000,
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  Modelica.Blocks.Sources.Ramp valveOpening(              duration=500,
      startTime=180)
  Modelica.Blocks.Sources.Constant RPM(k=2000)
  BaseClasses.HydraulicBus hydraulicBus
  AixLib.Fluid.Sources.Boundary_pT   boundary(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  Modelica.Blocks.Sources.BooleanConstant pumpOn
equation

  connect(hydraulicBus,Injection. hydraulicBus)
  connect(hydRes.port_b, Injection.port_a2)
  connect(hydRes.port_a, Injection.port_b1)
  connect(valveOpening.y, hydraulicBus.valveSet)
  connect(boundary.ports[1], Injection.port_a1)
  connect(boundary1.ports[1], Injection.port_b2)
  connect(RPM.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpOn.y, hydraulicBus.pumpBus.onSet)
end Injection2WayValve;


Simple Examples

within AixLib.Systems.HydraulicModules;
package Example "Simple Examples"
  extends Modelica.Icons.ExamplesPackage;

end Example;


Test for unmixed pump circuit

within AixLib.Systems.HydraulicModules.Example;
model Pump "Test for unmixed pump circuit"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.Pump Unmixed(
    pipeModel="PlugFlowPipe",
    parameterPipe=DataBase.Pipes.Copper.Copper_35x1(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    length=1,
    pipe3(length=2),
    T_amb=293.15)

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    m_flow_nominal=1,
    dp_nominal=100,
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  AixLib.Systems.HydraulicModules.BaseClasses.HydraulicBus hydraulicBus
  Modelica.Blocks.Sources.Ramp RPM_ramp(
    duration=500,
    height=3000, offset = 1,
    startTime=180)
  AixLib.Fluid.Sources.Boundary_pT   boundary(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  Modelica.Blocks.Sources.BooleanConstant pumpOn
equation
  connect(Unmixed.hydraulicBus, hydraulicBus)
  connect(hydRes.port_b, Unmixed.port_a2)
  connect(hydRes.port_a, Unmixed.port_b1)
  connect(boundary.ports[1], Unmixed.port_a1)
  connect(boundary1.ports[1], Unmixed.port_b2)
  connect(RPM_ramp.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpOn.y, hydraulicBus.pumpBus.onSet)
end Pump;


Test for ummixed throttle circuit

within AixLib.Systems.HydraulicModules.Example;
model Throttle "Test for ummixed throttle circuit"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.Throttle Throttle(
    redeclare package Medium = Medium,
    parameterPipe=DataBase.Pipes.Copper.Copper_28x1(),
    m_flow_nominal=1,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    T_amb=293.15,
    length=1,
    Kv=6.3,
    pipe3(length=2))

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow_nominal=8*996/3600,
    dp_nominal=8000,
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  AixLib.Systems.HydraulicModules.BaseClasses.HydraulicBus hydraulicBus
  Modelica.Blocks.Sources.Ramp valveOpening(              duration=500,
      startTime=180)
  AixLib.Fluid.Sources.Boundary_pT   boundary(
    p=boundary1.p + 1000,
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
equation
  connect(Throttle.hydraulicBus, hydraulicBus)
  connect(hydRes.port_b, Throttle.port_a2)
  connect(hydRes.port_a, Throttle.port_b1)
  connect(Throttle.port_a1, boundary.ports[1])
  connect(Throttle.port_b2, boundary1.ports[1])
  connect(valveOpening.y, hydraulicBus.valveSet)
end Throttle;


within AixLib.Systems.HydraulicModules.Example;
model ThrottlePump "Test for unmixed throttle and pump circuit"
  extends Modelica.Icons.Example;

  package Medium = AixLib.Media.Water

  AixLib.Systems.HydraulicModules.ThrottlePump ThrottlePump(
    parameterPipe=DataBase.Pipes.Copper.Copper_40x1(),
    redeclare
      AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
      PumpInterface(speed_rpm_nominal=2540, pump(redeclare
          AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to6 per)),
    redeclare package Medium = Medium,
    m_flow_nominal=1,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    length=1,
    Kv=6.3,
    T_amb=293.15)

  AixLib.Fluid.FixedResistances.PressureDrop hydRes(
    m_flow_nominal=8*996/3600,
    dp_nominal=8000,
    m_flow(start=hydRes.m_flow_nominal),
    dp(start=hydRes.dp_nominal),
    redeclare package Medium = Medium)
    "Hydraulic resistance in distribution cirquit (shortcut pipe)"
  AixLib.Systems.HydraulicModules.BaseClasses.HydraulicBus hydraulicBus
  Modelica.Blocks.Sources.Ramp valveOpening(              duration=500,
      startTime=180)
  Modelica.Blocks.Sources.Constant RPM(k=2000)
  AixLib.Fluid.Sources.Boundary_pT   boundary(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  AixLib.Fluid.Sources.Boundary_pT   boundary1(
    T=323.15,
    redeclare package Medium = Medium,
    nPorts=1)
  Modelica.Blocks.Sources.BooleanConstant pumpOn
equation
  connect(ThrottlePump.hydraulicBus, hydraulicBus)
  connect(ThrottlePump.port_b1, hydRes.port_a)
  connect(ThrottlePump.port_a2, hydRes.port_b)
  connect(valveOpening.y, hydraulicBus.valveSet)
  connect(ThrottlePump.port_a1, boundary.ports[1])
  connect(ThrottlePump.port_b2, boundary1.ports[1])
  connect(RPM.y, hydraulicBus.pumpBus.rpmSet)
  connect(pumpOn.y, hydraulicBus.pumpBus.onSet)
end ThrottlePump;


within AixLib.Systems.ModularAHU;
model GenericAHU
  "Generic air-handling unit with heat recovery system"
  replaceable package Medium1 =
    Modelica.Media.Interfaces.PartialCondensingGases "Medium in air canal in the component"

replaceable package Medium2 =
      Modelica.Media.Interfaces.PartialMedium "Medium in hydraulic circuits"

  parameter Modelica.Units.SI.Time tau=15
    "Time Constant for PT1 behavior of temperature sensors"
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Modelica.Fluid.Types.Dynamics massDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial
    "Type of mass balance: dynamic (3 initialization options) or steady state"

  parameter Fluid.Movers.BaseClasses.Characteristics.efficiencyParameters
    hydraulicEfficiency(
      V_flow={0},
      eta={0.7}) "Hydraulic efficiency of the fans"

  parameter  Modelica.Units.SI.Temperature T_amb "Ambient temperature";
  parameter Modelica.Units.SI.MassFlowRate m1_flow_nominal = 1
    "Nominal mass flow rate in air canal";
  parameter Modelica.Units.SI.MassFlowRate m2_flow_nominal = 0.5
    "Nominal mass flow rate in hydraulics";
  parameter Modelica.Units.SI.Temperature T_start=303.15
    "Initialization temperature"

  parameter Boolean usePreheater = true "If true, a preaheater is used"
  parameter Boolean useHumidifierRet = true "If true, a humidifier in return canal is used"
  parameter Boolean useHumidifier = true "If true, a humidifier in supply canal is used"
  parameter Boolean allowFlowReversal1=true
    "= false to simplify equations, assuming, but not enforcing, no flow reversal for medium in air canal"
  parameter Boolean allowFlowReversal2=true
    "= false to simplify equations, assuming, but not enforcing, no flow reversal for medium in hydraulics"

  Modelica.Fluid.Interfaces.FluidPort_a port_a1(redeclare package Medium =
        Medium1,
    h_outflow(start=Medium1.h_default, nominal=Medium1.h_default))
    "Fluid connector a1 (positive design flow direction is from port_a1 to port_b1)"
  Modelica.Fluid.Interfaces.FluidPort_b port_b1(redeclare package Medium =
        Medium1,
    h_outflow(start=Medium1.h_default, nominal=Medium1.h_default))
    "Fluid connector b1 (positive design flow direction is from port_a1 to port_b1)"
  Modelica.Fluid.Interfaces.FluidPort_a port_a2(redeclare package Medium =
        Medium1,
    h_outflow(start=Medium1.h_default, nominal=Medium1.h_default))
    "Fluid connector a2 (positive design flow direction is from port_a2 to port_b2)"
  Modelica.Fluid.Interfaces.FluidPort_b port_b2(redeclare package Medium =
        Medium1,
    h_outflow(start=Medium1.h_default, nominal=Medium1.h_default))
    "Fluid connector b2 (positive design flow direction is from port_a2 to port_b2)"
  RegisterModule preheater(
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium2,
    final allowFlowReversal1=allowFlowReversal1,
    final allowFlowReversal2=allowFlowReversal2,
    final m1_flow_nominal=m1_flow_nominal,
    m2_flow_nominal=m2_flow_nominal,
    T_start=T_start,
    tau=tau,
    T_amb=T_amb,
    energyDynamics=energyDynamics,
    massDynamics=massDynamics,
    redeclare replaceable HydraulicModules.Admix hydraulicModule)
                 if usePreheater "Preheating coil subsystem"
  RegisterModule cooler(
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium2,
    final allowFlowReversal1=allowFlowReversal1,
    final allowFlowReversal2=allowFlowReversal2,
    final m1_flow_nominal=m1_flow_nominal,
    m2_flow_nominal=m2_flow_nominal,
    T_start=T_start,
    tau=tau,
    T_amb=T_amb,
    energyDynamics=energyDynamics,
    massDynamics=massDynamics,
    redeclare replaceable HydraulicModules.Admix hydraulicModule)
                               "Cooling coil subsystem"
  RegisterModule heater(
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium2,
    final allowFlowReversal1=allowFlowReversal1,
    final allowFlowReversal2=allowFlowReversal2,
    final m1_flow_nominal=m1_flow_nominal,
    m2_flow_nominal=m2_flow_nominal,
    T_start=T_start,
    tau=tau,
    T_amb=T_amb,
    energyDynamics=energyDynamics,
    massDynamics=massDynamics,
    redeclare replaceable HydraulicModules.Admix hydraulicModule)
                               "Heating coil subsystem"
  Fluid.HeatExchangers.DynamicHX dynamicHX(
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium1,
    final allowFlowReversal1=allowFlowReversal1,
    final allowFlowReversal2=allowFlowReversal1,
    final m1_flow_nominal=m1_flow_nominal,
    final m2_flow_nominal=m1_flow_nominal,
    dp1_nominal=10,
    dp2_nominal=10,
    energyDynamics=energyDynamics,
    massDynamics=massDynamics,
    final T1_start=T_start,
    final T2_start=T_start,
    dT_nom=1,
    Q_nom=1000*m1_flow_nominal)
                            "Heat recovery heat exchanger"
  Modelica.Fluid.Interfaces.FluidPort_a port_a3(redeclare package Medium =
        Medium2)     if usePreheater
    "Fluid connector a3 (positive design flow direction is from port_a3 to port_b3)"
  Modelica.Fluid.Interfaces.FluidPort_b port_b3(redeclare package Medium =
        Medium2)     if usePreheater
    "Fluid connector b3 (positive design flow direction is from port_a3 to port_b3)"
  Fluid.Actuators.Dampers.Exponential flapSup(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    final dpDamper_nominal=dpDamper_nominal)
                                          "Supply air flap"
  Fluid.Actuators.Dampers.Exponential flapRet(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    final dpDamper_nominal=dpDamper_nominal)
                                          "Return air flap"
  Fluid.Actuators.Dampers.Exponential dampHX(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    final dpDamper_nominal=dpDamper_nominal)
                                          "Flap to heat recovery system"
  Fluid.Actuators.Dampers.Exponential dampBypass(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    final dpDamper_nominal=dpDamper_nominal)
                                          "Bypass flap of heat recovery system"
  Modelica.Blocks.Sources.Constant const(k=1)
  Modelica.Blocks.Math.Add add(k1=-1)
  Modelica.Fluid.Interfaces.FluidPort_a port_a4(redeclare package Medium =
        Medium2)
    "Fluid connector a2 (positive design flow direction is from port_a2 to port_b2)"
  Modelica.Fluid.Interfaces.FluidPort_b port_b4(redeclare package Medium =
        Medium2)
    "Fluid connector b2 (positive design flow direction is from port_a2 to port_b2)"
  Modelica.Fluid.Interfaces.FluidPort_a port_a5(redeclare package Medium =
        Medium2)
    "Fluid connector a2 (positive design flow direction is from port_a2 to port_b2)"
  Modelica.Fluid.Interfaces.FluidPort_b port_b5(redeclare package Medium =
        Medium2)
    "Fluid connector b2 (positive design flow direction is from port_a2 to port_b2)"
  Fluid.Movers.FlowControlled_dp fanSup(
    redeclare package Medium = Medium1,
    energyDynamics=energyDynamics,
    T_start=T_start,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    redeclare Fluid.Movers.Data.Generic per(
      etaHydMet=AixLib.Fluid.Movers.BaseClasses.Types.HydraulicEfficiencyMethod.Efficiency_VolumeFlowRate,

      etaMotMet=AixLib.Fluid.Movers.BaseClasses.Types.MotorEfficiencyMethod.NotProvided,

      efficiency=hydraulicEfficiency),
    final inputType=AixLib.Fluid.Types.InputType.Continuous) "Supply air fan"

  Fluid.Movers.FlowControlled_dp fanRet(
    redeclare package Medium = Medium1,
    energyDynamics=energyDynamics,
    T_start=T_start,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    redeclare Fluid.Movers.Data.Generic per(
      etaHydMet=AixLib.Fluid.Movers.BaseClasses.Types.HydraulicEfficiencyMethod.Efficiency_VolumeFlowRate,

      etaMotMet=AixLib.Fluid.Movers.BaseClasses.Types.MotorEfficiencyMethod.NotProvided,

      efficiency=hydraulicEfficiency),
    final inputType=AixLib.Fluid.Types.InputType.Continuous) "Return air fan"

  Fluid.Humidifiers.GenericHumidifier_u
                                 humidifier(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    energyDynamics=energyDynamics,
    T_start=T_start)
                    if useHumidifier "Steam or adiabatic humdifier in supply canal"

  Fluid.Humidifiers.GenericHumidifier_u humidifierRet(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    energyDynamics=energyDynamics,
    final steamHumidifier=false)
                           if useHumidifierRet
    "Adiabatic humidifier in retrun canal: cools inlet air of heat recovery system"

  Fluid.Sensors.TemperatureTwoPort senTRet(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    T_start=T_start) "Return air temperature sensor"
  Fluid.Sensors.TemperatureTwoPort senTExh(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    T_start=T_start) "Exhaust air temperature sensor"
  Fluid.Sensors.TemperatureTwoPort senTSup(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    T_start=T_start) "Supply air temperature sensor"
  Fluid.Sensors.TemperatureTwoPort senTOda(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final m_flow_nominal=m1_flow_nominal,
    T_start=T_start) "Outside air temperature sensor"
  Fluid.Sensors.VolumeFlowRate senVolFlo(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    m_flow_nominal=m1_flow_nominal) "Exhaust volume flow sensor"
  Fluid.Sensors.RelativeHumidityTwoPort senRelHumSup(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    m_flow_nominal=m1_flow_nominal) "Supply air humidity sensor"
  Fluid.Sensors.RelativeHumidityTwoPort senRelHumSup1(
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    m_flow_nominal=m1_flow_nominal) "Return air humidity sensor"

  BaseClasses.GenericAHUBus genericAHUBus "Bus connector for generic ahu"
  Fluid.Interfaces.PassThroughMedium passThroughPreheater(
    redeclare package Medium = Medium1,
    allowFlowReversal=allowFlowReversal1) if usePreheater == false
    "Passthrough if without preheater"
  Fluid.Interfaces.PassThroughMedium passThroughHumidifer(
    redeclare package Medium = Medium1,
    allowFlowReversal=allowFlowReversal1) if useHumidifier == false
    "Passthrough if without humidifier"
  Fluid.Interfaces.PassThroughMedium passThroughHumidiferRet(
    redeclare package Medium = Medium1,
    allowFlowReversal=allowFlowReversal1) if useHumidifierRet == false
    "Passthough if without adiabtic return air humidifier"

  parameter Modelica.Units.SI.PressureDifference dpDamper_nominal = 1
    "Pressure drop of fully open dampers at nominal mass flow rate";
protected
  Modelica.Blocks.Continuous.FirstOrder PT1_airIn(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
  Modelica.Blocks.Continuous.FirstOrder PT1_airIn1(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau) "Oda sensor delay"
  Modelica.Blocks.Continuous.FirstOrder PT1_airIn2(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
  Modelica.Blocks.Continuous.FirstOrder PT1_airIn3(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
equation
  connect(preheater.port_a2, port_a3)
  connect(preheater.port_b2, port_b3)
  connect(const.y, add.u2)
  connect(dampHX.port_b, dynamicHX.port_a2)
  connect(preheater.port_b1, dampHX.port_a)
  connect(flapSup.port_b,preheater. port_a1)
  connect(cooler.port_b1, heater.port_a1)
  connect(dampHX.port_a,dampBypass. port_a)
  connect(dampBypass.port_b, dynamicHX.port_b2)
  connect(cooler.port_a2, port_a4)
  connect(cooler.port_b2, port_b4)
  connect(heater.port_a2, port_a5)
  connect(heater.port_b2, port_b5)
  connect(dynamicHX.port_b2, cooler.port_a1)
  connect(heater.port_b1, humidifier.port_a)
  connect(humidifier.port_b, fanSup.port_a)

  connect(fanRet.port_b, humidifierRet.port_a)
  connect(humidifierRet.port_b, dynamicHX.port_a1)
  connect(senTExh.port_b, port_b2)
  connect(senTSup.port_b, port_b1)
  connect(port_a1, senTOda.port_a)
  connect(senTOda.port_b, flapSup.port_a)
  connect(dynamicHX.port_b1, senVolFlo.port_a)
  connect(senVolFlo.port_b, senTExh.port_a)
  connect(add.y, dampHX.y)
  connect(dampBypass.y, add.u1)
  connect(fanSup.port_b, senRelHumSup.port_a)
  connect(senRelHumSup.port_b, senTSup.port_a)
  connect(senTRet.port_b, senRelHumSup1.port_a)
  connect(port_a2, flapRet.port_a)
  connect(flapRet.port_b, senTRet.port_a)
  connect(senRelHumSup1.port_b, fanRet.port_a)
  connect(fanRet.dp_in, genericAHUBus.dpFanEtaSet)
  connect(fanRet.dp_actual, genericAHUBus.dpFanEtaMea)
  connect(fanRet.P, genericAHUBus.powerFanEtaMea)
  connect(fanSup.dp_in, genericAHUBus.dpFanSupSet)
  connect(fanSup.P, genericAHUBus.powerFanSupMea)
  connect(fanSup.dp_actual, genericAHUBus.dpFanSupMea)
  connect(senRelHumSup1.phi, genericAHUBus.relHumEtaMea)
  connect(senRelHumSup.phi, genericAHUBus.relHumSupMea)
  connect(humidifierRet.u, genericAHUBus.adiabHumSet)
  connect(humidifier.u, genericAHUBus.steamHumSet)
  connect(humidifier.powerEva, genericAHUBus.powerSteamHumMea)
  connect(flapRet.y, genericAHUBus.flapEtaSet)
  connect(flapRet.y_actual, genericAHUBus.flapEtaMea)
  connect(flapSup.y, genericAHUBus.flapSupSet)
  connect(flapSup.y_actual, genericAHUBus.flapSupMea)
  connect(dampBypass.y, genericAHUBus.bypassHrsSet)
  connect(dampBypass.y_actual, genericAHUBus.bypassHrsMea)
  connect(senVolFlo.V_flow, genericAHUBus.V_flow_EtaMea)
  connect(preheater.registerBus, genericAHUBus.preheaterBus)
  connect(cooler.registerBus, genericAHUBus.coolerBus)
  connect(heater.registerBus, genericAHUBus.heaterBus)

  connect(fanRet.port_b, passThroughHumidiferRet.port_a)
  connect(passThroughHumidiferRet.port_b, dynamicHX.port_a1)
  connect(heater.port_b1, passThroughHumidifer.port_a)

  connect(passThroughHumidifer.port_b, fanSup.port_a)
  connect(flapSup.port_b, passThroughPreheater.port_a)
  connect(passThroughPreheater.port_b, dampHX.port_a)
  connect(senTSup.T, PT1_airIn.u)
  connect(PT1_airIn.y, genericAHUBus.TSupMea)
  connect(senTOda.T, PT1_airIn1.u)
  connect(PT1_airIn1.y, genericAHUBus.TOdaMea)
  connect(senTExh.T, PT1_airIn2.u)
  connect(PT1_airIn2.y, genericAHUBus.TEhaMea)
  connect(senTRet.T, PT1_airIn3.u)
  connect(PT1_airIn3.y, genericAHUBus.TEtaMea)
end GenericAHU;


<html><p>
  This package contains modular systems for air-handling units. The
  modules base on the hydraulicModules.
</p>
</html>

within AixLib.Systems;
package ModularAHU
    extends Modelica.Icons.VariantsPackage;
end ModularAHU;


within AixLib.Systems.ModularAHU;
model RegisterModule "AHU register module for heaters and coolers"
    extends AixLib.Fluid.Interfaces.PartialFourPortParallel;

  parameter String hydraulicModuleIcon = "Admix" "Icon selection corresponding to module"

  parameter Modelica.Units.SI.MassFlowRate m1_flow_nominal(min=0)
    "Nominal mass flow rate"
  parameter Modelica.Units.SI.MassFlowRate m2_flow_nominal(min=0)
    "Nominal mass flow rate"
  parameter Modelica.Units.SI.Temperature T_start=293.15
    "Initialization temperature"
  parameter Modelica.Units.SI.Time tau=15
    "Time constant for PT1 behavior of temperature sensors in air canal"
  parameter Modelica.Units.SI.Temperature T_amb "Ambient temperature";
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Modelica.Fluid.Types.Dynamics massDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial
    "Type of mass balance: dynamic (3 initialization options) or steady state"
  parameter Modelica.Units.SI.Time tauHeaTra=1200
    "Time constant for heat transfer of temperature sensors in air chanal"
  replaceable HydraulicModules.Admix hydraulicModule
  constrainedby
    AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule(
    length=1,
    Kv=6.3,
    final energyDynamics=energyDynamics,
    final T_amb=T_amb,
    redeclare final package Medium = Medium2,
    final m_flow_nominal=m2_flow_nominal,
    T_start=T_start,
    final allowFlowReversal=allowFlowReversal2,
    massDynamics=massDynamics) "Hydraulic module selection"
  AixLib.Fluid.HeatExchangers.DynamicHX dynamicHX(final m1_flow_nominal=
        m1_flow_nominal, final m2_flow_nominal=m2_flow_nominal,
    final allowFlowReversal1=allowFlowReversal1,
    final allowFlowReversal2=allowFlowReversal2,
    redeclare final package Medium1 = Medium1,
    redeclare final package Medium2 = Medium2,
    dp1_nominal=10,
    dp2_nominal=10,
    tau1=2,
    tau2=8,
    energyDynamics=energyDynamics,
    final massDynamics=massDynamics,
    T1_start=T_start,
    T2_start=T_start,
    tau_C=10,
    dT_nom=1,
    Q_nom=1000*m1_flow_nominal)
  AixLib.Systems.ModularAHU.BaseClasses.RegisterBus registerBus

protected
  AixLib.Fluid.Sensors.TemperatureTwoPort senT_airIn(
    final tau=0.1,
    final T_start=T_start,
    final transferHeat=true,
    final TAmb=T_amb,
    final m_flow_nominal=m1_flow_nominal,
    redeclare final package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final tauHeaTra=tauHeaTra)
  Modelica.Blocks.Continuous.FirstOrder PT1_airIn(
    final initType=Modelica.Blocks.Types.Init.SteadyState,
    final y_start=T_start,
    final T=tau)
  AixLib.Fluid.Sensors.TemperatureTwoPort senT_airOut(
    tau=0.1,
    T_start=T_start,
    transferHeat=true,
    final TAmb=T_amb,
    final m_flow_nominal=m1_flow_nominal,
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1,
    final tauHeaTra=tauHeaTra)
  Modelica.Blocks.Continuous.FirstOrder PT1_airOut(
    final initType=Modelica.Blocks.Types.Init.SteadyState,
    final y_start=T_start,
    final T=tau)

  AixLib.Fluid.Sensors.VolumeFlowRate VFSen_out(
    T_start=T_start,
    final m_flow_nominal=m1_flow_nominal,
    redeclare package Medium = Medium1,
    final allowFlowReversal=allowFlowReversal1)
    "Inflow into admix module in forward line"
equation
  connect(hydraulicModule.port_b1, dynamicHX.port_a2)
  connect(hydraulicModule.port_a2, dynamicHX.port_b2)
  connect(senT_airIn.T, PT1_airIn.u)
  connect(senT_airOut.T, PT1_airOut.u)
  connect(dynamicHX.port_b1, senT_airOut.port_a)
  connect(hydraulicModule.hydraulicBus, registerBus.hydraulicBus)
  connect(senT_airIn.port_b, VFSen_out.port_a)
  connect(VFSen_out.port_b, dynamicHX.port_a1)
  connect(PT1_airIn.y, registerBus.TAirInMea)
  connect(PT1_airOut.y, registerBus.TAirOutMea)
  connect(senT_airIn.port_a, port_a1)
  connect(senT_airOut.port_b, port_b1)
  connect(hydraulicModule.port_a1, port_a2)
  connect(hydraulicModule.port_b2, port_b2)
  connect(VFSen_out.V_flow, registerBus.VFlowAirMea)
end RegisterModule;


Contains basic models

within AixLib.Systems.ModularAHU;
package BaseClasses "Contains basic models"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


Simple controller for AHU. This control uses the heating and cooling register to regulate the supply air temperature. The set point of the supply air can be given either by the parameter <i>TFlowSet </i>or by the external input variable <i>Tset.</i> The preheater use used for frost protection and has a fixed set point of 5°C. The heat recovery system is always used and the bypass closed. The supply and return air flaps are always open.

within AixLib.Systems.ModularAHU.Controller;
model CtrAHUBasic "Simple controller for AHU"

  parameter Modelica.Units.SI.Temperature TFlowSet=289.15
    "Flow temperature set point of consumer"
  parameter Boolean usePreheater=true "Set true, if ahu contains a preaheater"
  parameter Real TFrostProtect=273.15 + 5
    "Temperature set point of preheater for frost protection"

  parameter Boolean useExternalTset=false
    "If True, set temperature can be given externally";

  // Register controllers
  CtrRegBasic ctrPh(
    final useExternalTset=true,
    Td=0,
    final initType=initType,
    final reverseAction=true)
                             if usePreheater
  CtrRegBasic ctrCo(
    final useExternalTset=true,
    Td=0,
    final initType=initType,
    final reverseAction=false)
  CtrRegBasic ctrRh(
    final useExternalTset=true,
    final useExternalTMea=true,
    Td=0,
    final initType=initType,
    final reverseAction=true)

  // Parameter for volume flow controller
  parameter Modelica.Units.SI.VolumeFlowRate VFlowSet=3000/3600
    "Set value of volume flow [m^3/s]"
  parameter Real dpMax=5000 "Maximal pressure difference of the fans [Pa]"
  parameter Boolean useTwoFanCtr=false
    "If True, a PID for each of the two fans is used. Use two PID controllers for open systems (if the air canal is not closed)."
  parameter Real k=50 "Gain of controller"
  parameter Modelica.Units.SI.Time Ti=5 "Time constant of Integrator block"
  parameter Real y_start=0 "Initial value of output"
  parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"

  BaseClasses.GenericAHUBus genericAHUBus "Bus connector for genericAHU"

  Modelica.Blocks.Sources.Constant constTflowSet(final k=TFlowSet) if not useExternalTset
  Modelica.Blocks.Interfaces.RealInput Tset if useExternalTset
    "Connector of set temperature, if given externally"
  Modelica.Blocks.Sources.Constant TFrostProtection(final k=TFrostProtect)
 if usePreheater
  Controls.Continuous.LimPID PID_VflowSup(
    final yMax=dpMax,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=true,
    final reset=AixLib.Types.Reset.Disabled) "PID controller for supply fan"
  Controls.Continuous.LimPID PID_VflowRet(
    final yMax=dpMax,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=true,
    final reset=AixLib.Types.Reset.Disabled) if useTwoFanCtr
    "PID controller for return fan. Is deactivated if useTwoFanCtr is false."
  Modelica.Blocks.Sources.Constant ConstVflow(final k=VFlowSet)
    "Constant volume flow setpoint"

  Modelica.Blocks.Sources.Constant ConstHRS(final k=0)
    "Heat recovery is deactivated"
  Modelica.Blocks.Sources.Constant ConstFlap(final k=1) "Flaps are always open"
  Modelica.Blocks.Sources.Constant ConstHum(final k=0) "Humidifiers are off"

  Modelica.Blocks.Routing.RealPassThrough realPassThrough if not useTwoFanCtr
equation
  connect(ctrPh.registerBus, genericAHUBus.preheaterBus)
  connect(ctrCo.registerBus, genericAHUBus.coolerBus)
  connect(ctrRh.registerBus, genericAHUBus.heaterBus)
  connect(constTflowSet.y, ctrCo.Tset)
  connect(constTflowSet.y, ctrRh.Tset)
  connect(TFrostProtection.y, ctrPh.Tset)
  connect(ConstVflow.y, PID_VflowSup.u_s)
  connect(PID_VflowSup.u_m, genericAHUBus.heaterBus.VFlowAirMea)
  connect(Tset, ctrCo.Tset)
  connect(Tset, ctrRh.Tset)
  connect(ConstHRS.y, genericAHUBus.bypassHrsSet)
  connect(ConstFlap.y, genericAHUBus.flapEtaSet)
  connect(ConstFlap.y, genericAHUBus.flapSupSet)
  connect(ConstHum.y, genericAHUBus.steamHumSet)
  connect(ConstHum.y, genericAHUBus.adiabHumSet)
  connect(ConstVflow.y, PID_VflowRet.u_s)
  connect(PID_VflowSup.y, genericAHUBus.dpFanSupSet)
  connect(PID_VflowRet.u_m, genericAHUBus.V_flow_EtaMea)
  connect(PID_VflowRet.y, genericAHUBus.dpFanEtaSet)
  connect(ctrRh.TMea, genericAHUBus.TSupMea)
  if not useTwoFanCtr then
  end if;
  connect(PID_VflowSup.y, realPassThrough.u)
  connect(realPassThrough.y, genericAHUBus.dpFanEtaSet)
end CtrAHUBasic;


Controller for AHU with CO2-control. This control uses the heating and cooling register to regulate the supply air temperature. The set point of the supply air can be given either by the parameter <i>TFlowSet </i>or by the external input variable <i>Tset.</i> The preheater is used for frost protection and has a fixed set point of 5°C. The heat recovery system is always used and the bypass closed. The supply and return air flaps are always open.

within AixLib.Systems.ModularAHU.Controller;
model CtrAHUCO2 "Controller for AHU with CO2-control"

  parameter Modelica.Units.SI.Temperature TFlowSet=289.15
    "Flow temperature set point of consumer"
  parameter Boolean usePreheater=true "Set true, if ahu contains a preaheater"
  parameter Real TFrostProtect=273.15 + 5
    "Temperature set point of preheater for frost protection"
  parameter Real relHumSupSet=0.6
    "Set point for steam humidifier for relative humidity";

  parameter Boolean useExternalTset=false
    "If True, set temperature can be given externally";

  // Register controllers
  CtrRegBasic ctrPh(
    final useExternalTset=true,
    Td=0,
    final initType=initType) if usePreheater
  CtrRegBasic ctrCo(
    final useExternalTset=true,
    Td=0,
    final initType=initType,
    final reverseAction=false)
  CtrRegBasic ctrRh(
    final useExternalTset=true,
    final useExternalTMea=true,
    Td=0,
    final initType=initType)

  // Parameter for volume flow controller
  parameter Modelica.Units.SI.VolumeFlowRate Vflow_nominal=3000/3600
    "Nominal value of volume flow [m^3/s]"
  parameter Real minVflowPer(min=0,max=1) = 0.3
    "Minimal percentage volume flow"
  parameter Real CO2set = 800
    "Set value of CO2 concentration in ppm"
  parameter Real dpMax=5000 "Maximal pressure difference of the fans [Pa]"
  parameter Boolean useTwoFanCtr=false
    "If True, a PID for each of the two fans is used. Use two PID controllers for open systems (if the air canal is not closed)."
  parameter Real k=50 "Gain of Vflow controller"
  parameter Modelica.Units.SI.Time Ti=5 "Time constant of Integrator block Vflow"
  parameter Real kCO2=Vflow_nominal/1000 "Gain of CO2 controller"
  parameter Modelica.Units.SI.Time TiCO2=300 "Time constant of Integrator block CO2"
  parameter Real y_start=0 "Initial value of output"
  parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"

  BaseClasses.GenericAHUBus genericAHUBus "Bus connector for genericAHU"

  Modelica.Blocks.Sources.Constant constTflowSet(final k=TFlowSet) if not useExternalTset
  Modelica.Blocks.Interfaces.RealInput Tset if useExternalTset
    "Connector of set temperature, if given externally"
  Modelica.Blocks.Sources.Constant TFrostProtection(final k=TFrostProtect)
 if usePreheater
  Controls.Continuous.LimPID PID_VflowSup(
    final yMax=dpMax,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PI,
    final k=k,
    final Ti=Ti,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=true,
    final reset=AixLib.Types.Reset.Disabled) "PID controller for supply fan"
  Controls.Continuous.LimPID PID_VflowRet(
    final yMax=dpMax,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PI,
    final k=k,
    final Ti=Ti,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=true,
    final reset=AixLib.Types.Reset.Disabled) if useTwoFanCtr
    "PID controller for return fan. Is deactivated if useTwoFanCtr is false."

  Modelica.Blocks.Sources.Constant ConstHRS(final k=0)
    "Heat recovery is deactivated"
  Modelica.Blocks.Sources.Constant ConstFlap(final k=1) "Flaps are always open"
  Modelica.Blocks.Sources.Constant ConstHum(final k=0) "Humidifiers are off"

  Controls.Continuous.LimPID PID_CO2(
    final yMax=Vflow_nominal,
    final yMin=minVflowPer*Vflow_nominal,
    final controllerType=Modelica.Blocks.Types.SimpleController.PI,
    final k=kCO2,
    final Ti=TiCO2,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=false,
    final reset=AixLib.Types.Reset.Disabled) "PID controller for CO2 concentration"
  Modelica.Blocks.Sources.Constant constCO2Set(final k=CO2set)
    if not useExternalTset
  Modelica.Blocks.Interfaces.RealInput CO2Mea "measurement input signal for CO2 concentration"
  Modelica.Blocks.Routing.RealPassThrough realPassThrough if not useTwoFanCtr
  Controls.Continuous.LimPID PID_SteamHum(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PI,
    final k=0.5,
    final Ti=10,
    final Td=0,
    final initType=initType,
    y_start=y_start,
    final reverseActing=true,
    final reset=AixLib.Types.Reset.Disabled) "PID controller for supply fan"
  Modelica.Blocks.Sources.Constant constRelHumSup(final k=relHumSupSet)
    if not useExternalTset
equation
  connect(ctrPh.registerBus, genericAHUBus.preheaterBus)
  connect(ctrCo.registerBus, genericAHUBus.coolerBus)
  connect(ctrRh.registerBus, genericAHUBus.heaterBus)
  connect(constTflowSet.y, ctrCo.Tset)
  connect(constTflowSet.y, ctrRh.Tset)
  connect(TFrostProtection.y, ctrPh.Tset)
  connect(PID_VflowSup.u_m, genericAHUBus.heaterBus.VFlowAirMea)
  connect(Tset, ctrCo.Tset)
  connect(Tset, ctrRh.Tset)
  connect(ConstHRS.y, genericAHUBus.bypassHrsSet)
  connect(ConstFlap.y, genericAHUBus.flapEtaSet)
  connect(ConstFlap.y, genericAHUBus.flapSupSet)
  connect(PID_VflowSup.y, genericAHUBus.dpFanSupSet)
  connect(PID_VflowRet.u_m, genericAHUBus.V_flow_EtaMea)
  connect(PID_VflowRet.y, genericAHUBus.dpFanEtaSet)
  connect(ctrRh.TMea, genericAHUBus.TSupMea)
  connect(constCO2Set.y, PID_CO2.u_s)
  connect(PID_CO2.y, PID_VflowSup.u_s)
  connect(PID_CO2.y, PID_VflowRet.u_s)
  connect(PID_CO2.u_m, CO2Mea)
  connect(PID_VflowSup.y, realPassThrough.u)
  connect(realPassThrough.y, genericAHUBus.dpFanEtaSet)
  connect(ConstHum.y, genericAHUBus.adiabHumSet)
  connect(PID_SteamHum.u_m, genericAHUBus.relHumSupMea)
  connect(constRelHumSup.y, PID_SteamHum.u_s)
  connect(PID_SteamHum.y, genericAHUBus.steamHumSet)
end CtrAHUCO2;


Controller for heating and cooling registers. Simple controller for heating and cooling registers. The controlled
  variable is the air outflow temperature T_air_out. The pump (if
  existing in hydraulic circuit) operates at constant frequency and is
  always on.

within AixLib.Systems.ModularAHU.Controller;
block CtrRegBasic "Controller for heating and cooling registers"
  //Boolean choice;

  parameter Boolean useExternalTset = false "If True, set temperature can be given externally";
  parameter Boolean useExternalTMea = false "If True, measured temperature can be given externally";
  parameter Modelica.Units.SI.Temperature TflowSet = 293.15 "Flow temperature set point of consumer"
  parameter Real k(min=0, unit="1") = 0.025 "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small)=130
    "Time constant of Integrator block";
  parameter Modelica.Units.SI.Time Td(min=0) = 4
    "Time constant of Derivative block";
  parameter Real rpm_pump(min=0, unit="1") = 2000 "Rpm of the Pump";
  parameter Modelica.Blocks.Types.Init initType=.Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
  parameter Boolean reverseAction = true
    "Set to true if a heating coil, and false if a cooling coil is controlled";
  parameter Real xi_start=0
    "Initial or guess value value for integrator output (= integrator state)"
  parameter Real xd_start=0
    "Initial or guess value for state of derivative block"
  parameter Real y_start=0 "Initial value of output"
  Modelica.Blocks.Interfaces.RealInput Tset if useExternalTset
    "Connector of second Real input signal"
  AixLib.Controls.Continuous.LimPID PID(
    final yMax=1,
    final yMin=0,
    final controllerType=Modelica.Blocks.Types.SimpleController.PID,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    final initType=initType,
    final xi_start=xi_start,
    final xd_start=xd_start,
    final y_start=y_start,
    final reverseActing=reverseAction,
    final reset=AixLib.Types.Reset.Disabled) "PID controller for valve opening"
  Modelica.Blocks.Sources.Constant constRpmPump(final k=rpm_pump)
    "Constant pump speed"

  Modelica.Blocks.Sources.Constant constTflowSet(final k=TflowSet) if not useExternalTset
    "Constant internal flow temperature setoint, if not external"
  Modelica.Blocks.Sources.BooleanConstant booleanConstant "Pump is always on"
  BaseClasses.RegisterBus registerBus "Connector bus for register module"
  Modelica.Blocks.Interfaces.RealInput TMea if useExternalTMea
    "Connector of second Real input signal"
equation

    connect(PID.u_s, Tset)
    connect(constTflowSet.y, PID.u_s)

  if useExternalTMea==false then
  connect(PID.u_m, registerBus.TAirOutMea)
  end if;
  connect(PID.u_m, TMea)
  connect(booleanConstant.y, registerBus.hydraulicBus.pumpBus.onSet)
  connect(constRpmPump.y, registerBus.hydraulicBus.pumpBus.rpmSet)
  connect(PID.y, registerBus.hydraulicBus.valveSet)
end CtrRegBasic;


Controller for register modules

within AixLib.Systems.ModularAHU;
package Controller "Controller for register modules"
  extends Modelica.Icons.VariantsPackage;
end Controller;


Cooler register example

within AixLib.Systems.ModularAHU.Examples;
model Cooler "Cooler register example"
  extends Modelica.Icons.Example;
    package MediumWater = AixLib.Media.Water
  package MediumAir = AixLib.Media.Air

  RegisterModule registerModule(
    redeclare HydraulicModules.ThrottlePump hydraulicModule(
      parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
      parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
      length=1,
      Kv=6.3,
      redeclare
        AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
        PumpInterface(speed_rpm_nominal=2900, pump(redeclare
            AixLib.Fluid.Movers.Data.Pumps.Wilo.VeroLine50slash150dash4slash2
            per))),
    redeclare package Medium2 = MediumWater,
    redeclare package Medium1 = MediumAir,
    T_amb=293.15,
    T_start=297.15,
    dynamicHX(
      Q_nom=30000,
      dT_nom=20,
      dp1_nominal=100,
      dp2_nominal=6000),
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
    hydraulicModuleIcon="ThrottlePump",
    m1_flow_nominal=1,
    m2_flow_nominal=0.1,
    massDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial)

  Fluid.Sources.Boundary_pT boundaryWaterSource(
    p=300000,
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=279.15)
  Fluid.Sources.Boundary_pT boundaryWaterSink(
    p=300000,                                 nPorts=1, redeclare package Medium =
               MediumWater)
  Fluid.Sources.Boundary_pT boundaryAirSource(
    nPorts=1,
    redeclare package Medium = MediumAir,
    p=102000,
    T=298.15)
  Fluid.Sources.Boundary_pT boundaryAirSink(nPorts=1, redeclare package Medium =
        MediumAir)
  Controller.CtrRegBasic ctrBasic(
    k=0.04,
    Ti=120,
    Td=0.1,
    initType=Modelica.Blocks.Types.Init.InitialOutput,
    reverseAction=false,
    useExternalTset=true,
    TflowSet=289.15,
    rpm_pump=1000)
  Modelica.Blocks.Sources.Constant Tset(k=273.15 + 19)
equation
  connect(boundaryWaterSink.ports[1], registerModule.port_b2)
  connect(boundaryWaterSource.ports[1], registerModule.port_a2)
  connect(registerModule.port_b1, boundaryAirSink.ports[1])
  connect(registerModule.port_a1, boundaryAirSource.ports[1])
  connect(ctrBasic.registerBus, registerModule.registerBus)
  connect(ctrBasic.Tset, Tset.y)
end Cooler;


within AixLib.Systems.ModularAHU.Examples;
model DemandControlledAHU "Example for air handling unit with demand controlled ventilation"
  extends Modelica.Icons.Example;

  parameter Real CO2Con_start = 400
    "Start value for CO2 concentration in the thermal zone in ppm";
  parameter Real CO2ConAmb = 450
    "CO2 concentration in ambient air in ppm";

  replaceable package MediumAir = AixLib.Media.Air (extraPropertiesNames={"CO2"})
    "Medium in air canal in the component";
  replaceable package MediumWater = AixLib.Media.Water
    "Medium in hydronic systems";

  AixLib.Systems.ModularAHU.GenericAHU genericAHU(
    massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    preheater(
      T_start=288.15,
      energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
      redeclare HydraulicModules.Admix hydraulicModule(
        pipeModel="PlugFlowPipe",
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_28x1_5(),
        parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
        length=1,
        Kv=10,
        valveCharacteristic=AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.13,0.205,0.566,0.813,0.88,0.91,0.95,1}, phi={0,0.001,0.002,0.176,0.60,0.75,0.97,0.98,1}), b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.1,0.2,0.25,0.52,0.8,0.9,0.95,1}, phi={0,0.001,0.002,0.022,0.53,0.96,0.98,0.99,1})),
        valve(use_inputFilter=true),
        pipe1(length=1.53),
        pipe2(length=0.54),
        pipe3(length=1.06),
        pipe4(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=0.48),
        pipe5(length=1.44, fac=16),
        pipe6(length=0.52),
        redeclare HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled PumpInterface(pumpParam=AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN25_H1_8_V9(), calculatePower=true)),
      tau=90 + 70,
      T_amb=293.15,
      dynamicHX(
        dp1_nominal=66,
        dp2_nominal=6000 + 8000,
        nNodes=5,
        dT_nom=43.9,
        Q_nom=57700)),
    redeclare package Medium1 = MediumAir,
    redeclare package Medium2 = MediumWater,
    T_amb=293.15,
    m1_flow_nominal=1,
    m2_flow_nominal=0.5,
    usePreheater=true,
    useHumidifierRet=false,
    useHumidifier=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    cooler(
      energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
      redeclare HydraulicModules.Admix hydraulicModule(
        pipeModel="PlugFlowPipe",
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
        parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
        length=1,
        Kv=10,
        T_start=294.75,
        valveCharacteristic=AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.07,0.12,0.45,0.65,0.89,0.93,0.96,1}, phi={0,0.001,0.002,0.08,0.29,0.75,0.94,0.98,1}), b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.1,0.2,0.26,0.52,0.8,0.9,0.95,1}, phi={0,0.001,0.002,0.05,0.45,0.96,0.98,0.99,1})),
        valve(use_inputFilter=true),
        pipe1(
          T_start=283.15,
          parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_54x2(),
          length=4.5),
        pipe2(length=1.55),
        pipe3(length=0.9),
        pipe4(length=0.3),
        pipe5(length=2.95, fac=13),
        pipe6(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_22x1_1(), length=0.5),
        redeclare HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled PumpInterface(pumpParam=AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN32(), calculatePower=true)),
      T_start=293.65,
      tau=90,
      T_amb=296.65,
      dynamicHX(
        dp1_nominal(displayUnit="bar") = 138,
        dp2_nominal(displayUnit="bar") = 70600,
        nNodes=4,
        T1_start=305.15,
        dT_nom=22.16,
        Q_nom=53400)),
    heater(
      T_start=285.65,
      energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
      redeclare HydraulicModules.Admix hydraulicModule(
        pipeModel="PlugFlowPipe",
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_22x1(),
        parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
        length=1,
        Kv=6.3,
        valveCharacteristic=AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0.0,0.14,0.24,0.43,0.68,0.81,0.93,0.96,1.0}, phi={0.0,0.001,0.002,0.02,0.1,0.25,0.76,0.98,1.0}), b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0.0,0.02,0.05,0.08,0.27,0.6,0.95,1.0}, phi={0.0,0.001,0.002,0.01,0.3,0.9,0.97,1.0})),
        valve(use_inputFilter=false),
        pipe1(length=2.8, fac=9),
        pipe2(length=0.63, parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5()),
        pipe3(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=1.85),
        pipe4(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=0.4),
        pipe5(length=3.2, fac=10),
        pipe6(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_16x1(), length=0.82),
        redeclare HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled PumpInterface(pumpParam=AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN25_H1_8_V5(), calculatePower=true)),
      tau=90,
      T_amb=293.15,
      dynamicHX(
        dp1_nominal=33,
        dp2_nominal=4500 + 55000,
        nNodes=4,
        dT_nom=40.1,
        Q_nom=22300)),
    dynamicHX(
      dp1_nominal=220,
      dp2_nominal=220,
      dT_nom=1,
      Q_nom=1100),
    humidifier(
      dp_nominal=100,
      mWat_flow_nominal=0.01,
      TLiqWat_in=288.15),
    humidifierRet(
      dp_nominal=100,
      mWat_flow_nominal=0.5,
      TLiqWat_in=288.15))
  ThermalZones.ReducedOrder.ThermalZone.ThermalZone thermalZone(
    redeclare package Medium = MediumAir,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final C_start={CO2Con_start/1E6 * (MolCO2/MolAir)},
 redeclare AixLib.DataBase.ThermalZones.Office_1995_1000 zoneParam,
    use_C_flow=true,
    use_moisture_balance=true,
    internalGainsMode=3,
    use_NaturalAirExchange=true,
    XCO2_amb=CO2ConAmb/1E6 * (MolCO2/MolAir),
    metOnePerSit=58,
    nPorts=2)
  Fluid.Sources.Boundary_pT SourcePreheater(
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkPreheater(
    nPorts=1,
    redeclare package Medium = MediumWater,
    p=102000,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceCooler(
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=283.15)
  Fluid.Sources.Boundary_pT SinkCooler(
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceHeater(
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkHeater(nPorts=1, redeclare package Medium =
        MediumWater)
  Fluid.Sources.Outside out(
    C={6.8355*0.0001},      nPorts=1, redeclare package Medium = MediumAir)
  Fluid.Sources.Boundary_pT boundaryExhaustAir(nPorts=1, redeclare package
      Medium =                                                                      MediumAir)
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=ModelicaServices.ExternalReferences.loadResource("modelica://AixLib/Resources/weatherdata/TRY2015_Jahr_City_Aachen.mos"), computeWetBulbTemperature=false)
  Modelica.Blocks.Sources.CombiTimeTable internalGains(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    tableName="internalGains",
    fileName=ModelicaServices.ExternalReferences.loadResource("modelica://AixLib/Resources/LowOrder_ExampleData/SIA2024_SingleOffice_week.txt"),
    columns={2,3,4},
    tableOnFile=true,
    table=[0,0,0.1,0,0; 3540,0,0.1,0,0; 3600,0,0.1,0,0; 7140,0,0.1,0,0; 7200,0,0.1,0,0; 10740,0,0.1,0,0; 10800,0,0.1,0,0; 14340,0,0.1,0,0; 14400,0,0.1,0,0; 17940,0,0.1,0,0; 18000,0,0.1,0,0; 21540,0,0.1,0,0; 21600,0,0.1,0,0; 25140,0,0.1,0,0; 25200,0,0.1,0,0; 28740,0,0.1,0,0; 28800,0,0.1,0,0; 32340,0,0.1,0,0; 32400,0.6,0.6,1,1; 35940,0.6,0.6,1,1; 36000,1,1,1,1; 39540,1,1,1,1; 39600,0.4,0.4,1,1; 43140,0.4,0.4,1,1; 43200,0,0.1,0,0; 46740,0,0.1,0,0; 46800,0,0.1,0,0; 50340,0,0.1,0,0; 50400,0.6,0.6,1,1; 53940,0.6,0.6,1,1; 54000,1,1,1,1; 57540,1,1,1,1; 57600,0.4,0.4,1,1; 61140,0.4,0.4,1,1; 61200,0,0.1,0,0; 64740,0,0.1,0,0; 64800,0,0.1,0,0; 68340,0,0.1,0,0; 68400,0,0.1,0,0; 71940,0,0.1,0,0; 72000,0,0.1,0,0; 75540,0,0.1,0,0; 75600,0,0.1,0,0; 79140,0,0.1,0,0; 79200,0,0.1,0,0; 82740,0,0.1,0,0; 82800,0,0.1,0,0; 86340,0,0.1,0,0; 86400,0,0.1,0,0; 89940,0,0.1,0,0; 90000,0,0.1,0,0; 93540,0,0.1,0,0; 93600,0,0.1,0,0; 97140,0,0.1,0,0; 97200,0,0.1,0,0; 100740,0,0.1,0,0; 100800,0,0.1,0,0; 104340,0,0.1,0,0;
        104400,0,0.1,0,0; 107940,0,0.1,0,0; 108000,0,0.1,0,0; 111540,0,0.1,0,0; 111600,0,0.1,0,0; 115140,0,0.1,0,0; 115200,0,0.1,0,0; 118740,0,0.1,0,0; 118800,0.6,0.6,1,1; 122340,0.6,0.6,1,1; 122400,1,1,1,1; 125940,1,1,1,1; 126000,0.4,0.4,1,1; 129540,0.4,0.4,1,1; 129600,0,0.1,0,0; 133140,0,0.1,0,0; 133200,0,0.1,0,0; 136740,0,0.1,0,0; 136800,0.6,0.6,1,1; 140340,0.6,0.6,1,1; 140400,1,1,1,1; 143940,1,1,1,1; 144000,0.4,0.4,1,1; 147540,0.4,0.4,1,1; 147600,0,0.1,0,0; 151140,0,0.1,0,0; 151200,0,0.1,0,0; 154740,0,0.1,0,0; 154800,0,0.1,0,0; 158340,0,0.1,0,0; 158400,0,0.1,0,0; 161940,0,0.1,0,0; 162000,0,0.1,0,0; 165540,0,0.1,0,0; 165600,0,0.1,0,0; 169140,0,0.1,0,0; 169200,0,0.1,0,0; 172740,0,0.1,0,0; 172800,0,0.1,0,0; 176340,0,0.1,0,0; 176400,0,0.1,0,0; 179940,0,0.1,0,0; 180000,0,0.1,0,0; 183540,0,0.1,0,0; 183600,0,0.1,0,0; 187140,0,0.1,0,0; 187200,0,0.1,0,0; 190740,0,0.1,0,0; 190800,0,0.1,0,0; 194340,0,0.1,0,0; 194400,0,0.1,0,0; 197940,0,0.1,0,0; 198000,0,0.1,0,0; 201540,0,0.1,0,0; 201600,0,0.1,
        0,0; 205140,0,0.1,0,0; 205200,0.6,0.6,1,1; 208740,0.6,0.6,1,1; 208800,1,1,1,1; 212340,1,1,1,1; 212400,0.4,0.4,1,1; 215940,0.4,0.4,1,1; 216000,0,0.1,0,0; 219540,0,0.1,0,0; 219600,0,0.1,0,0; 223140,0,0.1,0,0; 223200,0.6,0.6,1,1; 226740,0.6,0.6,1,1; 226800,1,1,1,1; 230340,1,1,1,1; 230400,0.4,0.4,1,1; 233940,0.4,0.4,1,1; 234000,0,0.1,0,0; 237540,0,0.1,0,0; 237600,0,0.1,0,0; 241140,0,0.1,0,0; 241200,0,0.1,0,0; 244740,0,0.1,0,0; 244800,0,0.1,0,0; 248340,0,0.1,0,0; 248400,0,0.1,0,0; 251940,0,0.1,0,0; 252000,0,0.1,0,0; 255540,0,0.1,0,0; 255600,0,0.1,0,0; 259140,0,0.1,0,0; 259200,0,0.1,0,0; 262740,0,0.1,0,0; 262800,0,0.1,0,0; 266340,0,0.1,0,0; 266400,0,0.1,0,0; 269940,0,0.1,0,0; 270000,0,0.1,0,0; 273540,0,0.1,0,0; 273600,0,0.1,0,0; 277140,0,0.1,0,0; 277200,0,0.1,0,0; 280740,0,0.1,0,0; 280800,0,0.1,0,0; 284340,0,0.1,0,0; 284400,0,0.1,0,0; 287940,0,0.1,0,0; 288000,0,0.1,0,0; 291540,0,0.1,0,0; 291600,0.6,0.6,1,1; 295140,0.6,0.6,1,1; 295200,1,1,1,1; 298740,1,1,1,1; 298800,0.4,0.4,1,1; 302340,
        0.4,0.4,1,1; 302400,0,0.1,0,0; 305940,0,0.1,0,0; 306000,0,0.1,0,0; 309540,0,0.1,0,0; 309600,0.6,0.6,1,1; 313140,0.6,0.6,1,1; 313200,1,1,1,1; 316740,1,1,1,1; 316800,0.4,0.4,1,1; 320340,0.4,0.4,1,1; 320400,0,0.1,0,0; 323940,0,0.1,0,0; 324000,0,0.1,0,0; 327540,0,0.1,0,0; 327600,0,0.1,0,0; 331140,0,0.1,0,0; 331200,0,0.1,0,0; 334740,0,0.1,0,0; 334800,0,0.1,0,0; 338340,0,0.1,0,0; 338400,0,0.1,0,0; 341940,0,0.1,0,0; 342000,0,0.1,0,0; 345540,0,0.1,0,0; 345600,0,0.1,0,0; 349140,0,0.1,0,0; 349200,0,0.1,0,0; 352740,0,0.1,0,0; 352800,0,0.1,0,0; 356340,0,0.1,0,0; 356400,0,0.1,0,0; 359940,0,0.1,0,0; 360000,0,0.1,0,0; 363540,0,0.1,0,0; 363600,0,0.1,0,0; 367140,0,0.1,0,0; 367200,0,0.1,0,0; 370740,0,0.1,0,0; 370800,0,0.1,0,0; 374340,0,0.1,0,0; 374400,0,0.1,0,0; 377940,0,0.1,0,0; 378000,0.6,0.6,1,1; 381540,0.6,0.6,1,1; 381600,1,1,1,1; 385140,1,1,1,1; 385200,0.4,0.4,1,1; 388740,0.4,0.4,1,1; 388800,0,0.1,0,0; 392340,0,0.1,0,0; 392400,0,0.1,0,0; 395940,0,0.1,0,0; 396000,0.6,0.6,1,1; 399540,0.6,0.6,
        1,1; 399600,1,1,1,1; 403140,1,1,1,1; 403200,0.4,0.4,1,1; 406740,0.4,0.4,1,1; 406800,0,0.1,0,0; 410340,0,0.1,0,0; 410400,0,0.1,0,0; 413940,0,0.1,0,0; 414000,0,0.1,0,0; 417540,0,0.1,0,0; 417600,0,0.1,0,0; 421140,0,0.1,0,0; 421200,0,0.1,0,0; 424740,0,0.1,0,0; 424800,0,0.1,0,0; 428340,0,0.1,0,0; 428400,0,0.1,0,0; 431940,0,0.1,0,0; 432000,0,0,0,0; 435540,0,0,0,0; 435600,0,0,0,0; 439140,0,0,0,0; 439200,0,0,0,0; 442740,0,0,0,0; 442800,0,0,0,0; 446340,0,0,0,0; 446400,0,0,0,0; 449940,0,0,0,0; 450000,0,0,0,0; 453540,0,0,0,0; 453600,0,0,0,0; 457140,0,0,0,0; 457200,0,0,0,0; 460740,0,0,0,0; 460800,0,0,0,0; 464340,0,0,0,0; 464400,0,0,0,0; 467940,0,0,0,0; 468000,0,0,0,0; 471540,0,0,0,0; 471600,0,0,0,0; 475140,0,0,0,0; 475200,0,0,0,0; 478740,0,0,0,0; 478800,0,0,0,0; 482340,0,0,0,0; 482400,0,0,0,0; 485940,0,0,0,0; 486000,0,0,0,0; 489540,0,0,0,0; 489600,0,0,0,0; 493140,0,0,0,0; 493200,0,0,0,0; 496740,0,0,0,0; 496800,0,0,0,0; 500340,0,0,0,0; 500400,0,0,0,0; 503940,0,0,0,0; 504000,0,0,0,0; 507540,
        0,0,0,0; 507600,0,0,0,0; 511140,0,0,0,0; 511200,0,0,0,0; 514740,0,0,0,0; 514800,0,0,0,0; 518340,0,0,0,0; 518400,0,0,0,0; 521940,0,0,0,0; 522000,0,0,0,0; 525540,0,0,0,0; 525600,0,0,0,0; 529140,0,0,0,0; 529200,0,0,0,0; 532740,0,0,0,0; 532800,0,0,0,0; 536340,0,0,0,0; 536400,0,0,0,0; 539940,0,0,0,0; 540000,0,0,0,0; 543540,0,0,0,0; 543600,0,0,0,0; 547140,0,0,0,0; 547200,0,0,0,0; 550740,0,0,0,0; 550800,0,0,0,0; 554340,0,0,0,0; 554400,0,0,0,0; 557940,0,0,0,0; 558000,0,0,0,0; 561540,0,0,0,0; 561600,0,0,0,0; 565140,0,0,0,0; 565200,0,0,0,0; 568740,0,0,0,0; 568800,0,0,0,0; 572340,0,0,0,0; 572400,0,0,0,0; 575940,0,0,0,0; 576000,0,0,0,0; 579540,0,0,0,0; 579600,0,0,0,0; 583140,0,0,0,0; 583200,0,0,0,0; 586740,0,0,0,0; 586800,0,0,0,0; 590340,0,0,0,0; 590400,0,0,0,0; 593940,0,0,0,0; 594000,0,0,0,0; 597540,0,0,0,0; 597600,0,0,0,0; 601140,0,0,0,0; 601200,0,0,0,0; 604740,0,0,0,0])
    "Table with profiles for internal gains"
  Controller.CtrAHUCO2 ctrAHUCO2(
    TFlowSet=293.15,
    relHumSupSet=0.4,
    minVflowPer=0.2,
    CO2set=900,
    useTwoFanCtr=false,
    kCO2=3000/3600,
    initType=Modelica.Blocks.Types.Init.InitialState)
  Utilities.Psychrometrics.Phi_pTX phi
  BoundaryConditions.WeatherData.Bus weaBus1
             "Weather data bus"
protected
  constant Modelica.Units.SI.MolarMass MolCO2=0.04401
    "molar mass of CO2";
  constant Modelica.Units.SI.MolarMass MolAir=0.028949
    "molar mass of air";

equation
  connect(genericAHU.port_a2, thermalZone.ports[1])
  connect(genericAHU.port_b1, thermalZone.ports[2])
  connect(SourcePreheater.ports[1], genericAHU.port_a3)
  connect(SinkPreheater.ports[1], genericAHU.port_b3)
  connect(SourceCooler.ports[1], genericAHU.port_a4)
  connect(SinkCooler.ports[1], genericAHU.port_b4)
  connect(SourceHeater.ports[1], genericAHU.port_a5)
  connect(SinkHeater.ports[1], genericAHU.port_b5)
  connect(out.ports[1], genericAHU.port_a1)
  connect(genericAHU.port_b2, boundaryExhaustAir.ports[1])
  connect(weaDat.weaBus, out.weaBus)
  connect(weaDat.weaBus, thermalZone.weaBus)
  connect(internalGains.y, thermalZone.intGains)
  connect(ctrAHUCO2.genericAHUBus, genericAHU.genericAHUBus)
  connect(thermalZone.CO2Con, ctrAHUCO2.CO2Mea)
  connect(thermalZone.X_w, phi.X_w)
  connect(thermalZone.TAir, phi.T)
  connect(weaDat.weaBus, weaBus1)
  connect(phi.p, weaBus1.pAtm)
end DemandControlledAHU;


within AixLib.Systems.ModularAHU.Examples;
model EONERC_AHU2
  "GenericAHU model with parameters of air-handling unit 2 of the E.ON ERC test hall"
  extends Modelica.Icons.Example;
  AixLib.Systems.ModularAHU.GenericAHU genericAHU(
    massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    preheater(
    T_start=288.15,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    redeclare HydraulicModules.Admix hydraulicModule(
      pipeModel="PlugFlowPipe",
      parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_28x1_5(),
      parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
      length=1,
      Kv=10,
      valveCharacteristic=
          AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=
          AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.13,0.205,0.566,
          0.813,0.88,0.91,0.95,1}, phi={0,0.001,0.002,0.176,0.60,0.75,0.97,0.98,
          1}), b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.1,0.2,
          0.25,0.52,0.8,0.9,0.95,1}, phi={0,0.001,0.002,0.022,0.53,0.96,0.98,
          0.99,1})),
      valve(use_inputFilter=true),
      pipe1(length=1.53),
      pipe2(length=0.54),
      pipe3(length=1.06),
      pipe4(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=
            0.48),
      pipe5(length=1.44, fac=16),
      pipe6(length=0.52),
      redeclare
        AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled
        PumpInterface(pumpParam=
            AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN25_H1_8_V9(),
          calculatePower=true)),
    tau=90 + 70,
    T_amb=293.15,
    dynamicHX(
      dp1_nominal=66,
      dp2_nominal=6000 + 8000,
      nNodes=5,
      dT_nom=43.9,
      Q_nom=57700)),
    redeclare package Medium1 = Media.Air,
    redeclare package Medium2 = Media.Water,
    T_amb=293.15,
    m1_flow_nominal=1,
    m2_flow_nominal=0.5,
    usePreheater=true,
    useHumidifierRet=false,
    useHumidifier=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    cooler(
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    redeclare HydraulicModules.Admix hydraulicModule(
      pipeModel="PlugFlowPipe",
      parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
      parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
      length=1,
      Kv=10,
      T_start=294.75,
      valveCharacteristic=
          AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=
          AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.07,0.12,0.45,0.65,
          0.89,0.93,0.96,1}, phi={0,0.001,0.002,0.08,0.29,0.75,0.94,0.98,1}),
          b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0,0.1,0.2,0.26,
          0.52,0.8,0.9,0.95,1}, phi={0,0.001,0.002,0.05,0.45,0.96,0.98,0.99,1})),
      valve(use_inputFilter=true),
      pipe1(
        T_start=283.15,
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_54x2(),
        length=4.5),
      pipe2(length=1.55),
      pipe3(length=0.9),
      pipe4(length=0.3),
      pipe5(length=2.95, fac=13),
      pipe6(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_22x1_1(), length=
            0.5),
      redeclare
        AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled
        PumpInterface(pumpParam=
            AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN32(),
          calculatePower=true)),
    T_start=293.65,
    tau=90,
    T_amb=296.65,
    dynamicHX(
      dp1_nominal(displayUnit="bar") = 138,
      dp2_nominal(displayUnit="bar") = 70600,
      nNodes=4,
      T1_start=305.15,
      dT_nom=22.16,
      Q_nom=53400)),
    heater(
    T_start=285.65,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    redeclare HydraulicModules.Admix hydraulicModule(
      pipeModel="PlugFlowPipe",
      parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_22x1(),
      parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
      length=1,
      Kv=6.3,
      valveCharacteristic=
          AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(a_ab=
          AixLib.Fluid.Actuators.Valves.Data.Generic(y={0.0,0.14,0.24,0.43,0.68,
          0.81,0.93,0.96,1.0}, phi={0.0,0.001,0.002,0.02,0.1,0.25,0.76,0.98,1.0}),
          b_ab=AixLib.Fluid.Actuators.Valves.Data.Generic(y={0.0,0.02,0.05,0.08,
          0.27,0.6,0.95,1.0}, phi={0.0,0.001,0.002,0.01,0.3,0.9,0.97,1.0})),
      valve(use_inputFilter=false),
      pipe1(length=2.8, fac=9),
      pipe2(length=0.63, parameterPipe=
            AixLib.DataBase.Pipes.Copper.Copper_35x1_5()),
      pipe3(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=1.85),
      pipe4(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(), length=0.4),
      pipe5(length=3.2, fac=10),
      pipe6(parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_16x1(), length=0.82),
      redeclare
        AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_PumpSpeedControlled
        PumpInterface(pumpParam=
            AixLib.DataBase.Pumps.PumpPolynomialBased.Pump_DN25_H1_8_V5(),
          calculatePower=true)),
    tau=90,
    T_amb=293.15,
    dynamicHX(
      dp1_nominal=33,
      dp2_nominal=4500 + 55000,
      nNodes=4,
      dT_nom=40.1,
      Q_nom=22300)),
    dynamicHX(
      dp1_nominal=220,
      dp2_nominal=220,
      dT_nom=1,
      Q_nom=1100),
    humidifier(
      dp_nominal=100,
      mWat_flow_nominal=1,
      TLiqWat_in=288.15),
    humidifierRet(
      dp_nominal=100,
      mWat_flow_nominal=0.5,
      TLiqWat_in=288.15))

  Fluid.Sources.Boundary_pT boundaryOutsideAir(
    nPorts=1,
    redeclare package Medium = Media.Air,
    T=283.15)
  Fluid.Sources.Boundary_pT boundarySupplyAir(nPorts=1, redeclare package
      Medium = Media.Air)
  Fluid.Sources.Boundary_pT boundaryExhaustAir(nPorts=1, redeclare package
      Medium = Media.Air)
  Fluid.Sources.Boundary_pT boundaryReturnAir(
    T=293.15,
    nPorts=1,
    redeclare package Medium = Media.Air)
  Fluid.Sources.Boundary_pT SourcePreheater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkPreheater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    p=102000,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceCooler(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=283.15)
  Fluid.Sources.Boundary_pT SinkCooler(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceHeater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkHeater(nPorts=1, redeclare package Medium =
        Media.Water)
  Controller.CtrAHUBasic ctrAHUBasic(
    TFlowSet=293.15,
    useExternalTset=false,
    useTwoFanCtr=true,
    initType=Modelica.Blocks.Types.Init.InitialState,
    ctrRh(k=0.01))
equation
  connect(boundaryReturnAir.ports[1], genericAHU.port_a2)
  connect(boundarySupplyAir.ports[1], genericAHU.port_b1)
  connect(boundaryOutsideAir.ports[1], genericAHU.port_a1)
  connect(boundaryExhaustAir.ports[1], genericAHU.port_b2)
  connect(SourcePreheater.ports[1], genericAHU.port_a3)
  connect(SinkPreheater.ports[1], genericAHU.port_b3)
  connect(SourceCooler.ports[1], genericAHU.port_a4)
  connect(SinkCooler.ports[1], genericAHU.port_b4)
  connect(SourceHeater.ports[1], genericAHU.port_a5)
  connect(SinkHeater.ports[1], genericAHU.port_b5)
  connect(ctrAHUBasic.genericAHUBus, genericAHU.genericAHUBus)
end EONERC_AHU2;


Example of generic ahu model

within AixLib.Systems.ModularAHU.Examples;
model GenericAHU "Example of generic ahu model"
  extends Modelica.Icons.Example;
  AixLib.Systems.ModularAHU.GenericAHU genericAHU(
    massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    hydraulicEfficiency(V_flow={0,1000}, eta={0.7,0.7}),
    preheater(redeclare AixLib.Systems.HydraulicModules.Admix hydraulicModule(
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
        length=1,
        Kv=6.3,
        valveCharacteristic=
            AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
        redeclare
          AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
          PumpInterface(speed_rpm_nominal=3040, pump(redeclare
              AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to8 per))),
        dynamicHX(
        dp1_nominal=50,
        dp2_nominal=5000,
        tau1=5,
        tau2=15,
        dT_nom=30,
        Q_nom=30000)),
    redeclare package Medium1 = AixLib.Media.Air,
    redeclare package Medium2 = AixLib.Media.Water,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    T_amb=293.15,
    m1_flow_nominal=3000/3600*1.2,
    m2_flow_nominal=0.5,
    T_start=293.15,
    usePreheater=true,
    useHumidifierRet=true,
    useHumidifier=true,
    cooler(redeclare AixLib.Systems.HydraulicModules.Admix hydraulicModule(
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
        length=1,
        Kv=6.3,
        valveCharacteristic=
            AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
        redeclare
          AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
          PumpInterface(speed_rpm_nominal=3690, pump(redeclare
              AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos50slash1to12 per))),
        dynamicHX(
        dp1_nominal=80,
        dp2_nominal=1000,
        tau1=5,
        tau2=10,
        dT_nom=30,
        Q_nom=50000)),
    heater(redeclare AixLib.Systems.HydraulicModules.Admix hydraulicModule(
        parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
        length=1,
        Kv=6.3,
        valveCharacteristic=
            AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
        redeclare
          AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
          PumpInterface(speed_rpm_nominal=3040, pump(redeclare
              AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to8 per))),
        dynamicHX(
        dp1_nominal=50,
        dp2_nominal=5000,
        tau1=5,
        tau2=15,
        dT_nom=30,
        Q_nom=30000)),
    dynamicHX(
      dp1_nominal=200,
      dp2_nominal=200,
      dT_nom=2,
      Q_nom=30000),
    humidifier(
      dp_nominal=20,
      mWat_flow_nominal=1,
      TLiqWat_in=288.15),
    humidifierRet(
      dp_nominal=20,
      mWat_flow_nominal=0.5,
      TLiqWat_in=288.15))
  Fluid.Sources.Boundary_pT boundaryOutsideAir(
    nPorts=1,
    redeclare package Medium = Media.Air,
    T=283.15)
  Fluid.Sources.Boundary_pT boundarySupplyAir(nPorts=1, redeclare package
      Medium = Media.Air)
  Fluid.Sources.Boundary_pT boundaryExhaustAir(nPorts=1, redeclare package
      Medium = Media.Air)
  Fluid.Sources.Boundary_pT boundaryReturnAir(
    T=294.15,
    nPorts=1,
    redeclare package Medium = Media.Air)
  Fluid.Sources.Boundary_pT SourcePreheater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkPreheater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    p=102000,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceCooler(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=283.15)
  Fluid.Sources.Boundary_pT SinkCooler(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=283.15)
  Fluid.Sources.Boundary_pT SourceHeater(
    nPorts=1,
    redeclare package Medium = Media.Water,
    T=333.15)
  Fluid.Sources.Boundary_pT SinkHeater(nPorts=1, redeclare package Medium =
        Media.Water)
  Controller.CtrAHUBasic ctrAHUBasic(
    TFlowSet=293.15,
    usePreheater=true,
    useTwoFanCtr=true,
    VFlowSet=3000/3600,
    initType=Modelica.Blocks.Types.Init.InitialState, ctrRh(k=0.01))
equation
  connect(boundaryReturnAir.ports[1], genericAHU.port_a2)
  connect(boundarySupplyAir.ports[1], genericAHU.port_b1)
  connect(boundaryOutsideAir.ports[1], genericAHU.port_a1)
  connect(boundaryExhaustAir.ports[1], genericAHU.port_b2)
  connect(SourcePreheater.ports[1], genericAHU.port_a3)
  connect(SinkPreheater.ports[1], genericAHU.port_b3)
  connect(SourceCooler.ports[1], genericAHU.port_a4)
  connect(SinkCooler.ports[1], genericAHU.port_b4)
  connect(SourceHeater.ports[1], genericAHU.port_a5)
  connect(SinkHeater.ports[1], genericAHU.port_b5)
  connect(ctrAHUBasic.genericAHUBus, genericAHU.genericAHUBus)
end GenericAHU;


Heating register

within AixLib.Systems.ModularAHU.Examples;
model Heater "Heating register"
  extends Modelica.Icons.Example;
    package MediumWater = AixLib.Media.Water
  package MediumAir = AixLib.Media.Air

  RegisterModule registerModule(
    redeclare HydraulicModules.Admix hydraulicModule(
      parameterPipe=AixLib.DataBase.Pipes.Copper.Copper_35x1_5(),
      parameterIso=AixLib.DataBase.Pipes.Insulation.Iso25pc(),
      length=1,
      Kv=6.3,
      valveCharacteristic=
          AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage(),
      redeclare
        AixLib.Systems.HydraulicModules.BaseClasses.PumpInterface_SpeedControlledNrpm
        PumpInterface(speed_rpm_nominal=1800, pump(redeclare
            AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to4 per))),
    redeclare package Medium2 = MediumWater,
    redeclare package Medium1 = MediumAir,
    T_amb=293.15,
    dynamicHX(
      Q_nom=30000,
      dT_nom=20,
      dp1_nominal=100,
      dp2_nominal=6000),
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
    hydraulicModuleIcon="Admix",
    m1_flow_nominal=1,
    m2_flow_nominal=0.1,
    massDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial)

  Fluid.Sources.Boundary_pT boundaryWaterSource(
    nPorts=1,
    redeclare package Medium = MediumWater,
    T=343.15)
  Fluid.Sources.Boundary_pT boundaryWaterSink(nPorts=1, redeclare package Medium =
               MediumWater)
  Fluid.Sources.Boundary_pT boundaryAirSource(
    nPorts=1,
    redeclare package Medium = MediumAir,
    p=102000,
    T=283.15)
  Fluid.Sources.Boundary_pT boundaryAirSink(nPorts=1, redeclare package Medium =
        MediumAir)
  Controller.CtrRegBasic ctrBasic(
    k=0.04,
    Ti=100,
    Td=1,
    useExternalTset=false,
    TflowSet=293.15,
    initType=Modelica.Blocks.Types.Init.InitialOutput)
equation
  connect(boundaryWaterSink.ports[1], registerModule.port_b2)
  connect(boundaryWaterSource.ports[1], registerModule.port_a2)
  connect(registerModule.port_b1, boundaryAirSink.ports[1])
  connect(registerModule.port_a1, boundaryAirSource.ports[1])
  connect(ctrBasic.registerBus, registerModule.registerBus)
end Heater;


This package contains examples

within AixLib.Systems.ModularAHU;
package Examples "This package contains examples"
extends Modelica.Icons.ExamplesPackage;

end Examples;