Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help wich this lab using python programming Language. Can you please help me? LAB: Vapor Pressure Cakulation wing the Peag-Robiason Equation of State

image text in transcribed
image text in transcribed
image text in transcribed
I need help wich this lab using python programming Language. Can you please help me? LAB: Vapor Pressure Cakulation wing the Peag-Robiason Equation of State Introduction The purpose of this lab is to implement the calcelation of vapor pressure of a pure liquid substance using a real-gas equation of pressure is the pressure at which a pure substance boils at a specific temperature (conversely, the bolling point temperature is th a pure liquid substance boils at a spocifie pressane). We cnvision here a function whose inputs are (1) the identity of some pure s water, benunene, hexane, ammonia, whatever), and (2) the tomperabure, and whose output is the vapor pressure of that substance at Vapor-peessure calculations routinely perfoemed as part of the design of chemical process units, such a distillation columns and n Relevant Equations The basis of this lab is the fact that vapor pressure is implicir in real-gas equations of state. Before we consider how our program pressure will eventualy week, let's first consider what we mean by real-gas equatien of Mate. The ideal gas law RT is an examplk of an oquation of state, but it is not realistic enough to describe vapor-liquid equilibrium (eg, boiling). The actua among pressure, volume, moles, and temperature are much more complicated than the ideall gas law for real substances One indu gas" equation of state is the Peng-Robinson (PR) equation (D-Y. Peng and D. B. Robinson, Ind Eng Chem Fundam 197615 RT a(T) Here, b is a spocies-speocific parameter representing volume-per-melecule and aft) is a species-specifis function of temperature representing intermolecular interactions. For most uscful engineering calculations, the PR cquation (and other rcal-gas oquation has their own favorite) is cast in the form of a cubic equation in the cempresibility factor 2 K 0.37464 + 1.5422w-0.26992- A 0.45724 and Te Te P T P B 0.07780 This may look complicated, but it really only has four paramesers: the eritical temperature To the critical pressure P the aceic and the gas constant R. The temperature T and pressure P ane considered varialses, sot parameters. In this cubic form it is clear t have three roots For certain values of the cooficients co.ey, and etheore might exist three real roots, while for other valoes, the real foot In the case that only onc real ot is found, there is cely one phase 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 liqu one, say Zv. is associated with a vapor (Hore-the middle one is ignored.) Nete that we use the following-nits:P-bar, T- The existence of bodh a liquid root and a vapor root implies liquid-vapor coexistence, but it does not puarantee that P is the vapoe 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 their fugacities are eqal. Fugacity is a thermodynamic propenty derived by engineers to make phase-equilibeium caleulations ea obeying the P-R equation of state, one can compute the fugacityfat a specific Z wsing this equation Here, the parameters A and B are the same oees used in PR above. So, if we are lucky enough to find real values for 21 and Zy a and owr guess for P, we just plug them each into the fugacity equation independently to get two fugacity values; call them f and f then ask whether or not they have the same value. If so, then our guess P is PT) If not, we have to have an algorith m so adju signified by The Algorithm The convergent algorithm for computing Pha at T using P-R is as follows 1. Choose Te Pe ando for your substance 2. Specify temperature T Guess a valoe for P(I bar is good a lot of the time) 4. Compate the coefficients cj, and using the equations for A and B that depend on T. P. Te Po and e; Find the roots of the associated cubic using numpy roots[1.0..see below). The vapor-phase root Zy is the firstelo by numpy roots0 if it is real), and the liquid-phase root Z1, is the dhind clement returned by mampy.rootsO (if it is real If bodZv and Zg are mil numbers (not complex), then compte the two fugacities using Eqn 2: Ev-qZy) and ft-ZL). choose a different initial guess for P (if Z is really small, use a lower guess; if Z is elose to 1, use a higher guess). 6. Safarive the same valuc. Iso, 3:08 AM is PI aot, we have uignified by - The Algorithm The convergent algorithm for computing P at Tusing P-R is as follow I. Choose Te, Pe ando for your substance 2 Specify temperature T 3, Guess a value for P(l bar is good a lot of the time) 4. Compute the coefficients cj, and c using the equations for A and B that depend on T. P. TePe and Find the roots of the associated cubic using numpy root[1.0.c.see below). The vapor-phase root Zy is the firstclu 6. If both Zy ahd ZL-e mal nuelets(not con plex), then comple the two fupacities using Eqa 2: v-qZv) and _GZL). I If fy and fi are equal, then P is PP, and we're done. Ifnot, adjust the value of P by multiplying it by fi/fy and go to step 4 by sumpy.roots0 if it is real), and the biquid-phase rook Z1, is the shind clement eeturned by nampy roosO if it is real) choose a different initial guess for P (if Z is really small, use a lower guess; ifz is elose to 1, use a higher guess). Using numpyrooe) to Find Rooes 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 mak use it, you should first import the NumPy modele.(You may need to install on your own machine it first, dont worry- the pytho already, and if you install Anaconda on your own laptop as recommended, you already have it.) Then, you can use thmmpyro root of any polymomial. roots) takes single array argument ooetaining the coofficients of the polynomial, in a specific order. The coefficient on the highest power of x, the second is the cocficient on the sccond highest, and so forth An array of e clements imp polynomial. Consider the interactive Python session below >> from numpy import roots ceturn an azzay of-1, 1 as the zoots to x*2-1 oot(1.0-1 array(t-1 1-1 # compute roots of x^3-1 and stor. in array r OOLS(.0.0-11 >>>print (r[0) 0.5+0.8660254037845 >> print () -0.5-0.8660254037845 >>pzint (e[1].zeal) -0-5 >>print ((11.imag >> print (r [2)) >> roots(1.-6-11-6 >>> print ([01) >>> print (r(1)) >>> print (z(2)) Notice that the character j is Python's default for the imaginary number sq(-I), and complex numbers of tuples where the first el and the second is the iowaginary part One can access cither part wsing the real and amag mothods. Assignment Using an IDE or test editor ea your owa computer, dow nload and edit the template main.py to completely implement the fellow ing fourfunctee 1. kappa(omega Returms the value of given the value ofe 2. ,P.TePeamega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical t critical pressure Pe nd acestricity factor ea pr fugz,A,B.P): Cemputes the fugacity (in whatever units Phas) gven the value for Z(compressibility factor)A parameters), and the pressure P(see eqa 2) Returns the vaper pressure Phap at temperature T for the pure substance wi Te Pe and w Pinit is an initial guess for the vaper pressure, ep is an optional argument with default value 1.e-6 tha when tno floating peint numbers are "equal". maxiter is an optional argument with default value 1,000 that sets th 4. Pvap T.Pinit,Te iterations in the above algorithm. PrapO will call the functions pr fug0 and ARO and ABO will call Lappa). Test Benches Your four functions will be each be nested for accuracy. When you run dhe test benches, you will be able to determine, based on w where erros may be in your code. For example, if the first sest fails, this means you ane not computing kappa corroctly, If the seo means you are not computing the values of A and B correctly. You can run the test bench as many times as needed to debung your mportant test is the last, whore your code is used to compute the vagor pressure of cyclobcxane (a major synthetic commodity ch temperatures. The reaults of your code are compared to both the solation (which should match esastly) and to the published exper cyclobexane from the Doetmund Data Bank. Notice that your code does a peety good job repeoducing experiemental values Safr 3:08 AM > roots(1-6,11-61 >>> print (01) >>>print (r(1 >>print ([2)) Notice that the characterj is Python's default for the imaginary number si-), and complex numbers of tuples where the finst cl and the second is the iowaginary part. One can access either part wsing the real and imag methods Assignment Using an IDE or test editer ea your own computer, dow nload and edit the template main.py to completely implement the fellow ing fourfunctias: 1. kappa(omega) Retures the value ofgiven the value efe 2. T,P,TePeamega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical t 3. pr fugizA,B,P): Cemputes the fugacity (in whatever units Phas) given the value for 2(compressibility factor).A 4. Pvap (T.Pinit,Te critical pressure P and acemtricity factor e parameters), and the pressure P(see eq 2) Returns the vaper pressure Pp at temperature T for the pure substance wi Te Pe and Pinit is an initial guess for the vaper pressure, ep is an optional argument with default value 1.e6tha when two floating point numbers are "equal" maxiter is an optional argument with default value 1,000 that sets th iterations in the above algorichm. PrapO will call the functions pr fugO and ABO and ABO will call kappa) Test Benches Your four functions will be each be tested for accuracy. When you run dhe test benches, you will be able to determine, based on w where errors may be in your code. For example, if the first sest fails, this means you are not computing kappa correctly. If the secu means you are not computing the valles of A and B correctly. You can run the nest bench as many times as needed to debug your important test is the last, whore your code is used to compute the vagor pressure of cyclobexane (a major synthctic commodity ch temperatures The results of your code are compared to both the solution (which should match exactly) and to the published exper cyelolesane from the Doetmund Data Bank Notice that your code does a pecay good job ropeoducing expericmental values. PROGRAM FILE msin.py with stert mp def lappa( argumentis) go bere e your code here def ABargumem(s) go here eyour code here def pr fug ( argumemtsis) go here d your code here crit-o P- Pinit while abs( 1.0-crit)> ep and numiner In the case that only onc real ot is found, there is cely one phase 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 liqu one, say Zv. is associated with a vapor (Hore-the middle one is ignored.) Nete that we use the following-nits:P-bar, T- The existence of bodh a liquid root and a vapor root implies liquid-vapor coexistence, but it does not puarantee that P is the vapoe 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 their fugacities are eqal. Fugacity is a thermodynamic propenty derived by engineers to make phase-equilibeium caleulations ea obeying the P-R equation of state, one can compute the fugacityfat a specific Z wsing this equation Here, the parameters A and B are the same oees used in PR above. So, if we are lucky enough to find real values for 21 and Zy a and owr guess for P, we just plug them each into the fugacity equation independently to get two fugacity values; call them f and f then ask whether or not they have the same value. If so, then our guess P is PT) If not, we have to have an algorith m so adju signified by The Algorithm The convergent algorithm for computing Pha at T using P-R is as follows 1. Choose Te Pe ando for your substance 2. Specify temperature T Guess a valoe for P(I bar is good a lot of the time) 4. Compate the coefficients cj, and using the equations for A and B that depend on T. P. Te Po and e; Find the roots of the associated cubic using numpy roots[1.0..see below). The vapor-phase root Zy is the firstelo by numpy roots0 if it is real), and the liquid-phase root Z1, is the dhind clement returned by mampy.rootsO (if it is real If bodZv and Zg are mil numbers (not complex), then compte the two fugacities using Eqn 2: Ev-qZy) and ft-ZL). choose a different initial guess for P (if Z is really small, use a lower guess; if Z is elose to 1, use a higher guess). 6. Safarive the same valuc. Iso, 3:08 AM is PI aot, we have uignified by - The Algorithm The convergent algorithm for computing P at Tusing P-R is as follow I. Choose Te, Pe ando for your substance 2 Specify temperature T 3, Guess a value for P(l bar is good a lot of the time) 4. Compute the coefficients cj, and c using the equations for A and B that depend on T. P. TePe and Find the roots of the associated cubic using numpy root[1.0.c.see below). The vapor-phase root Zy is the firstclu 6. If both Zy ahd ZL-e mal nuelets(not con plex), then comple the two fupacities using Eqa 2: v-qZv) and _GZL). I If fy and fi are equal, then P is PP, and we're done. Ifnot, adjust the value of P by multiplying it by fi/fy and go to step 4 by sumpy.roots0 if it is real), and the biquid-phase rook Z1, is the shind clement eeturned by nampy roosO if it is real) choose a different initial guess for P (if Z is really small, use a lower guess; ifz is elose to 1, use a higher guess). Using numpyrooe) to Find Rooes 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 mak use it, you should first import the NumPy modele.(You may need to install on your own machine it first, dont worry- the pytho already, and if you install Anaconda on your own laptop as recommended, you already have it.) Then, you can use thmmpyro root of any polymomial. roots) takes single array argument ooetaining the coofficients of the polynomial, in a specific order. The coefficient on the highest power of x, the second is the cocficient on the sccond highest, and so forth An array of e clements imp polynomial. Consider the interactive Python session below >> from numpy import roots ceturn an azzay of-1, 1 as the zoots to x*2-1 oot(1.0-1 array(t-1 1-1 # compute roots of x^3-1 and stor. in array r OOLS(.0.0-11 >>>print (r[0) 0.5+0.8660254037845 >> print () -0.5-0.8660254037845 >>pzint (e[1].zeal) -0-5 >>print ((11.imag >> print (r [2)) >> roots(1.-6-11-6 >>> print ([01) >>> print (r(1)) >>> print (z(2)) Notice that the character j is Python's default for the imaginary number sq(-I), and complex numbers of tuples where the first el and the second is the iowaginary part One can access cither part wsing the real and amag mothods. Assignment Using an IDE or test editor ea your owa computer, dow nload and edit the template main.py to completely implement the fellow ing fourfunctee 1. kappa(omega Returms the value of given the value ofe 2. ,P.TePeamega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical t critical pressure Pe nd acestricity factor ea pr fugz,A,B.P): Cemputes the fugacity (in whatever units Phas) gven the value for Z(compressibility factor)A parameters), and the pressure P(see eqa 2) Returns the vaper pressure Phap at temperature T for the pure substance wi Te Pe and w Pinit is an initial guess for the vaper pressure, ep is an optional argument with default value 1.e-6 tha when tno floating peint numbers are "equal". maxiter is an optional argument with default value 1,000 that sets th 4. Pvap T.Pinit,Te iterations in the above algorithm. PrapO will call the functions pr fug0 and ARO and ABO will call Lappa). Test Benches Your four functions will be each be nested for accuracy. When you run dhe test benches, you will be able to determine, based on w where erros may be in your code. For example, if the first sest fails, this means you ane not computing kappa corroctly, If the seo means you are not computing the values of A and B correctly. You can run the test bench as many times as needed to debung your mportant test is the last, whore your code is used to compute the vagor pressure of cyclobcxane (a major synthetic commodity ch temperatures. The reaults of your code are compared to both the solation (which should match esastly) and to the published exper cyclobexane from the Doetmund Data Bank. Notice that your code does a peety good job repeoducing experiemental values Safr 3:08 AM > roots(1-6,11-61 >>> print (01) >>>print (r(1 >>print ([2)) Notice that the characterj is Python's default for the imaginary number si-), and complex numbers of tuples where the finst cl and the second is the iowaginary part. One can access either part wsing the real and imag methods Assignment Using an IDE or test editer ea your own computer, dow nload and edit the template main.py to completely implement the fellow ing fourfunctias: 1. kappa(omega) Retures the value ofgiven the value efe 2. T,P,TePeamega): Returns both the values of PR parameters A and B given temperature T, pressure P, critical t 3. pr fugizA,B,P): Cemputes the fugacity (in whatever units Phas) given the value for 2(compressibility factor).A 4. Pvap (T.Pinit,Te critical pressure P and acemtricity factor e parameters), and the pressure P(see eq 2) Returns the vaper pressure Pp at temperature T for the pure substance wi Te Pe and Pinit is an initial guess for the vaper pressure, ep is an optional argument with default value 1.e6tha when two floating point numbers are "equal" maxiter is an optional argument with default value 1,000 that sets th iterations in the above algorichm. PrapO will call the functions pr fugO and ABO and ABO will call kappa) Test Benches Your four functions will be each be tested for accuracy. When you run dhe test benches, you will be able to determine, based on w where errors may be in your code. For example, if the first sest fails, this means you are not computing kappa correctly. If the secu means you are not computing the valles of A and B correctly. You can run the nest bench as many times as needed to debug your important test is the last, whore your code is used to compute the vagor pressure of cyclobexane (a major synthctic commodity ch temperatures The results of your code are compared to both the solution (which should match exactly) and to the published exper cyelolesane from the Doetmund Data Bank Notice that your code does a pecay good job ropeoducing expericmental values. PROGRAM FILE msin.py with stert mp def lappa( argumentis) go bere e your code here def ABargumem(s) go here eyour code here def pr fug ( argumemtsis) go here d your code here crit-o P- Pinit while abs( 1.0-crit)> ep and numiner

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago