Vapor Compression Cycles:

This tutorial models both the refrigerant cicuit and the moist air side of a Vapor Compression Cycle using pre-built components from HVAC.jl. The R32 refrigerant is used with refrigerant properties queried from a fast and accurate spline-based model.

The following key components are modeled and connected:

  1. Condenser - Uses the TubeFinHEX component. Geometric configuration is defined using the TubeFinHEXGeo function, initial conditions are passed using the TubeFinHEXInit function.
  2. Evaporator - Similar to the condenser above.
  3. Compressor - Uses the TypicalCompressor component, initial conditions set with the TypicalCompressorInit function. A Constant block from the ModelingToolkitStandardLibrary is used to set the control input signal to the compressor.
  4. Valve - Uses the TypicalLEV component, initial conditions set with the TypicalLEVInit. A Constant block from the ModelingToolkitStandardLibrary is used to set the control input signal to the valve.
  5. Boundary source and sink components for the indoor and outdoor moist air modeled using MassFlowSource_Tϕ and Boundary_PTϕ

Copy-pasteable code:

using HVAC, RefpropSplines
using ModelingToolkit, OrdinaryDiffEq, ModelingToolkitStandardLibrary, ModelingToolkitStandardLibrary.Blocks
using Plots, Test, BenchmarkTools

# Load the refrigerant: 
ref_name = "R32"
refrigerant = load_refrigerant(ref_name*".yaml")

# Evaporating and Condensing pressure of the refrigerant
P_cond_in, P_cond_out, P_evap_in, P_evap_out = 2.6e6, 2.55e6, 1.0e6, 0.9e6

# Enthalpy of the refrigerant at the inlet and outlet of the condenser and evaporator
h_cond_in, h_cond_out, h_evap_in, h_evap_out = 520e3, 230e3, 230e3, 430e3

# Evaporating and condensing temperature of the refrigerant
T_cond, T_evap = 300.15, 285.15

# Refrigerant mass flow rate:
ref_mdot_start=0.03


# Air mass flow rate
air_mdot_in = 0.1

# Moist air relative humidities for indoor and outdoor air
ϕ_cond, ϕ_evap = 0.5, 0.6

# Control Inputs
compressor_speed = 30
LEV_position = 300

# COMPONENTS: Compressor and Valve: 
# Compressor
compressor_init = TypicalCompressorInit(;P_a_start=P_evap_out, P_b_start=P_cond_in, m_flow_start=ref_mdot_start)
@named compressor = TypicalCompressor(init = compressor_init)
# Comrpessor control input: 
@named compressor_speed_signal = Constant(; k = compressor_speed)

# Valve: 
LEV_init = TypicalLEVInit(;P_a_start=P_cond_out, P_b_start=P_evap_in, m_flow_start=ref_mdot_start)
@named LEV = TypicalLEV(init = LEV_init)
# Valve control input:
@named LEV_position_signal = Constant(; k = LEV_position)


# CONDENSER AND EVAPORATOR: 
# Condenser refrigerant side: 
nNodes=4; # Number of finite volumes per tube
nTube = 1; # Implying only one circuit is used
len=30; # Length per tube
diameter = 2.54e-2; # Tube diameter
height_ab = 0; # Relative height between of evaporator tube (non-zero accounts for gravity effects)
modelStructure = av_vb

geo_cond = TubeFinHEXGeo(; nTube = nTube, Lt=len, nSeg=nNodes)
init_cond = TubeFinHEXInit(;
                        circuit_h_in_start=h_cond_in,        
                        circuit_h_out_start=h_cond_out,       
                        circuit_p_in_start=P_cond_in,           
                        circuit_p_out_start=P_cond_out,       
                        circuit_mdot_start=ref_mdot_start,       
                        Twall_in_start=from_degC(27),    
                        Twall_out_start=from_degC(27),   
                        Twall_start=from_degC(27),
                        air_mdot_start = air_mdot_in,
                        air_Tin_start=T_cond - 5.,       
                        T_air_out_ref_port_a_start = from_degC(27),
                        T_air_out_ref_port_b_start = from_degC(27),
                        Q_init = 50
)
@named condenser = TubeFinHEX(model_structure=av_vb, htc_air=50, init=init_cond, geo=geo_cond)

# Condenser Air side: 
@named condAirSource = MassFlowSource_Tϕ(T_in=T_cond, ϕ_in=ϕ_cond, m_flow_in=air_mdot_in)
@named condAirSink = Boundary_PTϕ()

# Evaporator refrigerant side:
geo_evap = TubeFinHEXGeo(; nTube = nTube, Lt=0.8*len, nSeg=nNodes)
init_evap = TubeFinHEXInit(;
                        circuit_h_in_start=h_evap_in,        
                        circuit_h_out_start=h_evap_out,       
                        circuit_p_in_start=P_evap_in,           
                        circuit_p_out_start=P_evap_out,       
                        circuit_mdot_start=ref_mdot_start,       
                        Twall_in_start=from_degC(24),    
                        Twall_out_start=from_degC(24),   
                        Twall_start=from_degC(24),
                        air_mdot_start = air_mdot_in,
                        air_Tin_start=T_evap + 5.,       
                        T_air_out_ref_port_a_start = from_degC(24),
                        T_air_out_ref_port_b_start = from_degC(24),
                        Q_init = -50
                        )

@named evaporator = TubeFinHEX(model_structure=av_vb, htc_air=50, init=init_evap, geo=geo_evap)

# Evaporator Air side:
@named evapAirSource = MassFlowSource_Tϕ(T_in=T_evap, ϕ_in=ϕ_evap, m_flow_in=air_mdot_in)
@named evapAirSink = Boundary_PTϕ()


eqns = [
        connect(compressor.port_b, condenser.refPort_a)
        connect(condenser.refPort_b, LEV.port_a)
        connect(LEV.port_b, evaporator.refPort_a)
        connect(evaporator.refPort_b, compressor.port_a)

        connect(condAirSource.port, condenser.airPort_a)
        connect(condenser.airPort_b, condAirSink.port1)

        connect(evapAirSource.port, evaporator.airPort_a)
        connect(evaporator.airPort_b, evapAirSink.port1)

        # Control inputs
        connect(compressor_speed_signal.output, compressor.input)

        connect(LEV_position_signal.output, LEV.input)
       ]

# Define the ODE system: 
@named sys = ODESystem(eqns, t)
@named sysModel = compose(sys, [condenser, LEV, evaporator, compressor, condAirSource, condAirSink, evapAirSource, evapAirSink, compressor_speed_signal, LEV_position_signal])

# Structural simplification:
@time sysRed = structural_simplify(sysModel)

# Inspect reduced system: 
defs = ModelingToolkit.defaults(sysRed)
unset_ps = setdiff(parameters(sysRed), keys(defs)) # Optional check if any parameters are not set
unset_vs = setdiff(states(sysRed), keys(defs)) # Optional check if any states are not set

full_states_set = Set(states(sysModel))
red_states_set = Set(states(sysRed))

@info "Reduced system has $(length(states(sysRed))) states, full system has $(length(states(sysModel))) states."

prob = ODEProblem(sysRed, [defs...; compressor.port_a.m_flow => ref_mdot_start], (0.0, 300.0))
prob_1 = init_DAE(prob, loops = 2, verbose = true, sparsity = true)

# INSPECT SOLUTION: 
@time sol = solve(prob_1, Rodas4(autodiff=false))
# @test SciMLBase.successful_retcode(sol) Optional test

# PLOTS: 

(;m_flows_plot, q_flows_plot, T_plot, h_plot, p_plot, ρ_plot, xq_plot) = plot_comp(:evaporator, evaporator.circuit, nNodes, sol)
plot(xq_plot)
plot(ρ_plot)
plot(h_plot)
plot(p_plot)

(;m_flows_plot, q_flows_plot, T_plot, h_plot, p_plot, ρ_plot, xq_plot) = plot_comp(:condenser, condenser.circuit, nNodes, sol)
plot(xq_plot)
plot(ρ_plot)
plot(h_plot)
plot(p_plot)



(; m_flows_plot, h_flows_plot, p_plot) = plot_comp(:LEV, LEV, sol)
plot(p_plot)


(; m_flows_plot, h_flows_plot, p_plot) = plot_comp(:compressor, compressor, sol)
plot(p_plot)

Step-by-Step Solution:

1. Import required packages:

  • HVAC: Provides the pre-built components
  • RefpropSplines: Internal package to provide the refrigerant properties part of JuliaSim.
  • ModelingToolkit: Provides the acausal modeling framework
  • OrdinaryDiffEq: Provides the solver for the ODEs
  • ModelingToolkitStandardLibrary: Provides input output blocks for the control signals to compressor and valve.
using HVAC, RefpropSplines
using ModelingToolkit, OrdinaryDiffEq, ModelingToolkitStandardLibrary, ModelingToolkitStandardLibrary.Blocks
using Plots, Test, BenchmarkTools

2. Load the refrigerant medium:

In this example, the R32 refrigerant is used. Moist air is also used and is automatically loaded when the MassFlowSource_Tϕ or Boundary_PTϕ components are used.

ref_name = "R32"
refrigerant = load_refrigerant(ref_name*".yaml")
[ Info: Loading refrigerant from /home/github_actions/depots/deepsea1.2/packages/RefpropSplines/i4zIY/config/R32.yaml

3.a. Define the initial conditions:

# Evaporating and Condensing pressure of the refrigerant
P_cond_in, P_cond_out, P_evap_in, P_evap_out = 2.6e6, 2.55e6, 1.0e6, 0.9e6

# Enthalpy of the refrigerant at the inlet and outlet of the condenser and evaporator
h_cond_in, h_cond_out, h_evap_in, h_evap_out = 520e3, 230e3, 230e3, 430e3

# Evaporating and condensing temperature of the refrigerant
T_cond, T_evap = 300.15, 285.15

# Refrigerant mass flow rate:
ref_mdot_start=0.03

3.b. Define the boundary conditions of indoor and outdoor air:

# Air mass flow rate
air_mdot_in = 0.1

# Moist air relative humidities for indoor and outdoor air
ϕ_cond, ϕ_evap = 0.5, 0.6

3.c. Define the control inputs:

# Control Inputs
compressor_speed = 30
LEV_position = 300

4. Define the components:

i. Compressor and Valve

Use the TypicalCompressor and TypicalLEV respectively

# Compressor
compressor_init = TypicalCompressorInit(;P_a_start=P_evap_out, P_b_start=P_cond_in, m_flow_start=ref_mdot_start)
@named compressor = TypicalCompressor(init = compressor_init)
# Comrpessor control input:
@named compressor_speed_signal = Constant(; k = compressor_speed)

# Valve:
LEV_init = TypicalLEVInit(;P_a_start=P_cond_out, P_b_start=P_evap_in, m_flow_start=ref_mdot_start)
@named LEV = TypicalLEV(init = LEV_init)
# Valve control input:
@named LEV_position_signal = Constant(; k = LEV_position)

ii. The Condenser and Evaporator

A cross-flow configuration is used as discussed in Tube-Fin tutorial. Distributed mass, momentum and energy balance relations are constructed for the following configuration:

Geometry:

  • Length of pipe: 30 m
  • Diameter of pipe: 2.54 cm

Mass and Energy balance:

  • Number of finite volume cells per tube: 4

Momentum balance:

  • model_structure = av_vb

Used for numerical robustness by alternating flow (momentum balance) cells and volume (energy balance) cells. StraightPipe begins and ends with a volume cells with flow cells interleaved in the middle.

# Condenser refrigerant side:
nNodes=4; # Number of finite volumes per tube
nTube = 1; # Implying only one circuit is used
len=30; # Length per tube
diameter = 2.54e-2; # Tube diameter
height_ab = 0; # Relative height between of evaporator tube (non-zero accounts for gravity effects)
modelStructure = av_vb

geo_cond = TubeFinHEXGeo(; nTube = nTube, Lt=len, nSeg=nNodes)
init_cond = TubeFinHEXInit(;
                        circuit_h_in_start=h_cond_in,
                        circuit_h_out_start=h_cond_out,
                        circuit_p_in_start=P_cond_in,
                        circuit_p_out_start=P_cond_out,
                        circuit_mdot_start=ref_mdot_start,
                        Twall_in_start=from_degC(27),
                        Twall_out_start=from_degC(27),
                        Twall_start=from_degC(27),
                        air_mdot_start = air_mdot_in,
                        air_Tin_start=T_cond - 5.,
                        T_air_out_ref_port_a_start = from_degC(27),
                        T_air_out_ref_port_b_start = from_degC(27),
                        Q_init = 50
)
@named condenser = TubeFinHEX(model_structure=av_vb, htc_air=50, init=init_cond, geo=geo_cond)

# Condenser Air side:
@named condAirSource = MassFlowSource_Tϕ(T_in=T_cond, ϕ_in=ϕ_cond, m_flow_in=air_mdot_in)
@named condAirSink = Boundary_PTϕ()

# Evaporator refrigerant side:
geo_evap = TubeFinHEXGeo(; nTube = nTube, Lt=0.8*len, nSeg=nNodes)
init_evap = TubeFinHEXInit(;
                        circuit_h_in_start=h_evap_in,
                        circuit_h_out_start=h_evap_out,
                        circuit_p_in_start=P_evap_in,
                        circuit_p_out_start=P_evap_out,
                        circuit_mdot_start=ref_mdot_start,
                        Twall_in_start=from_degC(24),
                        Twall_out_start=from_degC(24),
                        Twall_start=from_degC(24),
                        air_mdot_start = air_mdot_in,
                        air_Tin_start=T_evap + 5.,
                        T_air_out_ref_port_a_start = from_degC(24),
                        T_air_out_ref_port_b_start = from_degC(24),
                        Q_init = -50
                        )



#@named cond_fan = SimpleFan()
#@named evap_fan = SimpleFan()
@named evaporator = TubeFinHEX(model_structure=av_vb, htc_air=50, init=init_evap, geo=geo_evap)

# Evaporator Air side:
@named evapAirSource = MassFlowSource_Tϕ(T_in=T_evap, ϕ_in=ϕ_evap, m_flow_in=air_mdot_in)
@named evapAirSink = Boundary_PTϕ()
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MassFlowSource_Tϕ currently hard-coded to MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: Boundary_PTϕ currently hard-coded to MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: MassFlowSource_Tϕ currently hard-coded to MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir
[ Info: Boundary_PTϕ currently hard-coded to MoistAir
[ Info: MultiComponentFluidPort is currently hard-coded for MoistAir

5. Define the connecting equations:

eqns = [
        connect(compressor.port_b, condenser.refPort_a)
        connect(condenser.refPort_b, LEV.port_a)
        connect(LEV.port_b, evaporator.refPort_a)
        connect(evaporator.refPort_b, compressor.port_a)

        connect(condAirSource.port, condenser.airPort_a)
        connect(condenser.airPort_b, condAirSink.port1)

        connect(evapAirSource.port, evaporator.airPort_a)
        connect(evaporator.airPort_b, evapAirSink.port1)

        # Control inputs
        connect(compressor_speed_signal.output, compressor.input)

        connect(LEV_position_signal.output, LEV.input)
       ]

6. Define the ODESystem:

# Define the ODE system:
@named sys = ODESystem(eqns, t)
@named sysModel = compose(sys, [condenser, LEV, evaporator, compressor, condAirSource, condAirSink, evapAirSource, evapAirSink, compressor_speed_signal, LEV_position_signal])

# Structural simplification:
@time sysRed = structural_simplify(sysModel)

# Inspect reduced system:
defs = ModelingToolkit.defaults(sysRed)
unset_ps = setdiff(parameters(sysRed), keys(defs)) # Optional check if any parameters are not set
unset_vs = setdiff(states(sysRed), keys(defs)) # Optional check if any states are not set

full_states_set = Set(states(sysModel))
red_states_set = Set(states(sysRed))

@info "Reduced system has $(length(states(sysRed))) states, full system has $(length(states(sysModel))) states."
  1.715920 seconds (7.29 M allocations: 444.443 MiB, 4.07% gc time, 47.99% compilation time)
[ Info: Reduced system has 71 states, full system has 1172 states.

Formulate the ODEProblem and Initialize:

## Initialization and Simulation
# Explicitly sets the initial conditions for the reduced states.
# The user can over-ride defaults are shown below for the `compressor.port_a.m_flow` state.
# Simulates 5 minutes (or 300 seconds) of the system.
prob = ODEProblem(sysRed, [defs...; compressor.port_a.m_flow => ref_mdot_start], (0.0, 300.0))

# Initialize the DAE system:
# More complicated DAE systems may require more than one loop of initialization. This particular system requires two loops, set by setting `loops = 2`.
prob_1 = init_DAE(prob, loops = 2, verbose = true, sparsity = true)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 300.0)
u0: 71-element Vector{Float64}:
      2.6e6
 520000.0
      2.5833333333333335e6
 423333.3333333333
      2.5666666666666665e6
 326666.6666666667
      2.55e6
 230000.0
    300.15
    300.15
      ⋮
  25088.296508185253
      0.005184972779248065
    285.14999999999986
 471698.1463626045
      0.010732865902983127
 101327.43615012922
      0.00721297400015273
 101327.43615012922
      0.00721297400015273

Solve the ODE problem for a time span of 300 seconds:

@time sol = solve(prob_1, Rodas4(autodiff=false))
# @test SciMLBase.successful_retcode(sol) # Optional test to check if the solver was successful
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 57-element Vector{Float64}:
   0.0
   1.0e-6
   1.1e-5
   0.00011099999999999999
   0.0010306366369619668
   0.0029510022118169723
   0.005694309471497925
   0.010124936050456557
   0.017811465173226224
   0.032823914692964175
   ⋮
  54.03493534579036
  64.14517995995911
  76.44106670912515
  93.12011181608192
 117.12531577844578
 152.44505702502076
 198.2460296532692
 263.358726965037
 300.0
u: 57-element Vector{Vector{Float64}}:
 [2.6e6, 520000.0, 2.5833333333333335e6, 423333.3333333333, 2.5666666666666665e6, 326666.6666666667, 2.55e6, 230000.0, 300.15, 300.15  …  1010.1427932506188, 25088.296508185253, 0.005184972779248065, 285.14999999999986, 471698.1463626045, 0.010732865902983127, 101327.43615012922, 0.00721297400015273, 101327.43615012922, 0.00721297400015273]
 [2.5999989719128874e6, 519999.9330796499, 2.583331357414717e6, 423333.17169639084, 2.5666653366230805e6, 326666.6017265647, 2.5500018186272797e6, 230000.00711767268, 300.15000141642895, 300.15002175681883  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 471698.8821401463, 0.01073287551473718, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.599988689699791e6, 519999.2638805761, 2.5833115996728684e6, 423331.55538996257, 2.566652036646774e6, 326665.9523322842, 2.5500199358578566e6, 230000.07821073206, 300.15001558048425, 300.15023932061104  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 471706.2395891734, 0.010732971629856635, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.599885733942001e6, 519992.5723399434, 2.583114166445009e6, 423315.3986167615, 2.566519082385025e6, 326659.4590618366, 2.550194280299179e6, 230000.78086683754, 300.1501571975709, 300.15241451898385  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 471779.7814650327, 0.01073393253650004, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.5989279587726844e6, 519931.0784422624, 2.581310604806619e6, 423167.34470843844, 2.565299916592548e6, 326599.80068061885, 2.551274231201687e6, 230006.6082781032, 300.1514575553712, 300.1723810848558  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 472453.3390047379, 0.010742747596164653, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.596870771823831e6, 519803.007571823, 2.577612027904142e6, 422861.16204806516, 2.562769521874954e6, 326475.532708442, 2.551345644490206e6, 230016.12660679957, 300.15416120948015, 300.21385941901224  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 473844.1056453225, 0.010761013661042365, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.5938223317684997e6, 519621.15928328317, 2.5724760528556714e6, 422430.37529220665, 2.5591753974523586e6, 326298.69058952405, 2.548993013509549e6, 230026.73133290056, 300.1579957454705, 300.2726151050961  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 475795.232669016, 0.010786718413468444, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.588701531249918e6, 519331.13585826993, 2.564511979443572e6, 421749.79257508647, 2.5533969009936517e6, 326014.72402874794, 2.5436081373742432e6, 230041.8789709308, 300.16411939906703, 300.3663028341902  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 478862.5996033495, 0.010827080042250957, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.5794825672644917e6, 518841.62121402606, 2.551538101316495e6, 420609.1453464046, 2.543434523155324e6, 325527.09863644454, 2.5337793265263964e6, 230067.38308342814, 300.1745395800752, 300.52542855349174  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 483957.4956899942, 0.010893098210945147, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.561179720128496e6, 517945.28044974443, 2.528705039587488e6, 418508.44273006055, 2.5242649946257835e6, 324594.96455286036, 2.514790470359334e6, 230116.76795519306, 300.19416035261656, 300.82446362819235  …  1010.1427932506192, 25088.296508185253, 0.005184972779248021, 285.15, 493179.8248622783, 0.011005390722373673, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 ⋮
 [2.6217533867111313e6, 379101.10468678566, 2.601069243925801e6, 344434.33138562186, 2.5802273995179064e6, 315275.8299755319, 2.5632596158828884e6, 282853.93409619585, 314.5801729998642, 314.69244143154975  …  1009.7170924404871, 25088.296508185253, 0.005184972779248021, 285.15, 413086.668527766, 0.012445560993347173, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.6535402704745685e6, 382197.1282443543, 2.6337053220153153e6, 346732.4660240835, 2.613507293162694e6, 314798.97399449314, 2.595247644952861e6, 284531.7308608714, 315.071836871751, 315.20604957096685  …  1009.7255892891135, 25088.296508185253, 0.005184972779248021, 285.15, 415584.74189680314, 0.01232317916319101, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.68239157269835e6, 383402.8344839259, 2.6628092740837405e6, 348666.22134160233, 2.6432157301268093e6, 315101.97023417376, 2.6243444494521436e6, 285907.89762279135, 315.5145241366718, 315.65991710168834  …  1009.7361848894132, 25088.296508185253, 0.005184972779248021, 285.15, 416568.86431243323, 0.012293509595179625, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.708678168516819e6, 383751.3344188954, 2.689060339862594e6, 349727.5104228913, 2.669654956186311e6, 315795.7719879365, 2.650487455793579e6, 287132.83245603874, 315.9154598322229, 316.06620263898077  …  1009.7477178362238, 25088.296508185253, 0.005184972779248021, 285.15, 417051.23602981935, 0.01229496926356953, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.7299304450498866e6, 384062.8870426974, 2.71026431819382e6, 350128.12381522433, 2.690746477089177e6, 316442.7526981896, 2.6713550276544034e6, 288154.4712591234, 316.237641530782, 316.3921593552679  …  1009.7578088083784, 25088.296508185253, 0.005184972779248021, 285.15, 417595.5312486717, 0.012289673011599254, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.7435329494652743e6, 384382.2099120689, 2.7238696897086413e6, 350356.5321999485, 2.7042554795151628e6, 316826.877964791, 2.6846922120253933e6, 288822.684962898, 316.44273693727104, 316.600232533637  …  1009.7643133175453, 25088.296508185253, 0.005184972779248021, 285.15, 418047.0018591289, 0.01228059888864237, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.7492119588052286e6, 384515.6853507062, 2.7295506763567613e6, 350463.64089728735, 2.7099027924782736e6, 316986.5922658566, 2.6902681279532686e6, 289101.0079644582, 316.528125860732, 316.6868798376009  …  1009.767023948441, 25088.296508185253, 0.005184972779248021, 285.15, 418231.4063372601, 0.012276995473432832, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.7509767434189967e6, 384556.7793780597, 2.731315931319409e6, 350496.3221193611, 2.7116572319918005e6, 317036.65129154274, 2.692000600225191e6, 289187.5135866849, 316.55463417621735, 316.71377588863646  …  1009.7678679324175, 25088.296508185253, 0.005184972779248021, 285.15, 418288.4932505999, 0.012275889765751537, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]
 [2.751191362134401e6, 384561.76899050374, 2.731530602179555e6, 350500.2842696804, 2.7118705769116883e6, 317042.74869533203, 2.6922112742213905e6, 289198.0342410072, 316.5578571991496, 316.71704587912774  …  1009.7679706101434, 25088.296508185253, 0.005184972779248021, 285.15, 418295.4382401361, 0.01227575519098407, 101327.43615012922, 0.007212974000152729, 101327.43615012922, 0.007212974000152729]

Inspect the solution. Plot the results:

The quality of the refrigerant in the evaporator increases to 1.0 (pure gas) from two-phase-

(;m_flows_plot, q_flows_plot, T_plot, h_plot, p_plot, ρ_plot, xq_plot) = plot_comp(:evaporator, evaporator.circuit, nNodes, sol)
plot(xq_plot)
plot(ρ_plot)
  plot(h_plot)
plot(p_plot)

Similarly the quality of the refrigerant in the condenser decreases from 1.0 (gases at first volume) to 0.0 (liquid) at 4th volume

(;m_flows_plot, q_flows_plot, T_plot, h_plot, p_plot, ρ_plot, xq_plot) = plot_comp(:condenser, condenser.circuit, nNodes, sol)
plot(xq_plot)
plot(ρ_plot)
  plot(h_plot)
plot(p_plot)

Valve:

(; m_flows_plot, h_flows_plot, p_plot) = plot_comp(:LEV, LEV, sol)
plot(p_plot)

Compressor

(; m_flows_plot, h_flows_plot, p_plot) = plot_comp(:compressor, compressor, sol)
plot(p_plot)