Mathematical Formulation of the Volume-Preserving Flow Smoothing Algorithm

This document presents the complete mathematical formulation of the Volume-Preserving Flow Smoothing Algorithm used in the Petroleum Refining Library (PRL) to convert discrete production plans into continuous mass flow profiles for Digital Twin simulation.

The engineering concepts behind the algorithm are explained in the companion article Flow Smoothing in Digital Twin Simulation: Converting Production Plans into Continuous Flows . This document focuses on the mathematical formulation, including hourly flow calculation, transition interpolation, mass balance preservation, and numerical correction used by the reference implementation.

The algorithm is implemented as part of the Petroleum Refining Library (PRL) , a simulation framework for refinery and oil & gas Digital Twin development. The mathematical model presented below is intended to support software developers, simulation engineers, and researchers who require a detailed description of the algorithm or wish to implement a similar approach in their own Digital Twin applications.

Related Documentation

1. Base Hourly Flow Rate

The monthly production plan is first converted into an average hourly mass flow rate.

$$Q_{base}=\frac{M_{month}}{H_{month}}$$

This value represents the constant flow that would exactly satisfy the monthly production plan if no smoothing were applied. It serves as the initial reference for constructing the smoothed flow profile.

2. Target Hourly Flow Rate

The target flow rate is calculated from the production plan of the next month.

$$Q_{next}=\frac{M_{next}}{H_{next}}$$

This value defines the operating condition that the smoothing algorithm must reach at the end of the transition period.

3. Main Operating Period

The month is divided into a main operating period and a smoothing period.

$$H_{main}=H_{month}-T_s$$

Only the final part of the current month participates in the transition. The remaining hours operate at a nearly constant flow rate.

4. Transition Mass

The initial production mass assigned to the smoothing interval is estimated using the base hourly flow.

$$M_{transition}=Q_{base}T_s$$

This value estimates the material contained within the transition period before interpolation is applied.

5. Remaining Monthly Mass

The remaining production mass is allocated to the main operating period.

$$M_{main}=M_{month}-M_{transition}$$

The remaining mass is distributed over the rest of the month.

6. Corrected Hourly Flow Rate

The corrected hourly flow is calculated for the main operating period.

$$Q_{main}=\frac{M_{main}}{H_{main}}$$

Equivalent form:

$$Q_{main}=\frac{M_{month}-Q_{base}T_s}{H_{month}-T_s}$$

This correction compensates for the future redistribution of production during the smoothing interval while preserving the monthly production target.

7. Interpolation Interval

The smoothing period is divided into equal interpolation intervals.

$$\Delta T=\frac{T_s}{N}$$

Multiple intervals approximate a continuous transition while remaining compatible with the simulation time step.

8. Interpolation Coefficient

The interpolation coefficient defines the relative position of each interval.

$$r_i=\frac{i+0.5}{N},\qquad i=0,\ldots,N-1$$

Using the midpoint of each interval provides a better approximation of the average flow over that interval.

9. Flow During the Transition

The flow assigned to each interpolation interval is calculated by linear interpolation.

$$Q_i=Q_{main}+(Q_{next}-Q_{main})r_i$$

The resulting profile is a piecewise-constant approximation of a continuous linear transition.

10. Simulated Monthly Mass

The total production mass is calculated after constructing the hourly flow profile.

$$M_{sim}=\sum_{h=1}^{H_{month}}Q_h$$

This value is compared with the original production plan.

11. Mass Balance Correction

A correction factor eliminates numerical deviations caused by discretization.

$$K=\frac{M_{month}}{M_{sim}}$$

The correction factor is typically very close to one.

12. Corrected Hourly Flow

Each hourly flow value is multiplied by the correction factor.

$$Q_h^{new}=KQ_h$$

This operation preserves the shape of the smoothed profile while restoring the exact production target.

13. Mass Preservation Condition

The final hourly flow profile satisfies the original production plan.

$$\sum_{h=1}^{H_{month}}Q_h^{new}=M_{month}$$

The algorithm redistributes production over time without changing the planned monthly production mass.