Corrosion Prediction for Naphtha and Gas System of Atmospheric Distillation Tower Based on Artificial Neural Network and Genetic Algorithm

The corrosion of low-temperature sections of a company's atmospheric and vacuum distillation unit was analyzed. Corrosion rate prediction model was established using BP neural network based on the corrosion detection data detected in the sewage on top of the tower over a period of time. In this model, the pH value, Cl ion concentration, Fe ion concentration and sulfide concentration of the sewage discharged from the top of the tower are taken as the input data, and the average corrosion rate as the output data, the results show that the prediction error is large. The BP neural network was optimized using the genetic algorithm. The optimized model could accurately predict the corrosion of the atmospheric unit at low temperatures. The corrosion rate prediction model was used to investigate the effect of each variable on the corrosion rate through the single factor change and the results could reflect the relationship between detected corrosion data and corrosion rate in the sewage on top of the atmospheric tower.


Introduction
The atmospheric and vacuum distillation unit has a large impact on the overall operation and processing capacity of the refinery as the first processing unit. The crude naphtha is transformed to distillates of different bnaphthaing ranges by distillation in the unit. Crude naphtha usually contains much Cl ions and sulfur ions, which easily forms a corrosive environment of HCl-H 2 S-H 2 O at high temperatures, causing corrosion attack on the naphtha and gas system of atmospheric distillation tower. Equipment maintenance and material replacement caused by corrosion waste a lot of resources and shorten the operation cycle of the devices [1]. Therefore, the corrosion prediction for naphtha and gas pipelines on top of atmospheric distillation tower is of great significance to the production and maintenance of the devices.
However, in the actual production environment, the influence of various factors on corrosion is complicated and it is difficult to establish an accurate mathematical model. The BP neural network can determine the mathematical model for corrosion through its own strong learning ability and multi-factor cooperation ability and predict the corrosion rate. However, the prediction accuracy is low when the data samples are limited, so it is difficult to meet the practical engineering demands. In this paper, the BP neural network was optimized by genetic algorithm, improving the prediction accuracy of corrosion rate and it provides reference for corrosion detection [2].

Pipeline Corrosion Factor Analysis and Training Data Source Selection
A company's atmospheric and vacuum unit mainly processes high-acid heavy crude naphtha, and its pipeline on top of atmospheric tower is made of carbon steel. Crude naphtha processing volume is 50t/h, temperature on the top of atmospheric pressure tower is 94-112°C, and pressure is 1.9-13.4kpa.
The reasons for the low-temperature part corrosion of the atmospheric equipment are mainly as follows: 1. The effect of electric desalination is poor leading to the high salt content, and a large amount of chloride flocks to the top of the atmospheric tower and the vacuum tower, forming hydrochloric acid solution with condensate water on the top of the tower causes corrosion of the pipeline [3]. 2. Ammonium injection equipment at the top of the tower is incomplete, which makes it impossible to accurately control the pH value at the top of the tower and it is easy to form HCL-H 2 S-H 2 O corrosion is easily formed, resulting in a higher concentration of Fe 2+ ions in the outlet water [4]. 3. The lack of means for detecting the pH value of the condensate water leads to the inability to timely adjust the amount of ammonia injection, making the pH value too low for a long period of time, resulting in long-term acidic corrosion of the atmospheric equipment [5].
Therefore, the pH value, Cl ion concentration, Fe ion concentration, and sulfide concentration of the sewage discharged from the top of the atmospheric tower are selected as training data, and the average corrosion rate is used as the output data.

Establishment and Prediction of BP Neural Network Model
The BP neural network selected in this paper has a three-layer structure of input layer, hidden layer and output layer. The main characteristics of multi-layer feedforward neural network are forward transmission of signals and backward transmission of errors [6]. The input signal is processed layer by layer through the input layer and then the hidden layer, output through the output layer. If the output value does not reach the desired output, the error between the output value and the expected value is back propagated, the weight and threshold value of the network are adjusted according to the error, and the error is reduced through repeated multiple iterations until the error is reduced to the permissible value, then the network training is completed. [7].

Network Structure Determination
The output data is pH value, Cl ion concentration, Fe ion concentration and sulfide content. Therefore, the number of nodes in the input layer is 4. The selection of nodes number in the hidden layer of the neural network is related to the final prediction accuracy, and the training error decreased with the number of nodes in the hidden layer increasing. Due to overfitting and other reasons, the training error increases with the number of nodes rising in the hidden layer when exceeding a certain scope [8]. Therefore, the approximate range of nodes number in the hidden layer was selected by empirical formula (1). The best effect is obtained when the nodes number of hidden layer is 5 after several experiments. The final output is the corrosion rate, so the nodes number in the output layer is 1. The topology of the neural network is 4-5-1. In this paper, 90 groups of data were randomly selected as training data, and 10 groups were used for network training for predictive data from the 100 sets of data obtained from field tests [9].
In this formula n -the number of nodes in the input layer; l -the number of nodes in the hidden layer; m -the number of nodes in the output layer; a -a constant between 0 and 10.

The Determination of Node Transfer Function
In this paper, the tansig function is selected as the training function, in which the output function H of the hidden layer is determined by formula (2), where x is the input variable, w ij is the connection weight number between the input layer and the hidden layer, a is the threshold value of the hidden layer, initialization assignment of the weight and threshold is randomly selected within the interval (0, 1) [10].
In this formula l -the number of nodes in the hidden layer;; f -activation function of hidden layer. The output layer function is the logsig function, and the predicted output O k of the artificial neural network can be calculated by formula (3).
In this formula: h -output of the hidden layer; W jk -connection weight; b -threshold value.

Error Calculation
The network prediction error e is obtained by equation (4).
In this formula: O -predicted output; Y -Expected output.

Weight Update
The connection weights of the network-w ij and w jk are updated by equations (5) In this formula: η -learning rate.

Process Determination
Determine if the iteration of the algorithm is complete. If not, returning to step 2.

Establishment and Prediction of Corrosion Rate Model
In this paper, MATLAB language is used for programming, 90 sets of data are randomly selected as training data, and 10 sets of data are predicted data. It can be seen in Figure 1 that the BP neural network established in this experiment can predict the corrosion of low-temperature parts of atmospheric equipment. Figure 2 shows the absolute error of forecasting results and actual results. The average relative error calculated by absolute error is 21.4%. In this paper, the ratio of the average of the absolute error and the average of the true value is selected as the average relative error, which can reflect the credibility of the measurement. The mean squared error calculated is 2.57%. Mean square error refers to the expected value of the difference between the parameter estimate and the true value of the parameter. The smaller the mean squared error, the better the accuracy of the prediction model to describe the experimental data.  The prediction results obtained by BP neural network corrosion are in good conformance with the actual corrosion rate. It shows that the BP neural network has strong learning ability and forecasting ability, but some individual prediction values diverge largely. The root cause is that the training data is sparse leading the BP neural network not fully trained and the network prediction value is subject to large errors. In this paper, a genetic algorithm is used to optimize the BP neural network to improve the prediction accuracy.

Genetic Algorithm to Optimize BP Neural Network
Genetic algorithm is a parallel stochastic-search optimization method through simulating the natural genetic mechanism and biological evolution theory [11]. According to the selected fitness function, individuals are screened through selection, crossover and mutation in inheritance. Individuals with good fitness values are retained, individuals with poor fitness are eliminated, and new groups inherit the superior information of the previous generation. This cycle will be repeated until the set condition is satisfied. [12]  Optimization of BP neural network based on genetic algorithm is to optimize the weights and thresholds of BP neural network by genetic algorithm [13]. Each individual in the population contains all the weights and thresholds of a network. The individual calculates the individual fitness value through the fitness function, and the genetic algorithm finds out the individuals with optimal fitness value through selection, crossover, and mutation operations. The BP neural network prediction uses the genetic algorithm to obtain the optimal individual and initial network weights and thresholds are assigned, the network predicts the output of the function after being trained [14]. Figure 3 shows the flow chart of the genetic algorithm.

Algorithm Flow
Since the BP neural network structure set in this paper is 4-5-1, that is, the output layer has 4 nodes, the hidden layer has 5 nodes and the output layer has 1 node, with a total of 25 weights and 6 thresholds so the genetic algorithm has an individual code length of 31. Randomly take 90 sets of data as training data and 10 sets of data as prediction data.

Genetic Algorithm Implementation
The elements of genetic algorithm optimizing BP neural network include population initialization, fitness function, selection operation, crossover operation and mutation operation [15].

Population Initialization
In this paper, all the corrosion data obtained are real strings after being normalized. Therefore, the encoding method selected is real coding, composed by 4 are parts, including the connection weights of the input layer and the hidden layer, the hidden layer threshold, the connection weights of the hidden layer and output layer, and output layer threshold. Combined with the previously established neural network architecture, a complete neural network can be formed.

Fitness Function
The sum E of the absolute error of the output value and the expected value predicted by the neural network is taken as the individual fitness value F, and its fitness can be obtained according to the calculation formula (9) In this formula: n -the number of network output nodes; Y i -the expected output of the I th node of the BP neural network; O i -the predicted output of the I th node; K-coefficient

Selection Operation
Based on a real string of samples, fitness-proportionate strategy was selected, namely the roulette method [15]. The selection probability p i of each individual i is: (11) In this formula: F i -the fitness value of individual i; coefficient; N -number of population individuals

Crossover Operation
The K chromosome a k and L chromosome a l are crossed at J level by real number crossing method, Methods as below; (1 ) In this formula: b-[0-1] random number

Variation Operation
The j-th gene a ij of the i-th individual is mutated as follows max min ij In this formula: amax-Upper bound of gene a ij ； amin-Lower bound of gene a ij ； f(g)- r2-random number; g-Current iterations; G max -Maximum number of evolutions； r-[0-1] random number

Genetic Algorithm Optimization BP Neural Network Implementation
In this paper, the BP neural network based on genetic algorithm is applied to predict the corrosion of the overhead naphtha and gas system of atmospheric tower based on genetic algorithm optimized by MATLAB. Through many experiments, the parameter of genetic algorithm is set to:population size 100, Number of evolution 250, The crossover probability is 0.3, The probability of mutation is 0.1.  The forecast result is shown in Figure 4 Corrosion prediction data of BP neural network optimized by genetic algorithm has higher prediction accuracy, Figure.5 shows the absolute error of the data prediction and actual results, The average relative error calculated by the absolute error is3.87%, The error value has a certain reduction compared with BP neural network. Calculating the mean square error of 3.03% also has a certain reduction compared with BP neural network. It shows that the performance of the BP neural network after the optimization of the genetic algorithm is higher than that of the non-optimized network, which reflects the better accuracy of the prediction model to describe the experimental data.

Corrosion Rate Model Operation
In the actual production environment, Corrosion is caused by a variety of factors. It is difficult to determine the influence of single factor on it, This makes some difficulties in the study of anticorrosion. This article uses the established corrosion prediction model to investigate the effect of various factors on the corrosion rate.

Influence of Iron Ion Concentration on Corrosion Rate
The iron ion in the sewage at the top of atmospheric pressure tower is the product of corrosion of the pipeline in the tower top equipment. Increased iron ion concentration indicates increased corrosion rate at the top of the pipeline. The higher the iron ion concentration, the more severe the corrosion of the pipeline [16].
First, pH value was kept at 8, chloride concentration was 30 mg/L, sulfide concentration was 30 mg/L, and the concentration of iron ion increased from 1 mg/L to 10 mg/L. The effect of iron ion concentration on corrosion rate is shown in Figure 6. Can be seen from Figure.6, The higher the ferric ion concentration, the greater the corrosion rate, in line with the natural law of corrosion. However, the corrosion rate is too small as the single variable increases, It may be that most of the selected data samples are within the normal range. The change of corrosion rate is relatively small, which leads to a smaller change of corrosion rate when the single variable exceeds normal range. In practice, the test data is within a reasonable range, and the model still has high accuracy in predicting the corrosion rate.

Effect of pH Value on Corrosion Rate
pH value directly affects the concentration of HCl in water, As the pH increases, the concentration of H + decreases, and the reduction of hydrogen atoms decreases, so the corrosion rate decreases [17]. Similarly, the increase of pH value and the increase of OHconcentration make the oxidation rate of iron decrease, so the corrosion rate decreases. Maintain ferric ion concentration of 3 mg/L, chloride concentration of 30 mg/L, and sulfide concentration of 30 mg/L, gradually increasing the pH from 1 to 14. The effect of pH value on the corrosion rate is shown in Figure 7. From Figure 7, it can be seen that as the pH value increases, the corrosion rate gradually decreases.

Effect of Chloride Ion Concentration on Corrosion Rate
Under normal circumstances, the chloride ion concentration is in the range of 0-100 mg/L. As the concentration of chloride ions increases, the conductivity of the solution increases, and the H + concentration in the solution increases, preventing the formation of oxide films and accelerating corrosion rate [18].
Keep the pH at 8, ferric ion concentration 3 mg/L, sulfide concentration 30 mg/L, and gradually increase the chloride ion concentration from 10 mg/L to 100 mg/L. Chloride ion concentration on the corrosion rate shown in Figure 8. It can be seen from Figure 8 that as the concentration of chloride ions increases, the corrosion rate gradually increases.

Effect of Sulfide Concentration on Corrosion Rate
With the increase of sulfide concentration, it acts as a catalyst to participate in the oxidation of iron, and the corrosion of carbon steel is intensified [19]. Keep the pH at 8, ferric ion concentration 3 mg/L, chloride ion concentration 30 mg/L, and gradually increase the sulfide concentration from 10 mg/L to 100 mg/L. The effect of sulfide concentration on the corrosion rate is shown in Figure 9. As can be seen from Figure. 9, as the sulfide concentration increases, the corrosion rate gradually increases.

Conclusion
In this paper, the corrosion prediction model of naphtha and gas system at the top of the atmospheric tower is established by using the strong self-learning ability of BP neural network and the ability of multi factor synergy combined with the actual production situation. Genetic algorithm is used to optimize the prediction model and get a high prediction accuracy. Through the single factor investigation of the established model, it is confirmed that chloride ion concentration and sulfide concentration can accelerate the corrosion rate，Increase the pH of wastewater to inhibit the corrosion rate，An increase in iron ion concentration indicates an increase in the corrosion rate. It is proved that the established model has certain reference value for the corrosion research of low temperature part of atmospheric vacuum distillation unit, It has a certain guiding significance for the corrosion detection in actual projects.