An Improved Model for the Prediction of Liquid Loading in gas Wells using Firefly and Particle Swarm Optimization Algorithms

*Corresponding author: aehinmowo@unilag.edu.ng doi: http://dx.doi.org/10.4314/njtd.v18i4.1 Figure 1: Gas well experiencing liquid loading (Waltrich et al., 2015). ABSTRACT: Liquid loading is an undesired phenomenon in gas wells that occurs when producing wells attain a flow rate below which liquid will not be able to flow to the surface. The inability of the energy from the gas to transport the liquid to the surface causes back flow and eventual accumulation of liquid at the wellbore. This is characterised by intermittent flow, which, if left unchecked, can eventually kill the well. An effective and reliable predictive method must therefore, be employed. In this study, improved models based on data set from condensate/water in a gas well were developed by applying firefly (FA) and particle swarm optimisation (PSO) algorithms. The results showed that the model developed outperform many of the existing models. The models predicted liquid loading in gas well at 86% level of accuracy compared to the 81% highest possible from published models. Although, the FA and PSO models predicted liquid loading at higher accuracy compared with Turner and Coleman models for higher wellhead pressure systems, the Coleman model appeared to perform better in the prediction of critical gas rate for low-pressure systems. However, the developed model can significantly improve the prediction of liquid loading in gas wells at a higher reliability and accuracy levels. Thus, the proposed models can be a veritable tool for accurately predicting liquid loading in gas wells.


I. INTRODUCTION
Gas wells experience decline in production during their lifetime due to reservoir pressure depletion. As the natural energy keeps depleting the gas flow from the wells decreases and a point is reached when the gas will be unable to transport the co-produced liquid, resulting in back flow and the liquid accumulates down hole. This phenomenon has been described as liquid loading (Lea et al., 2008). The accumulated liquid sometimes flows backward to the formation when the bottomhole pressure is greater than the pressure near wellbore area. As the near wellbore pressure becomes sufficiently lower, the fluid starts to flow again to the surface thereby causing the well to start producing again. This cyclic phenomenon is as shown in Figure 1. It is undesirable and can cause intermittence production which is unfriendly to topside facilities.
Liquid loading negatively affects gas wells production capacity and thus should be diagnosed early enough and adequate measures deployed for its mitigation. The production impairment occurs as liquid accumulates leading to increased bottomhole pressure. This eventually cause production to cease and ultimately kill the well and significant volume of gas then remain unproduced. It can also lead to increased operational cost in unloading the liquid.
The mechanism for the initiation of liquid loading has been extensively studied. Turner et al. (1969) posited that liquid loading is a consequence of backward flow through the tubing which occurs either as liquid film or entrained droplet. They conducted series of tests and analysis with field data and concluded that the backward flow was anticipated when entrained droplet occurs. Turner et al. (1969)  Where Vc is the critical velocity, P is the pressure. However, some researchers proposed that liquid will flow backward as film droplet rather than the entrained droplet (Luo et al., 2014;Westende et al., 2007). Veeken et al. (2010) and Belfroid et al. (2008) assumed that loading will start when a film droplet occurs in the wellbore while Shekhar (2017) considered backward fall of liquid film as the initiator of liquid loading. This view was supported by Waltrich (2015) who investigated liquid behaviour in the tubing system and reported that a film when formed will fall backwards as the gas rate changes in the wellbore. Coleman et al. (1991) predicted the critical rate to maintain low-pressure gas wells from loading without the 20 % adjustment by Turners model, hereafter referred to as Coleman Model. They suggested that gas wells having gasliquid ratios below 22.5 bbl/MMscf have no impact in determining when liquid loading starts.
More recently, attention has been given to liquid loading in deviated wells. Chen et al. (2016) examined deviating wells and assumed that tubing is composed of gas at the centre and film deposited on the walls of the tubing. They analysed the force acting in the tubing and therefore developed a correction term to compare their model with Turner and Belfroid models. Their model was reported to outperform both Turner and Belfroid models. Ming & He (2017) performed an experiment in deviated and horizontal wells. They reported that film will be formed in such wells and that the film will drop down in the tubing to initiate loading. They considered that the influence of inclination angle and Reynold number will affect the critical rate. Thus, they developed another model that determines the critical rate for deviated wells in transition or turbulence regime. Wang et al. (2010) used the shape model of the entrained droplet with a different drag coefficient value to deduce a new formula for the calculation of critical rate.
The use of nodal analysis for liquid loading prediction has been extensively researched. Nallaparaju (2012) predicted liquid loading using nodal analysis by comparing the critical velocity graphs obtained by Turner et al. (1969), Coleman et al. (1991), Nosseir (1997 and Shekhar et al. (2017). They concluded that the Turner model gave an accurate critical velocity compared to others and that Turner model also gave a better prediction of liquid loading. Also, Izuwa et al. (2015) used the Nodal system analysis approach by considering the operating conditions such as tubing head flowing pressure, gas-liquid ratio in their study and later discovered that the gas velocity is affected by these conditions. Pagan & Waltrich (2016) recommended a simplified transient model which makes use of nodal technique without considering critical velocity concept. This model predicted liquid loading and its characteristics.
Although significant progress has been made in the prediction of liquid loading, it appears little or nothing has been done in the application of data-driven techniques. Data driven approaches have continued to gain application in the oil and gas studies. This is because they provide opportunity of using computational intelligence to establish connections between the system state variables without overt knowledge of the physics behind such phenomenon unlike mechanistic models. They can also provide intelligent, cost-efficient and robust alternative and demonstrate superior performance to several empirical correlations and mechanistic models (Mohammadpoor et al., 2010).
Few authors have used artificial neural network models for the prediction of liquid loading in gas wells (Khamehchi et al., 2014;Osman et al., 2002;Ghadam and Kamali, 2015).
Firefly algorithm is a nature-inspired and intelligent technique developed based on the natural behaviour and luminary flashing patterns of fireflies (Yang, 2010). Inherently, fireflies are attracted to one another by their flash signals and the brighter the flash, the stronger the attraction. The brightness is evaluated as objective function. FA is based on two important parameters, first is the variation in light intensity and second is the formulation of attractiveness. It is assumed that attractiveness of firefly is determined by its brightness which is connected with the objective function.light absorption coefficient plays a crucial role in determining the speed of convergence and how FA algorithm behaves. It also characterizes the variation of the attractiveness and it varies from 0.1 to 10. If is zero, the attractiveness and brightness of all fireflies is constant and there is no decrease in attractiveness. However, as higher values of are applied the attractiveness and brightness of each individual firefly decreases significantly over quite small distances.
randomization, essentially control the randomness or the diversity of solutions (Arora and Singh, 2013).
On the other hand, Particle Swarm Optimisation (PSO) is a random search optimisation that is based on movement, intellect behaviour and patterns of swarms. It is a populationbased stochastic optimization algorithm (Wang et al., 2018;Talukder, 2011). Optimization-based data-driven algorithms have been reported to possess superior performance compared with other classes of data driven techniques (Ehinmowo et al.,2019).Despite the reported advantages of data-driven models, optimization algorithms such as Fire fly algorithm (FA) and particle swarm optimization techniques (PSO) have not been previously explored. Hence, the need to explore them for phenomenon like liquid loading. In this study, the predictive capability of these techniques was investigated and new models developed

II. MATERIALS AND METHODS
This study aims at developing data driven optimised models to determine the critical gas rate for 106 data sets used by Turner et al. (1969) from a condensate/water gas well. This study employed 56 data sets from Coleman et al. (1991) to validate the new model proposed in this study. The original equations used to evaluate the fitness function are presented here as Eqs. (3) and (4) and the critical rate as Eq. (5). where Qg is the critical gas flow rate, MMSCFD Firefly algorithm and Particle Swarm Optimisation are both used in this study. Both algorithms are applied to determine the optimal values of parameters B1 and B2 in equation (3) and (4) that minimises the difference in the error (i.e. MSE) between the actual . and predicted . critical rate and n is the number of flow data. The mean square error (MSE) is given as: A. Optimization algorithms 1.) Firefly algorithm Firefly algorithm is based on behaviour and patterns of fireflies (Yang 2010). The firefly's flash produces a signal that attracts other fireflies; brighter fireflies are more attractive to other fireflies. The brightness is evaluated as objective function. After initialisation, the light intensities of each of the fireflies are determined to evaluate the brightness (or attractiveness) of all the fireflies which are then shortened and ranked based on the intensity of the light. After ranking of the fireflies, the position of the fireflies are updated. Finally after updating, the limit is checked as there might be new position of fireflies outside the defined limit (Kumar et al., 2018). The workflow for the implementation of firefly algorithm is shown in Figure  2.
The distance between fireflies is given as (Arora & Singh, 2013): The movement of fireflies due to their difference in brightness is given as (Arora & Singh, 2013): 2). Particle swarm optimization Particle Swarm Optimisation (PSO) is a random search optimisation that is based on movement, intellect behaviour and patterns of swarms (Talukder, 2011). PSO was originally discovered by Kennedy and Eberhart (1995). Particle Swarm Optimisation has p population size. Each population has its own position , velocity , personal and global best ( and ). The parameters assigned to the PSO are the acceleration elements 1 and 2 and the inertia weight . The population are then initialised in a search space by random generation. After initialisation, the position, velocity, personal and global bests are updated.
According to Alam (2016) the updated position +1 and velocity +1 are given as: The workflow for the implementation of PSO is shown in Figure 3.

B. Field data used for this study
The data used for this study were the 106 data sets used by (Turner et al., 1969) from a condensate/water gas well and 56 data sets from Coleman et al. (1991) were used to validate the new model proposed in this study. Statistical analysis of the   (1969) and Coleman et al. (1991).

C. Procedure for Critical Rate Prediction using Firefly Algorithm/Particle Swarm Optimization Algorithm
Implementing firefly/particle swarm optimisation algorithm to optimize Eqs. (3) and (4) consist of the following steps: Step 1: The FA/PSO parameters were selected Step 2: The predicted critical rate was calculated for each sample data in the FA/Swarm population applying the optimal values 1 2 .
Step 3: The fitness function for each sample data was calculated. MSE is the objective function FA/PSO is aimed to minimise.
Step 4: Each sample was ranked in the population ascending according to its fitness function and the firefly/swarm position updated.
Step 5: Steps 2 to 4 were repeated for the next and subsequent iterations until all the specified iterations are completed.
Step 6: The lowest MSE and the best optimal values obtained in the last iteration were recorded and used to calculate equation (3) and (4) to evaluate the critical rate.
Step 7: The algorithm was repeated several times to verify it is converging to a stable solution.
Step 8: The FA/PSO codes were run and values of , , , and were varied to establish the best outcome. Matlab codes were developed to implement these algorithms.
In summary, the Turner data sets was used by the optimization algorithms to estimate the values of the parameters B1 and B2 by minimizing MSE between the Turner data sets and the prediction from equation 5. Afterwards, the estimated parameters are then used in equations 3 and 4 to predict the Coleman data sets, and comparison is made with the actual field data.

D. Statistical Analysis for the Determination of Model Accuracy
In this study, confusion matrix measures were evaluated to determine the accuracy, uncertainty of the FA and PSO models for predicting liquid loading. This technique is best suited for summarizing the performance of a classification algorithm. The confusion matrix shown in Table 3 and other statistical measures presented in Tables 5 and 8 were used to characterise the performance of the developed models. Eqs. (11) -(17) were used to obtain the statistical measures. They help in confirming if the well predicted as loaded is indeed loaded or not.    where TP is the true positive, TN is the true negative, FP is false positive and FN is false negative.

A. An improved Model using Firefly Algorithm
For the firefly algorithm model, the parameters assigned to the FA were the absorption coefficient , randomisation coefficient , maximum attractiveness , number of fireflies , Varmin (lower bound of unknown variables), Varmax (upper bound of unknown variables) and maximum generation . These parameters have significant effects on the performance of FA. A detailed study on their effects has been carried out by Arora and Singh (2013). In this study, after various trial, the performance was analysed by evaluating the fitness function in terms of the mean square error (MSE) in finding the optimal values of the unknown variables in the critical gas rate equation and the parameters employed are shown in Table 4.
The result obtained suggested the optimal values for 1 2 coefficient and the resulting model for FA are presented as Eqs. (18)  The developed model predicted liquid loading at 86% percent accuracy level compared with 73% and 81% for Turner et al. (1969) and Coleman et al. (1992) respectively as shown in Table 5 while the error rate for the FA model was 14% the Turner and Coleman models are 27% and 19% correspondingly.

Actual rate Loading Unloading Predicted rate
Loading 29 5 Unloading 8 48 model was higher than the Coleman's, its liquid loading predictive capability was superior. Figure 5 shows that indeed some wells predicted to be loaded are not and those predicted to be unloaded were loaded. Table 6 shows that the model predicted 29 loaded wells correctly compared with 14 wells for Turner et al. The remaining 16 data were categorised as questionable. The results were observed to be better than the results from Chen et al. (2016) where 28 wells were correctly predicted. This confirms that Turner model over predict the critical gas velocity (Chen et al.2016;Coleman et al.1991).

B. An improved Model using Particle Swarm Optimization Algorithm
For the Particle Swarm Optimisation model, the parameters assigned to the PSO were the number of swarm size , Varmin (lower bound of unknown variables), Varmax (upper bound of unknown variables) maximum generation , acceleration elements 1 and 2 and the inertia weight . These parameters have significant effects on the performance of PSO. A detailed study on their effects has been reported in Wang et al. (2018). In this study, after various trials, the performance was analysed by evaluating the fitness function in terms of the mean square error (MSE) in finding the optimal values of the unknown   variables in the critical gas rate equation and the parameters used are shown in Table 7.
The result obtained suggested the optimal values for 1 2 coefficient, which are used to obtain the PSO model given as equations (20) and (21) (21) Interestingly, the PSO model and the FA models were identical and their performance same. This may be due to the similarity in both algorithms as a little change in the constitutive equation of FA corresponds to the PSO and their abilities to minimise the MSE. Table 8 shows the statistical indices for the various models with PSO having the least error rate 14.4 % followed by Coleman et.al 18.8% and Turner et. al 26.7%. The better results obtained for PSO and FA models in this study may be due to the superior performance of optimization-based data-driven algorithms compared with other classes of techniques (Ehinmowo et al., 2019). Figure 6 shows the comparison of the developed PSO model with Turner et al. (1969), Coleman et al. (1991 model and the actual field data used in Coleman. The trend here is similar to Figure 4 and as can be seen, the PSO and Coleman models predicted the critical gas rate lower than the Turner model which had earlier been reported to overpredict the gas critical rates. Although, the Coleman model prediction of the critical gas rate appears closer compared with the FA and PSO, this can be traced to the significant difference in the wellhead pressure and tubing sizes of the wells from where the Turners' and Colemans' data were obtained. The average tubing size of 0.084ft 2 and 0.  (c) show the test flow rate compared to the predicted critical rate of the PSO, Turner and Coleman models respectively The area above the diagonal line is the unloading region while the area below the line is the loaded region. Turner model predicted 24 wells incorrectly; Coleman model predicted 19 wells incorrectly, while the Particle Swarm Optimisation models predicted 13 wells incorrectly when compared to the test flow model. The well is said to be loaded up if the test rate is less than a model's critical rate when the well status is loaded or both are in the same status (as in loaded up) else, said to be unloaded. The model developed in this study performed at the same level as Guo et al. (2006) where 13 wells were incorrectly predicted.

IV. CONCLUSION
The proficiency of data-driven model to predict liquid loading in gas wells was examined and the model developed based on the 106 data sets point adopted by Turner et al. (1969) and validated using the 56 data sets employed in Coleman et al.(1991). The data-driven model uses mean square error (MSE) as the objective function to minimise the error between the predicted and actual critical rate. Based on the findings from this work, the following conclusions can be drawn: a) The data-driven models can serve as useful tools in predicting liquid loading in gas wells. b) These models can outperform some published models with 86% accuracy compared with 81 and 73% accuracy for previous models, Coleman and Turner respectively and are at par with Guo et al. (2006). c) The FA and PSO models developed in this study performed at the same accuracy level of 86%. d) Although, the FA and PSO models predicted liquid loading at higher accuracy compared with Turner and Coleman models for higher wellhead pressure systems, the Coleman model appeared to perform better in the prediction of critical gas rate for low-pressure systems. e) Comparing the data-driven model with previous models, the data-driven model developed in this study can greatly improve the prediction of liquid loading in gas wells at a higher reliability and accuracy levels. The data-driven model could therefore be used as veritable alternatives for liquid loading prediction in gas wells. f) The application of these models may be useful for liquid loading prediction in deviated wells and this is a subject of further studies.

NOMENCLATURE
FA -firefly algorithm PSO -particle swarm optimization bblbarrel critical velocity interfacial tension liquid density gas density -particle position -particle velocity -personal best -global best 1 and 2 -acceleration elements +1 -updated position +1 -updated velocity -critical rate pressure temperature compressibility factor MSE = Mean Squared Error n -Number of data set .
measured critical rate .
predicted critical rate IBM -International Business Machines SPSS -Statistical Package for the Social Sciences TP -number of correct predictions that an instance is positive TN -number of correct predictions that an instance is negative FP -number of incorrect predictions that an instance is positive FN -number of incorrect predictions that an instance is negative ERR -Error rate ACC -Accuracy SN -Sensitivity SP -Specificity PREC -Precision FPR -False Positive Rate FNR -False Negative Rate S.D -Standard Deviation 1 2empirical coefficient -absorption coefficient -randomization coefficient -maximum attractiveness -number of fireflies/swarms Varmin -lower bound of parameters Varmax -upper bound of parameters -maximum generation -inertia weight