# The Cascade Control of Natural Gas Pipeline Systems
## 2 Cascade Control Algorithm
### State Space Model  
To get the cascade control algorithm, a mathematical model of the dynamic properties of the gas pipelines has to be established for the outer loop calculation. The modeling process starts from the fundamental governing equations of fluid.  
\[\frac{\partial\rho}{\partial t}+\frac{\partial\left(\rho\mathbf{u}\right)}{ \partial x}=0 \tag{1}\]  
\[\frac{\partial p}{\partial x}=-\frac{\partial\left(\rho\mathbf{u}\right)}{ \partial t}-\lambda\frac{u|u|}{2D}\rho-\rho g\sin\alpha \tag{2}\]  
\[\frac{\partial Q}{\partial x}(\rho\mathbf{u})=\frac{\partial}{\partial t}[( \rho)(\hat{\mathbf{u}}+\frac{\mathbf{u}^{2}}{2}+g\Delta h)]+\frac{\partial}{ \partial x}[(\rho)(H+\frac{\mathbf{u}^{2}}{2}+gs)] \tag{3}\]  
\[\frac{p}{\rho}=ZRT, \tag{4}\]  
where \(\rho\) is the gas density, \(kg/m^{3}\); \(D\) is the pipeline inner diameter, \(m\); \(g\) is the gravitational acceleration, \(m/s^{2}\); \(\alpha\) is the inclination; \(T\) is the gas temperature, \(Kelvins\) (\(K\)); \(R\) is the gas constant, \(kJ/(kg\cdot K)\); \(\lambda\) is the friction factor of the pipeline; \(Z\) is the gas compressibility factor; \(u\) is the gas axial velocity, \(m/s\); \(\frac{\partial Q}{\partial x}\) is the heat flow into the pipe per unit length of pipe and per unit time, \(J/(m\cdot s)\); \(\hat{\mathbf{u}}\) is the specific internal energy, \(J/kg\); \(\Delta h\) is the elevation, \(m\); \(H\) is the specific enthalpy, \(J/kg\); \(x\) is pipeline coordinate, \(m\); and \(t\) is time, \(s\).  
The method of characteristics, explicit and implicit finite difference methods, and finite element methods have been used to solve the governing equations to obtain good simulation results. However, a control oriented mathematical model is necessary for the automated scheduling process. The modeling process consists of the following steps:  
* The equivalent transfer functions are derived from the governing Equations (1)-(4).  
Figure 2: The cascade control system of the natural gas pipeline.  
* The series form of the models in time domain is obtained using the convolution theorem.
* A few dominant flow eigenmodes are used to construct an efficient reduced-order model, i.e., ordinary differential equation (ODE) model.  
As seen from the above, the state space models are to neglect some of the terms in partial differential equations (PDE) and maintain an appropriate level of accuracy at the same time. By the convenience of the state space model, it can be easily applied for the cascade controller design.  
Following the derivation process in [14], the state space models (Equation (5)) is ready to be obtained, where the gas pressure at inlet (\(P_{in}\)) and the mass flow rate at the outlet (\(M_{out}\)) are the input vectors, and the pressure at the outlet (\(P_{out}\)) and the gas mass flow rate at the inlet (\(M_{in}\)) are the output vectors.  
\[\dot{x}=\mathbb{A}x+\mathbb{B}u \tag{5}\] \[y=\mathbb{C}x+\mathbb{D}u\]  
where \(u=[P_{in},M_{out}]\) and \(y=[P_{out},M_{in}]\)  
\[\mathbb{A}=\left[\begin{array}{cccc}-\frac{a_{1}}{a_{2}}&1&0&0\\ 0&-\frac{1}{a_{2}}&0&0\\ 0&0&-\frac{a_{1}}{a_{2}}&1\\ 0&0&-\frac{\mathbb{I}}{a_{2}}&0\end{array}\right],\ \ \mathbb{B}=\left[\begin{array}{ c c}0&-\frac{k_{2}T_{1}}{a_{2}}\\ \frac{k_{1}}{a_{2}}&-\frac{k_{2}}{a_{2}}\\ \frac{T_{11}}{a_{2}}&0\\ 0&\frac{1}{a_{2}}\end{array}\right],\ \ \mathbb{C}=\left[\begin{array}{ c c c}1&0&0&0\\ 0&0&1&0\end{array}\right]. \tag{6}\]  
Since the state equation of pipe section is multi-dimensional, the state dimension is related to the number of pipe sections. There are two input variables and the output variables are related to the measurement points. Therefore, \(x\), \(u\), and \(y\) in the following formula are multi-dimensional vectors and the system is a multiple-input multiple-output (MIMO) system.  
\[G\left\{\begin{array}{l}\dot{x}(t)=Ax(t)+Bu(t)\\ y(t)=Cx(t)\end{array}\right. \tag{7}\]