Header file: "aga8part1.h"
The following is a header file:
#include "stdio.h"
#include "math.h"
/* declaration of the 'aga8' struct */
struct aga8p1
{
/* INPUT PARAMETERS */
double xi[21];//Molar fractions xi[0 to 20]
// MOLE FRACTIONS OF:
// x[0] Methane
// x[1] Nitrogen
// x[2] Carbon Dioxide
// x[3] Ethane
// x[4] Propane
// x[5] i-Butane
// x[6] n-Butane
// x[7] i-Pentane
// x[8] n-Pentane
// x[9] n-Hexane
// x[10] n-Heptane
// x[11] n-Octane
// x[12] n-Nonane
// x[13] n-Decane
// x[14] Hydrogen
// x[15] Oxygen
// x[16] Carbon monoxide
// x[17] Water
// x[18] Hydrogen sulfide
// x[19] Helium
// x[20] Argon
double P; //Absolute pressure [MPa]
double T; //Temperature [K]
/* OUTPUT PARAMETERS */
double res[24]; // Space to store all output parameters (results)
// res[0] - molar mass
// res[1] - molar density [kg-mole/m3]
// res[2] - density [kg/m3]
// res[3] - compressibility factor
// res[4] - relative density
// res[5] - reduced density of a gas mixture
// res[6] - gross heating value on a volumetric basis 25/0/1.01325 [MJ/m^3]
// res[7] - molar Helmholtz energy
// res[8] - molar ideal gas Helmholtz energy
// res[9] - molar residual Helmholtz energy
// res[10] - molar entropy
// res[11] - molar energy
// res[12] - molar enthalpy
// res[13] - molar Gibbs energy
// res[14] - molar isochoric heat capacity
// res[15] - molar isobaric heat capacity
// res[16] - speed of sound
// res[17] - Joule-Thomson coefficient
// res[18] - isentropic exponent
// res[19] - specific entropy
// res[20] - specific energy
// res[21] - specific enthalpy
// res[22] - specific isochoric heat capacity
// res[23] - specific isobaric heat capacity
long int es; //Error status
/* INTERMEDIATE RESULTS */
short i, j, n;
double xxi[21];// Space to backup mole fractions for test of the changings
//in the succeeding cycle
short offlineDone; //offlineDone=1 indicates that OFF-LINE calculations have
//already been performed
double Gij, Eij, Bnijx, B, Bx[18], U5, U, G, Q, F, K5, rhor, K3, dr, Z, M;
//Bx stands for B*
double Cx[58], zet[58]; // zet[n] stands for (Cn*)*pow(T,-un[n]), Eq. 4-36;
//used also in Eqs. 4.1 and 4.3.
double d1, d2, dk, d0, p1, p2, temp, z0, rden, ghv;
double ksi04[21], ksi05[21], ksi06[21], ksi07[21], psi[58], omega[58];
double a, ao, ar, Bt, Btt, aot, aott, art, artt, ard, ardd, ardt, dpd, dpT;
double s, ss, u, us, h, hs, g, cv, cvs, cp, cps, w, JTc, kapa;
double Par[28];
double xiCO2max;
long int errABC, errA, errB, errC;
};
/* declaration of the function 'aga8part1' */
void aga8part1(struct aga8p1 *aga0);
Example of a main program in C code calling the function "aga8part1()"
The following example illustrates the call to aga8x92dc() function from a main program. The program prompts for input parameters and then transfers the parameters to the struct. After the execution the program prints both the input parameters and the results on the screen.
/* **************************************** */
/* THE BEGINNING OF THE MAIN PROGRAM C-CODE */
/* **************************************** */
#include "stdio.h"
#include "conio.h"
#include "aga8part1.h"
void main(void)
{
struct aga8p1 aga, *agap; /* 'agap' is a pointer to the structure 'aga' */
unsigned short int i, j, igas;
char ch;
// AGA8/2017-Part1, Table B.1 (Titles of Natural Gases)
char *gastitle[6] = {
"'User defined gas composition'",
"'Gulf coast'",
"'Amarillo'",
"'Ekofisk'",
"'High N2'",
"'High CO2-N2'"
};
// AGA8/2017-Part1, Table B.1 (Compositions of Natural Gas in Mole Fractions)
double yy[5][21] = {
//Gulf coast
0.965222, 0.002595, 0.005956, 0.018186, 0.004596, 0.000977, 0.001007,
0.000473, 0.000324, 0.000664, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
//Amarillo
0.906724, 0.031284, 0.004676, 0.045279, 0.00828, 0.001037, 0.001563,
0.000321, 0.000443, 0.000393, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
//Ekofisk
0.859063, 0.010068, 0.014954, 0.084919, 0.023015, 0.003486, 0.003506,
0.000509, 0.00048, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
//High N2
0.81441, 0.13465, 0.00985, 0.033, 0.00605, 0.001, 0.00104,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
//High CO2-N2
0.81212, 0.05702, 0.07585, 0.04303, 0.00895, 0.00151, 0.00152,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
};
char *text[23] = {
"Methane.........", "Nitrogen........", "Carbon Dioxide..",
"Ethane..........", "Propane.........", "i-Butane........",
"n-Butane........", "i-Pentane.......", "n-Pentane.......",
"n-Hexane........", "n-Heptane.......", "n-Octane........",
"n-Nonane........", "n-Decane........", "Hydrogen........",
"Oxygen..........", "Carbon Monoxide.", "Water...........",
"Hydrogen Sulfide", "Helium..........", "Argon...........",
"Pressure [MPa]..", "Temperature [K]."
};
char *textres[24] = {
"Molar mass [g/mol]..........................",
"Molar density [mol/dm^3]....................",
"Density [kg/m^3]............................",
"Compressibility factor......................",
"Relative density............................",
"Reduced density.............................",
"Volumetric Gross heating value [MJ/m^3].....",
"Molar Helmholtz energy [J/mol]..............",
"Molar ideal gas Helmholtz energy [J/mol]....",
"Molar residual Helmholtz energy [J/mol].....",
"Molar entropy [J/(mol*K)]...................",
"Molar energy [J/mol]........................",
"Molar enthalpy [J/mol]......................",
"Molar Gibbs energy [J/mol]..................",
"Molar isochoric heat capacity [J/(mol*K)]...",
"Molar isobaric heat capacity [J/(mol*K)]....",
"Speed of sound [m/s]........................",
"Joule-Thomson coefficient [K/MPa]...........",
"Isentropic exponent.........................",
"Specific entropy [kJ/(kg*K)]................",
"Specific energy [kJ/kg].....................",
"Specific enthalpy [kJ/kg]...................",
"Specific isochoric heat capacity [kJ/(kg*K)]",
"Specific isobaric heat capacity [kJ/(kg*K)]"
};
for (j=0; ; ) {
printf("\nINPUT PARAMETERS\n");
printf("%s", "\nSelect the complete input parameter setup '0',");
printf("%s", "\nor select the one of five AGA8/2017-Part1, Table B.1,");
printf("%s", "\ncompositions of natural gas in mole fractions\n");
for (i=0; i<=5; i++) {
printf("%d%s%s%s", i, "-", gastitle[i], "\n");
}
printf("%s", "by typing the number between 0 and 5: ");
scanf("%d", &igas);
if (igas > 0 && igas <= 5) {
/* Copy molar fractions */
for (i=0; i<=20; i++) {
aga.xi[i] = yy[igas-1][i];
}
}
else {
/* Input molar fractions */
printf("Mole fraction of:\n");
for (i=0; i<=20; i++) {
printf("%s = ", text[i]);
scanf("%lf", &(aga.xi[i]));
}
}
printf("%s = ", text[21]);
scanf("%lf", &(aga.P)); /* Enter pressure */
printf("%s = ", text[22]);
scanf("%lf", &(aga.T)); /* Enter temperature */
agap = &aga; /* Put the address of 'aga' structure into 'agap' */
aga8part1(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%s", "Selected gas = ", gastitle[igas]); /* Print gas selection */
printf("\nMole fractions:"); /* Print mole fractions */
for (i=0; i<21; ++i) { /* Fractions of components 1-21 */
printf("\n%s = %f", text[i], aga.xi[i]);
}
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 */
for (i=0; i<24; ++i) { /* Print results of calculations */
printf("\n%s = %f",textres[i], aga.res[i]); /* print i-th result */
}
printf("\nPress X to exit or anything else to continue: ");
ch = getch();
if (( ch == 'X') || (ch == 'x')) {
break;
}
printf("\n");
}
}
/* ********************************** */
/* THE END OF THE MAIN PROGRAM C-CODE */
/* ********************************** */
Calculation example
The following example shows the input parameters and the results printed on the screen after successful completion of the calculations of volumetric and thermodynamic properties of natural gas "Ekofiks" (see Table B.1 of
AGA Report No. 8, Part 1) obtained at absolute pressure 6 MPa and temperature 333.15 K (60 °C).
INPUT PARAMETERS
Select the complete input parameter setup '0',
or select the one of five AGA8/2017-Part1, Table B.1,
compositions of natural gas in mole fractions
0-'User defined gas composition'
1-'Gulf coast'
2-'Amarillo'
3-'Ekofisk'
4-'High N2'
5-'High CO2-N2'
by typing the number between 0 and 5: 3
Pressure [MPa].. = 6
Temperature [K]. = 333.15
I N P U T P A R A M E T E R S:
Selected gas = 'Ekofisk'
Mole fractions:
Methane......... = 0.859063
Nitrogen........ = 0.010068
Carbon Dioxide.. = 0.014954
Ethane.......... = 0.084919
Propane......... = 0.023015
i-Butane........ = 0.003486
n-Butane........ = 0.003506
i-Pentane....... = 0.000509
n-Pentane....... = 0.000480
n-Hexane........ = 0.000000
n-Heptane....... = 0.000000
n-Octane........ = 0.000000
n-Nonane........ = 0.000000
n-Decane........ = 0.000000
Hydrogen........ = 0.000000
Oxygen.......... = 0.000000
Carbon Monoxide. = 0.000000
Water........... = 0.000000
Hydrogen Sulfide = 0.000000
Helium.......... = 0.000000
Argon........... = 0.000000
Pressure [MPa].. = 6.000000
Temperature [K]. = 333.150000
R E S U L T S:
Error(Hex) = 0
Molar mass [g/mol].......................... = 18.768272
Molar density [mol/dm^3].................... = 2.374298
Density [kg/m^3]............................ = 44.561464
Compressibility factor...................... = 0.912304
Relative density............................ = 0.649919
Reduced density............................. = 0.251504
Volumetric Gross heating value [MJ/m^3]..... = 44.385832
Molar Helmholtz energy [J/mol].............. = 6831.954083
Molar ideal gas Helmholtz energy [J/mol].... = 7097.020201
Molar residual Helmholtz energy [J/mol]..... = -265.066118
Molar entropy [J/(mol*K)]................... = -27.009531
Molar energy [J/mol]........................ = -2166.271106
Molar enthalpy [J/mol]...................... = 360.792058
Molar Gibbs energy [J/mol].................. = 9359.017247
Molar isochoric heat capacity [J/(mol*K)]... = 33.126345
Molar isobaric heat capacity [J/(mol*K)].... = 46.961635
Speed of sound [m/s]........................ = 419.406183
Joule-Thomson coefficient [K/MPa]........... = 3.648969
Isentropic exponent......................... = 1.306405
Specific entropy [kJ/(kg*K)]................ = -1.439106
Specific energy [kJ/kg]..................... = -115.421978
Specific enthalpy [kJ/kg]................... = 19.223509
Specific isochoric heat capacity [kJ/(kg*K)] = 1.765018
Specific isobaric heat capacity [kJ/(kg*K)] = 2.502182
Press X to exit or anything else to continue: