# A Sensitivity Analysis of a Computer Model-Based Leak Detection System for Oil Pipelines
## 2 Methodology  
### Leak Detection System  
SPS Statefinder consists of two main components, a real-time transient hydraulic model and a leak detection algorithm named state estimation [15]. The hydraulic model estimates the pipeline state by solving the conservation of mass and momentum equations of transient flow, assuming that the pipeline is free of leaks. The equations of mass and momentum conservation are given by:  
\[\frac{1}{\rho a^{2}}\bigg{(}\frac{\partial P}{\partial t}+V\frac{\partial P}{ \partial x}\bigg{)}+\frac{\partial V}{\partial x}=0 \tag{1}\]  
\[\frac{1}{\rho}\frac{\partial P}{\partial x}+V\frac{\partial V}{\partial x}+ \frac{\partial V}{\partial t}+\frac{fV|V|}{2D}+g\sin\alpha=0 \tag{2}\]  
where \(P\) is the pressure; \(V\) is the flow velocity; \(\rho\) is the density of the fluid;\(f\) is the Darcy-Weisbach friction factor; \(g\) is the gravitational acceleration; \(\alpha\) is the upward angle between the pipe and the horizontal; \(x\) is distance; \(t\) is time; \(D\) is the pipe diameter; and \(a\) is the wave speed in the pipe calculated by:  
\[a=\frac{\sqrt{K/\rho}}{\sqrt{1+\frac{K}{E}\frac{D}{e}}} \tag{3}\]  
where \(K\) is the bulk modulus; \(E\) is the [PERSON]'s modulus; and \(e\) is the pipe wall thickness [16]. A hydraulic model of a simple pipeline with one injection and one delivery point only needs two boundary conditions to completely determine the pipeline state, providing that all the input variables to the model precisely represent the actual system. However, this is never the case in real-life pipelines due to the existence of uncertainties. SPS Statefinder utilises an optimization algorithm, attempts to make best use of all available measured data and meaningfully attributes the discrepancy to real-world errors and leaks. Statefinder adjusts pressure drops and wave speed, as well as adds or removes fluid from the modelled pipeline. The hydraulic model is then rerun with these changes and computes a new pipeline state. Statefinder also adjusts measured pressure and flow rates. A penalty (\(E\)) is assigned for each adjustment being made as seen in the following equations (only showing terms relevant to this study), and the solution that minimizes the sum of all the penalties is sought by changing the decision variables within their corresponding constraints [15]:  
\[E_{1}=\sum_{i}\Bigg{(}\frac{W_{1}}{REP_{i}^{P}}\times\left(P_{i}^{M}-P_{i}^{A} \right)\Bigg{)}^{2}+\sum_{i}\Bigg{(}\frac{W_{2}}{REP_{i}^{Q}}\times\left(Q_{i }^{M}-Q_{i}^{A}\right)\Bigg{)}^{2} \tag{4}\]  
where \(E_{1}\) is the penalty associated with the errors in measured pressure and flow rate; \((P_{i}^{M}-P_{i}^{A})\) and \((Q_{i}^{M}-Q_{i}^{A})\) are the adjustments Statefinder made to the measured pressure and flow rate at sensor location \(i\), i.e., the variables to be optimized; \(REP_{i}^{P}\) and \(REP_{i}^{Q}\) are the repeatability of the pressure transmitters and flow meters and are used to calculate the constraints of the pressure and flow rate adjustments. The repeatability is estimated as the expected errors in the measured pressure and flow rate; \(W_{1}\) and \(W_{2}\) are the tuning weights assigned to pressure and flow rate measurements, respectively. A smaller weight indicates a higher level of uncertainty, and Statefinder assigns a lower penalty when making adjustments to the relevant variables [15]:  
\[E_{2}=\sum_{i}(W_{3}\times FPDC_{i})^{2} \tag{5}\]  
where \(E_{2}\) is the penalty associated with the errors in modelled pressure drop due to friction; \(W_{3}\) is the corresponding tuning weight; \(FPDC_{i}\) is a correction coefficient applied to the friction factor \(f\) of pipe segment \(i\) and it is the variable to be optimized. The constraint on \(FPDC_{i}\) is calculated by Statefinder and is a function of flow rate and a user-specified parameter called \(VER\) which describes the amount of error in fluid viscosity [15]:  
\[