Exporting AnyLogic Simulation Results to SQLite with Petroleum Refining Library

       AnyLogic SQLite export allows Petroleum Refining Library users to export AnyLogic simulation results to a structured relational database instead of relying exclusively on Excel workbooks. Unlike traditional spreadsheet-based reporting, SQLite makes it possible to manage multiple simulation runs, retrieve specific indicators using SQL queries, and integrate refinery simulation data with external analytical tools.

From Excel Reports to Database-Based Simulation Data Storage

       Excel workbooks provide a convenient way to review simulation results and prepare reports. However, managing results from numerous simulation runs and scenarios can become increasingly difficult when each run is stored in a separate file. SQLite offers a different approach to simulation data storage by storing results from multiple simulation runs in a structured relational database. Instead of processing multiple workbooks, users can retrieve and analyze simulation data directly using SQL queries.
       This is particularly useful for:
  • Storing results from multiple simulation runs in one database.
  • Comparing different scenarios and model configurations.
  • Retrieving specific indicators and reporting periods.
  • Integrating simulation data with external analytical tools.
       The SQLite exporter complements the existing Excel functionality, extending the ways simulation results can be stored and used.

AnyLogic SQLite Export Architecture

       The SQLite export process is built around three classes, each responsible for a specific stage of data processing:
       ExportSnapshotCollector collects statistics from Petroleum Refining Library components and prepares the export data.
       ExportSnapshot stores the collected data in a structured, validated snapshot.
       DatabaseExporter creates the SQLite database structure and writes the snapshot to the database.
       Data collection and database persistence are deliberately separated. ExportSnapshotCollector collects statistics in the simulation thread and creates an independent immutable snapshot. DatabaseExporter then uses this snapshot to perform database operations without directly accessing Petroleum Refining Library component statistics. This separation provides a consistent approach to database integration and simulation data persistence.

What Simulation Data Can Be Exported to SQLite?

       The SQLite exporter supports the main statistical components of Petroleum Refining Library:
  • Sources — feedstock supply statistics.
  • Process Units — production and processing statistics.
  • Tank Farms — storage levels, flows, and other tank farm indicators.
  • Product Mixers — blending statistics and product-related indicators.
  • Custom Statistics — additional indicators defined using AbstractAdditionalRowExport.
       Both numeric and text-based indicators can be stored. Each result value includes metadata such as the indicator name, measurement unit, component type, and reporting period. This allows different types of simulation statistics to be stored in a consistent database structure.

SQLite Database Structure

       The SQLite simulation database uses a relational structure consisting of six tables:
       The result_values table stores individual simulation observations. Each record is associated with a simulation run, model object, and reporting period. Additional fields identify the product, source, indicator, measurement unit, and value type where applicable. Both numeric and text values are supported through separate numeric_value and text_value columns. Additional fields identify the product, source, indicator, measurement unit, value type, component type, and label. Both numeric and text values are supported through separate numeric_value and text_value columns.

Simulation Run Identification and Reporting Periods

       Excel and SQLite provide different approaches to simulation results management. Excel is suitable for reviewing simulation results and preparing reports, while SQLite provides structured storage for multiple simulation runs, SQL-based data retrieval, and integration with external analytical tools. The choice depends on whether the primary goal is simulation reporting or long-term simulation data storage and analysis.
       Before saving, the exporter validates the snapshot and its database references. Data is then written within a single transaction. Repeated exports with identical data are recognized, while attempts to overwrite an existing run with different results are rejected as conflicts.The choice depends on how simulation results will be used: Excel for reporting and presentation, SQLite for persistent storage and further data analysis.

Conclusion

       AnyLogic SQLite export extends Petroleum Refining Library beyond traditional Excel-based simulation reporting by introducing structured database storage. The exporter provides a consistent way to collect, validate, and store petroleum refinery simulation results from multiple simulation runs. Combined with SQL-based data retrieval, this functionality creates new opportunities for refinery simulation analysis, scenario comparison, and integration with external analytical systems. SQLite complements Excel, providing an additional approach to simulation data management and analysis.

SQLite export functionality will be introduced in Petroleum Refining Library v2.2.6.

FAQ

1. What is AnyLogic SQLite export in Petroleum Refining Library?
It is a functionality that allows simulation results from PRL components to be stored in a structured SQLite database. It complements the existing Excel reporting capabilities of Petroleum Refining Library.

2. What simulation components are supported?
The exporter supports Sources, Process Units, Tank Farms, and Product Mixers. Custom statistics defined through AbstractAdditionalRowExport can also be included.

3. What types of reporting periods are available?
The exporter supports hourly, daily, monthly, and yearly reporting periods.

4. Can multiple simulation runs be stored in one SQLite database?
Yes. Each simulation run receives a unique identifier, allowing results from multiple runs and scenarios to be stored and analyzed in the same database.

5. Can SQLite store both numeric and text-based simulation results?
Yes. Numeric indicators are stored in numeric_value, while text-based values are stored in text_value.

6. How does the exporter prevent duplicate data?
The exporter recognizes repeated exports with identical data. If the data for an already assigned simulation run has changed, the exporter reports a conflict.

7. Is the SQLite export transactional?
Yes. Results are written within an atomic database transaction. If a persistence error occurs, the transaction is rolled back to prevent partially saved results.

8. Can exported results be analyzed using SQL?
Yes. Simulation runs, model objects, reporting periods, and result values are stored in relational tables and can be queried directly using SQL.

9. Does SQLite replace the existing Excel exporter?
No. SQLite complements Excel. Excel remains suitable for reporting and presentation, while SQLite is intended for structured data storage and further analysis.

10. Does the exporter support automatic database schema migration?
No. The exporter checks schema compatibility, but automatic migration from unsupported schema versions is not currently supported.