A mechanism and data double-constrained drilling gas invasion early warning method and device

By fusing a wellbore hydraulic model with a physical information neural network, downhole virtual sensing data is generated and graded early warnings are provided. This solves the problems of slow response, high cost, and high false alarm rate in drilling gas invasion early warning, and enables early and accurate early warning under complex working conditions in deep wells.

CN122511031APending Publication Date: 2026-08-04CHINA UNIV OF PETROLEUM (BEIJING)
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA UNIV OF PETROLEUM (BEIJING)
Filing Date
2026-04-23
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

Existing drilling gas invasion early warning methods are slow to respond, costly, have insufficient applicability, and have a high false alarm rate, making it difficult to achieve early and accurate early warning.

Method used

By fusing downhole virtual sensing data generated by a wellbore hydraulic model with ground-based measured data at the wellhead, a physical information neural network is trained to establish a gas intrusion early warning and prediction model. A comprehensive anomaly index is generated by combining physical errors and data reconstruction errors for graded early warning.

Benefits of technology

It enables early and accurate gas intrusion warnings under complex deep well conditions, reduces implementation costs, improves the timeliness and interpretability of warnings, and provides a clear assessment of risk levels.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122511031A_ABST
    Figure CN122511031A_ABST
Patent Text Reader

Abstract

The application discloses a kind of mechanism and data double-constrained drilling gas invasion early warning method and device, comprising: drilling engineering parameter is input to wellbore hydraulics model, generates virtual sensing data in well, and with wellhead ground measured data fusion forms multi-source fusion data, multi-source fusion data are used to train physical information neural network, and gas invasion early warning prediction model is obtained;Real-time fusion feature vector is input to gas invasion early warning prediction model, and wellhead pressure prediction value is output;According to wellhead pressure prediction value and wellhead ground measured data calculation physical error, and wellhead ground measured data are input to self-encoder calculation data reconstruction error, and physical error and data reconstruction error are fused into comprehensive anomaly index;Comprehensive anomaly index is compared with preset grading early warning threshold value, to carry out drilling gas invasion grading early warning according to comparison result.The application can realize complex drilling gas invasion risk early, accurate, reliable early warning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of oil and gas drilling technology, and in particular to a drilling gas invasion early warning method and device with dual constraints of mechanism and data. Background Technology

[0002] Drilling is a key means of oil and gas resource exploration and development. Gas intrusion in the wellbore is a major cause of major safety accidents such as well kicks and blowouts. Early and accurate warning of gas intrusion risks is of vital engineering significance for ensuring the safety of drilling operations.

[0003] Existing gas invasion early warning methods mainly suffer from the following problems: First, traditional early warning methods based on single or a few parameters such as inlet and outlet flow rates and mud pit volume have slow response speeds and are difficult to meet the needs of real-time early warning. Second, methods based on downhole measurement equipment are costly and prone to failure in complex working conditions such as deep wells and ultra-deep wells, limiting their applicability. Third, traditional mechanistic models have low computational efficiency and usually can only detect obvious anomalies in the middle and late stages of gas invasion, missing the opportunity for early control. Fourth, existing data-driven models have poor interpretability, are easily affected by noise, and have a high false alarm rate.

[0004] There is currently no effective solution to the above problems. Summary of the Invention

[0005] This specification provides a drilling gas invasion early warning method and device with dual constraints of mechanism and data to solve the problems of lagging gas invasion early warning, high false alarm rate and insufficient adaptability to complex deep well conditions in the prior art.

[0006] Firstly, embodiments of this specification provide a drilling gas invasion early warning method with dual constraints of mechanism and data, including: Drilling engineering parameters are input into the wellbore hydraulic model to generate downhole virtual sensing data, which is then fused with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas intrusion early warning and prediction model. The real-time fused feature vector is input into the gas invasion early warning prediction model, and the wellhead pressure prediction value is output. The real-time fused feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. The physical error is calculated based on the predicted wellhead pressure and the measured wellhead surface data. The measured wellhead surface data is then input into an autoencoder to calculate the data reconstruction error. The physical error and the data reconstruction error are then combined into a comprehensive anomaly index. The comprehensive anomaly index is compared with a preset graded early warning threshold to conduct graded early warning of drilling gas invasion based on the comparison results.

[0007] In some embodiments, the drilling engineering parameters include at least one of the following: wellbore structure parameters, drill string assembly parameters, drilling process parameters, boundary condition parameters, and time control parameters; the wellbore structure parameters include at least one of the following: total well depth, wellbore diameter of each grid node, well inclination angle of each grid node, and well depth node spacing; the drill string assembly parameters include at least one of the following: outer diameter of each grid node drill string and inner diameter of each grid node drill string; the drilling process parameters include fluid property parameters, drilling fluid thermal property parameters, and flow rate; the fluid property parameters include at least one of the following: initial density of drilling fluid and initial plastic viscosity of drilling fluid; the drilling fluid thermal property parameters include at least one of the following: initial specific heat at constant pressure of drilling fluid and initial thermal conductivity of drilling fluid; the boundary condition parameters include at least one of the following: measured casing pressure at the wellhead, measured standpipe pressure at the wellhead, and measured outlet flow rate at the wellhead; the time control parameters include at least one of the following: target time period and time step. The downhole virtual sensing data includes at least one of the following: bottom hole virtual pressure, bottom hole virtual temperature, and casing shoe position virtual pressure; The measured surface data at the wellhead includes at least one of the following: measured riser pressure at the wellhead, measured casing pressure at the wellhead, measured drilling fluid injection rate, measured wellhead outlet flow rate, and measured drilling fluid inlet temperature.

[0008] In some embodiments, the wellbore hydraulic model is composed of governing equations, which include mass conservation equations, momentum conservation equations, and energy conservation equations. Accordingly, the step of inputting drilling engineering parameters into the wellbore hydraulic model to generate downhole virtual sensing data includes: Based on the input drilling engineering parameters, the wellbore is discretized into a preset number of grid nodes along the well depth direction. The preset number is determined according to the ratio of the total well depth to the well depth node spacing. The mass conservation equation, momentum conservation equation, and energy conservation equation are respectively transformed into discrete difference equations on each grid node; The temperature and pressure distribution of the entire wellbore in the previous time step is obtained as the initial condition for the current time step. Starting from the bottom grid node, the discrete difference equations of the mass conservation equation, momentum conservation equation and energy conservation equation are solved iteratively from bottom to top, with the initial temperature and pressure at the bottom of the well as the starting point of the iteration, to obtain the temperature and pressure of each grid node. The fluid property parameters of the corresponding grid nodes are updated according to the temperature and pressure of each grid node. The updated fluid property parameters are used as the input for solving the temperature and pressure of the adjacent upper grid nodes until the wellhead grid node is solved, so as to obtain the whole wellbore temperature and pressure distribution at the current time step. The whole wellbore temperature and pressure distribution includes the wellhead pressure. The wellhead pressure is compared with the measured wellhead pressure. If the error comparison result is greater than the preset error threshold, the initial temperature and pressure at the bottom of the well are adjusted, and the solution is iterated from bottom to top, grid node by grid node, until the calculation of all time steps within the target time period is completed, and the temperature and pressure distribution of the entire wellbore for all time steps within the target time period is output. The temperature and pressure at key locations are extracted from the temperature and pressure distribution of the entire wellbore at all time steps within the target time period, and used as the downhole virtual sensing data.

[0009] In some embodiments, the step of iteratively solving the discrete difference equations of the mass conservation equation, momentum conservation equation, and energy conservation equation from bottom to top, node by node, includes: Substitute the updated fluid properties of the lower grid nodes into the discrete difference equation of the mass conservation equation to obtain the density of the current grid node. The pressure of the current grid node is obtained by substituting the density of the current grid node, the pressure of the grid node below it, and the updated fluid properties into the discrete difference equation of the momentum conservation equation. The current grid node's pressure, the temperature of the grid node below it, and the updated fluid properties are all substituted into the discrete difference equation of the energy conservation equation to obtain the temperature of the current grid node. The pressure and temperature obtained from solving the current grid node are substituted into the property update equation to update the fluid property parameters of the current grid node. The density, pressure, temperature of the current grid node and the updated fluid property parameters are used together as the solution input for the adjacent grid nodes above.

[0010] In some embodiments, the air intrusion early warning prediction model includes an input layer, a neural network body, an automatic differentiation module, a physical constraint module, and an output layer, wherein the physical constraint layer has built-in mass conservation equations and momentum conservation equations; Accordingly, the step of fusing feature vectors into the gas invasion early warning prediction model in real time and outputting wellhead pressure prediction values ​​includes: The system receives the real-time fused feature vector through the input layer; processes the real-time fused feature vector through the neural network body to output the predicted pressure field of the entire wellbore; calculates the partial derivatives of the predicted pressure field of the entire wellbore with respect to spatial coordinates and time through the automatic differentiation module; calculates the residuals of the mass conservation equation and the momentum equation based on the partial derivatives through the physical constraint module as the physical equation residuals, and determines that the model has converged when the physical equation residuals are less than a preset convergence threshold; and extracts the pressure value at the wellhead position from the predicted pressure field through the output layer as the predicted wellhead pressure value.

[0011] In some embodiments, calculating the residuals of the mass conservation equation and the momentum equation based on the partial derivatives as the residuals of the physical equations includes: The partial derivatives of the whole-wellbore predicted pressure field and the whole-wellbore predicted pressure field output by the automatic differentiation module with respect to spatial coordinates and time are substituted into the mass conservation equation and momentum conservation equation built into the physical constraint module, respectively, to calculate the actual predicted values ​​of the mass conservation equation and the momentum conservation equation. The deviation between the actual predicted value and the theoretical value of the mass conservation equation is defined as the residual of the mass conservation equation. The deviation between the actual predicted value and the theoretical value of the momentum conservation equation is defined as the momentum conservation equation residual. The residuals of the mass conservation equation and the momentum conservation equation are weighted and summed to obtain the residuals of the physical equation.

[0012] In some embodiments, the step of inputting the wellhead surface measured data into the self-compiler to calculate the data reconstruction error includes: The measured surface data at the wellhead is used as the raw input data and compressed into low-dimensional feature codes by the encoder part of the autoencoder. The decoder part of the autoencoder reconstructs the data based on the low-dimensional feature encoding to obtain the reconstructed data. The deviation between the original input data and the reconstructed data is calculated to obtain the data reconstruction error, which is used to characterize the degree of abnormality of the fluctuation of the wellhead surface measured data. The fusion is a comprehensive anomaly index, including: The data reconstruction error is normalized to obtain the normalized reconstruction error, and the physical equation residual is normalized to obtain the normalized physical residual. The normalized reconstruction error and the normalized physical residual are weighted and fused to obtain the comprehensive anomaly index.

[0013] In some embodiments, comparing the comprehensive anomaly index with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison result includes: The comprehensive anomaly index is compared sequentially with the first warning threshold, the second warning threshold, and the third warning threshold. If the comprehensive abnormal index is less than the first warning threshold, it is determined to be a normal operating condition; If the comprehensive abnormal index is greater than or equal to the first warning threshold and less than the second warning threshold, it is judged as a mild air intrusion. If the comprehensive anomaly index is greater than or equal to the second warning threshold and less than the third warning threshold, it is judged as a moderate air intrusion; If the comprehensive abnormal index is greater than or equal to the third warning threshold, it is judged as a severe air intrusion; Based on the determined level, a corresponding graded early warning signal is output.

[0014] Secondly, embodiments of this specification also provide a drilling gas invasion early warning device with dual constraints of mechanism and data, comprising: The first fusion module is used to input drilling engineering parameters into the wellbore hydraulic model, generate downhole virtual sensing data, and fuse it with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas intrusion early warning and prediction model. The prediction module is used to input the real-time fused feature vector into the gas invasion early warning prediction model and output the wellhead pressure prediction value. The real-time fused feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. The second fusion module is used to calculate the physical error based on the predicted wellhead pressure and the measured wellhead surface data, input the measured wellhead surface data into the autoencoder to calculate the data reconstruction error, and fuse the physical error and the data reconstruction error into a comprehensive anomaly index. The graded early warning module is used to compare the comprehensive anomaly index with a preset graded early warning threshold, so as to perform graded early warning of drilling gas invasion based on the comparison result.

[0015] Thirdly, embodiments of this specification also provide a computer-readable storage medium storing computer program instructions thereon, which, when executed by a processor, implement the steps of the aforementioned drilling gas invasion early warning method with dual constraints of mechanism and data.

[0016] This specification provides a drilling gas invasion early warning method and device with dual constraints of mechanism and data. First, drilling engineering parameters are input into a wellbore hydraulic model to generate downhole virtual sensing data, which is then fused with wellhead surface measurement data to form multi-source fusion data. This multi-source fusion data is used to train a physical information neural network to obtain a gas invasion early warning prediction model. Next, a real-time fused feature vector is input into the gas invasion early warning prediction model to output a wellhead pressure prediction value. The real-time fused feature vector includes the real-time generated downhole virtual sensing data and the real-time collected wellhead surface measurement data. Then, a physical error is calculated based on the wellhead pressure prediction value and the wellhead surface measurement data. The wellhead surface measurement data is then input into an autoencoder to calculate a data reconstruction error. The physical error and the data reconstruction error are fused into a comprehensive anomaly index. Finally, the comprehensive anomaly index is compared with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison results. In the embodiments described in this specification, virtual downhole sensing data is generated through a wellbore hydraulic model, solving the problem of the difficulty in directly measuring key downhole parameters. This avoids reliance on expensive and easily malfunctioning downhole measurement equipment, reduces implementation costs, and improves applicability in complex conditions such as deep and ultra-deep wells. Simultaneously, fusing virtual data with measured data provides a multi-source data foundation containing downhole physical information for model training, compensating for the shortcomings of solely relying on insufficient information from surface measured data. By using the trained gas invasion early warning prediction model to predict wellhead pressure in advance, abnormal trends can be detected before significant changes occur in parameters during the early stages of gas invasion, solving the problems of delayed warnings and slow response in traditional methods and meeting the timeliness requirements of real-time early warning. By calculating the physical error based on the predicted wellhead pressure value and the surface measured data, physical deviations caused by gas invasion can be identified, providing a data-independent physical criterion for anomaly identification and enhancing the interpretability of the model. Data reconstruction errors can identify abnormal fluctuations in the data itself. By integrating these two factors into a comprehensive anomaly index, dual verification of physical and data-based criteria can be achieved, effectively solving the problems of single-criteria susceptibility to noise interference and high false alarm rates. A tiered early warning mechanism provides on-site personnel with a clear assessment of risk levels, facilitating timely implementation of differentiated control measures based on risk levels, thus improving the practicality and operability of early warning information. Through the above scheme, early, accurate, and reliable early warning of complex drilling gas invasion risks is achieved. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a flowchart illustrating a drilling gas invasion early warning method with dual constraints of mechanism and data provided in the embodiments of this specification; Figure 2 This is a flowchart of the well hydraulic model solution provided in the embodiments of this specification; Figure 3 This is a schematic diagram of the physical information neural network model structure provided in the embodiments of this specification; Figure 4 This is a schematic diagram of the self-encoder multi-level early warning model structure provided in the embodiments of this specification; Figure 5 This is a schematic diagram of the overall framework provided in the embodiments of this specification; Figure 6 This is a schematic diagram of the structural composition of a drilling gas invasion early warning device with dual constraints of mechanism and data provided in the embodiments of this specification; Figure 7 This is a schematic diagram of the structural composition of the electronic device provided in the embodiments of this specification. Detailed Implementation

[0018] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.

[0019] Drilling is the only direct means of obtaining oil and gas resources. During drilling, when the pressure of the encountered oil and gas reservoir is higher than the bottom hole pressure, or when there are flow channels such as fractures or caves in the formation that connect to the wellbore, gas from the formation can enter the wellbore and mix with the annular drilling fluid, forming gas intrusion. Gas intrusion causes the drilling fluid to become contaminated with gas, reducing its density and weakening the annular fluid column pressure, making it difficult to effectively balance the bottom hole pressure and causing the wellhead fluid pressure to rise. If not controlled in time, this complex situation will further intensify and may induce serious accidents such as well kicks and blowouts. Currently, commonly used gas intrusion control methods include single circulation, double circulation, simultaneous circulation and weighting, annular push-and-kill, and pressure circulation, but regardless of the method used, a certain amount of time is required for treatment. Practice has shown that the earlier the gas intrusion risk is detected and the more timely the treatment, the lower the difficulty of control. Once gas intrusion develops into a well kick or blowout, only emergency measures such as forced well control can be taken, which is not only difficult to handle and seriously harmful, but also seriously threatens drilling safety and delays the construction progress. Therefore, research on early warning methods for air intrusion risk has significant practical implications and engineering value.

[0020] To obtain gas intrusion signals earlier and more accurately, some studies have attempted to combine monitoring of annular and downhole temperature and pressure parameters with drilling equipment for early warning. Examples include methods based on annular temperature measurement sensors, annular pressure measurement while drilling, drill bit measurement while drilling based on density conductivity, annular fluid parameter monitoring based on density sound velocity, and resistivity monitoring while drilling. However, these methods require instruments to withstand complex formation environments, especially under high temperature and pressure conditions, which have a significant impact on the equipment. Furthermore, their high cost limits their large-scale application.

[0021] Subsequently, the relatively low-cost integrated data method gradually became a research hotspot. This type of method mainly uses physical models to comprehensively process multi-dimensional data such as logging data, flow monitoring data, and fluid level, which greatly improves accuracy and real-time performance. However, the response speed is still not sensitive enough in deep wells and complex working conditions.

[0022] With the rapid development of computing power and artificial intelligence technology, gas intrusion early warning methods based on the fusion of artificial intelligence and integrated well logging data have attracted increasing attention. However, existing intelligent early warning models still need further improvement in terms of timeliness, accuracy, and interpretability.

[0023] To address the aforementioned issues, this specification provides a drilling gas intrusion early warning method and device with dual constraints of mechanism and data. Taking advantage of the Physics-Informed Neural Network (PINN)'s ability to effectively integrate physical laws and data-driven approaches, a downhole virtual sensor is constructed using a hydraulic mechanism model. This sensor generates downhole virtual sensing data and establishes a hybrid mechanism-data database (i.e., multi-source fusion data) that fuses surface and downhole data. This database is used to train the PINN model, enabling advanced and high-precision prediction of wellhead pressure. Furthermore, physical errors are calculated based on the predicted wellhead pressure and measured surface data. A comprehensive anomaly coefficient is generated by fusing physical errors and data reconstruction errors as dual criteria, enabling graded alarms for gas intrusion risk. This invention provides effective technical support for drilling parameter optimization and drilling safety improvement.

[0024] It should be noted that in the embodiments of this specification, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that this application has used or necessarily used such a solution.

[0025] See Figure 1 As shown in the embodiments of this specification, a drilling gas invasion early warning method with dual constraints of mechanism and data is provided. In specific implementation, the method may include the following: S101: Input drilling engineering parameters into the wellbore hydraulic model to generate downhole virtual sensing data, and fuse it with the wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train the physical information neural network to obtain the gas invasion early warning and prediction model.

[0026] In some embodiments, the drilling engineering parameters in S101 above may include at least one of the following: wellbore structure parameters, drill string assembly parameters, drilling process parameters, boundary condition parameters, and time control parameters; the wellbore structure parameters may include at least one of the following: total well depth, wellbore diameter of each grid node, well inclination angle of each grid node, and well depth node spacing; the drill string assembly parameters may include at least one of the following: outer diameter of each grid node drill string and inner diameter of each grid node drill string; the drilling process parameters may include fluid property parameters, drilling fluid thermal property parameters, and flow rate; the fluid property parameters may include at least one of the following: initial density of drilling fluid and initial plastic viscosity of drilling fluid; the drilling fluid thermal property parameters may include at least one of the following: initial specific heat at constant pressure of drilling fluid and initial thermal conductivity of drilling fluid; the boundary condition parameters may include at least one of the following: measured casing pressure at the wellhead, measured standpipe pressure at the wellhead, and measured outlet flow rate at the wellhead; the time control parameters may include at least one of the following: target time period and time step.

[0027] Specifically, wellbore structural parameters describe the geometry of the wellbore, and may include the total well depth Z. total Wellbore diameter D of each grid node i Inclination angle of each grid node Well depth node spacing Well depth node spacing It is the distance between two adjacent grid nodes when discretized along the well depth direction. Its value affects the calculation accuracy and efficiency, and can be set according to engineering needs.

[0028] Drill string assembly parameters describe the geometric characteristics of the drill string and may include the drill string outer diameter d of each grid node. p,i d of the drill bit at each grid node i,i These parameters are used to determine the geometry of the flow channels within the drill pipe and the flow channels in the annulus (between the wellbore and the drill string), and are the basis for calculating the flow area and hydraulic diameter.

[0029] Drilling process parameters describe the properties of the drilling fluid and the operating conditions, and may include fluid properties, drilling fluid thermophysical properties, and flow rate Q. Among these, fluid properties may include the initial density of the drilling fluid. Initial plastic viscosity of drilling fluid Drilling fluid thermophysical properties can include the initial isobaric specific heat of the drilling fluid. Initial thermal conductivity of drilling fluid The fluid properties will be dynamically adjusted with changes in temperature and pressure in the subsequent property update equations.

[0030] Boundary condition parameters may include the measured casing pressure P at the wellhead. cas (t), measured riser pressure at wellhead P surf (t), measured wellhead outlet flow rate Q out These parameters are important bases for model convergence verification and iterative solution.

[0031] Time control parameters can include the target time period t total The time step Δt can be used to control the time range and accuracy of transient calculations.

[0032] In some embodiments, the well hydraulic model in S101 above is composed of governing equations, which may include mass conservation equations, momentum conservation equations and energy conservation equations. Accordingly, the step of inputting drilling engineering parameters into the wellbore hydraulic model in S101 above to generate downhole virtual sensing data can, in specific implementation, include: Based on the input drilling engineering parameters, the wellbore is discretized into a preset number of grid nodes along the well depth direction. The preset number is determined according to the ratio of the total well depth to the well depth node spacing. The mass conservation equation, momentum conservation equation, and energy conservation equation are respectively transformed into discrete difference equations on each grid node; The temperature and pressure distribution of the entire wellbore in the previous time step is obtained as the initial condition for the current time step. Starting from the bottom grid node, the discrete difference equations of the mass conservation equation, momentum conservation equation and energy conservation equation are solved iteratively from bottom to top, with the initial temperature and pressure at the bottom of the well as the starting point of the iteration, to obtain the temperature and pressure of each grid node. The fluid property parameters of the corresponding grid nodes are updated according to the temperature and pressure of each grid node. The updated fluid property parameters are used as the input for solving the temperature and pressure of the adjacent upper grid nodes until the wellhead grid node is solved, so as to obtain the whole wellbore temperature and pressure distribution at the current time step. The whole wellbore temperature and pressure distribution includes the wellhead pressure. The wellhead pressure is compared with the measured wellhead pressure. If the error comparison result is greater than the preset error threshold, the initial temperature and pressure at the bottom of the well are adjusted, and the solution is iterated from bottom to top, grid node by grid node, until the calculation of all time steps within the target time period is completed, and the temperature and pressure distribution of the entire wellbore for all time steps within the target time period is output. The temperature and pressure at key locations are extracted from the temperature and pressure distribution of the entire wellbore at all time steps within the target time period, and used as the downhole virtual sensing data.

[0033] In some embodiments, the above-described bottom-up, node-by-node iterative solution of the discrete difference equations for the mass conservation equation, momentum conservation equation, and energy conservation equation may, in specific implementation, include: Substitute the updated fluid properties of the lower grid nodes into the discrete difference equation of the mass conservation equation to obtain the density of the current grid node. The pressure of the current grid node is obtained by substituting the density of the current grid node, the pressure of the grid node below it, and the updated fluid properties into the discrete difference equation of the momentum conservation equation. The current grid node's pressure, the temperature of the grid node below it, and the updated fluid properties are all substituted into the discrete difference equation of the energy conservation equation to obtain the temperature of the current grid node. The pressure and temperature obtained from solving the current grid node are substituted into the property update equation to update the fluid property parameters of the current grid node. The density, pressure, temperature of the current grid node and the updated fluid property parameters are used together as the solution input for the adjacent grid nodes above.

[0034] Specifically, the wellbore hydraulic model in S101 above consists of governing equations, which may include the mass conservation equation, momentum conservation equation, and energy conservation equation. These three equations describe the laws of mass conservation, momentum conservation, and energy conservation in the fluid flow and heat transfer process within the wellbore, and form the theoretical basis of wellbore hydraulics.

[0035] The specific process of using a wellbore hydraulic model to process drilling engineering parameters and generate downhole virtual sensing data can be summarized as follows: S1, Wellbore mesh discretization Based on the input drilling engineering parameters, the wellbore can be discretized into a preset number of grid nodes along the well depth direction. The preset number can be determined according to the total well depth Z. total Spacing between well depth nodes The ratio is determined, for example:

[0036] Where N is the total number of wellbore grid nodes (i.e., the preset number mentioned above). Each grid node corresponds to a calculation location.

[0037] By discretizing the grid, the wellbore space is transformed into a discrete computational domain from the bottom of the well (i=1) to the top of the well (i=N).

[0038] S2, Discretization of the governing equations

[0039] The mass conservation equation, momentum conservation equation, and energy conservation equation are transformed into discrete difference equations applicable to each grid node, so that they can be solved iteratively node by node in a bottom-up order.

[0040] S3, Determination of initial temperature and pressure at the bottom of the well.

[0041] The iteration starts from i=1 at the bottom of the well, with the initial temperature and pressure at the bottom of the well as the starting point for the iteration. The initial pressure at the bottom of the well can be determined based on the measured riser pressure P at the wellhead. surf (t), combined with the pressure drop due to gravity of the liquid column, the bottom pressure inside the drill pipe is calculated, and it is assumed that the pressure inside and outside the drill pipe at the bottom is equal. This calculated value is used as the initial pressure condition at the bottom of the well.

[0042] S4. Solve iteratively node by node from bottom to top.

[0043] The temperature and pressure distribution of the entire wellbore from the previous time step is used as the initial condition for the current time step. Starting from the bottom node, the three major conservation equations are solved sequentially from bottom to top, node by node, to obtain the density, pressure, and temperature of the current grid node. (That is: given the bottom boundary conditions (such as the initial pressure at the drill bit), combined with the temperature and pressure distribution of the entire wellbore from the previous time step, starting from the first node at the bottom of the well, the pressure and temperature of adjacent nodes are solved sequentially using the discretized difference equations. For each node solved, the fluid properties (density, viscosity, etc.) of that node are updated. This process is repeated upwards through all nodes until the wellhead node, to obtain the temperature and pressure distribution of the entire wellbore at the current time step.)

[0044] S41. Solving the mass conservation equation

[0045] Substitute the updated fluid property parameters of the lower grid node i-1 into the mass conservation discrete difference equation (i.e., the discrete difference equation of the mass conservation equation above) to obtain the density of the current grid node i. The mass conservation discrete difference equation can be defined as follows:

[0046] in, Let be the density (drilling fluid density) of the current grid node i at the nth time step, and be the output parameter to be solved in this equation; Let be the density of the current grid node i at the (n-1)th time step, and be the historically known parameters; The drilling fluid density at time step n, updated at the lower grid node i-1, is derived from the fluid property parameters updated by the lower grid node. Let be the fluid velocity at the current grid node i at time step n, which is determined by the drilling fluid discharge rate Q and the node flow area. Calculation yields ( , ); Let i be the fluid velocity at the lower grid node i-1 at time step n; The time step is a time control parameter derived from the drilling engineering parameters; The well depth node spacing is derived from the wellbore structure parameters in the drilling engineering parameters.

[0047] S42. Solving the Momentum Conservation Equation

[0048] Substituting the density of the current grid node i, the pressure already solved for at the lower grid node i-1, and the updated fluid properties into the momentum conservation discrete difference equation (the discrete difference equation of the momentum conservation equation), the pressure of the current grid node i can be obtained. The mass conservation discrete difference equation can be as follows:

[0049] in, Let be the pressure at the current grid node i at time step n, and be the output parameters to be solved in this equation. The pressure at the lower grid node i-1 at time step n; is the drilling fluid density updated at the lower grid node i-1 at time step n, derived from the fluid property parameters updated by the lower grid node; g is the gravitational acceleration. The well inclination angle of the i-th grid node is derived from the well structure parameters; Let be the density of the current grid node i at time step n; Let be the fluid velocity at the current grid node i at time step n; Let i be the fluid velocity at the lower grid node i-1 at time step n; The frictional voltage drop per unit length at the i-th grid node; The distance between nodes is the depth of the well.

[0050] in, The frictional pressure drop per unit length of the i-th grid node is based on the equivalent hydraulic diameter of the i-th grid node. Friction factor f (determined based on Reynolds number Re), fluid density at time step n, and updated at grid node i-1. and the fluid velocity at the nth time step and the i-th grid node The specific calculation formula is as follows: .

[0051] S43. Solving the energy conservation equation

[0052] Substituting the pressure of the current grid node i, the solved temperature of the lower grid node i-1, and the updated fluid properties into the energy conservation difference equation (the discrete difference equation of the energy conservation equation), the temperature of the current grid node is obtained. The energy conservation difference equation can be as follows:

[0053] in, Let be the temperature of the current grid node i at the nth time step, and be the output parameter to be solved in this equation; , These are the temperatures of the grid nodes i-1 and i-2 below, respectively. The drilling fluid density at time step n, updated at the lower grid node i-1, is derived from the fluid property parameters updated by the lower grid node. The initial isobaric specific heat of the drilling fluid is derived from drilling process parameters; The initial thermal conductivity of the drilling fluid is derived from drilling process parameters; Let be the fluid velocity at the current grid node i at time step n; The frictional voltage drop per unit length at the i-th grid node; The distance between nodes is the depth of the well.

[0054] S44, Fluid property parameter update

[0055] The pressure obtained from solving the current grid node and temperature Substitute the fluid properties into the property update equation to update the fluid property parameters of the current mesh node.

[0056] The property update equations are as follows:

[0057] in, , The updated density and plastic viscosity for the current mesh node i; , These are the initial density and initial plastic viscosity of the drilling fluid, derived from drilling process parameters; The pressure at the current grid node i at time step n is output by the momentum conservation equation. The temperature of the current grid node i at time step n is output by the energy conservation equation. , K represents the standard temperature and pressure at ground level; k1, k2, k3, and k4 are temperature and pressure correction coefficients for physical properties, determined through experiments or empirical formulas.

[0058] The updated fluid properties are used as inputs for solving the temperature and pressure of the adjacent upper grid node (i+1), allowing for continuous iterative solving from bottom to top, node by node. This continues until the wellhead grid node (i=N) is reached, yielding the full wellbore temperature and pressure distribution at the current time step.

[0059] S5. Wellhead convergence verification (boundary condition verification)

[0060] After iterating to the wellhead node i=N, the calculated wellhead pressure value (i.e., the wellhead pressure mentioned above) is obtained, and compared with the measured wellhead pressure P. surf (t n Perform error comparison:

[0061] in, This refers to the relative error of the wellhead pressure. P is the calculated wellhead pressure value. surf (t n () represents the measured pressure at the wellhead / measured pressure at the wellhead.

[0062] like > (If the preset error threshold is reached), then adjust the initial temperature and pressure at the bottom of the well and iterate again; if ≤ If the preset error threshold is reached, the calculation at the current time step will converge.

[0063] S6. Time step progression and downhole virtual sensing data generation

[0064] Advance the time step by time step Δt, repeat the iterative solution and convergence verification until the target time period t is completed. total The calculation of all time steps within the wellbore outputs temperature and pressure distribution data P(z,t) and T(z,t) for the entire wellbore and the entire time period. That is, the pressure value P(z,t) and temperature value T(z,t) of each node along the well depth direction at different times within the target time period.

[0065] Temperature and pressure at key locations (such as the bottom of the well and the casing shoe) are extracted from the temperature and pressure distribution to serve as downhole virtual sensing data. Downhole virtual sensing data may include at least one of the following: bottom-hole virtual pressure P. virtual (t), Virtual temperature at the bottom of the well T virtual (t), Virtual pressure P at the position of the cannula shoe shoe (t).

[0066] In some embodiments, the wellhead surface measurement data in S101 above may include at least one of the following: wellhead measured riser pressure P surf (t), measured casing pressure at the wellhead P cas (t), measured injection displacement of drilling fluid Q(t), measured outlet flow rate at wellhead Q out (t), measured inlet temperature of drilling fluid T in (t).

[0067] A downhole pressure "virtual sensor" can be constructed based on a wellbore hydraulic model. This model dynamically simulates downhole temperature and pressure data at key locations such as the well bottom under actual operating conditions, generating the aforementioned virtual downhole sensing data. Simultaneously, real sensors at the wellhead collect measured data from the surface. Finally, the simulated virtual downhole sensing data is fused with the real sensor data (measured data from the wellhead surface) to form a more comprehensive multi-source fused data set. This multi-source fused data set can more accurately and dynamically assess the changing trends of downhole parameters, providing a solid data foundation for the subsequent training of physical information neural networks.

[0068] The fusion method can be data splicing or feature combination. For example, downhole virtual data and ground measured data at the same time step can be organized into multi-source fused data in a certain order and used as input samples for subsequent training of physical information neural networks.

[0069] Based on the above embodiments, downhole virtual sensing data is generated through a wellbore hydraulic model, solving the problem of the difficulty in directly measuring key downhole parameters. This avoids dependence on expensive and easily malfunctioning downhole high-temperature and high-pressure measuring equipment, reducing hardware costs and implementation difficulty, and improving applicability in complex conditions such as deep and ultra-deep wells. Through bottom-up, node-by-node iterative solving, transient time-step progression, and a wellhead convergence verification mechanism, the calculation accuracy of the entire wellbore temperature and pressure distribution is ensured, enabling the virtual sensing data to truly reflect the downhole physical state. The virtual sensing data is fused with ground-measured data to form a multi-source fusion dataset containing both downhole physical information and ground-measured information. This overcomes the shortcomings of relying solely on insufficient ground-measured data, providing a high-quality, physically consistent data foundation for the subsequent training of the physical information neural network. Simultaneously, the time-step progression mechanism can simulate the dynamic changes in the entire wellbore temperature and pressure distribution within a target time period, providing time-series data support for early gas intrusion warning.

[0070] S102: Input the real-time fused feature vector into the gas invasion early warning prediction model and output the wellhead pressure prediction value. The real-time fused feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data.

[0071] In some embodiments, the air intrusion early warning prediction model in S102 above may include an input layer, a neural network body, an automatic differentiation module, a physical constraint module and an output layer, wherein the physical constraint layer has a built-in mass conservation equation and a momentum conservation equation. Accordingly, the step of fusing the feature vectors in real time into the gas invasion early warning prediction model in S102 above, and outputting the wellhead pressure prediction value, may include, in specific implementation: The system receives the real-time fused feature vector through the input layer; processes the real-time fused feature vector through the neural network body to output the predicted pressure field of the entire wellbore; calculates the partial derivatives of the predicted pressure field of the entire wellbore with respect to spatial coordinates and time through the automatic differentiation module; calculates the residuals of the mass conservation equation and the momentum equation based on the partial derivatives through the physical constraint module as the physical equation residuals, and determines that the model has converged when the physical equation residuals are less than a preset convergence threshold; and extracts the pressure value at the wellhead position from the predicted pressure field through the output layer as the predicted wellhead pressure value.

[0072] Specifically, the input layer can be used to receive a real-time fused feature vector. This real-time fused feature vector can include: a spatiotemporal coordinate pair (z, t) (i.e., the spatial coordinates z of the well depth and time t), and auxiliary input parameters (such as flow velocity, drilling fluid density, friction coefficient, etc. in real-time generated downhole virtual sensing data and real-time collected surface measurement data at the wellhead). The input layer integrates these parameters into an input feature vector and passes it to the main body of the neural network.

[0073] The neural network body can consist of multiple fully connected layers. Each layer uses an activation function (such as Tanh or ReLU) to perform a nonlinear transformation, learning the mapping relationship between the input feature vector and the output pressure field, outputting a predicted pressure field for the entire wellbore. The depth and width of the neural network body can be configured according to the problem complexity.

[0074] The automatic differentiation module can be used to calculate the partial derivatives of the full-wellbore predicted pressure field output by the neural network with respect to the input spatial coordinates z and time t. Automatic differentiation is a built-in function of neural network frameworks (such as TensorFlow and PyTorch), which can accurately calculate the derivative of the network output with respect to the input without manually deriving the gradient formula. This is a key technical means of embedding physical constraints into neural networks.

[0075] The physical constraint module can include built-in mass conservation equations and momentum conservation equations (specifically, continuous forms of these equations). These are used to calculate the physical equation residuals (mass conservation equation residuals and momentum equation residuals) based on the partial derivatives obtained from the automatic differentiation module and the relevant physical quantities in the input parameters. Model convergence is determined when the physical equation residuals are less than a preset convergence threshold, at which point accurate wellhead pressure predictions can be output through the output layer.

[0076] The output layer can be used to extract the pressure value at the wellhead location (z=0) from the predicted pressure field of the entire wellbore as the predicted wellhead pressure value.

[0077] In some embodiments, the above-mentioned calculation of the residuals of the mass conservation equation and the momentum equation based on the partial derivatives as the residuals of the physical equations may, in specific implementation, include: The partial derivatives of the whole-wellbore predicted pressure field and the whole-wellbore predicted pressure field output by the automatic differentiation module with respect to spatial coordinates and time are substituted into the mass conservation equation and momentum conservation equation built into the physical constraint module, respectively, to calculate the actual predicted values ​​of the mass conservation equation and the momentum conservation equation. The deviation between the actual predicted value and the theoretical value of the mass conservation equation is defined as the residual of the mass conservation equation. The deviation between the actual predicted value and the theoretical value of the momentum conservation equation is defined as the momentum conservation equation residual. The residuals of the mass conservation equation and the momentum conservation equation are weighted and summed to obtain the residuals of the physical equation.

[0078] Specifically, the pressure field of the entire wellbore will be predicted separately. And the partial derivatives of the predicted pressure field of the entire wellbore with respect to spatial coordinates z (or using x to represent spatial coordinates) and time t, output by the automatic differentiation module: , .

[0079] The mass conservation equation describes the conservation relationship of fluid mass during flow within the wellbore, and its continuous form is: Its theoretical value is 0.

[0080] Substituting the partial derivatives of the predicted pressure field of the entire wellbore and the predicted pressure field of the entire wellbore output by the automatic differentiation module with respect to spatial coordinates and time into the mass conservation equation built into the physical constraint module, the actual predicted value of the mass conservation equation is calculated:

[0081] in, The residuals of the mass conservation equation; Predicting the pressure field from the entire wellbore The calculated predicted density; The predicted flow velocity is obtained from the flow rate and the flow area; z is the spatial coordinate of the well depth; t is time.

[0082] The continuous form of the momentum conservation equation is: .

[0083] Substituting the partial derivatives of the predicted pressure field of the entire wellbore and the predicted pressure field of the entire wellbore output by the automatic differentiation module with respect to spatial coordinates and time into the momentum conservation equation, the actual predicted value of the momentum conservation equation is calculated:

[0084] in, This represents the residual of the momentum conservation equation; Predict the pressure field for the entire wellbore; This represents the spatial partial derivative of pressure along well depth; Predicting the pressure field from the entire wellbore The calculated predicted density; g is the acceleration due to gravity; F f The voltage drop per unit length due to frictional resistance; The residuals of the mass conservation equation and the momentum conservation equation are weighted and summed to obtain the physical equation residuals. :

[0085] in, The residuals of the mass conservation equation; This is the residual of the momentum conservation equation (which can be adjusted according to actual working conditions).

[0086] In some embodiments, the specific process of training a physical information neural network with multi-source fusion data to obtain an air intrusion early warning and prediction model can be as follows: The multi-source fusion data generated in S101 is used as training samples. The multi-source fusion data includes downhole virtual sensing data and wellhead ground measured data. The above data is then subjected to time-series alignment and normalization to form a standardized training dataset that can be used for model training.

[0087] A physical information neural network, primarily composed of a multi-layer fully connected network, is constructed. The mass conservation equation and momentum conservation equation are embedded into the network as physical constraints, forming the basic network structure of the gas intrusion early warning and prediction model. The partial derivatives of the predicted pressure field across the entire wellbore with respect to spatial coordinates and time are calculated using an automatic differentiation mechanism. These partial derivatives are then substituted into the embedded mass conservation equation and momentum conservation equation to obtain the residuals of the mass conservation equation and momentum equation, respectively. These residuals are further weighted to obtain the physical equation residuals.

[0088] The mean square error between the predicted wellhead pressure output by the network and the measured wellhead pressure data is used as the data loss, and the mean value of the physical equation residuals is used as the physical loss. The total loss function is obtained by weighted fusion of the data loss and the physical loss.

[0089] The physical information neural network is iteratively trained using optimization algorithms (such as the Adam optimizer) to continuously update the network parameters in order to reduce the total loss function, so that the pressure field output by the model can simultaneously match the distribution of the measured data and satisfy the physical conservation law of wellbore fluid.

[0090] When the total loss function converges (which may include the physical equation residuals being less than a preset convergence threshold) and meets the preset accuracy requirements, training stops, the network structure and parameters are saved, and the trained air intrusion early warning prediction model is obtained.

[0091] The formula for the total loss function can be as follows:

[0092] Among them, L total Total loss; L data Data loss (this part measures the error between the neural network's predictions and the observed data (or initial conditions, boundary conditions); L phy The physical loss is the residual generated by substituting the predicted pressure field output by the neural network into the mass conservation equation and the momentum conservation equation.

[0093] In this embodiment, a Physics-Informed Neural Network (PINN) is used to embed the physical laws of multiphase flow in the wellbore as constraints into the model training process. This allows the model to fit observed data while adhering to known physical mechanisms, thereby achieving high-precision and advanced prediction of wellhead pressure. Compared to purely data-driven black-box models, PINN maintains physical consistency even in data-sparse regions, exhibiting stronger generalization ability and interpretability. In other words, this model, driven by both mechanism and data, not only reduces its dependence on massive amounts of data but also enhances its generalization ability in data-sparse regions. Simultaneously, the introduction of physical constraints significantly improves the model's interpretability and the reliability of prediction results. The model is trained and hyperparameters optimized using the aforementioned multi-source fusion data. Compared to other models, this prediction model can dynamically extrapolate and predict the changing trends of key downhole parameters (such as wellhead pressure) with high precision and advancement, providing core decision support for real-time optimization of the drilling process and early risk warning.

[0094] Based on the above embodiments, a physical information neural network model is used to predict wellhead pressure in advance. Leveraging the fast inference speed of neural networks, abnormal trends can be detected early, before significant changes in parameters during the early stages of gas intrusion. This solves the problems of delayed warnings and slow response in traditional methods, meeting the timeliness requirements of real-time early warning. By embedding the mass conservation equation and momentum conservation equation as physical constraints into the neural network loss function, the model fits both observed data and physical laws during training, enhancing its interpretability and generalization ability in sparse data regions. Simultaneously, the residuals of the physical equations are output. Model convergence is determined when these residuals are less than a preset convergence threshold, at which point accurate wellhead pressure predictions can be output through the output layer. The automatic differentiation module accurately calculates partial derivatives, eliminating the need for manual derivation and discretization of partial differential equations, simplifying model implementation and improving computational accuracy.

[0095] S103: Calculate the physical error based on the predicted wellhead pressure and the measured wellhead surface data, input the measured wellhead surface data into the autoencoder to calculate the data reconstruction error, and merge the physical error and the data reconstruction error into a comprehensive anomaly index.

[0096] Specifically, accurate identification of gas intrusion anomalies can be achieved through a dual criterion of physical error and autoencoder data reconstruction error. Physical error reflects the physical deviation caused by gas intrusion by comparing the difference between the predicted wellhead pressure and the measured surface data. Data reconstruction error is calculated by encoding and decoding the measured surface data using an autoencoder, determining the deviation between the original and reconstructed data, and reflecting abnormal fluctuations in the data itself. Integrating these two criteria into a comprehensive anomaly index forms a dual-constraint anomaly detection mechanism based on both mechanism and data, effectively addressing the problems of single-criterion susceptibility to noise interference and high false alarm rates.

[0097] In some embodiments, the step of inputting the wellhead surface measured data into the self-compiler to calculate the data reconstruction error in S103 above may, in specific implementation, include: The measured surface data at the wellhead is used as the raw input data and compressed into low-dimensional feature codes by the encoder part of the autoencoder. The decoder part of the autoencoder reconstructs the data based on the low-dimensional feature encoding to obtain the reconstructed data. The deviation between the original input data and the reconstructed data is calculated to obtain the data reconstruction error, which is used to characterize the degree of abnormality of the fluctuation of the wellhead surface measured data. The fusion is a comprehensive anomaly index, including: The data reconstruction error is normalized to obtain the normalized reconstruction error, and the physical equation residual is normalized to obtain the normalized physical residual. The normalized reconstruction error and the normalized physical residual are weighted and fused to obtain the comprehensive anomaly index.

[0098] Specifically, the physical error can be calculated by comparing the predicted wellhead pressure output by the gas invasion early warning prediction model with the actual surface measurement data at the wellhead at the same time. The physical error reflects the degree of physical deviation between the actual operating conditions and normal operating conditions. Under normal operating conditions, the gas invasion early warning prediction model can accurately predict the wellhead pressure, and the physical error should be close to zero. Once gas invasion occurs, the actual physical state inside the wellbore deviates from normal operating conditions, the measured wellhead pressure changes, but the model still predicts the pressure value under normal operating conditions, leading to a significant increase in the physical error. Therefore, the magnitude of the physical error can serve as an important basis for determining whether gas invasion has occurred.

[0099] The measured surface data at the wellhead is input into the autoencoder to calculate the data reconstruction error. Calculating the data reconstruction error may include the following sub-steps: First, we construct the autoencoder structure. An autoencoder is an unsupervised learning neural network model consisting of an encoder and a decoder. The encoder part compresses the original input data into a low-dimensional "feature code," extracting key features from the data. The decoder part, based on this feature code, attempts to regenerate data that is identical to the original input data. The difference between the "regenerated data" and the "original input data" is the reconstruction error (data reconstruction error). When training the autoencoder with only normal data, the reconstruction error is small with normal data and large with abnormal data. Therefore, the magnitude of the reconstruction error can be used as a basis for determining whether there are abnormal fluctuations in the data.

[0100] Next, the measured data from the wellhead surface was used as the raw input data. The surface measurement data at the wellhead can include the measured casing pressure at the wellhead. Measured riser pressure at wellhead Measured injection displacement of drilling fluid Measured outlet flow rate at wellhead Measured inlet temperature of drilling fluid These are used to form a multidimensional feature vector, which is then input into the autoencoder. .

[0101] The wellhead surface measurement data is compressed using the encoder part of the autoencoder to obtain the low-dimensional feature code h:

[0102] Where h is the low-dimensional feature code output by the encoder; is the nonlinear mapping function of the encoder, which consists of a multi-layer fully connected network and an activation function.

[0103] The data is then reconstructed using the decoder part of the autoencoder based on the low-dimensional feature encoding h, resulting in the reconstructed data. :

[0104] in, is the nonlinear mapping function of the decoder, which consists of a multi-layer fully connected network and an activation function.

[0105] The data reconstruction error is obtained by calculating the deviation between the original input data and the reconstructed data.

[0106] in, denoted as data reconstruction error; M is the length of the time series.

[0107] Furthermore, the data reconstruction error and physical error are normalized separately, and then weighted and fused to obtain a comprehensive anomaly index:

[0108] Where S is the comprehensive anomaly index; This refers to the data reconstruction error after normalization. Normalized physical error; Weighting coefficients for data reconstruction errors; This is the physical error weighting coefficient, and the sum of the two is 1. The value of the weighting coefficient can be adjusted according to the actual working conditions; for example, it can be appropriately increased when the data quality is high. When the physical laws are clearer, the size can be appropriately increased. .

[0109] In some embodiments, an adaptive weighting discrimination rule can be employed to dynamically adjust the weighting coefficients based on the relative anomalies of the two types of errors. When the anomaly of the data reconstruction error is high while the physical error is normal, the system automatically reduces the weight of the data reconstruction error to avoid misjudging data acquisition anomalies as real physical anomalies. Conversely, the opposite is also true. This adaptive weighting mechanism improves the robustness and accuracy of anomaly identification.

[0110] Based on the above embodiments, by calculating data reconstruction errors using an autoencoder, abnormal patterns in surface logging data can be identified, and the characteristics of surface parameter changes caused by gas intrusion can be captured. Physical errors are used to identify anomalies in the downhole physical state, capturing the physical deviation between actual and normal operating conditions caused by gas intrusion. These two are fused into a comprehensive anomaly index, achieving dual verification of physical and data criteria. Physical errors reflect deviations in the downhole physical state caused by gas intrusion, while data reconstruction errors reflect abnormal fluctuations in surface logging data. The complementary verification effectively solves the problems of single criteria being susceptible to noise interference and having a high false alarm rate. Normalization eliminates dimensional differences, allowing the two types of errors to be fused at the same scale. Adaptive weight adjustment dynamically adjusts the criterion weights according to the source of the anomaly, further improving the robustness and accuracy of anomaly identification.

[0111] S104: Compare the comprehensive anomaly index with the preset graded early warning threshold to conduct graded early warning of drilling gas invasion based on the comparison result.

[0112] Specifically, based on the statistical characteristics of the comprehensive anomaly index under historical normal operating conditions, multiple warning thresholds can be preset. The comprehensive anomaly index calculated in real time can be compared with the thresholds at each level. The severity of the gas intrusion risk can be determined based on the comparison results, and corresponding graded warning signals can be output to provide on-site workers with a clear and operable risk level judgment.

[0113] In some embodiments, comparing the comprehensive anomaly index with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison result includes: The comprehensive anomaly index is compared sequentially with the first warning threshold, the second warning threshold, and the third warning threshold. If the comprehensive abnormal index is less than the first warning threshold, it is determined to be a normal operating condition; If the comprehensive abnormal index is greater than or equal to the first warning threshold and less than the second warning threshold, it is judged as a mild air intrusion. If the comprehensive anomaly index is greater than or equal to the second warning threshold and less than the third warning threshold, it is judged as a moderate air intrusion; If the comprehensive abnormal index is greater than or equal to the third warning threshold, it is judged as a severe air intrusion; Based on the determined level, a corresponding graded early warning signal is output.

[0114] Specifically, the aforementioned preset graded early warning thresholds are not fixed values, but are set based on the statistical characteristics (statistical mean μ, statistical standard deviation σ) of the comprehensive anomaly index under normal operating conditions. This ensures that the early warning thresholds closely match the actual drilling project, achieving accurate grading of gas intrusion risks. Ultimately, this forms a collaborative early warning system that integrates surface data and downhole physical conditions, enabling proactive and reliable identification of gas intrusion risks. The specific steps are as follows: First, the statistical benchmark for the early warning threshold is determined: by collecting a large amount of historical normal drilling data offline, the statistical mean μ and statistical standard deviation σ of the comprehensive anomaly index under normal operating conditions are calculated, where μ is the average level of the comprehensive anomaly index under normal operating conditions, reflecting the benchmark state of normal drilling conditions; σ is the fluctuation range of the comprehensive anomaly index under normal operating conditions, reflecting the reasonable fluctuation range of the index under normal operating conditions. The two together serve as the basis for setting the graded early warning threshold.

[0115] Secondly, the correspondence between the three-level early warning thresholds and the technical briefing is clarified. The thresholds are set as follows, and the following conditions must be met: First early warning threshold < Second early warning threshold < Third early warning threshold: The first warning threshold, corresponding to the yellow warning, is set at μ+1σ or μ+2σ. It can be flexibly selected according to the well type, drilling fluid properties, and engineering safety requirements on site. It is used to capture weak abnormal signals in the early stage of gas invasion. The second warning threshold, corresponding to the orange warning, is fixed at μ+3σ. It is used to determine that gas invasion has entered a stage of continuous development and timely response measures are required. The third warning threshold, corresponding to the red warning, is set at μ+4σ or higher. The threshold standard can be appropriately increased according to the well control safety level on site. It is used to determine that gas invasion has developed to a serious stage and there is a risk to well control safety.

[0116] Normal operating conditions: The comprehensive anomaly index is less than the first warning threshold (i.e., less than μ + 1σ and less than μ + 2σ). At this time, the comprehensive anomaly index is within the normal fluctuation range, there are no signs of gas invasion downhole, the system does not trigger the warning, and continuously monitors the surface measured data at the wellhead and the virtual sensor data downhole in real time to maintain the collaborative monitoring status. Mild gas intrusion: The comprehensive abnormal index is ≥ the first warning threshold and < the second warning threshold (i.e. ≥ μ + 1σ or ≥ μ + 2σ and < μ + 3σ), which corresponds to a yellow warning. There are weak signs of gas intrusion downhole. A yellow warning signal is output to remind on-site personnel to strengthen data monitoring and working condition observation, and to prepare for warning response. Moderate gas invasion: The comprehensive abnormal index is ≥ the second warning threshold and < the third warning threshold (i.e. ≥ μ + 3σ and < μ + 4σ), corresponding to an orange warning. The downhole gas invasion continues to develop, and an orange warning signal is output, prompting immediate action to take targeted measures such as pressure control and circulating exhaust to curb the aggravation of gas invasion. Severe gas invasion: The comprehensive abnormal index is ≥ the third warning threshold (i.e. ≥ μ+4σ or higher), corresponding to a red warning. A strong gas invasion has occurred downhole, posing safety risks such as well blowout. A red warning signal is output, the emergency well control plan is activated, and emergency measures such as well shut-in and well control are taken to ensure the safety of drilling operations.

[0117] By using the above method, the grading judgment logic is precisely integrated with the preset grading early warning threshold standard, realizing a one-to-one correspondence between the comprehensive anomaly index and the gas invasion early warning level. Combined with the synergistic effect of multi-source fusion data (ground measurement + downhole virtual sensing), a complete collaborative early warning system is formed, which not only avoids false early warnings caused by slight data fluctuations, but also captures early gas invasion signals in advance, ensuring the reliability and timeliness of gas invasion identification.

[0118] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. For details, please refer to the foregoing descriptions of the relevant processing embodiments; they will not be repeated here.

[0119] The foregoing description of this method is for illustrative purposes only and describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than those shown in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0120] In a specific implementation scenario, refer to Figure 2 The solution process for the wellbore hydraulic model is explained as shown below: Start: Initiate the wellbore hydraulic model calculation process; Input wellbore structure, inclination measurement data, and drill string assembly: Input wellbore geometry, well inclination azimuth data, and drill string assembly parameters to provide the geometric basis of the wellbore and drill string for model calculation; Mesh wellbore, i vertical nodes and j radial nodes: Based on the total well depth and the well depth node spacing, i grid nodes are divided vertically along the well depth and j grid nodes are divided radially along the wellbore, discretizing the continuous wellbore space into a computational domain that can be solved node by node; Input drilling fluid properties, operating parameters, and boundary conditions: Input drilling fluid property parameters, drilling process parameters, and boundary condition parameters to provide parameter basis for model solution; Pure liquid phase initialization of wellbore flow and heat transfer parameters: Using pure liquid phase drilling fluid as the initial state, initialize the pressure, temperature, flow velocity and other flow and heat transfer parameters of each grid node in the entire wellbore; Determining if an abnormal formation is encountered: This involves determining whether the current drilling operation has encountered any abnormal formations, such as gas layers. If the determination is negative, return to the "Pure Liquid Phase Initialization Wellbore Flow Heat Transfer Parameters" step and maintain the initial conditions of pure liquid phase; If the determination is yes, proceed to the next step; Update bottom hole flow and heat transfer parameters: Based on the initial estimated bottom hole pressure, update the flow and heat transfer parameters of the bottom hole grid nodes; Assuming the pressure of the i-th grid node is estimated by subtracting the gravity from the previous grid node, the pressure of the adjacent grid node below is subtracted from the gravity of the liquid column, which is used as the initial estimate of the pressure of the current i-th grid node. Update the flow and heat transfer parameters of the entire wellbore: Based on the pressure estimates of each node, update the flow and heat transfer parameters such as density, viscosity, and flow velocity of all grid nodes in the entire wellbore. Calculate the new temperature and pressure distribution at each node: Substitute the updated parameters into the mass conservation, momentum conservation, and energy conservation control equations to solve for the pressure and temperature distribution at each grid node in the entire wellbore; Calculate the wellhead pressure and temperature error: Compare the calculated wellhead pressure and temperature with the actual measured wellhead pressure and temperature, and calculate the wellhead error err. out (including relative error of wellhead pressure) ); Determine if the wellhead error meets the err standard. out <1e -4 If the result is negative, return to the "Update Bottom Well Flow and Heat Transfer Parameters" step, adjust the initial bottom well pressure, and iterate again to solve the problem. If the determination is yes, proceed to the next step; End: The current time step calculation has converged, and the temperature and pressure distribution data of the entire wellbore is output, completing the downhole virtual sensing data generation process.

[0121] See Figure 3 As shown, the structure and principle of the physical information neural network model can be specifically described as follows: The model input is formed by fusing the model results generated by downhole virtual sensors (downhole virtual sensing data) with the measurement data collected by real ground sensors (wellhead ground measured data), forming multi-source fusion data, which provides the model with complete information support on the downhole physical state and the actual ground operating conditions.

[0122] Using spatial coordinates x, time coordinates t, and multi-source fused data as input, a multi-layer fully connected neural network is used to perform nonlinear feature transformation and mapping to output the predicted pressure field of the entire wellbore.

[0123] Physical constraint modules (PDEs): These are the predicted stress fields output by the network. The partial derivatives obtained from the automatic differentiation are substituted into the built-in partial differential equations (PDEs), namely the mass conservation equation and the momentum conservation equation, to calculate the residuals of the physical equations and realize the constraints of physical laws. The continuous form of the mass conservation equation is: Its theoretical value is 0.

[0124] The continuous form of the momentum conservation equation is:

[0125] Where, ρ l v is the drilling fluid density. l Let P be the drilling fluid velocity, P be the wellbore pressure, g be the acceleration due to gravity, θ be the well inclination angle, and F be the drilling fluid velocity. f This represents the frictional voltage drop per unit length.

[0126] Model training and convergence judgment: The total loss function is composed of data loss (mean square error between the predicted wellhead pressure and the measured wellhead pressure) and physical equation residual loss (or the mean of the physical equation residuals as physical loss). The network parameters are optimized through iterative training. The model training is completed when the total loss satisfies MSE < ε (ε is the preset target convergence threshold, which may include the physical equation residuals being less than the preset convergence threshold) or when the total loss function converges and meets the preset accuracy requirements.

[0127] Model output layer: The trained gas invasion early warning and prediction model can output wellhead pressure prediction values ​​based on real-time input multi-source fusion data, providing core prediction basis for subsequent gas invasion anomaly identification and graded early warning.

[0128] See Figure 4As shown, the structure of the self-encoder multi-level early warning model can be as follows: the wellhead pressure prediction value and the real-time casing pressure measurement value output by PINN serve as the core inputs of the self-encoder; the self-encoder processes the input data, simultaneously extracting physical errors (the difference between the wellhead pressure prediction value and the measured wellhead surface data) and data reconstruction errors (the reconstruction error of the self-encoder). The two errors are weighted and fused using an adaptive weighting discrimination rule to calculate a comprehensive error coefficient (comprehensive anomaly index). The comprehensive error coefficient is compared with a preset threshold to trigger the corresponding yellow / orange / red graded alarm.

[0129] See Figure 5 As shown, the overall concept of this invention can be as follows: Virtual downhole data is generated through a wellbore hydraulic model simulation, while historical and real-time surface logging data are collected, forming a comprehensive dataset encompassing "virtual downhole data + historical surface data + real-time surface data." This multi-source data is input into the PINN model to complete model training and output advanced predictions of key parameters such as wellhead pressure. The PINN predictions and real-time surface logging data are then input into an autoencoder-based hierarchical early warning model. Gas intrusion anomaly identification is achieved through dual criteria, and hierarchical early warning results are output. From mechanism modeling to data fusion, and then to intelligent prediction, hierarchical early warning is ultimately achieved, forming a closed-loop process for gas intrusion early warning driven by both mechanism and data.

[0130] By integrating the results of the mechanistic model with actual measurement data, a physical information neural network model embedded with the flow equation is trained to predict wellhead pressure in advance. Anomaly identification based on dual criteria of predicted values ​​and real-time data is performed through an autoencoder, thereby improving the accuracy and timeliness of the earliest warning of gas invasion risk.

[0131] Although this specification provides the following examples or appendices Figure 6 The method or apparatus structure shown may include more or fewer combined operational steps or module units based on conventional or non-creative labor. In steps or structures where there is no logically necessary causal relationship, the execution order of these steps or the module structure of the apparatus is not limited to the execution order or module structure shown in the embodiments or drawings of this specification. When the method or module structure is applied in actual devices, servers, or terminal products, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or drawings (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed processing or server cluster implementation environment). Based on the above-mentioned drilling gas invasion early warning method with dual constraints of mechanism and data, this specification also proposes an embodiment of a drilling gas invasion early warning device with dual constraints of mechanism and data. Figure 6 As shown, the device may specifically include the following modules: The first fusion module 601 can be used to input drilling engineering parameters into the wellbore hydraulic model, generate downhole virtual sensing data, and fuse it with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas intrusion early warning and prediction model. Prediction module 602 can be used to input real-time fused feature vectors into the gas invasion early warning prediction model and output wellhead pressure prediction values. The real-time fused feature vectors include real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. The second fusion module 603 can be used to calculate the physical error based on the predicted wellhead pressure value and the measured wellhead surface data, input the measured wellhead surface data into the autoencoder to calculate the data reconstruction error, and fuse the physical error and the data reconstruction error into a comprehensive anomaly index. The graded early warning module 604 can be used to compare the comprehensive anomaly index with a preset graded early warning threshold, so as to perform graded early warning of drilling gas invasion based on the comparison result.

[0132] In some embodiments, the drilling engineering parameters in the first fusion module 601 described above may include at least one of the following: wellbore structure parameters, drill string assembly parameters, drilling process parameters, boundary condition parameters, and time control parameters; the wellbore structure parameters may include at least one of the following: total well depth, wellbore diameter of each grid node, well inclination angle of each grid node, and well depth node spacing; the drill string assembly parameters may include at least one of the following: outer diameter of each grid node drill string and inner diameter of each grid node drill string; the drilling process parameters may include fluid property parameters, drilling fluid thermal property parameters, and displacement, and the fluid property parameters may include at least one of the following: initial density of drilling fluid and initial plastic viscosity of drilling fluid. The drilling fluid thermophysical parameters may include at least one of the following: initial specific heat at constant pressure of drilling fluid, initial thermal conductivity of drilling fluid; the boundary condition parameters may include at least one of the following: measured casing pressure at wellhead, measured standpipe pressure at wellhead, measured outlet flow rate at wellhead; the time control parameters may include at least one of the following: target time period, time step; the downhole virtual sensing data may include at least one of the following: virtual pressure at bottom well, virtual temperature at bottom well, virtual pressure at casing shoe position; the wellhead surface measured data may include at least one of the following: measured standpipe pressure at wellhead, measured casing pressure at wellhead, measured drilling fluid injection rate, measured outlet flow rate at wellhead, measured inlet temperature of drilling fluid.

[0133] In some embodiments, the wellbore hydraulic model in the first fusion module 601 is composed of governing equations, including mass conservation equations, momentum conservation equations, and energy conservation equations. Correspondingly, the first fusion module 601 can specifically be used to discretize the wellbore into a preset number of grid nodes along the well depth direction based on input drilling engineering parameters. The preset number is determined according to the ratio of the total well depth to the well depth node spacing. The mass conservation equations, momentum conservation equations, and energy conservation equations are transformed into discrete difference equations on each grid node. The overall wellbore temperature and pressure distribution of the previous time step is obtained as the initial condition for the current time step. Starting from the bottom grid node, with the initial bottom temperature and pressure as the iteration starting point, the discrete difference equations of the mass conservation equation, momentum conservation equation, and energy conservation equation are iteratively solved from bottom to top, node by node. The equations are divided to obtain the temperature and pressure of each grid node. The fluid property parameters of the corresponding grid node are updated based on the temperature and pressure of each grid node. These updated fluid property parameters are used as inputs for solving the temperature and pressure of adjacent upper grid nodes until the wellhead grid node is reached, obtaining the full wellbore temperature and pressure distribution for the current time step, including the wellhead pressure. The wellhead pressure is compared with the measured wellhead pressure. If the error comparison result is greater than a preset error threshold, the initial temperature and pressure at the bottom of the well are adjusted, and the solution is iterated again from bottom to top, node by node, until all time steps within the target time period are calculated. The full wellbore temperature and pressure distribution for all time steps within the target time period is output. The temperature and pressure at key locations are extracted from the full wellbore temperature and pressure distribution for all time steps within the target time period as the downhole virtual sensing data.

[0134] In some embodiments, the first fusion module 601 can further be used to substitute the updated fluid property parameters of the lower grid node into the discrete difference equation of the mass conservation equation to solve for the density of the current grid node; substitute the density of the current grid node, the pressure of the lower grid node, and the updated fluid property parameters into the discrete difference equation of the momentum conservation equation to solve for the pressure of the current grid node; substitute the pressure of the current grid node, the temperature of the lower grid node, and the updated fluid property parameters into the discrete difference equation of the energy conservation equation to solve for the temperature of the current grid node; substitute the pressure and temperature obtained from solving for the current grid node into the property update equation to update the fluid property parameters of the current grid node, and use the density, pressure, temperature, and updated fluid property parameters of the current grid node as the solution input for the adjacent upper grid node.

[0135] In some embodiments, the gas invasion early warning prediction model in the prediction module 602 includes an input layer, a neural network body, an automatic differentiation module, a physical constraint module, and an output layer. The physical constraint layer has a built-in mass conservation equation and a momentum conservation equation. Accordingly, the prediction module 602 can be specifically used to receive the real-time fused feature vector through the input layer; process the real-time fused feature vector through the neural network body to output the whole-wellbore predicted pressure field; calculate the partial derivatives of the whole-wellbore predicted pressure field with respect to spatial coordinates and time through the automatic differentiation module; calculate the residuals of the mass conservation equation and the momentum equation based on the partial derivatives through the physical constraint module as the physical equation residuals, and determine that the model has converged when the physical equation residuals are less than a preset convergence threshold; and extract the pressure value at the wellhead position from the predicted pressure field through the output layer as the predicted wellhead pressure value.

[0136] In some embodiments, the prediction module 602 can further be used to substitute the partial derivatives of the whole-wellbore predicted pressure field and the whole-wellbore predicted pressure field output by the automatic differentiation module with respect to spatial coordinates and time into the mass conservation equation and momentum conservation equation built into the physical constraint module, respectively, to calculate the actual predicted values ​​of the mass conservation equation and the momentum conservation equation; the deviation between the actual predicted value of the mass conservation equation and the theoretical value of the mass conservation equation is determined as the residual of the mass conservation equation; the deviation between the actual predicted value of the momentum conservation equation and the theoretical value of the momentum conservation equation is determined as the residual of the momentum conservation equation; and the residuals of the mass conservation equation and the residuals of the momentum conservation equation are weighted and summed to obtain the residual of the physical equation.

[0137] In some embodiments, the second fusion module 603 can be specifically used to take the wellhead surface measured data as the original input data, compress it into low-dimensional feature codes by the encoder part of the autoencoder; reconstruct the data based on the low-dimensional feature codes by the decoder part of the autoencoder to obtain reconstructed data; calculate the deviation between the original input data and the reconstructed data to obtain the data reconstruction error, which is used to characterize the degree of abnormality of the fluctuation of the wellhead surface measured data; normalize the data reconstruction error to obtain the normalized reconstruction error, normalize the physical equation residual to obtain the normalized physical residual; and perform weighted fusion of the normalized reconstruction error and the normalized physical residual to obtain the comprehensive anomaly index.

[0138] In some embodiments, the aforementioned graded early warning module 604 can be specifically used to compare the comprehensive anomaly index with a first early warning threshold, a second early warning threshold, and a third early warning threshold in sequence; if the comprehensive anomaly index is less than the first early warning threshold, it is determined to be a normal operating condition; if the comprehensive anomaly index is greater than or equal to the first early warning threshold and less than the second early warning threshold, it is determined to be a mild air intrusion; if the comprehensive anomaly index is greater than or equal to the second early warning threshold and less than the third early warning threshold, it is determined to be a moderate air intrusion; if the comprehensive anomaly index is greater than or equal to the third early warning threshold, it is determined to be a severe air intrusion; and output the corresponding graded early warning signal according to the determination level.

[0139] This specification also provides an electronic device based on the above-mentioned mechanism and data dual-constraint drilling gas invasion early warning method, including a processor and a memory for storing processor-executable programs / instructions. Specifically, the processor can execute the following steps according to the program / instructions: inputting drilling engineering parameters into a wellbore hydraulic model to generate downhole virtual sensing data, and fusing it with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas invasion early warning prediction model; inputting a real-time fusion feature vector into the gas invasion early warning prediction model to output a wellhead pressure prediction value. The real-time fusion feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data; calculating the physical error based on the wellhead pressure prediction value and the wellhead surface measured data, and inputting the wellhead surface measured data into an autoencoder to calculate the data reconstruction error; fusing the physical error and the data reconstruction error into a comprehensive anomaly index; comparing the comprehensive anomaly index with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison result.

[0140] To execute the above instructions more accurately, please refer to... Figure 7 As shown in the embodiments of this specification, another specific electronic device is also provided, wherein the electronic device includes a network communication port 701, a processor 702, and a memory 703. The above structures are connected by internal cables so that the various structures can perform specific data interaction.

[0141] Specifically, the processor 702 can be used to input drilling engineering parameters into a wellbore hydraulic model, generate downhole virtual sensing data, and fuse it with wellhead surface measured data to form multi-source fusion data. This multi-source fusion data is used to train a physical information neural network to obtain a gas invasion early warning prediction model. A real-time fusion feature vector is input into the gas invasion early warning prediction model to output a wellhead pressure prediction value. The real-time fusion feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. A physical error is calculated based on the wellhead pressure prediction value and the wellhead surface measured data. The wellhead surface measured data is then input into an autoencoder to calculate a data reconstruction error. The physical error and the data reconstruction error are fused into a comprehensive anomaly index. The comprehensive anomaly index is compared with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison results.

[0142] The memory 703 can be used to store the corresponding instruction program.

[0143] In this embodiment, the network communication port 701 can be a virtual port bound to different communication protocols, thereby enabling the sending or receiving of different data. For example, the network communication port can be a port responsible for web data communication, a port responsible for FTP data communication, or a port responsible for email data communication. Furthermore, the network communication port can also be a physical communication interface or communication chip. For example, it can be a wireless mobile network communication chip, such as GSM or CDMA; it can also be a Wi-Fi chip; or it can be a Bluetooth chip.

[0144] In this embodiment, the processor 702 can be implemented in any suitable manner. For example, the processor can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers, etc. This specification is not limiting.

[0145] In this embodiment, the memory 703 may include multiple layers. In a digital system, anything that can store binary data can be a memory. In an integrated circuit, a circuit with storage function but no physical form is also called a memory, such as RAM, FIFO, etc. In a system, a storage device with a physical form is also called a memory, such as a memory stick, TF card, etc.

[0146] This specification also provides a computer storage medium for a drilling gas invasion early warning method based on the above-mentioned mechanism and data dual constraints. The computer storage medium stores a computer program / instruction, which, when executed, performs the following: inputting drilling engineering parameters into a wellbore hydraulic model to generate downhole virtual sensing data, and fusing it with wellhead surface measured data to form multi-source fusion data. This multi-source fusion data is used to train a physical information neural network to obtain a gas invasion early warning prediction model. A real-time fusion feature vector is input into the gas invasion early warning prediction model to output a wellhead pressure prediction value. The real-time fusion feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. A physical error is calculated based on the wellhead pressure prediction value and the wellhead surface measured data, and the wellhead surface measured data is input into an autoencoder to calculate a data reconstruction error. The physical error and the data reconstruction error are fused into a comprehensive anomaly index. The comprehensive anomaly index is compared with a preset graded early warning threshold to perform graded early warning of drilling gas invasion based on the comparison result.

[0147] In this embodiment, the storage medium includes, but is not limited to, Random Access Memory (RAM), Read-Only Memory (ROM), Cache, Hard Disk Drive (HDD), or Memory Card. The memory can be used to store computer program instructions. The network communication unit can be an interface configured according to standards specified in the communication protocol for network connection communication.

[0148] In this embodiment, the specific functions and effects implemented by the program instructions stored in the computer storage medium can be explained in comparison with other implementation methods, and will not be repeated here.

[0149] While this specification provides the steps of operation for the methods described in the embodiments or flowcharts, more or fewer steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or client product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in a process, method, product, or apparatus that includes said elements is not excluded. The terms "first," "second," etc., are used to denote names and do not indicate any particular order.

[0150] Those skilled in the art will also know that, besides implementing the controller using purely computer-readable program code, the same functions can be achieved by logically programming the method steps, making the controller function as logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers (PLCs), and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the devices within it used to implement various functions can also be considered structures within that hardware component. Alternatively, the devices used to implement various functions can be considered as both software modules implementing the method and structures within a hardware component.

[0151] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0152] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this specification can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solutions of this specification can essentially be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, mobile terminal, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments of this specification.

[0153] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. This specification can be used in numerous general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable electronic devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices, etc.

[0154] Although this specification has been described by way of examples, those skilled in the art will recognize that many variations of this specification are possible without departing from its spirit, and it is intended that the appended claims cover such variations without departing from the spirit of this specification.

Claims

1. A drilling gas invasion early warning method with dual constraints of mechanism and data, characterized in that, include: Drilling engineering parameters are input into the wellbore hydraulic model to generate downhole virtual sensing data, which is then fused with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas intrusion early warning and prediction model. The real-time fused feature vector is input into the gas invasion early warning prediction model, and the wellhead pressure prediction value is output. The real-time fused feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. The physical error is calculated based on the predicted wellhead pressure and the measured wellhead surface data. The measured wellhead surface data is then input into an autoencoder to calculate the data reconstruction error. The physical error and the data reconstruction error are then combined into a comprehensive anomaly index. The comprehensive anomaly index is compared with a preset graded early warning threshold to conduct graded early warning of drilling gas invasion based on the comparison results.

2. The method according to claim 1, characterized in that, The drilling engineering parameters include at least one of the following: wellbore structure parameters, drill string assembly parameters, drilling process parameters, boundary condition parameters, and time control parameters; the wellbore structure parameters include at least one of the following: total well depth, wellbore diameter of each grid node, well inclination angle of each grid node, and well depth node spacing; the drill string assembly parameters include at least one of the following: outer diameter of each grid node drill string and inner diameter of each grid node drill string; the drilling process parameters include fluid properties, drilling fluid thermal properties, and flow rate; the fluid properties include at least one of the following: initial density of drilling fluid and initial plastic viscosity of drilling fluid; the drilling fluid thermal properties include at least one of the following: initial specific heat at constant pressure of drilling fluid and initial thermal conductivity of drilling fluid; the boundary condition parameters include at least one of the following: measured casing pressure at the wellhead, measured standpipe pressure at the wellhead, and measured outlet flow rate at the wellhead; the time control parameters include at least one of the following: target time period and time step. The downhole virtual sensing data includes at least one of the following: bottom hole virtual pressure, bottom hole virtual temperature, and casing shoe position virtual pressure; The measured surface data at the wellhead includes at least one of the following: measured riser pressure at the wellhead, measured casing pressure at the wellhead, measured drilling fluid injection rate, measured wellhead outlet flow rate, and measured drilling fluid inlet temperature.

3. The method according to claim 1, characterized in that, The wellbore hydraulic model consists of governing equations, which include the mass conservation equation, the momentum conservation equation, and the energy conservation equation. Accordingly, the step of inputting drilling engineering parameters into the wellbore hydraulic model to generate downhole virtual sensing data includes: Based on the input drilling engineering parameters, the wellbore is discretized into a preset number of grid nodes along the well depth direction. The preset number is determined according to the ratio of the total well depth to the well depth node spacing. The mass conservation equation, momentum conservation equation, and energy conservation equation are respectively transformed into discrete difference equations on each grid node; The temperature and pressure distribution of the entire wellbore in the previous time step is obtained as the initial condition for the current time step. Starting from the bottom grid node, the discrete difference equations of the mass conservation equation, momentum conservation equation and energy conservation equation are solved iteratively from bottom to top, with the initial temperature and pressure at the bottom of the well as the starting point of the iteration, to obtain the temperature and pressure of each grid node. The fluid property parameters of the corresponding grid nodes are updated according to the temperature and pressure of each grid node. The updated fluid property parameters are used as the input for solving the temperature and pressure of the adjacent upper grid nodes until the wellhead grid node is solved, so as to obtain the whole wellbore temperature and pressure distribution at the current time step. The whole wellbore temperature and pressure distribution includes the wellhead pressure. The wellhead pressure is compared with the measured wellhead pressure. If the error comparison result is greater than the preset error threshold, the initial temperature and pressure at the bottom of the well are adjusted, and the solution is iterated from bottom to top, grid node by grid node, until the calculation of all time steps within the target time period is completed, and the temperature and pressure distribution of the entire wellbore for all time steps within the target time period is output. The temperature and pressure at key locations are extracted from the temperature and pressure distribution of the entire wellbore at all time steps within the target time period, and used as the downhole virtual sensing data.

4. The method according to claim 3, characterized in that, The discrete difference equations for iteratively solving the mass conservation equation, momentum conservation equation, and energy conservation equation node by node from bottom to top include: Substitute the updated fluid properties of the lower grid nodes into the discrete difference equation of the mass conservation equation to obtain the density of the current grid node. The pressure of the current grid node is obtained by substituting the density of the current grid node, the pressure of the grid node below it, and the updated fluid properties into the discrete difference equation of the momentum conservation equation. The current grid node's pressure, the temperature of the grid node below it, and the updated fluid properties are all substituted into the discrete difference equation of the energy conservation equation to obtain the temperature of the current grid node. The pressure and temperature obtained from solving the current grid node are substituted into the property update equation to update the fluid property parameters of the current grid node. The density, pressure, temperature of the current grid node and the updated fluid property parameters are used together as the solution input for the adjacent grid nodes above.

5. The method according to claim 1, characterized in that, The air intrusion early warning and prediction model includes an input layer, a neural network body, an automatic differentiation module, a physical constraint module, and an output layer. The physical constraint layer has built-in mass conservation equations and momentum conservation equations. Accordingly, the step of fusing feature vectors into the gas invasion early warning prediction model in real time and outputting wellhead pressure prediction values ​​includes: The system receives the real-time fused feature vector through the input layer; processes the real-time fused feature vector through the neural network body to output the predicted pressure field of the entire wellbore; calculates the partial derivatives of the predicted pressure field of the entire wellbore with respect to spatial coordinates and time through the automatic differentiation module; calculates the residuals of the mass conservation equation and the momentum equation based on the partial derivatives through the physical constraint module as the physical equation residuals, and determines that the model has converged when the physical equation residuals are less than a preset convergence threshold; and extracts the pressure value at the wellhead position from the predicted pressure field through the output layer as the predicted wellhead pressure value.

6. The method according to claim 5, characterized in that, The calculation of the residuals of the mass conservation equation and the momentum equation based on the partial derivatives as the residuals of the physical equations includes: The partial derivatives of the whole-wellbore predicted pressure field and the whole-wellbore predicted pressure field output by the automatic differentiation module with respect to spatial coordinates and time are substituted into the mass conservation equation and momentum conservation equation built into the physical constraint module, respectively, to calculate the actual predicted values ​​of the mass conservation equation and the momentum conservation equation. The deviation between the actual predicted value and the theoretical value of the mass conservation equation is defined as the residual of the mass conservation equation. The deviation between the actual predicted value and the theoretical value of the momentum conservation equation is defined as the momentum conservation equation residual. The residuals of the mass conservation equation and the momentum conservation equation are weighted and summed to obtain the residuals of the physical equation.

7. The method according to claim 1, characterized in that, The process of inputting the wellhead surface measured data into the self-compiler to calculate the data reconstruction error includes: The measured surface data at the wellhead is used as the raw input data and compressed into low-dimensional feature codes by the encoder part of the autoencoder. The decoder part of the autoencoder reconstructs the data based on the low-dimensional feature encoding to obtain the reconstructed data. The deviation between the original input data and the reconstructed data is calculated to obtain the data reconstruction error, which is used to characterize the degree of abnormality of the fluctuation of the wellhead surface measured data. The fusion is a comprehensive anomaly index, including: The data reconstruction error is normalized to obtain the normalized reconstruction error, and the physical equation residual is normalized to obtain the normalized physical residual. The normalized reconstruction error and the normalized physical residual are weighted and fused to obtain the comprehensive anomaly index.

8. The method according to claim 1, characterized in that, The step of comparing the comprehensive anomaly index with a preset graded early warning threshold, and performing graded early warning of drilling gas invasion based on the comparison result, includes: The comprehensive anomaly index is compared sequentially with the first warning threshold, the second warning threshold, and the third warning threshold. If the comprehensive abnormal index is less than the first warning threshold, it is determined to be a normal operating condition; If the comprehensive abnormal index is greater than or equal to the first warning threshold and less than the second warning threshold, it is judged as a mild air intrusion. If the comprehensive anomaly index is greater than or equal to the second warning threshold and less than the third warning threshold, it is judged as a moderate air intrusion; If the comprehensive abnormal index is greater than or equal to the third warning threshold, it is judged as a severe air intrusion; Based on the determined level, a corresponding graded early warning signal is output.

9. A drilling gas invasion early warning device with dual constraints of mechanism and data, characterized in that, include: The first fusion module is used to input drilling engineering parameters into the wellbore hydraulic model, generate downhole virtual sensing data, and fuse it with wellhead surface measured data to form multi-source fusion data. The multi-source fusion data is used to train a physical information neural network to obtain a gas intrusion early warning and prediction model. The prediction module is used to input the real-time fused feature vector into the gas invasion early warning prediction model and output the wellhead pressure prediction value. The real-time fused feature vector includes real-time generated downhole virtual sensing data and real-time collected wellhead surface measured data. The second fusion module is used to calculate the physical error based on the predicted wellhead pressure and the measured wellhead surface data, input the measured wellhead surface data into the autoencoder to calculate the data reconstruction error, and fuse the physical error and the data reconstruction error into a comprehensive anomaly index. The graded early warning module is used to compare the comprehensive anomaly index with a preset graded early warning threshold, so as to perform graded early warning of drilling gas invasion based on the comparison result.

10. A computer storage medium, characterized in that, The computer storage medium stores computer program instructions, which, when executed, implement the steps of the method according to any one of claims 1 to 8.