# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Example 9.1: Isentropic Compression (Air-Standard)
#
# *<NAME>, Ph.D., P.E.<br>
# University of Kentucky - Paducah Campus<br>
# ME 321: Engineering Thermodynamics II<br>*

# ## Problem Statement
# Air is compressed isentropically form $T_1=250\ \text{K}$, $p_1=1\ \text{bar}$ to $T_2=400\ \text{K}$
# * (a) What is the compression ratio
# * (b) What is the final pressure

# ## Solution
#
# __[Video Explanation](https://uky.yuja.com/V/Video?v=3074239&node=10465156&a=1753145453&autoplay=1)__

# ### Python Initialization
# We'll start by importing the libraries we will use for our analysis and initializing dictionaries to hold the properties we will be usings.

# + jupyter={"outputs_hidden": false}
from kilojoule.templates.kSI_K import *
air = idealgas.Properties('Air', unit_system='SI_K')
# -

# ### Given Parameters
# We now define variables to hold our known values.

# + jupyter={"outputs_hidden": false}
# %%showcalc
T[1] = Quantity(250,'K')
p[1] = Quantity(1,'bar')
T[2] = Quantity(400,'K')
# -

# #### Assumptions
# * Ideal gas
# * Adiabatic
# * Variable specific heat
# * Negligible changes in kinetic and potential energy

# + jupyter={"outputs_hidden": false}
# %%showcalc
# Ideal gaw
R = air.R
# -

# #### (a) Compression Ratio

# + jupyter={"outputs_hidden": false}
# %%showcalc
# Properties at inlet
v[1] = R*T[1]/p[1]
s[1] = air.s(T=T[1],p=p[1])

# Isentropic
s[2] = s[1]

# Specific volume at exit
v[2] = air.v(T=T[2],s=s[2])

# Compression ratio
r = v[1]/v[2]
# -

# #### (b) Final Pressure

# + jupyter={"outputs_hidden": false}
# %%showcalc
# Pressure at exit
p[2] = R*T[2]/v[2]

# Pressure ratio
r_p = p[2]/p[1]

# +
pv = air.pv_diagram()

pv.plot_state(states[1])
pv.plot_state(states[2])

pv.plot_process(states[1],states[2],path='isentropic',label='isentropic');

pv.plot_isotherm(T[1],xcoor=.3)
pv.plot_isotherm(T[2],xcoor=.3)
pv.plot_isobar(p[1],pos=0.5)
pv.plot_isobar(p[2],pos=0.5)
h[2] = air.h(T[2],p[2])
pv.plot_isenthalp(h[2],label=False);

# + jupyter={"outputs_hidden": false}
Summary();

# + jupyter={"outputs_hidden": false}
Summary(['r','r_p']);
# -



StarcoderdataJupyterScriptsDedupFiltered