AI-Based Tank Farm Control for Refinery Digital Twin Models

Introduction

       Refinery digital twins accurately simulate the dynamic behavior of refinery tank farms and support refinery process optimization, production planning, and operational decision support. This limits their use for real-time operational decision support. A practical solution is to combine simulation with artificial intelligence. A neural network is trained using simulation-generated data produced by the digital twin, creating an AI surrogate model for real-time refinery optimization. The digital twin provides high-fidelity training data, while the AI model delivers near-instant decisions for real-time control and optimization. The proposed workflow is implemented using the Petroleum Refining Library for AnyLogic. The simulation model automatically generates synthetic datasets that are subsequently used for neural network training.
       This article presents an AI-assisted approach for controlling flowing tank farms, where a trained neural network complements the digital twin by accelerating pumping control and operational decision-making.

AI-Assisted Pumping Control

       The objective is to determine an optimal outlet pumping rate for tank farm optimization while maintaining stable refinery operation. The control algorithm must maintain stable operation, prevent tank overflow or depletion, and compensate for fluctuations in the inlet flow while satisfying operational constraints.
       Instead of repeatedly executing the complete digital twin, a neural network is trained to approximate its behavior. The training dataset is created automatically by the simulation model under thousands of operating scenarios, including normal operation and critical conditions. As a result, the trained model reproduces the control strategy of the digital twin while producing predictions within milliseconds.
       The neural network receives the current operating state and predicts the recommended pumping strategy for real-time process control and operational optimization. This enables real-time operational decision support without sacrificing the accuracy provided by the digital twin.

Why Train AI Using a Digital Twin?

       Unlike conventional machine learning, refinery operating data collected from industrial process control systems rarely covers the full range of possible operating conditions. Critical events such as tank overflow, equipment shutdowns, emergency flow changes, or abnormal production scenarios occur infrequently and are therefore poorly represented in historical plant data. Moreover, collecting and labeling large volumes of real refinery data is often expensive, time-consuming, and may disrupt normal plant operation.
       A refinery digital twin overcomes this limitation by automatically generating virtually unlimited synthetic operating scenarios while strictly preserving material balance, process constraints, and refinery operating logic. Both normal production and rare emergency situations can be simulated repeatedly under controlled conditions without disrupting plant operation.
       As a result, the neural network is trained on physically consistent and fully labeled data rather than incomplete or noisy historical measurements. The trained AI model learns the control strategy embedded in the digital twin and can later reproduce its decisions within milliseconds, providing reliable real-time operational decision support while maintaining engineering consistency.

Training the Neural Network

       The neural network is trained entirely on data generated by the refinery digital twin. Thousands of simulation runs are performed by varying initial tank inventory, inlet flow profiles, and outlet pumping conditions. For each operating scenario, the digital twin records the corresponding control decisions and system response, forming the training dataset. Unlike plant measurements, simulation-generated data can include rare and critical operating conditions that are difficult or impossible to observe during normal refinery operation. This enables the neural network to learn both routine and emergency operating strategies while preserving the control logic embedded in the digital twin. Once trained, the neural network acts as an AI surrogate model for the refinery digital twin, providing rapid predictions for process optimization.

Performance Evaluation

       The neural network accurately predicts pumping strategies across a broad spectrum of operating conditions, including fluctuating inlet flow rates, varying tank inventory levels, and different process configurations. The model also demonstrated excellent generalization when tested on previously unseen operating scenarios, confirming that it learned the underlying control behavior rather than simply memorizing the training data. Because the surrogate model requires only minimal computational resources, thousands of operating scenarios can be evaluated in a fraction of the time required by conventional dynamic simulation. This combination of high prediction accuracy, low inference latency, scalability, and robust performance under both normal and abnormal operating conditions makes AI-assisted control a practical complement to refinery digital twins for real-time optimization and operational decision support.

Example: Using a Digital Twin to Train an AI Pumping Controller

       To demonstrate the proposed workflow, a neural network was trained to evaluate and predict pumping strategies for a flowing tank farm. Instead of relying on historical refinery measurements, the training dataset was generated automatically by the refinery digital twin. Thousands of operating scenarios were simulated by varying the initial tank inventory, inlet flow profile, outlet pumping rate, and operating conditions. Each simulation produced a fully labeled training sample containing the current operating state together with the corresponding control decision generated by the digital twin. Because the simulation preserves material balance and all operational constraints, every generated sample is physically consistent and suitable for AI model training.
       Unlike conventional datasets collected from industrial operation, the simulation dataset intentionally included both routine production and rare operating conditions such as rapidly changing inlet flows, low inventory levels, and situations approaching storage capacity limits. This significantly improves the robustness and generalization capability of the neural network.
       After training, the AI model reproduced the pumping decisions of the digital twin with high accuracy while producing predictions within milliseconds. As a result, thousands of alternative operating scenarios can be evaluated almost instantly, making the trained neural network suitable for real-time operational decision support without repeatedly executing the complete refinery digital twin.

       Simulation of multiple operating scenarios using the digital twin made it possible to generate the dataset required for neural network training (a fragment of the dataset is shown below). A planning horizon of one month (T) was adopted. In total, the digital twin generated 10,000 feature vectors for neural network training and 500 additional vectors for model validation. Each feature vector contained the initial tank inventory S(0), the initial outlet pumping rate Vout(0), the time-dependent inlet flow profile Vin(t), t ∈ [1, T], and the feasibility assessment of the pumping plan. The neural network was trained using the standard backpropagation algorithm.
The Figure below shows the relative error of the neural network during training. For illustration purposes, the training process was performed over 500 epochs. The trained neural network achieved an accuracy of more than 95% when predicting the feasibility of pumping plans generated for the flowing tank farm.
       After training, the neural network was evaluated using several performance metrics. The mean absolute error (MAE) was 0.10, while the root mean square error (RMSE) of the plan feasibility prediction was ±0.0215. The maximum prediction error did not exceed 0.975 for any evaluation sample.
As shown in Table, the neural network accurately predicts the feasibility of pumping plans for gas condensate and unstable gas condensate. Once the input variables are updated, the AI model produces predictions almost instantaneously, enabling real-time evaluation of pumping plan feasibility without repeatedly executing the full digital twin simulation.

Conclusion

       Artificial intelligence significantly extends the capabilities of refinery digital twins, enabling AI-assisted process optimization, real-time operational decision support, and intelligent production planning. Instead of replacing simulation, the trained neural network complements the digital twin by reproducing its control strategy with minimal computational cost.
       The proposed approach enables real-time pumping control, rapid evaluation of operating scenarios, and improved operational flexibility while preserving the accuracy of the underlying simulation model. This hybrid approach combines the engineering accuracy of physics-based simulation with the computational efficiency of artificial intelligence, providing a practical foundation for next-generation refinery digital twins.

Related Articles and Appendix

FAQ

1 What is AI-based tank farm control?
AI-based tank farm control uses machine learning models trained on refinery digital twins to predict optimal pumping rates, maintain stable tank inventory, and support real-time operational decision making.

2 Why use a neural network instead of a digital twin?
A digital twin provides highly accurate simulation but may require significant computation time. A trained neural network reproduces the behavior of the digital twin within milliseconds, making it suitable for real-time applications.

3 How is the neural network trained?
The neural network is trained using thousands of operating scenarios generated by the refinery digital twin. The simulation produces labeled data covering both normal and abnormal operating conditions that would be difficult to obtain from a real refinery.

4 Can AI replace a refinery digital twin?
No. The digital twin remains the primary engineering model. AI complements it by acting as a surrogate model for rapid prediction and operational decision support.

5 What are the benefits of AI-assisted pumping control?
The approach enables faster control decisions, real-time evaluation of operating scenarios, reduced computational requirements, improved pumping optimization, and more efficient refinery operation.

6 Can this approach be integrated with AnyLogic?
Yes. AI models can be trained using simulation data generated by AnyLogic-based refinery digital twins and then integrated into the simulation workflow to accelerate control and optimization tasks.