TankFarmContainer: Unified Modeling and Statistics for Complex Tank Farms in AnyLogic

Why Complex Tank Farms Require a Container

       In tank farm simulation in AnyLogic, a single physical storage facility does not always correspond to a single logical TankFarm agent. Different groups of tanks within the same facility may store different products or follow independent operating rules.
       Multiple products. A physical tank farm may store several crude oil grades in separate tanks. For example, three tanks may contain one crude grade and two others another. Modeling these groups as separate TankFarm agents preserves product segregation and independent operation, while allowing their outgoing streams to be combined downstream.
       Different operating rules. Tanks within the same facility may have different certification periods, operating schedules, or storage and discharge procedures. Separate TankFarm agents allow each group to maintain its own configuration and lifecycle.
In both cases, the simulation needs to preserve the independence of the underlying tank farms while representing them as one physical facility. The TankFarmContainer agent addresses this requirement. It groups multiple independent tank farms into a unified visual structure and aggregates their statistics without changing their operational logic.

What Is TankFarmContainer in Petroleum Refining Library?

       TankFarmContainer is a dedicated AnyLogic agent in Petroleum Refining Library that provides a unified representation of multiple independent TankFarm agents. It acts as a facility-level abstraction, allowing several tank farms to be displayed and monitored as a single storage facility while preserving their individual configurations, operational rules, and lifecycles. A TankFarmContainer can include any number of tank farms. Although accumulative and flow-through tank farms can technically coexist within the same container, facilities typically group tank farms of the same type. The agent provides two main capabilities:
  • Unified visualization: tanks from multiple tank farms are presented as parts of a single physical facility.
  • Aggregated statistics: operational data from the included tank farms is consolidated through the TankFarmContainerStatistics class.
       Crucially, the container does not control or coordinate the operation of its constituent tank farms. Each TankFarm continues to execute its own operational logic independently. The container simply provides a common representation and a consolidated statistical view. This architecture separates the modeling of individual storage processes from the representation of the physical facility, making complex refinery tank farm models easier to structure and monitor.

Aggregated Statistics with TankFarmContainerStatistics

       While TankFarmContainer provides a unified representation of multiple tank farms, TankFarmContainerStatistics makes their operational data available at the facility level. The statistics class aggregates data from the currently configured TankFarm agents and provides five main groups of statistics:
  • Input – combined incoming flows, including accepted, residual, and removable flows. It also provides information about incoming requests for accumulative tank farms.
  • Output – aggregated outgoing product flows and losses, with support for product-specific flow reporting.
  • TankLevels – combined tank loads, fill levels, active tank counts, and available storage. Fill ratios are calculated using the combined loads and capacities rather than averaging individual tank farm percentages.
  • Capacity – total storage capacity of all tank farms in the container.
  • UnacceptedFlows – aggregated incoming flows that could not be accepted by the tank farms.
       The API also supports formatted reports, product-based flow queries, and checks for flow and product availability. Statistics from individual tank farms can be displayed separately or combined into facility-level totals. All values are aggregated across the linked tank farms before rounding, preserving the accuracy of combined results. Importantly, the statistics are calculated from the current configuration of the container. This allows the aggregated view to reflect changes in the set of linked tank farms without introducing a separate synchronization or control mechanism.

Aggregated Input and Output Flow Statistics

       TankFarmContainerStatistics provides a unified view of material flows across all tank farms in the container. The Input, Output, and UnacceptedFlows providers expose incoming and outgoing flow data, including product-level values and formatted reports.
       Input Flow Statistics
       The Input provider combines incoming flow statistics from all linked tank farms, including:
  • Accepted incoming product flows.
  • Residual flows.
  • Removable flows.
       It supports total flow calculations, product-specific queries, and checks for residual flow availability and connectivity.
For accumulative tank farms, the API can also report the status of the current incoming request, including the request label, dispensed mass, planned mass, and completion percentage.

       Output Flow Statistics
       The Output provider aggregates outgoing product flows and losses across all linked tank farms. It supports total output calculations, product-specific flow queries, and separate loss reporting. Losses are included in the combined output report and counted once for each tank farm. This ensures that the facility-level report accounts for both product streams and material losses.

       Unaccepted Incoming Flows
       The UnacceptedFlows provider combines incoming flows that could not be accepted by the linked tank farms. This information helps identify rejected material and assess storage constraints at the facility level.

       Product-Level Aggregation and Reports
       Flow statistics can be queried by product ID or by an AnyLogic Fluid Library FluidBlock. The API also provides methods to retrieve connected products and check whether a particular product has an active flow. When several tank farms report flows for the same product, their values are combined into a single product entry. The aggregation preserves the order in which products first appear in the configured tank farms. Formatted reports can display individual tank farm results, product-level totals, and a facility-wide grand total. Additional labels and visibility settings allow reports to be adapted to the model's presentation requirements. All flow values are accumulated before rounding, ensuring that the combined statistics remain consistent with the underlying tank farm data.

Tank Levels and Storage Capacity Aggregation

       The TankLevels provider aggregates storage data across the container, including total load, active tank load, available storage, minimum fill level, and overall fill level. The overall fill level is calculated as the ratio of combined tank loads to their corresponding combined capacities, rather than as an average of individual tank farm percentages. This ensures that larger and smaller parks contribute proportionally to the result. Tank-level statistics account for tank operating states and exclude reserve or inactive tanks where appropriate. Direct-flow tank farms are excluded because they do not represent conventional storage. The Capacity provider calculates the total capacity of all linked tank farms, including reserve and Direct Flow parks. Therefore, total configured capacity and currently available storage are treated as separate metrics.

Using Aggregated Tank Farm Statistics in AnyLogic Refinery Simulation

       The TankFarmContainerStatistics class provides a unified API for tank farm simulation in AnyLogic, allowing model developers to access aggregated operational data from multiple storage facilities within a refinery simulation model. It eliminates the need to manually collect and combine statistics from individual TankFarm agents. The API supports numerical queries for incoming and outgoing flow rates, product-specific flows, material losses, tank loads, fill levels, active tank counts, and available storage capacity. These tank farm performance metrics help analyze refinery storage operations, monitor material flows, and evaluate storage utilization in complex petroleum refining simulation models. Formatted reports provide detailed tank farm statistics, including individual storage facility results, product-level totals, and aggregated facility performance. This unified data access supports operational monitoring, production planning analysis, and the development of oil and gas digital twin applications in AnyLogic. Statistics are retrieved from the currently linked tank farms, ensuring that aggregated results reflect changes in the container composition. The API is intended for refinery performance analysis, visualization, and reporting rather than controlling or coordinating individual tank farm operations.

Conclusion

       TankFarmContainer extends tank farm simulation in AnyLogic by providing a unified representation of complex storage facilities composed of multiple independent TankFarm agents. Its key capabilities include:
  • Unified visualization of multiple tank farms as one physical facility.
  • Aggregated statistics for input and output flows, losses, tank levels, and capacity.
  • Product-specific reporting with support for product IDs and AnyLogic FluidBlock objects.
  • Independent operation of each tank farm, preserving its own configuration, operating rules, and lifecycle.
       By separating operational logic from facility-level representation and reporting, TankFarmContainer makes complex refinery storage systems easier to structure, monitor, and analyze without introducing additional control mechanisms.
This approach supports more flexible and maintainable petroleum refining simulation models in AnyLogic.

TankFarmContainer will be available starting with Petroleum Refining Library version 2.2.6.

FAQ

1. What is TankFarmContainer in Petroleum Refining Library?
A TankFarm represents an individual storage system with its own tanks, configuration, and operational logic. A TankFarmContainer groups multiple independent TankFarm agents into a single facility-level representation and provides aggregated statistics. It does not replace or control the individual tank farms.

2. Does TankFarmContainer control or coordinate the operation of tank farms?
No. Each TankFarm operates independently and retains its own configuration, operating rules, and lifecycle. The container only provides unified visualization and statistics aggregation.

3. Can one TankFarmContainer include multiple tank farms storing different products?
Yes. A TankFarmContainer can include any number of independent tank farms. Different TankFarm agents can be configured to store different product grades, preserving product segregation and independent storage operations. The container aggregates their statistics but does not manage product allocation or enforce product separation.

4. Can a container include both accumulative and flow-through tank farms?
Yes. Both types can technically be included in the same container, although real facilities typically group tank farms of the same type.

5. What statistics does TankFarmContainer provide?
TankFarmContainerStatistics provides five groups of aggregated statistics:
  • Input – incoming product flows, including accepted, residual, and removable flows.
  • Output – outgoing product flows and material losses.
  • UnacceptedFlows – incoming flows that could not be accepted.
  • TankLevels – tank loads, active tank counts, fill levels, and available storage.
  • Capacity – total configured capacity of all linked tank farms.

6. Can I retrieve flow statistics for a specific product?
Yes. Flow providers support queries by product ID and AnyLogic FluidBlock. They also allow checking product connectivity and whether a product currently has a positive flow.

7. How is the overall tank farm fill level calculated?
The overall fill level is calculated as the ratio of combined tank loads to their corresponding capacities. It is not the arithmetic average of individual tank farm fill percentages.

8. Are Direct Flow tank farms included in storage statistics?
Tank farms operating in Direct Flow mode are excluded from TankLevels aggregation because they do not represent conventional tank storage. However, their configured capacity is included in the total capacity returned by Capacity.getTotalCapacity(). Therefore, total configured capacity and available storage are calculated using different inclusion criteria.

9. Does TankFarmContainer require synchronization with its tank farms?
No separate synchronization or aggregation mechanism is required. Each statistics query reads the current collection of tank farms linked to the container. Therefore, aggregated values reflect changes in the container composition when statistics are requested.

10. When should I use TankFarmContainer in an AnyLogic refinery simulation?
Use it when several independent tank farms represent one physical storage facility and you need unified visualization and facility-level statistics without combining their operational logic.