Averaging and Accumulations

Accurate averaging and accumulation are critical functions of a flow computer. A flow computer is required to average and accumulate values over many different time spans, including, minutes, hours and days. Averages and accumulations must also be accurate over partial time spans, or, in the case of batches, over multiple days.
 
Given some of the long time spans involved, testing this functionality by running a flow computer in real time means that comprehensive testing either takes a very long time, or only a small number of tests can occur. The cycle of testing, finding bugs, fixing those bugs and then retesting takes a very long time when running in real time.
 
All PLC Shift applications, including the Gas Flow and Liquid Flow apps, have a comprehensive automated test suite. With this test suite, we run the application, or parts of the application, much faster than real time. This approach has numerous benefits:
 
  • Tests that span days of real time can be executed in far less time.
  • The test-debug-fix-retest loop is very fast, making is easier to find and fix bugs, which ultimately leads to greater overall reliability.
  • We can easily feed the app under test with randomized input data. This is hard to do when testing in real time.
  • We can easily set arbitrary start and stop times, or run time.
 
Below we explain how some of our automated testing for averaging and accumulation works. This a small subset of our entire test suite and is only meant to illustrate how we approach automated testing. For all tests, when an error occurs, the test is stopped. Successful completion of a test means that no errors were detected.
 

Averaging

The test code below is used to test averaging for differential pressure (dp), static pressure (sp) and temperature inputs for the Gas Flow app. The Liquid Flow app uses the same code for averaging, so we can know that those averages are calculated correctly even if we don't explicitly test them. 
 
 
The code works as follows:
  •  Set up a test that runs for 56 hours, so that it covers multiple contract days.
  •  Calculate when the current minute, hour and contract day end. These are partial records because they do not cover the full time span.
  • In the main for loop, for every second that the script runs, do the following:
  • Generate a new random dp value once in a while.
  • Calculate exact averages.
  • When a minute, hour, or contract day occurs, verify that our calculated average from the test matches the average generated by the app.
  • Every so often, very that the hourly and daily averages generated by the flow computer match our calculated averages.
 
Single Averaging Test Result
 
 
Each test takes around 50 seconds to run and encompasses a real time of 3360 minutes. We can easily run any test, or the entire suite of tests, continuously or for an arbitrary number of iterations. By using randomly generated values, we can be sure that we cover a vast majority of real use cases.
 
Averaging of values by PLC Shift flow computers is accurate and works correctly, which leads to accurate measurement.
 

Accumulation

The test code below is used to test accumulation of corrected volumes for the Gas Flow app over multiple contract days. This same code is used for all other accumulations in the Gas Flow app, as well as accumulations for the the Liquid Flow app, so we can be assured that those accumulations are working correctly from this one test.  
 
 
The code works as follows:
  • Set up a test that runs for 62 hours, so it covers multiple contract days.
  • Calculate when the current minute, hour and contract day end. These are partial records because they do not cover the full time span.
  • Set the inputs. This test uses fixed inputs so that we can know what the accumulated corrected volume should be. We use the values from a test case published by the Alberta Energy Regulator (AER) so that we can know what the result of the flow calculation should be independent of our own algorithms.
  • Verify that the corrected volume output from the app matches our calculated value based on the elapsed time.
 
Single Accumulation Test Result
 
Each test takes around 50 seconds to run and encompasses a real time of 3720 minutes. We can easily run any test, or the entire suite of tests, continuously or for an arbitrary number of iterations.
 
Accumulation of values by PLC Shift flow computers is accurate and works correctly, which ensures accurate measurement.