Research of Heated Oil Pipeline Shutdown and Restart Process Based on VB and MATLAB
Автор: Changjun Li, Xia Wu, Wenlong Jia
Журнал: International Journal of Modern Education and Computer Science (IJMECS) @ijmecs
Статья в выпуске: 2 vol.2, 2010 года.
Бесплатный доступ
During the operation of a heated oil transportation pipeline, the shutdown was caused by some pipeline accidents and repairing. In order to ensure the safety operation of the pipeline, determine the temperature drop and restart pressure was needed at different shutdown is important. This paper builds the heated oil pipeline temperature drop model after shutdown based on the unsteady heat transfer theory and restart model based on fluid transient flow theory. In order to solve the models, MATLAB is adopted a code for the models solving program. VB and MATLAB hybrid programming method which is on the basis of COM technical is utilized to develop a friendly man-machine interface for the heated oil pipeline shutdown and restart simulation software. The practical application shows using of VB and MATLAB hybrid programming method can reduce the work of algorithm developing and enhance the reliability of heated oil pipeline shutdown and restart simulation software.
Heated oil pipeline, model, simulation, VB and MATLAB, hybrid programming, Component Object Module
Короткий адрес: https://sciup.org/15010054
IDR: 15010054
Текст научной статьи Research of Heated Oil Pipeline Shutdown and Restart Process Based on VB and MATLAB
Published Online December 2010 in MECS
The oil pipeline is an important way to transport the oil from the oil field and refinery to end-users. It is composed of pipelines, pump stations and heating stations typically (Fig.1).

a pump station end users
Figure 1. A typical heated oil transportation pipeline system
If the viscosity of the oil is high, the oil should be heated to decrease its viscosity. Then the transport friction can be decreased and the transport efficiency is enhanced. The heated oil pipeline is a kind of pipeline which is designed to transport heated oil specially [1]. Inevitably, during the operation process, the operation shutdown is caused by some pipeline accidents and repairing. The oil temperature decreases with the lasting of shutdown but the viscosity increases. Higher pressure at the pipeline entrance than the maximum operation pressure (MOP) may be needed to drive the high viscosity oil flow in the pipeline when the pipeline restarts after long shutdown lasting time. Consequently, in order to provide technical supports for safety operation of heated oil pipeline, it is important to investigate the temperature drop and restart pressure needed at different shutdown lasting time [2-3].
For solving these problems, Li, et al developed a new model of restart pressure for a gelled crude restart operation based on an indoor circular pipeline experiment [4]. Yang, et al constructed a definition problem on heat conduction between the oil pipeline and external environment, and obtained the analytical solution of the axial oil temperature change [5]. Liu, et al established a modified rectangular stable heat transfer physical model which was solved by finite difference method, so that the maximum flow stoppage time of pipeline can be gained [6]. Nossen described the implementation and use of a rheological model for gelled waxy crude oils in the dynamic multiphase flow simulator PeTra [7]. Yu, et al. used large experimental loops and OLGA software to study shutdown and restart transient flow characteristic in offshore multiphase pipeline [8]. Liu, et al built the restart model for heated oil pipeline on the basis of transient simulation model of the pipeline, and the model was solved by method of characteristic (MOC) and finite difference method [1].
In summary, the achievements of scholars indicate that we can obtain the temperature drop and restart pressure after a certain shutdown time by establishing mathematical models. The models of shutdown and restart are composed of a great amount of partial differential equations which can be solved by numerical solving methods, such as MOC, differences method and Newton-iteration method. Thus, complicated matrixes computation must be carried out. Corresponding simulation results are also need graphics output. Fortunately, MATLAB is specialized in matrix computation and graphic process.
MATLAB is Matrix Laboratory for short, and it is commercial mathematical software produced by the Mathworks which is known as major mathematical software as the same as Maple. It is an interactive, object- oriented programming language. MATLAB is intended primarily for numerical computing. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, and the creation of user interfaces. Although MATLAB has a powerful matrix and graphic processing functions, there are still some disadvantages. First, MATLAB language is an interpretive scripting language. Its program operating efficiency is low. Second, MATLAB program can only run on a MATLAB platform. Finally, the capability of accessing its hardware is relatively poor, and the user interface development is inconvenient. However, Visual Basic (VB) is the most popular application development environment in windows platform developed by Microsoft Corporation. The advantages of VB are programming quick and simple, good interface, convenient development of software interface, which covers the shortage of MATLAB [9]. Combination of the two programming software provides an effective way to develop more professional, flexible numerical simulation software [10-13].
On the basis of unsteady heat transfer model of the heated oil pipeline and transient flow theory, this paper builds the temperature drop model and restart model. Then, with using of VB and MATLAB hybrid programming technical, heated oil pipeline Shutdown and Restart Simulation Software (SRSS) is developed. The SRSS can provide technical supports for determining the safety shutdown time and the restart pressure needed after shutdown.
II. Temperature Drop Model and Restart Model
Heat transfer equation of heated oil pipeline:
5 T 5 Д 5 тД 5 Д 5 T
—L = — I Asr s I +—I As —
5t 5x ( 5x J 5y ( 5y
Heat transfer equation of pipeline wall:
. C 8_Tl=1 Af a T 1+-1 Ata )
n n 5t r 5r ( n 5r J r2 59 ( n 59 J
Heat transfer equation of soil:
5 T 5 Д 5 ТД 5 Д 5 T —- = — I Asr^ I + —I As—s
5t 5x ( 5x J 5y ( 5y
In order to form the definition problem of temperature drop model, the corresponding connecting conditions, initial conditions, and boundary conditions should be introduce into above equations.
Boundary conditions:
г 5 T .
lim r— = 0
r ^ o 5 r
5 Ts
5 y
= ^w (Ts - T)
y = 0 A s
Connecting conditions:
A o
5 T o
5 r
r = R 0
= A 1 5 T 1 5 r
>+
r = R
= -a( T - T) (6)
A. Temperature Drop Model After Shutdown
For the temperature drop calculation of heated oil pipeline after shutdown, established the coordinate system as shown in Fig. 1 and select the oil, pipeline, insulating layer, semi-infinite soil and air environment as the objects of research. Ignore the soil heat transfer along the axis Z direction of the pipeline. The unsteady heat transfer model of the pipeline is presented in (1)-(3).
5 T n
5 r
r = R
n
, 5 Tn+!
'n + 1 5 r
- - T n + 1 l r = R *
r = R
+ + n
n = 1,2, l , N - 1 (7)
n = 1,2, l, N - 1

Figure 1. Geometric coordinate system of buried pipeline
n
n
T I n l r = R
. 5 T n a n —I— |
= A . 5 ^" |
(9) |
5 r |
- = R N 5 r |
r = R N |
T N |
= T 1 + = R N sr = R N |
(10) |
Initial conditions: |
||
1 1 = 0 |
= f ( r, 9 ) |
(11) |
Tn\t = 0 = fn ( r, 9 ) |
(12) |
|
T s i t = 0 |
= f . ( x , У ) |
(13) |
Where, ρ is oil density, kg/m3; ρ n is density of the n layer(pipeline wall, insulating layer, and ), kg/m3; ρ n is the soil density, kg/m3; c is oil heat capacity, J/(kg. ^ ); Cn is the n layer heat capacity, J/(kg. °C); C s is the soil capacity, J/(kg. C ); X is oil thermal conductivity,
W/(m. °C ); X n is the n layer thermal conductivity , W/(m. C ); T is oil temperature, C ; T n is n layer temperature, C; T s is soil temperature, C ; T w is surface temperature, C ; a is heat transfer coefficient from oil to pipeline internal wall, W/(m. C ); a w is heat transfer from soil to air, W/(m. C ); R 0 is pipeline inside radius, m; Rn is outer diameter of n layer, m.
The definite problem is composed of (1)-(13). Conformal transformation is used to transform the semiinfinite region into finite region and then difference method is adapted to analyze the oil temperature variation with time along the pipeline after shutdown [2].
B.Restart Model
The restart of the pipeline is a transient flow process. According to the theory of fluid mechanics, the continuity equation, momentum equation and energy equation can be used to describe the relationship among the fluid pressure, temperature and flow in pipeline.
Continuity equation:
d P ,,3P 2 VV a
— + V — + pa2— = 0 dt 5x 5x
Momentum equation
av 1 ap. av . o x т.ы
+ + V = - g sin 9 V V
at p ax ax 2 d 1 1
Energy equation
a t t dpx a v _ a t , v
--1 (—) + V = X at pc dt p ax ax 2dc
-K- ( t - T )
p DCV 07
Similar to temperature drop model, the corresponding connecting conditions, initial conditions, and boundary conditions should be introduced into (14)-(16).
Temperature conditions, namely, the temperature of heated oil implanted into pipeline should be equal to the pipeline entrance temperature under steady-state:
( x = 0 ) : T\ x = 0 = T n (17)
Flow rate conditions, namely, the pipeline entrance (pump outlet) flow required by the thermal balance relationship and the task flow rate, is a variable value:
Q = Q rk - Q ы (18)
Pressure condition, namely, the pressure head in pump outlet determined by characteristic equation of pump and the flow rate in pump system inlet.
P L = 0 = AQ2 + BQ rk + c (19)
Boundary conditions of the pipeline end. The requirement of the elevation at the end point of pipeline and the remaining pressure head is as follow:
P L= L = H l (20)
The initial conditions at the starting time. The distribution of temperature field during the initial moment can be described as follow
T ( x , t ) \ x = 0 = f ( x ,0 ) (21)
Where, P is pressure in pipeline, Pa; θ is pipeline slope, rad; t is time, s; V is instantaneous velocity, m/s; g is gravitational acceleration, m/s2; x is pipeline position, m; K is overall heat transfer co-efficiency, W/(m2 • K); f is pipeline friction factor; D is external diameter, m. T in is the heated oil temperature in pipelines’ entrance, K; A,B,C is characteristic parameters in connection with centrifugal pump, dimensionless, obtained through curve fitting; H L is the sum of the elevation at the end point of pipeline and the remaining pressure head, m; Q is the starting flow rate in pipeline, m3/s; Q rk is the flow rate in pump system inlet, m3/s; Q hl is the flow back flow rate in pump outlet, m3/s; f ( x ,0) is the initial temperature field of crude oil in pipeline, C .
Then the method of characteristic (MOC) and Newton-Raphson method are utilized to obtain the numerical solution of the model. The restart pressure can be gained according to the highest pressure [14]. It’s notable that the properties of the oil are dependent on temperatures, thus the restart simulation must be on the basis of temperature calculation after shutdown.
Above all, the two models are transferred to non-linear equations which are solved by Newton-Raphson method. Consequently, large matrixes should be deal with in the computation process. As the powerful matrix manipulations of MATLAB, the iterative solving process can be realized conveniently by MATLAB.
Ш . VB and MATLAB Hybrid Programming Based on COM Technology
The powerful numerical calculation and graphics processing functions of MATLAB can be fully used by VB call MATLAB. The main methods that can be used to implement the VB and MATLAB hybrid programming are five ways: Dynamic Data Exchange (DDE), ActiveX Automation Server, Introduction of MatrixVB, Dynamic Link Library (DLL) and Component Object Module (COM) [15].
A Dynamic data exchange(DDE)
DDE is based on messages in Windows. A DDE server is a program to maintain the potential data for other Windows programs, which DDE clients get data from the server. DDE dialogue is initiated by client programs which send a message called WM-DDE-INITIATE to all the running Windows programs. This message notes the data class needed by client programs, and the DDE servers with these data will start to respond and go into a conversation. As a way of communication, DDE will not start MATLAB software. Therefore, MATLAB must be started before DDE runs, otherwise the program will not be able to run.
B Using ActiveX Control
As a new protocol for module integration, ActiveX technology from Microsoft is an extension of toolbox. After the introduction of ActiveX control into a program, it will become part of the development and run-time environments as well as providing new functions for applications. MATLAB provides an ActiveX Automation link between a VB application and MATLAB.
C Dynamic Link Library (DLL)
The program files (.M files) in MATLAB can be changed into dynamic link library (.DLL files) which can be called by VB. It can be realized in the following three ways: (1) change via MMC command in MATLAB; (2) change via the third-party plugin’s MATCOM; and (3) change in VC via the interface between Visual C++ and MATLAB. DLL files are linked to the process in the operation of a program, which can also be called by many processes simultaneously and updated easily. Flexible in application and quick in operation, the method solves the interface problem satisfactorily.
D Introduction of MatrixVB
MatrixVB is a third-party plug-in that former MathTools Corporation developed. MatrixVB can be embedded in VB using similar function and expression as MATLAB, which we can use MATLAB functions like using the functions and orders of VB. It provides more than 600 functions, including basic math calculation, powerful signal processing, linear algebra, string operation, graphics and image processing functions and so on.
E Component Object Model
A COM object is a software component that conforms to the Component Object Model. COM enforces encapsulation of the object, preventing direct access of its data and implementation. COM objects expose interfaces, which consist of properties, methods and events. A COM client is a program that makes use of COM objects. COM objects that expose functionality for use are called COM servers.
Not only the calling procedures of first two methods are complicate, but also run dependently with MATLAB. Thus the development and independent running of the software are dissatisfied. Although MatrixVB can run independently without MATLAB, the MatrixVB doesn’t have enough functions as MATLAB. Fortunately, MATLAB’s M-function files can be converted into a COM component applied in VB, which can not only take full advantages of VB and MATLAB, but also run independently without MATLAB [7-8]. This paper selects this method.
Since MATLAB 6.5, the MTALAB has provided COM Builder for users. The COM Builder can convert MATLAB program into COM component which can be called directly by VB, VC++ and many other programming languages that support COM. A COM builder interface, COM building in MATLAB and VB calling COM procedures are depicted in Fig.1 and Fig.2.

Figure 2. An interface of COM builder of MATLAB


Figure 3. Procedures of building COM object and VB call COM
W. Heated Oil Pipeline Shutdown and Restart Simulation Software Development
A Overall Design
VB mainly provides software operation functions which includes parameters and commands input and COM implements the core calculation according to the commands from VB. COM plots the calculation results automatically and returns the results to VB when the calculation is finished. Overall design of the heated oil pipeline shutdown and restart simulation software and the principle of the hybrid programming procedures are illustrated in Fig.4.

VB functions
COM functions
Figure 4. Overall design of heated oil pipeline shutdown and restart simulation software
Data exchange
Detail design of VB and MATLAB hybrid programming. With using of MATLAB 7.1, we code the heated oil pipeline shutdown and restart simulation program which is converted into COM named SRSS 1.0. In order to let the VB shell link to SRSS 1.0, we must check MWComUtil 7.1 Type Library and SRSS 1.0 Type Library in “Project - References” of VB. Then, we have added COM object reference to VB.
The program of VB call the COM is listed as follow:
Set aclass = New SRSS.SRSSclass
Call aclass.Simulation(6, H, Q, T, T11, Bk, Hmax, T0s, T00, Simt, Ko, Qds, Bv,Tas, Tst, Qfs, Djs, Hfs, Btm)
Lable 1.Caption “The software is Calculating. Please Wait… ”
If Bk >= 100 Then
Print "Fail to restart, please reinput the initial data." Else
Print "Calculation is over, please read the results »
B Detail Design
Detail of software interface. Based on the mathmatic model and software development method, we develop heated oil pipeline shutdown and restart simulation software (SRSS). The interface is developed by the MF(Multi Form) method of VB. An example of the parametes input interface is shown in Fig.5. The interface is divided into five aeras: menu area, tool buttons area, wrok area and status area.
“File” meun includes the oil properities setup, pipeline properities setup, enviroment properities setup, file save, storage, file select and software exit.
“Simulation” menu includes temperature drop calculation after shutdown and restrat simulation after certain shutdown time.
“Data” menu includes initail data output, initial data copy, results output and results copy.
“Help” includes the verison information and help file of SRSS.
The toolbar includes part of the functions which can be carried out in the menu area. The work area displays each children form of the software. The satus area displays the current location, date and time.

Figure 5. An example of software parameters input interface
End If
The programm of VB call the plot function in MATLAB as soon as calculation is over is listed as follow.
Pressure visualization program:
Set aclass = New SRSS.SRSSclass
Call aclass.PlotPressure(H, lk3)
Flowrate visualization program:
Set aclass = New SRSS.SRSSclass
Call aclass.liuliang(Q, lk2)
Currently, we can input related parameters and send calculation commands on the interface developed by VB. When the COM receives the data and commands from VB, it executes the corresponding function. The simulation results are outputted as graphics as soon as the simulation is over. Fig.6 is an example of VB call the temperature drop calculation function and plot function.

Figure 6. VB call COM of SRSS
-
V. Practical Application
A heated oil pipeline which is 100.332km in length, and its external diameter is 426mm, and wall thickness is 8mm. The oil is transported with anti-freezing agent but no insulating layer on the pipeline. This pipeline’s buried depth is 1.8 meters and the lowest environment temperature is 1 °C. The temperature drop after different shutdown time which range is 0h to 21 hour is simulated by SRSS. From the temperatures drop graphic (Fig.7), we can learn the temperatures along the pipeline at different shutdown lasting time (0 hour, 3hours, 6 hours et al).

Figure 7. Temperature drop
On the basis of temperature drop, the restart process is simulated. According to the restart pressure graphic, pressure variation at different sections of the pipeline (such as 0km, 11.5km et al) can be analyzed directly. For example, Fig.7 presents the pressure variation of different pipeline sections when the shutdown time is 9 hours.

Figure 8. Restart pressure variation at different pipeline section
The highest pressure head in Fig.8 is 698m which is the restart pressure needed. Whether the pipeline can restart successfully after a certain shutdown lasting time can be judged by comparing the highest pressure and the pipeline’s maximum operation pressure. From more calculations, we find the pipeline cannot restart successfully when the shutdown time is 24h.
The application shows hybrid programming of VB and MATLAB can combine the powerful matrixes computation and graphics process functions of MATLAB with friendly interface development function of VB. The reliability of the software would be increased with decreasing of mathematic calculation program in VB.
-
4. Conclusion
This paper establishes the shutdown and restart mathematic model of heated oil transportation on the basis of unsteady heat transfer and fluid transient flow theory.
In order to decrease the amount of algorithm program of VB, the VB and MATLAB hybrid programming method Component Object Model (COM) is selected from various hybrid methods to develop heated oil pipeline shutdown and restart simulation software (SRSS). This paper presents the overall design and detail design of SRSS. VB is mainly provides the interface and COM executes the core calculation and graphic process.
The application of SRSS shows the SRSS can simulate the temperature drop after different shutdown time and corresponding pressure variations at different pipeline sections. On the other side, the application shows powerful numerical calculation, graphic processing of MATLAB and the convenient interface development of VB can be fully used with using of VB and MATLAB hybrid programming. This software can run independently without VB and MATLAB, and the reliability of the software is enhanced.
Acknowledgement
This paper is a project supported by sub-project of National science and technology major project of China (No.2008ZX05054) and China National Petroleum Corporation ( CNPC ) tackling key subject: Research and Application of Ground Key Technical for CO2 flooding, JW10-W18-J2-11-20.
Список литературы Research of Heated Oil Pipeline Shutdown and Restart Process Based on VB and MATLAB
- E.B. Liu, C.J.Li, W.L. Jia, “Simulation of Shutdown and Restarting Process of Heated Oil Pipelines,”,The 2nd International Symposium on Information Engineering and Electronic Commerce(IEEC2010),IEEE Publisher, 23-25 July, Ternopil, Ukraine,2010.
- C.J.Li, W.L. Jia, X. Wu, “Study on Safety Technology of Shutdown and Restart Process for Waxy and High Viscosity Oil Transportation Pipeline,” 2010 International Symposium on Safety Science and Technology (ISSST2010), 26-29 October, Hangzhou, China,2010.
- Y. Peysson, A.Bensakhria, “Pipeline lubrication of heavy oil: Experimental investigation of flow and restart problems,” 2005 SPE International Thermal Operations and Heavy Oil Symposium, SPE, 1-3 November, Calgary, Canada, 2005.
- C. Li, M. Q. Qiao, “The restart pressure research of a hot waxy crude Pipeline,” OGST,vol.17,no.1, pp.1-14,1998
- H D Yang, M. Wu, “The study of axial temperature drop of shutdown on buried crude pipeline,” Journal of Petrochiemical Universities, vol.14,no.3,pp.51-56,2001
- X Liu, J. Sun, “Method of computing the maximum flow stoppage time of buried oil pipelines,” Oil and gas Hydrocarbon Spills III: Modelling, Analysis and Control,vol.11,pp.159-168,2002, Rhodes, Greece
- Nossen, J. O. Sendstad, “Restart model for gelled multiphase pipelines,” The 11th International Conference on Multiphase, BHR Group Limited, 11-13 June, San Remo, Italy, 2003.
- X. C. Yu, Q. P. Li, “Shutdown and restart transient flow characteristic study in offshore multiphase pipeline,” Journal of Engineering Thermophysics, vol.29. no.2. pp.251-255, 2008.
- L. H. Hong, J. L. Cai, “The application guide of mixed programming between MATLAB and other programming languages,” The 2nd International Conference on Computer and Automation Engineering, IEEE Publisher ,26-28 Feb. Singpore, 2010.
- X.Han, X.Xu, and Z.P. Chen,” Protection Simulation Based on Data Exchange between Matlab and VB,” Power Automation Equipment, vol.26,no.5, pp. 62 -66,2006.
- L. Li, Y.T. long, “Motor Testing Data Processing With Hybrid Programming Technology,” The 1st International Conference on Information Science and Engineering (ICISE2009),IEEE Publisher,26-28 Decmber, Nanjing, Chian, 2009.
- D. A. Zhao, T. H. Pan, “Identification of grain mildewing with ANN pattern recognition software based on VB and MATLAB,” International conference on Networking, sensing and Control, IEEE Publisher,6-8 April, Sanya, China. 2008.
- J. P. Zhang, R.T. Wang, “The system of lifetime prediction for VFD based on VB and MATLAB,” Artificial Intelligence and Computational Intelligence 2009, IEEE Publisher, 7-8 Nov. Shanghai, China,2009.
- C. J. Li, W. L. Jia, “Water Hammer Analysis for Heated Liquid Transmission Pipeline with Entrapped Gas Based on Homogeneous Flow Model and Fractional Flow Model,” 2010 Asia-Pacific Power and Energy Engineering Conference, IEEE Publisher, 28-32 March ,2010, Chengdu, China,2010 .
- C. F. Zhen, “The study and application of data visualization technology in test system,” 2010 International Conference on Computer Application and System Modeling, IEEE Publisher, 22-24 Oct. Taiyuan, China,2010.
- Y. Yu., X. W. Zhou, “Application of the COM Component to VB Calling MATLAB,” Computer Engineering & Science, vol.30, no.2. pp.110-112, 2005 (in Chinese).
- Y.Y. Jin, Z.H. Pang, and H.Cui,” Real-time monitoring system based on VB and Matlab,” Control Engineering of China, vol.12.no.2, pp150-152,2005 (in Chinese).
- X.Ren, Y.Q. Ren, and H.C. Zhu, “Control system study of dry pilverized coal pressure gasifier”, Control and Instruments in Chemical Industry, vol.37, no.2,pp.90-92, 2010(in Chinese).