Tank Farm Simulation Algorithm for Refinery Digital Twin Models (Limited Receiving Tank Farm Capacity Case)

       The previous article Tank Farm Simulation Algorithm for Refinery Digital Twin Models, presented a control algorithm that stabilizes outlet flow, maintains the target inventory level, and compensates for fluctuations in the incoming stream in digital twins. The discussion assumed that the downstream receiving node always had sufficient available capacity to accept the required outlet flow. In petroleum refining operations, however, available storage may be temporarily limited. The receiving tank farm may be constrained by limited available storage, tanks under maintenance or scheduled transfers. As a result, the maximum outlet flow is no longer determined solely by the flow but also by downstream storage constraints.This fundamentally changes the refinery process simulation problem and the behavior of the Digital Twin. When the required outlet flow exceeds the receiving tank farm capacity, excess flow accumulates in the flowing tank farm, causing inventory growth and potentially triggering overflow protection or upstream production constraints.
       The comparison highlights that the proposed algorithm extends the basic flow smoothing strategy by introducing predictive control based on downstream tank availability. Instead, this article focuses exclusively on the additional challenges introduced by limited downstream receiving tank farm capacity and its impact on flow control in simulation, inventory dynamics, and system behavior.

Problem Formulation

       The previous article assumed that the downstream receiving tank farm always had sufficient capacity to accept the required outlet flow. In practice, however, available storage may be temporarily limited by tank filling, certification, shipment, maintenance, or other operational constraints.
       This article considers a limited receiving tank farm capacity case, where only one tank may receive product and one tank may perform shipment at any time, while each filled tank must complete certification before becoming available for discharge. Under these conditions, the receiving tank farm becomes an active constraint on the pumping rate. Consequently, the algorithm must predict the availability of receiving tanks and adjust the outlet flow to prevent interruptions, excessive inventory growth, and overflow.
       The control objective is no longer to maintain only the target inventory level. The algorithm must maximize continuous product transfer while ensuring that both the source and receiving tank farms remain operationally synchronized. The pumping rate therefore becomes constrained simultaneously by hydraulic limits, source tank availability, and receiving tank availability.

Control Strategy

       Unlike the basic flow smoothing algorithm, this algorithm can no longer determine the outlet flow solely from the current inventory level. The pumping rate must also satisfy downstream storage constraints while ensuring uninterrupted material transfer between the two tank farms. Consequently, the algorithm simultaneously considers:
  • the allowable outlet flow determined by equipment limitations and the possibility of a planned shutdown when downstream receiving capacity becomes unavailable;
  • the availability of a prepared source tank;
  • the availability of a receiving tank capable of accepting the product.
       The control algorithm predicts the future availability of both the source and receiving tank farms and selects the highest outlet flow that can be maintained continuously without interrupting material transfer.

Prediction of Source and Receiving Tank Availability

       Algorithm must account for the future availability of both the source and receiving tank farms. A continuous pipeline transfer is only possible if a prepared source tank is available for discharge and a receiving tank is simultaneously available for filling.
For the source tank farm, the algorithm estimates when the next tank will become available for shipment. The prediction considers the current operating state of each tank, the remaining filling time, the certification period, and the expected completion of ongoing shipment operations. Based on this information, the algorithm determines the maximum outlet flow that can be maintained without interrupting product transfer because of an unavailable source tank. A similar prediction is performed for the receiving tank farm. The algorithm evaluates the operating state of every receiving tank and estimates when the next tank will become available to accept product. This prediction accounts for the completion of ongoing shipment and certification operations, allowing the algorithm to determine the maximum flow that can be accepted without causing transfer interruptions.
The target outlet flow is then selected as the highest flow rate that satisfies both the source and receiving tank availability constraints while remaining within the allowable operating range determined in the previous section.

Target Flow Selection

       The algorithm calculates two independent flow limits. The first is determined by the availability of prepared tanks in the source tank farm, while the second is imposed by the receiving tank farm. To ensure uninterrupted operation, the outlet flow must satisfy both constraints simultaneously. The target outlet flow is therefore selected as the highest flow rate that can be continuously sustained by both tank farms while remaining within the allowable operating range determined by the pumping equipment. If the receiving tank farm becomes the limiting factor, the outlet flow is reduced accordingly, even if additional product is available in the source tank farm. This predictive approach prevents sudden interruptions in material transfer, improves inventory management, minimizes inventory fluctuations, and ensures stable refinery operation despite temporary downstream storage constraints.

Dynamic Flow Control Algorithm

       This section presents a predictive control algorithm for a refinery configuration in which a source tank farm transfers product through a pipeline to a receiving tank farm with limited available storage capacity. Unlike the basic flow smoothing case, the receiving tank farm is treated as an active storage constraint whose availability depends on tank filling, certification, and shipment operations.
       As illustrated, the transfer system consists of three interacting components:
        - the source tank farm (Node 1),
        - the transfer pipeline (Node 2),
        - the receiving tank farm (Node 3).
       The objective of the control algorithm is to determine the outlet flow rate that ensures uninterrupted product transfer while respecting pump limitations and the dynamic availability of both source and receiving tanks. At each control interval, the algorithm predicts the future availability of tanks at both ends of the pipeline and calculates the maximum sustainable outlet flow. This predictive approach prevents unexpected transfer interruptions, minimizes inventory accumulation, and enables controlled pumping rate reduction when insufficient downstream receiving capacity is anticipated.

See Appendix A. Mathematical Model of Flowing Tank Farm Simulation

Step 1. Determine the allowable outlet flow range

       The algorithm calculates the minimum and maximum admissible outlet flow based on pump operating limits and the maximum allowable flow variation during a control interval. This defines the feasible operating range for the current simulation step.

Step 2. Predict source tank availability

       The algorithm evaluates the operating state of each tank in the source tank farm and estimates when the next tank will become available for shipment. Based on this prediction, it determines the maximum outlet flow that can be maintained without interrupting product transfer because of an unavailable source tank.

Step 3. Predict receiving tank availability

       The algorithm analyzes the operating state of the receiving tank farm to estimate when the next tank will become available for filling. The prediction considers filling, certification, shipment, and other operational delays to determine the maximum flow that can be continuously accepted by the downstream system.

Step 4. Calculate the target outlet flow

       The target outlet flow is selected as the highest sustainable flow that satisfies both the source and receiving tank constraints while remaining within the allowable operating range determined in Step 1.

Step 5. Update the output

       The algorithm applies the calculated outlet flow for the current control interval. At the next simulation step, the entire procedure is repeated using the updated tank states and inventory levels.

Numerical Example

       To demonstrate the proposed control algorithm, consider a transfer system consisting of a source tank farm with Q = 3 storage tanks and a receiving tank farm with U = 3 storage tanks connected by a transfer pipeline. Each source tank has a maximum capacity of 17,440 t, while each receiving tank has a maximum capacity of 17,350 t. The certification period is 24 h for the source tank farm and 48 h for the receiving tank farm.
       At the beginning of the simulation, the source tank farm contains one tank under certification, one tank being filled, and one tank under shipment. The receiving tank farm is initialized in a similar manner, with one tank being filled, one under certification, and one under shipment. This configuration represents a realistic refinery operating condition in which tanks continuously alternate between receiving, certification, and transfer operations.
       Figure shows the evolution of the total inventory in both tank farms together with the inlet and outlet flow rates. The algorithm continuously adjusts the outlet flow according to the predicted availability of receiving tanks. When no receiving tank is expected to become available in time, the pumping rate is reduced in advance, preventing an unexpected interruption of material transfer. After the next receiving tank completes certification, the outlet flow is gradually restored while respecting pump capacity and allowable flow variation limits.
       The simulation demonstrates that the proposed predictive algorithm maintains stable product transfer despite temporary downstream storage constraints while supporting realistic refinery production planning and logistics analysis. As shown in Figure, the outlet flow is reduced in advance when downstream storage becomes unavailable, causing temporary inventory accumulation in the source tank farm before gradually returning to its normal operating level.

Practical Considerations

       The proposed algorithm has one practical limitation: it requires frequent recalculations of the outlet flow. In large refinery models, these repeated calculations may reduce simulation performance. To address this issue, Petroleum Refining Library provides in the RpFlowing tank farm agent the configurable parameters dailyCorrectionSteps (Label: Intensity of the recalc, 'Flow Correction' state (times per day)) and dailySteadyFlowSteps (Label: Intensity of the recalc, 'Daily steady' state (times per day)), allowing users to reduce the frequency of recalculations and find a suitable balance between computational performance and control accuracy.
       The proposed algorithm provides a practical compromise between simulation accuracy and computational performance. Users can adjust the recalculation frequency according to the required level of control precision and the complexity of the refinery model, enabling efficient simulation of both small process units and large-scale Digital Twin models.
       Unlike static production planning tools, the algorithm operates as a closed-loop control system. Every calculation depends on the current state of the refinery, allowing the model to respond naturally to fluctuations in production, changing inventory levels, maintenance activities, and transportation constraints. This continuous recalculation enables the Digital Twin to simulate realistic refinery behavior while maintaining material balance, operational stability, and safe equipment operation.

Advantages of Predictive Flow Control

       Unlike conventional inventory-based control, the proposed algorithm considers the future availability of both source and receiving tanks when determining the outlet flow. As a result, control decisions are based not only on the current inventory level but also on predicted downstream operating conditions. This predictive strategy provides several important advantages:
  • prevents flow interruptions caused by unavailable receiving tanks;
  • minimizes unnecessary inventory accumulation;
  • reduces the risk of overflow under downstream storage constraints;
  • maintains smoother outlet flow despite temporary operational restrictions;
  • reduces pump cycling;
  • improves refinery logistics planning;
  • supports production scheduling;
  • supports refinery Digital Twin development;
  • improves optimization model accuracy;
  • improves the stability and realism of refinery Digital Twin simulations.
       These capabilities improve process optimization, refinery logistics, and storage-constrained production planning while preserving realistic process dynamics. By incorporating operational constraints directly into the control logic, the algorithm reproduces the behavior of industrial tank farms more accurately than conventional inventory control approaches.

Implementation in Petroleum Refining Library

       The Petroleum Refining Library (PRL) implements the flowing tank farm as an intelligent simulation component that continuously regulates outlet flow while maintaining material balance and satisfying operational constraints. The RpFlowing component is fully integrated with PRL, enabling realistic simulation of refinery storage, product transfer, and oil and gas logistics. During simulation, the component automatically selects the appropriate operating mode based on inventory level, inlet flow conditions, downstream availability, and equipment constraints.
       Key features include:
        - automatic or manual outlet flow control;
        - adaptive operating mode management;
        - continuous inventory and material balance calculations;
        - pump and pipeline capacity constraints;
        - configurable flow rate adjustment limits;
        - overflow prevention and controlled pumping-down;
        - equipment maintenance modeling;
        - integrated operational performance indicators (KPIs).
       These capabilities enable Petroleum Refining Library to reproduce realistic refinery storage and transfer operations while supporting production planning, refinery logistics, Digital Twin development, and process optimization without the need for custom control logic.

Industrial Applications

       The proposed predictive flow control algorithm is applicable to a wide range of refinery storage and transfer operations, including crude oil transfer between tank farms and process units, intermediate product storage, blending systems, and product dispatch terminals. It is particularly valuable in refinery Digital Twin models where temporary storage constraints directly influence production continuity, logistics, and production planning.

Conclusion

       The proposed control algorithm extends the basic flow smoothing strategy by incorporating downstream storage constraints into the control process. Unlike conventional inventory-based control, the algorithm predicts the future availability of both source and receiving tanks, allowing it to adjust the outlet flow before interruptions occur.
Together with the basic flow smoothing algorithm presented in Part 1, the proposed predictive control strategy provides a comprehensive framework for realistic refinery tank farm simulation under both unconstrained and storage-constrained operating conditions. These algorithms form the basis of the RpFlowing component implemented in the Petroleum Refining Library for AnyLogic. Together, they enable realistic simulation of refinery storage, transfer operations, and production planning under a wide range of operating conditions.

Related Articles and Appendix

FAQ

1 What is limited receiving tank farm capacity?
Limited receiving tank farm capacity is an operating condition where the downstream tank farm cannot continuously accept the required product flow because of storage limitations, certification procedures, maintenance activities, or sequential tank operations.

2 Why is receiving tank capacity important in refinery simulation?
Receiving tank capacity directly affects material flow, inventory dynamics, and production continuity. Ignoring these constraints can produce unrealistic Digital Twin behavior and overestimate refinery throughput.

3 How does the control algorithm prevent flow interruptions?
The algorithm predicts the future availability of both source and receiving tanks and adjusts the outlet flow before transfer interruptions occur. This predictive strategy maintains stable operation while respecting storage constraints.

4 Can this algorithm simulate certification delays?
Yes. The algorithm considers tank certification as one of the operating states that determine when a tank becomes available for shipment or product reception.

5 Is the algorithm suitable for AnyLogic refinery Digital Twins?
Yes. The algorithm is designed for dynamic refinery Digital Twin models developed in AnyLogic and can be integrated with tank farm, pipeline, and process unit simulations.

6 Does the algorithm support multiple receiving tanks?
Yes. The algorithm evaluates the operating state of every receiving tank and predicts when the next tank will become available, allowing continuous operation under sequential tank management.