Flow Discrepancy in Refinery Simulation

       Reliable refinery process simulation requires not only correct process logic but also consistent material balance throughout the entire simulation. Continuous simulation model validation is essential for ensuring engineering reliability. Even when a model operates correctly, small residual flow discrepancies may accumulate over time. Monitoring these discrepancies is an important part of model validation, especially in long-running simulations and digital twin applications.
       FlowDiscrepancy is a validation component that continuously tracks accumulated residual flow during simulation. It compares the measured discrepancy with a configurable threshold and automatically throws a Java RuntimeException if the allowed limit is exceeded. This allows engineers to detect model inconsistencies early, validate simulation accuracy, and ensure that accumulated discrepancies remain within acceptable engineering tolerances.
       FlowDiscrepancy validates model correctness, whereas PlanCompletionStatus evaluates production plan execution.

Why Monitor Flow Discrepancies?

       Accurate material balance is one of the primary indicators of a reliable refinery model. Even small residual flow discrepancies can accumulate during long simulation runs. Although these discrepancies are typically negligible, continuous growth may indicate configuration errors, unexpected process behavior, or inconsistencies within the model.
       Monitoring accumulated discrepancy provides an independent verification of model consistency and serves as an important part of material balance validation and simulation verification for refinery models. Instead of evaluating only production results, engineers can also verify that material transfers remain within an acceptable tolerance throughout the entire simulation. This additional validation is particularly valuable for long-term production planning, capacity studies, optimization, refinery digital twin validation, and advanced engineering studies.
       The FlowDiscrepancy component continuously accumulates residual flow and compares the result with a user-defined threshold. If the configured limit is exceeded, the component immediately throws a Java RuntimeException, allowing material balance violations to be detected immediately during simulation.

FlowDiscrepancy in Petroleum Refining Library

       FlowDiscrepancy is a validation component of the Petroleum Refining Library designed to monitor accumulated residual flow during refinery simulations. It helps support refinery model validation by tracking flow discrepancies, monitoring accumulated residual flow, and ensuring that material balance remains within a user-defined tolerance.
The component can be installed at any location where residual flow should be monitored. It is integrated into Plant components by default but can also be used independently to validate other sections of a refinery flowsheet.

       During simulation, FlowDiscrepancy continuously maintains two statistics:
        - accumulated discrepancy – the residual flow used to verify model consistency.
        - total throughput – the total mass that has passed through the component.

       The accumulated discrepancy is periodically compared with the configured discrepancyThreshold. If the threshold is exceeded, the component immediately throws a Java RuntimeException, allowing model validation issues to be detected during simulation rather than after the results have been analyzed.

Configuration Parameters

       FlowDiscrepancy behavior is controlled through a small set of configuration parameters that define how discrepancies are measured, reported, and validated during simulation.

Selecting a Discrepancy Threshold

       The appropriate threshold depends on the required validation accuracy and the expected duration of the simulation. Smaller thresholds provide stricter model verification, while larger thresholds may be suitable for long-running production studies where minor numerical discrepancies are acceptable. For production-scale refinery models developed with Petroleum Refining Library, a discrepancyThreshold of approximately 30 tons over a 90-day simulation has proven to be a practical engineering validation criterion. This value is intended as an engineering guideline rather than a universal recommendation and should be adjusted according to the required accuracy of the specific simulation model.

Runtime Behavior

       During simulation, FlowDiscrepancy accumulates residual flow and periodically updates the measured value according to discrepancyUpdateInterval. Each update compares the accumulated discrepancy with the configured discrepancyThreshold to verify that the model remains within the specified validation tolerance. FlowDiscrepancy operates as a passive validation component. It does not influence material transfer or refinery process logic. Instead, it continuously collects discrepancy statistics while the process model executes normally. When the accumulated discrepancy exceeds discrepancyThreshold and pauseOnLimitExceeded is enabled, the component immediately throws a Java RuntimeException. This allows model inconsistencies to be detected at the moment they occur, preventing simulations with excessive accumulated discrepancy from continuing unnoticed. Unlike FlowQuota, which actively controls material transfer by closing its internal valve, FlowDiscrepancy performs passive validation without affecting process operation.

Typical Applications

       FlowDiscrepancy is primarily used during the development, verification, and maintenance of refinery simulation models. Typical applications include:
  • Material balance verification and material balance validation— ensuring that accumulated residual flow remains within an acceptable tolerance throughout the simulation.
  • Long-term simulation validation — detecting discrepancies that become noticeable only during extended production planning or scheduling scenarios.
  • Model debugging — identifying process sections where accumulated discrepancies originate after changes to model configuration or process logic.
  • Library integration testing — verifying that updates to Petroleum Refining Library components do not introduce unexpected material balance discrepancies.
  • Independent subsystem validation for large refinery process simulation models — monitoring individual process units, tank farms, or complete production areas separately to simplify discrepancy analysis in large refinery models.
       For large refinery models, multiple FlowDiscrepancy components can be installed at different locations. Comparing discrepancy values between individual process sections helps isolate the source of accumulated discrepancies and significantly reduces debugging time.

API Reference

       FlowDiscrepancy provides a compact API for monitoring accumulated discrepancy and accessing runtime statistics. The available methods are summarized below.
updateDiscrepancy(double discrepancyValue)
Updates the current accumulated discrepancy using the latest flow information. If pauseOnLimitExceeded is enabled and the accumulated discrepancy exceeds discrepancyThreshold, the method throws a Java RuntimeException, immediately terminating the simulation. This method is normally invoked automatically by the component according to discrepancyUpdateInterval and does not need to be called explicitly.

getTotalDiscrepancy()
Returns the cumulative mass processed by the component since the start of the simulation.

Best Practices

       The following recommendations help improve the effectiveness of FlowDiscrepancy when validating refinery simulation models.
  • Monitor process sections independently. Install separate FlowDiscrepancy components for major refinery units, such as individual Plant or Reservoir Park systems. This approach makes it significantly easier to identify where accumulated discrepancies originate.
  • Use realistic validation thresholds. Configure discrepancyThreshold according to the required accuracy of the simulation. For long refinery production studies, the threshold should reflect acceptable engineering tolerances rather than theoretical numerical precision.
  • Enable validation during model development. Setting pauseOnLimitExceeded to true helps detect configuration errors and model inconsistencies immediately after the discrepancy exceeds the permitted limit.
  • Review discrepancy statistics regularly. Even when the configured threshold is not exceeded, a continuously increasing discrepancy may indicate an issue that should be investigated before the model is used for engineering studies.
  • Validate models after structural changes. Whenever process units, material routing, or control logic are modified, review FlowDiscrepancy results to confirm that the updated model maintains a consistent material balance.
       FlowDiscrepancy is most effective when used as part of the overall model verification process. Combined with engineering validation and material balance analysis, it helps ensure that Petroleum Refining Library models remain accurate, consistent, and suitable for long-term refinery simulation.

Runtime Example

       Consider a Reservoir Park with a total capacity of 15,000 tons distributed across three storage tanks. During the simulation, material is continuously transferred into the park from upstream process units. Because of normal modeling tolerances, including small variations in the incoming flow, passportization delays, and pumping rate limitations, the park does not accept approximately 1% of the total incoming material. This residual (unaccepted) flow is routed to the FlowDiscrepancy component, where it is accumulated and used for model validation. After the simulation, the accumulated discrepancy indicates that only a small fraction of the total transferred material was not accepted by the park. This result demonstrates that the reservoir park performs as expected while FlowDiscrepancy provides quantitative information about the overall accuracy and consistency of the simulation model.
       Model conclusion;Reservoir Park successfully handles material transfer. FlowDiscrepancy confirms that the accumulated residual flow remains within the expected modeling tolerance.

Conclusion

       Maintaining a consistent material balance is essential for producing reliable refinery process simulation results and effective material balance validation. FlowDiscrepancy extends the Petroleum Refining Library with a dedicated validation component that continuously monitors accumulated residual flow and automatically detects excessive discrepancies during model execution. By providing continuous discrepancy monitoring, automatic runtime validation, and comprehensive simulation verification, FlowDiscrepancy helps engineers identify material balance inconsistencies early, improve refinery model reliability, and increase confidence in engineering decisions based on refinery digital twin and production simulation results. FlowDiscrepancy is commonly used together with Shipment Node and production planning components to validate long-term refinery simulations.

FAQ

1. What is the purpose of FlowDiscrepancy?
FlowDiscrepancy validates refinery simulation models by monitoring accumulated residual flow. It helps verify material balance consistency and detect excessive discrepancies during simulation.

2. Where should FlowDiscrepancy be installed?
The component can be installed anywhere discrepancy monitoring is required. It is integrated into Plant components by default but can also be used independently to validate other refinery units or process sections.

3. Can multiple FlowDiscrepancy components be used in the same model?
Yes. Installing separate FlowDiscrepancy components for different process sections, such as Plant and Reservoir Park, simplifies discrepancy analysis and helps identify where accumulated residual flow originates.

4. What happens when the discrepancy threshold is exceeded?
If pauseOnLimitExceeded is enabled, FlowDiscrepancy immediately throws a Java RuntimeException, terminating the simulation. Otherwise, discrepancy monitoring continues while the simulation remains running.

5. What unit is used to measure discrepancy?
FlowDiscrepancy measures accumulated discrepancy in tons, consistent with the mass-based calculations used throughout the Petroleum Refining Library.

6. How should the discrepancy threshold be selected?
The threshold depends on the required validation accuracy and simulation duration. For many refinery production models, 30 tons over a 90-day simulation is used as a practical engineering guideline.

7. Does FlowDiscrepancy correct discrepancies automatically?
No. FlowDiscrepancy is a passive validation component. It never modifies material flow, routing, or process operation. It only monitors accumulated discrepancy and reports validation failures.