Algorithmic Accuracy
The Alberta Energy Regulator (AER) publishes a measurement handbook called Directive 017: Measurement Requirements for Oil and Gas Operations. This guidebook contains test cases for gas and liquids flow measurements using industry standard algorithms. In this section we show that the calculation results from the PLC Shift gas and liquid flow computers line up with the results of the test cases published in Directive 017. For gas flow using AGA 2017 Part 2 (GERG), we also show that our results line up with publicly available test cases published by NIST.
Please note that this is merely a subset of the testing that we have done. We have also done extensive automated testing against test cases in the relevant specifications like AGA 3, AGA 8, AGA 11 and others. However, because these specifications are not publicly available, and we have no right to reproduce them, we felt that for this applications note, it was better to test against publicly available test cases.
We are confident in the accuracy of our implementations of the relevant algorithms, and we have a comprehensive automated test suite, so if you would like to see test results against specific use cases, or against competing products, please contact us.
PLC Shift apps use double precision (64 bit) floating point numbers in their internal calculations, leading to greater accuracy when compared to older solutions that use single precision (32 bit) math. Only single precision values are synchronized with a PLC, however. Flow history export uses double precision values and leads to the most accurate measurement results, versus passing values through the PLC. In other words, PLC Shift flow computers are fully 64 bit from the inputs on, including the exported data.
PLC Shift applications use double precision (64 bit) numbers internally and export data in double precision format.
|
Gas Flow
AER Directive 017
AER Directive 017 has 7 test cases for gas flow measurement. Test cases for gas measurement can be found at the end of Chapter 4. For the March 2022 release, test cases are on pages 4-40 to 4-47.
Test cases 1 to 7 use AGA3 1990 for flow measurement and AGA8 1994 for the compressibility calculation. Test case 8 uses AGA7 (turbine input) for flow measurement and AGA8 1994 for compressibility. Configurations for all test cases can be downloaded below, but test case 8 (AGA7) is slightly more difficult to test for end users because a constantly increasing counter input must be simulated.
In all cases, the allowable deviation according to the AER is +/-0.25%. The deviation is much less than this in all cases. Test case 6 with an upstream tap has the worst deviation at 0.003988718981597353%. This is still 60 times better than the allowable deviation of 0.25%.
Test Case
|
Tap Location
|
Expected Value (e3m3/24hr)
|
Calculated Value (e3m3/24hr)
|
Difference (%)
|
1
|
Downstream
|
2.7531
|
2.7530230478354203
|
0.002795109679255792
|
1
|
Upstream
|
2.7478
|
2.7476657570010006
|
0.004885471977553801
|
2
|
Downstream
|
146.18
|
146.18036698540715
|
0.000251050353769612
|
2
|
Upstream
|
146.08
|
146.07530704171222
|
0.003212594665793275
|
3
|
Downstream
|
8575.48
|
8575.042921812765
|
0.005096836413062294
|
3
|
Upstream
|
8564.77
|
8564.340288784259
|
0.005017195041336986
|
4
|
Downstream
|
503.63
|
503.64409436615574
|
0.002798555716646303
|
4
|
Upstream
|
503.44
|
503.45219234453236
|
0.002421806875172007
|
5
|
Downstream
|
813.0
|
812.9833216251882
|
0.002051460616459751
|
5
|
Upstream
|
799.83
|
799.820562674861
|
0.001179916374612193
|
6
|
Downstream
|
14.746
|
14.74658637180739
|
0.003976480451582848
|
6
|
Upstream
|
14.687
|
14.687585823156827
|
0.003988718981597353
|
7
|
Downstream
|
1.4489
|
1.4489061369122083
|
0.0004235566435356336
|
7
|
Upstream
|
1.4335
|
1.4335124298504038
|
0.0008670980400306193
|
8
|
N/A (AGA7)
|
3770.9
|
3770.934235567103
|
0.0009078884908846425
|
Test configurations for the PLC Shift Gas Flow app can be downloaded from this link. Once the configuration is deployed to a device, make sure to set the inputs correctly as described in the associated test. This can be done by syncing tags with a PLC, or via the 'User Defined Tags' tab in the app's view in PLC Shift Manager when online.

Gas Flow Test Configurations
AGA8 2017 Part 2 (GERG)
The National Institute of Standards and Technology (NIST) worked with the American Gas Association (AGA) to develop the AGA 8 2017 standards. The AGA 8 2017 standard is well documented and includes sample code as well as test cases on NIST's website, at this link. Specifically, the AGA.XLS file contains VBA code that executes the AGA 8 compressibility calculations. For our use case, we input a temperature value, a pressure value, a gas composition, and the calculation returns a density.
We can use this spreadsheet along with some automatically generated test cases to compare the results of PLC Shift code versus the reference implementation. We wrote a small program that generates test cases in a format that is suitable for use in the spreadsheet and in our own code. We first come up with a randomized gas composition, and then for that one gas composition, come up with 20 random values of pressure and temperature. Temperature values are between 230 and 450 Kelvin, and pressure values are between 0.15 and 35 MPa.
The results can be found in the spreadsheet at this link, on the 'PLC Shift' tab. This is same spreadsheet that NIST distributes, but the input and output units were configured to be metric. The VBA code in the spreadsheet has a setting to change units. The calculation internally is done in metric, so using metric units for inputs and outputs results in greater accuracy.

Modified AGA8.XLS Spreadsheet that shows PLC Shift Result vs NIST result

PLC Shift Code that Executes Test Cases
In the modified AGA8.XLS spreadsheet, we enter values for temperature, pressure and a gas composition and use the VBA in the spreadsheet to calculate a density. We run the same test cases in the same order against the PLC Shift implementation, as shown in the screen grab above. We copy the results from the our tests into the spreadsheet and then calculate the difference between the value from our implementation and the NIST implementation. If the difference is greater that 1e-5, we highlight the cell in the 'Diff' column in red.
There are a few places where the results don't match up, mostly because the calculation does not converge. When the calculation does not converge on the PLC Shift side, a value of '-1' is entered for the density. In other cases, we see two phase flow, or other outliers where the algorithm is known to be inaccurate. Excluding these cases, the PLC Shift result matches the NIST result extremely closely, with a typical error of less than 1 ppm.
The spreadsheet only contains 10 000 test cases, but we have run this test many times and see that the PLC Shift results consistently match up with the reference implementation. We are confident in the accuracy of our implementation of the AGA8 2017 Part 2 (GERG) calculation.
Additional Considerations
The PLC Shift Gas Flow application executes once per second. Complete AGA-8 and AGA-3 calculations are performed every cycle. Many legacy flow computers only calculate compressibility (AGA 8) when inputs change by a certain amount, or some time has passed, or by using other metrics. This leads to inaccurate measurement. Some vendors call the ability to execute the compressibility calculation once per second "Enhanced Mode", while other vendors don't even mention that they are only calculating compressibility intermittently. Clearly this matters, and better measurement is obtained by calculating compressibility on every cycle.
Liquid Flow
AER Directive 017
AER Directive 017 has 20 test cases for liquid flow measurement. Test cases for liquid measurement can be found towards the end of Chapter 14. For the March 2022 release, test cases are on pages 14-21 and 14-22.
Test cases 1 to 5 are for corrections of crude oil flowing density to base density at 15 C. Test cases 11 to 15 are corrections of Natural Gas Liquids (NGL) from flowing conditions to base conditions. These test cases are what a flow computer normally does and as such can be tested by the user by configuring the flow computer and setting the inputs as required.
Test cases 6 to 10 correct the base density to flowing conditions for crude oil. Test cases 16 to 20 correct the base density to flowing conditions for NGL. AP1 11 uses this type of calculation internally, which is why it is included in the AER test cases, but it's not possible to configure the PLC Shift Liquid Flow app to calculate these results. We show the results of the internal calculation below and we can provide more detail on request.
In all cases, the allowable deviation according to the AER is +/-0.1%.
Test Cases 1 - 5, Crude Oil
Results for test cases 1 to 5 are shown below. In all cases the the difference is much smaller than the allowable limit of 0.1%. These cases can be tested by configuring an instance of the Liquid Flow app and setting the input density and temperature to the test values. The liquid product type used for the tests below is 'Crude Oil'. A pressure of 0 is not allowed, so for the tests 1 to 5, we set the pressure to 0.01 kPa.
Test Case
|
Flowing Density (kg/m3)
|
Flowing Temperature (°C)
|
Expected Value (kg/m3)
|
Calculated Value (kg/m3)
|
Difference (%)
|
1
|
875.5
|
120.0
|
945.0
|
945.0 (944.9909474859332)
|
0.000957937996482
|
2
|
693.0
|
11.4
|
689.8
|
689.8
(689.7994370840061)
|
0.0000816056827953
|
3
|
644.0
|
84.45
|
705.7
|
705.7 (705.7116042861803)
|
0.00164436533658
|
4
|
625.5
|
53.05
|
661.4
|
661.3 (661.3368322928314)
|
0.0055696798475
|
5
|
779.0
|
25.0
|
786.8
|
786.8 (786.8278641212767)
|
0.00354144906923
|
Test Cases 6 - 10, Crude Oil
Test cases 6 to 10 convert a base density at 15 C to a flowing density. The PLC Shift Liquid Flow app cannot be configured to perform this type of calculation, but we can perform the calculation using our internal algorithms in a standalone way. The test code below shows how we execute our 'CalculateRhoTp' function against the AER test cases.
The console output of the test code is shown below. In all cases, the difference is less than the allowable limit of 0.1%.
Test Cases 11 - 15, NGL
Results for test cases 11 to 15 are shown below. In all cases the the difference is much smaller than the allowable limit of 0.1%. These cases can be tested by configuring an instance of the Liquid Flow app and setting the input density and temperature to the test values. The liquid product type used for the tests below is 'Natural Gas Products'. A pressure of 0 is not allowed, so for the tests 11 to 15, we set the pressure to 0.01 kPa.
Note that the Liquid Flow app will always implement vapor pressure correction according to API MPMS 11.2.2. Even with an almost 0 pressure, this correction affects the final result. For example, for test case 4, calculated CTL is 0.9465848737197989 and calculated CPL 0.999779620483238 which results in a base density of 658.828863878071. Without the pressure component, the corrected density is 623.5 / 0.9465848737197989 = 658.683671491, which is closer to the expected result. The expected results from the AER implement temperature correction only.
Test Case
|
Flowing Density (kg/m3)
|
Flowing Temperature (°C)
|
Expected Value (kg/m3)
|
Calculated Value (kg/m3)
|
Difference (%)
|
11
|
525.0
|
92.5
|
614.9
|
614.9 (614.8948804660221)
|
0.000832579928103
|
12
|
412.5
|
11.4
|
404.5
|
404.4 (404.440504920726)
|
0.0147083014274
|
13
|
355.5
|
84.45
|
506.9
|
506.9 (506.94389433819)
|
0.00865936835471
|
14
|
623.5
|
53.05
|
658.7
|
658.8 (658.828863878071)
|
0.0195633639094
|
15
|
652.5
|
25.0
|
661.5
|
661.5 (661.4593253841491)
|
0.00614884593362
|
Test Cases 16 - 20, NGL
Test cases 16 to 20 convert a base density at 15 C to a flowing density. The PLC Shift Liquid Flow app cannot be configured to perform this type of calculation, but we can perform the calculation using our internal algorithms in a standalone way. The test code below shows how we execute our algorithms against the AER test cases.
The console output of the test code is shown below. In all cases, the difference is less than the allowable limit of 0.1%.