FE-AGA8-92DC-C (Revised: February 26, 2010) is the C source code implementation of:
Function | |||
---|---|---|---|
void aga8x92dc(struct aga8 *); |
Input parameters | |||
---|---|---|---|
Data type | Parameter name | Parameter description | Unit of measure |
double | aga8.x[0] | molar fraction of Methane | mol |
double | aga8.x[1] | molar fraction of Nitrogen | mol |
double | aga8.x[2] | molar fraction of Carbon dioxide | mol |
double | aga8.x[3] | molar fraction of Ethane | mol |
double | aga8.x[4] | molar fraction of Propane | mol |
double | aga8.x[5] | molar fraction of Water | mol |
double | aga8.x[6] | molar fraction of Hydrogen sulfide | mol |
double | aga8.x[7] | molar fraction of Hydrogen | mol |
double | aga8.x[8] | molar fraction of Carbon monoxide | mol |
double | aga8.x[9] | molar fraction of Oxygen | mol |
double | aga8.x[10] | molar fraction of iso-Butane | mol |
double | aga8.x[11] | molar fraction of n-Butane | mol |
double | aga8.x[12] | molar fraction of i-Pentane | mol |
double | aga8.x[13] | molar fraction of n-Pentane | mol |
double | aga8.x[14] | molar fraction of n-Hexane | mol |
double | aga8.x[15] | molar fraction of n-Heptane | mol |
double | aga8.x[16] | molar fraction of n-Octane | mol |
double | aga8.x[17] | molar fraction of n-Nonane | mol |
double | aga8.x[18] | molar fraction of n-Decane | mol |
double | aga8.x[19] | molar fraction of Helium | mol |
double | aga8.x[20] | molar fraction of Argon | mol |
double | aga8.p | Pressure (absolute) | MPa |
double | aga8.t | Temperature | K |
Output parameters | |||
double | aga8.mm | gas mixture molar mass | kg/kmol |
double | aga8.md | gas mixture molar density | kg⋅mol/m3 |
double | aga8.density | gas mixture density | kg/m3 |
double | aga8.zf | gas mixture compression factor | dimensionless |
double | aga8.rd | gas mixture relative density | dimensionless |
double | aga8.scv | gas mixture superior calorific value | MJ/m3 |
long | aga8.es | error status | dimensionless |
Ranges of application implemented in FE-AGA8-92DC-C | |
---|---|
Parameter | Range |
Mole fraction of Methane | 0 to 1.00 |
Mole fraction of Nitrogen | 0 to 1.00 |
Mole fraction of Carbon dioxide | 0 to 1.00 |
Mole fraction of Ethane | 0 to 1.00 |
Mole fraction of Propane | 0 to 0.12 |
Mole fraction of Water | 0 to 0.10 |
Mole fraction of Hydrogen sulfide | 0 to 1.00 |
Mole fraction of Hydrogen | 0 to 1.00 |
Mole fraction of Carbon monoxide | 0 to 0.03 |
Mole fraction of Oxigen | 0 to 0.21 |
Mole fraction of butanes (n-Butane + i-Butane) | 0 to 0.06 |
Mole fraction of pentanes (n-pentane + i-Pentane) | 0 to 0.04 |
Mole fraction of hexanes plus (n-Hexane + n-Heptane + n-Octane + n-Nonane + n-Octane) | 0 to 0.10 |
Mole fraction of Helium | 0 to 0.03 |
Mole fraction of Argon | 0 to 0.01 |
Pressure (absolute) | 10-8 to 278.5 MPa |
Temperature | 144 to 678 K |
Relative density | 0.07 to 1.52 |
Superior calorific value | 0 to 67.066 MJ/m3 |
Errors and warnings | |
---|---|
"long aga8.es" represents errors and warnings generated during program execution as follows: | |
Bit 0 =1 (0000001H) | Error: There exist at least one molar fraction < 0 or > 1 |
Bit 1 =1 (0000002H) | Error: The total sum of molar fractions <0.98 or >1.02 |
Bit 2 =1 (0000004H) | Warning: Total sum of molar fractions is <0.999999 or >1.000001. If set this bit only warns that the fractions have been normalized to give the total sum of molar fractions exactly equal to 1. If only bit 2 was set during the calculation the results are valid. |
Bit 3 =1 (0000008H) | Error: Mole fraction of Methane out of range. |
Bit 4 =1 (0000010H) | Error: Mole fraction of Nitrogen out of range. |
Bit 5 =1 (0000020H) | Error: Mole fraction of Carbon Dioxide out of range. |
Bit 6 =1 (0000040H) | Error: Mole fraction of Ethane out of range. |
Bit 7 =1 (0000080H) | Error: Mole fraction of Propane out of range. |
Bit 8 =1 (0000100H) | Error: Mole fraction of Water out of range. |
Bit 9 =1 (0000200H) | Error: Mole fraction of Hydrogen sulfide out of range. |
Bit 10 =1 (0000400H) | Error: Mole fraction of Hydrogen out of range. |
Bit 11 =1 (0000800H) | Error: Mole fraction of Carbon monoxide out of range. |
Bit 12 =1 (0001000H) | Error: Mole fraction of Oxygen out of range. |
Bit 13 =1 (0002000H) | Error: Mole fraction of Butanes) out of range. |
Bit 14 =1 (0004000H) | Error: Mole fraction of Pentanes out of range. |
Bit 15 =1 (0008000H) | Error: Mole fraction of Hexanes plus out of range. |
Bit 16 =1 (0010000H) | Error: Mole fraction of Helium out of range. |
Bit 17 =1 (0020000H) | Error: Mole fraction of Argon out of range. |
Bit 18 =1 (0040000H) | Error: Pressure (absolute) out of range. |
Bit 19 =1 (0080000H) | Error: Temperature out of range. |
Bit 20 =1 (0100000H) | Error: Relative density out of range. |
Bit 21 =1 (0200000H) | Error: Superior calorific value out of range. |
Bit 22 =1 (0400000H) | Unused |
Bit 23 =1 (0800000H) | Unused |
Bit 24 =1 (1000000H) | Error: OFF-LINE calculation failed. |
Bit 25,... All higher order bits are unused | |
The results are valid if bits 0,...,24 are all cleared, or if only bit 2 was set during the calculation, otherwise the results are invalid, i.e. cleared. |
#include "stdio.h" #include "math.h" // declaration of the 'aga8' struct struct aga8 { // INPUT PARAMETERS double t; // Temperature [K] double p; // Pressure in [MPa] double x[21]; // Natural gas molar fractions // MOLE FRACTIONS OF: // x[0] Methane, x[1] Nitrogen, x[2] Carbon Dioxide, x[3] Ethane // x[4] Propane, x[5] Water, x[6] Hydrogen sulfide, x[7] Hydrogen, // x[8] Carbon Monoxide, x[9] Oxygen, x[10] i-Butane, x[11] n-Butane // x[12] i-Pentane, x[13] n-Pentane, x[14] n-Hexane, x[15] n-Heptane // x[16] n-Octane, x[17] n-Nonane, x[18] n-Decane, x[19] Helium, x[20] Argon // OUTPUT PARAMETERS unsigned long int es; // Error status double scv; // Superior calorific value on a volumetric basis [MJ/m^3] // at combustion temperature 298.15 K, // metering temperature 273.15K, and // combustion and metering pressure 0.101325 MPa double rd; // Relative density at 273.15 K and 0.101325 MPa double zf; // Compression (compressibility factor) double d; // Density [kg/m3] double md; // Molar density [kg-mole/m3] double mm; // Molar mass // Temporary parameters double Gij, Eij, Bnijx, B, U5, U, G, Q, F, K5, dr, Z, Cnx[58]; double d1, d2, dk, R, p1, p2, temp, z0, rden, sc; int i, j, n; // Intermediate results in OFF-LINE calculations double K3, M; unsigned long int es_off; double BB[18]; double Cnx0[58]; // Temporary registers double tmp[10]; double RT, SumCnx; // Natural gas composition from previous cycle: to be compared with actual // composition to see whether the OFF-LINE calculation is necessary or not double xx[21]; }; // declaration of the function 'aga8x92dc' void aga8x92dc(struct aga8 *);
/* ******************* */ /* MAIN PROGRAM C-CODE */ /* ******************* */ #include "stdio.h" #include "conio.h" #include "aga8x92dc.h" void main(void) { struct aga8 aga, *agap; /* 'agap' is a pointer to a structure 'aga' */ unsigned short int i, j, igas; char ch; /* ISO-12213-2 examples */ /* Array of gas mixture molar fractions */ // double twodim[2][3] = { 11, 12, 13, 21, 22, 23 }; double yy[6][21] = { 0.965, 0.003, 0.006, 0.018, 0.0045, 0.0, 0.0, 0.0, 0.0, 0.0, 0.001, 0.001, 0.0005, 0.0003, 0.0007, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.907, 0.031, 0.005, 0.045, 0.0084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.001, 0.0015, 0.0003, 0.0004, 0.0004, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.859, 0.01, 0.015, 0.085, 0.023, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0035, 0.0035, 0.0005, 0.0005, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.735, 0.1, 0.016, 0.033, 0.0074, 0.0, 0.0, 0.095, 0.01, 0.0, 0.0012, 0.0012, 0.0004, 0.0004, 0.0002, 0.0001, 0.0001, 0.0, 0.0, 0.0, 0.0, 0.812, 0.057, 0.076, 0.043, 0.009, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0015, 0.0015, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.826, 0.117, 0.011, 0.035, 0.0075, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0012, 0.0012, 0.0004, 0.0004, 0.0002, 0.0001, 0.0, 0.0, 0.0, 0.0, 0.0 }; char *text[29] = { "Methane ", "Nitrogen ", "Carbon Dioxide ", "Ethane ", "Propane ", "Water ", "Hydrogen Sulfide", "Hydrogen ", "Carbon Monoxide ", "Oxygen ", "iso-Butane ", "n-Butane ", "i-Pentane ", "n-Pentane ", "n-Hexane ", "n-Heptane ", "n-Octane ", "n-Nonane ", "n-Decane ", "Helium ", "Argon ", "Pressure [MPa] ", "Temperature [K] ", "Molar mass ", "Molar density [kg-mole/m3]", "Density [kg/m3] ", "Compression ", "Relative density ", "Superior calorific value " }; for (j=0; ; ) { printf("\nINPUT PARAMETERS\n"); /* Input molar fractions */ printf("Mole fraction of:\n"); for (i=0; i<=20; i++) { printf("%s = ", text[i]); scanf("%lf", &(aga.x[i])); } printf("%s = ", text[21]); /* Enter pressure */ scanf("%lf", &(aga.p)); printf("%s = ", text[22]); /* Enter temperature */ scanf("%lf", &(aga.t)); agap = &aga; /* Put the address of 'aga' structure into 'agap' */ aga8x92dc(agap); /* Call function by passing the pointer to structure */ /* Print input parameters and results */ printf("\nI N P U T P A R A M E T E R S:"); printf("\n%s%d", "Selected gas = Gas", igas+1); /* Print gas selection */ printf("\nMole fractions:"); /* Print mole fractions */ for (i=0; i<10; ++i) { /* Fractions of components 1-20 */ printf("\n%s = %f, %s = %f",text[2*i], aga.x[2*i], text[2*i+1], aga.x[2*i+1]); } printf("\n%s = %f",text[20], aga.x[20]); /* Fraction of component 21 */ printf("\n%s = %f", text[21], aga.p); /* Print pressure */ printf("\n%s = %f", text[22], aga.t); /* Print temperature */ printf("\n\nR E S U L T S"); printf("\nError(Hex) = %x", aga.es); /* errr status */ /* Print results */ printf("\n%s = %f",text[23], aga.mm); /* print molar mass */ printf("\n%s = %f",text[24], aga.md); /* print molar density */ printf("\n%s = %f",text[25], aga.d); /* print density */ printf("\n%s = %f",text[26], aga.zf); /* compression */ printf("\n%s = %f",text[27], aga.rd); /* relative density */ printf("\n%s = %f",text[28], aga.scv); /* superior calorific value */ printf("\nPress X to exit or anything else to continue: "); ch = getch(); if (( ch == 'X') || (ch == 'x')) break; } } /* ****************************** */ /* END OF THE MAIN PROGRAM C-CODE */ /* ****************************** */