aga3 - Instructions for use
Revision:
E-mail: info@felib.com
aga3
is the C source code implementation of the natural gas flow-rate
calculation in accordance with AGA
Report No. 3.
References:
1. AGA Report No. 3, “ORIFICE METERING OF NATURAL GAS AND OTHER RELATED HYDROCARBON FLUIDS
PART1: General Equations and
Uncertainty Guidelines, (Third Edition, October 1990, 2nd printing,
June 2003), American Gas Association and American Petroleum Institute, 1990,
2003.
PART4: Background, Development,
Implementation Procedure, and Subroutine Documentation for Empirical
Flange-Tapped Discharge Coefficient Equation, (Third Edition, October 1992, 2nd
Printing, August 1995, 3rd Printing, June 2003), American Gas Association
and American Petroleum Institute, 1992, 1995, 2003.
The software is written in a C-language. The routine is, by default, customized for embedded systems and floating point numbers are declared in a single precision. The example calculations given in Section 6 are obtained using single precision floating point arithmetic. To switch to double precision it is necessary to rename all floats to doubles in the source code and to recompile the program.
1. Function prototype
The following is the definition of the function prototype:
void
aga3(
/* output parameters */
unsigned long int
*errflag, /*
Error status */
float *mfr, /* Mass flow rate [kg/s] */
float *vfr, /*
Volume flow rate at flowing conditions [m3/s] */
float *vfrb, /* Volume
flow rate at base conditions [m3/s] */
float *cd, /*
Coefficient of discharge [] */
float *y, /* Expansion factor
*/
float *ev, /*
Velocity of approach factor */
float *ReD, /*
Pipe Reynolds number [] */
float *od, /*
Orifice diameter [m] */
float *pd, /* Meter tube diameter
[m] */
float *br, /*
Orifice to pipe diameter ratio at flowing temperature [] */
/* input parameters */
short ud, /*
Position of pressure measurement tap: 0-upstream, 1-downstream */
float px, /*
Flowing pressure [Pa] measured either upstream or downstream */
float pl, /* Local barometric
pressure [Pa] if gauge pressure measurement else pl=0 */
float dp, /*
Differential pressure [Pa] */
float tf, /*
Flowing temperature [K] */
float tp, /*
Temperature [K] at which meter tube internal diameter was measured */
float pdtp, /*
Meter tube internal diameter [m] measured at temperature tp
*/
float ap, /*
Linear coefficient of thermal expansion [m/m-K] of the meter tube material */
float to, /* Temperature [K]
at which orifice diameter was measured */
float odto, /*
Orifice bore diameter [m] measured at temperature to */
float ao, /*
Linear coefficient of thermal expansion of the orifice plate material [m/m-K]
*/
float d, /*
Fluid density [kg/m3] */
float db, /* Fluid base
density [kg/m3] */
float v, /*
Fluid dynamic viscosity [Pa*s] */
float k /*
Isentropic exponent [], k=-1 for liquids) */
)
2. Parameter ranges
The following Table shows the range limits for ‘aga3’ input parameters.
Table 2.1 Ranges of application for ‘aga3’ flow rate calculation
|
Ranges of application for 'aga3' flow rate calculation using AGA
Report No. 3/2003 |
|
|
Parameter |
Valid range |
|
Absolute pressure: Pf |
0.0 Pa to 109 Pa |
|
Temperature: Tf |
0 to 104 K |
|
Differential pressure: dP |
0 to 0.3* Pf_upstream Pa |
|
Local barometric pressure: Plb |
0 to 0.2 MPa |
|
Meter tube internal diameter
measured at temperature Tp: Pd |
40 to 1000 mm |
|
Temperature at which meter tube
internal diameter is measured: Tp |
223.15 to 373.15 K |
|
Linear coefficient of thermal
expansion of the meter tube material: ap |
0 to 0.01 m/m-K |
|
Orifice bore diameter measured at
temperature Td: Od |
0.05*Pd£Od£0.75Pd; Od³4mm |
|
Temperature at which orifice plate bore
diameter was measured: To |
223.15 to 373.15 K |
|
Linear coefficient of thermal
expansion of the orifice plate material: ao |
0 to 0.01 m/m-K |
|
Orifice bore diameter to meter tube
internal diameter ratio – beta ratio: br |
0.05£br£0.75 |
|
Fluid density : d |
0.000001£d£10000 kg/m3 |
|
Fluid dynamic viscosity: v |
0.0£v£10.0 Pa*s |
|
Isentropic exponent: k |
0.1£k£2000; k=-1 for liquids |
3. Error
status
After completion of the routine the error_flag (unsigned long integer) will be cleared if there were no errors during the calculation, or the corresponding bits will be set if certain errors were encountered. The description of the error_flag bits is given in Table 3.1.
Table 3.1
|
Bit number |
Hexadecimal address |
Description |
|
Bit 0 |
=1 (000001H) |
If pressure <0.0 Pa or >1000 MPa, else =0. |
|
Bit 1 |
=1 (000002H) |
If temperature <0 K or >10000 K, else =0. |
|
Bit 2 |
=1 (000004H) |
If differential pressure <0 Pa or >0.3* Pf_upstream Pa, else =0. |
|
Bit 3 |
=1 (000008H) |
If local barometric pressure <0 MPa or >0.2 Mpa, else =0. |
|
Bit 4 |
=1 (000010H) |
If meter tube internal diameter <40 mm or >1000 mm, else =0. |
|
Bit 5 |
=1 (000020H) |
If
temperature at which meter tube internal diameter was measured <223.15
K or >373.15 K, else =0. |
|
Bit 6 |
=1 (000040H) |
If linear coefficient of thermal expansion of the meter tube material <0 m/m-K or >0.01 m/m-K, else =0. |
|
Bit 7 |
=1 (000080H) |
If
orifice bore diameter <4mm or >0.75*Pd, else =0. |
|
Bit 8 |
=1 (000100H) |
If
temperature at which orifice plate bore diameter was measured <223.15
K or >373.15 K, else =0. |
|
Bit 9 |
=1 (000200H) |
If
linear coefficient of thermal expansion of the orifice plate material <0
m/m-K or >0.01 m/m-K, else =0. |
|
Bit 10 |
=1 (000400H) |
If
fluid density <0.000001 kg/m3 or >10000
kg/m3, else =0 |
|
Bit 11 |
=1 (000800H) |
If
fluid dynamic viscosity <0 Pa*s or >10
Pa*s, else =0 |
|
Bit 12 |
=1 (001000H) |
If isentropic exponent ¹-1 and (<0.1 or >2000), else =0 |
|
Bit 13 |
=1 (002000H) |
If
Pipe Reynolds number <4000, else=0 |
|
Bit 14 |
=1 (004000H) |
If
beta ratio <0.05 or >0.75, else=0 |
|
Bit 15,... |
=x (008000H) |
All higer bits are unused |
The error_status is returned as unsigned long integer representing all the errors encountered in the calculation. If bits 0,...,14 are all cleared, the returned output results are valid. If only bit 13 of the error_status is set the returned results are obtained at low Reynolds number and need to be used with caution. In all other cases the results are beyond the scope of AGA-3 and will be cleared.
4. aga3 input/output parameters and units
Input parameters to aga3 must be given in SI units and the output parameters are returned in SI too.
The Table 4.1 outlines the aga3
input/output parameters and the corresponding units.
Table 4.1 aga3 input/output parameters and units.
|
Input parameters in SI units: |
||||||||||
|
ud [] |
Up- or down-stream pressure tap: If ud=1 downstream tap, else upstream tap |
|||||||||
|
Pfx [Pa] |
Flowing pressure measured at either up- or down-stream tap |
|||||||||
|
Plb [Pa] |
Local barometric pressure |
|||||||||
|
DP [Pa] |
Differential pressure |
|||||||||
|
Tf [K] |
Flowing temperature |
|||||||||
|
TmD [K] |
Temperature at which meter tube internal diameter was measured |
|||||||||
|
Dm [m] |
Meter tube internal diameter measured at temperature TmD |
|||||||||
|
ap [m/m-K] |
Linear coefficient of thermal expansion of the meter tube material |
|||||||||
|
Tmd [K] |
Temperature at which orifice plate bore diameter was measured |
|||||||||
|
dm [m] |
Orifice bore diameter measured at temperature Tmd |
|||||||||
|
a0 [m/m-K] |
Linear coefficient of thermal expansion of the orifice plate material |
|||||||||
|
rt,p [kg/m3] |
Density of the fluid at flowing conditions |
|||||||||
|
rb [kg/m3] |
Density of the fluid at base conditions |
|||||||||
|
m [Pa-s] |
Absolute viscosity of flowing fluid |
|||||||||
|
k [] |
Isentropic exponent of compressible fluid (For incompressible fluids set k=-1 ‘minus one’) |
|||||||||
|
Output parameters in SI units: |
||||||||||
|
error_status |
Error status |
|||||||||
|
qm[kg/s] |
Mass flow rate |
|||||||||
|
qv[m3/s] |
Volume flow rate at flowing conditions |
|||||||||
|
qvb[m3/s] |
Volume flow rate at base conditions |
|||||||||
|
Cd |
Coefficient of dischsrge |
|||||||||
|
Y |
Expansion factor |
|||||||||
|
Ev |
Velocity of approach factor |
|||||||||
|
ReD |
Pipe Reynolds number |
|||||||||
|
df [m] |
Orifice bore diameter at flowing temperature Tf |
|||||||||
|
Df [m] |
Meter tube internal diameter at flowing temperature Tf |
|||||||||
|
b |
Ratio of orifice bore diameter to meter tube diameter at flowing conditions (beta ratio) |
|||||||||
|
Constants - SI Units |
||||||||||
|
R=8314.51 |
Mr=28.9625 |
Nc=1.0 |
NIc=1.0 |
N3=1.0 |
N4=0.0254 |
N5=0.0 |
Tr=293.15 |
|||
|
p=3.14159 |
A0=0.5961 |
A1=0,0291 |
A2=-0.229 |
A3=0.003 |
A4=2.8 |
A5=0.000511 |
A6=0.021 |
|||
|
S1=0.0049 |
S2=0.0433 |
S3=0.0712 |
S4=-0.1145 |
S5=-0.2300 |
S6=-0.0116 |
S7=-0.5200 |
S8=-0.1400 |
|||
|
Xc=1.142 139 337 256 165 |
A=4.343 524 261 523 267 |
B=3.764 387 693 320 165 |
||||||||
5. Example of
a main program calling the function aga3
/*
**************************************** */
/* THE BEGINNING OF THE MAIN
PROGRAM C-CODE */
/* ****************************************
*/
#include "stdio.h"
#include "conio.h"
/* declaration of the function
CalculateFlowRate */
void aga3(
/* output parameters */
unsigned long int *errflag, /*
Error status */
float *mfr, /*
Mass flow rate [kg/s] */
float *vfr, /* Volume flow rate at
flowing conditions [m3/s] */
float *vfrb, /* Volume flow rate at base
conditions [m3/s] */
float *cd, /* Coefficient of
discharge [] */
float *y, /*
Expansion factor */
float *ev, /* Velocity of approach
factor */
float *ReD, /* Pipe
Reynolds number [] */
float *od, /* Orifice diameter [m]
*/
float *pd, /*
Meter tube diameter [m] */
float *br, /* Orifice to pipe
diameter ratio at flowing temperature [] */
/* input parameters */
short ud, /* Position of pressure measurement tap:
0-upstream, 1-downstream */
float px, /* Flowing pressure [Pa] measured either
upstream or downstream */
float pl, /*
Local barometric pressure [Pa] if gauge pressure measurement else pl=0 */
float dp, /* Differential pressure [Pa] */
float tf, /* Flowing temperature [K] */
float tp, /* Temperature [K] at which meter tube
internal diameter was measured */
float pdtp, /* Meter tube internal diameter [m] measured
at temperature tp */
float ap, /* Linear coefficient of thermal expansion
[m/m-K] of the meter tube material */
float to, /*
Temperature [K] at which orifice diameter was measured */
float odto, /* Orifice bore diameter [m] measured at
temperature to */
float ao, /* Linear coefficient of thermal [m/m-K]
expansion of the orifice plate material */
float d, /*
Fluid density [kg/m3] */
float db, /*
Fluid base density [kg/m3] */
float v, /*
Fluid dynamic viscosity [Pa*s] */
float k /*
Isentropic exponent [], k=-1 for liquids) */
);
void main(void)
{
unsigned short int j, i, m;
char ch;
float yy[13][14]
= {
/* AGA-3/Part 4/Chapter 3.4.3
Calculation Examples */
101325.0f, 0.0f, 27415.0f,
372.04f, 293.15f, 0.049262f, 0.0000112f,
293.15f, 0.036909f,
0.0000167f, 941.75f, 999.01f, 0.0002825f, -1.0f,
101325.0f, 0.0f, 2238.0f,
255.37f, 293.15f, 0.202729f, 0.0000112f,
293.15f, 0.040481f,
0.0000167f, 932.26f, 910.83f, 1.8650f, -1.0f,
1378950.0f, 0.0f, 13987.0f,
255.37f, 293.15f, 0.102270f, 0.0000112f,
293.15f, 0.067667f,
0.0000167f, 32.783f, 1.86131f, 0.00001352f, 1.3198f,
1378950.0f, 0.0f, 559.5f,
255.37f, 293.15f, 0.049262f, 0.0000112f,
293.15f, 0.004961f,
0.0000167f, 32.783f, 1.86131f, 0.00001352f, 1.3198f,
1378950.0f, 0.0f, 109663.0f,
255.37f, 293.15f, 0.049262f, 0.0000112f,
293.15f, 0.004961f,
0.0000167f, 32.783f, 1.86131f, 0.00001352f, 1.3198f,
101325.0f, 0.0f, 559.5f,
255.37f, 293.15f, 0.202729f, 0.0000112f,
293.15f, 0.020241f,
0.0000167f, 932.26f, 910.83f, 1.8650f, -1.0f,
/* EUB test cases 1 to 7 */
2818090.0f, 0.0f, 10200.0f,
330.15f, 293.15f, 0.05237f, 0.0000112f,
293.15f, 0.009525f,
0.0000167f, 24.96808f, 0.958787f, 0.000010268f, 1.3f,
9.100940E+06f, 0.0f,
11000.0f, 323.15f, 293.15f, 0.10226f, 0.0000112f,
293.15f, 0.047625f,
0.0000167f, 90.33028f, 0.91661f, 0.000010268f, 1.3f,
1.034214E+07f, 0.0f,
22160.0f, 333.15f, 293.15f, 0.59055f, 0.0000112f,
293.15f, 0.3048f, 0.0000167f,
107.9166f, 1.007916f, 0.000010268f, 1.3f,
9.839990E+06f, 0.0f, 6613.0f,
295.5f, 293.15f, 0.14636f, 0.0000112f,
293.15f, 0.0889f, 0.0000167f,
79.88845f, 0.712488f, 0.000010268f, 1.3f,
2.499900E+06f, 0.0f,
75000.0f, 307.15f, 293.15f, 0.15405f, 0.0000112f,
293.15f, 0.09525f,
0.0000167f, 23.1822f, 0.929256f, 0.000010268f, 1.3f,
2.506330E+06f, 0.0f,
17050.0f, 280.35f, 293.15f, 0.0525f, 0.0000112f,
293.15f, 0.01905f,
0.0000167f, 30.377f, 1.03149f, 0.000010268f, 1.3f,
2.999200E+05f, 0.0f, 6345.5f,
274.82f, 293.15f, 0.0525f, 0.0000112f,
293.15f, 0.0127f, 0.0000167f,
2.57668f, 0.824924f, 0.000010268f, 1.3f,
};
/* Output data */
unsigned long int
error;
float mfr; /*
Mass flow rate [kg/s] */
float vfr; /* Volume flow rate at
flowing conditions [m3/s] */
float vfrb; /* Volume flow rate at
base conditions [m3/s] */
float