Increasing the Efficiency of a Control System for Detecting the Type and Amount of Oil Product Passing through Pipelines Based on Gamma-Ray Attenuation, Time Domain Feature Extraction, and Artificial Neural Networks

Instantaneously determining the type and amount of oil product passing through pipelines is one of the most critical operations in the oil, polymer and petrochemical industries. In this research, a detection system is proposed in order to monitor oil pipelines. The system uses a dual-energy gamma source of americium-241 and barium-133, a test pipe, and a NaI detector. This structure is implemented in the Monte Carlo N Particle (MCNP) code. It should be noted that the results of this simulation have been validated with a laboratory structure. In the test pipe, four oil products—ethylene glycol, crude oil, gasoil, and gasoline—were simulated two by two at various volume percentages. After receiving the signal from the detector, the feature extraction operation was started in order to provide suitable inputs for training the neural network. Four time characteristics—variance, fourth order moment, skewness, and kurtosis—were extracted from the received signal and used as the inputs of four Radial Basis Function (RBF) neural networks. The implemented neural networks were able to predict the volume ratio of each product with great accuracy. High accuracy, low cost in implementing the proposed system, and lower computational cost than previous detection methods are among the advantages of this research that increases its applicability in the oil industry. It is worth mentioning that although the presented system in this study is for monitoring of petroleum fluids, it can be easily used for other types of fluids such as polymeric fluids.


Introduction
In the oil industry, a pipe is usually used to transport various oil products, which significantly reduces the cost of product transfer operations. When one product is inside the pipe, and the next product is loaded into the pipe, the two products mix at a cross-section, which is called the interface region. Therefore, the implementation of a control system to determine the amount and type of product inside the pipe is very important. Previous researchers have used gamma-ray-based systems as a reliable system for determining the parameters of two-phase [1][2][3] and three-phase [4][5][6] flows. In [1], researchers used wavelet transform as an effective method for feature extraction. The structure consisted of a Cs-137 source, two sodium iodide detectors, and a test pipe. Three homogeneous, stratified, and annular flow regimes at different volume percentages were simulated using the MCNP code. All flow regimes were fully detectable and volumetric percentages were predicted with relatively high accuracy. Nazemi et al. [2] implemented a laboratory structure in which they implemented the three flow regimes of annular, stratified, and bubbly in a test pipe at different volume percentages. Two NaI detectors and a cesium source were placed on either side of the pipe. The received signals were applied to the RBF neural network without any characteristic extraction to determine the volume fraction and type of flow regimes. Roshani et al. used a sodium iodide detector to optimize the structure of the detection system [3]. Co-60 was utilized as the gamma source and the properties of count under full energy peaks of 1.173 and 1.333 MeV, and count under Compton continuum were extracted from the signals received by the detector. Due to the extraction of inappropriate features in this study, flow regimes were not fully classifiable. In [4], the researchers simulated a three-phase flow regime, including water, oil, and gas, only in an annular flow regime and at different volume percentages. In this study, an adaptive neuro-fuzzy inference system (ANFIS) has been used to predict volume percentages, which obtained relatively good accuracy for predicting volume percentages. Studies [5,6] examined the performance of a GMDH neural network and Jaya algorithm to determine volume percentages of threephase flows, respectively. In Articles [7,8], Sattari et al. used time-domain feature extraction techniques to increase the accuracy of determining the type of flow regimes and volume percentages, and they implemented neural networks such as GMDH and MLP with the time characteristics. In previous studies [9], Roshani et al. examined the characteristics of count under Compton continuum, count under photopeak of 1.173 MeV, count under photopeak of 1.333 MeV, and average value. By using a GMDH neural network, they recognized the type of flow regime and the volume percentage of two-phase flows with high accuracy. In another study [10], the thickness of the scale inside the pipe was predicted using the characteristics of counts under photopeak of Ba-133 and Cs-137 with energy of 356 keV and 662 keV and the RBF neural network. In [11], the researchers implemented a structure to control the type and amount of petroleum product in the pipe, which consisted of a dual-energy gamma source, a test pipe, and a detector. Although the amount and type of volume percentages were detectable in this study, the lack of use of feature extraction techniques prevents the achievement of a high-precision system.
In several previous studies, X-ray tubes have been used more than radioisotopes due to the ability to turn them off; this advantage limits potential health risks for people working with this device. In studies [12,13], the authors used a structure based on an X-ray tube to detect the type of flow regime and the volume percentages of multiphase flows. In [12], time characteristics, namely variance, skewness, kurtosis, Summation of Square Roots (SSR), and Summation of Variable Exponent Roots (SVER), were extracted from the received signal from a detector and defined as inputs for the MLP neural network. In [13], a three-phase flow was investigated. An X-ray tube, a pipe, and two NaI detectors were used in the structure of the detection system. The received signals from the two detectors were transmitted to the frequency domain using Fast Fourier Transform (FFT) and frequency characteristics were extracted. Three RBF neural networks were trained with the tasks of determining volume percentages and detecting the type of flow regimes using frequency characteristics. In [14], X-ray tubes were used to implement a diagnostic system, but the lack of characteristic extraction techniques was a disadvantage of this system. In another study [15], wavelet transform characteristics were applied to develop previous work ( [14]). In [15], the characteristics of the fifth stage approximation and the details of the first to fifth stages were extracted using wavelet transform and introduced as the inputs for the MLP neural network. In [16], in order to design a system for detecting the type and amount of petroleum products in a pipe, different time characteristics were extracted. By calculating the correlation of these characteristics with each other, the characteristics that have the least similarity with each other were considered as the input for the MLP neural network. In all previous research, gamma-based systems have been introduced as the golden standard and a reliable system for determining the parameters of multiphase flows.
In this research, following the implementation of a precise system to control the type and amount of product in the pipe, a dual-energy gamma-ray-based system with a detector and a test pipe is proposed. Extracting the characteristics of the received signals and implementing the RBF neural networks using these characteristics is the difference between the proposed system and previous research, which has significantly increased the accuracy of the detection system. The present paper is divided as follows: In Section 2, the simulated structure with the MCNP is reported. Section 3 describes the extracted features in detail. The next section contains descriptions of the RBF neural network. Sections 5 and 6 are result and discussion and conclusion sections, respectively.

Simulation Geometry
The purpose of this study is to propose a control system to determine the amount and type of oil product passing through pipelines. For this purpose, a test pipe with a dual-energy gamma source and a NaI detector on both sides is simulated. Ethylene glycol, crude oil, gasoline, and gasoil are the four petroleum products that have been studied in this study, and their density values are 1.114, 0.975, 0.721, and 0.826 g/cm 3 , respectively. This simulation was performed using a Monte Carlo N Particle (MCNP) code. When there is one product in the pipe and the other product is loaded in the pipe, in a cross-section, these two products are mixed. Subsequently, as the flow passes through the pipe, the amount of the first product decreases and the amount of the second product increases. The mentioned products were examined two by two in six different cases. All six possible modes were simulated at different volume ratios (from 5% to 95%). A total of 118 (6 different modes × 19 different volume ratios + 4 modes with only one product in the pipe) modes were simulated. The gamma source on one side of the pipe contains an americium-241 and barium-133. After the gamma-ray is emitted and collides with the test pipe and the products inside the pipe, the transmitted photons are collected by the detector, located on the other side of the pipe and directly in front of the source. The size of this detector is 25.4 mm × 25.4 mm and it is situated at a distance of 30 cm from the source. The simulated structure and sample of the signal received by the detector are shown in Figure 1. The simulation results of this study have been validated by previous studies [17]. In this study, several laboratory structures were implemented and compared to the results obtained from the MCNP code. Since the tally output in the MCNP code is per source particle, both were normalized to units to compare experimental and simulation data. The maximum relative error of 2.2% was the difference between the simulation results and the laboratory structure. The attenuation for the narrow gamma-ray beam follows Lambert-Beer's law according to the following equation: where the intensity of un-collided and primary photons is shown by I and I 0 , respectively. µ and ρ represent the mass attenuation coefficient and density of absorber material, respectively. x is the beam path length through the absorber. According to this equation, different intensities are recorded by the detector due to the collision of photons with different objects. This difference in recorded intensity can be an important factor in determining the volume ratio of the petroleum product in the pipe. different objects. This difference in recorded intensity can be an important factor in determining the volume ratio of the petroleum product in the pipe.

Characteristic Extraction
The raw signals received from the detector need to be analyzed and processed so that they can be used as suitable inputs for the design of neural networks. To better interpret the received signals, reduce the size of the data, and reduce the computational costs imposed on neural networks, the feature extraction technique in the time domain was applied. Four time characteristics-variance, fourth order moment, skewness, and kurtosis-were extracted from the received signals with the following equations. The extracted features have been introduced as very useful features in previous research [7,8,18]. For this reason, in this research, in order to increase the efficiency of the control system, these characteristics have been extracted from the signals received by the detector.

Fluid1 Fluid2
Interface region of fluid1 with fluid 2

Detector
Dual energy source Shield Figure 1. Simulated structure and sample signal recorded by the detector.

Characteristic Extraction
The raw signals received from the detector need to be analyzed and processed so that they can be used as suitable inputs for the design of neural networks. To better interpret the received signals, reduce the size of the data, and reduce the computational costs imposed on neural networks, the feature extraction technique in the time domain was applied. Four time characteristics-variance, fourth order moment, skewness, and kurtosis-were extracted from the received signals with the following equations. The extracted features have been introduced as very useful features in previous research [7,8,18]. For this reason, in this research, in order to increase the efficiency of the control system, these characteristics have been extracted from the signals received by the detector.
• fourth order moment: • skewness: • kurtosis: where n is the number of data sets, N is the total number of data, and X n denotes main signal in time domain.

Radial Basis Function Neural Network
In recent years, different mathematical approaches have been used for analyzing data in plenty of engineering fields , but it has been proven that an artificial neural network (ANN) is the most well-known and powerful tool for prediction and classification. RBF neural networks, abbreviated as "Radial Basis Function", are special types of artificial neural networks that are distance-based and measure the similarity between data based on distance. An RBF network is a type of feed-forward artificial neural network that consists of three layers: the input layer, the hidden layer, and the output layer. Hidden layer neurons are activated by a Radial Basis Function. The most common form of radial base function is as follows [47]: r is the numerical value of the distance from the center of the cluster. Equation (7) shows a normal bell-shaped curve. A hidden layer consists of an array of computational units called hidden nodes. Each hidden node contains a central vector c, which is a parametric vector of length similar to the input vector x. The Euclidean distance between the center vector and the input vector x of the network is defined as [48]: Therefore, the output of the jth neuron in the hidden layer is as follows: The width or radius of the bell curve is described by σ. The hidden layer of an RBF network has units that are weighted, and these weights corresponding to the vector represent the center of the cluster. Weights can be obtained using traditional methods such as the K-Mean algorithm or techniques based on the Kohonen algorithm. In any case, the training is performed non-supervised but the number of expected clusters (k) is pre-selected, these algorithms then obtain the best fit for these clusters. To design a neural network, the available data are usually divided into two categories: training and testing data. Training data contains more data (usually 70%). With this data, the neural network is implemented and the final model is fitted to the data. After this step, the function of the neural network should be tested. For this purpose, test data is given as input to the network. It should be noted that the neural network has not seen this data before, and the correct response to this data can assure that the network is functioning properly. MATLAB (2016, The MathWorks Inc., Natick, MA, USA) software was used to extract the characteristics mentioned in the previous section and to implement the RBF neural network. In this MATLAB software, there are several toolboxes for implementing neural networks; however, in this research, no pre-designed toolboxes have been used to implement neural networks and all stages of training and testing the neural networks have been programmed step-by-step for more freedom of action. It should be noted that the "newrb" function has been used to train the neural network. After providing the appropriate inputs, the neural network design operation began. The goal was to determine the volume ratio of the four oil products passing through the pipeline, which are mixed in a cross-section. For this purpose, four neural networks with the same inputs were designed, in which the output of each neural network is a percentage of the volume ratio of each product. There are various methods to show the function of neural networks but one of the most widely used methods is the use of regression and error diagrams. To increase productivity and increase speed in neural network training, available data should be optimized. There are various optimization methods that can be used according to the type and nature of available data [49][50][51][52][53]. In this research, in order to optimize the data, all the input and output data were transferred to a range between 0 and 1, and after training the network, the output data were returned to their original state.

Result and Discussion
The performance of the designed networks can be seen in the regression and error diagrams for the training and test data shown in Figures 2-5. In the regression diagrams, the black line represents the desired outputs and the blue circle represents the output of the neural network. The error diagram shows the amount of error between the target data and the network output for each sample. The greater compatibility of the line and the circle indicates the high accuracy of the designed network. The specifications of these networks are shown in Table 1. The general process of the proposed detection system can be seen in Figure 6. The general process of the current research is that four oil products mixed two by two at different volume rates were first simulated in a test pipe. On both sides of this pipe, a dual-energy gamma source and a sodium iodide detector were placed. The detector provides the intensity of the transmitted photons. Four characteristics-variance, fourth order moment, skewness, and kurtosis-were extracted from the received spectrum to reduce dimensions, allow for better interpretation of data, and reduce computational load. The extracted features were considered as the inputs of four RBF neural networks. Each of these neural networks is responsible for determining the volume percentages of a product. By operating these four neural networks simultaneously, the type of product and volume percentage in the pipe can be recognized. One of the advantages of this research is reducing computational load. In this way, by manually extracting the characteristic, it has become easier for the neural network to assign the data and predict the volume rates with a fewer number of neurons.     In order to calculate the error of the designed neural networks, two error criteria (mean square error (MSE) and root mean square error (RMSE)) were calculated with the following equations, and the obtained values are shown in Table 1. Proper feature extraction is always one of the most important steps in signal analysis. Failure to use feature extraction techniques or not selecting the appropriate feature to determine volume ratio can be an obstacle to achieving high efficiency regarding the detection system. As can be seen from Table 1, the calculated error of the designed networks is very low, which is due to the application of appropriate inputs to the neural networks. Appropriate inputs in this study have been obtained by extracting time characteristics. The use of these features as input to other neural networks to achieve higher efficiency is highly recommended in future research. The target outputs and the outputs of all four designed neural networks are shown in Table 2. The comparison of this detection system with the others is shown in Table 3. It is clear that, by extracting the convenient characteristics, the error of the system can be outstandingly decreased. In order to calculate the error of the designed neural networks, two error criteria (mean square error (MSE) and root mean square error (RMSE)) were calculated with the following equations, and the obtained values are shown in Table 1. Proper feature extraction is always one of the most important steps in signal analysis. Failure to use feature extraction techniques or not selecting the appropriate feature to determine volume ratio can be an obstacle to achieving high efficiency regarding the detection system. As can be seen from Table 1, the calculated error of the designed networks is very low, which is due to the application of appropriate inputs to the neural networks. Appropriate inputs in this study have been obtained by extracting time characteristics. The use of these features as input to other neural networks to achieve higher efficiency is highly recommended in future research. The target outputs and the outputs of all four designed neural networks are shown in Table 2. The comparison of this detection system with the others is shown in Table 3. It is clear that, by extracting the convenient characteristics, the error of the system can be outstandingly decreased.

Conclusions
Designing an effective and reliable control system is very important in the oil industry. For this purpose, a structure consisting of a dual-energy gamma source and a NaI detector was simulated. It should be noted that a pipe has also been used to simulate different combinations of petroleum products. After simulating two by two combinations of four different oil products at different volume ratios, the received signals from the detector were processed. From each of the received signals, four time characteristics-variance, fourth order moment, skewness, and kurtosis-were extracted and defined as inputs of neural networks. Four RBF neural networks were designed to determine the amount of each oil product. The simultaneous operation of four neural networks allows the amount and type of product within the pipeline to be measured quickly. The maximum RMSE of designed networks is 0.68, which is a very low error value for predicting volume ratios. This low error has turned the system into an efficient system that can help the oil industry to control oil products crossing the pipeline. The use of this methodology to determine parameters, such as the type of flow regimes and volume percentages of multiphase flows, as well as the use of deep neural networks can be considered as future research topics. Due to being unable to turn off gamma sources, users who use these sources must wear protective clothing, which is a major limitation in this research.