Flow Smoothing for Digital Twins

Why Flow Smoothing Is Essential for Digital Twin Simulation?

       Modern oil and gas Digital Twin simulation models must represent the continuous behavior of material flows over time. Accurate dynamic simulation requires converting aggregated production planning data into continuous flow profiles. However, production data used for simulation is often provided as aggregated planning information, such as daily or monthly production volumes.
       For example, when simulating a refinery Digital Twin, oil production plans may be provided as monthly feedstock supply schedules:
        - January: 100,000 tons
        - February: 150,000 tons
Flow smoothing controls transitions between planning periods, while Source Control in Refinery Simulation provides runtime mechanisms for managing feedstock flow limits during simulation.

       Although the AnyLogic Fluid Library does not provide built-in flow smoothing, this functionality can be implemented using specialized classes.
       This conversion is a common requirement in refinery production planning, process simulation, and oil and gas logistics models. To use this data in a dynamic simulation model, monthly volumes must be converted into continuous flow representations suitable for continuous flow simulation (for example, tons per hour). This conversion is a fundamental step in production planning and feedstock scheduling, where discrete supply plans must be transformed into continuous operating conditions for simulation. Without this conversion, the simulation loses temporal resolution and may produce results that are less representative of actual operations. Events occurring within a planning period can only be reflected when the model advances to the next discrete period. For example, an operating mode may need to change early in the day because the tank farm reaches its maximum level. In a daily model, this change may not be captured until the beginning of the next day, creating an artificial delay in the response. Converting discrete supply plans into continuous flow rates allows the simulation to respond to such events at the time they actually occur, resulting in more realistic flow dynamics, inventory levels, and operating decisions.
       In real oil and gas production systems, production rates evolve continuously due to operational constraints and production management practices. However, aggregating continuous production into discrete planning periods introduces artificial step changes at the boundaries between consecutive periods. These discontinuities are especially noticeable in monthly production plans and do not reflect the actual behavior of the production system.
       Artificial flow discontinuities at the boundaries of monthly planning periods may temporarily change the operating modes of downstream process units. Although these effects are caused solely by data aggregation, they produce unrealistic transient behavior in the digital twin. Flow smoothing provides a mechanism to convert discrete production plans into realistic continuous flow profiles while preserving the original planned production volume. The objective is not to change the production plan, but to ensure that the transition between different planning periods is represented correctly in a dynamic simulation model.
       Monitoring Source output is essential when production plans are converted into continuous flow rates for refinery simulation. The main Source performance metrics used to evaluate output and production plan execution are described in detail in our dedicated guide.

Limitations of Direct Production Plan Conversion

       Converting a production plan into a constant flow rate is mathematically straightforward but does not always represent real operation. A monthly production plan specifies only the total volume to be delivered during a period and provides no information about how production should transition between consecutive months. Consequently, direct conversion into a simulation input produces an instantaneous change in flow at the planning boundary. Although this preserves the planned monthly volume, it introduces an artificial discontinuity into the material flow.
       In real oil and gas production systems, production rates change gradually due to production ramp-up and ramp-down constraints, pipeline operating conditions, equipment response time, storage availability, and coordination between upstream and downstream facilities. Abrupt flow changes are generally avoided because they can generate hydraulic transients in pipelines and disturb normal tank breathing conditions.
       These dynamics are particularly important for digital twins that include tank farms and other storage systems. Storage control algorithms determine withdrawal rates based on the expected incoming flow together with current inventory levels and available capacity. As will be shown in more detail later, such abrupt changes in flow rate can also lead optimization and control algorithms to make incorrect or operationally unrealistic decisions. This interaction is one of the key challenges in storage simulation and refinery logistics models. They are especially relevant in tank farm simulation, where storage behavior strongly depends on predicted incoming feedstock flows. Artificial step changes at planning boundaries therefore create a mismatch between the predicted and actual inflow, potentially causing temporary operating mode changes, unrealistic transient behavior, and false storage constraints. Such discontinuities reduce the accuracy of refinery simulation because they introduce operating conditions that would not occur in real industrial systems.
The objective not simply to convert production volumes into flow rates, but to construct a continuous flow profile that preserves the production plan while eliminating artificial discontinuities and providing physically realistic input for downstream simulation.

Mass-Preserving Flow Smoothing Algorithm

       Note. This article focuses on the engineering principles of the algorithm. The complete mathematical derivation and reference Java implementation are provided in separate appendices to keep the main article concise.

       Flow smoothing in digital twin software should not be considered as a simple filtering operation that reduces fluctuations in a signal. Its purpose is different: it ttransforms discrete production planning data into a continuous flow representation suitable for dynamic simulation. The main principle of the algorithm is that smoothing changes only the distribution of mass flow over time while preserving the total planned delivery mass. The proposed algorithm is intended for digital twin software that integrates production planning with continuous process simulation.
       For a given planning period:

Mplanned = Msimulated

when no external operational limitations are applied.

       The algorithm uses two main inputs:
        - the current actual mass flow rate at the end of the planning period;
        - the target mass flow rate defined by the next production plan.
       Instead of applying an instantaneous change at the month boundary, the transition is distributed over a predefined smoothing period.
       The transition is applied before the end of the current planning period rather than at the beginning of the next one. This approach ensures that the next period remains consistent with its original production plan.
The effect of flow smoothing on production output can be evaluated using Source performance metrics in refinery simulation, including output flow, plan completion, and historical production data.

The algorithm therefore provides three important properties
  • Flow continuity

    Eliminates unrealistic instantaneous changes between planning periods
  • Mass balance preservation

    Maintains the original production target after smoothing
  • Operational consistency

    Creates realistic input data for downstream assets such as pipelines, tank farms, and refinery units

Mathematical Appendix

       The algorithm presented in this section is intentionally described at a conceptual level. Readers interested in the complete mathematical derivation, including all equations, interpolation formulas, proof of mass preservation, and numerical implementation details, can refer to the Mathematical Appendix.

See Mathematical Formulation of the Mass-Preserving Flow Smoothing Algorithm.

Why Flow Smoothing Is Applied at the End of the Planning Period?

       A key design decision in the flow smoothing algorithm is the location of the transition period. The smoothing is applied at the end of the current planning period rather than at the beginning of the next one. Consider a case where the next month's production plan is significantly reduced or even equal to zero. If the smoothing transition starts at the beginning of the next month, the transition flow will contribute additional mass to that month before reaching the new target flow rate.
       This ensures that:
       - the next planning period starts with the correct target flow rate;
       - the total planned delivery mass of each period remains unchanged;
       - the transition does not create artificial production outside the planned period.

       This approach is especially important for digital twin models, where production plans are used together with downstream constraints such as tank farm capacity, pipeline limitations, and refinery processing requirements.

Transition from Actual Operating Conditions to Future Production Plans

       A key feature of the flow smoothing algorithm is that the transition does not start from the average flow rate calculated from the current monthly production plan. Instead, it starts from the current actual mass flow rate generated by the Digital Twin at the end of the planning period. This distinction is important because the current flow rate already reflects the actual operating state of the system, including previous planning transitions and operational constraints.
       A simplified approach would assume: Current month average flow → Smoothing transition → Next month planned flow
       However, this approach ignores the dynamic history of the system. The actual operating flow at the end of the month may differ from the monthly average because of:
  • previous flow transitions;
  • downstream equipment limitations;
  • pipeline restrictions;
  • storage system behavior.
       The Petroleum Refining Library approach uses the actual simulated flow as the starting point:
Current actual mass flow rate (at the end of current period) → Linear smoothing transition → Next period target mass flow rate (from production plan).
       This ensures continuity of the Digital Twin state. The model does not restart the production system at each planning boundary; instead, it continues the existing operating trajectory and gradually moves toward the new planned condition.
       This approach is especially important when production plans change significantly between periods. The transition begins from the real current state of the system and not from an artificial average value, resulting in more realistic behavior of downstream assets such as pipelines, tank farms, and processing facilities.

       Before concluding this section, two additional characteristics of the proposed smoothing algorithm should be highlighted.
       First, smoothing is not applied at the initial simulation time because no previous operating state exists. The Digital Twin assumes that the modeled production system has already been operating before the simulation begins. Therefore, the initial planning period is treated as a continuation of an existing operating regime rather than as a transition from zero flow.
       Second, the calculation of the target average flow should account for planned shutdowns of downstream process units. During maintenance periods, the receiving equipment is temporarily unable to accept incoming flows, causing the actual flow to temporarily drop to zero. To preserve the planned delivery mass over the planning period, scheduled equipment shutdowns should be taken into account when estimating the target average flow. Ignoring scheduled maintenance would underestimate the required flow during normal operation and could prevent the planned delivery from being completed within the specified period.

Configuring Flow Smoothing Parameters

       The flow smoothing algorithm provides two main parameters that control how the transition between production periods is represented in the digital twin model:
       SMOOTHING_DURATION - defines the total time period over which the flow transition is performed;
       SMOOTHING_INTERVAL - defines the time step used to recalculate the intermediate flow values during the transition.
       These parameters control the temporal resolution and smoothness of the transition but do not affect the total planned planned delivery mass. Access to these parameters is provided through the Constants inner class of the Source agent, allowing the smoothing behavior to be configured directly within the source component.

Smoothing duration

       SMOOTHING_DURATION determines how quickly the system moves from the current operating flow rate to the target flow rate of the next production period.
       The appropriate value depends on the required level of operational realism. In Petroleum Refining Library, this parameter is configurable by the model user. The optimal configuration depends on the required level of operational realism and the objectives of production optimization. For monthly production plans, a smoothing duration of approximately three-five days is recommended as a practical balance between preserving planning accuracy and avoiding unrealistic flow discontinuities.

Smoothing interval

       SMOOTHING_INTERVAL defines how frequently the transition flow rate is recalculated. By default 6 hours.
       For example: SMOOTHING_DURATION = 5 days, SMOOTHING_INTERVAL = 6 hours creates 5 × 24 / 6=20 calculation steps.
       A smaller interval provides a higher temporal resolution of the transition, while a larger interval creates fewer intermediate points. The interval affects the representation of the transition in the simulation model but does not change the final target flow rate or the preserved planned delivery mass. Together, these parameters allow engineers to adapt the Digital Twin behavior to the required simulation detail while maintaining the fundamental principles of the algorithm:
  • continuous flow transition;
  • preservation of planned delivery mass;
  • realistic interaction with downstream assets.

Impact of Flow Smoothing on Downstream Simulation Accuracy

       Flow smoothing is not intended to replace physical constraints or operational control logic inside a Digital Twin. Its purpose is to provide realistic input data for downstream simulation objects by avoiding artificial changes in feedstock delivery rates. This is especially important for tank farms, which operate as dynamic buffers between production sources and processing facilities. The storage behavior depends on the relationship between:
  • incoming mass flow rate;
  • current residuals;
  • available storage capacity;
  • required withdrawal rate.
This is particularly important in refinery process simulation, where downstream operating decisions depend on predicted feedstock availability.
       Based on the expected incoming flow, the Digital Twin calculates the required withdrawal strategy to maintain stable operation. If the incoming flow profile is unrealistic, the calculated operating decisions may also become incorrect. For example, without flow smoothing, a monthly production plan transition can create an artificial increase in incoming feedstock:
       The tank farm model may interpret this as a real operational change and increase the required withdrawal rate. However, if the actual production system would increase its flow gradually, this decision is based on incorrect information.
       Possible consequences include:
  • incorrect estimation of tank residuals;
  • unnecessary increase of withdrawal rates;
  • artificial tank filling scenarios;
  • false identification of capacity limitations.
       With flow smoothing, the digital twin receives a continuous and realistic feedstock profile. As a result, downstream objects can evaluate their operational behavior based on a more realistic representation of future incoming flows. It is important to note that flow smoothing does not eliminate real operational limitations. If a pipeline, valve, tank farm, or processing unit cannot accept the calculated flow rate, the physical constraints of the Digital Twin model will still limit the actual flow. The smoothing algorithm only ensures that these constraints are evaluated using realistic input conditions.

Flow Smoothing Implementation in Petroleum Refining Library

       In the Petroleum Refining Library (PRL), flow smoothing is implemented within the Source agent, which is responsible for converting production plans into continuous material flows for Digital Twin simulation. The Source agent from database receives production plans defined over discrete planning periods, such as monthly production volumes. These plans are then transformed into continuous mass flow rates that can be used by downstream simulation objects.

       The smoothing mechanism is applied when a transition between planning periods occurs. At this point, the Source agent already has the current actual mass flow rate generated by the simulation and uses it as the starting point for the transition.
       The algorithm then:
  1. Calculates the target mass flow rate from the next production plan.
  2. Creates a linear transition between the current actual flow and the future planned flow.
  3. Applies the transition during the configured smoothing period.
  4. Adjusts the remaining part of the current planning period to preserve the total planned mass.
       Because the Source agent operates within the AnyLogic simulation environment, further limitations are handled by the physical model itself. For example, valves, pipelines, tank farms, and processing units can restrict the actual accepted flow according to their capacity and operating conditions.

Source Code Reference

       The complete Java implementation of the flow smoothing algorithm used in the Petroleum Refining Library (PRL) is available as an implementation appendix.
The source code demonstrates:
  • monthly plan conversion;
  • linear interpolation;
  • mass balance correction;
  • transition scheduling;
  • interaction with the AnyLogic simulation engine.
Typical industrial applications include refinery production planning, crude oil logistics, tank farm simulation, feedstock scheduling, and Digital Twin–based operational optimization.

See SmoothingFlows.java (Java Implementation of the Petroleum Refining Library Flow Smoothing Algorithm)

Conclusion: Why Flow Smoothing Is Essential for Oil and Gas Digital Twins

       Production planning data and dynamic simulation models operate at different levels of detail. Production plans define target mass quantities over a specific period, while Digital Twins must reproduce the continuous behavior of material flows and equipment interactions over time.
       Direct conversion of monthly production plans into constant flow rates can create unrealistic discontinuities at planning boundaries. These artificial changes may affect downstream simulation results, especially for tank farms and other storage systems that rely on predicted incoming flows to determine operational strategies.

       The flow smoothing approach described in this article addresses this challenge by:
  • converting discrete production plans into continuous mass flow representations for continuous flow simulation;
  • preserving the original planned delivery mass balance;
  • maintaining continuity between consecutive planning periods;
  • using the actual current operating flow as the transition starting point;
  • providing realistic input conditions for pipelines, tank farms, and refinery units.
The algorithm is therefore well suited for production planning and feedstock scheduling applications in Digital Twin environments.
       In a Digital Twin environment, accurate flow representation is essential because operational decisions depend not only on total production volumes but also on how these volumes are distributed over time. By applying volume-preserving flow smoothing, oil and gas simulation models can better represent real production behavior, avoid artificial bottlenecks, and provide more reliable analysis of supply chains, storage systems, and refinery operations.

Learn how flow smoothing fits into the complete Crude Oil Supply Chain Simulation workflow.

Related Articles

For readers interested in implementation details, additional resources are available: