Formation Mechanism of Trailing Oil in Product Oil Pipeline

Trailing oil is the tail section of contamination in oil pipelines. It is generated in batch transportation, for which one fluid, such as diesel oil follows another fluid, such as gasoline, and it has an effect on the quality of oil. This paper describes our analysis of the formation mechanism of trailing oil in pipelines and our study of the influence of dead-legs on the formation of trailing oil. We found that the oil replacement rate in a dead-leg is exponentially related to the flow speed, and the length of the dead-leg is exponentially related to the replacement time of the oil. To reduce the amount of mixed oil, the main flow speed should be kept at about 1.6 m/s, and the length of the dead-leg should be less than five times the diameter of the main pipe. In our work, the Reynolds time-averaged method is used to simulate turbulence. To obtain contamination-related experimental data, computational fluid dynamics (CFD) software is used to simulate different flow rates and bypass lengths. MATLAB software was used to perform multi-nonlinear regression for the oil substitution time, the length of the bypass, and the flow speed. We determined an equation for calculating the length of the trailing oil contamination produced by the dead-leg. A modified equation for calculating the length of the contamination was obtained by combining the existing equation for calculating the length of the contamination with new factors based on our work. The amounts of contamination predicted by the new equation is closer to the actual contamination amounts than predicted values from other methods suggested by previous scholars.


Introduction
When two different liquids, such as diesel oil and gasoline, are moved in sequence through the same pipeline, there is some mixing of the two in the process.A considerable amount of oil contamination is caused by the presence of the trailing oil, which is the second fluid to move through the pipeline, in the fluid that moved first through the pipeline, and the contamination by the trailing oil on the quality of the initial oil is often overlooked.Properly controlling and removing the trailing oil contamination can improve the quality of the refined oil and increase its economic value.There are two main reasons for the formation of trailing oil contamination.One is the effect of the laminar flow boundary layer, and the other is the outflow of the preceding batch that remains in the dead-legs.Mass transfer in the bottom layer of the laminar flow restricts the change in the velocity distribution caused by the viscosity difference between the old and new batches, which leads to contamination of both two batches [1,2].In the batch transportation of refined oil, the boundary layer formed by the preceding batch will be slowly mixed into the next batch to form trailing oil contamination.
There are many valve chambers and pump stations in pipelines for long-distance transportation of refined oil.When the oil products pass through these valve chambers, dead-legs are formed (Figure 1).When a new batch of oil flows through the dead-leg, which contains oil from the preceding batch, first due to gravity, the latter batch pushes the preceding batch out of the dead-leg.The two kinds of oil products will form a "lock exchange" flow [3] at the mouth of the dead-leg, which leads to contamination.Initially, convection is the main factor.When half of the preceding batch in the dead-leg is replaced, diffusion transfer gradually begins to play the main role.Under the effect of turbulent diffusion, the second batch gradually flows into the dead-leg, and the preceding batch is gradually replaced.The time of the turbulent diffusion stage is longer than the convection stage.The preceding batch flowing from the dead-leg will form trailing oil contamination in the main pipe run.
Processes 2018, 6, x FOR PEER REVIEW 2 of 20 first due to gravity, the latter batch pushes the preceding batch out of the dead-leg.The two kinds of oil products will form a "lock exchange" flow [3] at the mouth of the dead-leg, which leads to contamination.Initially, convection is the main factor.When half of the preceding batch in the deadleg is replaced, diffusion transfer gradually begins to play the main role.Under the effect of turbulent diffusion, the second batch gradually flows into the dead-leg, and the preceding batch is gradually replaced.The time of the turbulent diffusion stage is longer than the convection stage.The preceding batch flowing from the dead-leg will form trailing oil contamination in the main pipe run.In the 2982 km Keystone pipeline from Canada into the U.S. [4], there are 39 pumping stations in the NPS30/36 pipeline.Bypasses in pipelines lead to contamination.For example, the amount of contamination increased by 37.5% in the first pump station of the Keystone pipeline with its four bypasses, and an additional 18.3% contamination was added after passing through the second pump station.
Long distance sequential transmission of oil products produces a considerable amount of mixed oil, and the treatment of this contaminated oil is expensive and reduces the economic benefits of oil [5].Many scholars have studied the problem of contamination in batch transportation of refined oil from the perspective of both basic theory and experiment.Taylor et al. [6] found that when the contaminated oil slowly passes through a small-bore pipe, it will diffuse under the combined action of molecular diffusion and velocity change.Taylor et al. suggested that the change of velocity is very important in the axial diffusion of matter, and they proposed the Fick model to calculate the degree of axial diffusion.Aunicky [7] pointed out that there were certain defects in the Taylor study, and that the diffusion coefficient was not a constant value.Krantz et al. [8] modified the Taylor analysis method.They found that when the fluid approached the laminar flow area, the axial mixing increased rapidly, and the roughness would also lead to a small amount of axial contamination.Austin and Palfrey suggested that at a high Reynolds number, Taylorʹs analysis would have errors due to the influence of the trailing oil.Austin et al. [9] also found that the turbulence model in Taylorʹs analysis at a low Reynolds number ignored the deviation caused by the effect of viscosity near the wall.They proposed an equation with empirical constants for calculating the length of interfacial contamination.Scott et al. [10], through extensive experimental analysis, found that diffusion transfer is the main factor leading to oil mixing.Levenspiel [11] presented the idea that in a turbulent pipe, molecular diffusion does not cause any appreciable mixing.Deng [12] developed equations for a twodimensional finite difference method that predicted the ʺtail effectʺ observed earlier by Austin [9].Botros [13] proposed a non-mechanical separators model for predicting contamination in batch transportation.The governing equation of the model is a nonlinear boundary value problem, which is solved by coupling the finite element method with Newton method.Rachid et al. [14,15] proposed a new mixing calculation model.They found that the flow direction had no effect on the mixing volume with the same change in pipe diameter.The above research shows that the viscosity difference is the main factor that causes the tail of contamination, but these studies do not consider In the 2982 km Keystone pipeline from Canada into the U.S. [4], there are 39 pumping stations in the NPS30/36 pipeline.Bypasses in pipelines lead to contamination.For example, the amount of contamination increased by 37.5% in the first pump station of the Keystone pipeline with its four bypasses, and an additional 18.3% contamination was added after passing through the second pump station.
Long distance sequential transmission of oil products produces a considerable amount of mixed oil, and the treatment of this contaminated oil is expensive and reduces the economic benefits of oil [5].Many scholars have studied the problem of contamination in batch transportation of refined oil from the perspective of both basic theory and experiment.Taylor et al. [6] found that when the contaminated oil slowly passes through a small-bore pipe, it will diffuse under the combined action of molecular diffusion and velocity change.Taylor et al. suggested that the change of velocity is very important in the axial diffusion of matter, and they proposed the Fick model to calculate the degree of axial diffusion.Aunicky [7] pointed out that there were certain defects in the Taylor study, and that the diffusion coefficient was not a constant value.Krantz et al. [8] modified the Taylor analysis method.They found that when the fluid approached the laminar flow area, the axial mixing increased rapidly, and the roughness would also lead to a small amount of axial contamination.Austin and Palfrey suggested that at a high Reynolds number, Taylor's analysis would have errors due to the influence of the trailing oil.Austin et al. [9] also found that the turbulence model in Taylor's analysis at a low Reynolds number ignored the deviation caused by the effect of viscosity near the wall.They proposed an equation with empirical constants for calculating the length of interfacial contamination.Scott et al. [10], through extensive experimental analysis, found that diffusion transfer is the main factor leading to oil mixing.Levenspiel [11] presented the idea that in a turbulent pipe, molecular diffusion does not cause any appreciable mixing.Deng [12] developed equations for a two-dimensional finite difference method that predicted the "tail effect" observed earlier by Austin [9].Botros [13] proposed a non-mechanical separators model for predicting contamination in batch transportation.The governing equation of the model is a nonlinear boundary value problem, which is solved by coupling the finite element method with Newton method.Rachid et al. [14,15] proposed a new mixing calculation model.They found that the flow direction had no effect on the mixing volume with the same change in pipe diameter.The above research shows that the viscosity difference is the main factor that causes the tail of contamination, but these studies do not consider the special situations, such as dead-legs in a valve chamber, and are not closely integrated with practical engineering.
Patrachari et al. [16] and Botros et al. [17] studied the additional contamination problem in a main pipe run due to dead-legs.Their work shows that in a pump station with four pumps, the bypass line of each pump will form a dead-leg, and the four dead-legs will result in an additional 400 m to 420 m of contamination due to diffusion.They also found that the contamination formed by dead-legs was caused by the fluid stagnating in the bypass entering the main pipe that runs through the mouth of the dead-leg.There are two mechanisms for this.First, gravity causes the fluid stagnating in the dead-leg to flow out and contaminate the main flow, and then the turbulent mixing and diffusing effect of the slight infiltration into the dead-leg at the mouth of dead-leg leads to mixing.The first mechanism accounts for about half of the outflow volume.However, the second mechanism takes a longer time to discharge the same volume of fluid.Jamalabadi et al. [18] studied the effects of injection angle, density ratio, and viscosity on droplet formation in a microfluidic T-junction.The results show that contact angle, slip length, and injection angles near the perpendicular and parallel conditions have an increasing impact on the diameter of generated droplets, while flow rate, density ratios, viscosity ratios, and other injection angles had less effect on the diameter of the droplets.However, Patrachari et al. did not modify the traditional formula for calculating contamination content in the trailing oil caused by the dead-legs.
An extensive literature exsits on the mixing of different batches in pipelines.However, previous scholars have seldom studied the influence of dead-legs in pumping stations or valve chambers on the amount of oil mixing, especially mixing of trailing oil.This paper describes how we analyzed the mechanism for the formation of trailing oil in dead-legs, and the effect of trailing oil on the amount of contamination in oil.Through simulation analysis, we determined the best flow speed and the dead-leg length to reduce contamination during the delivery of refined oil.In this paper, we suggest a correction to obtain an equation for calculating the length of the contamination and the influence of the trailing oil.Using engineering data, the contamination predicted by the corrected equation is closer to the actual contamination than that predicted by other equation.

Method
First, we assume that the convection-diffusion process is the most basic factor for the formation of contamination [19,20].For the two-dimensional convection-diffusion mechanism, the axial diffusion of mixing is caused by uneven speed, and the radial diffusion of mixing due to concentration difference.The diffusion effects tend to make the concentrations more uniform.The theoretical formula [21] used to calculate the contamination length in the symmetric range of concentration is: where C is the contamination length (m), L is the length of pipeline (m), d is the pipe internal diameter (m), Re pj is the average Reynolds number of two kinds of oil, and α is the correction coefficient.The thicker the laminar flow is, the greater the contamination content will be.Z is an integrated variable corresponding to the cutting concentration of contaminants.In the symmetrical concentration range, the mixing length derived from the diffusion theory is related to the flow regime, the pipe diameter, and the length of the mixing interface.Next, we calculated the contamination length by using the Austin-Palfrey formula [9].Generally, the mixing length in the range of 99% to 1% of oil concentration is regarded as the contamination length.When the pipe diameter and pipe length are fixed, the Reynolds number has different effects on contamination length for two different conditions.The Reynolds number and the dimensionless quantity C 2 /Ld for both conditions are linear in the log-coordinate system.The first condition is when the Reynolds number is larger than the critical Reynolds number for contamination.For this condition, the formula for calculating the contamination length is: When the Reynolds number is less than the critical Reynolds number of contamination, the equation is: C = 18384d 0.5 L 0.5 Re −0.9 e 2.18d 0.5 The critical Reynolds number is: The flow state of these fluids for the two different conditions is distinguished by the critical Reynolds number Re j , and the contamination characteristics of the oil for the different conditions can be determined.Therefore, depending on which of the conditions applies, the proper equation is selected to calculate the contamination length.Our analysis shows that the equations do not take into account the influence of trailing oil on the contamination length.Therefore, after the simulation and data analysis, we used MATLAB software (MATLAB 8.3, The MathWorks, Natick, MA, USA, 2014) to perform multi-nonlinear regression for the oil substitution time, the length of the dead-leg, and the flow speed to calculate the contamination length [22].We were able to correct the existing equation to bring its solutions to better fit the actual data.

Model
We simulated the contamination situation in the batch transportation of oil in the Lan-Cheng-Yu pipeline.Table 1 shows the main parameters that we obtained from actual field data.In the process of batch transportation, trailing oil contamination forms when the preceding batch sticks to the pipe wall and is carried away by the second batch.Therefore, the formation of trailing oil contamination is greatly affected by the viscosity of the oil adhering to the wall, especially considering the influence of the laminar bottom layer.In Fluent software, the wall function cannot be selected for a simulation [23].The near-wall model method is more suitable for simulating the model wall formed by the trailing oil [24].For the formation of the trailing oil layer, we adopted the volume of fluid (VOF) model in the multiphase flow model, and we used a structured hexahedron for the mesh [25,26].We selected the velocity-inlet boundary condition and set the exit boundary as the outflow condition.The no-slip boundary condition is applied at the wall.
We used the commercially available computational fluid dynamics (CFD) software ANSYS FLUENT 14.5 (ANSYS 14.5, ANSYS.inc., Pittsburgh, PA, USA, 2012) to simulate mixing in a pumping station.The pump of the pumping station was equipped with a bypass pipe with a structure similar to Figure 2. The length between the check valve and the mouth of bypass was 2 m.The pumping station had a 508 mm pipe diameter, and the pipe diameter of the bypass was 168 mm.According to the calculation results, the following batch had flowed through two-thirds of the cross-section of the pipeline in 4 seconds, so we took the volume fraction of the oil at 4 seconds for the grid independence verification and the step independence verification [27,28].We analyzed the volume fraction of oil in Section 3, which is shown in Figure 3.A grid independence verification was conducted for four grid numbers, including 603042, 1532451, 2034861, and 3021581, and a step length independence verification was conducted for four time steps of 0.0005 s, 0.001 s, 0.01 s, and 0.05 s.When the grid number changed from 600,000 to 3 million, the oil volume fraction changed very little with the increase of the grid number, indicating that these four grid numbers had little influence on the calculation results (see Table 2 and Figure 4).According to the calculation results, the following batch had flowed through two-thirds of the cross-section of the pipeline in 4 s, so we took the volume fraction of the oil at 4 s for the grid independence verification and the step independence verification [27,28].We analyzed the volume fraction of oil in Section 3, which is shown in Figure 3.A grid independence verification was conducted for four grid numbers, including 603042, 1532451, 2034861, and 3021581, and a step length independence verification was conducted for four time steps of 0.0005 s, 0.001 s, 0.01 s, and 0.05 s.When the grid number changed from 600,000 to 3 million, the oil volume fraction changed very little with the increase of the grid number, indicating that these four grid numbers had little influence on the calculation results (see Table 2 and Figure 4).It can be assumed that the grid number of 600,000 reached grid independence.Therefore, the grid number of 600,000 was taken as the calculation grid.As the step length decreased, the change in the oil volume fraction became smaller and smaller.When the time step was 0.001 s, the oil volume fraction could be considered to be approximately stable.If the step size was too small, the calculation cycle sharply increased.If the step size was too large, the calculation accuracy was affected.For a comprehensive consideration, the time step size for our work was 0.001 s.

Analysis of the Mechanism of Dead-Leg Mixing
Figure 5a shows a series of contamination concentration distributions at a flow rate of 1.4 m/s for different times.It shows the process of the following batch (diesel oil) entering the dead-leg.Because of the density difference, the diesel oil in the main pipe run moves to the closed end of the dead-leg and then returns to the mouth of dead-leg.This process, which is called "gravity flow," takes about 26 s.In the first 13 s, it moves to the closed end, and in the last 13 s, it turns back to the mouth.The velocity of the gravity flow is 0.15 m/s.
The Reynolds number calculated from the arithmetic mean of the viscosity of the two fluids is 259894.03,which shows that the outcome flow in the pipe is turbulent [29].
Figure 5a shows that at 20 s, the advance gravity flow height at the closed end was about 0.056 m, which was determined by the geometric structure relative to the pipe diameter of the dead-leg.In this case, the ratio between the wave characteristic height and the pipe diameter was 0.33, and the Froude number was 0.91.The non-viscous, frictionless, non-mixing gravity current velocity was 0.21 m/s.The flow rate of 0.15 m/s was about 44% less than the ideal flow rate at the same gravity flow height.There are three reasons for this: (1) Both gasoline and diesel oil have a significant viscosity, so the fluid is not non-viscous.(2) There are obvious signs of mixing at the interface between the two oils, where they exchange momentum, leading to a decrease in the velocity of the leading batch.(3) When gasoline enters the main run, hydraulic fluctuation occurs at the mouth due to the high flow rate of diesel oil in the main run.Without the above three factors to reduce the velocity of gravity flow, the gravity flow characteristic height would reach half of the pipe diameter and flow at a speed of 0.21 m/s.It can be assumed that the grid number of 600,000 reached grid independence.Therefore, the grid number of 600,000 was taken as the calculation grid.As the step length decreased, the change in the oil volume fraction became smaller and smaller.When the time step was 0.001 s, the oil volume fraction could be considered to be approximately stable.If the step size was too small, the calculation cycle sharply increased.If the step size was too large, the calculation accuracy was affected.For a comprehensive consideration, the time step size for our work was 0.001 s.

Analysis of the Mechanism of Dead-Leg Mixing
Figure 5a shows a series of contamination concentration distributions at a flow rate of 1.4 m/s for different times.It shows the process of the following batch (diesel oil) entering the dead-leg.Because of the density difference, the diesel oil in the main pipe run moves to the closed end of the dead-leg and then returns to the mouth of dead-leg.This process, which is called "gravity flow," takes about 26 s.In the first 13 s, it moves to the closed end, and in the last 13 s, it turns back to the mouth.The velocity of the gravity flow is 0.15 m/s.
The Reynolds number calculated from the arithmetic mean of the viscosity of the two fluids is 259894.03,which shows that the outcome flow in the pipe is turbulent [29].
Figure 5a shows that at 20 s, the advance gravity flow height at the closed end was about 0.056 m, which was determined by the geometric structure relative to the pipe diameter of the dead-leg.In this case, the ratio between the wave characteristic height and the pipe diameter was 0.33, and the Froude number was 0.91.The non-viscous, frictionless, non-mixing gravity current velocity was 0.21 m/s.The flow rate of 0.15 m/s was about 44% less than the ideal flow rate at the same gravity flow height.There are three reasons for this: (1) Both gasoline and diesel oil have a significant viscosity, so the fluid is not non-viscous.(2) There are obvious signs of mixing at the interface between the two oils, where they exchange momentum, leading to a decrease in the velocity of the leading batch.(3) When gasoline enters the main run, hydraulic fluctuation occurs at the mouth due to the high flow rate of diesel oil in the main run.Without the above three factors to reduce the velocity of gravity flow, the gravity flow characteristic height would reach half of the pipe diameter and flow at a speed of 0.21 m/s.
When diesel oil flows into the dead-leg from the junction, the same volume of gasoline flows out of the dead-leg and into the main run.This flow is called the "lock exchange" flow.Because the flow rate of gasoline is small and the main diesel flow rate is large, trailing oil will be formed at the junction, especially when gravity plays a dominant role.
Processes 2018, 6, x FOR PEER REVIEW 7 of 20 When diesel oil flows into the dead-leg from the junction, the same volume of gasoline flows out of the dead-leg and into the main run.This flow is called the "lock exchange" flow.Because the flow rate of gasoline is small and the main diesel flow rate is large, trailing oil will be formed at the junction, especially when gravity plays a dominant role.After 30 s, the dominant effect of the gasoline outflow changed from gravity to turbulent diffusion, and the gasoline outflow from the dead-leg will form a turbulent mixing-like flow at a distance from joint of 2-3 times the pipe diameter.This was caused by the interfacial shear force between gasoline and diesel oil.Therefore, more contamination appeared in the dead-leg, and the concentration distribution of contamination was increased (see Figure 5b).
The gas volume fraction at Section 8 (at 1 m from the junction) began to decrease at 8 s (Figure 6).Since the flow rate of gravity flow in the dead-leg was 0.15 m/s, the time of diesel oil flow from After 30 s, the dominant effect of the gasoline outflow changed from gravity to turbulent diffusion, and the gasoline outflow from the dead-leg will form a turbulent mixing-like flow at a distance from joint of 2-3 times the pipe diameter.This was caused by the interfacial shear force between gasoline and diesel oil.Therefore, more contamination appeared in the dead-leg, and the concentration distribution of contamination was increased (see Figure 5b).
The gas volume fraction at Section 8 (at 1 m from the junction) began to decrease at 8 s (Figure 6).Since the flow rate of gravity flow in the dead-leg was 0.15 m/s, the time of diesel oil flow from the junction to the Section 8 was about 5 s, and the remaining 3 s was the time from the contact between the two kinds of oil to the time they reached the junction.
the junction to the Section 8 was about 5 s, and the remaining 3 s was the time from the contact between the two kinds of oil to the time they reached the junction.At 30 s, when the gravity flow returned to the junction from the closed end, about half of the gasoline had formed a lock exchange flow with diesel oil due to gravity, and then it flowed out of the dead-leg, which is consistent with the previous diagram of the concentration distribution of the contamination in the dead-leg.The remaining half of the gasoline took longer to outflow from the pipes, because the mechanism of the flow was turbulent diffusion, which mainly occurred in the joints.Diesel oil slowly penetrated via turbulent diffusion into the dead-leg, where it replaced the gasoline.This is why the contamination interface in the gravity flow stage in the dead-leg fluctuated, while the contamination interface in the turbulent diffusion stage did not.
The movement of the diesel oil drained the gasoline in the pipeline away.Figure 7 showed that after passing through the dead-leg along the conveying direction, there was a small amount of contamination adhering to the pipe wall at the upper end of the main pipe, either in a thin strip, or floating above the diesel oil in a droplet form.These mixtures were formed when gasoline in the dead-leg entered the main pipe under the action of gravity and turbulent diffusion.The trailing oil increased the amount of contamination, so the real amount of contamination was greater than that predicted by theory.At 30 s, when the gravity flow returned to the junction from the closed end, about half of the gasoline had formed a lock exchange flow with diesel oil due to gravity, and then it flowed out of the dead-leg, which is consistent with the previous diagram of the concentration distribution of the contamination in the dead-leg.The remaining half of the gasoline took longer to outflow from the pipes, because the mechanism of the flow was turbulent diffusion, which mainly occurred in the joints.Diesel oil slowly penetrated via turbulent diffusion into the dead-leg, where it replaced the gasoline.This is why the contamination interface in the gravity flow stage in the dead-leg fluctuated, while the contamination interface in the turbulent diffusion stage did not.
The movement of the diesel oil drained the gasoline in the pipeline away.Figure 7 showed that after passing through the dead-leg along the conveying direction, there was a small amount of contamination adhering to the pipe wall at the upper end of the main pipe, either in a thin strip, or floating above the diesel oil in a droplet form.These mixtures were formed when gasoline in the dead-leg entered the main pipe under the action of gravity and turbulent diffusion.The trailing oil increased the amount of contamination, so the real amount of contamination was greater than that predicted by theory.Figure 8 show that because the statistical data started at 1 s, the gasoline in Section 1 of the pipeline had been replaced, so the volume fraction of gasoline in Section 1 had not changed with time.Section 2 was located before the dead-leg, so Section 2 was not filled with gasoline from the dead-leg.Therefore, the volume fraction of Section 2 only reflected the volume fraction of gasoline in the main run.The other three curves in Figure 8 showed a certain regularity in the gentle phase.With an increase in distance along the pipeline, the maximum value of the gentle phase increased, and the Figure 8 show that because the statistical data started at 1 s, the gasoline in Section 1 of the pipeline had been replaced, so the volume fraction of gasoline in Section 1 had not changed with time.Section 2 was located before the dead-leg, so Section 2 was not filled with gasoline from the dead-leg.Therefore, the volume fraction of Section 2 only reflected the volume fraction of gasoline in the main run.The other three curves in Figure 8 showed a certain regularity in the gentle phase.With an increase in distance along the pipeline, the maximum value of the gentle phase increased, and the slope of the curve increased.These increases were due to the fact that after Section 2, the volume fraction of gasoline at each cross-section was influenced by the dead-leg.The volume fraction of these cross-sections was the sum of the volume fraction of gasoline attached to the pipe wall and the volume fraction of gasoline flowing out of the dead-leg.As the distance increases, the sum of the two increases, increasing the mixing oil content.The slope increases because, due to diffusion, the farther away the cross-section was, the less the influence the dead-leg had.The faster the volume fraction of gasoline decreased, the larger the slope of the curve was.

The Influence of Velocity on the Trailing Oil
Figure 9 shows that the higher the flow rate led to the faster the oil replacement rate and the smaller the amount of mixing.Figure 10 shows the relationship between the gasoline volume fraction and time for three different flow rates.The figure shows that there were three stages in the process.In Stage 1, diesel had not yet reached Section 3, which explained the straight line with a value of 1 for the gasoline fraction.In Stage 2, in the initial stage of mixing, most of the gasoline in the pipeline was pushed away by diesel oil, so the volume fraction of gasoline dropped rapidly, and the slope of the curve was very large.The duration of this stage was about 2 s for each flow rate.In Stage 3, the trailing oil formed as gasoline attached to the wall of the pipe.The volume fraction of gasoline in this stage decreased slowly, and the slope of the curve was small.The oil in the dead-leg flowed out due to gravity, and the two kinds of liquids formed a lock exchange flow at the junction.At this time, the main factor causing the contamination was convective transmission.When about half of the preceding batch was replaced in the dead-leg, the influence of convection was gradually reduced, and diffusion transfer began to play a role.After turbulent diffusion, the following batch gradually flowed into the dead-leg and the liquid was slowly replaced.In these two processes, the time of turbulent diffusion was obviously longer than that of convection, and the forward batch from the dead-leg formed trailing oil in the main pipe run.

The Influence of Velocity on the Trailing Oil
Figure 9 shows that the higher the flow rate led to the faster the oil replacement rate and the smaller the amount of mixing.Figure 10 shows the relationship between the gasoline volume fraction and time for three different flow rates.The figure shows that there were three stages in the process.In Stage 1, diesel had not yet reached Section 3, which explained the straight line with a value of 1 for the gasoline fraction.In Stage 2, in the initial stage of mixing, most of the gasoline in the pipeline was pushed away by diesel oil, so the volume fraction of gasoline dropped rapidly, and the slope of the curve was very large.The duration of this stage was about 2 s for each flow rate.In Stage 3, the trailing oil formed as gasoline attached to the wall of the pipe.The volume fraction of gasoline in this stage decreased slowly, and the slope of the curve was small.the gasoline fraction.In Stage 2, in the initial stage of mixing, most of the gasoline in the pipeline was pushed away by diesel oil, so the volume fraction of gasoline dropped rapidly, and the slope of the curve was very large.The duration of this stage was about 2 s for each flow rate.In Stage 3, the trailing oil formed as gasoline attached to the wall of the pipe.The volume fraction of gasoline in this stage decreased slowly, and the slope of the curve was small.For the flow rate of 0.8 m/s, Stage 1 lasted about 4 s, but for 1.6 m/s, Stage 1 lasted only about 2 s.Next, at the end of Stage 2, about 40% of the gasoline remained for the flow rate of 0.8 m/s, and only about 5% remained for 1.6 m/s.Finally, in Stage 3, the rate of decline of the gasoline volume fraction was different.The time required for the volume fraction of gasoline to decrease from 20% to 15% was about 1 s for the flow rate of 0.8 m/s, but it was only about 0.4 s for 1.2 m/s.These differences show that in the initial mixing stage, the faster the flow rate was, the faster the diesel oil reached each cross-section, and the faster the oil replacement speed was.This stage was only about 2 seconds.In the initial mixing stage, the greater the flow rate, the stronger the diesel oilʹs ability to carry gasoline.Finally, the faster the flow rate was, the faster the diesel oil carried the gasoline, and less trailing oil was formed.
Figure 11a shows that when the flow rate in a dead-leg varies, the rate of decrease for the gasoline volume fraction in the dead-leg stayed essentially the same.The gasoline in the dead-leg entered the main pipe run mainly because of the lock exchange flow formed by gravity.The diesel oil with higher viscosity entered the dead-leg due to gravity.In the first 20 seconds, the amount of gasoline entering the main pipe was about the same for the different speeds.From 20 s to 30 s, the main form of the lock exchange flow was still the gasoline entering the main run, but the turbulent diffusion became more important as the diesel entered the dead-leg.After 30 s, nearly half of the liquid in the dead-leg was diesel oil.Turbulent diffusion replaces gravity as the main driving force for gasoline to flow into the main run.At this time, the larger the main flow speed, the less time it took to carry gasoline, and the less important the turbulent diffusion effect with the gasoline was in the dead-leg, even though the carrying capacity of the diesel oil per unit volume of gasoline was unchanged.This made the remaining gasoline volume fraction in the dead-leg increase with the increasing diesel transmission speed in the main run; that is, the oil replacement speed in the dead- For the flow rate of 0.8 m/s, Stage 1 lasted about 4 s, but for 1.6 m/s, Stage 1 lasted only about 2 s.Next, at the end of Stage 2, about 40% of the gasoline remained for the flow rate of 0.8 m/s, and only about 5% remained for 1.6 m/s.Finally, in Stage 3, the rate of decline of the gasoline volume fraction was different.The time required for the volume fraction of gasoline to decrease from 20% to 15% was about 1 s for the flow rate of 0.8 m/s, but it was only about 0.4 s for 1.2 m/s.These differences show that in the initial mixing stage, the faster the flow rate was, the faster the diesel oil reached each cross-section, and the faster the oil replacement speed was.This stage was only about 2 s.In the initial mixing stage, the greater the flow rate, the stronger the diesel oil's ability to carry gasoline.Finally, the faster the flow rate was, the faster the diesel oil carried the gasoline, and less trailing oil was formed.
Figure 11a shows that when the flow rate in a dead-leg varies, the rate of decrease for the gasoline volume fraction in the dead-leg stayed essentially the same.The gasoline in the dead-leg entered the main pipe run mainly because of the lock exchange flow formed by gravity.The diesel oil with higher viscosity entered the dead-leg due to gravity.In the first 20 s, the amount of gasoline entering the main pipe was about the same for the different speeds.From 20 s to 30 s, the main form of the lock exchange flow was still the gasoline entering the main run, but the turbulent diffusion became more important as the diesel entered the dead-leg.After 30 s, nearly half of the liquid in the dead-leg was diesel oil.Turbulent diffusion replaces gravity as the main driving force for gasoline to flow into the main run.At this time, the larger the main flow speed, the less time it took to carry gasoline, and the less important the turbulent diffusion effect with the gasoline was in the dead-leg, even though the carrying capacity of the diesel oil per unit volume of gasoline was unchanged.This made the remaining gasoline volume fraction in the dead-leg increase with the increasing diesel transmission speed in the main run; that is, the oil replacement speed in the dead-leg slowed down.

The Effect of the Dead-Leg Length on Trailing Oil
For the system we considered, the diameter of the main pipe was d = 508 mm; the length of the dead-leg was d, 2d, 3d, 4d, 5d, 6d, 7d; and the flow speed was 1.4 m/s.The diameter of the bypass was 168 mm, and the delivery sequence was diesel oil pushing gasoline.When the volume fraction of gasoline in the dead-leg was less than 1%, we considered it to be completely replaced [32][33][34].
Figure 12 shows that the relationship between the length of the dead-leg and the time needed for the replacement of the dead-leg oil product can be described as:  The gasoline was considered to be completely replaced by diesel oil when the volume percentage of gasoline in the dead-leg was less than 1% [30,31].Figure 11b shows that when the flow rate was larger than 1.6 m/s, the replacement time of dead-leg oil increased rapidly.The length of the trailing oil formed in the main run increased accordingly, so the flow rate should be kept at about 1.6 m/s.
According to the data in Figure 11b, the relationship between the replacement time and the flow velocity of the dead-leg can be described as: The simulation and analysis of different flow rates shows that in the main pipe run, faster flow speed led to faster oil replacement rates, shorter contamination length, and smaller contamination content.In the dead-leg, faster flow speed led to slower oil replacement rates, longer trailing oil lengths in the main pipe run, and greater contamination.

The Effect of the Dead-Leg Length on Trailing Oil
For the system we considered, the diameter of the main pipe was d = 508 mm; the length of the dead-leg was d, 2d, 3d, 4d, 5d, 6d, 7d; and the flow speed was 1.4 m/s.The diameter of the bypass was 168 mm, and the delivery sequence was diesel oil pushing gasoline.When the volume fraction of gasoline in the dead-leg was less than 1%, we considered it to be completely replaced [32][33][34].
Figure 12 shows that the relationship between the length of the dead-leg and the time needed for the replacement of the dead-leg oil product can be described as: Processes 2018, 6, x FOR PEER REVIEW 14 of 20 Figure 13 shows that when the length of the dead-leg was larger than 5 times that of the main pipe diameter, the time required for the forward batch to be replaced by the backward batch in the dead-leg increased sharply, which indicated that the effect of turbulent diffusion was still relatively large for this length.Beyond this length, the effect of turbulent diffusion was significantly weakened, and the sample formed a long trailing oil in the main run.
Figure 13 shows that the rate of decrease in the gasoline volume fraction shown in each curve changed back and forth between faster and slower.There were three different trends in these changes.The first was that as time went on, the slope of the curves decreased for each stage.This was due to the flow mechanism of dead-leg gasoline changing from lock exchange flow to turbulent diffusion, which took longer to move the same volume of gasoline out.The second was that with an increase in the length of the dead-leg, the decrease in the rate of the gasoline volume fraction became smaller and smaller.This was because the longer the dead-leg length was, the lower the turbulent diffusion effect on the closed end of the gasoline, and the longer the oil replacement time was.The third was that with an increase in the length of the dead-leg, the time between the changes between faster and slower rate changes became longer and longer.This was because the volume fraction of gasoline represented by the curve referred to the volume fraction of gasoline at Section 8, which was 1 m away from the junction, not the volume fraction of gasoline in the whole dead-leg.The longer the dead-leg length, the longer the time required for gravity flowing back to the section, such that the cycle time between faster and slower changes decreased.
Through the simulation and analysis of different length of dead-leg, it can be concluded that the longer dead-leg led to a slower replacement rate of the oil in the dead-leg, a longer length of trailing oil in the main pipe, and a greater amount of contamination.  Figure 13 shows that when the length of the dead-leg was larger than 5 times that of the main pipe diameter, the time required for the forward batch to be replaced by the backward batch in the dead-leg increased sharply, which indicated that the effect of turbulent diffusion was still relatively large for this length.Beyond this length, the effect of turbulent diffusion was significantly weakened, and the sample formed a long trailing oil in the main run.

Formula Correction
Our data can be used to obtain the relationship between the length of trailing oil in a 508 mm pipeline for different pipe segments and the influencing factors when diesel fuel was used to push gasoline.Using MATLAB to simulate the oil replacing time, the dead-leg length, and the speed, the following equations were obtained (Table 3): where T is the time to replace the oil in the dead-leg, V is the flow rate, and Lm is the length of the dead-leg.The determination coefficient R 2 of the fitting formula was as high as 0.9969, indicating that the formula is highly reliable.Knowing the time required to replace the oil in the dead-leg, the contamination length of the trailing oil, C, produced in the main pipe after passing through a deadleg can be calculated using:  Figure 13 shows that the rate of decrease in the gasoline volume fraction shown in each curve changed back and forth between faster and slower.There were three different trends in these changes.The first was that as time went on, the slope of the curves decreased for each stage.This was due to the flow mechanism of dead-leg gasoline changing from lock exchange flow to turbulent diffusion, which took longer to move the same volume of gasoline out.The second was that with an increase in the length of the dead-leg, the decrease in the rate of the gasoline volume fraction became smaller and smaller.This was because the longer the dead-leg length was, the lower the turbulent diffusion effect on the closed end of the gasoline, and the longer the oil replacement time was.The third was that with an increase in the length of the dead-leg, the time between the changes between faster and slower rate changes became longer and longer.This was because the volume fraction of gasoline represented by the curve referred to the volume fraction of gasoline at Section 8, which was 1 m away from the junction, not the volume fraction of gasoline in the whole dead-leg.The longer the dead-leg length, the longer the time required for gravity flowing back to the section, such that the cycle time between faster and slower changes decreased.
Through the simulation and analysis of different length of dead-leg, it can be concluded that the longer dead-leg led to a slower replacement rate of the oil in the dead-leg, a longer length of trailing oil in the main pipe, and a greater amount of contamination.

Formula Correction
Our data can be used to obtain the relationship between the length of trailing oil in a 508 mm pipeline for different pipe segments and the influencing factors when diesel fuel was used to push gasoline.Using MATLAB to simulate the oil replacing time, the dead-leg length, and the speed, the following equations were obtained (Table 3): T = 119.1V+ 15.48e 0.7756Lm + 175.3 (7) where T is the time to replace the oil in the dead-leg, V is the flow rate, and L m is the length of the dead-leg.The determination coefficient R 2 of the fitting formula was as high as 0.9969, indicating that the formula is highly reliable.Knowing the time required to replace the oil in the dead-leg, the contamination length of the trailing oil, C, produced in the main pipe after passing through a dead-leg can be calculated using: Because there were often many dead-legs in the station, the forward batch in the first dead-leg inevitably affected the density of oil in the pipeline after re-entering the main pipe, thereby affecting the oil carrying speed and the trailing oil length in the subsequent dead-legs.
Table 4 shows the effect of the number of dead-legs on the length of trailing oil when the density of diesel oil in the rear batch was 842 kg/m 3 and the density of gasoline in the forward batch was 722 kg/m 3 .The table shows that with an increase in the number of dead-legs, the average density of contamination decreased, oil substitution time in dead-leg increased, and the length of trailing oil increased correspondingly.The increasing rule was obtained through nonlinear fitting, and the Equation ( 8) is modified to: where N is the number of dead-legs.We also simulated the situation of contamination formed via dead-legs with different densities of the rear batch.Figure 14 shows that a higher density of the rear batch slows the decrease in the volume fraction of the forward batch in the main pipe.This shows that a greater difference in the densities between the two kinds of liquids led to faster outflow velocities of the forward batch in the dead-leg, and shorter lengths of trailing oil formed.In the actual calculation of the length of contamination, only the oil of the unqualified part in the mixing oil section was usually thought to need contamination cutting.For the identification of contamination and the need for on-site contamination cutting, the length of contamination was calculated using the existing calculation formula when the volume fraction of oil in the forward batch was larger than 1%, so only this part was considered in the correction process based on the equation.The influence of most of the trailing oil on oil quality could be ignored.
Figure 14 shows that the volume fraction of gasoline at 6 s to 9 s was less than 1%.The distance between the two interfaces with 99% and 1% forward batch concentration was defined as the length of the contamination.Equation ( 9) can be modified to yield: According to the data from the Lan-Cheng-Chong pipeline, there are 16 stations along the 1250 km pipeline.The diameter for the Lanzhou-Jiangyou section is 508 mm, the diameter for the Jiangyou-Chengdu section is 457 mm, and the diameter for the Chengdu-Chongqing section is 323.9 mm.
The transportation of the pipeline was analyzed, and the initial throughput of the pipeline was 21220.021t/day, and the contamination content at the end point was 334.109 t.The contamination content calculated from the first method's equation (Equation ( 1)) was 396.785 t, and the second method's equations (Equation (2) and Equation ( 3)) led to 314.415 t.The contamination content of the second method with our correction was 331.067 t, and the relative error was 0.9% (Figure 15). Figure 14 shows that the volume fraction of gasoline at 6 s to 9 s was less than 1%.The distance between the two interfaces with 99% and 1% forward batch concentration was defined as the length of the contamination.Equation ( 9) can be modified to yield: According to the data from the Lan-Cheng-Chong pipeline, there are 16 stations along the 1250 km pipeline.The diameter for the Lanzhou-Jiangyou section is 508 mm, the diameter for the Jiangyou-Chengdu section is 457 mm, and the diameter for the Chengdu-Chongqing section is 323.9 mm.
The transportation of the pipeline was analyzed, and the initial throughput of the pipeline was 21220.021t/day, and the contamination content at the end point was 334.109 t.The contamination content calculated from the first method's equation (Equation ( 1)) was 396.785 t, and the second method's equations (Equation (2) and Equation ( 3)) led to 314.415 t.The contamination content of the second method with our correction was 331.067 t, and the relative error was 0.9% (Figure 15).According to the above comparison, Equations ( 2) and (3) should be revised for calculating the contamination length considering the length of trailing oil.
When the Reynolds number was larger than the critical Reynolds number of contamination, the formula for calculating the contamination length is: C = 11.75d 0.5 L 0.5 Re −0.1 + 9[0.21 ln(N) + 0.96] ( When the Reynolds number is larger than the critical Reynolds number of contamination, the equation becomes: C = 18384d 0.5 L 0.5 Re −0.9 e 2.18d 0.5 + 9[0.21 ln(N) + 0.96]V (12) The above equations yield results that are closer to real data, therefore they provide a greater guide for the accurate cutting of contamination, which has practical significance.According to the above comparison, Equations ( 2) and (3) should be revised for calculating the contamination length considering the length of trailing oil.
When the Reynolds number was larger than the critical Reynolds number of contamination, the formula for calculating the contamination length is: When the Reynolds number is larger than the critical Reynolds number of contamination, the equation becomes: The above equations yield results that are closer to real data, therefore they provide a greater guide for the accurate cutting of contamination, which has practical significance.

Conclusions
This paper describes our analysis of the formation mechanism of trailing oil in pipelines and our study of the influence of dead-legs on the formation of trailing oil using numerical simulation with Fluent software.
(1) Dead-legs and the oil adhered to the walls, forming a laminar bottom, were the main factors for the formation of trailing oil.There were two stages of trailing oil formation in a dead-leg, a gravity flow stage and turbulent diffusion stage.The turbulent diffusion stage took a longer time and the amount of mixed oil was larger.
(2) The effect of flow velocity on the replacement time of the oil in the dead-leg was opposite to that in the main pipe run.The oil replacement time in the main pipe was negatively correlated with the flow velocity, while the oil replacement speed in the dead-leg was positively correlated with the flow velocity, and the relationship between the two was exponential: T = 345.59e 0.1252v .The longer the oil replacement time was, the longer the mixing length was, and the larger the contamination content was.Because the replacement time of oil in the dead-leg was greatly influenced by the flow rate, the flow rate should be controlled to about 1.6 m/s in order to reduce the contamination content.

Conclusions
This paper describes our analysis of the formation mechanism of trailing oil in pipelines and our study of the influence of dead-legs on the formation of trailing oil using numerical simulation with Fluent software.
(1) Dead-legs and the oil adhered to the walls, forming a laminar bottom, were the main factors for the formation of trailing oil.There were two stages of trailing oil formation in a dead-leg, a gravity flow stage and turbulent diffusion stage.The turbulent diffusion stage took a longer time and the amount of mixed oil was larger.
(2) The effect of flow velocity on the replacement time of the oil in the dead-leg was opposite to that in the main pipe run.The oil replacement time in the main pipe was negatively correlated with the flow velocity, while the oil replacement speed in the dead-leg was positively correlated with the flow velocity, and the relationship between the two was exponential: T = 345.59e 0.1252v .The longer the oil replacement time was, the longer the mixing length was, and the larger the contamination content was.Because the replacement time of oil in the dead-leg was greatly influenced by the flow rate, the flow rate should be controlled to about 1.6 m/s in order to reduce the contamination content.
(3) The length of the dead-leg was exponentially related to the oil substitution time: T = 64.547e 0.5878d .In order to reduce the contamination content, the dead-leg length should be less than five times the diameter of the main pipe.
(4) Based on the simulation results, we modified the theoretical formula for calculating the contamination length.The formula includes the influence of the trailing oil formed by the dead-leg on the contamination length, which makes the formula more consistent with real data.
(5) In order to reduce the amount of oil mixing, the flow rate should be controlled and the length of the dead-leg should be reduced.Reasonable removal of the trailing oil can improve the quality of the refined oil and increase its economic value.

Figure 1 .
Figure 1.Dead-legs formed by bypasses in valve chambers and pumping stations.

Figure 1 .
Figure 1.Dead-legs formed by bypasses in valve chambers and pumping stations.

Figure 2 .
Figure 2. Schematic diagram of the model grid.

Figure 2 .
Figure 2. Schematic diagram of the model grid.

Figure 4 .
Figure 4. Grid independence and step-length independence verification diagram.

Figure 4 .
Figure 4. Grid independence and step-length independence verification diagram.

Figure 5 .
Figure 5. Cross-section diagram of contamination concentration in the dead-leg at different times (a) Section 6; (b) Section 7.

Figure 5 .
Figure 5. Cross-section diagram of contamination concentration in the dead-leg at different times (a) Section 6; (b) Section 7.

Figure 6 .
Figure 6.Variation in the gasoline volume fraction at Section 8 with time.

Figure 6 .
Figure 6.Variation in the gasoline volume fraction at Section 8 with time.

20 Figure 7 .
Figure 7. Distribution of mixed oil density at different times during v = 1.4 m/s.

Figure 7 .
Figure 7. Distribution of mixed oil density at different times during v = 1.4 m/s.

Figure 8 .
Figure 8. Curves of gasoline volume fraction varying with time at different pipe sections.

Figure 8 .
Figure 8. Curves of gasoline volume fraction varying with time at different pipe sections.

Figure 9 .
Figure 9. Distribution of mixed oil density at different conveying speeds for 15 s.

Figure 9 .Figure 10 .
Figure 9. Distribution of mixed oil density at different conveying speeds for 15 s.

Figure 10 .
Figure 10.The relationship between gasoline volume fraction and time at Section 3 for different flow rates.

Figure 11 .
Figure 11.(a) Relationship between contamination and speed in Section 8, and (b) relationship between replacement time and speed of liquid in a dead-leg.

Figure 11 .
Figure 11.(a) Relationship between contamination and speed in Section 8, and (b) relationship between replacement time and speed of liquid in a dead-leg.

Figure 12 .
Figure 12.Relationship between the dead-leg length and the time required for gasoline replacement.

Figure 12 .
Figure 12.Relationship between the dead-leg length and the time required for gasoline replacement.

Figure 13 .
Figure 13.Relationships between gasoline volume fractions and time for different dead-leg lengths.

Figure 13 .
Figure 13.Relationships between gasoline volume fractions and time for different dead-leg lengths.

Figure 14 .
Figure 14.Relationship between the contamination volume fraction in Section 3 and time for different densities of the rear batch.

Figure 14 .
Figure 14.Relationship between the contamination volume fraction in Section 3 and time for different densities of the rear batch.

Figure 15 .
Figure 15.Calculation of contamination content by three different ways.

Figure 15 .
Figure 15.Calculation of contamination content by three different ways.

Table 1 .
Physical property parameters of oil.

Table 2 .
Variation of oil volume fraction with grid number and time step.

Table 2 .
Variation of oil volume fraction with grid number and time step.

Table 4 .
The effect of the number of dead-legs on the trailing oil length.