# A Simulation Study on Pressure Control in Oil Well Drilling Using Gain-Scheduled PID Controllers
## 2 Wellbore Pressure Model
### Linearization of Bottom-Hole Pressure Dynamics  
To implement the Internal Model Control method, it was necessary to model the process as a set of linear equations. Linearizing nonlinear models is a common, crucial, and beneficial practice in engineering. This linearization process involves expanding the nonlinear function into a Taylor series around the operating point, retaining only the linear term [14]. The Kassa model is presented in (1)-(4):  
\[V_{d}\dot{P}_{p}=\beta_{d}(q_{p}-q_{b})\,, \tag{1}\]  
\[V_{a}\dot{P}_{e}=\beta_{a}(q_{b}+q_{r}+q_{c}-q_{e}), \tag{2}\]  
\[\dot{q}_{b}M = P_{p}-P_{e}-F_{a}\big{(}q_{b}+q_{r})^{2}-F_{d}{q_{b}}^{2}+(\rho_{d}- \rho_{a})g{h_{b}}\,, \tag{3}\] \[P_{b}M = M_{d}P_{e}+M_{a}P_{p}+M_{d}F_{a}\big{(}q_{b}+q_{r})^{2}-M_{a}F_{d }{q_{b}}^{2}+(M_{a}\rho_{d}-M_{d}\rho_{a})g{h_{b}}\,\,\,. \tag{4}\]  
First, the input and output variables of the system, represented by the previously mentioned nonlinear equations, had to be identified. The input variables were those that could be manipulated to influence other variables, such as the parameters \(q_{p}\), \(q_{r}\), \(q_{d}\), \(q_{e}\), and \({h_{b}}\) in this case. Using Equations (1)-(4), the Taylor series expansion was applied, resulting in equations that were then arranged into the state equation of the dynamic system, as shown in Equations (5)-(8). \[J_{a}= \begin{pmatrix}\frac{\partial\dot{P}_{p}}{\partial P_{p}}&\frac{\partial \dot{P}_{p}}{\partial P_{e}}&\frac{\partial\dot{P}_{p}}{\partial b_{b}}\\ \frac{\partial\dot{P}_{p}}{\partial P_{e}}&\frac{\partial\dot{P}_{e}}{\partial P _{e}}&\frac{\partial\dot{P}_{e}}{\partial b_{b}}\\ \frac{\partial\dot{P}_{p}}{\partial P_{e}}&\frac{\partial\dot{P}_{e}}{\partial P _{e}}&\frac{\partial\dot{P}_{e}}{\partial b_{b}}\\ \end{pmatrix} , \tag{5}\]  
Figure 1: A schematic of a well drilling system with fluid flow dynamics and pressure control. \[J_{b}= \begin{pmatrix}\frac{\partial P_{b}}{\partial q_{p}}&\frac{\partial P_{p}}{ \partial u}&\frac{\partial P_{b}}{\partial q_{p}}&\frac{\partial P_{p}}{ \partial b_{b}}\\ \frac{\partial P_{p}}{\partial q_{p}}&\frac{\partial P_{p}}{\partial u}&\frac{ \partial P_{p}}{\partial q_{p}}&\frac{\partial P_{p}}{\partial b_{b}}\\ \frac{\partial d_{b}}{\partial q_{p}}&\frac{\partial d_{b}}{\partial u}&\frac {\partial d_{b}}{\partial q_{p}}&\frac{\partial b_{b}}{\partial b_{b}}\end{pmatrix} . \tag{6}\]  
The input \(u\) is the sum of the flow rate from the throttling valve and the flow produced by the backpressure pump (\(u=q_{c}-q_{e}\)). \[J_{c}= \begin{pmatrix}\frac{\partial P_{b}}{\partial P_{p}}\ \vdots\ \frac{ \partial P_{b}}{\partial p_{e}}\ \vdots\ \frac{\partial P_{b}}{\partial q_{b}}\end{pmatrix} , \tag{7}\]  
\[J_{d}= \begin{pmatrix}\frac{\partial P_{b}}{\partial q_{p}}\ \vdots\ \frac{ \partial P_{b}}{\partial u}\ \vdots\ \frac{\partial P_{b}}{\partial q_{r}}\ \vdots\ \frac{\partial P_{b}}{\partial h_{b}}\end{pmatrix} . \tag{8}\]  
The state equation of a dynamic system describes the relationship between the input variables (\(U\)), state variables (\(X\)), and output variables (\(Y\)). \[ \begin{array}{c}\dot{X}=J_{a}X+J_{b}U\,\ \ x(0)=x_{o},\\ Y=J_{c}X+J_{d}U\end{array}  \tag{9}\]  
Equations (10) and (11) illustrate the arrangement of Equation (9), highlighting its identified input, output, and state variables. \[ \begin{pmatrix}\dot{P}_{p}\\ \dot{P}_{e}\\ \dot{q}_{b}\end{pmatrix} =J_{a} \begin{pmatrix}P_{p}\\ P_{e}\\ q_{b}\end{pmatrix} +J_{b} \begin{pmatrix}q_{p}\\ u\\ q_{r}\\ h_{b}\end{pmatrix} ,\ \ \begin{pmatrix}P_{p}(0)\\ P_{e}(0)\\ q_{b}(0)\end{pmatrix} , \tag{10}\]  
\[P_{b}=J_{c} \begin{pmatrix}P_{p}\\ P_{e}\\ q_{b}\end{pmatrix} +J_{d} \begin{pmatrix}q_{p}\\ u\\ q_{r}\\ h_{b}\end{pmatrix} . \tag{11}\]  
Equations (12)-(15) present the parameters of the state equation for the linearized dynamic system. \[J_{a}= \begin{pmatrix}0&0&-\frac{\beta_{c}}{\beta_{c}}\\ 0&0&\frac{\beta_{a}}{\beta_{a}}\\ \frac{1}{M}&\frac{-1}{M}&-\frac{2}{M}[(F_{c}+F_{a})\overline{q_{b}}+F_{a} \overline{q_{r}}]\end{pmatrix} , \tag{12}\]  
\[J_{b}=