\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

Oct 24, 2024 | 637 words | 6 min read

6.3.1. Task 1#

Learning Objectives#

Create and implement user-defined functions in Python; Construct logic operations using comparison, membership, and logical operators to generate control flow statements in Python; Utilize conditional if-elif-else statements while programming in Python, as well as previously learned objectives such as: Output data from a function to the screen in Python; Apply course code standard in development of Python scripts; Modularize and comment code in Python for readability and reusability.

Introduction#

Supercritical fluids are a state of matter that exhibits properties of both a gas and a liquid. They are formed when a substance is subjected to temperature and pressure conditions that exceed its critical point (see Fig. 6.1). At this point and beyond, the substance loses its distinct gas and liquid phases and instead exists as a single-phase fluid with unique characteristics. In a supercritical fluid, molecules move freely and rapidly, similar to a gas. However, unlike a gas, a supercritical fluid possesses a high density and exhibits solvent-like properties, like a liquid. This means that it can dissolve a wide range of substances like a liquid and transport them, making it an excellent medium for extraction and chemical reactions. Supercritical carbon dioxide is one of the most used supercritical fluids for extraction applications such as retrieving hydrocarbons from soils or decaffeinating coffee. You can learn more about the supercritical CO2 extraction process by watching this video.

../../../../../_images/Carbon_dioxide_pressure-temperature_phase_diagram-en.svg

Fig. 6.1 CO2 phase diagram (source: https://en.wikipedia.org/wiki/Supercritical_fluid)#

Task Instructions#

You will write a program that monitors the conditions inside the extraction vessel to ensure that the temperature and pressure are within an acceptable range. Begin by creating a flow diagram and save it in a PDF file named py2_ind_1_username.pdf, where username is your Purdue login. Then, write a Python program to solve the task.

Open the standard template ENGR133_Python_Template.py and name it, py2_ind_1_username.py where you will write a user-defined function named check_status and your main function as defined below. Reference value for your program are provided in Table 6.7.

check_status

Accepts temperature and pressure values as arguments and checks the temperature and pressure values for the following conditions:

  1. Is the value below the critical point value for carbon dioxide?

    • If so, print a warning message and tell the user by how much the value should be increased to reach the critical point. (Use appropriate number formatting.)

  2. Is the value exactly at the critical point?

    • If both the temperature and pressure are at their critical point values, print a statement that informs the user that the carbon dioxide is at its critical point.

  3. Is the value above safe operating levels?

    • If the value is greater than or equal to \(\qty{95}{\percent}\) of the maximum operating specifications, print a warning statement and tell the user how much the value should be decreased to reach safe operating levels.

  4. If the extraction vessel is within normal operating parameters (i.e. above the critical point and within safe operating levels), print a message that indicates everything is operating safely.

main

Collects temperature and pressure values from the user, checks if they are valid, and handles calling the check_status function.

  1. Ask the user to input the temperature in Kelvin. If the temperature is below zero, print an error message and exit the program.

  2. Ask the user to input the pressure in bar. If the pressure is below zero, print an error message and exit the program.

  3. If both the temperature and pressure are valid, call the check_status function with the temperature and pressure values as arguments.

Table 6.7 Reference Values#

Property

Temperature (K)

Pressure (bar)

Carbon Dioxide Critical Point

304.2

73.8

Maximum Operating Specification

344.14

137

Sample Output#

Use the values in Table 6.8 below to test your program.

Table 6.8 Test Cases#

Case

Temperature (\(\fahrenheit\))

Pressure (\(\bar\))

1

314.15

120.3

2

-3

3

320

-5

4

304.2

73.8

5

315

140

6

299

80.5

7

349.3

71.5

Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.

Case 1 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 314.15 Enter the pressure of carbon dioxide in bar: 120.3 Temperature is within safe operating conditions. Pressure is within safe operating conditions.

Case 2 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: -3 Error: Please enter a valid temperature.

Case 3 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 320 Enter the pressure of carbon dioxide in bar: -5 Error: Please enter a valid pressure.

Case 4 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 304.2 Enter the pressure of carbon dioxide in bar: 73.8 CO2 is at the critical point.

Case 5 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 315 Enter the pressure of carbon dioxide in bar: 140 Temperature is within safe operating conditions. Warning! Reduce the pressure! Decrease the pressure by at least 9.85 bar.

Case 6 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 299 Enter the pressure of carbon dioxide in bar: 80.5 CO2 is below the critical temperature. Increase the temperature by at least 5.20 Kelvin. Pressure is within safe operating conditions.

Case 7 Sample Output

$ python3 py2_ind_1_username.py Enter the temperature of carbon dioxide in Kelvin: 349.3 Enter the pressure of carbon dioxide in bar: 71.5 Warning! Reduce the temperature! Decrease the temperature by at least 22.37 Kelvin. CO2 is below the critical pressure. Increase the pressure by at least 2.30 bar.