**1. Introduction**

Since the mid nineteenth century, the unsteady flow of fluid has been a much discussed topic for scholars. In steady flow, the parameter at any point does not change with time; while in unsteady flow, the parameter at any point is a function of time and changes with it [1,2]. When boundary conditions at the end of a pipeline change, the steady flow in the pipeline will also change accordingly, manifested as a sudden change in the flow rate and pressure of the fluid, which causes momentum conversion. The occurrence time of this phenomenon is generally very short, so it is called transient flow, also known as water hammer or water hammer [3,4]. At present, the most representative work on water hammer is "Transient Flow" written by Professor Streeter, an American hydraulicsist [5]. This

**Citation:** Duan, J.; Li, C.; Jin, J. Establishment and Solution of Four Variable Water Hammer Mathematical Model for Conveying Pipe. *Energies* **2022**, *15*, 1387. https:// doi.org/10.3390/en15041387

Academic Editors: Min Wang, Sheng-Qi Yang, Kun Du, Chun Zhu, Qi Wang, Wen Zhang and Antonio Crespo

Received: 7 January 2022 Accepted: 11 February 2022 Published: 14 February 2022

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Copyright:** © 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

monograph systematically explains the types of water hammer process, the mechanism and derivation of water hammer, the applicable conditions of the model and the corresponding solution method, etc. Today, the method of characteristics (MOC), first proposed in the monograph, are widely used to characterize the water hammer process.

The classical transient flow models of pressurized pipe flow all use a reservoir-pipevalve system as the research object and close the valve as the research condition [6,7]. The mathematical model includes the motion equation and the continuity equation. The pipeline element is selected as the control body. The momentum equation is established by the momentum change of the fluid entering and exiting the control body, and the continuity equation is established by the mass conservation of the fluid entering and exiting the control body. When the valve is closed, a short section of fluid at the valve stops flowing instantaneously, and the next section of fluid next to this section of fluid and in the upstream direction is blocked, decelerating to a standstill. By analogy, the fluid in the tube gradually stops moving along the upstream direction. Since the kinetic energy of the fluid is reduced and converted into pressure energy, the pressure in the tube gradually increases along the upstream direction. That is, a pressure wave propagates upstream at a wave velocity *a* [8,9]. Figure 1 shows the movement of the liquid in a horizontal pipeline after the valve is suddenly closed at the end of a pipeline, ignoring the friction and local loss.

**Figure 1.** The fluid movement state in the pipe after the valve is suddenly closed (ignoring friction) [10].

In recent years, many scholars have performed research on the transient flow in fluid pipelines. Baba [11] considered the numerical calculation of the transient flow model of a hydrogen-natural gas mixture in pipelines with different types of valves. The influence of the valve function was analyzed, and the calculation results under different mass ratios and gas mixture flow parameters were given. Wahba [12] used one-dimensional and twodimensional water hammer models to numerically study the attenuation of turbulence in pipelines. The one-dimensional model was solved by the characteristic line method, and the two-dimensional model was solved by the semidiscretization method and the fourth-order Runge—Kutta method. Kandil [13] used the characteristic line method to numerically solve the water hammer equation and studied pressure fluctuations by changing the elastic modulus of the pipeline and Poisson's ratio. Hossam [14] first used the wave characteristic line method to numerically simulate the transient flow in a viscoelastic pipe, re-derived the Joukowsky equation of the elastic pipe, and derived the quadratic equation of energy conservation in the viscoelastic pipe. Khamoushi [15] proposed a one-dimensional model of transient flow in non-Newtonian fluids, using Zielke's unsteady friction solution for

power law fluids and cross fluids. The time increment updated the weight function of the Zielke model. Abdeldayem [16] studied and explored the performance of different unsteady friction models in terms of accuracy, efficiency, and reliability to determine the most suitable model for engineering practice. Through comparison, it was found that Vítkovský's unsteady friction model is the most suitable. Taking the reservoir-pipe-valve system as an example, the effectiveness of the method was verified by experimental data. Lashkarbolok [17] used radial-basis functions and least-squares optimization technology to solve the numerical solution of one-dimensional equations governing transient pipe flow. The method can deal with geometrically nonuniform pipes by employing an arbitrary distribution of scattering nodes in the space domain. Aliabadi [18] studied fluid-structure interaction (FSI) during water hammer in a viscoelastic (VE) pipe in the frequency domain. The main aim was to investigate pressure and stress waves using the transfer matrix method (TMM) in a typical reservoir-VE pipe-valve (RPV) system. Both major coupling mechanisms, namely Poisson and junction, are taken into account. Firouzi [19] proposed a time-varying reliability method to predict the failure risk of pipeline strength reduction due to the combination of water hammer pressure and corrosion and proposed the coupling model of pitting corrosion and water hammer pressure. It was found that with an increase in the average incidence of water hammer, the risk of pipeline failure increases, and the sudden closure of pipeline valves will have a destructive impact on the safety of a pipe network. Henclik [20] proposed an original concept of applying a shock response spectrum (SRS) method to water hammer events. The method is shortly presented, its numerical approach developed, and its application to water hammer loads described. SRS computations and analysis of water hammer experimental results measured at a laboratory pipeline are performed and concluded. Chen [21] constructed a fluid-solid coupling 4 equation model applied to high-temperature and high-pressure oil and gas based on the fluid-solid coupling theory and selected the best coupling method and combined the characteristic line method to obtain the pressure-wave velocity. Zhu [22,23] conducted a transient flow experiment using a sudden valve closing of a gas-liquid two-phase pressurized pipe flow and used the experiment to verify that the pressure-wave velocity of a pressurized pipe flow transient flow model was corrected by the gas content rate. At the same time, considering the nonconstant friction and the viscoelasticity of the pipe, the influence on gas flow and pressure-wave dissipation was studied, and the relevant parameters were checked. Fu [24,25] used the split-phase flow model to simulate the liquid column separation caused by transient flow in the pressure pipe flow and also considered the influence of the pipe stress wave on the pressure wave. Due to the existence of nonconservative terms in the model and to ensure the convergence of the results, this model needed to be solved separately while relaxation parameters were introduced. Han [26] examined bridging the water hammer in long-distance pipelines. He based his study on classic water hammer theory, considering the growth and reduction of cavities, the air content in the pipeline, and the water hammer after the instantaneous change in the pressure in the corrugated tube, among other factors. The process was described in semianalytical mathematics, and the influence of the growth and reduction time of cavities, the size of the gas content, and the relative elevation of the highest point of the pipeline to the horizontal section on bridging the water hammer pressure was analyzed.

After investigation, it was found that a large number of domestic and foreign literatures regard the fluid density in the conveying pipe as a constant. When the fluid in the tube is all liquid, the error caused by the fluid density as a constant is within the engineering allowable range. However, when there is gas (natural gas, etc.) in the tube, the gas has different degrees of compressibility and the density varies widely. Treating it as a constant violates the actual process of fluid flow in the tube. The density is closely related to the pressure-wave speed, which should also be constantly changing along the pipeline.

Furthermore, when calculating water hammer pressure, earlier researchers did not consider the change and inconsistency of the research object at the beginning and end of the period due to fluid inflow and outflow in the d*t* period. Based on the essence of water hammer, the interaction between pipeline fluid motion and water hammer wave propagation is considered in this paper, and the pressure, velocity, density and overflow area are set as variables. A new set of water hammer calculation equations is deduced and solved numerically. The effects of different valve closing time, flow rate and gas content on pressure distribution and water hammer effect are studied. Such calculations of the propagation process of the water hammer wave are more reasonable and reliable.

#### **2. Mathematical Model**

#### *2.1. Fluid Motion Equation*

Taking the water body in the flow section of length x as the research object, this paper tracks it to study the water body in the flow section. The analysis diagram of the interaction between the pipe water movement and the water hammer wave propagation is shown in Figure 2. The initial length of the stream segment is set to *x*. The liquid in the flow section between section 1-1 and section 2-2 at the initial time is taken as the research object. Taking into account the original flow of the liquid, after the d*t* period, the flow segment 1-2 moves to a new position 1 -2 , and the crest of the water hammer wave also propagates to the position of section 1 -1 .

**Figure 2.** Schematic diagram of water hammer wave propagation.

As shown in Figure 2, after the d*t* period, section 1-1 of the studied control body moves to the position of section 1 -1. The movement distance is d*s*. The water hammer wave moves from section 2-2 to Section 1 -1 at wave speed *c*. The movement distance is y, and section 2-2 moves to Section 2 -2 .

At the beginning of d*t*, the momentum of the liquid in the 1-2 flow section is:

$$\begin{cases} \rho + \frac{\partial \rho}{\partial s} \frac{\mathbf{x}}{2} \Big) \left( A + \frac{\partial A}{\partial s} \frac{\mathbf{x}}{2} \right) \left( v + \frac{\partial \mathbf{x}}{\partial s} \frac{\mathbf{x}}{2} \right) \mathbf{x} = \rho A v \mathbf{x} + \frac{1}{2} \frac{\partial (\rho A v)}{\partial s} \mathbf{x}^2 \\\ + \frac{1}{4} \Big( \rho \frac{\partial A}{\partial s} \frac{\partial v}{\partial s} + A \frac{\partial \rho}{\partial s} \frac{\partial v}{\partial s} + v \frac{\partial \rho}{\partial s} \frac{\partial A}{\partial s} \Big) \mathbf{x}^3 + \frac{1}{8} \frac{\partial \rho}{\partial s} \frac{\partial A}{\partial s} \frac{\partial v}{\partial s} \mathbf{x}^4 \approx \rho A v \mathbf{x} + \frac{1}{2} \frac{\partial (\rho A v)}{\partial s} \mathbf{x}^2 \end{cases} \tag{1}$$

At the end of time d*t*, the average density of the fluid in the 1 -2 flow section is:

$$\begin{cases} \widetilde{\rho} = \frac{1}{2} \left\{ \rho + \frac{\partial \rho}{\partial s} \mathrm{ds} + \frac{\partial}{\partial t} \left( \rho + \frac{\partial \rho}{\partial s} \mathrm{ds} \right) \mathrm{d}t + \rho + \frac{\partial \rho}{\partial s} (\mathrm{x} + \mathrm{d}\mathrm{l}) + \frac{\partial}{\partial t} \left[ \rho + \frac{\partial \rho}{\partial s} (\mathrm{x} + \mathrm{d}\mathrm{l}) \right] \mathrm{d}t \right\} \\ \approx \rho + \frac{\partial \rho}{\partial s} \mathrm{ds} + \frac{\partial \rho}{\partial t} \mathrm{d}t + \frac{1}{2} \frac{\partial \rho}{\partial s} \mathrm{x} \end{cases} \tag{2}$$

In the same way, at the end of time d*t*, the average area of the fluid in the 1 -2 flow section is:

$$
\widetilde{A} \approx A + \frac{\partial A}{\partial s} \text{ds} + \frac{\partial A}{\partial t} \text{dt} + \frac{1}{2} \frac{\partial A}{\partial s} \text{x} \tag{3}
$$

The average velocity of the fluid in the 1 -2 stream section is:

$$
\tilde{\upsilon} \approx \upsilon + \frac{\partial \upsilon}{\partial \mathbf{s}} \mathbf{d} \mathbf{s} + \frac{\partial \upsilon}{\partial t} \mathbf{d}t + \frac{1}{2} \frac{\partial \upsilon}{\partial \mathbf{s}} \mathbf{x} \tag{4}
$$

Therefore, at the end of time d*t*, the fluid momentum in the 1 -2 flow section is:

$$\begin{aligned} \rho \mathbf{u} &= \left(\rho + \frac{\partial \rho}{\partial s} \mathbf{ds} + \frac{\partial \rho}{\partial t} \mathbf{dt} + \frac{1}{2} \frac{\partial \rho}{\partial s} \mathbf{x}\right) \left(A + \frac{\partial A}{\partial s} \mathbf{ds} + \frac{\partial A}{\partial t} \mathbf{dt} + \frac{1}{2} \frac{\partial A}{\partial s} \mathbf{x}\right) \left(\mathbf{v} + \frac{\partial \mathbf{u}}{\partial s} \mathbf{ds} + \frac{\partial \mathbf{v}}{\partial t} \mathbf{dt} + \frac{1}{2} \frac{\partial \mathbf{v}}{\partial s} \mathbf{x}\right) (\mathbf{y} + \mathbf{dl}) \\ &= \rho A \mathbf{v} \mathbf{x} + \frac{\partial (\rho A \mathbf{v})}{\partial s} \mathbf{x} \mathbf{ds} + \frac{\partial (\rho A \mathbf{v})}{\partial t} \mathbf{x} \mathbf{dt} + \frac{1}{2} \frac{\partial (\rho A \mathbf{v})}{\partial s} \mathbf{x}^2 + \rho A \mathbf{v} \mathbf{x} \frac{\partial \mathbf{v}}{\partial s} \mathbf{d} \mathbf{t} \end{aligned} \tag{5}$$

At the time of d*t*, the increase of momentum in the studied control body is:

$$\begin{aligned} \rho \rho &= \quad \left[\rho A v \mathbf{x} + \frac{\partial (\rho A v)}{\partial \mathbf{s}} \mathbf{x} \mathbf{d} \mathbf{s} + \frac{\partial (\rho A v)}{\partial \mathbf{t}} \mathbf{x} \mathbf{d} \mathbf{t} + \frac{1}{2} \frac{\partial (\rho A v)}{\partial \mathbf{s}} \mathbf{x}^2 + \rho A v \mathbf{x} \frac{\partial v}{\partial \mathbf{s}} \mathbf{d} \mathbf{t} \right] - \\ & \left[\rho A v \mathbf{x} + \frac{1}{2} \frac{\partial (\rho A v)}{\partial \mathbf{s}} \mathbf{x}^2 \right] = \frac{\partial (\rho A v)}{\partial \mathbf{s}} \mathbf{x} \mathbf{d} \mathbf{s} + \frac{\partial (\rho A v)}{\partial \mathbf{t}} \mathbf{x} \mathbf{d} \mathbf{t} + \frac{1}{2} \frac{\partial (\rho A v)}{\partial \mathbf{s}} \mathbf{x}^2 \end{aligned} \tag{6}$$

The external force acting on the control body includes the hydrodynamic pressure of the cross-section at both ends, the hydrodynamic pressure of the side, gravity and the frictional resistance of the pipe wall. Because the distance of the control body movement in the d*t* period is very small, when analyzing the combined external force it receives, the analysis of the 1-2 flow section is equivalent to the 1 -2 analysis. Therefore, at the time of d*t*, the impulse of the external force received by the control body is:

$$\frac{\partial(\rho A v)}{\partial s} \mathbf{x} \, \mathrm{d}s + \frac{\partial(\rho A v)}{\partial t} \mathbf{x} \, \mathrm{d}t + \rho A v \mathbf{x} \, \frac{\partial v}{\partial s} \, \mathrm{d}t = \left[ -\frac{\partial(\rho A)}{\partial s} \mathbf{x} + p \frac{\partial A}{\partial s} \mathbf{x} + \rho g A \mathbf{x} \, \sin \theta - \eta \chi \mathbf{x} \right] \, \mathrm{d}t \tag{7}$$

After sorting, the formula can be obtained:

$$\left(\frac{1}{\rho}\frac{\mathrm{d}\rho}{\mathrm{d}\rho} + \frac{1}{A}\frac{\mathrm{d}A}{\mathrm{d}\rho}\right)\frac{\mathrm{d}p}{\mathrm{d}t} + \frac{1}{v}\frac{\mathrm{d}v}{\mathrm{d}t} + \frac{\partial v}{\partial s} + \frac{1}{\rho v}\frac{\partial p}{\partial s} - \frac{g}{v}\sin\theta + \frac{\tau\_{0}\chi}{\rho Av} = 0\tag{8}$$

Through the simultaneous establishment of a one-dimensional unsteady continuity equation:

$$\frac{1}{v}\frac{\partial v}{\partial t} + \frac{\partial v}{\partial s} + \frac{1}{\rho v}\frac{\partial p}{\partial s} - \frac{g}{v}\sin\theta + \frac{\tau\_0 \chi}{\rho Av} = 0 \tag{9}$$

Because of *<sup>∂</sup><sup>z</sup> <sup>∂</sup><sup>s</sup>* = − sin *θ*, substitute the above formula to obtain:

$$\frac{1}{g}\frac{\partial v}{\partial t} + \frac{v}{g}\frac{\partial v}{\partial s} + \frac{1}{\gamma}\frac{\partial p}{\partial s} + \frac{\partial z}{\partial s} + \frac{\pi\_0 \chi}{\gamma A} = 0 \tag{10}$$

Equation (10) is the water hammer motion equation.

#### *2.2. Fluid Continuity Equation*

The derivation of a water hammer continuity equation uses the law of mass conservation and takes the fluid in the flow section with length *x* as the research object, as shown in Figure 2. Both ends of the pipe section are section 1-1 and section 2-2, respectively.

The difference in the quality of the liquid flowing into and out of the control body during the d*t* period is:

$$\frac{1}{\mathcal{g}}\frac{\partial v}{\partial t} + \frac{v}{\mathcal{g}}\frac{\partial v}{\partial s} + \frac{1}{\gamma}\frac{\partial p}{\partial s} + \frac{\partial z}{\partial s} + \frac{\pi\_0 \chi}{\gamma A} = 0 \tag{11}$$

At the beginning of the d*t* period, the fluid quality in flow section 1-2 is:

$$\rho \left(\rho + \frac{\partial \rho}{\partial s} \frac{x}{2}\right) \left(A + \frac{\partial A}{\partial s} \frac{x}{2}\right) \mathbf{x} \approx \rho A \mathbf{x} + \frac{1}{2} \frac{\partial (\rho A)}{\partial s} \mathbf{x}^2 \tag{12}$$

At the end of the d*t* period, the fluid quality in flow section 1-2 is:

$$\left(\rho + \frac{\partial \rho}{\partial s} \frac{\mathbf{x}}{2} + \frac{\partial \rho}{\partial t} \mathbf{d}t\right) \left(A + \frac{\partial A}{\partial s} \frac{\mathbf{x}}{2} + \frac{\partial A}{\partial t} \mathbf{d}t\right) \mathbf{x} \approx \rho A \mathbf{x} + \frac{\partial (\rho A)}{\partial s} \frac{\mathbf{x}^2}{2} + \frac{\partial (\rho A)}{\partial t} \mathbf{x} \mathbf{d}t \tag{13}$$

Therefore, the fluid mass increase in flow segment 1-2 during the d*t* period is:

$$\left[\rho A\mathbf{x} + \frac{\partial(\rho A)}{\partial \mathbf{s}} \frac{\mathbf{x}^2}{2} + \frac{\partial(\rho A)}{\partial t} \mathbf{x} \mathbf{d}t\right] - \left[\rho A\mathbf{x} + \frac{\partial(\rho A)}{\partial \mathbf{s}} \frac{\mathbf{x}^2}{2}\right] = \frac{\partial(\rho A)}{\partial t} \mathbf{x} \mathbf{d}t \tag{14}$$

According to the law of conservation of mass, during the d*t* period, the difference between the mass of fluid flowing into and out of the control body should be equal to the increase in the mass of the fluid in the control body during the same period, that is:

$$\frac{\partial(\rho A)}{\partial t} + \frac{\partial(\rho A v)}{\partial s} = 0 \tag{15}$$

Equation (15) is the water hammer continuity equation derived in this paper. Therefore, the water hammer calculation equations can be obtained as:

$$\begin{cases} \frac{\partial(\rho A)}{\partial t} + \frac{\partial(\rho A v)}{\partial s} = 0\\ \frac{1}{\mathcal{g}} \frac{\partial v}{\partial t} + \frac{v}{\mathcal{g}} \frac{\partial v}{\partial s} + \frac{1}{\gamma} \frac{\partial p}{\partial s} + \frac{\partial z}{\partial s} + \frac{\pi y\_X}{\gamma A} = 0 \end{cases} \tag{16}$$

#### *2.3. Complete Equations of Water Hammer*

Since:

Generally in engineering, it is customary to use the piezometer head *H* to reflect the pressure *p*. Therefore, substituting *p* = *ρg*(*H* − *z*) into the equation of motion, we can get:

$$\frac{\partial \mathbf{d}\rho}{\partial t} = \frac{\partial p}{\partial t} + v \frac{\partial p}{\partial s} = \frac{\partial [\rho \mathbf{g}(H - z)]}{\partial t} + v \frac{\partial [\rho \mathbf{g}(H - z)]}{\partial s} = \rho \mathbf{g} \frac{\mathbf{d}(H - z)}{\mathbf{d}t} + \mathbf{g}(H - z) \frac{\mathbf{d}\rho}{\mathbf{d}t} \tag{17}$$

where, *<sup>∂</sup><sup>z</sup> <sup>∂</sup><sup>t</sup>* <sup>=</sup> 0, *<sup>∂</sup><sup>z</sup> <sup>∂</sup><sup>s</sup>* = − sin *θ*, *θ* is the included angle between the pipe axis and the horizontal direction.

The above formula considers the variation of liquid density *ρ* with time *t* and distance *s* during water hammer, which is different from the traditional water hammer equations.

$$\frac{\partial p}{\partial s} = \frac{\partial [\rho g(H - z)]}{\partial s} = \gamma \frac{\partial H}{\partial s} - \gamma \frac{\partial z}{\partial s} + g(H - z) \frac{\partial \rho}{\partial s} \tag{18}$$

Then substitute *γ* = *ρg*, *τ*<sup>0</sup> = <sup>1</sup> <sup>8</sup> *<sup>f</sup> <sup>ρ</sup>v*<sup>2</sup> and *<sup>χ</sup>*<sup>0</sup> = *<sup>π</sup><sup>D</sup>* = <sup>2</sup> <sup>√</sup>*π<sup>A</sup>* into the equation of motion to obtain:

$$\frac{\partial v}{\partial t} + v \frac{\partial v}{\partial s} + g \frac{\partial H}{\partial s} + \frac{(H - z)g}{\rho} \frac{\partial \rho}{\partial s} + \frac{fv|v|}{4} \sqrt{\frac{\pi}{A}} = 0 \tag{19}$$

Since the fluid elasticity equation is:

$$\frac{1}{\rho} \frac{\mathbf{d}\rho}{\mathbf{d}p} = \frac{1}{K} \tag{20}$$

The elastic equation of the pipe is:

$$\frac{1}{A} \frac{\mathbf{d}A}{\mathbf{d}p} = \frac{D}{E\epsilon} \tag{21}$$

The simultaneous hydroelasticity Equations (20) and (19) can be obtained:

$$
\left(\frac{\partial\rho}{\partial t} + v\frac{\partial\rho}{\partial s} - \frac{\rho}{\left[\frac{K}{\rho\xi} - (H - z)\right]}\right)\left(\frac{\partial H}{\partial t} + v\frac{\partial H}{\partial s} + v\sin\theta\right) = 0\tag{22}
$$

The simultaneous elastic equation of pipe (21) and Equation (19) can be obtained:

$$
\rho \frac{\partial A}{\partial t} + v \frac{\partial A}{\partial s} - \frac{\frac{2AK}{\varepsilon\pi} \sqrt{\frac{A}{\pi}}}{\left[\frac{K}{\rho\%} - (H - z)\right]} \left(\frac{\partial H}{\partial t} + v \frac{\partial H}{\partial s} + v \sin \theta\right) = 0\tag{23}
$$

After sorting, the formula can be obtained:

$$
\rho \frac{\partial H}{\partial t} + \upsilon \frac{\partial H}{\partial s} + \upsilon \sin \theta + \frac{\frac{1}{\rho \mathcal{S}} - \frac{(H - z)}{K}}{\frac{2}{\text{Ec}} \sqrt{\frac{A}{\pi}} + \frac{1}{\mathcal{R}}} \frac{\partial \upsilon}{\partial s} = 0 \tag{24}
$$

Thus, the water hammer closure equations are:

$$\begin{cases} \frac{\partial v}{\partial t} + v \frac{\partial v}{\partial s} + \mathcal{S} \frac{\partial H}{\partial s} + \frac{(H-z)\mathcal{K}}{\rho} \frac{\partial \rho}{\partial s} + \frac{fv|v|}{4} \sqrt{\frac{\mu}{A}} = 0 \\\\ \frac{\partial H}{\partial t} + v \frac{\partial H}{\partial s} + v \sin \theta + \frac{\frac{1}{\rho \xi} - \frac{(H-z)}{\kappa}}{\frac{\partial}{\partial z} \sqrt{\frac{\mu}{A} + \frac{1}{\kappa}}} \frac{\partial v}{\partial s} = 0 \\\\ \frac{\partial \rho}{\partial t} + v \frac{\partial \rho}{\partial s} - \frac{\rho}{\left[ \frac{K}{\rho \xi} - (H-z) \right]} \left( \frac{\partial H}{\partial t} + v \frac{\partial H}{\partial s} + v \sin \theta \right) = 0 \\\\ \frac{\partial A}{\partial t} + v \frac{\partial A}{\partial s} - \frac{\frac{24K}{\rho \xi} \sqrt{\frac{\mu}{\tau}}}{\left[ \frac{K}{\rho \xi} - (H-z) \right]} \left( \frac{\partial H}{\partial t} + v \frac{\partial H}{\partial s} + v \sin \theta \right) = 0 \end{cases} \tag{25}$$

### **3. Model Solving and Boundary Conditions**

#### *3.1. Difference Equation*

In the calculation of water hammer equations, the more common methods are the characteristic line method and the direct difference method based on the finite difference method [27,28]. Because their deformation form cannot be transformed into characteristic equations, the characteristic line method cannot be used for calculation of the Gestalt equations proposed in this paper. Instead, the direct difference method is selected for calculation.

Compatibility, convergence and stability must be considered in difference calculations [28–30]. Change the differential equation into a difference equation. If the computational grid is reduced, the difference equation tends to be consistent with the differential equation. For example, the solution of the difference equation converges to the solution of the differential equation, which is convergence. If the rounding error and initial error in the calculation are always controlled within a limited range, and the calculated value is close to the true solution, then this scheme is stable. For the diffusion difference scheme adopted in this paper, the stability condition is the Courant condition. Since the water hammer equation is a hyperbolic equation, its stability condition should still meet the following requirements even though the concept of water hammer wave velocity is not introduced:

$$v\frac{\Delta s}{\Delta t} \ge v \text{ OR } \frac{\Delta s}{\Delta t} \ge \left| v \pm \frac{1}{\sqrt{\rho \left(\frac{1}{K} + \frac{D}{Ex}\right)}}\right|\_{\text{max}}\tag{26}$$

In order to solve this model, the basic equation needs to be discretized and the differential equation needs to be transformed into a differential algebraic equation. Here, the diffusion difference scheme is used to solve the equation. Figure 3 shows the *L-t* plane of characteristic grid of the four variable water hammer model. Use *X* to represent the objective function head *H*, velocity *V* and density *ρ* and area *A*. Then the partial differential of *X* to time and position can be expressed as:

$$\frac{\partial X}{\partial t} = \frac{X\_i^k - \left[ \xi X\_i^{k-1} + \frac{1 - \xi}{2} \left( X\_{i+1}^{k-1} + X\_{i-1}^{k-1} \right) \right]}{\Delta t} \tag{27}$$

**Figure 3.** *L-t* plane of characteristic grid.

*ρk i* − &

$$\frac{\partial X}{\partial z} = \frac{X\_{i+1}^{k-1} - X\_{i-1}^{k-1}}{2\Delta z} \tag{28}$$

By introducing Equations (27) and (28) into the water hammer closure calculation model, the following difference equations can be obtained:

*vk i* − & *ξvk*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*vk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*vk*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *i vk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*vk*−<sup>1</sup> *i*−1 2Δ*z* <sup>+</sup>*<sup>g</sup> <sup>H</sup>k*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*Hk*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* <sup>+</sup> *<sup>H</sup>k*−<sup>1</sup> *<sup>i</sup> g ρk*−<sup>1</sup> *i ρk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*ρk*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* <sup>+</sup> *f vk*−<sup>1</sup> *<sup>i</sup>* |*vk*−<sup>1</sup> *<sup>i</sup>* <sup>|</sup> <sup>2</sup>*<sup>D</sup>* <sup>=</sup> <sup>0</sup> (29) *Hk i* − & *ξHk*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*Hk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*Hk*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *i Hk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*Hk*−<sup>1</sup> *i*−1 2Δ*z* +*vk*−<sup>1</sup> *<sup>i</sup>* sin *<sup>θ</sup>* <sup>+</sup> <sup>1</sup> *<sup>ρ</sup><sup>g</sup>* <sup>−</sup> (*H*−*z*) *K* 2 *Ee* <sup>1</sup> *<sup>A</sup> <sup>π</sup>* <sup>+</sup> <sup>1</sup> *K vk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*vk*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* = 0 (30) *ξρk*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*ρk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*ρk*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *ρk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*ρk*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* <sup>−</sup> *<sup>ρ</sup>k*−<sup>1</sup> *<sup>i</sup> <sup>K</sup>* ·

$$\begin{aligned} \frac{\Delta t}{\Delta t} + \upsilon\_i - \frac{\Delta \chi}{2\Delta z} & \quad \frac{\frac{K}{\rho\_i^{k-1}} - \left(H\_i^{k-1} - z\_i\right)}{\rho\_i^{k-1} - \left(H\_i^{k-1} - z\_i\right)} \\ \left\{ \frac{H\_i^k - \left[\xi H\_i^{k-1} + \frac{1-\xi}{2} \left(H\_{i+1}^{k-1} + H\_{i-1}^{k-1}\right)\right]}{\Delta t} + \upsilon\_i^{k-1} \left(\frac{H\_{i+1}^{k-1} - H\_{i-1}^{k-1}}{2\Delta z} + \sin \theta\right) \right\} &= 0 \end{aligned} \tag{31}$$

$$\begin{cases} \frac{A\_i^k - \left[\xi A\_i^{k-1} + \frac{1-\xi}{2} \left(A\_{i+1}^{k-1} + A\_{i-1}^{k-1}\right)\right]}{\Delta t} + v\_i^{k-1} \frac{A\_{i+1}^{k-1} - A\_{i-1}^{k-1}}{2\Delta z} - \frac{2KA\_i^{k-1}}{\rho\_i^{k-1}Ec} \sqrt{\frac{A\_i^{k-1}}{\pi}}. \\\\ \left\{ \frac{\rho\_i^k - \left[\xi \rho\_i^{k-1} + \frac{1-\xi}{2} \left(\rho\_{i+1}^{k-1} + \rho\_{i-1}^{k-1}\right)\right]}{\Delta t} + v\_i^{k-1} \frac{\rho\_{i+1}^{k-1} - \rho\_{i-1}^{k-1}}{2\Delta z} \right\} = 0 \end{cases} \tag{32}$$

Make the following assumptions:

$$\begin{cases} X\_{H1} = \mathbb{f}\_{i}^{H\_{i}^{k-1}} + \frac{1-\mathbb{\zeta}}{2} \left( H\_{i+1}^{k-1} + H\_{i-1}^{k-1} \right), & X\_{H2} = \left( H\_{i+1}^{k-1} - H\_{i-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \\\\ X\_{v1} = \mathbb{f}\_{i}^{v} \mathbb{z}\_{i}^{k-1} + \frac{1-\mathbb{\zeta}}{2} \left( \mathbb{v}\_{i+1}^{k-1} + \mathbb{v}\_{i-1}^{k-1} \right), & X\_{v2} = \left( \mathbb{v}\_{i+1}^{k-1} - \mathbb{v}\_{i-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \\\\ X\_{\rho1} = \mathbb{z}\_{\rho}^{\prime} \mathbb{z}\_{i}^{k-1} + \frac{1-\mathbb{\zeta}}{2} \left( \mathbb{\rho}\_{i+1}^{k-1} + \mathbb{\rho}\_{i-1}^{k-1} \right), & X\_{\rho2} = \left( \mathbb{\rho}\_{i+1}^{k-1} - \mathbb{\rho}\_{i-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \\\\ X\_{A1} = \mathbb{z}\_{i}^{\prime} A\_{i}^{k-1} + \frac{1-\mathbb{\zeta}}{2} \left( A\_{i+1}^{k-1} + A\_{i-1}^{k-1} \right), & X\_{A2} = \left( A\_{i+1}^{k-1} - A\_{i-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \end{cases} \tag{33}$$

After sorting, the expressions of the four unknowns are as follows:

$$\begin{cases} H\_{i}^{k} = X\_{H1} - v\_{i}^{k-1} \left(\frac{X\_{H2}}{2} + \Delta t \sin \theta \right) - X\_{\theta 2} \left[ \frac{1}{\frac{\rho\_{i}^{k} - 1}{\pi} - \frac{\beta \Delta t}{\pi}} \frac{\left( \frac{h\_{i}^{k-1} - z\_{i}}{\pi} \right)}{\pi} \right] \\\\ \upsilon\_{i}^{k} = X\_{\upsilon 1} - \frac{v\_{i}^{k-1}}{2} X\_{\upsilon 2} - \frac{\beta}{2} X\_{H2} - \frac{\left( \frac{H\_{i}^{k-1} - z\_{i}}{\pi} \right) \mathbb{S}}{2 \rho\_{i}^{k-1}} X\_{\rho 2} - \frac{f \Delta t}{2D} \upsilon\_{i}^{k-1} \left| \upsilon\_{i}^{k-1} \right| = 0 \\\\ \rho\_{i}^{k} = X\_{\rho 1} - \frac{v\_{i}^{k-1}}{2} X\_{\rho 2} + \frac{\rho\_{i}^{k-1}}{\left[ \frac{K}{\rho\_{i}^{k-1} - \xi} \left( \mu\_{i}^{k-1} - z\_{i} \right) \right]} \left[ H\_{i}^{k} - X\_{H1} + \upsilon\_{i}^{k-1} \left( \frac{X\_{H2}}{2} + \Delta t \sin \theta \right) \right] \\\\ A\_{i}^{k} = X\_{A1} - \frac{v\_{i}^{k-1}}{2} X\_{A2} + \frac{2A\_{i}^{k-1} \chi}{\rho\_{i}^{k-1} \pi e} \sqrt{\frac{A\_{i}^{k}}{\pi}} \left( \rho\_{i}^{k} - X\_{\rho 1} + \frac{v\_{i}^{k-1}}{2} X\_{\rho 2} \right) \end{cases} \tag{34}$$

The fluid in the oil pipeline is not all liquid in the field. What happens when there is a small amount of gas in the oil pipeline? Assuming that there are only gas-liquid two phases in the pipe, the density of the gas-liquid mixture is [31]:

$$
\rho\_{\rm m} = \rho\_{\rm g} \mathbb{C}\_{\rm g} + \rho\_{\rm l} \left( 1 - \mathbb{C}\_{\rm g} \right) \tag{35}
$$

where, *C*g is the gas content.

Since the density in this paper is considered a variable, according to the difference principle, we can get:

$$
\rho\_{\mathbf{m}\_l^k} = \rho\_{\mathfrak{E}\_l^k} \mathbf{C}\_{\mathfrak{E}\_l^k} + \rho\_l^k \left(1 - \mathbf{C}\_{\mathfrak{E}\_l^k}^k\right) \tag{36}
$$

$$
\rho\_{\mathbb{M}\_i^k}{}^{k-1} = \rho\_{\mathbb{g}\_i^k}{}^{k-1} \mathbb{C}\_{\mathbb{g}\_i^k}{}^{k-1} + \rho\_{\mathbb{I}\_i^k}{}^{k-1} \left(1 - \mathbb{C}\_{\mathbb{g}\_i^k}{}^{k-1}\right) \tag{37}
$$

$$
\rho\_{\mathbf{m}\_{i}i+1} = \rho\_{\mathbf{g}i+1} \mathbf{C}\_{\mathbf{g}i+1}^{k-1} + \rho\_{li+1}^{k-1} \left( 1 - \mathbf{C}\_{\mathbf{g}i+1}^{k-1} \right) \tag{38}
$$

$$
\rho\_{\mathbf{m}\_{i-1}^{k-1}} = \rho\_{\mathbf{g}\_{i}^{k}-1} \mathbf{C}\_{\mathbf{g}\_{i}^{k}-1} + \rho\_{l\_{i}-1}^{k-1} \left(1 - \mathbf{C}\_{\mathbf{g}\_{i}^{k}-1}^{k-1}\right) \tag{39}
$$

Accordingly, the flow rate also becomes the mixing flow rate, and its expression is:

$$v\_{\rm m} = \frac{Q\_{\rm f} + Q\_{\rm l}}{A} \tag{40}$$

Then according to the difference principle, we can get:

$$v\_{\mathbf{m}\_i^k} = \frac{Q\_{\mathcal{S}\_i^k} + Q\_{\mathbf{l}\_i^k}}{A\_i^k} \tag{41}$$

$$w\_{\mathbf{m}\_i^k}{}^{k-1} = \frac{Q\_{\mathbf{g}\_i^k}{}^{k-1} + Q\_i^{k-1}}{A\_i^{k-1}} \tag{42}$$

$$v\_{\mathbf{m}\_{i+1}} = \frac{Q\_{\mathbf{g}\_{i+1}} - Q\_{i+1}}{A\_{i+1}^{k-1}} \tag{43}$$

$$v\_{\mathbf{m}\_{i-1}^{k-1}} = \frac{Q\_{\mathfrak{K}\_{i-1}^{k-1}} + Q\_{i-1}^{k-1}}{A\_{i-1}^{k-1}} \tag{44}$$

Thus, formulas (29)–(32) are deformed as:

$$\begin{split} \frac{v\_{\mathbf{m}\_{i}^{k}} - \left[ \zeta v\_{\mathbf{m}\_{i}^{k-1}} + \frac{1 - \overline{\zeta}}{2} \left( v\_{\mathbf{m}\_{i}^{k-1}} + v\_{\mathbf{m}\_{i}^{k-1}} \right) \right]}{\Delta t} + \upsilon\_{\mathbf{m}\_{i}^{k}} \frac{v\_{\mathbf{m}\_{i}^{k-1}} - \upsilon\_{\mathbf{m}\_{i}^{k-1}}}{2 \Delta z} \\ + g \frac{H\_{i+1}^{k-1} - H\_{i-1}^{k-1}}{2 \Delta z} + \frac{H\_{i}^{k-1} \overline{\zeta}}{\rho\_{\mathbf{m}\_{i}^{k-1}}} \frac{\rho\_{\mathbf{m}\_{i+1}^{k-1}} - \rho\_{\mathbf{m}\_{i}^{k-1}}}{2 \Delta z} + \frac{f v\_{\mathbf{m}\_{i}^{k-1}} \left| v\_{\mathbf{m}\_{i}^{k-1}} \right|}{2D} = 0 \end{split} \tag{45}$$

$$\begin{split} \frac{H\_i^k - \left[ \,^t H\_i^{k-1} + \frac{1-\tilde{\ell}}{2} \left( H\_{i+1}^{k-1} + H\_{i-1}^{k-1} \right) \right]}{\Delta t} + \upsilon\_{\text{m}\_i^{k-1}} \frac{H\_{i+1}^{k-1} - H\_{i-1}^{k-1}}{2\Delta z} \\ + \upsilon\_{\text{m}\_i^{k-1}} \sin \theta + \frac{\frac{1}{\rho\_{\text{m}\_i^{k-1}} - \frac{1}{\rho\_i}} \frac{\left( H\_i^{k-1} - z \right)}{\kappa} \frac{\upsilon\_{\text{m}\_{i+1}^{k-1}} - \upsilon\_{\text{m}\_{i-1}^{k-1}}}{2\Delta z} = 0 \end{split} \tag{46}$$

*ρ*m*<sup>k</sup> i* − & *ξρ*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*ρ*m*k*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*ρ*m*k*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *i ρ*m*k*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*ρ*m*k*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* <sup>−</sup> *<sup>ρ</sup>*m*k*−<sup>1</sup> *<sup>i</sup> <sup>K</sup> <sup>ρ</sup>k*−<sup>1</sup> *<sup>i</sup> <sup>g</sup>* <sup>−</sup>(*Hk*−<sup>1</sup> *<sup>i</sup>* <sup>−</sup>*zi*) · ( *<sup>H</sup><sup>k</sup> i* − & *ξHk*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*Hk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*Hk*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *i Hk*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*Hk*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* + sin *θ* ) = 0 (47) *Ak i* − & *ξAk*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*Ak*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*Ak*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *i Ak*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*Ak*−<sup>1</sup> *i*−1 <sup>2</sup>Δ*<sup>z</sup>* <sup>−</sup> <sup>2</sup>*KAk*−<sup>1</sup> *i ρk*−<sup>1</sup> *<sup>i</sup> Ee* 1 *Ak*−<sup>1</sup> *i π* · ( *<sup>ρ</sup>*m*<sup>k</sup> i* − & *ξρ*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>+</sup> <sup>1</sup>−*<sup>ξ</sup>* <sup>2</sup> (*ρ*m*k*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>+</sup>*ρ*m*k*−<sup>1</sup> *<sup>i</sup>*−<sup>1</sup> ) ' <sup>Δ</sup>*<sup>t</sup>* <sup>+</sup> *<sup>v</sup>k*−<sup>1</sup> *ρ*m*k*−<sup>1</sup> *<sup>i</sup>*+<sup>1</sup> <sup>−</sup>*ρ*m*k*−<sup>1</sup> *i*−1 ) = 0 (48)

*i*

2Δ*z*

The corresponding assumptions will also be changed accordingly:

$$\begin{cases} X\_{v1}^{\rm m} = \zeta v\_{\rm m}{}^{k-1} + \frac{1-\overline{\zeta}}{2} \left( v\_{\rm m}{}^{k-1} + v\_{\rm m}{}^{k-1} \right), \quad X\_{v2}^{\rm m} = \left( v\_{\rm m}{}^{k-1} - v\_{\rm m}{}^{k-1} \right) \frac{\Delta t}{\Delta z} \\\ X\_{\rho1}^{\rm m} = \overline{\zeta}\rho\_{\rm m}{}^{k-1} + \frac{1-\overline{\zeta}}{2} \left( \rho\_{\rm m}{}^{k-1} + \rho\_{\rm m}{}^{k-1} \right), \quad X\_{\rho2}^{\rm m} = \left( \rho\_{\rm m}{}^{k-1} - \rho\_{\rm m}{}^{k-1} \right) \frac{\Delta t}{\Delta z} \end{cases} \tag{49}$$

After sorting, the expressions of four unknowns considering gas-liquid two-phase are obtained as follows:

⎧ ⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨ ⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎩ *Hk <sup>i</sup>* <sup>=</sup> *XH*<sup>1</sup> <sup>−</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *i XH*<sup>2</sup> <sup>2</sup> + Δ*t* sin *θ* − *<sup>X</sup>*<sup>m</sup> *v*2 ⎡ ⎢ ⎣ 1 *<sup>ρ</sup>*m*k*−<sup>1</sup> *<sup>i</sup> <sup>g</sup>* <sup>−</sup> (*Hk*−<sup>1</sup> *<sup>i</sup>* <sup>−</sup>*zi*) *<sup>K</sup>* 4 *Ee* 0 *<sup>A</sup>k*−<sup>1</sup> *<sup>i</sup> <sup>π</sup>* <sup>+</sup> <sup>1</sup> *K* ⎤ ⎥ ⎦ *v*m*<sup>k</sup> <sup>i</sup>* = *<sup>X</sup>*<sup>m</sup> *<sup>v</sup>*<sup>1</sup> <sup>−</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>2</sup> *<sup>X</sup>*<sup>m</sup> *<sup>v</sup>*<sup>2</sup> <sup>−</sup> *<sup>g</sup>* <sup>2</sup> *XH*<sup>2</sup> − *<sup>H</sup>k*−<sup>1</sup> *<sup>i</sup>* <sup>−</sup>*zi g* <sup>2</sup>*ρ*m*k*−<sup>1</sup> *<sup>i</sup> X*<sup>m</sup> *<sup>ρ</sup>*<sup>2</sup> <sup>−</sup> *<sup>f</sup>*Δ*<sup>t</sup>* <sup>2</sup>*<sup>D</sup> <sup>v</sup>*m*k*−<sup>1</sup> *i v*m*k*−<sup>1</sup> *i* <sup>=</sup> <sup>0</sup> *ρ*m*<sup>k</sup> <sup>i</sup>* = *<sup>X</sup>*<sup>m</sup> *<sup>ρ</sup>*<sup>1</sup> <sup>−</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>2</sup> *<sup>X</sup>*<sup>m</sup> *<sup>ρ</sup>*<sup>2</sup> <sup>+</sup> *<sup>ρ</sup>*m*k*−<sup>1</sup> <sup>4</sup> *<sup>i</sup> K <sup>ρ</sup>*m*k*−<sup>1</sup> *<sup>i</sup> <sup>g</sup>* − *<sup>H</sup>k*−<sup>1</sup> *<sup>i</sup>* <sup>−</sup>*zi* 5 & *Hk <sup>i</sup>* <sup>−</sup> *XH*<sup>1</sup> <sup>+</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *i XH*<sup>2</sup> <sup>2</sup> + Δ*t* sin *θ* ' *Ak <sup>i</sup>* <sup>=</sup> *XA*<sup>1</sup> <sup>−</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>2</sup> *XA*<sup>2</sup> <sup>+</sup> <sup>2</sup>*Ak*−<sup>1</sup> *<sup>i</sup> <sup>K</sup> <sup>ρ</sup>*m*k*−<sup>1</sup> *<sup>i</sup> Ee* <sup>0</sup> *<sup>A</sup>k*−<sup>1</sup> *<sup>i</sup> π ρ*m*<sup>k</sup> <sup>i</sup>* − *<sup>X</sup>*<sup>m</sup> *<sup>ρ</sup>*<sup>1</sup> <sup>+</sup> *<sup>v</sup>*m*k*−<sup>1</sup> *<sup>i</sup>* <sup>2</sup> *<sup>X</sup>*<sup>m</sup> *ρ*2 (50)

### *3.2. Boundary Conditions*

The boundary point is different from the inner node. It has an equation with boundary conditions, and the number of equations is more than the number of unknowns. For the previous solutions, one is to synthesize the continuity equation and motion equation into a partial differential equation and then transform it into a difference equation. The second is not to establish the continuity equation and the motion equation, but to introduce the characteristic equation. For example, the inverse characteristic line equation can be introduced for the upstream and the along characteristic line equation can be introduced for the downstream [32,33]. For the equation form of four variables in this paper, neither method is applicable. The solution obtained by method one does not converge and cannot meet the stability condition. However, if the continuity Equation (24) is abandoned, the ideal results can be obtained by using the equation of motion (19) and Equations (20) and (21) together with the upstream boundary conditions. The downstream boundary of a simple pipeline can be treated by method one, and the results are stable and convergent.

The equations of motion (19)–(21) are used to solve the upstream boundary conditions. When the upstream is a reservoir, the reservoir water level can be regarded as constant, and the boundary condition is a constant, that is *<sup>∂</sup><sup>H</sup> <sup>∂</sup><sup>t</sup>* = 0, from the motion equation:

$$v\_0^k = v\_0^{k-1} \left( 1 - X'\_{v2} \right) - \mathcal{g} \left[ X'\_{H2} + \frac{\left( H\_0^{k-1} - z\_0 \right)}{\rho\_0^{k-1}} X'\_{\rho 2} - \frac{f \Delta t}{2 \text{g} D} v\_0^{k-1} \left| v\_0^{k-1} \right| \right] \tag{51}$$

$$\rho\_0^k = \rho\_0^{k-1} - v\_0^{k-1} X\_{\rho 2}' + \frac{\rho\_0^{k-1}}{\frac{K}{\rho\_0^{k-1} \mathcal{J}} - \left(H\_0^{k-1} - z\_0\right)} v\_0^{k-1} \left(X\_{A2}' + \Delta t \sin \theta\right) \tag{52}$$

Combine formulas (20) and (21) and substitute the calculated value to obtain:

$$A\_0^k = A\_0^{k-1} - v\_0^{k-1} X'\_{A2} + \frac{2A\_0^{k-1} K}{\rho\_0^{k-1} E \varepsilon} \sqrt{\frac{A\_0^{k-1}}{\pi}} \left(\rho\_0^k - \rho\_0^{k-1} + v\_0^{k-1} X'\_{\rho2}\right) \tag{53}$$

where in:

$$\begin{cases} X\_{\,\,\,H2}' = \left(H\_1^{k-1} - H\_0^{k-1}\right) \frac{\Delta t}{\Delta z} & X\_{\,\,v2}' = \left(v\_1^{k-1} - v\_0^{k-1}\right) \frac{\Delta t}{\Delta z} \\ X\_{\,\,\,p2}' = \left(\rho\_1^{k-1} - \rho\_0^{k-1}\right) \frac{\Delta t}{\Delta z} & X\_{\,\,A2}' = \left(A\_1^{k-1} - A\_0^{k-1}\right) \frac{\Delta t}{\Delta z} \end{cases} \tag{54}$$

Here, the equation of motion (19) and the continuity Equation (24) are integrated into a partial differential equation and then transformed into a difference equation. The specific form is:

$$\frac{\partial H}{\partial t} + (v + v\_0) \frac{\partial H}{\partial s} + \frac{v\_0}{g} \frac{\partial v}{\partial t} + \begin{bmatrix} \frac{1}{\rho g} - \frac{(H - z)}{K} \\ \frac{2}{2\pi} \sqrt{\frac{A}{\pi}} + \frac{1}{K} \end{bmatrix} \frac{\partial v}{\partial s} + \frac{(H - z)v\_0}{\rho} \frac{\partial \rho}{\partial s} + v \sin \theta + v\_0 \frac{fv|v|}{2gD} = 0 \tag{55}$$

When the downstream end of the pipeline is a valve, it can be regarded as an orifice to obtain [34]:

$$
\upsilon\_t^A = \upsilon\_\mathrm{m} \tau\_\mathrm{k} \sqrt{\frac{H\_t^A}{H\_0}} \tag{56}
$$

where *H*<sup>0</sup> is the initial head pressure of the downstream section. For downstream *N* section, rewrite it as:

$$
\upsilon\_N^k = \upsilon\_\mathrm{m} \tau\_k \sqrt{\frac{H\_N^k}{H\_N^0}} \tag{57}
$$

Solve the above equation with Equations (20), (21) and (39):

$$w\_N^k = -\Upsilon\_1 \Upsilon\_2 + \sqrt{(\Upsilon\_1 \Upsilon\_2)^2 - 2\Upsilon\_2 \Upsilon\_3} \tag{58}$$

When the flow rate is obtained, the following formula (37) can be obtained:

$$H\_N^k = -\Upsilon\_1 \upsilon\_N^k - \Upsilon\_3 \tag{59}$$

Substitute into Equations (20) and (21) to obtain:

$$\rho\_N^k = \rho\_N^{k-1} - \upsilon\_N^{k-1} X'' \, \_{\rho 2} + \frac{\rho\_N^{k-1}}{\frac{K}{\rho\_N^{k-1} \mathcal{S}} - \left(H\_N^{k-1} - z\_0\right)} \left[H\_N^k - H\_N^{k-1} + \upsilon\_N^{k-1} (X'' \, \_{A2} + \Lambda t \sin \theta)\right] \tag{60}$$

$$A\_N^k = A\_N^{k-1} - \upsilon\_N^{k-1} X'' \, \_{A2} + \frac{2A\_N^{k-1} K}{\rho\_N^{k-1} E e} \sqrt{\frac{A\_N^{k-1}}{\pi}} \left(\rho\_N^k - \rho\_N^{k-1} + \upsilon\_N^{k-1} X'' \, \_{\rho 2} \right) \tag{61}$$

where *v*<sup>m</sup> is the initial flow velocity at the downstream section of the pipeline and *τ<sup>k</sup>* is the opening of the downstream valve.

$$Y\_1 = \frac{v\_0}{\mathcal{g}}\tag{62}$$

$$Y\_2 = \frac{\left(v\_{\rm m}\eta\_{\rm k}\right)^2}{2H\_N^0} \tag{63}$$

$$\begin{cases} Y\_3 = & -H\_N^{k-1} + \left( v\_N^{k-1} + v\_0 \right) X^\nu \, \_{H2} - v\_0 \left[ \frac{v\_N^{k-1}}{\mathcal{S}} - \frac{\left( \operatorname{div}\_N^{k-1} - z\_0 \right)}{\rho v\_N^{k-1}} X^\nu \, \_{\rho 2} - \frac{f \Delta t}{\mathcal{S}^{k-1}} v\_N^{k-1} \left| \boldsymbol{v}\_N^{k-1} \right| \right] \\ & + \begin{bmatrix} \frac{1}{\rho\_N^{k-1}} - \frac{\left( \operatorname{tr}\_N^{k-1} - z\_0 \right)}{\mathcal{S}} + \frac{\tau\_0 v\_N^{k-1}}{\mathcal{S}} \\ \frac{\tau\_0 \sqrt{\frac{\lambda\_N^{k-1}}{\mathcal{T}}} + \frac{1}{\tau}} \end{bmatrix} X^\nu \, \_{\upsilon 2} + \tau\_N^{k-1} \cdot \Delta t \sin \theta \\\\ \boldsymbol{X}^\nu \, \_{\upsilon \nu} = \begin{pmatrix} H\_{N-1}^{k-1} - H\_{N-1}^{k-1} \end{pmatrix} \frac{\Delta t}{\Delta t} \qquad \boldsymbol{X}^\nu \, \_{\upsilon 2} - \left( \boldsymbol{f}\_{N-1}^{k-1} - \boldsymbol{r}\_{N-1}^{k-1} \right) \frac{\Delta t}{\Delta t} \end{cases} \tag{64}$$

$$\begin{cases} X^{\nu} \, \_{H2} = \left( H\_N^{k-1} - H\_{N-1}^{k-1} \right) \frac{\Delta t}{\Delta z} & X^{\nu} \, \_{v2} = \left( \upsilon\_N^{k-1} - \upsilon\_{N-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \\ X^{\nu} \, \_{\rho2} = \left( \rho\_N^{k-1} - \rho\_{N-1}^{k-1} \right) \frac{\Delta t}{\Delta z} & X^{\nu} \, \_{A2} = \left( A\_N^{k-1} - A\_{N-1}^{k-1} \right) \frac{\Delta t}{\Delta z} \end{cases} \tag{65}$$

The above is the treatment of the boundary problem of a simple pipeline. Figure 4 shows the calculation flowchart.

**Figure 4.** Flowchart of calculation of water hammer four variable closed model.

#### *3.3. Model Validation*

To verify the accuracy of the water hammer model, a water hammer calculation was carried out on a case of a fluid pipeline in the literature, and the calculation results were compared with those in the literature [35].

As shown in Figure 5, the calculation results of water hammer are compared. The red is the calculation result of the literature, and the blue is the calculation result of the article model. It can be seen from the figure that there are certain deviations in the results, which may be caused by different mathematical models since the model in this paper considers the four variables of pressure, flow rate, density and flow area.

**Figure 5.** Comparison between calculation results of the present model and literature results.

#### **4. Field Application and Result Discussion**

*4.1. Sample Pipeline Foundation Parameters*

Taking an oil pipeline X as an example, this paper simulates the pressure fluctuation in the pipeline after the valve at the end is closed and the effects of different factors such as valve closing time, flow and gas content on water hammer pressure. The buried depth of the pipeline is 1.8 m, the pipe diameter is 300 mm, and the wall thickness is 6 mm. The physical parameters of oil, soil, anticorrosion coating and pipeline are shown in Table 1. The atmospheric temperature is 20 ◦C, the soil temperature is 5 ◦C, and the oil temperature is 22 ◦C.

**Table 1.** Physical parameters of oil, soil, anticorrosion coating and pipe.


#### *4.2. Result and Discussion*

Assuming that the valve closing time is about 5 s, the valve closing index m is 1.0 (linear valve closing), and the calculation time is 200 s. Figure 6 is the change of pressure at the pipe end after valve closing. It can be seen from the figure that at the moment of valve closing, the fluid flow rate at the pipe end suddenly changes to 0, the pressure increases rapidly, reaches the peak value of 4.95 MPa at 5.08 s, then starts to decline, reaching the valley value of 3.37 MPa at 12.80 s. Due to friction along the way, the fluctuating pressure will decay quickly and finally reach the equilibrium pressure.

**Figure 6.** Pressure fluctuation at the end of the pipeline.

Take the section close to the pipe end as the research plane and calculate the fluctuation of velocity in this plane as shown in Figure 7. Before closing the valve, the initial flow velocity of the section is 2.85 m/s. When the valve is closed, the flow rate drops rapidly and fluctuates around 0. According to the principle of the Bernoulli equation, the fluctuation will become weaker and weaker over time. Finally, the fluid pressure in the pipe will be a certain value and the flow rate will be 0.

**Figure 7.** Difference of natural frequency of tubing under two model analysis methods.

The effects of different valve closing time on the fluctuation of pressure and velocity at the pipe end are studied by the model. As shown in Figure 8a, the simulation results of fluctuating pressure at the pipe end under five different valve closing times are shown. According to the calculation, with the gradual increase of valve closing time, the maximum fluctuating pressure at the pipe end decreases, and the time of peak value lags behind. Figure 8b shows the simulation results of fluctuation velocity near the pipe end under five different valve closing times. The shorter the valve closing time, the earlier the flow rate drops to 0 and fluctuates around 0, and the greater the fluctuation range.

**Figure 8.** Influence of valve closing time on pressure and velocity fluctuation at the end of a pipeline: (**a**) represents pressure response; (**b**) represents velocity response.

Figure 9 shows the influence of different flow rates on pipe end pressure. It can be seen from Figure 9a that the pressure at the pipe end first decreases and then increases at the moment of valve closing. When the flow in the pipe is 0.4 kg/s, the decline amplitude is the largest, but the rise speed is also the fastest and the peak value is the highest. Similarly, when the flow rate is 0.4 kg/s, the decline rate of pipe end pressure from peak to valley is the fastest and the valley is the smallest. That is, the greater the flow, the greater the

change of pipe end pressure, the faster the speed change, and the more obvious the water hammer effect.

**Figure 9.** Influence of flow rate on pressure and velocity fluctuation at the end of a pipeline: (**a**) represents pressure response; (**b**) represents velocity response.

As Figure 9b shows, the greater the flow rate, the greater the initial flow velocity in the pipe and the fastest the decline rate of flow velocity. According to the enlarged view shown in Figure 9b, when the flow rate is large (e.g., flow rate is 0.4 kg/s), flow rate fluctuation is more intense. Moreover, there will be small fluctuations at inflection points such as falling from peak value and rising from valley value. The larger the flow, the more obvious the small fluctuations. It shows that the flow with large flow is greatly disturbed by instantaneous obstacles such as valve closing. However, with the increase of time, the impact of flow will be less and less obvious, whether it is pressure or flow rate.

After the fluctuating pressure is generated at the pipe end, it will propagate upstream along the pipeline to form a pressurization wave surface. To intuitively obtain the propagation of pressure wave in all calculation time, the three-dimensional diagram of pressure-wave propagation with pipe length and time after valve closing is drawn (Figure 10).

**Figure 10.** Three-dimensional diagram of pressure-wave propagation with pipe length and time after valve closing: (**a**) represents pressure response; (**b**) represents velocity response.

The effects of different pipe length and time on the fluctuating pressure in the pipe are studied, as shown in Figure 11. Figure 11a shows the pressure change chart in a 500 m section at 40 s. Pressure changes with pipe length when the blue line is 40 s. The red line shows the change of pressure with time at 500 m. By analogy, Figure 11b–d are the pressure change charts of a 1000 m section at 80 s, 1500 m section at 120 s and 2000 m section at 160 s after valve closing. The meaning of the blue line and the red line is the same as that in Figure 11a. It can be seen from the figure that the pressure fluctuation will gradually attenuate along the pipe length with the increase of time. The place with the greatest water hammer effect is near the valve. Under the coupling effect of time and tube length, the shorter the time and the shorter the tube length, the more obvious the pressure fluctuation; the longer the time and the longer the tube, the weaker the pressure fluctuation.

**Figure 11.** Effect of different pipe length and time on fluctuating pressure in pipe: (**a**) represents the pressure change chart in a 500 m section at 40 s; (**b**) represents the pressure change chart in a 1000 m section at 80 s; (**c**) represents the pressure change chart in a 1500 m section at 120 s; (**d**) represents the pressure change chart in a 2000 m section at 160 s.

Through the water hammer model established in this paper, the changes of pipe end pressure and flow velocity under five conditions with gas content of 1%, 3%, 5%, 7% and 9% were calculated, respectively (Figure 12). Figure 12a shows that the greater the gas content, the smaller the fluctuation peak of pipe end pressure. The time of the first peak of pressure wave is basically the same, but the time of the first valley value begins to be different. The greater the gas content, the later the minimum pressure appears. With the increase of time, this difference becomes more and more obvious, which is reflected in a longer water hammer cycle. Since the water hammer period is the ratio of pipe length to pressure-wave velocity, the greater the void fraction, the smaller the pressure-wave velocity. Slightly different is that there is a difference in the time when the first fluctuation value of velocity wave appears. The greater the void fraction, the longer the time lag of flow rate fluctuation, as shown in Figure 12b. According to Bernoulli's theory, pressure and velocity should be in a trade-off relationship and as the former increases, the latter decreases. Therefore, when the gas content is large, although the velocity fluctuation lags, the absolute value of velocity is large.

**Figure 12.** Influence of gas content on pressure and velocity fluctuation at the end of a pipeline: (**a**) represents pressure response; (**b**) represents velocity response.

When there is free gas in the oil pipe, the gas will form uneven bubbles in the pipe. When the bubble is free in the oil, it can be approximately regarded as an elastic deformable body. When there is pressure fluctuation in the oil, the bubbles will be forced to compress and increase their internal energy. At this time, the bubbles are not stable, and work will be done to the surrounding oil to release energy, so that the momentum of the oil increases and compresses the surrounding bubbles. Due to energy dissipation, the increase of oil momentum is not equal to the increase of internal energy after bubble forcing, and the energy of bubble forcing comes from pressure fluctuation. Therefore, the actual pressure fluctuation value is obviously lower than that without gas, and the size of the pressure wave mainly depends on the gas content [36–38].

#### **5. Conclusions**

Based on the essence of water hammer, the interaction between pipeline fluid motion and water hammer wave propagation is considered, and the pressure, velocity, density and overflow area are set as variables. A new set of water hammer calculation equations is deduced and solved numerically. The effects of different valve closing time, flow rate and gas content on pressure distribution and water hammer effect were studied. The following conclusions can be drawn:

With the increase of valve closing time, the maximum fluctuating pressure at the pipe end decreases, and the time of peak value also lags behind. The shorter the valve closing time, the earlier the flow rate drops to zero and fluctuates around zero, and the greater the fluctuation range. When the valve closing time increases from 5 s to 25 s, the difference of water hammer pressure is 0.72 MPa and the difference of velocity fluctuation amplitude is 0.076 m/s.

With greater flow, the pressure change at the pipe end is greater. With faster speed changes, the water hammer effect becomes more obvious. With larger flow, flow velocity fluctuations increase, and there will be a small amplitude fluctuation. Our calculations show that the flow with large flow is greatly disturbed by instantaneous obstacles such as valve closing. However, with the increase of time, the impact of flow will be less and less obvious, whether it is pressure or flow rate.

With the increase of time, the pressure fluctuation will gradually attenuate along the pipe length. The place with the greatest water hammer effect is near the valve. Under the coupling effect of time and tube length, the shorter the time and the shorter the tube length, the more obvious the pressure fluctuation.

Our calculations show that the larger the gas content is, the smaller the fluctuation peak of pipe end pressure is, the longer the water hammer cycle is, and the smaller the pressure-wave velocity is. The actual pressure fluctuation value is obviously lower than that without gas, and the size of the pressure wave mainly depends on the gas content. When the gas content increases from 1% to 9%, the difference in water hammer pressure is 0.41 MPa. When the gas content is large, although the velocity fluctuation lags, the absolute value of velocity is large.

**Author Contributions:** Conceptualization, methodology, software, C.L.; investigation, J.J.; validation, formal analysis, writing—original draft preparation, writing—review and editing, J.D. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research received no external funding.

**Conflicts of Interest:** The authors declare no conflict of interest.

#### **Nomenclature**


### **References**

