AGA Calculations Library and Source Code

SCADACore provides American Gas Association calculation libraries and full source code to developers needing to calculate gas flow.

Complete C/C++, C#, and Python AGA Calculation Source Code

SCADACore’s AGA Gas Flow Library / Source Code provides verified AGA gas flow calculations specified by the American Gas Association. All available AGA Calculations are combined into one easy-to-use DLL. The source code is also available for use in embedded systems, as well as to assist manufacturers in bringing their flow computers to the market with accurate flow calculations.

  • Verified with AGA Test Cases

  • Trusted and Deployed on Numerous Systems

  • Complete Suite of AGA Calculations

  • Usage Example Project

  • Save Hundreds of Hours of Development and Testing

  • Licensed by Companies Worldwide

  • Full Source Code Files in C/C++, C#, and Python

Source Code Functions with Full Double Precision

AGA3

struct AGA3Result
{
Flow;
SpecificGravity;
FlowingCompressibility_Zf;
BaseCompressibility_Zb;
Compressibility_FPV;
}

AGA3Result CalculateFlow(flowTemperature, pipeReferenceTemperature, orificeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, orificeSize, pipeSize, AgaConstants.MaterialType orificeMaterial, AgaConstants.MaterialType pipeMaterial, tapIsUpstream, GasComps gasCompositions)

AGA3Result CalculateFlow(flowTemperature, pipeReferenceTemperature, orificeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, orificeSize, pipeSize, AgaConstants.MaterialType orificeMaterial, AgaConstants.MaterialType pipeMaterial, tapIsUpstream, flowCompressibility, baseCompressibility, specificGravity)

AGA3Result CalculateFlowWithViscosity(flowTemperature, pipeReferenceTemperature, orificeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, orificeSize, pipeSize, AgaConstants.MaterialType orificeMaterial, AgaConstants.MaterialType pipeMaterial, tapIsUpstream, flowCompressibility, baseCompressibility, specificGravity, viscosity)

AGA3Result CalculateFlow(flowTemperatureInKelvin, pipeReferenceTemperatureInKelvin, orificeReferenceTemperatureInKelvin, baseTemperatureInKelvin, staticPressureKPA, baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM, orificeExpansionCoefficient, pipeExpansionCoefficient, tapIsUpstream, FlowZCalc, BaseZCalc, SpecificGravity)

AGA3Result CalculateFlowWithViscosity(flowTemperatureInKelvin, pipeReferenceTemperatureInKelvin, orificeReferenceTemperatureInKelvin,
baseTemperatureInKelvin, staticPressureKPA, baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM, orificeExpansionCoefficient, pipeExpansionCoefficient, tapIsUpstream, FlowZCalc, BaseZCalc, SpecificGravity, viscosity)

AGA7

struct AGA7Result
{
Flow;
SpecificGravity;
FlowingCompressibility_Zf;
BaseCompressibility_Zb;
Compressibility_FPV;
}

AGA7Result CalculateFlow(flowVolume, flowTemperature, baseTemperature, staticPressure, basePressure, meterFactor, GasComps gasCompositions)

AGA7Result CalculateFlow(flowVolume, flowTemperature, baseTemperature, staticPressure, basePressure,meterFactor, flowCompressibility, baseCompressibility, specificGravity)

AGA7Result CalculateAGA7(flowVolumeInM3, flowTemperatureInKelvin, baseTemperatureInKelvin, staticPressureKPA, basePressureKPA, meterFactor, FlowZCalc, BaseZCalc, SpecificGravity)

AGA8

struct AGA8Result
{
FlowCompressiblity;
SpecificGravity;
}

AGA8Result CalculateZ(GasComps gasCompositions, temperatureInKelvin, pressurePSI)

molarMass(gasComps)

DDetail(Pressure, TempInKevin)

Bracket(TemperatureInKelvin, Pressure)

PDetail(Rho, temp)

ZDetail(density, temperatureInKelvin)

BMix(tempInKelvin)

Temp(temperatureInKelvin)

AGA11

struct AGA11Result
{
Rho;
SpecificGravity;
FlowingCompressibility_Zf;
BaseCompressibility_Zb;
Compressibility_FPV;
VolumetricFlowRate_Qb;
VolumetricFlowRate_Qf;
}

AGA11Result CalculateFlow(flowTemperature, baseTemperature, staticPressure, baseStaticPressure, moleWeight, GasComps gasCompositions)

AGA11Result CalculateFlow(flowTemperature, baseTemperature, staticPressure, baseStaticPressure, moleWeight, flowCompressibility, baseCompressibility, specificGravity)

AGA11Result CalculateFlow(flowTemperatureInKelvin, staticAbsolutePressureKPA, moleWeight, FlowZCalc, BaseZCalc, SpecificGravity)

VCone

struct VConeResult
{
Flow;
SpecificGravity;
FlowingCompressibility_Zf;
BaseCompressibility_Zb;
Compressibility_FPV;
}

VConeResult CalculateFlowFromVConeSize(flowTemperature, pipeReferenceTemperature, vConeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, VConeSize, pipeSize, AgaConstants.MaterialType vConeMaterial, AgaConstants.MaterialType pipeMaterial,  tapIsUpstream, flowCoefficient, GasComps gasCompositions)

VConeResult CalculateFlowFromVConeSize(flowTemperature, pipeReferenceTemperature, vConeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, vConeSize, pipeSize, AgaConstants.MaterialType vConeMaterial, AgaConstants.MaterialType pipeMaterial, tapIsUpstream, flowCompressibility, baseCompressibility, specificGravity, flowCoefficient)

VConeResult CalculateFlowFromVConeBeta(flowTemperature, pipeReferenceTemperature, vConeReferenceTemperature, baseTemperature, staticPressure, baseStaticPressure, differentialPressure, vConeBeta, pipeSize, AgaConstants.MaterialType vConeMaterial, AgaConstants.MaterialType pipeMaterial,  tapIsUpstream, flowCompressibility, baseCompressibility, specificGravity, flowCoefficient)

VConeResult CalculateVConeFlowFromBeta(flowTemperatureInKelvin, pipeReferenceTemperatureInKelvin, baseTemperatureInKelvin, staticPressureKPA,  baseStaticPressureKPA, differentialPressureKPA, vConeBeta, pipeSizeMM, pipeExpansionCoefficient, tapIsUpstream, FlowZCalc, BaseZCalc, SpecificGravity,  flowCoefficient)

VConeResult CalculateVConeFlowConeSize(flowTemperatureInKelvin, pipeReferenceTemperatureInKelvin, vConeReferenceTemperatureInKelvin, baseTemperatureInKelvin, staticPressureKPA, baseStaticPressureKPA, differentialPressureKPA, VConeSizeMM, pipeSizeMM, vConeExpansionCoefficient, pipeExpansionCoefficient, tapIsUpstream, FlowZCalc, BaseZCalc, SpecificGravity, flowCoefficient)

Venturi

struct VenturiflowResult
{
Flow;
Mass;
SpecificGravity;
FlowingCompressibility_Zf;
BaseCompressibility_Zb;
Compressibility_FPV;
}

VenturiflowResult CalculateVentriFlow(pipeDiameter_mm, venturiDiameter_mm, staticPressure_kPa, basePressure_kPa, atmosphericPressure_kPa,  differentialPressure_kPa, specificGravity, flowZCalc, refTemperature_C, flowTemperature_C)

Code Usage Samples

The AGA 3 Calculation is the most common AGA calculation used for measure natural gas flow through orifice meters and V-Cone. 

Compressibility factors if known can be inputted manually or AGA 8 calculations can be performed to calculate the compressibility based on the gas compositions of the well.

private void AGA3Example()
{
double flowTemperatureInCelcius = 57;
double pipeReferenceTemperatureInCelcius = 20;
double orificeReferenceTemperatureInCelcius = 20;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 2818.09;
double baseStaticPressureKPA = 101.325;
double differentialPressureKPA = 10.2000;
double orificeSizeMM = 9.525;
double pipeSizeMM = 52.370;
AgaConstants.MaterialType orificeMaterial = AgaConstants.MaterialType.StainlessSteel;
AgaConstants.MaterialType pipeMaterial = AgaConstants.MaterialType.CarbonSteel;
bool tapIsUpstream = true;
double flowCompressibility = .9280;
double baseCompressibility = .9959;
double specificGravity = .7792;

AGAFlowCalculation.Aga3 aga3calc = new AGAFlowCalculation.Aga3();

AGA3Result result = aga3calc.CalculateFlow(flowTemperatureInCelcius, pipeReferenceTemperatureInCelcius, orificeReferenceTemperatureInCelcius, baseTemperatureInCelcius, staticPressureKPA, baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM,
orificeMaterial, pipeMaterial, tapIsUpstream,flowCompressibility,baseCompressibility,specificGravity);

System.Console.WriteLine(“AGA3 Test with Flow Compressibility, Base Compressibility, and Specific Gravity Entered”);
System.Console.WriteLine(“Base Compressibility: ” + result.BaseCompressibility_Zb);
System.Console.WriteLine(“Compressibility: ” + result.Compressibility_FPV);
System.Console.WriteLine(“Flowing Compressibility: ” + result.FlowingCompressibility_Zf);
System.Console.WriteLine(“Specific Gravity: ” + result.SpecificGravity);

System.Console.WriteLine(“***Flow***: ” + result.Flow);

System.Console.WriteLine(“Press Enter To Exit”);
System.Console.ReadLine();
}

The AGA 8 Calculations take Gas Compositions as parameters and produce the compressibility factors that can then be used by AGA 3, AGA 7 or AGA 11 to perform more accurate calculations.

private void AGA8Example()
{
//Example of AGA8/AGA3 Flow calculation with Gas Compositions…
AGAFlowCalculation.GasComps gascomps = new AGAFlowCalculation.GasComps();

gascomps.Add(.0184, AGAFlowCalculation.AgaConstants.GasCompositions.Nitrogen_N2);
gascomps.Add(0, AGAFlowCalculation.AgaConstants.GasCompositions.CarbonDioxide_CO2);
gascomps.Add(.0260, AGAFlowCalculation.AgaConstants.GasCompositions.HydrogenSulfide_H2S);
gascomps.Add(.7068, AGAFlowCalculation.AgaConstants.GasCompositions.Methane_C1);
gascomps.Add(.1414, AGAFlowCalculation.AgaConstants.GasCompositions.Ethane_C2);
gascomps.Add(.0674, AGAFlowCalculation.AgaConstants.GasCompositions.Propane_C3);
gascomps.Add(.0081, AGAFlowCalculation.AgaConstants.GasCompositions.iButane_iC4);
gascomps.Add(.0190, AGAFlowCalculation.AgaConstants.GasCompositions.nButane_nC4);
gascomps.Add(.0038, AGAFlowCalculation.AgaConstants.GasCompositions.iPentane_iC5);
gascomps.Add(.0043, AGAFlowCalculation.AgaConstants.GasCompositions.nPentane_nC5);
gascomps.Add(.0026, AGAFlowCalculation.AgaConstants.GasCompositions.nHexane_C6);
gascomps.Add(.0022, AGAFlowCalculation.AgaConstants.GasCompositions.nHeptane_C7);

double flowTemperatureInCelcius = 57;
double pipeReferenceTemperatureInCelcius = 20;
double orificeReferenceTemperatureInCelcius = 20;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 2818.09;
double baseStaticPressureKPA = 101.325;
double differentialPressureKPA = 10.2000;
double orificeSizeMM = 9.525;
double pipeSizeMM = 52.370;
AgaConstants.MaterialType orificeMaterial = AgaConstants.MaterialType.StainlessSteel;
AgaConstants.MaterialType pipeMaterial = AgaConstants.MaterialType.CarbonSteel;
bool tapIsUpstream = true;

AGAFlowCalculation.Aga3 aga3calc = new AGAFlowCalculation.Aga3();

AGA3Result result = aga3calc.CalculateFlow(flowTemperatureInCelcius, pipeReferenceTemperatureInCelcius,
orificeReferenceTemperatureInCelcius, baseTemperatureInCelcius, staticPressureKPA,
baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM,
orificeMaterial, pipeMaterial, tapIsUpstream, gascomps);

System.Console.WriteLine(“AGA3 Test with AGA8 Gas Compositions calculating compressibility and specific gravity”);
System.Console.WriteLine(“Base Compressibility: ” + result.BaseCompressibility_Zb);
System.Console.WriteLine(“Compressibility: ” + result.Compressibility_FPV);
System.Console.WriteLine(“Flowing Compressibility: ” + result.FlowingCompressibility_Zf);
System.Console.WriteLine(“Specific Gravity: ” + result.SpecificGravity);

System.Console.WriteLine(“***Flow***: ” + result.Flow);

System.Console.WriteLine(“Press Enter To Continue”);
System.Console.ReadLine();
}

When performing AGA 7 calculations you can either manually input the compressibility factors or use AGA 8 calculations to calculate the compressibility using the gas compositions.

public void AGA 7 Test()
{
AGAFlowCalculation.GasComps gascomps = new AGAFlowCalculation.GasComps();

gascomps.Add(.0184, AGAFlowCalculation.AgaConstants.GasCompositions.Nitrogen_N2);
gascomps.Add(0, AGAFlowCalculation.AgaConstants.GasCompositions.CarbonDioxide_CO2);
gascomps.Add(.0260, AGAFlowCalculation.AgaConstants.GasCompositions.HydrogenSulfide_H2S);
gascomps.Add(.7068, AGAFlowCalculation.AgaConstants.GasCompositions.Methane_C1);
gascomps.Add(.1414, AGAFlowCalculation.AgaConstants.GasCompositions.Ethane_C2);
gascomps.Add(.0674, AGAFlowCalculation.AgaConstants.GasCompositions.Propane_C3);
gascomps.Add(.0081, AGAFlowCalculation.AgaConstants.GasCompositions.iButane_iC4);
gascomps.Add(.0190, AGAFlowCalculation.AgaConstants.GasCompositions.nButane_nC4);
gascomps.Add(.0038, AGAFlowCalculation.AgaConstants.GasCompositions.iPentane_iC5);
gascomps.Add(.0043, AGAFlowCalculation.AgaConstants.GasCompositions.nPentane_nC5);
gascomps.Add(.0026, AGAFlowCalculation.AgaConstants.GasCompositions.nHexane_C6);
gascomps.Add(.0022, AGAFlowCalculation.AgaConstants.GasCompositions.nHeptane_C7);

double flowTemperatureInCelcius = 45.5;
double meterFactor = 2.0000;
double flowVolume = 10;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 13789.4;
double baseStaticPressureKPA = 101.325;

AGAFlowCalculation.Aga7 aga7calc = new AGAFlowCalculation.Aga7();

AGA7Result result = aga7calc.CalculateFlow(flowVolume, flowTemperatureInCelcius,
baseTemperatureInCelcius, staticPressureKPA, baseStaticPressureKPA, meterFactor, 0.848356, 0.997761, 1);

Assert.AreEqual(2.894755, result.Flow, (2.894755 * .001));
}

When performing AGA 11 calculations you can either manually input the compressibility factors or use AGA 8 calculations to calculate the compressibility using the gas compositions.

Contact Us

Redistributable License

  • License will allow a company to build applications that are accessible by both customers and internal employees. 
  • License can be used as a part of an existing application to add real-time gas flow calculations.
  • License does not have limits on the number of developers.
  • License can not be used to offer a free gas flow calculator similar to the SCADACore’s AGA Gas Flow Calculators, SCADACore’s AGA Gas Flow Calculators For Windows, or SCADACore’s Mobile Gas Flow Calculators

Want to know more?

Interested in the AGA Library? You can verify the accuracy of the calculator with the online calculator here: https://www.scadacore.com/tools/aga-calculators/aga-gas-flow-calculator/

Note that the library will provide higher precision numbers compared to the online calculator; and with the full source code, you can use the the library to develop any software or embedded hardware for your application.

  • Do you need to accurately verify your well flow values? Check out our Excel Calculator here.

  • Do you spend hours each month manually calculating flow values?
  • Do you want to automate tedious tasks and save time and money in the process?
  • Do you want to make your job easier?