Compressor - Nouman090/ThermoSim GitHub Wiki

A compressor increases the pressure of a gas-phase working fluid (e.g., air, helium, CO₂) by consuming work. It is commonly used in Brayton cycles, gas turbines, and refrigeration systems. The compression process is modeled with isentropic and mechanical efficiencies.

Physics

h_out = h_in + (h_out,isen - h_in) / η_isen
W_in = ṁ × (h_out - h_in) / η_mech
Ex_D = W_in + Ex_in - Ex_out

The compressor tracks the pressure ratio (P_out / P_in), which is a key parameter in gas turbine performance.

Syntax

Compressor(Model, ID, In_state, Out_state,
           n_isen=1.0, n_mech=1.0, Calculate=False)
Parameter Type Default Description
Model ThermodynamicModel The model object
ID str Unique component name
In_state str Inlet state point name
Out_state str Outlet state point name
n_isen float 1.0 Isentropic efficiency (0–1)
n_mech float 1.0 Mechanical efficiency (0–1)
Calculate bool False Solve immediately if True

Output Attributes

Attribute Type Unit Description
.work float W Work input (positive value)
.pressure_ratio float P_out / P_in
.Ex_D float/str W Exergy destruction
.Solution_Status bool True if solved
.In Prop Inlet state point object
.Out Prop Outlet state point object

Cases

Case 1: Known Inlet, Unknown Outlet (Forward Calculation)

Most common. You know the inlet conditions and outlet pressure. The compressor calculates the outlet state.

from Thermosim import ThermodynamicModel, Compressor

Model = ThermodynamicModel()
Model.set_dead_state()

# Inlet: atmospheric air at 25°C
Model.add_point('air', '1', P=101325, T=298.15, Mass_flowrate=1)
# Outlet: compressed to 10 bar
Model.add_point('air', '2', P=1e6)

Compressor(Model, 'C1', '1', '2', n_isen=0.85, Calculate=True)

print(f"Work input:      {Model.Component['C1'].work/1e3:.2f} kW")
print(f"Pressure ratio:  {Model.Component['C1'].pressure_ratio:.2f}")
print(f"Outlet T:        {Model.Point['2'].T - 273.15:.2f} °C")
print(f"Outlet H:        {Model.Point['2'].H:.0f} J/kg")

Case 2: Known Outlet, Unknown Inlet (Reverse Calculation)

You know the outlet conditions and inlet pressure. The compressor solves for the inlet state using fsolve.

Model = ThermodynamicModel()
Model.set_dead_state()

# Inlet: only pressure known
Model.add_point('air', '1', P=101325, Mass_flowrate=1)
# Outlet: fully defined
Model.add_point('air', '2', P=1e6, T=600)

Compressor(Model, 'C1', '1', '2', n_isen=0.85, Calculate=True)

print(f"Inlet T: {Model.Point['1'].T - 273.15:.2f} °C")
print(f"Inlet H: {Model.Point['1'].H:.0f} J/kg")

Case 3: Both Inlet and Outlet Known

Used when you already know both states (e.g., from another calculation). The compressor just computes work and exergy.

Model = ThermodynamicModel()
Model.set_dead_state()

Model.add_point('air', '1', P=101325, T=298.15, Mass_flowrate=1)
Model.add_point('air', '2', P=1e6, T=600)

Compressor(Model, 'C1', '1', '2', n_isen=0.85, Calculate=True)

print(f"Work input: {Model.Component['C1'].work/1e3:.2f} kW")

Case 4: Mass Flow Not Given

If neither inlet nor outlet has a mass flow rate, the compressor assumes 1 kg/s and issues a warning. After calculation, mass flow is reset to None.

Model.add_point('air', '1', P=101325, T=298.15)   # no mass flow
Model.add_point('air', '2', P=1e6)

Compressor(Model, 'C1', '1', '2', n_isen=0.85, Calculate=True)
# Warning: Mass flowrate through C1 set to 1 kg/s

Case 5: Isentropic Compressor (η = 1)

Compressor(Model, 'C1', '1', '2', n_isen=1.0, Calculate=True)
# Outlet entropy equals inlet entropy

Case 6: Multi-Stage Compression

Model.add_point('air', '1', P=101325, T=298.15, Mass_flowrate=1)
Model.add_point('air', '2', P=3e5)     # 1st stage outlet
Model.add_point('air', '3', P=3e5, T=298.15)  # intercooler
Model.add_point('air', '4', P=1e6)     # 2nd stage outlet

Compressor(Model, 'LP_Comp', '1', '2', n_isen=0.85, Calculate=True)
Compressor(Model, 'HP_Comp', '3', '4', n_isen=0.85, Calculate=True)

print(f"Stage 1 work: {Model.Component['LP_Comp'].work/1e3:.2f} kW")
print(f"Stage 2 work: {Model.Component['HP_Comp'].work/1e3:.2f} kW")

Print Component Data

print(Model.Component['C1'])

Output:

C1 (Compressor):
  P_in             : 1.01 bar
  P_out            : 10.00 bar
  Pressure ratio   : 9.87
  η_isen           : 85.0 %
  η_mech           : 100.0 %
  Work input       : XXXXX.XX W  (XXX.XX kW)
  Exergy destr.    : XXXXX.XX
  Solved           : True

Complete Example

from Thermosim import ThermodynamicModel, Compressor

# Create model
Model = ThermodynamicModel()
Model.set_dead_state()

# Define state points
Model.add_point('air', '1', P=101325, T=298.15, Mass_flowrate=1)
Model.add_point('air', '2', P=1e6)

# Add compressor
Compressor(Model, 'MainCompressor', '1', '2', n_isen=0.85, n_mech=0.98, Calculate=True)

# Access results
comp = Model.Component['MainCompressor']
print(f"Work input:         {comp.work/1e3:.2f} kW")
print(f"Pressure ratio:     {comp.pressure_ratio:.2f}")
print(f"Exergy destruction: {comp.Ex_D/1e3:.2f} kW")
print(f"Outlet temperature: {Model.Point['2'].T - 273.15:.2f} °C")
print(f"Outlet pressure:    {Model.Point['2'].P/1e5:.2f} bar")