within AixLib.Obsolete.Year2024.Systems.HeatPumpSystems.BaseClasses;
partial model PartialHeatPumpSystem
  "Partial model containing the basic heat pump block and different control blocks(optional)"
    extends AixLib.Fluid.Interfaces.PartialFourPortInterface(
    redeclare final package Medium1 = Medium_con,
    final m1_flow_nominal=mFlow_conNominal,
    final m2_flow_nominal=mFlow_evaNominal,
    final allowFlowReversal1=allowFlowReversalCon,
    final allowFlowReversal2=allowFlowReversalEva,
    final m1_flow_small=1E-4*abs(mFlow_conNominal),
    final m2_flow_small=1E-4*abs(mFlow_evaNominal),
    final show_T=false,
    redeclare package Medium2 = Medium_eva);
  import Modelica.Blocks.Types.Init;
  extends AixLib.Obsolete.Year2024.Systems.HeatPumpSystems.BaseClasses.HeatPumpSystemParameters(
   cpCon = Medium_con.heatCapacity_cp(stateCon_default),
   cpEva = Medium_eva.heatCapacity_cp(stateEva_default));

//General
  replaceable package Medium_con = Modelica.Media.Interfaces.PartialMedium "Medium at sink side"
  replaceable package Medium_eva = Modelica.Media.Interfaces.PartialMedium "Medium at source side"
  parameter Modelica.Units.SI.MassFlowRate mFlow_conNominal
    "Nominal mass flow rate, used for regularization near zero flow"
  parameter Modelica.Units.SI.MassFlowRate mFlow_evaNominal
    "Nominal mass flow rate"
  final parameter Medium_con.ThermodynamicState stateCon_default = Medium_con.setState_pTX(
    T=Medium_con.T_default,
    p=Medium_con.p_default,
    X=Medium_con.X_default[1:Medium_con.nXi])
    "Medium state in condenser at default values";
  final parameter Medium_eva.ThermodynamicState stateEva_default = Medium_eva.setState_pTX(
    T=Medium_eva.T_default,
    p=Medium_eva.p_default,
    X=Medium_eva.X_default[1:Medium_eva.nXi])
    "Medium state in evaporator at default values";
  parameter Boolean use_secHeaGen=true "True if a bivalent setup is required"

  replaceable model SecHeatGen = AixLib.Fluid.HeatExchangers.HeaterCooler_u
  parameter Modelica.Units.SI.HeatFlowRate Q_flow_nominal
    "Nominal heat flow rate of second heat generator. Used to calculate input singal y."
  parameter Boolean use_conPum=true
    "True if pump or fan at condenser side are included into this model"
  parameter Boolean use_evaPum=true
    "True if pump or fan at evaporator side are included into this model"
  replaceable parameter AixLib.Fluid.Movers.Data.Generic perEva
    constrainedby AixLib.Fluid.Movers.Data.Generic
    "Record with performance data"
  replaceable parameter AixLib.Fluid.Movers.Data.Generic perCon
    constrainedby AixLib.Fluid.Movers.Data.Generic
    "Record with performance data"

//HeatPump Control
  replaceable model TSetToNSet = AixLib.Controls.HeatPump.TwoPointControlledHP
    constrainedby AixLib.Controls.HeatPump.BaseClasses.PartialTSetToNSet
  parameter Boolean use_tableData=true
    "Choose between tables or function to calculate TSet"
  replaceable function HeatingCurveFunction =
      AixLib.Controls.SetPoints.Functions.HeatingCurveFunction

  parameter
    AixLib.DataBase.Boiler.DayNightMode.HeatingCurvesDayNightBaseDataDefinition
    heatingCurveRecord=
      AixLib.DataBase.Boiler.DayNightMode.HeatingCurves_Vitotronic_Day25_Night10()
         "Record with information about heating curve data"
  parameter Real declination=2 "Declination of heating curve"
  parameter Real day_hour=6 "Hour of day at which day mode is enabled"
  parameter Real night_hour=22 "Hour of day at which night mode is enabled"
  parameter AixLib.Utilities.Time.Types.ZeroTime zerTim=AixLib.Utilities.Time.Types.ZeroTime.NY2017
    "Enumeration for choosing how reference time (time = 0) should be defined. Used for heating curve and antilegionella"
  parameter Boolean use_antLeg=true
    "True if Anti-Legionella control is considered"
  parameter Modelica.Units.SI.ThermodynamicTemperature TLegMin=333.15
    "Temperature at which the legionella in DWH dies"
  parameter Modelica.Units.SI.Time minTimeAntLeg
    "Minimal duration of antilegionella control"
  parameter Boolean weekly=true
    "Switch between a daily or weekly trigger approach"
  parameter Integer trigWeekDay=5
    "Day of the week at which control is triggered"
  parameter Integer trigHour=3 "Hour of the day at which control is triggered"
//Safety Control
  parameter Boolean use_sec=true
    "False if the Safety block should be disabled"
  parameter Boolean use_minRunTime=false
    "False if minimal runtime of HP is not considered"
  parameter Modelica.Units.SI.Time minRunTime=300
    "Minimum runtime of heat pump"
  parameter Boolean use_minLocTime=false
    "False if minimal locktime of HP is not considered"
  parameter Modelica.Units.SI.Time minLocTime=300
    "Minimum lock time of heat pump"
  parameter Boolean use_runPerHou=false
    "False if maximal runs per hour of HP are not considered"
  parameter Integer maxRunPerHou=3
                              "Maximal number of on/off cycles in one hour"
  parameter Boolean pre_n_start=false
                                     "Start value of pre(n) at initial time"
  parameter Boolean use_opeEnv=true
    "False to allow HP to run out of operational envelope"
  parameter Boolean use_opeEnvFroRec=false
    "Use a the operational envelope given in the datasheet"
  parameter Obsolete.Year2024.DataBase.HeatPump.HeatPumpBaseDataDefinition
    dataTable "Data Table of HP"
  parameter Real tableUpp[:,2]=[0,60; 5,70; 30,70]
                               "Upper boundary of envelope"
  parameter Modelica.Units.SI.TemperatureDifference dTHystOperEnv=5
    "Temperature difference used for both upper and lower hysteresis in the operational envelope."
  parameter Boolean use_deFro=true "False if defrost in not considered"
  parameter Real minIceFac "Minimal value above which no defrost is necessary"
  parameter Real deltaIceFac = 0.1 "Bandwitdth for hystereses. If the icing factor is based on the duration of defrost, this value is necessary to avoid state-events."
  parameter Boolean use_chiller=false
    "True if defrost operates by changing mode to cooling. False to use an electrical heater"
  parameter Modelica.Units.SI.Power calcPel_deFro
    "Calculate how much eletrical energy is used to melt ice"
  parameter Boolean use_antFre=false
    "True if anti freeze control is part of safety control"
  parameter Modelica.Units.SI.ThermodynamicTemperature TantFre=276.15
    "Limit temperature for anti freeze control"
//Initialization
  parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.InitialState
    "Type of initialization (InitialState and InitialOutput are identical)"
  parameter Modelica.Media.Interfaces.Types.AbsolutePressure pCon_start=
      Medium_con.p_default "Start value of pressure"
  parameter Modelica.Media.Interfaces.Types.Temperature TCon_start=Medium_con.T_default
    "Start value of temperature"
  parameter Modelica.Media.Interfaces.Types.MassFraction XCon_start[Medium_con.nX]=
     Medium_con.X_default "Start value of mass fractions m_i/m"
  parameter Modelica.Media.Interfaces.Types.AbsolutePressure pEva_start=
      Medium_eva.p_default "Start value of pressure"
  parameter Modelica.Media.Interfaces.Types.Temperature TEva_start=Medium_eva.T_default
    "Start value of temperature"
  parameter Modelica.Media.Interfaces.Types.MassFraction XEva_start[Medium_eva.nX]=
     Medium_eva.X_default "Start value of mass fractions m_i/m"

//Dynamics
  parameter Modelica.Fluid.Types.Dynamics massDynamics
    "Type of mass balance: dynamic (3 initialization options) or steady state (only affects fluid-models)"
  parameter Modelica.Fluid.Types.Dynamics energyDynamics
    "Type of energy balance: dynamic (3 initialization options) or steady state (only affects fluid-models)"
//Assumptions
  parameter Modelica.Units.SI.Time tauSenT=1
    "Time constant at nominal flow rate (use tau=0 for steady-state sensor, but see user guide for potential problems)"
  parameter Boolean transferHeat=true
    "If true, temperature T converges towards TAmb when no flow"
  parameter Boolean allowFlowReversalEva=false
    "= false to simplify equations, assuming, but not enforcing, no flow reversal"
  parameter Boolean allowFlowReversalCon=false
    "= false to simplify equations, assuming, but not enforcing, no flow reversal"
  parameter Boolean addPowerToMediumEva=true
    "Set to false to avoid any power (=heat and flow work) being added to medium (may give simpler equations)"
  parameter Boolean addPowerToMediumCon=true
    "Set to false to avoid any power (=heat and flow work) being added to medium (may give simpler equations)"

  parameter Modelica.Units.SI.Time tauHeaTraEva=1200
    "Time constant for heat transfer in temperature sensors in evaporator, default 20 minutes"
  parameter Modelica.Units.SI.Temperature TAmbEva_nominal=273.15
    "Fixed ambient temperature for heat transfer of sensors at the evaporator side"
  parameter Modelica.Units.SI.Time tauHeaTraCon=1200
    "Time constant for heat transfer in temperature sensors in condenser, default 20 minutes"
  parameter Modelica.Units.SI.Temperature TAmbCon_nominal=291.15
    "Fixed ambient temperature for heat transfer of sensors at the condenser side"

  replaceable AixLib.Fluid.Interfaces.PartialFourPortInterface heatPump
    constrainedby AixLib.Fluid.Interfaces.PartialFourPortInterface
  AixLib.Fluid.Movers.SpeedControlled_y pumSin(
    redeclare final package Medium = Medium_con,
    final energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final p_start=pCon_start,
    final T_start=TCon_start,
    final X_start=XCon_start,
    final allowFlowReversal=allowFlowReversalCon,
    final m_flow_small=1E-4*abs(mFlow_conNominal),
    final init=initType,
    final addPowerToMedium=addPowerToMediumCon,
    final per=perCon,
    final inputType=AixLib.Fluid.Types.InputType.Continuous) if use_conPum
    "Fan or pump at sink side of HP"
  AixLib.Fluid.Movers.SpeedControlled_y pumSou(
    redeclare package Medium = Medium_eva,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final p_start=pEva_start,
    final T_start=TEva_start,
    final X_start=XEva_start,
    final allowFlowReversal=allowFlowReversalEva,
    final m_flow_small=1E-4*abs(mFlow_evaNominal),
    final init=initType,
    final addPowerToMedium=addPowerToMediumEva,
    final per=perEva,
    final inputType=AixLib.Fluid.Types.InputType.Continuous) if use_evaPum
    "Fan or pump at source side of HP"

  Modelica.Blocks.Interfaces.RealInput T_oda(unit="K")
    "Outdoor air temperature"
  AixLib.Fluid.Interfaces.PassThroughMedium mediumPassThroughSin(
    final allowFlowReversal=allowFlowReversalEva,
    redeclare final package Medium = Medium_con)
                                           if not use_conPum
  AixLib.Fluid.Interfaces.PassThroughMedium mediumPassThroughSou(
    final allowFlowReversal=allowFlowReversalCon,
    redeclare final package Medium = Medium_eva)
                                           if not use_evaPum
  SecHeatGen secHeaGen(
    redeclare final package Medium = Medium_con,
    final allowFlowReversal=allowFlowReversalCon,
    final m_flow_nominal=mFlow_conNominal,
    final dp_nominal=0,
    final m_flow_small=1E-4*abs(mFlow_conNominal),
    final Q_flow_nominal=Q_flow_nominal,
    final energyDynamics=energyDynamics) if use_secHeaGen

  AixLib.Fluid.Interfaces.PassThroughMedium mediumPassThroughSecHeaGen(
    final allowFlowReversal=allowFlowReversalEva,
    redeclare final package Medium = Medium_con)
                                           if not use_secHeaGen
    "Used if monovalent HP System"

  AixLib.Obsolete.Year2024.Systems.HeatPumpSystems.BaseClasses.HPSystemController hPSystemController(
    final use_secHeaGen=use_secHeaGen,
    final heatingCurveRecord=heatingCurveRecord,
    final declination=declination,
    final day_hour=day_hour,
    final night_hour=night_hour,
    final zerTim=zerTim,
    final use_antLeg=use_antLeg,
    final TLegMin=TLegMin,
    final minTimeAntLeg=minTimeAntLeg,
    final trigWeekDay=trigWeekDay,
    final trigHour=trigHour,
    redeclare final model TSetToNSet = TSetToNSet,
    final use_tableData=use_tableData,
    redeclare final function HeatingCurveFunction = HeatingCurveFunction,
    final use_sec=use_sec,
    final use_minRunTime=use_minRunTime,
    final minRunTime=minRunTime,
    final use_minLocTime=use_minLocTime,
    final minLocTime=minLocTime,
    final pre_n_start=pre_n_start,
    final use_opeEnv=use_opeEnv,
    final use_opeEnvFroRec=use_opeEnvFroRec,
    final dataTable=dataTable,
    final tableUpp=tableUpp,
    final dTHystOperEnv=dTHystOperEnv,
    final use_deFro=use_deFro,
    final minIceFac=minIceFac,
    final deltaIceFac=deltaIceFac,
    final use_chiller=use_chiller,
    final calcPel_deFro=calcPel_deFro,
    final use_antFre=use_antFre,
    final TantFre=TantFre,
    final use_runPerHou=use_runPerHou,
    final maxRunPerHou=maxRunPerHou,
    final cp_con=cpCon)
  Modelica.Blocks.Interfaces.RealInput TAct(unit="K")
    "Supply temperature for controls"
equation
  connect(pumSin.port_b, heatPump.port_a1)

  connect(pumSou.port_b, heatPump.port_a2)
  connect(mediumPassThroughSin.port_b, heatPump.port_a1)
  connect(mediumPassThroughSou.port_b, heatPump.port_a2)
  connect(heatPump.port_b1, secHeaGen.port_a)
  connect(heatPump.port_b1, mediumPassThroughSecHeaGen.port_a)
  connect(heatPump.port_b2, port_b2)
connect(pumSou.port_a, port_a2)
  connect(mediumPassThroughSou.port_a, port_a2)
  connect(port_a1, pumSin.port_a)
  connect(mediumPassThroughSin.port_a, port_a1)
  connect(port_b1, port_b1)
  connect(T_oda, hPSystemController.T_oda)
  connect(hPSystemController.y_sou, pumSin.y)
  connect(hPSystemController.ySecHeaGen, secHeaGen.u)
  connect(hPSystemController.y_sin, pumSou.y)
  connect(secHeaGen.port_b, port_b1)
  connect(mediumPassThroughSecHeaGen.port_b, port_b1)
  connect(TAct, hPSystemController.TSup)
end PartialHeatPumpSystem;


Example for a heat pump system

within AixLib.Obsolete.Year2024.Systems.HeatPumpSystems.Examples;
model HeatPumpSystem "Example for a heat pump system"
  package Medium_sin = AixLib.Media.Water;
  package Medium_sou = AixLib.Media.Water;
  AixLib.Fluid.MixingVolumes.MixingVolume vol(
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    redeclare package Medium = Modelica.Media.Air.SimpleAir,
    V=40,
    m_flow_nominal=40*6/3600,
    T_start=293.15)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=10000/40)
    "Thermal conductance with the ambient"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHea
    "Prescribed heat flow"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCap(C=2*40*1.2*1006)
    "Heat capacity for furniture and walls"
  Modelica.Blocks.Sources.CombiTimeTable timTab(
      extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
      smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    table=[-6*3600,0; 8*3600,4000; 18*3600,0])
                          "Time table for internal heat gain"
  AixLib.Fluid.HeatExchangers.Radiators.RadiatorEN442_2 rad(
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    T_a_nominal(displayUnit="degC") = 323.15,
    dp_nominal=0,
    m_flow_nominal=20000/4180/5,
    Q_flow_nominal=20000,
    redeclare package Medium = Medium_sin,
    T_start=313.15,
    T_b_nominal=318.15,
    TAir_nominal=293.15,
    TRad_nominal=293.15)         "Radiator"

  AixLib.Fluid.Sources.Boundary_pT preSou(
    redeclare package Medium = Medium_sin,
    nPorts=1,
    T=313.15)
    "Source for pressure and to account for thermal expansion of water"

  AixLib.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
        Modelica.Utilities.Files.loadResource(
        "modelica://AixLib/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data reader"
  AixLib.BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature TOut
    "Outside temperature"
  AixLib.Fluid.Sources.Boundary_pT sou(
    nPorts=1,
    redeclare package Medium = Medium_sou,
    p=200000,
    T=283.15) "Fluid source on source side"

  AixLib.Fluid.Sources.Boundary_pT sin(
    nPorts=1,
    redeclare package Medium = Medium_sou,
    p=200000,
    T=281.15) "Fluid sink on source side"
  AixLib.Obsolete.Year2024.Systems.HeatPumpSystems.HeatPumpSystem heatPumpSystem(
    redeclare package Medium_con = Medium_sin,
    redeclare package Medium_eva = Medium_sou,
    dataTable=AixLib.Obsolete.Year2024.DataBase.HeatPump.EN255.Vitocal350BWH113(),
    use_deFro=false,
    massDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    refIneFre_constant=0.01,
    dpEva_nominal=0,
    deltaM_con=0.1,
    use_opeEnvFroRec=true,
    tableUpp=[-100,100; 100,100],
    minIceFac=0,
    use_chiller=true,
    calcPel_deFro=100,
    minRunTime(displayUnit="min"),
    minLocTime(displayUnit="min"),
    use_antLeg=false,
    use_refIne=true,
    initType=Modelica.Blocks.Types.Init.InitialOutput,
    minTimeAntLeg(displayUnit="min") = 900,
    scalingFactor=1,
    use_tableData=false,
    dpCon_nominal=0,
    use_conCap=true,
    CCon=3000,
    use_evaCap=true,
    CEva=3000,
    Q_flow_nominal=5000,
    cpEva=4180,
    cpCon=4180,
    use_secHeaGen=false,
    redeclare model TSetToNSet = AixLib.Controls.HeatPump.TwoPointControlledHP
        (bandwidth=5),
    use_sec=true,
    QCon_nominal=10000,
    P_el_nominal=2500,
    redeclare model PerDataHea =
        AixLib.Obsolete.Year2024.DataBase.HeatPump.PerformanceData.LookUpTable2D
        (
        smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments,
        dataTable=
            AixLib.Obsolete.Year2024.DataBase.HeatPump.EN255.Vitocal350BWH113(
            tableP_ele=[0,-5.0,0.0,5.0,10.0,15.0; 35,3750,3750,3750,3750,3833;
            45,4833,4917,4958,5042,5125; 55,5583,5667,5750,5833,5958; 65,7000,
            7125,7250,7417,7583]),
        printAsserts=false,
        extrapolation=false),
    redeclare function HeatingCurveFunction =
        AixLib.Controls.SetPoints.Functions.HeatingCurveFunction (TDesign=328.15),
    use_minRunTime=true,
    use_minLocTime=true,
    use_runPerHou=true,
    pre_n_start=true,
    redeclare AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos80slash1to12 perEva,
    redeclare AixLib.Fluid.Movers.Data.Pumps.Wilo.Stratos25slash1to4 perCon,
    TCon_nominal=313.15,
    TCon_start=313.15,
    TEva_start=283.15,
    use_revHP=false,
    VCon=0.004,
    VEva=0.004)

  AixLib.Fluid.Sensors.TemperatureTwoPort
                             senT_a1(
    redeclare final package Medium = Medium_sin,
    final m_flow_nominal=1,
    final transferHeat=true,
    final allowFlowReversal=true)
                                "Temperature at sink inlet"
equation
  connect(theCon.port_b,vol. heatPort)
  connect(preHea.port,vol. heatPort)
  connect(heaCap.port,vol. heatPort)
  connect(timTab.y[1],preHea. Q_flow)
  connect(rad.heatPortCon,vol. heatPort)
  connect(rad.heatPortRad,vol. heatPort)
  connect(weaDat.weaBus,weaBus)
  connect(weaBus.TDryBul,TOut. T)
  connect(TOut.port,theCon. port_a)
  connect(sou.ports[1], heatPumpSystem.port_a2)
  connect(sin.ports[1], heatPumpSystem.port_b2)
  connect(weaBus.TDryBul, heatPumpSystem.T_oda)
  connect(senT_a1.port_a, heatPumpSystem.port_b1)
  connect(senT_a1.port_b, rad.port_a)
  connect(senT_a1.T, heatPumpSystem.TAct)
  connect(rad.port_b, heatPumpSystem.port_a1)
  connect(rad.port_b, preSou.ports[1])
end HeatPumpSystem;


within AixLib.Obsolete.Year2024.Systems.HeatPumpSystems;
package Examples "Package with Examples for Heat Pump Systems"
end Examples;


Fluidsource for sink.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Chiller;
model Chiller
  extends Modelica.Icons.Example;
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor
  FastHVAC.Components.Pumps.FluidSource fluidSource(medium=
        FastHVAC.Media.WaterSimple()) "Fluidsource for sink"
  Components.Chiller.Chiller chiller(
    use_revChi=true,
    redeclare model PerDataMainChi =
        AixLib.Obsolete.Year2024.DataBase.Chiller.PerformanceData.LookUpTable2D (
          dataTable=AixLib.Obsolete.Year2024.DataBase.Chiller.EN14511.Vitocal200AWO201()),
    redeclare model PerDataRevChi =
        AixLib.Obsolete.Year2024.DataBase.HeatPump.PerformanceData.LookUpTable2D (
          smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments, dataTable=
           AixLib.Obsolete.Year2024.DataBase.HeatPump.EN14511.Vitocal200AWO201()),
    Q_useNominal=0,
    use_autoCalc=false,
    refIneFre_constant=1,
    Medium_con=Media.WaterSimple(),
    Medium_eva=Media.WaterSimple(),
    mFlow_conNominal=0.5,
    VCon=0.04,
    deltaM_con=0.1,
    use_ConCap=false,
    CCon=100,
    GCon=5,
    mFlow_evaNominal=0.5,
    VEva=0.4,
    deltaM_eva=0.1,
    use_EvaCap=false,
    CEva=100,
    GEva=5,
    allowFlowReversalEva=true,
    TCon_start(displayUnit="K"),
    TEva_start(displayUnit="K"),
    TAmbCon_nominal=273.15,
    TAmbEva_nominal=288.15)
  FastHVAC.Components.Sinks.Vessel vessel_ev
    "vessel for open evaporator circuit"
  Modelica.Blocks.Sources.Constant dotm_sink(k=1) "Sink mass flow signal"
  Modelica.Blocks.Sources.Constant dotm_source(k=0.106)
    "source mass flow signal"
  Modelica.Blocks.Sources.Constant iceFac(final k=1)
    "Fixed value for icing factor. 1 means no icing/frosting (full heat transfer in heat exchanger)"
  Modelica.Blocks.Sources.Constant T_amb_internal(k=291.15)
    "Constant internal ambient temeprature"
  Modelica.Blocks.Sources.Ramp TsuSinkRamp(
    duration=1000,
    startTime=1000,
    height=25,
    offset=278)
    "Ramp signal for the temperature input of the sink side's ideal mass flow source"
  BaseClasses.WorkingFluid Room(m_fluid=5*1000, T0=293.15) "Volume"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heatFlowRateCon
    "Heat flow rate of the condenser"
  Modelica.Blocks.Math.Gain gain(k=1)  "negate sine signal"
  Modelica.Blocks.Sources.Sine sine(
    f=1/3600,
    amplitude=500,
    phase=3.1415926535898,
    offset=500) "hourly sine "
  Components.Pumps.Pump pump "source pump"
  Modelica.Blocks.Math.BooleanToReal booleanToReal
  Modelica.Blocks.Logical.Hysteresis hysCooling(
    pre_y_start=false,
    uHigh=273.15 + 17,
    uLow=273.15 + 14)
  Modelica.Blocks.Sources.BooleanStep     booleanStep(
      startValue=true, startTime=15000)
  Modelica.Blocks.Logical.Not not2 "Negate output of hysteresis"
  Modelica.Blocks.Logical.Hysteresis hysHeating(
    pre_y_start=true,
    uLow=273.15 + 25,
    uHigh=273.15 + 30)
  Modelica.Blocks.Logical.LogicalSwitch logicalSwitch
  Year2024.Controls.Interfaces.VapourCompressionMachineControlBus sigBus1
equation
  connect(dotm_sink.y, fluidSource.dotm)
  connect(TsuSinkRamp.y, fluidSource.T_fluid)
  connect(dotm_source.y, pump.dotm_setValue)
  connect(sine.y, gain.u)
  connect(gain.y, heatFlowRateCon.Q_flow)
  connect(temperatureSensor.enthalpyPort_b, Room.enthalpyPort_a)
  connect(Room.enthalpyPort_b, pump.enthalpyPort_a)
  connect(heatFlowRateCon.port, Room.heatPort)
  connect(pump.enthalpyPort_b, chiller.enthalpyPort_a1)
  connect(fluidSource.enthalpyPort_b, chiller.enthalpyPort_a)
  connect(vessel_ev.enthalpyPort_a, chiller.enthalpyPort_b)
  connect(hysHeating.y,not2. u)
  connect(logicalSwitch.y,booleanToReal. u)
  connect(not2.y,logicalSwitch. u3)
  connect(hysCooling.y,logicalSwitch. u1)
  connect(booleanStep.y,logicalSwitch. u2)
  connect(chiller.enthalpyPort_b1, temperatureSensor.enthalpyPort_a)
  connect(temperatureSensor.T, hysHeating.u)
  connect(temperatureSensor.T, hysCooling.u)
  connect(booleanStep.y, chiller.modeSet)
  connect(chiller.nSet, booleanToReal.y)
  connect(chiller.sigBus, sigBus1)
  connect(iceFac.y, sigBus1.iceFacMea)
  connect(iceFac.y, chiller.iceFac_in)
end Chiller;


Test DHWHeatExchanger
(inclusive heating and cooling circuit).

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatExchangers.DHWHeatExchanger;
model DHWHeatExchanger
extends Modelica.Icons.Example;
  Components.HeatGenerators.Boiler.Boiler     boilerBase
  Components.Pumps.Pump pump
  Modelica.Blocks.Sources.Constant dotm_heatingCircuit(k=0.09)
  Modelica.Blocks.Sources.BooleanExpression booleanOnOffBoiler(y=true)
  Modelica.Blocks.Sources.Constant dotm_dHW(k=0.058)
  Modelica.Blocks.Sources.Constant T_coldWater(k=273.15 + 10)
  Modelica.Blocks.Sources.Constant dotQ_rel(k=1)
  Components.HeatExchangers.DHWHeatExchanger dHWHeatExchanger
  Components.Pumps.FluidSource fluidSource
  Components.Sinks.Vessel vessel
equation
  connect(pump.enthalpyPort_b, boilerBase.enthalpyPort_a1)
  connect(dotm_heatingCircuit.y, pump.dotm_setValue)
  connect(booleanOnOffBoiler.y, boilerBase.onOff_boiler)
  connect(dotQ_rel.y, boilerBase.dotQ_rel)
  connect(boilerBase.enthalpyPort_b1, dHWHeatExchanger.enthalpyPort_heaterIn)
  connect(pump.enthalpyPort_a, dHWHeatExchanger.enthalpyPort_heaterOut)
  connect(T_coldWater.y, fluidSource.T_fluid)
  connect(dotm_dHW.y, fluidSource.dotm)
  connect(dHWHeatExchanger.enthalpyPort_dHWIn, fluidSource.enthalpyPort_b)
  connect(dHWHeatExchanger.enthalpyPort_dHWOut, vessel.enthalpyPort_a)
end DHWHeatExchanger;


within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatExchangers.MultiRadiator;
model ValidationMultiRadiator

  extends Modelica.Icons.Example;
  Components.Valves.Splitter          splitter(n=3)
  Components.Valves.Manifold          manifold(n=3)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedConvHeatFlow(Q_flow=-4500)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedConvHeatFlow1(Q_flow=-1500)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedConvHeatFlow2(Q_flow=-1500)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedConvHeatFlow3(Q_flow=-1500)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedRadHeatFlow(Q_flow=-150)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedRadHeatFlow1(Q_flow=-50)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedRadHeatFlow2(Q_flow=-50)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedRadHeatFlow3(Q_flow=-50)
  Components.Sinks.Vessel          vessel
  Components.Sinks.Vessel          vessel1
  Components.Pumps.FluidSource          fluidSource(medium=
        FastHVAC.Media.WaterSimple())
  Components.Pumps.FluidSource          fluidSource1(medium=
        FastHVAC.Media.WaterSimple())
  Components.Sensors.TemperatureSensor       temperatureSensor
  Components.Sensors.TemperatureSensor       temperatureSensor1
  Components.HeatExchangers.RadiatorMultiLayer
                                       radiator_ML(selectable=true,
    medium=FastHVAC.Media.WaterSimple(),
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom())
  Components.HeatExchangers.RadiatorMultiLayer
                                       radiator_ML1(selectable=true,
    medium=FastHVAC.Media.WaterSimple(),
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom())
  Components.HeatExchangers.RadiatorMultiLayer
                                       radiator_ML2(selectable=true,
    medium=FastHVAC.Media.WaterSimple(),
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom())
  Modelica.Blocks.Sources.Constant Tset(k=273.15 + 75)
  Components.HeatExchangers.MultiRadiator multiRadiator1(
                                                        selectable=true,
    medium=FastHVAC.Media.WaterSimple(),
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom())
  Modelica.Blocks.Sources.Constant dotMSet(k=0.111)
equation
  connect(splitter.enthalpyPort_a, fluidSource1.enthalpyPort_b)
  connect(manifold.enthalpyPort_b, temperatureSensor1.enthalpyPort_a)
  connect(temperatureSensor1.enthalpyPort_b, vessel1.enthalpyPort_a)
  connect(temperatureSensor.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(splitter.enthalpyPort_b[2], radiator_ML.enthalpyPort_a1)
  connect(radiator_ML.enthalpyPort_b1, manifold.enthalpyPort_a[2])
  connect(splitter.enthalpyPort_b[1], radiator_ML2.enthalpyPort_a1)
  connect(radiator_ML2.enthalpyPort_b1, manifold.enthalpyPort_a[1])
  connect(splitter.enthalpyPort_b[3], radiator_ML1.enthalpyPort_a1)
  connect(radiator_ML1.enthalpyPort_b1, manifold.enthalpyPort_a[3])
  connect(fixedConvHeatFlow1.port, radiator_ML2.ConvectiveHeat)
  connect(fixedConvHeatFlow2.port, radiator_ML.ConvectiveHeat)
  connect(fixedConvHeatFlow3.port, radiator_ML1.ConvectiveHeat)
  connect(fixedRadHeatFlow3.port, radiator_ML1.RadiativeHeat)
  connect(fixedRadHeatFlow2.port, radiator_ML.RadiativeHeat)
  connect(fixedRadHeatFlow1.port, radiator_ML2.RadiativeHeat)
  connect(Tset.y, fluidSource.T_fluid)
  connect(Tset.y, fluidSource1.T_fluid)
  connect(multiRadiator1.enthalpyPort_b, temperatureSensor.enthalpyPort_a)
  connect(fluidSource.enthalpyPort_b, multiRadiator1.enthalpyPort_a)
  connect(multiRadiator1.ConvectiveHeat, fixedConvHeatFlow.port)

  connect(fixedRadHeatFlow.port, multiRadiator1.RadiativeHeat)
  connect(dotMSet.y, fluidSource.dotm)
  connect(dotMSet.y, fluidSource1.dotm)
end ValidationMultiRadiator;


K

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatExchangers.RadiatorMultiLayer;
model ValidationRadiator
  extends Modelica.Icons.Example;
  Modelica.Fluid.Sources.MassFlowSource_T source(
    use_m_flow_in=true,
    m_flow=1,
    T(displayUnit="K") = 333,
    use_T_in=true,
    nPorts=1,
    redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Fluid.Pipes.StaticPipe pipe1(
    length=10,
    diameter=0.02,
    redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature T_room1(T=293.15)
  inner Modelica.Fluid.System system(p_start=system.p_ambient,
      p_ambient(displayUnit="Pa"))
  Modelica.Fluid.Sensors.Temperature temperatureOut(redeclare package
      Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Fluid.Sources.FixedBoundary
                                  sink(
    nPorts=1, redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Blocks.Sources.Constant dotm_source1(k=0.0405)
  Modelica.Blocks.Sources.Constant T_source1(k=348.15)
  Fluid.HeatExchangers.Radiators.Radiator radiatorFluid(
    selectable=true,
    redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater,
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom(),
    m_flow_nominal=0.05,
    calc_dT=AixLib.Fluid.HeatExchangers.Radiators.BaseClasses.CalcExcessTemp.exp)

  Modelica.Blocks.Sources.Constant T_source(k=348.15)
  Components.Sinks.Vessel vessel

  Modelica.Blocks.Sources.Constant dotm_source(k=0.0405)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature T_room(T=293.15)
  Components.Sensors.TemperatureSensor temperatureSensor
  Components.HeatExchangers.RadiatorMultiLayer radiatorFastHvac(
    selectable=true,
    medium=FastHVAC.Media.WaterSimple(),
    radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom(),
    calc_dT=AixLib.Fluid.HeatExchangers.Radiators.BaseClasses.CalcExcessTemp.exp)

  Components.Pumps.FluidSource fluidSource(medium=
        FastHVAC.Media.WaterSimple(c=4119, rho=995))
equation

  connect(temperatureSensor.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(radiatorFastHvac.enthalpyPort_b1, temperatureSensor.enthalpyPort_a)
  connect(fluidSource.enthalpyPort_b, radiatorFastHvac.enthalpyPort_a1)
  connect(T_source.y, fluidSource.T_fluid)
  connect(T_room.port, radiatorFastHvac.RadiativeHeat)
  connect(T_room.port, radiatorFastHvac.ConvectiveHeat)
  connect(dotm_source.y, fluidSource.dotm)
  connect(pipe1.port_b,sink. ports[1])
  connect(temperatureOut.port,pipe1. port_a)
  connect(T_source1.y,source. T_in)
  connect(dotm_source1.y,source. m_flow_in)
  connect(source.ports[1], radiatorFluid.port_a)
  connect(radiatorFluid.port_b, pipe1.port_a)
  connect(radiatorFluid.ConvectiveHeat, T_room1.port)
  connect(radiatorFluid.RadiativeHeat, T_room1.port)
end ValidationRadiator;


    November 28, 2016  Tobias Blacha:

    Moved into AixLib

.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatGenerators.Boiler;
model Boiler

 extends Modelica.Icons.Example;
  FastHVAC.Components.Pumps.FluidSource fluidSource
  FastHVAC.Components.Sinks.Vessel vessel
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor_before
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor_after
  Modelica.Blocks.Sources.Constant T_source(k=283.15)
  Modelica.Blocks.Sources.Constant dotm_source(k=0.038)
  Modelica.Blocks.Sources.BooleanPulse booleanOnOffBoiler(width=50, period=
        36000)
  Modelica.Blocks.Sources.Ramp dotQ_rel(
    height=0.8,
    duration=36000,
    offset=0.2)
  FastHVAC.Components.HeatGenerators.Boiler.Boiler boiler
equation

  connect(fluidSource.enthalpyPort_b, temperatureSensor_before.enthalpyPort_a)
  connect(temperatureSensor_after.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(T_source.y, fluidSource.T_fluid)

  connect(dotm_source.y, fluidSource.dotm)
  connect(temperatureSensor_before.enthalpyPort_b, boiler.enthalpyPort_a1)
  connect(boiler.enthalpyPort_b1, temperatureSensor_after.enthalpyPort_a)
  connect(boiler.dotQ_rel, dotQ_rel.y)
  connect(boiler.onOff_boiler, booleanOnOffBoiler.y)
end Boiler;


within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatGenerators.CHP;
model CHP
 extends Modelica.Icons.Example;
  FastHVAC.Components.Pumps.FluidSource fluidSource
  FastHVAC.Components.Sinks.Vessel vessel
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor_before
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor_after
  Modelica.Blocks.Sources.Constant T_source(k=313.15)
  Modelica.Blocks.Sources.Constant dotm_source(k=0.04)
  Modelica.Blocks.Sources.BooleanPulse booleanOnOffCHP(width=50, period=
        36000)
  FastHVAC.Components.HeatGenerators.CHP.CHP_PT1 cHP_PT1_1(
    param=FastHVAC.Data.CHP.Ecopower_3_0(),
    selectable=true,
    sigma(start=0.4),
    T0=293.15)
  Modelica.Blocks.Sources.Ramp P_elRel(
    height=0.8,
    duration=36000,
    offset=0.2)
equation
  connect(fluidSource.enthalpyPort_b, temperatureSensor_before.enthalpyPort_a)
  connect(temperatureSensor_after.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(T_source.y, fluidSource.T_fluid)
  connect(dotm_source.y, fluidSource.dotm)
  connect(temperatureSensor_before.enthalpyPort_b, cHP_PT1_1.enthalpyPort_a)
  connect(cHP_PT1_1.enthalpyPort_b, temperatureSensor_after.enthalpyPort_a)
  connect(booleanOnOffCHP.y, cHP_PT1_1.onOff)
  connect(P_elRel.y, cHP_PT1_1.P_elRel)
end CHP;


Fluidsource for source.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.HeatGenerators.HeatPump;
model HeatPump
  extends Modelica.Icons.Example;
  FastHVAC.Components.Sensors.TemperatureSensor temperatureSensor
  FastHVAC.Components.Pumps.FluidSource fluidSource(medium=
        FastHVAC.Media.WaterSimple()) "Fluidsource for source"
  Components.HeatGenerators.HeatPump.HeatPump heatPump(
    refIneFre_constant=1,
    Medium_con=Media.WaterSimple(),
    Medium_eva=Media.WaterSimple(),
    mFlow_conNominal=0.5,
    VCon=0.4,
    deltaM_con=0.1,
    use_ConCap=false,
    CCon=100,
    GCon=5,
    mFlow_evaNominal=0.5,
    VEva=0.04,
    deltaM_eva=0.1,
    use_EvaCap=false,
    CEva=100,
    GEva=5,
    allowFlowReversalEva=true,
    use_revHP=true,
    TCon_start(displayUnit="K"),
    TEva_start(displayUnit="K"),
    redeclare model PerDataHea =
        AixLib.Obsolete.Year2024.DataBase.HeatPump.PerformanceData.LookUpTable2D (
         dataTable=AixLib.Obsolete.Year2024.DataBase.HeatPump.EN14511.Vitocal200AWO201()),
    redeclare model PerDataChi =
        AixLib.Obsolete.Year2024.DataBase.Chiller.PerformanceData.LookUpTable2D (
         dataTable=AixLib.Obsolete.Year2024.DataBase.Chiller.EN14511.Vitocal200AWO201()),
    Q_useNominal=0,
    use_autoCalc=false,
    TAmbCon_nominal=288.15)
  FastHVAC.Components.Sinks.Vessel vessel_ev
    "vessel for open evaporator circuit"
  Modelica.Blocks.Sources.Constant dotm_source(k=1) "Source mass flow signal"
  Modelica.Blocks.Sources.Constant dotm_sink(k=0.106) "sink mass flow signal"
  Modelica.Blocks.Sources.Constant iceFac(final k=1)
    "Fixed value for icing factor. 1 means no icing/frosting (full heat transfer in heat exchanger)"
  Modelica.Blocks.Sources.Constant T_amb_internal(k=291.15)
    "Constant internal ambient temeprature"
  Modelica.Blocks.Math.BooleanToReal booleanToReal "on off control "
  Modelica.Blocks.Sources.Ramp TsuSourceRamp(
    duration=1000,
    startTime=1000,
    height=25,
    offset=278)
    "Ramp signal for the temperature input of the source side's ideal mass flow source"
  BaseClasses.WorkingFluid Room(m_fluid=5*1000, T0=293.15) "Volume"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heatFlowRateCon
    "Heat flow rate of the condenser"
  Modelica.Blocks.Math.Gain gain(k=-1) "negate sine signal"
  Modelica.Blocks.Sources.Sine sine(
    f=1/3600,
    amplitude=3000,
    offset=3000) "hourly sine "
  Components.Pumps.Pump pump "sink pump"
  Modelica.Blocks.Sources.BooleanStep booleanStep(startTime=10000,
      startValue=true)
  Modelica.Blocks.Logical.Hysteresis hysHeating(
    pre_y_start=true,
    uLow=273.15 + 30,
    uHigh=273.15 + 35)
  Modelica.Blocks.Logical.Not not2 "Negate output of hysteresis"
  Modelica.Blocks.Logical.LogicalSwitch logicalSwitch
  Modelica.Blocks.Logical.Hysteresis hysCooling(
    pre_y_start=false,
    uLow=273.15 + 15,
    uHigh=273.15 + 19)
equation
  connect(dotm_source.y, fluidSource.dotm)
  connect(iceFac.y, heatPump.iceFac_in)
  connect(TsuSourceRamp.y, fluidSource.T_fluid)
  connect(dotm_sink.y, pump.dotm_setValue)
  connect(sine.y, gain.u)
  connect(gain.y, heatFlowRateCon.Q_flow)
  connect(temperatureSensor.enthalpyPort_b, Room.enthalpyPort_a)
  connect(Room.enthalpyPort_b, pump.enthalpyPort_a)
  connect(heatFlowRateCon.port, Room.heatPort)
  connect(hysHeating.y, not2.u)
  connect(logicalSwitch.u1, not2.y)
  connect(hysCooling.y, logicalSwitch.u3)
  connect(logicalSwitch.y, booleanToReal.u)
  connect(booleanToReal.y, heatPump.nSet)
  connect(booleanStep.y, heatPump.modeSet)
  connect(booleanStep.y, logicalSwitch.u2)
  connect(temperatureSensor.T, hysHeating.u)
  connect(temperatureSensor.T, hysCooling.u)
  connect(heatPump.enthalpyPort_b, temperatureSensor.enthalpyPort_a)
  connect(pump.enthalpyPort_b, heatPump.enthalpyPort_a)
  connect(fluidSource.enthalpyPort_b, heatPump.enthalpyPort_a1)
  connect(heatPump.enthalpyPort_b1, vessel_ev.enthalpyPort_a)
end HeatPump;


Dynamic pipes.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Pipes;
model Pipes
  extends Modelica.Icons.Example;
  Components.Pipes.DynamicPipe PipeInsulationAndConvectionandRadiation(
    withInsulation=true,
    withConvection=true,
    withRadiation=true)
  Components.Pumps.FluidSource fluidSource1
  Components.Sinks.Vessel vessel1
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature
    fixedTemperatureSurroundingAir2(
                                   T=293.15)
  Modelica.Blocks.Sources.Constant TFlow1(
                                         k=273.15 + 60)
  Modelica.Blocks.Sources.Ramp mFlow1(
                                     height=1, duration=5000)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature
    fixedTemperatureSurroundingAir3(T=288.15)
  Components.Pipes.DynamicPipe PipeInsulationAndConvection(
    withInsulation=true,
    withConvection=true,
    withRadiation=false)
  Components.Pumps.FluidSource fluidSource2
  Components.Sinks.Vessel vessel2
  Modelica.Blocks.Sources.Constant TFlow2(
                                         k=273.15 + 60)
  Modelica.Blocks.Sources.Ramp mFlow2(
                                     height=1, duration=5000)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature
    fixedTemperatureSurroundingAir5(T=288.15)
  Modelica.Blocks.Sources.Constant TFlow3(
                                         k=273.15 + 60)
  Modelica.Blocks.Sources.Ramp mFlow3(
                                     height=1, duration=5000)
  Components.Pumps.FluidSource fluidSource3
  Components.Pipes.DynamicPipe PipeInsulation(
    withInsulation=true,
    withRadiation=false,
    withConvection=false)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature
    fixedTemperatureSurroundingAir1(T=288.15)
  Components.Sinks.Vessel vessel3
equation
  connect(TFlow1.y, fluidSource1.T_fluid)
  connect(fixedTemperatureSurroundingAir2.port,
    PipeInsulationAndConvectionandRadiation.star)
  connect(fixedTemperatureSurroundingAir3.port,
    PipeInsulationAndConvectionandRadiation.heatPort_outside)
  connect(TFlow2.y, fluidSource2.T_fluid)
  connect(fixedTemperatureSurroundingAir5.port, PipeInsulationAndConvection.heatPort_outside)
  connect(fluidSource2.enthalpyPort_b, PipeInsulationAndConvection.enthalpyPort_a1)
  connect(fixedTemperatureSurroundingAir1.port, PipeInsulation.heatPort_outside)
  connect(TFlow3.y, fluidSource3.T_fluid)
  connect(fluidSource3.enthalpyPort_b, PipeInsulation.enthalpyPort_a1)
  connect(PipeInsulation.enthalpyPort_b1, vessel3.enthalpyPort_a)
  connect(PipeInsulationAndConvection.enthalpyPort_b1, vessel2.enthalpyPort_a)
  connect(fluidSource1.enthalpyPort_b,
    PipeInsulationAndConvectionandRadiation.enthalpyPort_a1)
  connect(PipeInsulationAndConvectionandRadiation.enthalpyPort_b1, vessel1.enthalpyPort_a)
  connect(mFlow3.y, fluidSource3.dotm)
  connect(mFlow2.y, fluidSource2.dotm)
  connect(mFlow1.y, fluidSource1.dotm)
end Pipes;


Fluid source model accepts real input values.
 The output connector creates a fluid with
the properties temperature [K], mass flow
rate [kg/s], specific heat capacity [J/kgK]
and specific enthalpy [J/kg].

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Pumps;
model FluidSource
  extends Modelica.Icons.Example;

  Components.Pumps.FluidSource fluidSource
  Components.Sinks.Vessel vessel
  Modelica.Blocks.Sources.Constant dotm_source(k=2)
  Modelica.Blocks.Sources.Constant T_source(k=333.15)
equation
  connect(T_source.y, fluidSource.T_fluid)
  connect(fluidSource.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(dotm_source.y, fluidSource.dotm)
end FluidSource;


Test pump model
(inclusive boiler and radiator model).

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Pumps;
model Pump
    extends Modelica.Icons.Example;

  Components.Pumps.Pump pump
  Modelica.Blocks.Sources.RealExpression mdot(y=2)
  Components.HeatExchangers.RadiatorMultiLayer
                                       radiator_ML(selectable=true,
      radiatorType=
        DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom())
  Components.HeatGenerators.Boiler.Boiler     boilerBase(paramBoiler=
        Data.Boiler.General.Boiler_Vitogas200F_11kW(), T_start=333.15)
  Modelica.Blocks.Sources.BooleanExpression booleanOnOffBoiler(y=true)
  Modelica.Blocks.Sources.RealExpression dotQ_rel(y=0.3)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature idealSink(T=294.15)
equation
  connect(boilerBase.enthalpyPort_b1, pump.enthalpyPort_a)
  connect(pump.enthalpyPort_b, radiator_ML.enthalpyPort_a1)
  connect(radiator_ML.enthalpyPort_b1, boilerBase.enthalpyPort_a1)
  connect(mdot.y, pump.dotm_setValue)
  connect(dotQ_rel.y, boilerBase.dotQ_rel)
  connect(booleanOnOffBoiler.y, boilerBase.onOff_boiler)
  connect(radiator_ML.ConvectiveHeat, idealSink.port)
  connect(radiator_ML.RadiativeHeat, idealSink.port)
end Pump;


Vessel model

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Sensors;
model SensorVerification
  extends Modelica.Icons.Example;

  Components.Sensors.MassFlowSensor massFlowFastHVAC
  Components.Sensors.TemperatureSensor TemperatureFastHVAC
  Components.Pumps.FluidSource fluidSource1
  Modelica.Blocks.Sources.Constant m_flow(k=2)
  Modelica.Blocks.Sources.Constant T_fluid(k=333.15)
  Components.Sinks.Vessel vessel
  Modelica.Fluid.Sources.MassFlowSource_T boundary(
    use_m_flow_in=true,
    use_T_in=true,
    nPorts=1,
    redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Blocks.Sources.Constant T_fluid1(
                                           k=333.15)
  Modelica.Blocks.Sources.Constant m_flow1(
                                          k=2)
  Modelica.Fluid.Sensors.TemperatureTwoPort TemperatureFluid(redeclare package
              Medium =
               Modelica.Media.Water.ConstantPropertyLiquidWater)
  Modelica.Fluid.Sensors.MassFlowRate massFlowFluid(redeclare package
      Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
  inner Modelica.Fluid.System system
  Modelica.Fluid.Sources.FixedBoundary
                                  Sink(
    nPorts=1, redeclare package Medium =
        Modelica.Media.Water.ConstantPropertyLiquidWater)
equation
  connect(T_fluid.y, fluidSource1.T_fluid)
  connect(fluidSource1.enthalpyPort_b, massFlowFastHVAC.enthalpyPort_a)
  connect(massFlowFastHVAC.enthalpyPort_b, TemperatureFastHVAC.enthalpyPort_a)
  connect(TemperatureFastHVAC.enthalpyPort_b, vessel.enthalpyPort_a)
  connect(m_flow1.y, boundary.m_flow_in)
  connect(T_fluid1.y, boundary.T_in)
  connect(boundary.ports[1], massFlowFluid.port_a)
  connect(massFlowFluid.port_b, TemperatureFluid.port_a)
  connect(TemperatureFluid.port_b, Sink.ports[1])
  connect(m_flow.y, fluidSource1.dotm)
end SensorVerification;


Test sink model
(incl. fluid source model)
.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Sinks;
model SinkSourceVesselTest
  extends Modelica.Icons.Example;

  Components.Sinks.Sink sink
  Components.Sinks.Vessel vessel
  Components.Pumps.FluidSource fluidSource
  Components.Sinks.Sink source(isSource=true)
  Modelica.Blocks.Sources.Constant dotm(k=0.05)
  Modelica.Blocks.Sources.Constant T_source(k=333.15)
  Modelica.Blocks.Sources.Constant source_heatFlow(k=1000)
  Modelica.Blocks.Sources.Constant sink_heatFlow(k=1000)
  Components.Sensors.TemperatureSensor T_afterSink
  Components.Sensors.TemperatureSensor T_afterSource
equation
  connect(fluidSource.enthalpyPort_b, sink.enthalpyPort_a1)
  connect(sink_heatFlow.y, sink.Load)
  connect(source_heatFlow.y, source.Load)
  connect(T_source.y, fluidSource.T_fluid)
  connect(dotm.y, fluidSource.dotm)
  connect(sink.enthalpyPort_b1, T_afterSink.enthalpyPort_a)
  connect(T_afterSink.enthalpyPort_b, source.enthalpyPort_a1)
  connect(source.enthalpyPort_b1, T_afterSource.enthalpyPort_a)
  connect(T_afterSource.enthalpyPort_b, vessel.enthalpyPort_a)
end SinkSourceVesselTest;


    December 20, 2016  Tobias Blacha:

    Moved into AixLib

.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Storage;
model BufferStorageVariablePorts

  extends Modelica.Icons.Example;

  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature ambient(T=288.15)
  Modelica.Blocks.Sources.Constant T_load1(k=273.15 + 85)
  Modelica.Blocks.Sources.Constant dotmUnload1(k=0.03)
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow heatingRod(Q_flow=2000)
  Components.Storage.HeatStorageVariablePorts heatStorageVariablePorts(
    load_cycles=[10,4; 6,1],
    n_HC1_up=10,
    n_HC1_low=6,
    n_HC2_up=4,
    n_HR=10,
    unload_cycles=[1,10; 4,10],
    T_start_wall=323.15,
    T_start_ins=323.15,
    n=10)
  FastHVAC.Components.Pumps.FluidSource fluidSource
  Modelica.Blocks.Sources.Constant dotmLoad1(k=0.007)
  Modelica.Blocks.Sources.Constant T_load2(k=273.15 + 60)
  Modelica.Blocks.Sources.Constant dotmLoad2(k=0.01)
  Modelica.Blocks.Sources.Constant T_unload1(k=273.15 + 40)
  Modelica.Blocks.Sources.Constant T_unload2(k=273.15 + 10)
  Modelica.Blocks.Sources.Constant dotmUnload2(k=0.03)
  FastHVAC.Components.Pumps.FluidSource fluidSource1
  FastHVAC.Components.Sinks.Vessel vessel
  FastHVAC.Components.Pumps.FluidSource fluidSource2
  FastHVAC.Components.Pumps.FluidSource fluidSource3
  FastHVAC.Components.Pumps.FluidSource fluidSource4
  FastHVAC.Components.Pumps.FluidSource fluidSource5
  Modelica.Blocks.Sources.Constant T_HC1(k=273.15 + 90)
  Modelica.Blocks.Sources.Constant dotmHC1(k=0.01)
  Modelica.Blocks.Sources.Constant T_HC2(k=273.15 + 50)
  Modelica.Blocks.Sources.Constant dotmHC2(k=0.01)
  FastHVAC.Components.Sinks.Vessel vessel1
  FastHVAC.Components.Sinks.Vessel vessel2
  FastHVAC.Components.Sinks.Vessel vessel3
  FastHVAC.Components.Sinks.Vessel vessel4
  FastHVAC.Components.Sinks.Vessel vessel5
equation

  connect(T_load2.y, fluidSource3.T_fluid)
  connect(fluidSource1.T_fluid, T_unload1.y)
  connect(dotmUnload1.y, fluidSource1.dotm)
  connect(T_unload2.y, fluidSource2.T_fluid)
  connect(dotmUnload2.y, fluidSource2.dotm)
  connect(T_HC1.y, fluidSource4.T_fluid)
  connect(dotmHC1.y, fluidSource4.dotm)
  connect(T_HC2.y, fluidSource5.T_fluid)
  connect(dotmHC2.y, fluidSource5.dotm)
  connect(dotmLoad1.y, fluidSource.dotm)
  connect(T_load1.y, fluidSource.T_fluid)
  connect(fluidSource5.enthalpyPort_b, heatStorageVariablePorts.port_HC2_in)
  connect(heatStorageVariablePorts.out, ambient.port)
  connect(dotmLoad2.y, fluidSource3.dotm)
  connect(vessel4.enthalpyPort_a, heatStorageVariablePorts.port_HC1_out)
  connect(vessel5.enthalpyPort_a, heatStorageVariablePorts.port_HC2_out)
  connect(heatingRod.port, heatStorageVariablePorts.heatingRod)
  connect(fluidSource4.enthalpyPort_b, heatStorageVariablePorts.port_HC1_in)
  connect(vessel3.enthalpyPort_a, heatStorageVariablePorts.UnloadingCycle_Out[1])
  connect(vessel2.enthalpyPort_a, heatStorageVariablePorts.UnloadingCycle_Out[2])
  connect(vessel.enthalpyPort_a, heatStorageVariablePorts.LoadingCycle_Out[2])
  connect(vessel1.enthalpyPort_a, heatStorageVariablePorts.LoadingCycle_Out[1])
  connect(fluidSource.enthalpyPort_b, heatStorageVariablePorts.LoadingCycle_In[
    1])
  connect(fluidSource3.enthalpyPort_b, heatStorageVariablePorts.LoadingCycle_In[
    2])
  connect(heatStorageVariablePorts.UnloadingCycle_In[1], fluidSource1.enthalpyPort_b)
  connect(fluidSource2.enthalpyPort_b, heatStorageVariablePorts.UnloadingCycle_In[
    2])
end BufferStorageVariablePorts;


Connector of Real output signal.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Valves;
model ThermostaticValve
  extends Modelica.Icons.Example;
   Modelica.Blocks.Sources.Constant T_setRoom(k=273.15 + 20)
  Components.Valves.ThermostaticValve thermostaticValve(
    riseTime=5,
    k=1,
    dotm_nominal=0.2,
    filteredOpening=false)
  Modelica.Blocks.Interfaces.RealOutput dotm_pump
  Modelica.Blocks.Interfaces.RealOutput setTemperature
    "Connector of Real output signal"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature varTemp
  Modelica.Blocks.Sources.Ramp ramp(
    duration=36000,
    offset=273.15 + 15,
    height=5)
  Modelica.Blocks.Interfaces.RealOutput T_actually
    "Connector of Real output signal"
equation

  connect(T_setRoom.y, thermostaticValve.T_set)
  connect(thermostaticValve.dotm_set, dotm_pump)
  connect(T_setRoom.y, setTemperature)
  connect(varTemp.port, thermostaticValve.T_room)
  connect(ramp.y, varTemp.T)
  connect(ramp.y, T_actually)
end ThermostaticValve;


Connector of Real output signal.

within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Valves;
model ThermostaticValveRadiator
 extends Modelica.Icons.Example;
  Modelica.Blocks.Sources.Constant T_setRoom(k=273.15 + 20)
  Modelica.Blocks.Sources.Sine sine1(
    f=1/86400,
    offset=-2000,
    amplitude=1214)
  Components.Valves.ThermostaticValve thermostaticValve(
    riseTime=5,
    filteredOpening=true,
    k=1,
  dotm_nominal=0.3)
  Components.Pumps.FluidSource fluidSource
  Modelica.Blocks.Sources.Constant T_source(k=348.15)
  Components.Sinks.Vessel vessel
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor room(C=99999999, T(
        start=293.15))
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heatLossesRoom
  Components.HeatExchangers.RadiatorMultiLayer radiatorMultiLayer(
  selectable=true,
  calc_dT=AixLib.Fluid.HeatExchangers.Radiators.BaseClasses.CalcExcessTemp.log,
  radiatorType=
      DataBase.Radiators.Standard_MFD_WSchV1984_OneAppartment.Radiator_Livingroom(
      length=5))

  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor roomTemperature
  Modelica.Blocks.Interfaces.RealOutput dotm_pump
  Modelica.Blocks.Interfaces.RealOutput setTemperature
    "Connector of Real output signal"
equation

  connect(sine1.y, heatLossesRoom.Q_flow)
  connect(room.port, heatLossesRoom.port)
connect(radiatorMultiLayer.enthalpyPort_b1, vessel.enthalpyPort_a)
connect(fluidSource.enthalpyPort_b, radiatorMultiLayer.enthalpyPort_a1)
  connect(thermostaticValve.dotm_set, fluidSource.dotm)
  connect(T_source.y, fluidSource.T_fluid)
  connect(T_setRoom.y, thermostaticValve.T_set)
  connect(thermostaticValve.T_room, room.port)
connect(room.port, radiatorMultiLayer.ConvectiveHeat)
connect(room.port, radiatorMultiLayer.RadiativeHeat)
  connect(roomTemperature.port, room.port)
  connect(thermostaticValve.dotm_set, dotm_pump)
  connect(T_setRoom.y, setTemperature)
end ThermostaticValveRadiator;


within AixLib.Obsolete.YearIndependent.FastHVAC.Examples.Valves;
model ThreeWayValve
  extends Modelica.Icons.Example;
  Components.Valves.ThreeWayValve threeWayValve
  Components.Pumps.FluidSource fluidSource
  Components.Sinks.Vessel vessel
  Components.Sinks.Vessel vessel1
  Modelica.Blocks.Sources.Constant dotm(k=1.0)
  Modelica.Blocks.Sources.Constant temp(k=293.15)
  Modelica.Blocks.Sources.Sine sine(
    amplitude=0.5,
    f=1/3600,
    offset=0.5)
equation
  connect(vessel1.enthalpyPort_a, threeWayValve.enthalpyPort_b)
  connect(threeWayValve.enthalpyPort_a, vessel.enthalpyPort_a)
  connect(fluidSource.enthalpyPort_b, threeWayValve.enthalpyPort_ab)
  connect(temp.y, fluidSource.T_fluid)
  connect(dotm.y, fluidSource.dotm)
  connect(sine.y, threeWayValve.opening)
end ThreeWayValve;


info

within AixLib.Obsolete.YearIndependent.FastHVAC;
package Media
  extends Modelica.Icons.Package;
end Media;


within AixLib.Obsolete.YearIndependent.Utilities;
package HeatTransfer "\"Models for different types of heat transfer\""
  extends Modelica.Icons.Package;
  model HeatConvPipeInside
    "Model for Heat Transfer through convection inside a pipe, based on Nussel Correlations"
    extends AixLib.Obsolete.BaseClasses.ObsoleteModel;
    extends Modelica.Thermal.HeatTransfer.Interfaces.Element1D;
    parameter Modelica.Units.SI.Length length(min=0) "length of total pipe";
    parameter Modelica.Units.SI.Length d_i(min=0) "inner diameter of pipe";
    parameter Modelica.Units.SI.Length d_a(min=0) "outer diameter of pipe";
    parameter Modelica.Units.SI.Area A_sur(min=0) "surface for heat transfer";
    parameter Boolean calcHCon=true "Use calculated value for inside heat coefficient";
    parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConIn_const=30
      "Constant convective heat transfer coefficient (Inside)"
    parameter Obsolete.YearIndependent.FastHVAC.Media.BaseClasses.MediumSimple
      medium=Obsolete.YearIndependent.FastHVAC.Media.WaterSimple();
    Modelica.Units.SI.ReynoldsNumber Re;
    Modelica.Units.SI.Velocity v;
    Modelica.Units.SI.NusseltNumber Nu;
    Modelica.Units.SI.NusseltNumber Nu_lam_1;
    Modelica.Units.SI.NusseltNumber Nu_lam_2;
    Modelica.Units.SI.NusseltNumber Nu_lam;
    Modelica.Units.SI.NusseltNumber Nu_tur;
    Modelica.Units.SI.PrandtlNumber Pr;
    Modelica.Units.SI.CoefficientOfHeatTransfer hCon
      "Convective heat transfer coefficient";
    Real zeta "pressure loss coefficient";

    Modelica.Blocks.Interfaces.RealInput m_flow
  equation
    if calcHCon then
      v      =        4*m_flow/(Modelica.Constants.pi * d_i^2 * medium.rho);
      Re     =    Modelica.Fluid.Pipes.BaseClasses.CharacteristicNumbers.ReynoldsNumber(
        v,medium.rho,medium.eta, d_i)
                                     "Reynolds numbers";
      Pr     =        medium.eta *medium.c /medium.lambda;
      zeta   =        (1.8*log10(max(1e-10,Re))-1.5)^(-2);
      Nu_lam_1 =      3.66;
      Nu_lam_2 =      1.615 * (Re*Pr*d_i/length)^(1/3);
      Nu_lam   =      (Nu_lam_1^3 + 0.7^3 + (Nu_lam_2 - 0.7)^3)^(1/3);
      Nu_tur   =      (zeta/8*Re*Pr)/(1+12.7*(zeta/8)^0.5*(Pr^(2/3)-1))*(1+(d_i/length)^(2/3));
      Nu       =      smooth(0,if Re<=2300 then Nu_lam else Nu_tur);
    else
      //prevent solver from solving the equations if they are not used
      v=0;
      Re=0;
      Pr=0;
      zeta=0;
      Nu_lam_1=0;
      Nu_lam_2=0;
      Nu_lam=0;
      Nu_tur=0;
      Nu=0;
      end if;
    hCon = if calcHCon then Nu*medium.lambda/d_i else hConIn_const;
    port_a.Q_flow =hCon*A_sur*(port_a.T - port_b.T);
  end HeatConvPipeInside;
end HeatTransfer;


within AixLib.Obsolete.YearIndependent;
package Utilities "Package with utility functions such as for I/O"
  extends Modelica.Icons.Package;
end Utilities;


within AixLib;
package Systems "This package contains subsystems which allow a fast modeling of complete systems."
extends Modelica.Icons.Package;
end Systems;


within AixLib.Systems.HydraulicModules;
model Admix "Admix circuit with three way valve and pump"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule;

  parameter Modelica.Units.SI.Volume vol=0.0005 "Mixing Volume"

  parameter Fluid.Actuators.Valves.Data.GenericThreeWay valveCharacteristic "Valve characteristic of three way valve"
                                                                           // = AixLib.Fluid.Actuators.Valves.Data.LinearEqualPercentage()

  Fluid.Actuators.Valves.ThreeWayTable valve(
    order=1,
    init=Modelica.Blocks.Types.Init.InitialState,
    CvData=AixLib.Fluid.Types.CvTypes.Kv,
    redeclare package Medium = Medium,
    T_start=T_start,
    y_start=0,
    tau=0.2,
    final m_flow_nominal=m_flow_nominal,
    final energyDynamics=energyDynamics,
    Kv=Kv,
    dpFixed_nominal={10,10},
    final flowCharacteristics1=valveCharacteristic.a_ab,
    final flowCharacteristics3=valveCharacteristic.b_ab)
  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe4(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe5(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe6(
    redeclare final package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.MixingVolumes.MixingVolume junc456(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    T_start=T_start,
    nPorts=3,
    final m_flow_nominal=m_flow_nominal,
    final V=vol,
    final energyDynamics=energyDynamics)
  replaceable BaseClasses.BasicPumpInterface PumpInterface(
    redeclare package Medium = Medium,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)     "Needs to be redeclared"

equation

  connect(const.y, prescribedTemperature.T)
  connect(valve.port_2, pipe2.port_a)
  connect(valve.y, hydraulicBus.valveSet)
  connect(valve.y_actual, hydraulicBus.valveMea)
  connect(pipe5.port_a,junc456. ports[1])
  connect(pipe6.port_a,junc456. ports[2])
  connect(pipe4.port_a, senT_a2.port_b)
  connect(pipe6.heatPort, prescribedTemperature.port)
  connect(pipe2.heatPort, prescribedTemperature.port)
  connect(pipe1.heatPort, prescribedTemperature.port)
  connect(pipe3.heatPort, prescribedTemperature.port)
  connect(pipe5.heatPort, prescribedTemperature.port)
  connect(pipe4.heatPort, prescribedTemperature.port)
  connect(PumpInterface.pumpBus, hydraulicBus.pumpBus)
  connect(PumpInterface.port_b, pipe3.port_a)
  connect(senT_a1.port_b,pipe1. port_a)
  connect(pipe1.port_b, valve.port_1)
  connect(pipe4.port_b, junc456.ports[3])
  connect(pipe5.port_b, senT_b2.port_a)
  connect(pipe2.port_b, PumpInterface.port_a)
  connect(pipe3.port_b, senT_b1.port_a)
  connect(pipe6.port_b, valve.port_3)
end Admix;


within AixLib.Systems.HydraulicModules;
model Injection "Injection circuit with pump and three way valve"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule;

  parameter Fluid.Actuators.Valves.Data.GenericThreeWay valveCharacteristic "Valve characteristic of three way valve"

  parameter Modelica.Units.SI.Volume vol=0.0005 "Mixing Volume"

  Fluid.Actuators.Valves.ThreeWayTable valve(
    order=1,
    init=Modelica.Blocks.Types.Init.InitialState,
    CvData=AixLib.Fluid.Types.CvTypes.Kv,
    redeclare package Medium = Medium,
    T_start=T_start,
    tau=0.2,
    final m_flow_nominal=m_flow_nominal,
    final energyDynamics=energyDynamics,
    y_start=0,
    Kv=Kv,
    dpFixed_nominal={10,10},
    flowCharacteristics1=valveCharacteristic.a_ab,
    flowCharacteristics3=valveCharacteristic.b_ab)

  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe4(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe5(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
    Fluid.FixedResistances.GenericPipe  pipe6(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe7(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe8(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe9(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.MixingVolumes.MixingVolume junc3v6(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    final T_start=T_start,
    final V=vol,
    final m_flow_nominal=m_flow_nominal,
    nPorts=3,
    final allowFlowReversal=allowFlowReversal,
    final energyDynamics=energyDynamics)

  replaceable BaseClasses.BasicPumpInterface PumpInterface(
    redeclare package Medium = Medium,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    energyDynamics=energyDynamics,
    massDynamics=massDynamics)           "Needs to be redeclared"

protected
  Fluid.Sensors.VolumeFlowRate          VFSen_injection(redeclare package
      Medium = Medium, final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal)
    "Volume flow in injection line"
  Fluid.MixingVolumes.MixingVolume junc15j(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    final V=vol,
    final T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    nPorts=3,
    final allowFlowReversal=allowFlowReversal,
    final energyDynamics=energyDynamics)
  Fluid.MixingVolumes.MixingVolume juncjp6(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    final V=vol,
    final T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    nPorts=3,
    final allowFlowReversal=allowFlowReversal,
    final energyDynamics=energyDynamics)

equation
  connect(pipe7.port_a, valve.port_2)

  connect(PumpInterface.port_b, pipe4.port_a)
  connect(VFSen_injection.V_flow, hydraulicBus.VF_injection)

  connect(PumpInterface.pumpBus, hydraulicBus.pumpBus)
  connect(pipe8.heatPort, pipe9.heatPort)
  connect(pipe2.port_a, junc15j.ports[1])
  connect(VFSen_injection.port_b, juncjp6.ports[1])
  connect(pipe6.port_a, junc3v6.ports[1])
  connect(juncjp6.ports[2], pipe3.port_a)
  connect(senT_a1.port_b, pipe1.port_a)
  connect(pipe5.port_a, senT_a2.port_b)
  connect(prescribedTemperature.port, pipe3.heatPort)
  connect(pipe1.heatPort, pipe3.heatPort)
  connect(pipe2.heatPort, pipe3.heatPort)
  connect(pipe4.heatPort, pipe3.heatPort)
  connect(pipe7.heatPort, prescribedTemperature.port)
  connect(pipe5.heatPort, prescribedTemperature.port)
  connect(pipe6.heatPort, prescribedTemperature.port)
  connect(valve.y, hydraulicBus.valveSet)
  connect(valve.y_actual, hydraulicBus.valveMea)
  connect(pipe1.port_b, junc15j.ports[2])
  connect(pipe2.port_b, VFSen_injection.port_a)
  connect(pipe3.port_b, PumpInterface.port_a)
  connect(pipe5.port_b, junc3v6.ports[2])
  connect(pipe6.port_b, valve.port_1)
  connect(pipe7.port_b, senT_b2.port_a)
  connect(pipe8.port_b, valve.port_3)
  connect(pipe9.port_b, juncjp6.ports[3])
  connect(pipe9.port_a, junc3v6.ports[3])
  connect(pipe4.port_b, senT_b1.port_a)
  connect(pipe8.port_a, junc15j.ports[3])
  connect(pipe9.heatPort, prescribedTemperature.port)
end Injection;


within AixLib.Systems.HydraulicModules;
model Injection2WayValve
  "Injection circuit with pump and two way valve"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule;

  parameter Modelica.Units.SI.Volume vol=0.0005 "Mixing Volume"

  Fluid.Actuators.Valves.TwoWayTable  valve(
    CvData=AixLib.Fluid.Types.CvTypes.Kv,
    redeclare package Medium = Medium,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    Kv=Kv,
    order=1,
    init=Modelica.Blocks.Types.Init.InitialState,
    y_start=0,
    flowCharacteristics=Fluid.Actuators.Valves.Data.Linear())
      replaceable BaseClasses.BasicPumpInterface PumpInterface(
    redeclare package Medium = Medium,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)    "Needs to be redeclared"
  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe4(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe5(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe6(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe7(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

   Fluid.MixingVolumes.MixingVolume junc3v6(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    final T_start=T_start,
    final V=vol,
    final m_flow_nominal=m_flow_nominal,
    nPorts=3,
    final allowFlowReversal=allowFlowReversal,
    final energyDynamics=energyDynamics)

protected
  Fluid.MixingVolumes.MixingVolume juncjp6(
    redeclare package Medium = Medium,
    final massDynamics=massDynamics,
    final V=vol,
    final T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    nPorts=3,
    final allowFlowReversal=allowFlowReversal,
    final energyDynamics=energyDynamics)

equation

  connect(PumpInterface.port_b, pipe3.port_a)

  connect(PumpInterface.pumpBus, hydraulicBus.pumpBus)
  connect(pipe5.port_a, junc3v6.ports[1])
  connect(valve.port_b, pipe6.port_a)
  connect(juncjp6.ports[1], pipe2.port_a)
  connect(senT_a1.port_b, pipe1.port_a)
  connect(pipe1.heatPort, prescribedTemperature.port)
  connect(pipe2.heatPort, prescribedTemperature.port)
  connect(pipe7.heatPort, prescribedTemperature.port)
  connect(pipe3.heatPort, prescribedTemperature.port)
  connect(pipe5.heatPort, prescribedTemperature.port)
  connect(pipe6.heatPort, prescribedTemperature.port)
  connect(pipe4.heatPort, prescribedTemperature.port)
  connect(pipe4.port_a, senT_a2.port_b)
  connect(valve.y, hydraulicBus.valveSet)
  connect(valve.y_actual, hydraulicBus.valveMea)
  connect(pipe1.port_b, juncjp6.ports[2])
  connect(pipe2.port_b, PumpInterface.port_a)
  connect(pipe3.port_b, senT_b1.port_a)
  connect(pipe4.port_b, junc3v6.ports[2])
  connect(pipe7.port_b, juncjp6.ports[3])
  connect(pipe7.port_a, junc3v6.ports[3])
  connect(pipe5.port_b, valve.port_a)
  connect(pipe6.port_b, senT_b2.port_a)
end Injection2WayValve;


within AixLib.Systems;
package HydraulicModules "Basic Hydraulic Systems without controller"
  extends Modelica.Icons.VariantsPackage;

end HydraulicModules;


Unmixed circuit with pump

within AixLib.Systems.HydraulicModules;
model Pump "Unmixed circuit with pump"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule(final Kv = 0);

  replaceable BaseClasses.BasicPumpInterface PumpInterface(
    redeclare package Medium = Medium,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)    "Needs to be redeclared"
  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

equation
  connect(PumpInterface.port_b, pipe2.port_a)
  connect(PumpInterface.pumpBus, hydraulicBus.pumpBus)
  connect(senT_a1.port_b, pipe1.port_a)
  connect(pipe3.port_a, senT_a2.port_b)
  connect(pipe1.heatPort, prescribedTemperature.port)
  connect(pipe2.heatPort, prescribedTemperature.port)
  connect(pipe3.heatPort, prescribedTemperature.port)
  connect(pipe1.port_b, PumpInterface.port_a)
  connect(pipe2.port_b, senT_b1.port_a)
  connect(pipe3.port_b, senT_b2.port_a)
end Pump;


Simple Consumer

within AixLib.Systems.HydraulicModules;
model SimpleConsumer "Simple Consumer"
  extends AixLib.Fluid.Interfaces.PartialTwoPort;
  import    Modelica.Units.SI;

  parameter Real kA(unit="W/K")=1 "Heat transfer coefficient times area [W/K]"
  parameter SI.Temperature T_fixed = 293.15
                                           "Ambient temperature for convection"
  parameter SI.HeatCapacity capacity=1 "Capacity of the material";
  parameter SI.Volume V=0.001 "Volume of water";
  parameter SI.HeatFlowRate Q_flow_fixed = 0 "Prescribed heat flow"
  parameter Boolean allowFlowReversal=true
    "= true to allow flow reversal, false restricts to design direction (port_a -> port_b)"
  parameter SI.MassFlowRate m_flow_nominal(min=0)
    "Nominal mass flow rate";
  parameter SI.Temperature T_start=293.15
    "Initialization temperature"
  parameter String functionality "Choose between different functionalities"

  Fluid.MixingVolumes.MixingVolume volume(
    final V=V,
    final T_start=T_start,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    redeclare package Medium = Medium,
    nPorts=2)
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heatCapacitor(
                          T(start=T_start, fixed=true), C=capacity)
  Modelica.Thermal.HeatTransfer.Components.Convection convection
 if functionality == "T_input" or functionality == "T_fixed"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature
    prescribedTemperature if functionality == "T_input" or functionality == "T_fixed"
  Modelica.Blocks.Sources.RealExpression realExpression(y=kA) if functionality == "T_input"
     or functionality == "T_fixed"
  Modelica.Blocks.Sources.RealExpression realExpression1(y=T_fixed)
 if functionality == "T_fixed"
  Modelica.Blocks.Interfaces.RealInput T if functionality == "T_input"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow
 if functionality == "Q_flow_input" or functionality == "Q_flow_fixed"
  Modelica.Blocks.Sources.RealExpression realExpression2(y=Q_flow_fixed)
 if functionality == "Q_flow_fixed"
  Modelica.Blocks.Interfaces.RealInput Q_flow if functionality == "Q_flow_input"
equation
  connect(volume.heatPort,heatCapacitor. port)
  connect(heatCapacitor.port,convection. solid)
  connect(convection.fluid,prescribedTemperature. port)
  connect(realExpression.y,convection. Gc)
  connect(realExpression1.y, prescribedTemperature.T)
  connect(prescribedTemperature.T, T)
  connect(prescribedHeatFlow.Q_flow, realExpression2.y)
  connect(prescribedHeatFlow.Q_flow, Q_flow)
  connect(prescribedHeatFlow.port, heatCapacitor.port)
  connect(port_a, volume.ports[1])
  connect(volume.ports[2], port_b)
end SimpleConsumer;


Throttle circuit with two way valve

within AixLib.Systems.HydraulicModules;
model Throttle "Throttle circuit with two way valve"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule;

  Fluid.Actuators.Valves.TwoWayTable         valve(
    redeclare package Medium = Medium,
    final m_flow_nominal=m_flow_nominal,
    CvData=AixLib.Fluid.Types.CvTypes.Kv,
    final allowFlowReversal=allowFlowReversal,
    Kv=Kv,
    order=1,
    init=Modelica.Blocks.Types.Init.InitialState,
    y_start=0,
    flowCharacteristics=Fluid.Actuators.Valves.Data.Linear())
  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

equation
  connect(valve.port_b, pipe2.port_a)
  connect(valve.y, hydraulicBus.valveSet)
  connect(valve.y_actual, hydraulicBus.valveMea)
  connect(pipe3.port_a, senT_a2.port_b)
  connect(pipe1.port_a, senT_a1.port_b)
  connect(pipe1.heatPort, prescribedTemperature.port)
  connect(pipe2.heatPort, prescribedTemperature.port)
  connect(pipe3.heatPort, prescribedTemperature.port)
  connect(pipe1.port_b, valve.port_a)
  connect(pipe2.port_b, senT_b1.port_a)
  connect(pipe3.port_b, senT_b2.port_a)
end Throttle;


within AixLib.Systems.HydraulicModules;
model ThrottlePump "Throttle circuit with pump and two way valve"
  extends AixLib.Systems.HydraulicModules.BaseClasses.PartialHydraulicModule;

  Fluid.Actuators.Valves.TwoWayTable         valve(
    redeclare package Medium = Medium,
    m_flow_nominal=m_flow_nominal,
    CvData=AixLib.Fluid.Types.CvTypes.Kv,
    final allowFlowReversal=allowFlowReversal,
    Kv=Kv,
    order=1,
    init=Modelica.Blocks.Types.Init.InitialState,
    y_start=0,
    flowCharacteristics=Fluid.Actuators.Valves.Data.Linear())
  replaceable BaseClasses.BasicPumpInterface PumpInterface(
    redeclare package Medium = Medium,
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)    "Needs to be redeclared"
  Fluid.FixedResistances.GenericPipe  pipe1(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe2(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

  Fluid.FixedResistances.GenericPipe  pipe3(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)
  Fluid.FixedResistances.GenericPipe  pipe4(
    redeclare package Medium = Medium,
    pipeModel=pipeModel,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    length=length,
    parameterPipe=parameterPipe,
    parameterIso=parameterIso,
    final hCon=hCon,
    final energyDynamics=energyDynamics,
    final massDynamics=massDynamics)

equation
  connect(valve.port_b, pipe2.port_a)
  connect(valve.y, hydraulicBus.valveSet)
  connect(PumpInterface.port_b, pipe3.port_a)
  connect(valve.y_actual, hydraulicBus.valveMea)
  connect(PumpInterface.pumpBus, hydraulicBus.pumpBus)
  connect(senT_a1.port_b, pipe1.port_a)
  connect(pipe4.port_a, senT_a2.port_b)
  connect(pipe2.heatPort, prescribedTemperature.port)
  connect(pipe4.heatPort, prescribedTemperature.port)
  connect(pipe3.heatPort, prescribedTemperature.port)
  connect(pipe1.heatPort, prescribedTemperature.port)
  connect(pipe1.port_b, valve.port_a)
  connect(pipe2.port_b, PumpInterface.port_a)
  connect(pipe3.port_b, senT_b1.port_a)
  connect(pipe4.port_b, senT_b2.port_a)
end ThrottlePump;


Pump interface for different pump types. This is a basic container model for different pump typs. A new
  container model for a specific pump should be extended from this
  class. In this way, replacing the pump model in the hydraulic modules
  is easy.

within AixLib.Systems.HydraulicModules.BaseClasses;
partial model BasicPumpInterface "Pump interface for different pump types"
 extends AixLib.Fluid.Interfaces.PartialTwoPortInterface;

  AixLib.Fluid.Movers.PumpsPolynomialBased.BaseClasses.PumpBus
    pumpBus

  // Initialization
  parameter Modelica.Units.SI.Temperature T_start=Medium.T_default
    "Initialization temperature"

  // Dynamics
  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=energyDynamics
    "Type of mass balance: dynamic (3 initialization options) or steady state"
end BasicPumpInterface;


Base classes for hydraulic modules

within AixLib.Systems.HydraulicModules;
package BaseClasses "Base classes for hydraulic modules"
  extends Modelica.Icons.BasesPackage;

end BaseClasses;


Base class for hydraulic module.

within AixLib.Systems.HydraulicModules.BaseClasses;
partial model PartialHydraulicModule "Base class for hydraulic module."
  extends AixLib.Fluid.Interfaces.PartialFourPort(
    redeclare package Medium1 = Medium,
    redeclare package Medium2 = Medium,
    final allowFlowReversal1 = allowFlowReversal,
    final allowFlowReversal2 = allowFlowReversal);
  replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
    "Medium in the system"

  // General Parameters
  parameter String pipeModel="SimplePipe"
  parameter Modelica.Units.SI.Length length
    "Pipe length of all pipes (can be overwritten in each pipe)"
  parameter DataBase.Pipes.PipeBaseDataDefinition parameterPipe=
      AixLib.DataBase.Pipes.Copper.Copper_6x1() "Pipe type and diameter (can be overwritten in each pipe)"
  parameter DataBase.Pipes.InsulationBaseDataDefinition parameterIso=
      AixLib.DataBase.Pipes.Insulation.Iso50pc() "Insulation Type (can be overwritten in each pipe)"
  parameter Real Kv "Kv value of valve (can be overwritten in the valve)"
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal(min=0)
    "Nominal mass flow rate"

  // Initialization
  parameter Modelica.Units.SI.Temperature T_start=303.15
    "Initialization temperature"

  // Advanced
  parameter Modelica.Units.SI.Time tau=15
    "Time Constant for PT1 behavior of temperature sensors"
  parameter Modelica.Units.SI.Temperature T_amb=298.15
    "Ambient temperature for heat loss"
  parameter Modelica.Units.SI.Time tauHeaTra=parameterPipe.d_i*parameterPipe.d_i
      /4*1000*4180*(log(parameterPipe.d_i/parameterPipe.d_o)/2/parameterPipe.lambda
       + log(parameterPipe.d_o/parameterPipe.d_o*(1 + parameterIso.factor))/2/
      parameterIso.lambda + 1/hCon/parameterPipe.d_o*(1 + parameterIso.factor))
    "Time constant for heat transfer of temperature sensors to ambient"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hCon=4
    "Convection heat transfer coeffient for all pipes"

  // Assumptions
  parameter Boolean allowFlowReversal=true
    "= true to allow flow reversal, false restricts to design direction (port_a -> port_b)"

  // Dynamics
  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"

  BaseClasses.HydraulicBus hydraulicBus
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature
    prescribedTemperature

  Modelica.Blocks.Sources.Constant const(k=T_amb)

  // -------------------------------------------------
  // Sensors
  // -------------------------------------------------

protected
  Fluid.Sensors.VolumeFlowRate VFSen_out(
    redeclare package Medium = Medium,
    T_start=T_start,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal)
    "Inflow into admix module in forward line"
  Fluid.Sensors.VolumeFlowRate VFSen_in(
    redeclare package Medium = Medium,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final allowFlowReversal=allowFlowReversal) "Outflow out of forward line"

  Fluid.Sensors.TemperatureTwoPort senT_a1(
    tau=0.01,
    T_start=T_start,
    redeclare package Medium = Medium,
    transferHeat=true,
    final TAmb=T_amb,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    tauHeaTra=tauHeaTra)
  Fluid.Sensors.TemperatureTwoPort senT_a2(
    redeclare package Medium = Medium,
    tau=0.01,
    transferHeat=true,
    final TAmb=T_amb,
    final m_flow_nominal=m_flow_nominal,
    T_start=T_start,
    final allowFlowReversal=allowFlowReversal,
    tauHeaTra=tauHeaTra)
  Fluid.Sensors.TemperatureTwoPort senT_b1(
    final m_flow_nominal=m_flow_nominal,
    tau=0.01,
    T_start=T_start,
    redeclare package Medium = Medium,
    transferHeat=true,
    final TAmb=T_amb,
    final allowFlowReversal=allowFlowReversal,
    tauHeaTra=tauHeaTra)
  Fluid.Sensors.TemperatureTwoPort senT_b2(
    tau=0.01,
    T_start=T_start,
    redeclare package Medium = Medium,
    transferHeat=true,
    final TAmb=T_amb,
    final m_flow_nominal=m_flow_nominal,
    final allowFlowReversal=allowFlowReversal,
    tauHeaTra=tauHeaTra)

  Modelica.Blocks.Continuous.FirstOrder PT1_b2(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
  Modelica.Blocks.Continuous.FirstOrder PT1_b1(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
  Modelica.Blocks.Continuous.FirstOrder PT1_a1(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)
  Modelica.Blocks.Continuous.FirstOrder PT1_a2(
    initType=Modelica.Blocks.Types.Init.SteadyState,
    y_start=T_start,
    final T=tau)

equation

  connect(VFSen_out.V_flow, hydraulicBus.VFlowInMea)
  connect(VFSen_in.V_flow,hydraulicBus.VFlowOutMea)
  connect(VFSen_out.port_a, port_a1)
  connect(VFSen_in.port_b, port_b1)
  connect(port_b2, senT_b2.port_b)
  connect(VFSen_out.port_b, senT_a1.port_a)
  connect(senT_b1.port_b, VFSen_in.port_a)
  connect(senT_a2.port_a, port_a2)
  connect(PT1_b2.u, senT_b2.T)
  connect(senT_a1.T, PT1_a1.u)
  connect(senT_b1.T, PT1_b1.u)
  connect(PT1_b1.y, hydraulicBus.TFwrdOutMea)
  connect(PT1_a1.y, hydraulicBus.TFwrdInMea)
  connect(PT1_b2.y, hydraulicBus.TRtrnOutMea)
  connect(senT_a2.T, PT1_a2.u)
  connect(PT1_a2.y, hydraulicBus.TRtrnInMea)
  connect(const.y, prescribedTemperature.T)
end PartialHydraulicModule;


within AixLib.Systems.HydraulicModules.BaseClasses;
model PumpInterface_PumpHeadControlled
  "Head controlled polynomial based pump with controller"
  extends AixLib.Systems.HydraulicModules.BaseClasses.BasicPumpInterface;

  parameter AixLib.DataBase.Pumps.PumpPolynomialBased.PumpBaseRecord pumpParam = AixLib.DataBase.Pumps.PumpPolynomialBased.PumpBaseRecord()
    "pump parameter record"

  parameter Medium.AbsolutePressure p_start=Medium.p_default "Start value for pressure."

  // Assumptions
  parameter Modelica.Units.SI.Volume V=0 "Volume inside the pump"

  // Power and Efficiency
  parameter Boolean calculatePower=true "calc. power consumption?"
  parameter Boolean calculateEfficiency=false
    "calc. efficency? (eta = f(H, Q, P))"

  Fluid.Movers.PumpsPolynomialBased.PumpHeadControlled physics(
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    final pumpParam=pumpParam,
    redeclare final package Medium = Medium,
    final p_start=p_start,
    final T_start=T_start,
    final V=V,
    final energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
    final massDynamics=massDynamics,
    final calculatePower=calculatePower,
    final calculateEfficiency=calculateEfficiency,
    redeclare final function efficiencyCharacteristic =
        Fluid.Movers.PumpsPolynomialBased.BaseClasses.efficiencyCharacteristic.Wilo_Formula_efficiency)

equation
  connect(physics.port_a, port_a)
  connect(physics.port_b, port_b)
  connect(physics.pumpBus, pumpBus)
end PumpInterface_PumpHeadControlled;


within AixLib.Systems.HydraulicModules.BaseClasses;
model PumpInterface_PumpSpeedControlled
  "Speed controlled polynomial based pump with controller"
  extends AixLib.Systems.HydraulicModules.BaseClasses.BasicPumpInterface;
  parameter AixLib.DataBase.Pumps.PumpPolynomialBased.PumpBaseRecord pumpParam=AixLib.DataBase.Pumps.PumpPolynomialBased.PumpBaseRecord()
    "pump parameter record"

  parameter Medium.AbsolutePressure p_start=Medium.p_default "Start value for pressure."

  parameter Modelica.Units.SI.Volume V=0 "Volume inside the pump"
  // Power and Efficiency
  parameter Boolean calculatePower=false "calc. power consumption?"
  parameter Boolean calculateEfficiency=false
    "calc. efficency? (eta = f(H, Q, P))"

  Fluid.Movers.PumpsPolynomialBased.PumpSpeedControlled physics(
    final allowFlowReversal=allowFlowReversal,
    final m_flow_nominal=m_flow_nominal,
    final pumpParam=pumpParam,
    redeclare final package Medium = Medium,
    final p_start=p_start,
    final T_start=T_start,
    final V=V,
    final energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial,
    final massDynamics=massDynamics,
    final calculatePower=calculatePower,
    final calculateEfficiency=calculateEfficiency,
    redeclare final function efficiencyCharacteristic =
        Fluid.Movers.PumpsPolynomialBased.BaseClasses.efficiencyCharacteristic.Wilo_Formula_efficiency)

equation
  connect(physics.port_a, port_a)
  connect(physics.port_b, port_b)
  connect(physics.pumpBus, pumpBus)
end PumpInterface_PumpSpeedControlled;


within AixLib.Systems.HydraulicModules.BaseClasses;
model PumpInterface_SpeedControlledNrpm
  "Interface for the SpeedControlled_Nrpm pump model"
  extends AixLib.Systems.HydraulicModules.BaseClasses.BasicPumpInterface;
  parameter Modelica.Units.NonSI.AngularVelocity_rpm speed_rpm_nominal=1500 "Nominal rotational speed";

  Fluid.Movers.SpeedControlled_y pump(
    redeclare package Medium = Medium,
    final energyDynamics=energyDynamics,
    T_start=T_start)
  Modelica.Blocks.Logical.Switch switchToZero
  Modelica.Blocks.Sources.Constant constZero(final k=0)

  Modelica.Blocks.Math.Gain gaiSpe(final k=1/speed_rpm_nominal) "Pressure gain"
equation
  connect(pump.port_a, port_a)
  connect(pump.port_b, port_b)
  connect(pump.P, pumpBus.PelMea)
  connect(pump.y_actual, pumpBus.rpmMea)
  connect(constZero.y, switchToZero.u3)
  connect(switchToZero.u2, pumpBus.onSet)
  connect(gaiSpe.u, pumpBus.rpmSet)
  connect(switchToZero.u1, gaiSpe.y)
  connect(switchToZero.y, pump.y)
end PumpInterface_SpeedControlledNrpm;


Density of Medium. Calculates the power auf hydraulic modules and returns the power as
  real

within AixLib.Systems.HydraulicModules.Controller;
model CalcHydraulicPower

  parameter Real rho = 1000 "Density of Medium";
  parameter Real cp = 4180 "Heat Capacity of Medium";
public
  BaseClasses.HydraulicBus  hydraulicBus
  Modelica.Blocks.Math.Add add(k1=-1, k2=+1)
  Modelica.Blocks.Math.Product product1
  Modelica.Blocks.Math.Gain gain(k=rho)
  Modelica.Blocks.Math.Gain gain1(k=cp)
  Modelica.Blocks.Interfaces.RealOutput Q_flow
    "Connector of Real output signal"
equation
  connect(add.u2, hydraulicBus.TFwrdInMea)
  connect(add.u1, hydraulicBus.TRtrnOutMea)
  connect(product1.u1, add.y)
  connect(gain.u, hydraulicBus.VFlowInMea)
  connect(gain.y, gain1.u)
  connect(gain1.y, product1.u2)
  connect(product1.y, Q_flow)
  connect(Q_flow, Q_flow)
end CalcHydraulicPower;