You are on page 1of 54
35 APPENDIX A DETAIL CHARACTERIZATION METHOD APPENDIX A.1 - NOMENCLATURE - a7 APPENDIX A.2 - COMPUTATION PROCEDURES 38 APPENDIX A.3 - COMPUTER PROGRAM DOCUMENTATION 40 APPENDIX A.4 - FORTRAN CODE LISTING . . 49 APPENDIX A.5 - COMPUTER PROGRAM CALCULATIONS | 74 APPENDIX A.6 - CALCULATION UNCERTAINTIES : 76 APPENDIX A.7 - REFERENCES ; Fe 37 APPENDIX A.1 NOMENCLATURE ‘Symbol = Represented Quantity AAD = average absolute deviation B = second virial costticient BIAS = bias. coefficients which are function of composition molar density F,, = supercompressibilty factor maximum value of Zo number of data points absolute pressure {gas constant Toot mean squared deviation standard deviation absolute temperature ‘components of the mixture compressibility factor compressibility factor at base conditions calculated compressibility factor Za = felative percentage difference between calculated and experimental compressibility factors Zens = Zya for ith data point (Zamoae = Maximum value of Zye experimental compressibility factor p= mass density 38 APPENDIX A.2 DETAIL CHARACTERIZATION METHOD COMPUTATION PROCEDURES A.2.1 Computations of Compressibility Factors and Densities, Figure A.2.1 gives the procedure used for computation of the compressibility factor Z using the DETAIL CHARACTERIZATION METHOD in Section 8.1, 1. Input is made of the mole fractions of the components in the gas. The gas mixture molar mass is calculated using Equation 3, Section 4, 2. Input is made for the temperature and pressure for which the computation of the compressibility factor is desired. 3, Computation is made of the coefficients B and C;, in the equation of state. These coeticients are functions of absolute temperature and the mole fractions of the components in the gas mixture. Constants required for this calculation {re given in Section 8.1 in Tables 3, 4 and 5. Equations 15 through 23, Section 8.1.2, are required for the computations of B and C, 4. The molar density d is computed using the equation of state relation for the prossure P given in Equation 24, Section 8.1.3. The computation procedure Used is referred to as Brent's method and is given in Reference 5 in Appendix (AT. In the iterative procedure for solving for the molar density d, the convergence criterion is either agreement of the pressure calculated using Equation 24 with the specified pressure within an absolute relative deviation of 1x10° or agreement of successive iterative values of d within an absolute relative deviation of 1x10", The mass density is calculated using Equation 4, 5. The compressibility factor Z is computed using Equation 12, Section 8.1.2, ‘A.2.2 Computations of Other Quantities Other quantities of interest such as the supercompressibility factor, the density at contract conditions and the volumetric gross heating value for specttied reference conditions Can be calculated using relations in Equations 1-11 in Sections 4 and 6 and Appendix C. 39 [ Compute coefficients BC; | Iterate P-dRTU1 «B+. Output Z,F ede Figure A2.1. Procedure for Calculation of Z, F,,,.d, and p 40. APPENDIX A.3 DETAIL CHARACTERIZATION METHOD COMPUTER PROGRAM DOCUMENTATION. A.3.1 Scope “This appendix provides summary documentation for the FORTRAN language computer program code listing whieh is given in Appendix A.4 for the DETAIL CHARACTERIZATION METHOD. This documentation includes a summary flow diagram of the computer program and descriptions of the main program and each subroutine. Additional documentation is provided by comment statements within the computer program listing, A.3.2 Summary Flow Diagram Figure A.3-1 is a summary flow diagram for use of the computer program in Appendix A4. This computer program was developed for efficient computations of natural gas ‘compressibility factors using the DETAIL CHARACTERIZATION METHOD, in which the mole percentages of gas mixture components are known. ‘One program driver block (Application Program) and four computation blocks are shown in Figure A.-1, The principal subroutine used by a given computation block is shown to the left of that computation block, The computation blocks and the principal subroutines used are, (1) calculation of component dependent quantities (PARAMDL), (2) calculation of composition dependent quentities (CHARDL), (3) calculation of temperature dependent quantities (TEMP), (4) calculation of density dependent quantities (DDETA\L). A.3.3 Driver Block For efficient computations, the application program should call the principal subroutines in @ sequence corresponding to the sequence of the four computation blocks. This ‘computation sequence is efficient because it minimizes unnecessary repeated calculations ‘An example of an unnecessary repeated calculation is the calculation of a temperature dependent quantity each time the density is calculated at a series of pressures, even though the temperature may be the same for some of these density calculations. Thus, if the computation sequence in Figure A.3-t is incorporated in any other driver program, the efficiency of this sequence will be maintained a DETAIL CHARACTERIZATION METHOD COMPUTER PROGRAM STRUCTURE HARD Dora PRESSURE CHANGE. TEMPERATURE CHANGE CHANGE W COMPONENTS Figure A.3-1. Computation Sequence for DETAIL CHARACTERIZATION METHOD Computer Program 42. A.3.4 Component Dependent Quantities Block ‘The computer program structure shown in Figure A.3-1 corresponds to the four levels, of information which are required in the DETAIL CHARACTERIZATION METHOD equation of state, First, the components of which the gas mixture is composed must be identified. The ‘number of components, NCC, and the component identification numbers, C1D(1), C1D(2). CIDINCC), are required by subroutine PARAMDL. PARAMDL obtains fixed parameters from BLOCK DATA and calculates other parameters required subsequently. This completes the frst ‘computation block. Note that for most efficient computation, subroutine PARAMDL is never called again until the components in the gas mixture change. A.3.5 Composition Dependent Quantities Block For computations in the second computation block, the composition of the gas mixture must be identified. The mole percentages of each component, XI(1}, X1(2), .., XI(NCC), are required by subroutine CHARDL. CHARDL calculates composition dependent quantities which are required subsequently. Note that for most efficient computation, CHARDL subroutine is. ‘never called again until there is a change in the composition of the gas mixture. A.3.6 Temperature Dependent Quantities Block For computations in the third computation block, the temperature must be identiied. ‘Subroutine TEMP requires the absolute temperature T. TEMP calls subroutine B, which calculates the second virial coefficient B for the gas mixture at the temperature T. TEMP then calculates the other coefficients in the equation of state for the gas mixture, C;, for the absolute temperature T. Note that for most efficient computation, subroutine TEMP and subroutine B are never called again until there is a change in the temperature of the gas mixture, A.3.7 Density Dependent Quant For computations of density and density dependent quantities in the fourth computation block, the pressure must be identified. Function DDETAIL requires the absolute pressure P. DDETAIL uses Brent's method to solve for the density of the gas mixture of composition XI(1), Xi(2), -.. XI(NCC) at absolute temperature T and specified absolute pressure P. Function DDETAIL calls subroutine BRAKET, which determines two values of density, RHOL and HOH, which, when used in the equation of state, yield calculated absolute pressures PRHOL. and PRHOH which bracket the specified pressure P. The densities RHOL and RHOH, which bracket the solution for density at the specified pressure P, are then used in function DDETAIL to solve for the density corresponding to the specified pressure P. Both function DDETAIL and subroutine BRAKET call funcion PDETAIL, which calculates the pressure for a specified density, RHO. Function PDETAIL calls function ZDETAIL, which calculates the compressibility factor for a specified temperature and density. ‘A.3.8 Descriptions of Functions and Subroutines FORTRAN functions and subroutines used to calculate density related properties from the DETAIL CHARACTERIZATION MODEL are listed below. These routines are available in the module DETAILXZ.FOR, listed in Appendix A.4, FUNCTION DETAIL (P, T) FUNCTION PDETAIL (D, T) FUNCTION ZDETAIL (D, T) SUBROUTINE B (T, BMIX) SUBROUTINE BRAKET (CODE, T, P, RHO, RHOL, RHOH, PRHOL, PRHOH) SUBROUTINE CHARDL (NCC, XI, 28, DB) SUBROUTINE PARAMDL (NCC, CID) SUBROUTINE TEMP (T) BLOCK DATA 4.3.8.1 BLOCK DATA BLOCK DATA is a block data section which contains the fixed constants used in the equation of siate computations of the compressibility factor using the DETAIL CHARACTERIZATION METHOD. These fixed constants include the gas constant, RGAS, the equation of state constants, A(1) through A(58), compound characterization parameters, thal fs, the molecular masses CMWB(J) for each compound, energy, size and orientation parameters EIB(J). RKIB(J), and WIB(J) for each compound, and’ the binary interaction parameters BEIJE(i.J), BKIJB(I,J), BWIJB(|wJ), and BUWB(IW). ‘A.3.8.2 Subroutine PARAMDL Subroutine PARAMDL assigns component and binary parameters for a mixture containing NCC components with component identification numbers CID(1), CID(2), CID(NCC) from Tables § and 6. Pure component and binary parameters in BLOCK DATA which are required by PARAMDL are accessed through the common block COMMON/PARAM 3.8.3 Subroutine CHARDL Subroutine CHARDL calculates a number of composition dependent quantities using the mole percent values for the components in the mixture, XI(1), XI(2).... XINCC). The mole Percent values are used to calculate normalized mole fractions by dividing each component ‘mole percent by the sum of the component mole percents, The gas mixture average molar ‘mass is calculated as the molar average of the component molar masses. Composition dependent coefficients of temperature functions in the second viria) coetficient are calculated for subsequent use in subroutine B. Also calculated are values of the mixture size parameter (K" in the text and RK3PO in the program), the mixture quadrupole parameter (QF in the text ‘8nd Q2PO in the program). the mixture energy parameter (U in the text and U in the program), fand the mixture onentation parameter (W in the text and W in the program) 44 A.3.8.4 Subroutine B Subroutine B calculates the second virial coefficient for the gas mixture at the absolute temperature T. The required composition dependent coetticients are accessed through COMMON/VIRI. The computed second viral coefficient BMIX is made accessible through the subroutine argument, A.3.8.5 Subroutine TEMP Subroutine TEMP calculates a number of quantities which are functions of temperature but not density, These quantities are B4 through B12 and FN(13) through FN(58), which are related to the coetficients of the density functions in the equation of state. Required mixture parameters are accessed through COMMON/AGAVARIABLES/. Required equation of siate parameters are accessed from BLOCK DATA through COMMON/EOSAI/. The required absolute temperature T is accessed through the subroutine TEMP argument. Subroutine TEMP calls subroutine B for the calculation of the second virial coefficient at the absolute temperature T. The quantities calculated in subroutine TEMP are made accessible through COMMON/AGAVARIABLES/ and COMMON/AGAEOS). 4.3.8.6 Function Subprogram DDETAIL Function subprogram DDETAIL uses Brent's method to calculate the molar density for the specific temperature and pressure in argument of DETAIL (P, T) DDETAIL calls subroutine BRAKET, which brackets the solution for the density. BRAKET determines two values of density, RHOL and RHOH, which, when used in the equation of state, yield calculated absolute pressures PRHOL and PRHOH which bracket the specified pressure P, The densities RHOL and RHOH, which bracket the solution for density at the specified pressure P, are then used by DDETAIL as initial values for use in Brent's method, The first iteration of Brent's method uses inverse linear interpolation between RHOL and RHOH to estimate a thitd trial root, Subsequent iterations of Brent's method make the most efficient choice between inverse quadratic interpolation, inverse linear interpolation and bisection to estimate a new trial root. New trial roots in a given iteration are not allowed to stop outside of the current bounds which bracket the solution for density (if an interpolation fails to stay within the bracketing bounds, the method defaults to the bisection method for that iteration), DDETAIL calls function subprogram PDETAIL for the calculation of the absolute pressure at trial Gensity roots. The iterative calculation is considered converged in DDETAIL when the absolute value of the differance between the calculated pressure and the specified pressure 1s less than the product of the specified absolute pressure and the pressure ‘convergence tolerance EPSP and when the absolute value of the difference between wo Gensities which bracket the solution is less than the produc! of the more accurate density and the density convergence tolerance EPSR. The two convergence tolerances EPSP and EPSR are speciiied in DDETAIL. The maximum allowed number of iterations, ITMAX, also is specified in the data statement. The quantily EPSMIN, which must be smaller than EPSR and 45, greater than the machine floating point precision for the computer being used, must also be specified in DDETAIL so that iterative steps in density which are smaller than the computer precision will not be attempted. The quantity CODE is initialized to 0.0; CODE is set to 1.0 in subroutine BRAKET when there is a maximum in pressure versus density at a pressure below the specified absolute pressure P. 4.3.8.7 Subroutine BRAKET ‘Subroutine BRAKET determines two densities, RHOL and RHOH, which bracket the solution for density. The corresponding absolute pressures, PRHOL and PRHOH, bracket the specified pressure P. Thus, when the density RHOL is used in the equation of state, the absolute pressure PRHOL is calculated, such that PRHOLP. The first tral values for density in BRAKET are RHO1=0,0 and RHO2. RHO? is approximately the ideal gas equation density. This density is then used in the equation of state to calculate the pressure P2; BRAKET calls function PDETAIL for this calculation. If P2>P then the solution for density is bracketed between RHOL = 0.0 (Tor which PRHOL = 0.0) and RHOH = RHO2 (for which PRHOH = P2); BRAKET then returns these results to DDETAIL through the subroutine BRAKET argument. When the trial for density in BRAKET, RHO2 yields a value of P2 which is less than P. an algorithm is initiated to bracket the solution for density. In this algorithm, the trial density 's increased iteratively until the calculated absolute pressure exceeds the specified absolute Pressure P. The density is then bracketed between the values of density from the final two iterations. In the first step, the density is increased by DEL. In subsequent steps, the density is increased by twice the previous value of DEL. The solution for density is bracketed in this manner and the resultant values of RHOL, RHOH, PRHOL and PRHOH are retumed to DETAIL through the subroutine BRAKET argument. If an iterative value of the calculated absolute pressure is fess than a previous value, this indicates that there is a maximum in pressure versus density at a pressure less than P. Then CODE is changed from 0.0 to 1.0 and the density trom the previous iteration is returned to DDETAIL as RHO in argument list cf subroutine BRAKET. Function subprogram DDETAIL then uses the value RHO for the Solution for density and returns this value to the calling location; Brent's method is not used in DDETAIL in this situation because it requires two densities which bracket the solution for density 4.3.8.8 Function Subprogram PDETAIL Function subprogram PDETAIL calculates the absolute pressure using the equation of State equation for pressure. The function subprogram ZDETAIL is called for the calculation of the compressibility factor. 46 ‘A.3.8.9 Function Subprogram ZDETAIL Function subprogram ZDETAIL calculates the compressibility factor using the DETAIL CHARACTERIZATION METHOD equation of state. A.3.9 Example Calculations Presented below is a computer listing for an example application. Output trom the example is listed in Table A.2-1. This example simulates a flow computer application in which there ate 20 discrete step temperature-pressure conditions and the gas composition changes during these 20 diserete steps. The last column of Table A3-1 gives the number of ‘computation blocks in Figure A.3-1 which are called for each calculation of Z, ‘PROGRAM EXAMPLE PURPOSE © “Enis exanple program shows how to use the DETAIL method as & © gtand-alone program © cowpiieD wire ¢ ““ETKELN2 FOR - Source code which contains routines for calculating ¢ properties with the DETAI! CHARACTERIZATION METHOD. onitseron - Source code which contains unit conversion routines )) NeGi, IH, CED(21), NCC, ICOM, ILEVEL, TTABLE DB, FPV, TK, PMP, DETAIL, “ZDETAIL, UNITS PbatA (20), xe(2i,2), HE(21), KH(21), XIC(21) © See up pressure & temperature arrays é PATA() - Arzay of temperatures in degrees F. . PDATA) ~ Arvay of pressures in peis © Set up composition tables é Rxii.d) Array of mole fraction compositions. € 1 Methane f Hydrogen 15 ~ n-Hexane c 2 > titregen 9 ~ Carbon Monoxide c 3 | Carbon Dioxide 10 — c ae ne c é Gb € 5 - Hydrogen Sulfide 1a - DATA (TDATA(Z) ,1=1,20) /65-D0,€5 D0, 65.0500, 65.0500, 63 -0500, a'65 0500, £5,0500, 65-0500, 65.050, 65.100, 65.1500, 68.2800, 65-1500, £ 65:18n0, €8.1500, 65, 1500, 65.1509,65.15D), 68 200, 6= 75007 DATA (PDATAIT) ,121,30)/780.00,750. $00, 751,D0, 751.00, 753.000 4953.000-791,D0, 754.500, 781.800, 752..D0, 752,500, 752.800, 752-500, $0, 783.800,754,D0,754.D0/ 3) 96522200, .002595D0, .00595eD0, .0181 86D & o0oseae DATA. (XK (2,2) ,5=1, 21) 90672400, .022284p0, .00467602, .04527900, & 9082800.0,0/0,0,0,0.00103700, 0,002562D0, .000321D0, .00044300. & 100039300,0,0.0,0.0,0 RA a7 = es FI OPEN (ONT TRIN were (1,12) 12 FORMAT (//, 33%, "TABLE A.3-2",/, 24x, ‘Detail Characterization Method’, /, 25x) ‘Output from EXAMPLE Progran’ ./ 22x, "Por Program Verification Purposes’, //) ‘wRave (2,12) a2 Porn (5%, "VALUE. 4x, 07 (PF) °,4x,'P (peda), 4x,D (bm £e"3)", ee Sie "10K, PPEU' SK, LEVEL! /14X, 72 (Se be} Tart BO loop eo set up Table with TABLE Values. © change to second Composition at 10th Table Value es € oe. 200 TK = UNETS(TDATA(IH), “T*, 1 bo Tis, TTABLE EP (1H.£0-10) 1comp © 2 nec = IEEVEL = 0 bo del, 21 TP (XK(T, 1COMP) .NE.0) THEN nce = Nee + 2 cxpqec) «5 XIQNCC) = XK(T, TCOMP) RECINCC) = K(E, COMP) ENDIF. ENDDO. IF (IH.EQ-1) GoTo 400 Check last values (NCCH, CIDH, XIH, etc.) with new values to see if they are different. For the first pass, call all subroutines. Tf the composition has changed, call CHARDL. if the terperature is different, recalculate the virial coefficients. If the pressure is different, recalculate the density. If nothing has changed, print the previous results. The LEVEL colum is interpreted az follows. tio change Pressure change ‘Temperature change Gas characterization change Set up GROSSKZ constants ° 1 2 3 4 EF (NCCH.NE.NCC) GOTO 400, Do T=1,Nec IF (CIDH ().NE.CID(I)) GoTo 400 ENDBO DO Tet Nee IF(XIH(Z) .NE.XI(T)) GoTo 300 ENDO IF (TOATA(TH) .NE.TDATA(TH-1)} GOTO 200 EP (PDATA(TH) .NE:PDATA(IH-1}) GOTO 100 Goro 10 Start the calculation process by calling the appropriate subroutine. 400 CALL pARAMDL (NCC, CID) IUEVEL = TLeveL + 3 300 GALL CHARDLINCC, XZ, 28, DB) ILEVEL = TLRVEL’ <2 CALL Temp (TK) ILEVEL = TLEVEL © 2 200 PMP = UNITS(POATA(TH), °P', ‘pete + oma, 4 LEVEL = ILEVEL + 1 D> DDETAIL(PHP, "TK} 2 = 2DBTAIL(D. GKI FRY = DsgRriza/2) Di UNITS(D, 'D" , ‘mo/an*3 *, "Abas" ") "Fh WRETE (1,100) 1H, TORTA(TI), PDATA(IH), D. 2, aooe FORMAT (3k,25/2°12.8,F13-5,Fi2.6,F13.5,2%,12) ce (eee Be ea Ev wold values for checking in next iteration Bo isi Nec crpw(z) = cxp(7) REK(I) = x1C() ENDO NccH = Nec ‘ENDO 999 END TABLE A,3-1 petail characterization Method ‘Guepat. from EXAMPLE Program For Progran Verification Purposes VALE TUF) tpsta) iD (bm feed) 2 3 65.000009 750.900000 «2.892940. 897619 1.054364 2 631000000 750.500000 2 0.897555 iloseso 3 €8!osvv00 781000000, 0.897528 Llosa: 2 4 5.080000 751. 000000, 0.897529 iiosaai 0 5 8.080000 751 c00000, 2lasezs 01897528 Lloseat 0 & 8.080000 751.0000, 2igge2e 0.897528 iioseai 0 7 81080000 752.0000 2iase2e 0897529 10sec: 0 & 8.050000 751.sco000 2.49812 0.897485 aiosaas 1 3 5.050000 751.s00000 «249812 0897465 ilosaas 0 29 €S1190009 752-0000 2163098 0.893031 Elos702 3 32 81150000 752.500000 2163258 0.853004 ilos7o3 2 32 6$.150000 752.5000 2163258 0.893004 ilos703 0 13 68!380000 752/s00000 2143256 01693004 11057030 24 5.150000 752.500000 2'€325¢ 0.893008 ilos703 0 25 651150000 752.500000 2163256 0.893004 ilos703 0 1g 81180000 733 000000 2ie3as1 01992937 103707 17 681150000 753.500000 2163648 0-892870 tlosma i ie 65.480000 753-500000 «2.63646 0.892870 ilos712 oo is 5.200009 754.000000 «263803 0.852843 ilos7is 2 20 681250000 754.000000 263768 0.892884 Llosmio 2 49 APPENDIX A.4 DETAIL CHARACTERIZATION METHOD FORTRAN CODE LISTING ‘Subprograms Function DDETAIL(P,T) Funetion PDETAIL(D,T) Function ZDETAIL(D,T) Subroutine B(T.BMIX) Subroutine BRAKET(CODE7,P,AHO,AHOL,AHON, PRHOL, RHO Subroutine CHARDL(NCC,X1,28,DB) . Subroutine PARAMDL((NEC.C1D) ‘Subroutine TEMP(T) BLOCK DATA 50 54 2 55, : 87 58 et 65 o7 6 COPYRIGHT (C) 1992, 1994 AMERICAN GAS ASSOCIATION ALL RIGHTS RESERVED COPYRIGHT APPLIES TO ALL SUBPROGRAMS FOR INFORMATION CONTACT: DR. JEFFREY L. SAVIOGE GAS RESEARCH INSTITUTE, ‘8600 W. BRYN MAWR AVE, CHICAGO, IL 60631 PHONE (312) 399-8100, FAX (312) 399-6170 OR: MS. LORI TRAWEEK [AMERICAN GAS ASSOCIATION 4515 WILSON BOULEVARD ARLINGTON, VA 22209 PHONE (703) 841-8400 c: c c c c c e c ic ¢ c c ¢ c c c c c c PROGRAM WRITTEN BY KENNETH STARLING ° VERSION 1.2 FUNCTION DDETAIL(P, T) PURPOSE! Calculates density for the AGAB model given pressure and temperature. This function uses Brent's method and PDETAIL to determine the density. DESCRIPTION OF ARGUMENTS: P- Pressure in MPa. (Input) T_- Temperature in kelvins. (Input) DDETAIL - Molar density at P and T in molidm*S. (Output) 90000000000 REAL'6 DHIGH, PLOW, PHIGH, TLOW, THIGH COMMON/LIMITS/ DHIGH, PLOW, PHIGH, TLOW, THIGH INTEGER IMAX, |, CODE REAL'S EPSP, EPSR, EPSMIN, T, P, RHO, RHOL, RHOH, PRHOL, PRHOH REALS ODETAIL, POETAIL, X1, X2, X3, Y1, ¥2, YS REAL"8 DELX, DELPRV, DELMIN, DELBIS, KNUMER, XDENOM, SGNDEL REAL's Y2MY3, YaMY1, YIMY2, BOUNDN IMAX = EPSP = 1.0-6 EPSR = 1.06 EPSMIN = 1.0-7 CODE =0 150 1.0. D: Copynant © 1998, 1994 Amencan Gas Azsosanon 51 C....GALL SUBROUTINE BRAKET TO BRACKET DENSITY SOLUTION ‘CALL BRAKET (CODE, T,P,RHO,RHOL, RHOH,PRHOL,PRHOH) ©... CHECK VALUE OF "CODE" RETURNED FROM SUBROUTINE BRAKET IF (CODE.EQ.1.0R.CODE.EQ.3) THEN DDETAIL = RHO RETURN ENDIF SET UP TO START BRENT'S METHOD X IS THE INDEPENDENT VARIABLE, Y THE DEPENDENT VARIABLE DELX IS THE CURRENT ITERATION CHANGE IN X DELPRV IS THE PREVIOUS ITERATION CHANGE IN X Xt = RHOL, X2 = RHOH Yt = PRHOL- P Y2 = PRHOH - P DELX = X1-x2 DELPRY = DELX e009 C.... NOTE THAT SOLUTION IS BRACKETED BETWEEN X1 AND X2 C...A THIRD POINT X3 IS INTRODUCED FOR QUADRATIC INTERPOLATION X3-= Xt Y= Yt C..uNOTE THAT ITERATIVE LOOP STARTS HERE, ENDS AT “10 CONTINUEt DO 10 I=1, MAX -¥3 MUST BE OPPOSITE IN SIGN FROM Y2, SO SOLUTION BETWEEN X2, x3. IF (Y2*Y3.GT.0.D0) THEN x3 = Xt CY MUST BE VALUE OF Y CLOSEST TO Y=0.0, THEN X2NEW=X20LD+DELX IF (DABS(Y3).LT.DABS(Y2)) THEN Xt = x2 C.DELMIN 1S MINIMUM ALLOWED STEP SIZE FOR UNCONVERGED ITERATION © SMALLER STEPS THAN DELMIN CAN CAUSE OSCILLATIONS Conynatt © 1992, 1904 Amencan Gas Associaton AVPighe Rosered 82. DELMIN = EPSMIN*DABS(X2) IF PROCEDURE IS NOT CONVERGING, LE., ABS(Y2)>ABS(Y1), OR IF DELPRV IS LESS THAN DELMIN, E., INTERPOLATION IS CONVERGING TOO SLOWLY, USE BISECTION DELBIS = 0.5D0"(X3 - X2) IS THE BISECTION DELX DELBIS = 9.5D0"(X3 - X2) e009 G....TESTS TO DECIDE NUMERICAL METHOD FOR CURRENT IT. -!ATION IF (DABS(DELPRV).LT.DELMIN .OR. DABS(¥'1).LT.DABS(¥2)) THEN C.nnsnUSE BISECTION DELX = DELBIS DELPRV = DELBIS ELSE IF (X3.NE.X1) THEN C.snsmnUSE INVERSE QUADRATIC INTERPOLATION yimy2 XDENOM = -(Y 1MY2)"(¥2MY3)*(Y3MY1) XNUMER = X1*Y2"Y3"(Y2MY3)+X2"Y3"Y1"(Y3MY1) & +X3°Y1°Y2"(Y IMY2)-X2"XDENOM ELSE ..USE INVERSE LINEAR INTERPOLATION XNUMER = (X2-X1)*Y2 XDENOM = Y1-Y2 ENDIF CunmnnFOLLOWING BRENT'S PROCEDURE, BEFORE CALCULATING DELX, ©” CHECK THAT DELX=XNUMER/XDENOM DOES NOT STEP OUT OF BOUNDS: IF (2,00"DABS(XNUMER).LT.DABS(DELPRV"XDENOM)) THEN CusnneenPROCEDURE CONVERGING, USE INTERPOLATION, DELPRV =DELX DELX = XNUMER/XDENOM ELSE © .snssnP ROCEDURE DIVERGING, USE BISECTION DELX = DELBIS DELPAV = DELBIS. ENDIF ENDIF Cn .CHECK FOR CONVERGENCE IF(OABS(¥2).LT.EPSP*P).AND.(DABS(DELX).LT.EPSR*DABS(X2))) THEN DDETAIL = X2sDELX CConyngtt © 1992, 1994 Arercan Gas Atsocitn 53 RETURN ENDIF WHEN UNCONVERGED, ABS(DELX) MUST BE GREATER THAN DELMIN MINIMUM ALLOWED MAGNITUDE OF CHANGE IN X2 IS 1.0000009*DELMIN SGNDEL, THE SIGN OF CHANGE IN X2 IS SIGN OF DELBIS IF (DABS(DELX).LT.DELMIN) THEN 'SGNDEL = DELBIS/OABS(DELBIS) DELX = 1.0000009°SGNDEL"DELMIN DELPRV = DELX ENDIF 909 C....FINAL CHECK TO INSURE THAT NEW X2 IS IN RANGE OF OLD x2 AND X3 C.BOUNDN IS NEGATIVE IF NEW X2 IS IN RANGE OF OLD x2 AND X3 BOUNDN = DELX"(X2+DELX-X3) IF(BOUNDN.GT.0.00) THEN C.uPROCEDURE STEPPING OUT OF BOUNDS, USE BISECTION DELX = DELBIS DELPRV = DELBIS. ENDIF C.....RELABEL VARIABLES FOR NEXT ITERATION. C XINEW=X20LD, YINEW=Y20LD Xt = X2 Vie ye G.....1NEXT ITERATION VALUES FOR X2, 2 X@ = X24DELX ‘Y2 = PDETAIL(X2, T) - P ©....RETURN TO START OF LOOP FOR NEXT ITERATION 10 CONTINUE WRITE (-/) (ODETAIL: MAXIMUM NUMBER OF ITERATIONS EXCEEDED’ DETAIL = x2 RETURN END Cepyrnt © 1992. 1004 amancan Gas Associaton As Reserved ° FUNCTION PDETAIL(D, T) PURPOSE: Calculates the pressure from the AGAB model as a function of density and temperature. DESCRIPTION OF ARGUMENTS: D - Molar density in mol/dm*3. (Input) T _- Temperature in kelvins. (Input) PDETAIL - Pressure in MPa. (Output) go0ee00000 INTEGER PROG REAL" RGAS, MXNUMER, MW(5) COMMON/CONSTANTS/ PROG, RGAS, MXNUMER, MW REAL'8 D, T, PDETAIL, ZDETAIL PDETAIL = ZDETAIL(D, T)"D"RGAS'T RETURN: END Copyrgnt © 1992. 1994 Anenean Gas Assocaton Ini Fignts Reserved OC EUNGTION ZDETAIL(D, 1) PURPOSE: This function calculates the compressibility factor from the AGAB model as a function of density and temperature. DESCRIPTION OF ARGUMENTS: 1D - Molar density in movdm’3. (Input) T___- Temperature in kelvins. (Input) ZDETAIL - Compressibiity factor. (Output) go0ac000e0 REAL" FN(S8) COMMON/AGAEOS/ FN REAL"8 UU,AK3PO,WW,Q2P0,HH.BMIX COMMON/AGAVARIABLES/ UU,RK3PO,WW,2P0, HH,BMIX REAL‘ TOLD COMMON/TOLDO/ TOLD REAL“8 D1, D2, D3, D4, DS, D6, 07, D8, D9, EXP1, EXP2, EXPS, EXP4 REAL'8 D, T, ZDETAIL IF (T.NE.TOLD) CALL TEMP(T) TOLD =T Di = RK3PO"D D2 = 0101 D3 = D201 D4 = D3"Dt DS = D401 Ds = D501 Ds01 7-01 De = Dept EXP1 = DEXP(-D1) EXP2 = DEXP(-D2) EXPS = DEXP(-D3) EXP4 = DEXP(-D4) ZDETAIL = 1.00 + BMIX'D & + EN(13)"D1"(EXPS - 1,09 - 3,0°D3"EXP3) & + (EN(14) + FN(1S) + FN(16))"D1(EXP2 - 1.00 - 2.00"D2"EXP2) & + 1FN(17) + FN(18))"D1 (EXP - 1.00 - 4.00"D4*ExP4) & + (FN(19) + FN(20))*D2"2.00 & + (EN(21) + FN(22) + FN(23))"D2"(2.D0 - 2.0"D2)"=ExP2 & + (FN(24) + FIN(25) + FN(26))"D2"(2.D0 - 4.D0"D4)"EXP4 xnyor 192.1984 Amncan Gat Associaton 56 & a & a a a a a a & & a & a & ‘ a & & + FN(27)"D2"(2.00 - 4.00°D4)"EXP4 + FN(28)"D3°3.00 + (FN(28) + FN(30))*D3"(3.D0 - D1)"EXPt + (FN(@1) + FN(32))"D3"(3.00 - 2,D0°D2)"EXP2 + (FN(G3) + FN(G4))"D3"(3.D0 - 3.D0°D3)"EXPS. 2 (FNS) + FN(36) + FN(S7))"D3"(3.D9 - 4.00"D4)"EXPA + (FN(B) + FN(39))"D4"4.D0 + (EN(40) + FN(41) + FN(42))"D4"(4.00 - 2.00°D2)"EXP2 + (FN(43) + FN(44))"D4"(4.D0 - 4.D0*D4)"EXPA 4+ FN(45)"D5"5.D0 + (FN(46) + FN(47))"D5"(5.00 - 2.00°D2)" EXP + (FN(48) + FN(49))"D5"(5.00 - 4.0°D4)"EXPS + FN(50)"D6"6.00 FN(51)*D6"(6.D0 - 2.00°D2)"EXP2 FIN(62)"07"7.D0 FIN(63)*D7"(7.D0 - 2.D0°D2)"EXP2 = FN(54)"D8"(8.D0 - D1)"EXPt + (FN(S5) + FN(S6))*DB"(8.00 - 2.00°D2)"EXP2 2 (FIN(57) + FN(G8))"D9"(9.00 - 2.00°D2)"EXP2 END, CCopyioht © 1982, 1994 amencan Gas Associaton ‘nivigits Reserved SUBROUTINE B(T,BMIX) PURPOSE: ‘Calculates the second virial coefficient using the AGAB. method given temperature. DESCRIPTION OF ARGUMENTS: T __~ Temperature in kelvins. (Input) MIX. - Second virial coefficient in moVidm's. (Output) go0000000 9 REALS B1,82,83,B4,85,B6,87,B8,89,810,811,B12,513, 8 B14,B15,816,817,818 COMMON/VIF’ B1,B2,83,B4,85,86,07,88,89,810,811,812,813, 8 B14,B15,816,817,818 REAL‘8 TOPS, T2PO, T3PO, T3P5, TAPS, TEPO, T11P0, BMIX, T FEAL"8 T7PS,T9P5,112P0,T12P5, ToPS = DSQAT(T) T2Po = TT T3P0 = T'T2P0 TaP5 = T3PO'TOPS T4aPS = T'TSPS TePO = T3PO"TSPO TH1P9 = T4Ps*T4P5*T2PO TIPS = T6PO‘T*TOPS T9P5 = T7P5*T2PO T12Po = TaPS*TOPS*T2PO T12P5 = T12PO"TOPS BMIX = B1+ B2/TOPS + BAT + B4/TSP5 + BS*TOPS + BE/TAPS & + B7/TOP5+ BB/T7PS + B9/TSPS + BIOITEPO + B11/T12PO & + B12/T12P5 + B13°T6PO + B14/T2PO + B1S/TSPO + B1G/T2PO & + BI7/T2PO + B18/T11PO RETURN END emyran © 102,104 xnatcan Gas Assoceton 9a00 c. Cu. SOBROUTINE BRAKET (CODE. T, P, RHO, RHOL, HOH, PRHOL, PRHOH) PURPOSE! Brackets the density solution. INTEGER PROG REAL‘ RGAS, MXNUMER, MWW(5) COMMON/CONSTANTS/ PROG, RGAS, MXNUMER, MW REAL*8 UU,RK3PO,WW,G2P0,HH.BMIX COMMON/AGAVARIABLES/ UU,RK3PO,WW,Q2PO,HH.BMIX INTEGER IMAX, IT, CODE REAL"8 DEL, RHOMAX, T, P, RHO, PDETAIL, VIDEAL REAL'S RHOL, PRHOL, RHOH, PRHOH, RHO1, RHO2, Pt, P2 ‘CODE =0 IMAX = 200 RHOMAX = 1.DO/RK3PO. IF (T.GT.1.2593D0°UU) RHOMAX = 20.D0°RHOMAX VIDEAL = RGAS*T/P IF(OABS(BMIX).LT.(0.167D0°VIDEAL)) THEN RHO? = 0,95D0(VIDEAL+BMIX) ELSE RHO2 = 1.1SDO/VIDEAL ENDIF NOTE: PRESSURE (P2) AT DENSITY RHO2 NOT YET CALCULATED DEL = RHO2/20.00 T=0 START ITERATIVE DENSITY SEARCH LOOP 101T ret IF ((T.GT.MAX) THEN MAXIMUM NUMBER OF ITERATIONS EXCEEDED ‘CODE = 3 Copyignt © 1982, 1994 Amencan Gas Assocation hts Reserve: 59 IF (CODE.NE.2 AND. RHO2.GT.RHOMAX) THEN Conn.DENSITY IN BRAKET EXCEEDS MAXIMUM ALLOWABLE DENSITY ‘CODE =2 WRITE (", 1020) DEL = 0.01D0"(RHOMAX - RHO1) + P(RGAS*T)/20,D0 RHO2 = AHOT + DEL GOTO 10 ENDIF ©... CALCULATE PRESSURE P2 AT DENSITY RHO? P2 = PDETAIL(RHO2, T) C....TEST VALUE OF P2 RELATIVE TO P AND RELATIVE TO P1 IF (P2.GT.P) THEN C...4.THE DENSITY ROOT IS BRACKETED (P1

P) RHOL = RHOt PRHOL = P1 RHOH = RHO2 PRHOH = P2 RETURN ELSEIF (P2.GT-P1 AND, CODE.EQ.2) THEN C.....AETAIN CONSTANT VALUE FOR DEL (CODE RHOT = RHOZ Pi=P2 RHO2 = RHOt + DEL GOTO 10 ELSEIF (P2.GT.P1. AND. CODE.EQ.0) THEN RHO = RHOZ Pi =P2 RHO2 = RHOT + DEL GOTO 10 ENDIF ABOVE IF/ELSEIF CONDITIONS UNSATISFIED IMPLIES P2

You might also like