Study on Computer Monitoring System for Oilfield Joint Sta- tions Based on the BP Neural Network PID Control Algorithm

The Hanqu Joint Station of the Dingbian Oil Production Plant of Yanchang Oilfield Co., Ltd is located at the edge of the desert in northern China. the bad field conditions and strong sandstorm, the hardware of computer monitoring system of Joint Station is often damaged. At the same time, the core equipment of the joint station three-phase separator oil chamber liquid level is hard to achieve high precision constant value control, the general control algorithm is difficult to meet the control requirements.This paper proposed a design scheme of a oilfield joint station computer monitoring system based on the Siemens S7-300 PLC, the hardware of the monitoring system adopts the redundancy scheme of dual monitoring computers, dual programmable logic controllers (PLCs), and dual industrial Ethernet. The BP neural network PID control algorithm was used to realize constant value control of the oil chamber liquid level of the three-phase separator of the core equipment of the joint station,and realized high control precision. The monitoring system could well adapt to the harsh environment of the scene, and showed high reliability and efficiency.


Introduction
Oilfield joint stations are comprehensive production facilities that integrate multiple processes, such as crude oil metering, oil-water separation, sewage treatment, crude oil and natural gas gathering and transportation, oil transportation and dehydration, and water injection [1] .
This project is based on the computer monitoring project of the Hanqu Joint Station of the Dingbian Oil Production Plant of Yanchang Oilfield Co., Ltd. Due to harsh field conditions, strong wind, and sand, hardware equipment, such as computers and PLCs, are often damaged. Therefore, the reliability of the computer monitoring system in the joint station is very important. At the same time, the process requirements of the core equipment of the joint station threephase separator oil chamber liquid level control precision are very high, must achieve high precision constant value control, the general control algorithm is difficult to meet the control requirements.
In this paper, a software redundancy system based on Siemens S7-300 was used to improve the reliability of the monitoring systems of joint stations. The BP neural network PID control algorithm is used to realize the high-precision constant value control of the liquid level in the oil chamber of the three-phase separator. This computer monitoring system improve the management level, eliminate the hidden dangers of production accidents, and ensure the smooth, and efficient operation of oilfield gathering and transportation systems.

Brief introduction of the production process
The production process of joint stations is roughly divided into crude oil gathering and transportation and sewage treatment. In the process of crude oil gathering and transportation, the transported oil (liquid) from each single well or automobile first enters an oil-gas-water three-phase separator, where the separation of gas and liquid is realized [2] . Natural gas escapes from the upper part of the three-phase separator and enters a deoiler. After it is condensed, it is exported. The oil-water mixture flows from the lower part of the three-phase separator and enters the settling tank through a heat exchanger. Most of the crude oil is separated from the upper part of the settling tank. After the secondary oil-water separation of the settling tank, the crude oil has almost no water content, and it then enters the purification tank to be exported. The oily sewage under the sedimentation tank is exported to the sewage area for sewage treatment. The suspended solids, emulsified oil, colloid, dispersed oil, and floating oil are removed by physical oil removal, coagulation oil removal, and filtration. In the sewage treatment process, the content of the suspended solids, dispersed oil, suspended oil, colloid, and emulsion oil in the water should be strictly monitored, and water can be injected into the undergroun for oil displacement once again after reaching the standard values [3] . The schematic diagram of the production process of the combination stations is shown in Fig. 1  In the three-phase separator, it is necessary to control the oil level to maintain constant. In this study, the classical PID control algorithm was used to realize analog closed-loop control using the PID controller in S7-300.

Point numbers on the monitoring systen
The monitoring system of joint stations includes the liquid level detection of various tanks and separators, gas outlet pressure detection of three-phase separators, liquid level control of three-phase separators, temperature detection of the crude oil pipelines of heat exchangers, instantaneous detection of the unloading and loading flows, detection of the combustible gas concentration in the plant area, and monitoring the sewage treatment processes. The numbers of the system monitoring points are shown in Table 1.
A control system mainly realizes the centralized monitoring, control, and management of the process production operation parameters in stations. It typically includes screen display, supervision, alarm systems, recording documents, parameter modification, personnel management, and report functions. 3. Hardware scheme of the monitoring system In view of the importance of joint station monitoring systems and Party A requirements, the proposed computer monitoring system scheme adopts a software redundancy scheme based on Siemens S7-300 PLC [4] . In the software redundancy scheme, the processor is used in two ways. When the main processor fails, data synchronization is achieved, and switching is completed by compiling the monitoring program and data exchange processing program in advance in the CPU module program.

Hardware composition of the software redundancy
The software redundancy scheme based on Siemens S7-300 PLC must generally have the following modules and equipment: 1.
1) CPU module Generally, the S7-300 series only uses the CPU31X-2DP model to achieve software redundancy without the hardware redundancy function. S7-400 full-series CPUs can be applied to software redundancy systems. However, only S7-400H CPUs can be applied to hardware redundancy systems [5] .

2)CP comunications processor series
The CP342-5 PROFIBUS communication module is selected when the CPU module of a PLC communicates with the monitoring host using the PROFIBUS protocol. The CP 343-1 communication module should be selected when using Ethernet protocol communication, but it should be used in conjunction with the SCALANCE X005 industrial Ethernet switch [6] .

3)ET200M substation
ET200M is a PROFIBUS DP distributed slave station that is often used in industrial fields. The ET200M substation is mainly composed of a power supply, an IM153 series interface module, an all-I/O module suitable for ET200M, a rail, etc. The software redundancy scheme of the S7-300 series PLC must have an ET200M substation in addition to special requirements: • Two IM153 series interface modules must be connected to different CPU modules through the PROFIBUS bus.
• To support hot-plugging, an active bus guide rail and an active bus template must be selected. This way, the I/O module on it can support the hot-plug function.

4)software redundancy
In addition to Step 7 of the S7-300 programming software SIMATIC, the support of the Siemens software redundancy package is needed, as it contains the program block library necessary for the redundancy function. The example program of different system can significantly reduce the difficulty of PLC redundancy programming [7] .

2. Hardware composition of the software redundancy
Two industrial computers (IPC-610H) and two 22-inch LCDs were selected to constitute the dual redundancy of the monitoring computer of the monitoring system. At the same time, real-time monitoring of the production process conditions of the joint station was realized using two high-performance Siemens PLCs. The communication between the two upper monitor computers and PLCs was established using industrial Ethernet, and the whole system was organically joint with industrial Ethernet as a redundant network. The hardware structure of the monitoring system is shown in Fig. 2. The monitoring system has two completely independent CPU modules of Siemens PLC and the corresponding PROFIBUS bus, which constitute a redundant system. The CPU module of Siemens PLC selects the S7 315-2 DP module, which has two interfaces, one is the MPI interface, and the other is the PROFIBUS bus interface [8] . The MPI interface of the two CPU modules is connected to form a data synchronization communication link between the main system and the standby system. The two CPU modules are connected with an ET200M slave station through their respective PROFIBUS bus interface to form a communication link between the main system, standby system, and slave station.
On-site various physical signals are converted into 4-20 mA current signals through sensors and are then collected into the PLC through various I/O modules of the ET200M slave station. The PLC calculates and processes the data. On one hand, it outputs the control signal to the control module of the ET200M slave station. On the other hand, it transmits the corresponding data to the upper monitoring computer.
The hardware structure diagram of the monitoring system shows that the system is composed of two independent S7-300 PLC systems. The software redundancies of the monitoring system are as follows: 1) Redundancy of the upper monitor computer and Ethernet line.

4) PROFIBUS Fieldbus network redundancies that include the communication interface, bus connector, and bus cable redundancies.
Redundancy of the communication interface module IM153-2 at the ET200M station. The only thing that the monitoring system fails to achieve redundancy is the I/O module on the ET200M slave station [9] .

Principle of the closed-loop control system for the oil chamber
In the joint station monitoring system, the most core processing piece of equipment is the oil-gas-water three-phase separator. Through it, the oil-water mixture from the oil well is turned into heavy oil, water, and natural gas after the separation process. To make the three-phase separator work normally, it is very important to keep the oil chamber's liquid level constant. Fig. 3 shows a schematic diagram of the oil chamber liquid level closed-loop control system. The liquid level meter sends the measured actual value of the liquid level into the PLC and compares it with the liquid level set value in the PLC. After the PID operation, the error outputs the calculated PID control signal. The signal controls the inverter's output frequency, which controls the motor speed of the output pump through frequency conversion speed regulation so as to realize the flow change of the output pump and keep the liquid level of the oil chamber constant [10] . In the system function module of S7-300, SFB41-SFB43 are mainly used for PID control, and SFB41-43 should be called in OB100 and OB35 of the cycle interruption. In the continuous PID controller SFB41, SFB ' CONT C ' can be used as a single PID constant controller. Or, a cascade controller, hybrid controller, and proportional controller can be realized in multi-closed-loop control [11] .

Design of the BP neural network PID controller
In 1986, Romelhart and Mc-clelland proposed a BP (backpropagation) neural network, which is usually composed of three layers: input layer, hidden layer, and output layer. The two processes of signal forward propagation and error reverse propagation constitute its learning process, which is also its basic principle [12] .

1) Struture detemination of the BP neural netwark
The BP neural network structure adopts a three-layer architecture. Since the liquid level constant control algorithm is designed based on the PID control of the BP neural network, that is, the combination of the BP neural network and PID, the input value of the neural network is set to four, including the input signals of three input layers, which are the specified input rin (k), actual input yout (k), and error value error (k). These input layers correspond to the proportional coefficient (Kp), integral coefficient (Ki), and differential coefficient (Kd) of the PID control law. The middle layer is the hidden layer, and it contains five neurons. The last layer is the output layer, where three neurons are set, corresponding to Kp, Ki, and Kd of the PID controller, as shown in Fig. 4 [13] .

2) Selection of the transfer functions
There are two kinds of activation functions that are commonly used in BP neural networks: the logarithmic Sigmoid function and hyperbolic tangent S-type function. The S-type function is a differentiable function with nonlinear characteristics. Through the analysis of researchers, it was concluded that under the premise of known deviation, the BP neural network adopts the S-type function in the middle layer and the linear function in the output layer and that it can approximate any rational number [14] . So, in this study, the S function was selected as an activation function, and the initial value was determined as a random value between −1 and 1, so each derivation is smaller than the original in the subsequent calculation. When the level is more, the derivation result is that the gradient increases and becomes closer to zero. The activation function of the output layer is as follows. (1)

3) Initialization of neural network weights
The performance of BP neural networks mainly depends on the initialization of neural network weights. In general, the initial values are randomly selected, making the network unreproducible [15] . The selection of neural network weights is related to the activation function used in the network. In this study, the S function was used as the activation function, and the initial value was determined as a random value between −1 and 1. The closer it is to 0, the be er it is. In the subsequent calculation, each derivative is smaller than the original. When there are many levels, the derivative result, i.e., the gradient, is more and more close to 0.

4) Choice of the learning ratio
The value of the learning rate is determined by constantly adjusting the weight threshold in the learning process. In the BP neural network, if the learning rate is too high, serious linearization and decline in stability take place. If the learning rate is too low, both the learning time and cost increase [16] . The specific parameter settings are determined according to the control requirements, according to which the learning rate of this design was found to be 0.3.

5) Calculation of the input and output parameters of the neural network
Through the neural network structure diagram, the calculation formula of the neural network input and output parameters was obtained as follows.

Input layer parameters:
(2) Input-output function of the hidden layer: In the above equation, the upper corner markers (1), (2), and (3) represent the input layer, hidden layer, and output layer, respectively. The lower corner i represents the i neurons of the hidden layer.
Output layer parameter calculation: The standard error function of the minimum variance was selected as the performance index function, which has good stability, low complexity, and a fast calculation speed [17] . (10) In the neural network, the search speed and coefficient correction play a significant role in the control system and produce accurate results. The coefficient correction is mainly weight (W) and bias (B) [18] . To achieve optimal values, various optimization strategies and algorithms are needed to analyze, calculate, and update the network parameters. This design uses the steepest descent method to modify and optimize the coefficient, and the specific calculation is as follows.
The weight of the output layer can be obtained by combining the above equations as follows.
The weight of the hidden layer is calculated as follows.

Struture of the BP network PID control system
The core components of the PID controller based on the BP neural network are the incremental PID controller and BP neural network. The system directly controls the controlled object through closed-loop control. The output of the BP neural network output layer corresponds to the control parameters of the PID controller. It modifies the weighting coefficient through autonomous learning and updating and then adjusts the three parameters of the PID controller in real time, namely Kp, Ki, and Kd, so as to obtain the optimal combination of the parameters of the control system and optimize the control effect of the controller [19] . The details are shown in Fig. 5. The oil chamber's liquid level control algorithm of the three-phase separator of the joint station adopts the threelayer BP neural network joint with incremental PID. The control algorithm flow is shown in Fig. 6.   The BP algorithm can be described as: 1) Determine the BP neural network structure model, initialize the input weight value, and set the learning rate.
2) The obtained actual parameter values are compared with the preset values, and the error signal e is calculated. Then, the input and output parameters of the neurons in each layer are calculated, and the results of the output layer are input into the three parameters corresponding to the PID controller.
3) The PID controller calculates the three parameters of Kp, Ki, and Kd and then obtains the output value of the controller. The output value is transmitted to the actuator, and the liquid level is controlled by the actuator.
4) The weighting coefficient is continuously adjusted according to the control requirements and compared with the expected results. If the requirements are met, the process is terminated, and vice versa.

System simulation
The control system is simulated using MATLAB. The software is powerful and can be used in matrix operation, numerical analysis, signal processing, and artificial intelligence. It is mainly composed of MATLAB language, an AP interface, a graphic processing system, a mathematical library, and a development environment. The mathematical function library of the software is very rich, and it supports the operation of complex matrices in addition to a variety of algorithms. It gathers matrix calculation, system simulation modeling, virtual data visualization, etc. in a userfriendly window interface, which provides great convenience for users. Also, it provides technical support for scientific research and industry.

1) Modeling of the liquid level control system in the oil chamber
The mathematical simulation model of the oil chamber's liquid level control system of the three-phase separator of the joint station was built by Simulink. Due to its hysteresis and time-varying operation, this design selected the second-order system to simulate the liquid level control system. Its transfer function is as follows. (20)

2) Control system smulation and result analysis
Through the MATLAB/Simulink software, a simulation analysis of the oil chamber's liquid level control system, which is based on the BP neural network PID control algorithm, was performed. In the simulation, the advanced function module S-Function of Simulink was introduced, and the S function was written to generate a .m file so that it is convenient to use in Simulink.
A comparison of the simulation curves of the PID control based on the BP neural network and conventional PID control is shown in Fig. 7. It can be seen from the figure that the conventional PID control and BP neural network PID control could eventually make the control system stable. It can be seen from the figure 7. that the control effect of the orange solid line (BP neural network PID) is better than that of the red dotted line (conventional PID). It reduced the overshoot of the system, shortened the adjustment time, and significantly improved the steady state and dynamic performance.

Conclusion
In this study, a novel computer monitoring system was designed for the joint stations used in the oil and gas industry. The system adopts the S7 300 PLC software redundancy autonomous switching technology, which improves its reliability and effectively prevents the failures of control systems, which can be caused by the shutdown of single PLCs.
The BP neural network PID control algorithm was used to realize high-precision constant control of the liquid level of the three-phase separator's oil chamber.
The system was successfully put into operation in the Hanqu Joint Station of Dingbian Oil Production Plant in Shaanxi Province, China. It showed good real-time performance and reliability and led to great economic and social benefits.