Compressor Model Example

This example demonstrates how to use the compressor component directly from the library. The compressor is modeled assuming a constant isentropic efficiency.

1. Check the Inputs and Parameters

To identify the required inputs and parameters, use the print_setup method. This will display the names of the component’s connectors, as well as the inputs and parameters needed to define the model.

[ ]:
# Import the compressor model with constant isentropic efficiency
from labothappy.component.compressor.compressor_csteff import CompressorCstEff

# Create an instance of the compressor
compressor = CompressorCstEff()

# Display the component’s setup: inputs, outputs, connectors, and parameters
compressor.print_setup()
=== Component Setup ===

Inputs:
  - P_su: Not set
  - T_su: Not set
  - P_ex: Not set
  - fluid: Not set

Parameters:
  - eta_is: Not set
======================

2. Fill in the Required Inputs and Parameters

Option 1: Fill Through the Connectors

In this option, you will provide the necessary inputs through the connectors. As indicated by the print_setup method, the required inputs are:

  • Supply Pressure (P_su)

  • Exhaust Pressure (P_ex)

  • Supply Temperature (T_su)

  • Fluid

These inputs are assigned through the following connectors:

  • MassConnector ‘su’: Set the supply temperature (T), supply pressure (P), and fluid.

  • MassConnector ‘ex’: Set the supply pressure (P).

After filling in the inputs, you can call the print_setup method again to verify that all connectors, inputs, and parameters have been correctly assigned.

[15]:
"Set inputs of the model through the connectors"
compressor.su.set_fluid('R1233ZDE')

# Set properties for su connector
compressor.su.set_p(319296.5575177148)
compressor.su.set_T(331.033964665788)  # You need to set su.h appropriately

# Set properties for ex connector
compressor.ex.set_p(606240.1433176235)

compressor.print_setup()
=== Component Setup ===

Inputs:
  - P_su: 319296.5575177148
  - T_su: 331.033964665788
  - P_ex: 606240.1433176235
  - fluid: R1233ZDE

Parameters:
  - eta_is: Not set
======================

Option 2: Fill Through the Inputs

In this option, you will provide the necessary inputs through directly through the dictionarry containing all of the inputs with the method ‘set_inputs’.

[16]:
"Set inputs of the model directly"
# Setting inputs
compressor.set_inputs(
    P_su=319296.5575177148,
    T_su=331.033964665788,
    P_ex=606240.1433176235,
    fluid='R1233ZDE'  # Make sure to include fluid information
)
compressor.print_setup()
=== Component Setup ===

Inputs:
  - P_su: 319296.5575177148
  - T_su: 331.033964665788
  - P_ex: 606240.1433176235
  - fluid: R1233ZDE

Parameters:
  - eta_is: Not set
======================

Set Parameters

The parameters of the model are set through the method ‘set_parameters’.

[17]:
# Setting parameters
compressor.set_parameters(
    eta_is = 0.8
)
compressor.print_setup()
=== Component Setup ===

Inputs:
  - P_su: 319296.5575177148
  - T_su: 331.033964665788
  - P_ex: 606240.1433176235
  - fluid: R1233ZDE

Parameters:
  - eta_is: 0.8
======================

3. Solve the Model

Once you have set all the necessary inputs and parameters, you can solve the model by calling the solve method. After solving, you can view the results by using the print_results method.

By using these methods, you can easily solve the model and analyze the results.

[18]:
# Solve the compressor model
compressor.solve()
compressor.print_results()

=== Compressor Results ===
Connectors:
  - su: fluid=R1233ZDE, T=331.033964665788, p=319296.5575177148, h=476278.3066771153
  - ex: fluid=R1233ZDE, T=354.2932947565178, p=606240.1433176235, h=491635.7887210136

Results:
  - h_ex: 491635.7887210136
  - T_ex: 354.2932947565178
=========================