Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, please. Assignment guidelines are below under Assignment. In Python, please. Assignment guidelines are above under Assignment. BELOW IS THE OUTLINE FOR THE CODE

In Python, please. Assignment guidelines are below under "Assignment".

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

In Python, please. Assignment guidelines are above under "Assignment". BELOW IS THE OUTLINE FOR THE CODE IT MUST BE USED:

image text in transcribed

6.24 LAB: Vapor Pressure Calculation using the Peng-Robinson Equation of State Introduction The purpose of this lab is to implement the calculation of vapor pressure of a pure liquid substance using a real-gas equation of state. The vapor pressure is the pressure at which a pure substance boils at a specific temperature (conversely, the boiling point temperature is the temperature at which a pure liquid substance boils at a specific pressure). We envision here a function whose inputs are (1) the identity of some pure substance (for example, water, benzene, hexane, ammonia, whatever), and (2) the temperature, and whose output is the vapor pressure of that substance at that temperature. Vapor-pressure calculations routinely performed as part of the design of chemical process units, such a distillation columns and flash separators Relevant Equations The basis of this lab is the fact that vapor pressure is implicit in real-gas equations of state. Before we consider how our program to uncover vapor pressure will eventually work, let's first consider what we mean by real-gas equation of state. The ideal gas law where is an example of an equation of state, but it is not realistic enough to describe vapor-liquid equilibrium (e.g, boiling). The actual interrelationships among pressure, volume, moles, and temperature are much more complicated than the ideal gas law for real substances One industry-standard 'real-gas" equation of state is the Peng-Robinson (PR) equation (D.-Y. Peng and D. B. Robinson, Ind. Eng. Chem. Fundam. 1976:15:59) RT a(T) Here, b is a species-specific parameter representing volume-per-molecule and a(T) is a species-specific function of temperature representing intermolecular interactions. For most useful engineering calculations, the PR equation (and other real-gas equations of state everybody has their own favorite) is cast in the form of a cubic equation in the compressibility factor Z RT = 0.37464 + 1.54220 -0.26992- A 0.45724 B = 0.07780 P (T PcT Te P T P an This may look complicated, but it really only has four parameters: the critical temperature Tc, the critical pressure Pc, the acentricity factor ("omega"), and the gas constant R. The temperature T and pressure P are considered variables, not parameters. In this cubic form, it is clear that the PR equation can have three roots. For certain values of the coefficients co, C1, and c2, there might exist three real roots, while for other values, there might exist only one real root (the other two are complex conjugates of each other). In the case that only one real root is found, there is only one phase (either liquid or vapor) at the specified T and P. However, in the case that three real roots are found, then the lowest one, say Z is associated with a liquid, and the highest one, say Zv, is associated with a vapor. (Here, the middle one is ignored.) Note that we use the following units: P [] bar, T []K. The existence of both a liquid root and a vapor root implies liquid-vapor coexistence, but it does not guarantee that P is the vapor pressure at T. To decide whether the liquid and vapor phases signified by the two roots of P-R are in fact in equilibrium with each other, one has to confirm that their fugacities are equal. Fugacity is a thermodynamic property derived by engineers to make phase-equilibrium calculations easy. For substances obeying the P-R equation of state, one can compute the fugacity fat a specific Z using this equation: f(T, P) = P expl Z-1-ln(Z-B) In Here, the parameters A and B are the same ones used in PR above. So, if we are lucky enough to find real values for ZL and Zy at the requested T and our guess for P we just plug them each into the fugacity equation independently to get two fugacity values, call them f and fv, respectively. We then ask whether or not they have the same value. If so, then our guess P is PVap(T). If not, we have to have an algorithm to adjust P until we get Pvap, signified by fu f The Algorithm The convergent algorithm for computing pvap at T using P-R is as follows I. Choose Tc, Pc, and for your substance; 2. Specify temperature T 3. Guess a value for P (1 bar is good a lot of the time) 4. Compute the coefficients Co. C1, and C2 using the equations for A and B that depend on T, P Tc, Pc, and u; 5. Find the roots of the associated cubic using numpy. roots ( [ 10, c2, c1 , ) (see below). The vapor-phase root Zv is the first element returned by numpy. roots () (if it is real), and the liquid-phase root Zu is the third element returned by numpy.roots is real) (if it 6. If both Zy and Zu arereal numbers (not complex), then compute the two fugacities using Eqn. 2: fy-f(Zy) and f f(Zu). If not, go to step 3. and choose a different initial guess for P (if Z is really small, use a lower guess, if Z is close to 1, use a higher guess) 7. If fy and f are equal, then P is pvap, and we're done. If not, adjust the value of P by multiplying it by f/fy and go to step 4 Using numpy.roots() to Find Roots of a Cubic Part of your solution to this lab will require finding the roots of a cubic equation. The roots() function of the Numpy module makes this very easy. To use it, you should first import the NumPy module. (You may need to install on your own machine it first, don't worry-the python in zyBooks has it already, and if you install Anaconda on your own laptop as recommended, you already have it.) Then, you can use the numpy.roots() function to find the root of any polynomial. roots() takes single array argument containing the coefficients of the polynomial, in a specific order. The first element is the coefficient on the highest power of x, the second is the coefficient on the second highest, and so forth. An array of n elements implies an n-1-order polynomial. Consider the interactive Python session belovw >>> from numpy import roots # return an array of -1, 1 as the roots to x^2-1 array ([-1., 1.]) # compute roots of x^3-1 and store in array r >>> print (r [0]) (-0.5+0.866025403784j) >>> print (r [1]) (-0.5-0.866025403784j) >>>print (r [1].real) >>>print (r [1].imag) -0.86602540784 >>> print (r [2]) # compute roots of x^3-6 x^2 + 11 x - 6 = (x-3) (x-2) (x-1); note order of elements in array r >>>print (r[0]) 3 >>>print (r [1]) >>>print (r [2]) 1 Notice that the character j is Python's default for the imaginary number sqrt(1), and complex numbers of tuples where the first element is the real part and the second is the imaginary part. One can access either part using the real and .imag methods Assignment Using an IDE or text editor on your own computer, download and edit the template main.py to completely implement the following four functions 1. kappa ( omega ) : Returns the value of given the value of 2. AB(T,P, Tc, Pc,omega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical temperature Tc 3. pr_fug (z,A,B,P) Computes the fugacity (in whatever units P has) given the value for Z (compressibility factor), A and B (the P-R 4. Pvap(T,Pinit,Tc, Pc,omega,ep,maxiter) Returns the vapor pressure pvap at temperature T for the pure substance with critical pressure Pc, and acentricity factor w parameters), and the pressure P (see eqn. 2) critical constants To, Pc and w; Pinit is an initial guess for the vapor pressure. ep is an optional argument with default value 1.e-6 that sets the tolerance for when two floating point numbers are "equal. maxiter is an optional argument with default value 1,000 that sets the maximum number of iterations in the above algorithm. Pvap() will call the functions pr_fug) and AB, and AB() will call kappa() Test Benches Your four functions will be each be tested for accuracy. When you run the test benches, you will be able to determine, based on which test fails first, where errors may be in your code. For example, if the first test fails, this means you are not computing kappa correctly. If the second test fails, this means you are not computing the values of A and B correctly. You can run the test bench as many times as needed to debug your code. The most important test is the last, where your code is used to compute the vapor pressure of cyclohexane (a major synthetic commodity chemical) at various temperatures. The results of your code are compared to both the solution (which should match exactly) and to the published experimental data for cyclohexane from the Dortmund Data Bank. Notice that your code does a pretty good job reproducing experiemental values def kappaargument(s) go here' "' : your code here def AB argument(s) go here: your code here def pr fug (" arguments(s) go here"'"): your code here def Pvaparguments(s) go here'"": crit 0 numiter - 0 p-Pinit while abs(1.0-crit) > ep and numiter >> from numpy import roots # return an array of -1, 1 as the roots to x^2-1 array ([-1., 1.]) # compute roots of x^3-1 and store in array r >>> print (r [0]) (-0.5+0.866025403784j) >>> print (r [1]) (-0.5-0.866025403784j) >>>print (r [1].real) >>>print (r [1].imag) -0.86602540784 >>> print (r [2]) # compute roots of x^3-6 x^2 + 11 x - 6 = (x-3) (x-2) (x-1); note order of elements in array r >>>print (r[0]) 3 >>>print (r [1]) >>>print (r [2]) 1 Notice that the character j is Python's default for the imaginary number sqrt(1), and complex numbers of tuples where the first element is the real part and the second is the imaginary part. One can access either part using the real and .imag methods Assignment Using an IDE or text editor on your own computer, download and edit the template main.py to completely implement the following four functions 1. kappa ( omega ) : Returns the value of given the value of 2. AB(T,P, Tc, Pc,omega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical temperature Tc 3. pr_fug (z,A,B,P) Computes the fugacity (in whatever units P has) given the value for Z (compressibility factor), A and B (the P-R 4. Pvap(T,Pinit,Tc, Pc,omega,ep,maxiter) Returns the vapor pressure pvap at temperature T for the pure substance with critical pressure Pc, and acentricity factor w parameters), and the pressure P (see eqn. 2) critical constants To, Pc and w; Pinit is an initial guess for the vapor pressure. ep is an optional argument with default value 1.e-6 that sets the tolerance for when two floating point numbers are "equal. maxiter is an optional argument with default value 1,000 that sets the maximum number of iterations in the above algorithm. Pvap() will call the functions pr_fug) and AB, and AB() will call kappa() Test Benches Your four functions will be each be tested for accuracy. When you run the test benches, you will be able to determine, based on which test fails first, where errors may be in your code. For example, if the first test fails, this means you are not computing kappa correctly. If the second test fails, this means you are not computing the values of A and B correctly. You can run the test bench as many times as needed to debug your code. The most important test is the last, where your code is used to compute the vapor pressure of cyclohexane (a major synthetic commodity chemical) at various temperatures. The results of your code are compared to both the solution (which should match exactly) and to the published experimental data for cyclohexane from the Dortmund Data Bank. Notice that your code does a pretty good job reproducing experiemental values def kappaargument(s) go here' "' : your code here def AB argument(s) go here: your code here def pr fug (" arguments(s) go here"'"): your code here def Pvaparguments(s) go here'"": crit 0 numiter - 0 p-Pinit while abs(1.0-crit) > ep and numiter

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Is there any formal training for teaching?

Answered: 1 week ago