Tank Farm Simulation Algorithm with Unlimited Receiving Capacity

       Modern refineries rarely operate under perfectly steady conditions. Digital Twin refinery simulation model of logistics requires stable material flow despite continuously changing production conditions. Feedstock production changes throughout the day, process units adjust their throughput, maintenance activities temporarily reduce capacity, and downstream facilities continuously modify product demand. As a result, flow rates throughout the refinery constantly fluctuate. Without an effective buffering mechanism, these fluctuations propagate across the entire production chain. A temporary increase in upstream production can overload downstream units, while a sudden decrease may force expensive process slowdowns or even equipment shutdowns. The larger and more integrated the refinery, the more critical stable material flow becomes.
A tank farm is far more than a storage facility. In modern petroleum refining, it acts as a dynamic buffer and control element that absorbs flow disturbances, maintains inventory within safe operating limits, and delivers a stable outlet flow despite continuously changing inlet conditions.See how inventories influence the feasible product slate.
This capability is especially important in simulation models, where realistic simulation of storage dynamics directly affects production planning, refinery logistics, equipment utilization, and process optimization.
Learn more about digital twin simulation in petroleum refining.
Treating a tank farm as a passive storage node often produces unrealistic simulation results and inaccurate operational forecasts. This is one of the key differences between steady-state simulation and dynamic refinery simulation used in simulation software.
This article explains how tank farm refinery simulation model can represent dynamic inventory behavior, automatic flow regulation, and operational constraints in refinery Digital Twins in Anylogic. It also describes the control optimization algorithm implemented in the Petroleum Refining Library (PRL), where a flowing tank farm continuously adjusts its operating mode according to process conditions while maintaining material balance and operational stability.
The limited receiving capacity case is discussed in Limited Receiving Tank Farm Capacity in Refinery Digital Twin Models.

Why Traditional Tank Farm Models Are No Longer Sufficient?

       Many simulation models still represent a tank farm as a simple storage vessel with a fixed inventory balance:

Inventory = Previous Inventory + Inlet Flow − Outlet Flow

This equation is discussed in more detail in Material Balance in Refinery Simulation.
       Although mathematically correct, this simplified approach ignores the operational reality of refinery tank farms. In practice, outlet flow cannot change instantaneously. Pumping systems have minimum and maximum capacities, pipelines impose allowable ramp rates, and operators intentionally maintain inventory around a target level to provide sufficient buffer capacity for unexpected process disturbances. Maintenance activities, emergency shutdowns, and temporary interruptions in downstream transportation further complicate daily operation.
       As a consequence, the tank farm itself becomes an active participant in refinery process control rather than a passive storage location. A realistic digital twin must therefore simulate not only inventory accumulation but also operational decision-making.

       At every refinery simulation model step, the model should determine:
        - whether inventory remains within safe operating limits;
        - whether outlet flow should increase or decrease;
        - whether pump capacity constraints are satisfied;
        - whether flow-rate changes exceed allowable ramp limits;
        - whether the facility should switch to another operating mode, such as flow correction, steady flow, overflow protection, or pumping down.

What Is a Flowing Tank Farm?

       A flowing tank farm is a storage system designed not only for temporary product accumulation but also for continuous regulation of flow between interconnected refinery processes. Flowing tank farms are widely used in petroleum refining, crude oil transportation, pipeline logistics, and condensate processing.
Unlike traditional storage facilities like accumulative tank farms, where tanks are primarily used for receiving, storing, blending, and shipping products in separate operational stages, a flowing tank farm continuously receives and dispatches flows at the same time. The stored inventory acts as a dynamic buffer that absorbs short-term flow fluctuations while maintaining stable downstream operation.
This operating principle is widely used in oil and gas processing, particularly for crude oil, stabilized condensate, intermediate refinery streams, and finished petroleum products transported through pipelines. The objective is not to maximize storage utilization but to ensure uninterrupted production and stable process conditions.
Instead of functioning as passive storage, the tank farm becomes an active element of the refinery control system. It continuously compensates for differences between incoming and outgoing flow rates while maintaining inventory within predefined operating limits.

The Equivalent Tank Model

       Although an industrial tank farm may consist of dozens of physical tanks, pipelines, pumps, and valves, its dynamic behavior can often be represented by a single equivalent storage model. Instead of simulating every individual tank, the digital twin tracks the total inventory stored within the facility. The equivalent inventory changes according to the material balance:

Inventory = Previous Inventory + Inlet Flow − Outlet Flow

Material balance alone cannot reproduce process dynamics, real-time inventory control, or flow smoothing, all of which are essential for refinery Digital Twins in Anylogic. This abstraction dramatically simplifies simulation while preserving the operational behavior that is most important for production planning and process optimization. The same modeling approach is commonly applied in large-scale refinery simulation, process optimization, and production scheduling. It also allows the same control optimization algorithm to represent facilities of very different sizes without increasing model complexity. For a detailed explanation of flowing tank farm operation, see flowing tank farm control

Target Inventory Instead of Maximum Storage

       One of the most important differences between a flowing and an accumulative tank farm is the operating objective.
Traditional storage facilities often aim to maximize available inventory while ensuring sufficient capacity for future deliveries.
A flowing tank farm follows a different strategy.
       Its objective is to maintain inventory close to a predefined target level that provides sufficient flexibility for both unexpected increases in inlet flow and temporary interruptions of downstream transportation. The target inventory concept is explained further in smoothing in refinery simulation. If inventory becomes too low, the system loses its ability to compensate for supply interruptions. If inventory becomes too high, the available buffer capacity decreases and the risk of overflow increases. For this reason, the algorithm continuously regulates outlet flow to keep inventory near the target operating level while respecting equipment limitations and operational constraints. Maintaining the target inventory significantly improves inventory optimization, storage utilization, and refinery logistics planning. This dynamic inventory control forms the foundation of realistic tank farm simulation and enables Digital Twin models to reproduce the behavior of real refinery operations with much higher accuracy than static inventory calculations.

Operating Modes of a Flowing Tank Farm

       A flowing tank farm continuously evaluates its operating conditions and automatically selects the most appropriate control strategy. This finite-state algorithm enables realistic process control simulation and automatic operating mode selection. Rather than operating with a fixed outlet flow, it adapts its behavior according to the current inventory level, inlet flow rate, equipment constraints, and downstream operating requirements.
       In the Petroleum Refining Library (PRL) as an AnyLogic library , the tank farm operates as a finite-state algorithm that switches between several operating modes. Each mode is designed to solve a specific operational problem while maintaining material balance and ensuring safe refinery operations.
For more details, see here

Intelligent State Transitions

       The operating modes described above are not selected manually. Instead, the algorithm continuously evaluates process conditions and automatically switches between states whenever operating criteria change. This state-based control architecture allows the Digital Twin to respond naturally to changing refinery conditions while preserving stable operation and maintaining realistic equipment behavior. Rather than relying on fixed operating rules, the tank farm behaves as an adaptive control system capable of balancing production, storage, and transportation under continuously changing process conditions.

Dynamic Flow Control Algorithm

       This section presents a dedicated control algorithm for calculating the smoothed outlet flow rate in a typical refinery configuration where N upstream process units (Plants) discharge their product into a common flowing tank farm, which subsequently feeds the downstream transfer pipeline. The algorithm represents a practical implementation of dynamic process control within refinery Digital Twins. The objective is to determine the outlet flow while accounting for the limited pumping capacity, maintaining a smooth outlet pumping profile, and ensuring that the tank farm inventory remains within its allowable operating limits without overflowing. The algorithm therefore calculates the outlet flow at each control interval so that hydraulic and operational constraints are satisfied while ensuring stable downstream operation.
       As illustrated in example Figure below, the flowing tank farm is located between several upstream production units generating variable product flows and the downstream processing facilities connected by the transfer pipeline. Since the downstream refinery is capable of processing significantly larger volumes than the tank farm can store, the tank farm serves as a short-term hydraulic buffer rather than a long-term storage facility.
       The control algorithm therefore determines the outlet flow Vout(t) at every control interval to keep the inventory close to its target operating level while smoothing fluctuations of the combined inlet flow Vin(t), preventing overflow or depletion, and satisfying all equipment and operational constraints. The runtime operating logic is explained in flowing tank farm control

Operational Constraints in Tank Farm Simulation

       A realistic tank farm refinery simulation model must consider much more than material balance. Every outlet flow adjustment is constrained by equipment capabilities, operating procedures, and safety requirements. Ignoring these constraints may produce mathematically correct but physically infeasible results. Therefore, before updating the outlet flow, the Digital Twin evaluates the following operational constraints:
       1 Material Balance. Inventory changes according to the difference between the inlet and outlet flows. Although straightforward, maintaining material balance becomes challenging when all operational constraints must be satisfied simultaneously.
       2 Inventory Operating Limits. The tank farm operates within predefined minimum and maximum inventory levels. The minimum inventory protects downstream operation during supply interruptions, while the maximum inventory provides buffer capacity to absorb production increases and prevent overflow. Within these limits, inventory is maintained near a target level.
       3 Pump Capacity Constraints. The outlet flow must remain within the available pumping capacity. The allowable operating range depends on the available pumps and may change because of maintenance or equipment availability.
       4 Flow Ramp Rate Limits. The outlet flow cannot change instantaneously. The maximum rate of flow increase or decrease is limited to ensure smooth pump operation and avoid hydraulic disturbances.
       5 Pipeline Constraints. The downstream pipeline may further restrict the achievable outlet flow because of hydraulic resistance, operating pressure, or other pipeline characteristics. These constraints are evaluated together with pump and inventory limits.
       6 Tank Breathing Constraints. Excessively rapid changes in pumping rate may cause equally rapid pressure variations inside storage tanks, exceeding the normal breathing capacity of the tank venting system. Limiting the rate of outlet flow variation helps maintain stable pressure conditions, reduces mechanical stress on the tanks, and improves the realism of the simulation.
       Only after all constraints have been verified is a new outlet flow accepted. The control algorithm integrates production planning, inventory management, pipeline transportation, and equipment constraints into a unified Digital Twin model.

Step 1. Collect Current Operating Data

       The control cycle begins by reading the current process variables from the simulation model. These include:
       - total inlet flow from all upstream sources;
       - current outlet flow;
       - total inventory stored in the tank farm;
       - operating mode;
       - pump availability and constraints;
       - pipeline constraints.
       cause all calculations are performed using the current process state, algorithm continuously adapts to changing refinery conditions without requiring predefined operating schedules.

Step 2. Determine the Operating Mode

       Next, the algorithm determines which operating mode should be active.
The decision primarily depends on two factors:
  • current inventory level;
  • relationship between inlet and outlet flow.
This operating mode determines which control strategy will be used during the current calculation cycle. For example:
  • inventory close to the target activates steady flow mode;
  • significant inventory deviation activates flow correction mode;
  • inventory approaching the maximum limit activates overflow protection mode;
loss of inlet flow activates pumping down mode.

Step 3. Calculate the Allowable Outlet Flow Range

       Rather than immediately selecting a new outlet flow, the algorithm first determines the range of physically feasible operating conditions by evaluating all applicable constraints, including pump capacity limits, inventory limits, maximum outlet flow ramp rate, and tank breathing constraints. The intersection of these constraints defines the feasible operating range for the outlet flow, ensuring realistic process simulation and safe refinery operation.

Step 4. Calculate the Preferred Outlet Flow

       Once the allowable range has been established, the algorithm determines the preferred outlet flow. Its objective is simple: move the inventory toward the target level as efficiently as possible. If the inventory is above the target, the algorithm generally increases the outlet flow, whereas if the inventory is below the target, it reduces it. At the same time, the outlet flow is constrained to change gradually, ensuring a smooth pumping profile that complies with pump operating limits and preventing abrupt transitions to zero flow when the tank farm becomes depleted. However, the preferred value is only accepted if it satisfies all operational constraints calculated in the previous step. Otherwise, the closest feasible min or max value is selected. This approach ensures that every control decision remains physically achievable.

Step 5. Handle Exceptional Operating Conditions

       Certain operating situations require additional control logic beyond normal inventory regulation. One important example is the sudden loss of inlet flow. If plants flow production unexpectedly stops, maintaining a high outlet flow could rapidly empty the tank farm and interrupt downstream operation. Instead, the algorithm gradually reduces the outlet flow while respecting the maximum allowable ramp rate. The stored inventory is therefore used strategically to extend downstream operation for as long as possible while gradually decreasing the outlet flow to the minimum allowable pumping rate, ensuring a smooth transition instead of an abrupt drop to zero flow.
       An optional risk-aware constraint may also be applied. If the inlet flow suddenly becomes zero, the outlet flow must not be so high that the algorithm cannot reduce it to the minimum pumping rate before the available inventory is exhausted. To prevent this situation, the algorithm can proactively limit the maximum outlet flow, ensuring that a feasible deceleration trajectory always exists. This additional constraint improves operational robustness but slightly reduces maximum pumping capacity. Alternatively, it may be disabled to maximize throughput while accepting a higher risk of abrupt flow interruption.

Step 6. Update the Digital Twin

       After the outlet flow has been determined, the Digital Twin updates the material balance. The new inventory is calculated using the current inlet flow, outlet flow, and simulation time step. These updated values become the starting point for the next control cycle. Because this procedure is repeated throughout the simulation, the Digital Twin continuously reproduces the dynamic interaction between production, storage, transportation, and process control.

Numerical Example

       Consider a flowing tank farm with constant inlet flow Vin(t)=548t/h, initial inventory S(0)=5 090t and target inventory Sg=3 533t. The example illustrates the behavior of the Digital Twin during automatic flow control under changing operating conditions.
  • During t ∈ [1,22] h the tank farm operates in state Flow Correction (inventory correction).
  • During t ∈ [1,9] h the outlet flow Vout(t) is gradually increased, which causes the inventory S(t) to decrease. When Vin(t)=Vout(t) (from t ≈ 9h), the inventory stabilizes near the target level and the system transitions to state Steady Flow (support).

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 tarm 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. 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.
The digital twin used to generate the simulation training datasets is described in detail in Tank Farm Simulation Algorithm for Refinery Digital Twin Models (Part 2: Limited Receiving Tank Farm Capacity Case), which explains the flowing tank farm control algorithm and its operational constraints.

Operational Benefits

       The simulation demonstrates several important advantages of dynamic flow control. Compared with a passive storage model, the flowing tank farm:
  • reduces outlet flow fluctuations;
  • maintains inventory near its target level;
  • prevents overflow and inventory depletion;
  • minimizes abrupt pump operating changes;
  • improves downstream process stability;
  • increases operational flexibility during production disturbances;
  • supports more accurate production planning and refinery logistics.
       These benefits become increasingly important in large integrated refineries, where even small flow disturbances can propagate through multiple process units and significantly affect overall plant performance. These improvements directly increase the accuracy of refinery optimization, logistics simulation, and production scheduling.

Why This Matters for Digital Twins?

       A Digital Twin is expected to reproduce the behavior of the physical refinery as accurately as possible. If the tank farm is represented only as a static storage vessel, the model cannot predict the dynamic interaction between inventory, production, pumping systems, and downstream demand. By incorporating automatic flow control and operational constraints, the Digital Twin captures the true role of the tank farm as an active process control element rather than a passive storage facility. This enables engineers to evaluate operational strategies, optimize production schedules, analyze equipment limitations, and assess refinery performance under realistic operating conditions.
       The Digital Twin is not only used for simulation. It also provides the operational data required for production planning, scheduling, refinery optimization, and what-if analysis. Because the flowing tank farm continuously predicts future inventory and outlet flow, planners can evaluate alternative operating strategies before implementing them in the real refinery.

Implementation in Petroleum Refining Library

       The Petroleum Refining Library (PRL) implements a flowing tank farm as an intelligent simulation component that continuously regulates outlet flow while maintaining material balance and respecting operational constraints. RpFlowing AnyLogic simulation component is fully integrated with the Petroleum Refining Library, supporting complete refinery process simulation and oil and gas logistics modeling. The flowing tank farm automatically switches between operating modes depending on the current process conditions, including inventory level, inlet flow, and equipment availability.
       Key features include:
        - automatic or user-controlled outlet flow;
        - automatic operating mode selection;
        - inventory tracking and material balance;
        - pump and pipeline constraints;
        - configurable flow ramp limits;
        - overflow protection and pumping-down logic;
        - maintenance simulation;
        - built-in operational KPIs.
       By combining automatic flow control with operational constraints, Petroleum Refining Library enables accurate simulation of production planning, refinery logistics, and process optimization without requiring users to implement custom control algorithms.

Benefits of Flowing Tank Farm Simulation

       Modeling a tank farm as an active flow control system provides a much more realistic representation of refinery operations than treating it as passive storage. By continuously balancing inlet flow, outlet flow, and inventory, the digital twin captures transient operating conditions that significantly influence production planning and refinery performance.

The main advantages include:
        - smoother downstream flow despite fluctuating upstream production;
        - improved inventory utilization;
        - reduced risk of overflow and inventory depletion;
        - realistic representation of pump and pipeline limitations;
        - support for maintenance and equipment availability analysis;
        - more accurate production planning and refinery logistics;
        - improved digital twin fidelity for operational decision-making.
       These capabilities allow engineers to evaluate operating strategies before implementation, identify potential bottlenecks, and optimize refinery performance under changing production conditions.

Conclusion

       A flowing tank farm is not simply a storage facility. It is an active control system that dynamically balances production, transportation, and inventory. By combining material balance, automatic flow regulation, operational constraints, and finite-state control logic, the Digital Twin reproduces the real behavior of refinery storage systems and provides a reliable foundation for production planning, logistics optimization, and operational decision support. The proposed approach combines tank farm simulation, Digital Twin technology, dynamic process simulation, inventory optimization, production planning, process control, flow smoothing, refinery logistics, and AnyLogic simulation into a unified engineering framework for modern petroleum refining and oil and gas applications.

Related Articles and Appendix

FAQ

1 What is a flowing tank farm?
A flowing tank farm is a storage system that continuously receives and dispatches material while automatically regulating outlet flow to stabilize downstream refinery operation.

2 Why is tank farm simulation important?
Tank farm simulation allows engineers to predict inventory changes, evaluate flow control strategies, prevent operational bottlenecks, and improve production planning before changes are implemented in the real refinery.

3 How does a Digital Twin model a tank farm?
A Digital Twin combines material balance, inventory dynamics, operational constraints, and automatic flow control to reproduce the behavior of a real tank farm under changing operating conditions.

4 Why is flow smoothing important?
Flow smoothing reduces the impact of upstream production fluctuations on downstream process units, improving operational stability and reducing unnecessary equipment adjustments.

5 Can Petroleum Refining Library automatically control outlet flow?
Yes. Petroleum Refining Library supports automatic outlet flow calculation based on inventory level, inlet flow, equipment constraints, and operating mode. Manual outlet flow control is also available for scenario analysis and testing.