Source Control in Refinery Simulation: Runtime Flow Management

       Modern refinery simulation requires flexible control of refinery feedstock flow control during model execution. Source Control in AnyLogic Refinery Simulation provides runtime mechanisms for setting refinery flow control and responding to operating changes. The Petroleum Refining Library (PRL) Source API supports both individual source element control (individual field-level) and combined output (cluster field-level) control, allowing engineers to set, monitor, and restore flow limits, configure source connections, and respond to flow changes through event-driven callbacks. Runtime Source Control can be combined with Source performance metrics to evaluate how feedstock flow changes affect the simulated refinery. These capabilities can also support broader crude oil supply chain simulation studies, where changing feedstock production, transportation, and refinery supply conditions need to be represented within a single simulation model.

Why Runtime Source Control Matters in Refinery Simulation

       Refinery operating conditions can change during simulation, requiring feedstock refinery flow control to be adjusted without modifying the model structure. Runtime Source Control provides this capability by allowing engineers to impose and remove flow limits while the simulation is running. Runtime Source Control is particularly useful in crude oil supply chain simulation, where variable production rates, transportation constraints, and changing feedstock conditions must be represented dynamically.
       The Petroleum Refining Library Source API supports two control levels: individual Source elements and the combined Source output. This allows a specific feedstock stream to be restricted independently or a common limit to be applied to the total output.
Runtime control also supports event-driven model response. When a Source element changes speed, onSpeedChange() provides the updated speeds with zero atomic delay, allowing downstream logic to respond immediately without periodic polling.
       This creates a simple operational control cycle:

Operating condition → flow limit → actual Source speed change → onSpeedChange()

       Runtime Source Control is therefore useful for refinery flow control, production planning, and digital twin scenarios where feedstock conditions may change during model execution.

Source Properties

       Source configuration properties control how the Source is configured, grouped, connected, and operated during simulation. They define how planning data is loaded, whether daily or monthly planning is used, how flow transitions between planning periods are handled, and whether Source statistics are stored. Some properties also allow the Source to operate independently of database plans or load plans from an alternative database table. For monthly production plans, flow smoothing can be used to create continuous transitions between planning periods and avoid artificial flow discontinuities in the simulation. See Flow Smoothing in Refinery Digital Twin Simulation for the underlying approach and implementation principles.

Source Runtime Control API

       The Source runtime API provides methods for setting, monitoring, and restoring flow limits at the individual-element and combined-output levels.

Source Flow Connections

       The connect() method establishes Source output connections and is normally called once during model setup. It initializes the connections between Source elements and external fluid flows and validates the configured routing.
The connection can also be deferred until after model startup when delayed connection is enabled. This allows the Source to establish its output connections later in the simulation initialization sequence rather than immediately during model construction.
       The method supports two configurations:
  • Multiple output flows — each Source element is connected to the output corresponding to its product.
  • Single output flow — all Source element flows are merged into one combined output.
       In the standard connection mode, connect() cannot be called again after the Source has been initialized and its outputs have been defined.

Source Runtime Events and Callbacks

       Source event callbacks provide an event-driven interface for integrating Source behavior with custom simulation logic. They support initialization hooks and immediate response to source flow-rate changes.
       This event-driven approach avoids the need for periodic polling of Source speed changes and is useful for synchronizing downstream logic with changing feedstock flows.

Source Constants

       The inner Constants class defines global parameters used to configure Source behavior in the refinery simulation. These parameters control flow smoothing and the database tables used to load source plans.
The main Source-related constants are:
  • SMOOTHING_DURATION — duration of the flow-smoothing period in hours. Default: 24 h.
  • SMOOTHING_INTERVAL — interval between successive smoothing updates. Default: 6 h.
  • SOURCE_PLANTS_TABLENAME — name of the database table containing standard Source plans. Default: source_plans.
  • USER_SOURCE_PLANS_TABLENAME — name of an alternative database table used to load Source plans from an external source. Default: user_source_plans. Its structure must match the source_plans table.
       These parameters can be customized when creating the constants object or through the ConstantBuilder, allowing Source behavior and plan data sources to be configured without changing the Source implementation.

Conclusion

       Source Control in AnyLogic Refinery Simulation provides flexible runtime control of refinery feedstock flows. Engineers can set and monitor flow limits for individual source elements or a combined output, restore maximum flow capacity, and configure Source connections. Event callbacks such as onSpeedChange() provide an immediate response to flow-rate changes. Together, these capabilities make Source suitable for refinery flow control, refinery production planning, and refinery digital twin applications.

FAQ

1. Can Source flow limits be changed during simulation?
Yes. The Source API allows flow-rate limits to be changed at runtime for individual source elements or for a combined Source output.

2. Can I control individual Source elements separately?
Yes. Use setElementSpeedLimit() with the corresponding sourceId.

3. Can I limit the total Source output?
Yes. setSpeedLimit() sets the maximum total output flow limit when all Source flows are merged into a single output.

4. How can I restore the maximum flow rate?
Use resetElementSpeedLimit() for an individual source element or resetSpeedLimit() for a combined Source output.

5. Can Source notify the model when its flow rate changes?
Yes. The onSpeedChange() event provides updated speeds for the affected source elements with zero atomic delay.

6. Can Source outputs be connected after model construction?
Yes. The connect() method establishes the output connections and can be configured to defer connection until after startup.

7. What units are used for Source flow limits?
The public API specifies source flow limits in tons per hour.