Mathematical Model 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 derives the hourly profile, right-endpoint interpolation, and the direct mass-balance calculation used by the current 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.
SourceItem calculates a target mass-flow profile from production plans. Let $M$ be the current month's primary plan in tons, $M_{next}$ the next month's primary plan, and $H$ and $H_{next}$ their respective hour counts. The Source passes the start of the current month as the reference date, and the calculation uses 24 hours per calendar day.
For the usual case where the transition fits within the month, let $T$ be its duration in hours, rounded up to a multiple of the update interval $\Delta t$. The transition occupies the last $T$ hours, and $N=T/\Delta t$ is the number of intervals. The default settings give $T=24$ h, $\Delta t=6$ h and $N=4$.
The final transition interval uses the average rate implied by the next month's plan:
$$Q_{next}=\frac{M_{next}}{H_{next}}.$$Let $Q_{main}$ denote the constant rate in the main part of the current month. Each transition interval has a constant rate evaluated at its right endpoint:
$$r_i=\frac{i}{N},\qquad Q_i=(1-r_i)Q_{main}+r_i Q_{next},\qquad i=1,\ldots,N.$$The profile changes in steps of $\Delta t$. The final interval reaches $Q_{next}$ exactly. With four intervals, the weights on $Q_{next}$ are 0.25, 0.50, 0.75 and 1.00.
The main period contributes $(H-T)Q_{main}$. Integrating the constant rates over the transition adds $\Delta t\sum_{i=1}^{N}Q_i$. Since $\sum_{i=1}^{N}r_i=(N+1)/2$, the balance in tons is:
$$M=\left[H-T+T\frac{N-1}{2N}\right]Q_{main}+T\frac{N+1}{2N}Q_{next}.$$The implementation computes the main rate directly from this equation:
$$Q_{main}=\frac{M-T\frac{N+1}{2N}Q_{next}}{H-T+T\frac{N-1}{2N}}.$$The main rate therefore accounts for the mass assigned to the transition before the hourly profile is filled. The configured transition keeps its final target rate because the profile is calculated without a global rescaling step. A zero-length transition reduces to $Q_{main}=M/H$.
In the current implementation, the first calculation of a positive monthly plan can build the end-of-month transition. Subsequent monthly calculations return the constant rate $M/H$. The monthly profile calculation stores the enableFlowSmoothing flag but does not consult it when selecting these branches. A monthly plan at or below the minimum threshold produces a zero profile. Daily planning uses the daily plan directly.
The mass balance describes the calculated target profile. Actual delivered mass may differ when flow limits or downstream capacity restrict the source.