Combining Knowledge and a Data Driven Method for Identifying the Gas Kick Type in a Fractured Formation

: The main forms of gas kicks into the wellbore during drilling in fractured carbonate reservoirs are underbalanced pressure and gravity displacement. These two forms of gas kicks have different mechanisms of gas entry into the wellbore and different well control measures, which require the timely identiﬁcation of the type of gas kick when it occurs. A two-phase ﬂow model with a wellbore-formation coupling was developed, based on the gas kick rate models. The variation characteristics of the bottomhole gas inﬂux rate, the wellbore free gas, the bottomhole pressure, the bottomhole pressure change rate, the pit gain and the outlet ﬂow rate during an underbalanced pressure gas kick and a gravity displacement gas kick, were compared and analyzed. Combining the dynamic time warping (DTW) and the wellbore-formation, coupled with a two-phase ﬂow model, an identiﬁcation method of the gas kick type, based on the DTW was proposed. Following the detection of the gas kick, the identiﬁcation is performed by calculating the DTW distance between the surface parameter time series, obtained from the two-phase ﬂow simulation and the surface parameter time series, measured in real time. The ﬁeld example results show that the method can identify the type of gas kick, based on the real-time surface measurement parameters and provide a basis for taking targeted well control measures.


Introduction
As the chemical cementation of the carbonate formation is greater than the mechanical compaction, the genetic mechanism and prediction methods of the abnormal high pressure are different from those of the clastic formation, which makes it difficult to predict the formation pore pressure. When drilling in fractured carbonate gas reservoirs, especially with a narrow safety mud density window, drilling risks, such as a gas kick, are prone to occur, which seriously affects the drilling safety and prolongs the drilling cycle [1]. The formation of a gas kick, in addition to being caused by the negative pressure difference in the underbalanced case, may also be formed by the gravity displacement in the overbalanced case. Due to the different mechanisms of gas kicks, different measures need to be taken, otherwise the operational risk may be increased [2], it often leads to the occurrence of a secondary well kick or blowout, resulting in serious consequences, such as the well destruction, destruction of the oil and gas resources, and pollution of the natural environment. However, a gravity displacement gas kick and an underbalanced pressure gas kick have similar performance characteristics at the surface, both of which show an increase in the pit gain, due to the gas entry into the wellbore, making identification difficult. Researchers have been studying an underbalanced pressure gas kick for a long time and have continuously developed its mechanism and control theory, while the study of a gravity displacement gas kick has only been gradually carried out in recent years.
Some studies performed a sensitivity analysis on the effect of the fracture size, the drilling fluid performance and other parameters on the gas-liquid gravity displacement, based on

Physical Modeling and Characterization of the Gas Kick in Fractured Reservoirs
The different ways of gas entry into the wellbore under different gas kick types will result in different characteristics of both the gas influx rates and the surface measurement parameters. By coupling the bottomhole gas influx rate model and the two-phase flow model of the wellbore, the regular characteristics of the surface measurement parameters, under different gas intrusion types, can be obtained, which provides an identification basis for the gas kick type.  Figure 1 shows the physical model of a two-phase flow in the wellbore annulus, during overflow. In fluid mechanics, fluid motion is generally described using the Eulerian method, which focuses on the state of a specified location in a fixed and immobile space in the wellbore annulus (the space is called the control body). This method analyzes the instantaneous velocity, pressure, density and other parameters of the fluid mass as it passes through the specified location, by studying the variation of the flow volume at the location with time. In turn, the pressure, gas-liquid distribution, gas-liquid velocity, and gas-liquid density in the entire wellbore annulus are obtained. As shown in Figure 1, a micro-element of length a, cross-sectional area A and well slope angle b, are taken as a control body in the wellbore annulus for the study, and the fluid flows from its cross-sectional section S to its cross-sectional section S'.
The different ways of gas entry into the wellbore under different gas kick types will result in different characteristics of both the gas influx rates and the surface measurement parameters. By coupling the bottomhole gas influx rate model and the two-phase flow model of the wellbore, the regular characteristics of the surface measurement parameters, under different gas intrusion types, can be obtained, which provides an identification basis for the gas kick type. Figure 1 shows the physical model of a two-phase flow in the wellbore annulus, during overflow. In fluid mechanics, fluid motion is generally described using the Eulerian method, which focuses on the state of a specified location in a fixed and immobile space in the wellbore annulus (the space is called the control body). This method analyzes the instantaneous velocity, pressure, density and other parameters of the fluid mass as it passes through the specified location, by studying the variation of the flow volume at the location with time. In turn, the pressure, gas-liquid distribution, gas-liquid velocity, and gas-liquid density in the entire wellbore annulus are obtained. As shown in Figure 1, a micro-element of length a, cross-sectional area A and well slope angle b, are taken as a control body in the wellbore annulus for the study, and the fluid flows from its crosssectional section S to its cross-sectional section S'. For establishing a set of control equations for the two-phase flow in the wellbore annulus, during overflow, the conservation laws of mass, momentum and energy are followed, starting from a continuous medium model and the following assumptions. (1) Ignoring the compressibility of the drilling fluid during the circulation drilling; (2) The fluid in the wellbore is flowing along a one-dimensional axial direction, ignoring the radial flow; (3) Ignoring the effect of the rock cuttings, with a gas-liquid two-phase fluid in the wellbore. (4) The temperature and pressure of each phase in the cross section are the same.

Wellbore Two-Phase Flow Model under Well Surge Conditions
The physical model of the continuity equation is built using the conservation law of mass. It is expressed as the mass of fluid flowing into the control body being equal to the mass of fluid flowing out of the control body, plus the change in the mass of fluid within For establishing a set of control equations for the two-phase flow in the wellbore annulus, during overflow, the conservation laws of mass, momentum and energy are followed, starting from a continuous medium model and the following assumptions.
(1) Ignoring the compressibility of the drilling fluid during the circulation drilling; (2) The fluid in the wellbore is flowing along a one-dimensional axial direction, ignoring the radial flow; (3) Ignoring the effect of the rock cuttings, with a gas-liquid two-phase fluid in the wellbore. (4) The temperature and pressure of each phase in the cross section are the same.

Wellbore Two-Phase Flow Model under Well Surge Conditions
The physical model of the continuity equation is built using the conservation law of mass. It is expressed as the mass of fluid flowing into the control body being equal to the mass of fluid flowing out of the control body, plus the change in the mass of fluid within the control body, per unit of time. The continuity equations for the gas and liquid phases are Equations (1) and (2), respectively. The detailed derivation process is given in [23].
∂(ρ l v l AE l ) ∂z where ρ g is the gas phase density, kg/m 3 ; ρ l is the liquid phase density, kg/m 3 ; v g is the gas phase velocity, m/s; v l is the liquid phase velocity, m/s; E g is the true gas holdup; E l is the true liquid holdup; A is the annular cross-sectional area, m 2 .
where g is the acceleration of gravity, m/s 2 ; θ is the angle of inclination of the well, rad; p is the pressure in the annulus, Pa; f r is the flow friction pressure drop, Pa. Following the reservoir gas intrusion into the wellbore, the heat transfer process between the formation and the wellbore fluid becomes non-stationary. According to the law of energy conservation, the difference between the heat inflow per unit time within the control body through the bottom interface and the formation, and the heat outflow through the top and the drill string, is equal to the amount of the heat change within the control body, which can be expressed as Equation (4).
where m g is the gas phase mass flow rate, kg/s; m l is the liquid phase mass flow rate, kg/s; C pg is the specific heat capacity of the gas phase, J/(kg · • C); C pl is the specific heat capacity of the liquid phase, J/(kg · • C); T f is the formation temperature, • C; T a is the annular temperature, • C; T p is the fluid temperature inside the drill string, • C; X is the integrated heat transfer coefficient between the formation and the annulus fluid, J/(kg · • C); Y is the heat transfer coefficient by conduction between the annular fluid and the drill string fluid, J/(kg · • C).

Gas Kick Model
During the gas reservoir drilling, when the bottomhole pressure is lower than the formation pore pressure, the formation gas will enter the wellbore annulus under their differential pressure. Compared with the extraction of gas wells, the differential pressure between the formation pressure and the bottomhole pressure during the gas kick, is much lower than that during the gas extraction, and its isothermal expansion effect is weak, which can be approximated as a Darcy linear flow of the formation of the gas seepage during the gas kick. In addition, since the bottomhole pressure is underbalanced, the influence of the drilling fluid on the permeability of the near-well zone can be ignored. It is known from the literature [11] that the rate of the gas influx into the wellbore can be expressed as Equation (5).
TZµln r e r w (5) where Q SC is the rate of the gas influx into the wellbore at standard conditions, m 3 /d; Q g is the gas flow rate at the temperature and the pressure at the bottom of the well, m 3 /d; K is the permeability of the formation, mD; h is the thickness of the drilled reservoir, m; P e is the formation of the pore pressure, MPa; P wf is the bottomhole pressure, MPa; r e is the radius of the supply boundary, m; r w is the radius of the wellbore, m; µ is the gas viscosity, mPa · s; Z is the gas compressibility factor; T is the formation temperature, K. When drilling in the fractured formations under overbalanced or near balanced conditions, a gravity displacement will occur between the drilling fluid in the annulus and the gas in the formation fractures, due to the density difference between them. The drilling fluid flows into the fracture along the lower wall of the fracture, while the gas influxes into the wellbore along the upper wall, and this process is known as the gravity displacement gas kick. The driving force for the gravity displacement gas kick is the density difference between the drilling fluid and gas. The gas influx rate is affected by parameters, such as the formation porosity, the formation permeability and the wellbore size, as shown in Equation (6). During the gas kick, the formation parameters and the wellbore size remain almost constant, and although the bottomhole pressure decreases continuously with the gas kick, the change in the bottomhole gas density is small in the early stage of the gas kick. Therefore, the gas influx rate of the gravity displacement gas kick can be considered as a constant value. q r = g(K, φ, r w ) (6) where φ is the formation porosity.

Model Solution
A formation-wellbore coupled multiphase flow model is used, and Equations (5) and (6) are used as the bottomhole boundary conditions. Simulations of the underbalanced pressure gas kick and the gravity displacement gas kick are conducted separately, in order to obtain the variation law of the surface measurement parameters under different types of gas kicks. Meanwhile, by analyzing the variation law of the surface measurement parameters, the characteristics of the gas kick under different types of gas kicks are obtained. In addition, the establishment and solution of the formation-wellbore coupled two-phase flow model has been studied extensively by previous authors and have formed a fairly mature theory, which will not be repeated in this paper.

Model Initialization
The initial state of the model is as follows.
where h is depth, m; v sl is the liquid superficial velocity, m/s; Q l is the drilling fluid displacement, L/s.

Characteristics Comparison of the Gas Kicks
The casing programs of well M in the Sichuan Basin and its current bottomhole assembly (BHA) for the open hole are shown in Table 1. The drilling fluid performance and the drilling parameters are shown in Table 2. In addition, the formation permeability is approximately 50 mD, the formation supply radius is approximately 167 m, the wellhead temperature is 20 • C, the geothermal gradient is 0.02 • C/m and the reservoir thickness is approximately 2 m. The underbalanced pressure gas kick simulation is calculated at an initial negative differential pressure of 1.75 MPa (115 MPa for the formation pressure), and a bottomhole gas influx rate of 0.09 m 3 /min is used as the simulation condition for the gravity displacement gas kick. Then, the simulations were carried out using the above parameters, respectively. Figure 2 shows the distribution of the bottomhole gas influx rate for the duration of the gas kick. It can be observed that the gas influx rate of the underbalanced pressure gas kick increases with time, while it remains nearly constant for the gravity displacement gas kick. The underbalanced pressure gas kick simulation is calculated at an initial negative differential pressure of 1.75 MPa (115 MPa for the formation pressure), and a bottomhole gas influx rate of 0.09 m 3 /min is used as the simulation condition for the gravity displacement gas kick. Then, the simulations were carried out using the above parameters, respectively. Figure 2 shows the distribution of the bottomhole gas influx rate for the duration of the gas kick. It can be observed that the gas influx rate of the underbalanced pressure gas kick increases with time, while it remains nearly constant for the gravity displacement gas kick.  Figure 3 illustrates the distribution of the wellbore annular gas holdup for the gravity displacement gas kick and the underbalanced pressure gas kick, when the total influx reaches 2 m 3 . At this moment, the top of the gas-liquid mixed-phase section rises to about 900 m from the bottomhole. The gas holdup distribution for the gravity displacement gas kick shows a slight increase in the gas holdup as the well depth decreases, which is due to the constant gas influx rate at the bottomhole, and the volume expansion caused by the decrease in the annulus pressure during the gas kick rises. In contrast, the distribution of the gas holding rate for the underbalanced pressure gas kick is the opposite of the former, showing that the gas holdup in the shallow part of the wellbore is lower than that in its deeper part. It is attributed to the increasing bottomhole gas influx rate for the underbalanced pressure gas kick, and the fact that the volume expansion effect of the gas, as it rises in the annulus, is much smaller than the increase in the bottomhole gas influx rate.  Figure 3 illustrates the distribution of the wellbore annular gas holdup for the gravity displacement gas kick and the underbalanced pressure gas kick, when the total influx reaches 2 m 3 . At this moment, the top of the gas-liquid mixed-phase section rises to about 900 m from the bottomhole. The gas holdup distribution for the gravity displacement gas kick shows a slight increase in the gas holdup as the well depth decreases, which is due to the constant gas influx rate at the bottomhole, and the volume expansion caused by the decrease in the annulus pressure during the gas kick rises. In contrast, the distribution of the gas holding rate for the underbalanced pressure gas kick is the opposite of the former, showing that the gas holdup in the shallow part of the wellbore is lower than that in its deeper part. It is attributed to the increasing bottomhole gas influx rate for the underbalanced pressure gas kick, and the fact that the volume expansion effect of the gas, as it rises in the annulus, is much smaller than the increase in the bottomhole gas influx rate.
The changes in the bottomhole pressure during the underbalanced pressure gas kick and the gravity displacement gas kick are shown in Figure 4. From the beginning of gas kick to the overflow volume of 2 m 3 , the bottomhole pressure under both types of gas kicks decreases continuously with time, but the decreasing trend is different. As seen in Figure 5, there is a slightly decreasing trend in the absolute value of the change rate of the bottomhole pressure during the gravity displacement gas kick, while it keeps increasing for the underbalanced pressure gas kick. Appl. Sci. 2022, 12, 10912 7 of 16 The changes in the bottomhole pressure during the underbalanced pressure gas kick and the gravity displacement gas kick are shown in Figure 4. From the beginning of gas kick to the overflow volume of 2 m 3 , the bottomhole pressure under both types of gas kicks decreases continuously with time, but the decreasing trend is different. As seen in Figure 5, there is a slightly decreasing trend in the absolute value of the change rate of the bottomhole pressure during the gravity displacement gas kick, while it keeps increasing for the underbalanced pressure gas kick.   The changes in the bottomhole pressure during the underbalanced pressure gas kick and the gravity displacement gas kick are shown in Figure 4. From the beginning of gas kick to the overflow volume of 2 m 3 , the bottomhole pressure under both types of gas kicks decreases continuously with time, but the decreasing trend is different. As seen in Figure 5, there is a slightly decreasing trend in the absolute value of the change rate of the bottomhole pressure during the gravity displacement gas kick, while it keeps increasing for the underbalanced pressure gas kick.     Figure 6 illustrates the variation of the pit gain with time, during the underbalanced pressure gas kick and the gravity displacement gas kick, and their overflow volumes both reach 2 m 3 at 1300 s. It can be seen that the pit gain under the gravity displacement gas kick is approximately a straight line with time, while it presents a curve with time, during the underbalanced pressure gas kick. The change rate of the pit gain with time is the increment of the wellhead outlet flow rate, as shown in Figure 7. The outlet flow rate under the gravity displacement gas kick increases abruptly at the beginning and increases slowly thereafter, while the outlet flow rate tends to increase continuously during the underbalanced pressure gas kick. Therefore, they can be determined, based on the outlet flow rate.  Figure 6 illustrates the variation of the pit gain with time, during the underbalanced pressure gas kick and the gravity displacement gas kick, and their overflow volumes both reach 2 m 3 at 1300 s. It can be seen that the pit gain under the gravity displacement gas kick is approximately a straight line with time, while it presents a curve with time, during the underbalanced pressure gas kick. The change rate of the pit gain with time is the increment of the wellhead outlet flow rate, as shown in Figure 7. The outlet flow rate under the gravity displacement gas kick increases abruptly at the beginning and increases slowly thereafter, while the outlet flow rate tends to increase continuously during the underbalanced pressure gas kick. Therefore, they can be determined, based on the outlet flow rate.

Data-Driven Modeling of the Gas Kick Type Identification
Dynamic time warping (DTW) is a classical similarity analysis and pattern recognition algorithm, which is widely used to solve pattern recognition problems in many fields. In this paper, a recognition model, based on DTW is established for the identification of

Data-Driven Modeling of the Gas Kick Type Identification
Dynamic time warping (DTW) is a classical similarity analysis and pattern recognition algorithm, which is widely used to solve pattern recognition problems in many fields. In this paper, a recognition model, based on DTW is established for the identification of the gas kick types.

DTW Algorithm
For the three time series, X = {x 1 , x 2 , · · · , x i , · · · x k } is the simulated outlet flow rate series of the gravity displacement gas kick, Y = {y 1 , y 2 , · · · , y i , · · · y m } is the simulated outlet flow rate series of the underbalanced pressure gas kick, Z = {z 1 , z 2 , · · · , z i , · · · z n } is the actual measured outlet flow rate series during drilling, and k, m and n are the lengths of the time series X, Y, and Z.
The DTW algorithm uses the dynamic programming principle (DPP) to nonlinearly match the similar features of time series X and Z, Y and Z. The shortest distances, L X-Z and L Y-Z, between time series X and Z, Y and Z are obtained, and L X-Z and L Y-Z are the similarity scales of time series X and Z, Y and Z. If the similarity scale L Y-Z is smaller than L X-Z , it indicates that the matching degree of time series Y and Z is higher than the matching degree of X and Z. That is, the outlet flow curve measured and the outlet flow curve obtained from the underbalanced pressure gas kick simulation, are more similar. Therefore, the gas kick type can be identified as an underbalanced pressure gas kick, otherwise it is a gravity displacement gas kick.
The calculation process of the DTW algorithm consists of two parts: (1) calculating the distance between each element in time series X and Z, forming the distance matrix D m×n (Equations (7) and (8)); (2) using dynamic programming, calculating the cumulative distance matrix T m×n , based on the distance matrix D m×n , and finding the optimal dynamic warping path in T m×n , to obtain the dynamic warping distance between time series X and Z. The specific calculation steps are as follows [24].
where D m×n is the distance matrix, consisting of the square of the Euclidean distance between the elements in time series X and Z.
To find the optimal dynamic warping path, it can be obtained by recursively solving any locally optimal solution in the distance matrix, from the starting point d(x 1 , z 1 ) to the end point d(x m , z n ). Then, the dynamic programming is used to decompose the problem into similar subproblems and to solve the original problem by solving the subproblems, thereby. Using Equation (10) to calculate the local optimal cumulative distance t x i , z j , the cumulative distance matrix is gradually obtained (Equation (9)).
where t(x m , z n ) is the dynamic warping distance L X-Z of time series X and Z.

DTW Based Identification Process of the Gas Kick Type
For fractured reservoirs prone to overflow, the formation-wellbore coupled two-phase flow model is used to simulate and calculate the underbalanced pressure gas kick and gravity displacement gas kick, respectively. Then, the simulated time series of the outlet flow rate is obtained as the reference for judgment. The outlet flow sensor is used to measure the outlet flow rate in real time during the gas kick, and the measurements are converted into the time series to be judged. The DTW algorithm, described in the previous section, to calculate the DTW distance between the reference time series and the time series to be judged, was used to determine the type of gas kick. Figure 8 illustrates the flow of the gas kick type identification, based on DTW.

Results
The casing programs of well L in Tazhong, Xinjiang are shown in Table 3, the drilling fluid performance parameters are given in Table 4. The overflow occurred when drilling to about 6140 m, when the outlet flow rate was 13.5 L/s and the standpipe pressure was 18.7 MPa. Figure 9 shows the outlet flow data, measured in real time during the overflow, and the time series to be judged, composed of the measurements is = { 1 , 2 , ⋯ , , ⋯ , }.

Results
The casing programs of well L in Tazhong, Xinjiang are shown in Table 3, the drilling fluid performance parameters are given in Table 4. The overflow occurred when drilling to about 6140 m, when the outlet flow rate was 13.5 L/s and the standpipe pressure was 18.7 MPa. Figure 9 shows the outlet flow data, measured in real time during the overflow, and the time series to be judged, composed of the measurements is C = {c 1 , c 2 , · · · , c k , · · · , c l }.   The parameters of well L were used for the formation-wellbore coupled two-phase flow simulations, to derive the outlet flow data during the underbalanced pressure gas kick and the gravity displacement gas kick, as shown in Figure 10. The data obtained from the simulation are composed into a time series as the judgment reference, where the reference time series of the underbalanced pressure gas kick is = { 1 , 2 , ⋯ , , ⋯ } and the reference time series of the gravity displacement gas kick is = { 1 , 2 , ⋯ , , ⋯ }. Figure 11 illustrates the time series of the judgment reference time series A and B and time series C, to be judged.  The parameters of well L were used for the formation-wellbore coupled two-phase flow simulations, to derive the outlet flow data during the underbalanced pressure gas kick and the gravity displacement gas kick, as shown in Figure 10. The data obtained from the simulation are composed into a time series as the judgment reference, where the reference time series of the underbalanced pressure gas kick is A = {a 1 , a 2 , · · · , a i , · · · a m } and the reference time series of the gravity displacement gas kick is B = b 1 , b 2 , · · · , b j , · · · b n . Figure 11 illustrates the time series of the judgment reference time series A and B and time series C, to be judged. The parameters of well L were used for the formation-wellbore coupled two-phase flow simulations, to derive the outlet flow data during the underbalanced pressure gas kick and the gravity displacement gas kick, as shown in Figure 10. The data obtained from the simulation are composed into a time series as the judgment reference, where the reference time series of the underbalanced pressure gas kick is = { 1 , 2 , ⋯ , , ⋯ } and the reference time series of the gravity displacement gas kick is = { 1 , 2 , ⋯ , , ⋯ }. Figure 11 illustrates the time series of the judgment reference time series A and B and time series C, to be judged.  The DTW algorithm is used to calculate the DTW distance between time series C an time series A and B at different times, respectively.
(1) The calculation period is 0 to 600 s Table 5 displays the DTW distances between any two of the above three time serie before 600s. As can be seen from Table 5, the DTW distance LA-C between time series A an C is 7.3, and the DTW distance LB-C between time series B and C is 7.53. Although th similarity between sequence C and sequence A is greater than that between sequence and sequence C, the gap between them is small. In order to ensure accuracy, subsequen data changes need to be calculated. (2) The calculation period is 0 to 1000 s Table 6 displays the DTW distances between any two of the above three time serie As can be seen from Table 5, the DTW distance LA-C between time series A and C is 7.68 and the DTW distance LB-C between time series B and C is 11.62. The similarity betwee sequence C and sequence A is greater than that between sequence B and sequence C. can be preliminarily judged that the kick type is an underbalanced pressure gas kick. the well is not shut in at this time, the corresponding dynamic time warping distance ca be calculated later to improve the judgment accuracy. The DTW algorithm is used to calculate the DTW distance between time series C and time series A and B at different times, respectively.
(1) The calculation period is 0 to 600 s Table 5 displays the DTW distances between any two of the above three time series before 600s. As can be seen from Table 5, the DTW distance L A-C between time series A and C is 7.3, and the DTW distance L B-C between time series B and C is 7.53. Although the similarity between sequence C and sequence A is greater than that between sequence B and sequence C, the gap between them is small. In order to ensure accuracy, subsequent data changes need to be calculated. (2) The calculation period is 0 to 1000 s Table 6 displays the DTW distances between any two of the above three time series. As can be seen from Table 5, the DTW distance L A-C between time series A and C is 7.68, and the DTW distance L B-C between time series B and C is 11.62. The similarity between sequence C and sequence A is greater than that between sequence B and sequence C. It can be preliminarily judged that the kick type is an underbalanced pressure gas kick. If the well is not shut in at this time, the corresponding dynamic time warping distance can be calculated later to improve the judgment accuracy. (3) The calculation period is 0 to 1300 s Table 7 displays the DTW distances between any two of the above three time series. As can be seen from Table 7, the DTW distance L A-C between time series A and C is 8.25, and the DTW distance L B-C between time series B and C is 20.66. There is a higher similarity between the measured time series C and the time series of the simulated underbalanced pressure gas kick. Therefore, the type of gas kick is judged to be the underbalanced pressure gas kick, and the results are consistent with the actual drilling conditions.

Discussions
(1) Comparison with the current method At present, the type of gas kick can be judged by changing the wellhead back pressure, during managed pressure drilling. As the underbalanced gas kick is mainly affected by the bottomhole pressure, and the bottomhole pressure has little effect on the gravity displacement gas kick. By increasing the wellhead back pressure, after the bottomhole pressure state changes from underbalanced to overbalanced, the underbalanced gas kick will no longer occur, and the outlet flow will gradually decrease, while the gravity displacement gas kick will maintain the original intrusion rate, the outlet flow will continue to increase. In [12], the wellhead back pressure increased by 3.4MPa at 1300s after the kick was detected on the ground. It was observed that the outlet flow was equal to the inlet flow after a lag time of about 7 h, and judged as an underbalanced gas kick.
Compared with the existing methods, the method proposed in this paper does not need to wait for a lag time, and there is no need to adjust the wellhead backpressure, and the fine outlet flow measurement is not required, which is not only suitable for managed pressure drilling but also for conventional drilling.
(2) DTW Computational Feature Analysis From the calculation results in Tables 5-7, it can be seen that, according to the increase of time series data, the judgment effect is better. Note that Tables 5-7 reveal the characteristics of DTW, where the DTW distance between the same time series is 0, indicating that the same time series is perfectly similar. The maximum DTW distance between time series A and B indicates the least similarity between the outlet flow rate of the underbalanced pressure gas kick and the gravity displacement gas kick. Meanwhile, it indirectly demonstrates that there is a difference in the presentation between an underbalanced pressure gas kick and a gravity displacement gas kick, and they can be identified using DTW algorithms.

Conclusions
(1) Based on the transient two-phase drift flow model with wellbore-formation coupling, the changes of the bottomhole pressure, gas holdup distribution and wellhead flow parameters during an underbalanced pressure gas kick and gravity displacement gas kick, are simulated and analyzed. Although both exhibit an increase in pit gain and a decrease in bottomhole pressure, there is a difference in the rate of change in the bottomhole pressure and pit gain. (2) The DTW algorithm is used to calculate the DTW distance between the measured outlet flow curve and the simulated curve, and the degree of similarity between them can be obtained. Then, the similarity between the curves is used to identify the type of gas kick. By using the feature, is it understood that the underbalanced pressure gas kick and gravity displacement gas kick present different characteristics on the outlet flow curve. With the increase of time series data, the judgment effect is better. (3) The method proposed in this paper can greatly reduce the identification time, and the dependence on drilling equipment is not high, which is not only suitable for managed pressure drilling but also for conventional drilling. Institutional Review Board Statement: Not applicable.