This document contains code for calculating surge and swab pressures in an oil well. It takes inputs like pipe dimensions, fluid properties, flow rates, and calculates parameters like pressure losses and optimal flow rate. The code contains sections for calculating pressures at different flow rates, plotting the well dynamics, and determining the optimum hydraulic path and flow rate that balances maximum pump pressure with nozzle area and bit pressure loss.
Rudder Control Analysis / Hydraulic Pump AnalysisAndrè G. Odu
The objective of the lab is to analyze the performance of a hydraulic pump, responsible for the transfer of fluid between two tanks at a constant flow, in function of its rotational speed.
As the RPM vary from 0 to 4000 we are mainly interested in studying the speed, flow rate and pressures when entering and exiting the pump, the coefficient of head losses associated with the delivery duct, the required hydraulic power and the hydraulic power generated.
As the lab progresses, we find ourselves needing to solve the problem of cavitation that manifests itself in the aspiration duct, and are asked to calculate the plate angle of orientation when the cylinders are placed along a circumference with diameter of 60mm.
The objective of the lab is to analyze the operativity of an actuator used to control the movements of an Airbus A320 rudder.
The Airbus A320 uses three actuators with double redundancy, each of which is designed to control the mobile surface independently.
Given the opposing moment that must be overcome we can calculate the muscular force required to control the mobile surface, from which we can determine the dimensional specifics for the actuator that will be introduced, the equations of operation and the approximate time required to complete the movement.
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfmeerobertsonheyde608
Consider a 4-Link robot manipulator shown below. Use the forward kinematic D-H table and
write an m file that plots the manipulator. The instructions are given in the module 6. Submit
your solutions by the due date, in a single MATLAB m file.
Solution
Please give the kinetic D-H table else it would be difficult to code as we need to know the
rotation spin axis and other momentum of manipulator
Stating a general example code for manipulator with data
function X = fwd_kin(q,x)
% given a position in the configuration space, calculate the position of
% the end effector in the workspace for a two-link manipulator.
% q: vector of joint positions
% x: design vector (link lengths)
% X: end effector position in cartesian coordinates
% configuration space coordinates:
q1 = q(1); % theta 1
q2 = q(2); % theta 2
% manipulator parameters:
l1 = x(1); % link 1 length
l2 = x(2); % link 2 length
% calculate end effector position:
X = [l1*cos(q1) + l2*cos(q1+q2)
l1*sin(q1) + l2*sin(q1+q2)];
% SimulateTwolink.m uses inverse dynamics to simulate the torque
% trajectories required for a two-link planar robotic manipulator to follow
% a prescribed trajectory. It also computes total energy consumption. This
% code is provided as supplementary material for the paper:
%
% \'Engineering System Co-Design with Limited Plant Redesign\'
% Presented at the 8th AIAA Multidisciplinary Design Optimization
% Specialist Conference, April 2012.
%
% The paper is available from:
%
% http://systemdesign.illinois.edu/publications/All12a.pdf
%
% Here both the physical system design and control system design are
% considered simultaneously. Manipulator link length and trajectory
% specification can be specified, and torque trajectory and energy
% consumption are computed based on this input. It was found that maximum
% torque and total energy consumption calculated using inverse dynamics
% agreed closely with results calculated using feedback linearization, so
% to simplify optimization problem solution an inverse dynamics approach
% was used, which reduces the control design vector to just the trajectory
% design.
%
% In the conference paper several cases are considered, each with its own
% manipulator task, manipulator design, and trajectory design. The
% specifications for each of these five cases are provided here, and can be
% explored by changing the case number variable (cn).
%
% This code was incorporated into a larger optimization project. The code
% presented here includes only the analysis portion of the code, no
% optimization.
%
% A video illustrating the motion of each of these five cases is available
% on YouTube:
%
% http://www.youtube.com/watch?v=OR7Y9-n5SjA
%
% Author: James T. Allison, Assistant Professor, University of Illinois at
% Urbana-Champaign
% Date: 4/10/12
clear;clc
% simulation parameters:
p.dt = 0.0005; % simulation step size
tf = 2; p.tf = tf; % final time
p.ploton = 0; % turn off additional plotting capabilities
p.ploton2 = 0;
p.Tallow = 210; % maximum .
I need help understanding the Pan Tompkins algorythm, and Id also .pdfeyewatchsystems
I need help understanding the Pan Tompkins algorythm, and I\'d also like to know how to detect
QRS peaks of the ECG (with circles, for example). I\'m using the script in this website as a
guidance, but I have trouble understanding what it\'s doing. Perhaps there\'s a simpler way to do
it? http://cnx.org/contents/YR1BUs9_@1/QRS-Detection-Using-Pan-Tompki
Our teacher has otherwise explained to us FIR filters, and wants us to use them instead of the
low pass, high pass that are mentioned in the website and though I do understand how they work,
I don\'t really know which window is the best, or how many coefficients the filter needs. I\'ve
applying the cut-off frequencies 5-15 because I\'ve seen that\'s where the QRS peaks are
concentrated. Is there any way to improve this as well?
TB=1;
TBn=TB/Fs;
N2=ceil(3.3/TBn);
Fc1 =5;
Fc2 =15 ;
wc1 = 2*pi*Fc1;
wc2 = 2*pi*Fc2;
wcn1 = 2*pi*Fc1/Fs;
wcn2 = 2*pi*Fc2/Fs;
Bz=fir1(N2,[wcn1 wcn2]);
y3=filter(Bz,1,x1);
figure; plot(x1); figure; plot(y3);
Solution
Save the function and use it as given below ::
pan_tompkin(ECG1,200,1) 1st is ECG raw data , 2nd is sampling frequency, 3rd is
for plots -always set it to 1
Matlab Code ------------------------------------ function .
function [qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,fs,gr)
%% function [qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,fs)
% Complete implementation of Pan-Tompkins algorithm
%% Inputs
% ecg : raw ecg vector signal 1d signal
% fs : sampling frequency e.g. 200Hz, 400Hz and etc
% gr : flag to plot or not plot (set it 1 to have a plot or set it zero not
% to see any plots
%% Outputs
% qrs_amp_raw : amplitude of R waves amplitudes
% qrs_i_raw : index of R waves
% delay : number of samples which the signal is delayed due to the
% filtering
if ~isvector(ecg)
error(\'ecg must be a row or column vector\');
end
if nargin < 3
gr = 1; % on default the function always plots
end
ecg = ecg(:); % vectorize
%% Initialize
qrs_c =[]; %amplitude of R
qrs_i =[]; %index
SIG_LEV = 0;
nois_c =[];
nois_i =[];
delay = 0;
skip = 0; % becomes one when a T wave is detected
not_nois = 0; % it is not noise when not_nois = 1
selected_RR =[]; % Selected RR intervals
m_selected_RR = 0;
mean_RR = 0;
qrs_i_raw =[];
qrs_amp_raw=[];
ser_back = 0;
test_m = 0;
SIGL_buf = [];
NOISL_buf = [];
THRS_buf = [];
SIGL_buf1 = [];
NOISL_buf1 = [];
THRS_buf1 = [];
%% Plot differently based on filtering settings
if gr
if fs == 200
figure, ax(1)=subplot(321);plot(ecg);axis tight;title(\'Raw ECG Signal\');
else
figure, ax(1)=subplot(3,2,[1 2]);plot(ecg);axis tight;title(\'Raw ECG Signal\');
end
end
%% Noise cancelation(Filtering) % Filters (Filter in between 5-15 Hz)
if fs == 200
%% Low Pass Filter H(z) = ((1 - z^(-6))^2)/(1 - z^(-1))^2
b = [1 0 0 0 0 0 -2 0 0 0 0 0 1];
a = [1 -2 1];
h_l = filter(b,a,[1 zeros(1,12)]);
ecg_l = conv (ecg ,h_l);
ecg_l = ecg_l/ max( abs(ecg_l));
delay = 6; %based on the paper
if gr
ax(2)=subplot(322);plot(ecg_l);axis tight;title(\'Low pass filtered\');
end
%% High Pas.
Rudder Control Analysis / Hydraulic Pump AnalysisAndrè G. Odu
The objective of the lab is to analyze the performance of a hydraulic pump, responsible for the transfer of fluid between two tanks at a constant flow, in function of its rotational speed.
As the RPM vary from 0 to 4000 we are mainly interested in studying the speed, flow rate and pressures when entering and exiting the pump, the coefficient of head losses associated with the delivery duct, the required hydraulic power and the hydraulic power generated.
As the lab progresses, we find ourselves needing to solve the problem of cavitation that manifests itself in the aspiration duct, and are asked to calculate the plate angle of orientation when the cylinders are placed along a circumference with diameter of 60mm.
The objective of the lab is to analyze the operativity of an actuator used to control the movements of an Airbus A320 rudder.
The Airbus A320 uses three actuators with double redundancy, each of which is designed to control the mobile surface independently.
Given the opposing moment that must be overcome we can calculate the muscular force required to control the mobile surface, from which we can determine the dimensional specifics for the actuator that will be introduced, the equations of operation and the approximate time required to complete the movement.
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfmeerobertsonheyde608
Consider a 4-Link robot manipulator shown below. Use the forward kinematic D-H table and
write an m file that plots the manipulator. The instructions are given in the module 6. Submit
your solutions by the due date, in a single MATLAB m file.
Solution
Please give the kinetic D-H table else it would be difficult to code as we need to know the
rotation spin axis and other momentum of manipulator
Stating a general example code for manipulator with data
function X = fwd_kin(q,x)
% given a position in the configuration space, calculate the position of
% the end effector in the workspace for a two-link manipulator.
% q: vector of joint positions
% x: design vector (link lengths)
% X: end effector position in cartesian coordinates
% configuration space coordinates:
q1 = q(1); % theta 1
q2 = q(2); % theta 2
% manipulator parameters:
l1 = x(1); % link 1 length
l2 = x(2); % link 2 length
% calculate end effector position:
X = [l1*cos(q1) + l2*cos(q1+q2)
l1*sin(q1) + l2*sin(q1+q2)];
% SimulateTwolink.m uses inverse dynamics to simulate the torque
% trajectories required for a two-link planar robotic manipulator to follow
% a prescribed trajectory. It also computes total energy consumption. This
% code is provided as supplementary material for the paper:
%
% \'Engineering System Co-Design with Limited Plant Redesign\'
% Presented at the 8th AIAA Multidisciplinary Design Optimization
% Specialist Conference, April 2012.
%
% The paper is available from:
%
% http://systemdesign.illinois.edu/publications/All12a.pdf
%
% Here both the physical system design and control system design are
% considered simultaneously. Manipulator link length and trajectory
% specification can be specified, and torque trajectory and energy
% consumption are computed based on this input. It was found that maximum
% torque and total energy consumption calculated using inverse dynamics
% agreed closely with results calculated using feedback linearization, so
% to simplify optimization problem solution an inverse dynamics approach
% was used, which reduces the control design vector to just the trajectory
% design.
%
% In the conference paper several cases are considered, each with its own
% manipulator task, manipulator design, and trajectory design. The
% specifications for each of these five cases are provided here, and can be
% explored by changing the case number variable (cn).
%
% This code was incorporated into a larger optimization project. The code
% presented here includes only the analysis portion of the code, no
% optimization.
%
% A video illustrating the motion of each of these five cases is available
% on YouTube:
%
% http://www.youtube.com/watch?v=OR7Y9-n5SjA
%
% Author: James T. Allison, Assistant Professor, University of Illinois at
% Urbana-Champaign
% Date: 4/10/12
clear;clc
% simulation parameters:
p.dt = 0.0005; % simulation step size
tf = 2; p.tf = tf; % final time
p.ploton = 0; % turn off additional plotting capabilities
p.ploton2 = 0;
p.Tallow = 210; % maximum .
I need help understanding the Pan Tompkins algorythm, and Id also .pdfeyewatchsystems
I need help understanding the Pan Tompkins algorythm, and I\'d also like to know how to detect
QRS peaks of the ECG (with circles, for example). I\'m using the script in this website as a
guidance, but I have trouble understanding what it\'s doing. Perhaps there\'s a simpler way to do
it? http://cnx.org/contents/YR1BUs9_@1/QRS-Detection-Using-Pan-Tompki
Our teacher has otherwise explained to us FIR filters, and wants us to use them instead of the
low pass, high pass that are mentioned in the website and though I do understand how they work,
I don\'t really know which window is the best, or how many coefficients the filter needs. I\'ve
applying the cut-off frequencies 5-15 because I\'ve seen that\'s where the QRS peaks are
concentrated. Is there any way to improve this as well?
TB=1;
TBn=TB/Fs;
N2=ceil(3.3/TBn);
Fc1 =5;
Fc2 =15 ;
wc1 = 2*pi*Fc1;
wc2 = 2*pi*Fc2;
wcn1 = 2*pi*Fc1/Fs;
wcn2 = 2*pi*Fc2/Fs;
Bz=fir1(N2,[wcn1 wcn2]);
y3=filter(Bz,1,x1);
figure; plot(x1); figure; plot(y3);
Solution
Save the function and use it as given below ::
pan_tompkin(ECG1,200,1) 1st is ECG raw data , 2nd is sampling frequency, 3rd is
for plots -always set it to 1
Matlab Code ------------------------------------ function .
function [qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,fs,gr)
%% function [qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,fs)
% Complete implementation of Pan-Tompkins algorithm
%% Inputs
% ecg : raw ecg vector signal 1d signal
% fs : sampling frequency e.g. 200Hz, 400Hz and etc
% gr : flag to plot or not plot (set it 1 to have a plot or set it zero not
% to see any plots
%% Outputs
% qrs_amp_raw : amplitude of R waves amplitudes
% qrs_i_raw : index of R waves
% delay : number of samples which the signal is delayed due to the
% filtering
if ~isvector(ecg)
error(\'ecg must be a row or column vector\');
end
if nargin < 3
gr = 1; % on default the function always plots
end
ecg = ecg(:); % vectorize
%% Initialize
qrs_c =[]; %amplitude of R
qrs_i =[]; %index
SIG_LEV = 0;
nois_c =[];
nois_i =[];
delay = 0;
skip = 0; % becomes one when a T wave is detected
not_nois = 0; % it is not noise when not_nois = 1
selected_RR =[]; % Selected RR intervals
m_selected_RR = 0;
mean_RR = 0;
qrs_i_raw =[];
qrs_amp_raw=[];
ser_back = 0;
test_m = 0;
SIGL_buf = [];
NOISL_buf = [];
THRS_buf = [];
SIGL_buf1 = [];
NOISL_buf1 = [];
THRS_buf1 = [];
%% Plot differently based on filtering settings
if gr
if fs == 200
figure, ax(1)=subplot(321);plot(ecg);axis tight;title(\'Raw ECG Signal\');
else
figure, ax(1)=subplot(3,2,[1 2]);plot(ecg);axis tight;title(\'Raw ECG Signal\');
end
end
%% Noise cancelation(Filtering) % Filters (Filter in between 5-15 Hz)
if fs == 200
%% Low Pass Filter H(z) = ((1 - z^(-6))^2)/(1 - z^(-1))^2
b = [1 0 0 0 0 0 -2 0 0 0 0 0 1];
a = [1 -2 1];
h_l = filter(b,a,[1 zeros(1,12)]);
ecg_l = conv (ecg ,h_l);
ecg_l = ecg_l/ max( abs(ecg_l));
delay = 6; %based on the paper
if gr
ax(2)=subplot(322);plot(ecg_l);axis tight;title(\'Low pass filtered\');
end
%% High Pas.
1. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 1 of 13
% Surge/Swab Pressure Calculations Algorithm Version 1.0
%
close all
clear
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Developed by Ankit Kukreja (ankit.kukreja.89@gmail.com)
% on July 3rd, 2012
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d=2.25; % Pipe ID (inch)
d1=4; % Pipe OD (inch)
d2=6.25; % Casing ID (inch)
rho=9; % Fluid density (ppg)
L= 10000; % Depth of well (ft)
theta600=60.8; % Fann dial reading at 600 rpm
theta300=37.4; % Fann dial reading at 300 rpm
Cd=0.9697; % Discharge coefficient at nozzle
Nsize=12; % Current nozzle size
Nno=3; % Number of Nozzles currently in use
qmin = 125; % Minimum flow rate (gpm)
% Pump parameters
Ppmax=3000; % Maximum achievable pump pressure
PHP=1250; % Pump rating (Horsepower)
e=0.91; % Pump efficiency
% Enter the choice of criterion to choose
% 1 - Maximum Jet impact force
% 2 - Maximum drill bit hydraulic horsepower
% 3 - Maximum jet velocity
choice=1;
%
% Step 1 calculations
% Flow behaviour parameter, n (dimensionless)
n=3.32*log10(theta600/theta300)
% Flow behaviour parameter, K (lbf/100 ft^2)
K=510*theta300/(511^n)
% Effective area through nozzle
Aeff=(pi/4)*Nno*((Nsize/32)^2)
% Maximum possible flow (gpm)
qmax=1714*PHP*e/Ppmax
% Selection of two flow rates
q1=qmax/3 % Flow rate 1 (gpm)
q2=2*qmax/3 % Flow rate 2 (gpm)
% q1=350; % Flow rate 1 (gpm)
% q2=550; % Flow rate 2 (gpm)
%%
% Calculation of pump pressure corresponding to flow rate q1
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe1=q1/(2.448*(d^2))
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann1=q1/(2.448*((d2^2)-(d1^2)));
2. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 2 of 13
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe1=(89100*rho*(vbar_pipe1^(2-n))/K)*((0.0416*d/(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann1=(109000*rho*(vbar_ann1^(2-n))/K)*((0.0208*(d2-d1)/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC1=2000;
else
if n<0.5 && n>=0.2
log_ReC1=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC1=10^(log_ReC1);
end
end
if NRe_pipe1<ReC1
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe1=K*(vbar_pipe1^n)*(((3+(1/n))/0.0416)^n)/(144000*(d^(1+n)))
% Pump pressure, Pp
deltaPp1 = L*Lam_Pgrad_pipe1
end
if NRe_ann1<ReC1
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann1=K*(vbar_ann1^n)*(((2+(1/n))/0.0208)^n)/(144000*((d2-d1)...
^(1+n)))
end
% Calculation of friction factor of pipe, f_pipe
f_pipe1 = fsolve(@(f_pipe1)(sqrt(1/f_pipe1))-((4/(n^0.75))*log10...
(NRe_pipe1*(f_pipe1^(1-(n/2)))))+(0.395/(n^1.2)),1)
% Calculation of friction factor of annulus, f_ann
f_ann1 = fsolve(@(f_ann1)(sqrt(1/f_ann1))-((4/(n^0.75))*log10...
(NRe_ann1*(f_ann1^(1-(n/2)))))+(0.395/(n^1.2)),1)
if NRe_pipe1>=ReC1
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe1=(f_pipe1*rho*(vbar_pipe1^2))/(25.8*d)
% Pump pressure, Pp
deltaPp1 = L*Tur_Pgrad_pipe1
end
if NRe_ann1>=ReC1
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann1=(f_ann1*rho*(vbar_ann1^2))/(21.1*(d2-d1))
end
% Pressure loss at bit, deltaPb
deltaPb1=8.311*(10^(-5))*rho*(q1^2)/((Cd^2)*(Aeff^2))
%
%%
% Calculation of pump pressure corresponding to flow rate q2
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe2=q2/(2.448*(d^2))
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann2=q2/(2.448*((d2^2)-(d1^2)))
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe2=(89100*rho*(vbar_pipe2^(2-n))/K)*((0.0416*d/(3+(1/n)))^n)
% Turbulence criteria of annulus, NRe_ann
NRe_ann2=(109000*rho*(vbar_ann2^(2-n))/K)*((0.0208*(d2-d1)/(2+(1/n)))^n)
% Define critical Reynold number, ReC
3. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 3 of 13
if n<=1 && n>=0.5
ReC2=2000;
else
if n<0.5 && n>=0.2
log_ReC2=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC2=10^(log_ReC2);
end
end
if NRe_pipe2<ReC2
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe2=K*(vbar_pipe2^n)*(((3+(1/n))/0.0416)^n)/(144000*(d^(1+n)))
% Pump pressure, Pp
deltaPp2 = L*Lam_Pgrad_pipe2
end
if NRe_ann2<ReC2
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann2=K*(vbar_ann2^n)*(((2+(1/n))/0.0208)^n)/(144000*...
((d2-d1)^(1+n)))
end
% Calculation of friction factor of pipe, f_pipe
f_pipe2 = fsolve(@(f_pipe2)(sqrt(1/f_pipe2))-((4/(n^0.75))*...
log10(NRe_pipe2*(f_pipe2^(1-(n/2)))))+(0.395/(n^1.2)),1)
% Calculation of friction factor of annulus, f_ann
f_ann2 = fsolve(@(f_ann2)(sqrt(1/f_ann2))-((4/(n^0.75))*...
log10(NRe_ann2*(f_ann2^(1-(n/2)))))+(0.395/(n^1.2)),1)
if NRe_pipe2>=ReC2
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe2=(f_pipe2*rho*(vbar_pipe2^2))/(25.8*d)
% Pump pressure, Pp
deltaPp2 = L*Tur_Pgrad_pipe2
end
if NRe_ann2>=ReC2
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann2=(f_ann2*rho*(vbar_ann2^2))/(21.1*(d2-d1))
end
% Pressure loss at bit, deltaPb
deltaPb2=8.311*(10^(-5))*rho*(q2^2)/((Cd^2)*(Aeff^2))
%
%%
% Parasitic pressure loss
deltaPd1=deltaPp1-deltaPb1 % Corresponding to flow rate q1
deltaPd2=deltaPp2-deltaPb2 % Corresponding to flow rate q2
% Slope of analysis plot
m=(log10(deltaPd2/deltaPd1))/(log10(q2/q1))
%%%%%%%%%%%%%%%%% Path of optimum hydraulics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if choice==1
% For max jet impact force
deltaPd_choice=(2/(m+2))*Ppmax
end
if choice==2
% For max bit hydraulic horsepower
deltaPd_choice=(1/(m+1))*Ppmax
end
if choice==3
4. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 4 of 13
% For max jet velocity
deltaPd_choice=100
end
% Path definition
for qline=50:0.1:qmax
deltaPdline=10^(log10(deltaPd1)+m*log10(qline/q1));
plot(log10(qline),log10(deltaPdline))
hold on
if deltaPdline<=deltaPd_choice
plot(log10(qmax),log10(deltaPdline),'r')
hold on
end
if deltaPdline>=deltaPd_choice
plot(log10(qmin),log10(deltaPdline),'r')
hold on
end
if qline<=qmax && qline>=qmin
plot(log10(qline),log10(deltaPd_choice),'r')
hold on
end
plot(log10(qmin+1),log10(deltaPdline),'g')
hold on
for i=log10(100):0.1:log10(deltaPd_choice)
if log10(deltaPdline)<=log10(i+1) && log10(deltaPdline)...
>=log10(i-1) && log10(qline)<=log10(qmax+1) && ...
log10(qline)>=log10(qmax-1)
deltaPdopt=i;
qopt=qline;
end
end
if log10(deltaPdline)<=log10(deltaPd_choice+1) && ...
log10(deltaPdline)>=log10(deltaPd_choice-1) && ...
log10(qline)<log10(qmax) && log10(qline)>log10(qmin)
deltaPdopt=deltaPd_choice;
qopt=qline;
end
for k=log10(deltaPd_choice+1):0.1:log10(Ppmax)
if log10(deltaPdline)<=k+1 && log10(deltaPdline)>=k-1 && ...
log10(qline)<=log10(qmin+1) && log10(qline)>=log10(qmin-1)
deltaPdopt=k;
qopt=qline;
end
end
end
xlabel('Flow Rate (gpm)')
ylabel('Parasitic Pressure Loss(psi)')
grid on
title('Well dynamics (in blue) and optimum hydraulic path(in red and green)')
%%
% Calculation of pump pressure corresponding to flow rate qopt
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipeopt=qopt/(2.448*(d^2));
% Average velocity of annulus, vbar_ann (ft/sec)
5. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 5 of 13
vbar_annopt=qopt/(2.448*((d2^2)-(d1^2)));
% Turbulence criteria of pipe, NRe_pipe
NRe_pipeopt=(89100*rho*(vbar_pipeopt^(2-n))/K)*((0.0416*d/(3+(1/n)))^n)
% Turbulence criteria of annulus, NRe_ann
NRe_annopt=(109000*rho*(vbar_annopt^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n)
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReCopt=2000;
else
if n<0.5 && n>=0.2
log_ReCopt=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReCopt=10^(log_ReCopt);
end
end
if NRe_pipeopt<ReCopt
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipeopt=K*(vbar_pipeopt^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)))
% Pump pressure, Pp
deltaPpopt = L*Lam_Pgrad_pipeopt
end
if NRe_annopt<ReCopt
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_annopt=K*(vbar_annopt^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)))
end
% Calculation of friction factor of pipe, f_pipe
f_pipeopt = fsolve(@(f_pipeopt)(sqrt(1/f_pipeopt))-((4/(n^0.75))*...
log10(NRe_pipeopt*(f_pipeopt^(1-(n/2)))))+(0.395/(n^1.2)),1)
% Calculation of friction factor of annulus, f_ann
f_annopt = fsolve(@(f_annopt)(sqrt(1/f_annopt))-((4/(n^0.75))*...
log10(NRe_annopt*(f_annopt^(1-(n/2)))))+(0.395/(n^1.2)),1)
if NRe_pipeopt>=ReCopt
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipeopt=(f_pipeopt*rho*(vbar_pipeopt^2))/(25.8*d)
% Pump pressure, Pp
deltaPpopt = L*Tur_Pgrad_pipeopt
end
if NRe_annopt>=ReCopt
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_annopt=(f_annopt*rho*(vbar_annopt^2))/(21.1*(d2-d1))
end
% Optimum bit pressure loss
deltaPbopt=deltaPpopt-deltaPdopt
% Proper total nozzle area
Aeffopt=sqrt(8.311*(10^-5)*rho*(qopt^2)/((Cd^2)*deltaPbopt))
% Surge/Swab Pressure calculation starts from here
% surgecp = surge with closed pipe
% surgeop = surge with open pipe
% K for closed pipe is tuned to value:
6. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 6 of 13
K_cp=1.527;
% Is the pipe is moving up or down?
% Down - 1
% Up - 2
direction=2;
vp=1/3; % Tripping speed (ft/s)
if direction==1
disp('Calculating surge pressure for closed pipe..')
% For closed pipe
q_surgecp=vp*pi*(d1^2)/4;
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgecp=0;
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgecp=q_surgecp/(2.448*((d2^2)-(d1^2)))+(K_cp*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgecp=(89100*rho*(vbar_pipe_surgecp^(2-n))/K)...
*((0.0416*d/(3+(1/n)))^n)
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgecp=(109000*rho*(vbar_ann_surgecp^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n)
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgecp=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgecp=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgecp=10^(log_ReC_surgecp);
end
end
if NRe_pipe_surgecp<ReC_surgecp
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgecp=K*(vbar_pipe_surgecp^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgecp = L*Lam_Pgrad_pipe_surgecp
end
if NRe_ann_surgecp<ReC_surgecp
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgecp=K*(vbar_ann_surgecp^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgecp = L*Lam_Pgrad_ann_surgecp
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgecp = fsolve(@(f_pipe_surgecp)(sqrt(1/f_pipe_surgecp))...
-((4/(n^0.75))*log10(NRe_pipe_surgecp*(f_pipe_surgecp^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgecp = fsolve(@(f_ann_surgecp)(sqrt(1/f_ann_surgecp))-((4/(n^0.75))*...
log10(NRe_ann_surgecp*(f_ann_surgecp^(1-(n/2)))))+(0.395/(n^1.2)),1);
7. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 7 of 13
if NRe_pipe_surgecp>=ReC_surgecp
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgecp=(f_pipe_surgecp*rho*(vbar_pipe_surgecp^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgecp = L*Tur_Pgrad_pipe_surgecp
end
if NRe_ann_surgecp>=ReC_surgecp
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgecp=(f_ann_surgecp*rho*(vbar_ann_surgecp^2))/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgecp = L*Tur_Pgrad_ann_surgecp
end
disp('Calculating Equivalent Mud Weight for closed pipe..')
rho_c=rho+(231/(12*deltaPa_surgecp))
disp('Calculating surge pressure for open pipe..')
% For open pipe
K_op=1.2;
for fa=0:0.01:1
qa_surgeop=fa*vp*((pi*(d1^2)/4)-Aeffopt);
qp_surgeop=(1-fa)*vp*((pi*(d1^2)/4)-Aeffopt);
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgeop=qp_surgeop/(2.448*(d^2))+(K_op*vp);
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgeop=qa_surgeop/(2.448*((d2^2)-(d1^2)))+(K_op*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgeop=(89100*rho*(vbar_pipe_surgeop^(2-n))/K)*...
((0.0416*d/(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgeop=(109000*rho*(vbar_ann_surgeop^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgeop=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgeop=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgeop=10^(log_ReC_surgeop);
end
end
if NRe_pipe_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgeop=K*(vbar_pipe_surgeop^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgeop = L*Lam_Pgrad_pipe_surgeop;
end
if NRe_ann_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgeop=K*(vbar_ann_surgeop^n)*(((2+(1/n))/0.0208)^n)/...
8. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 8 of 13
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgeop = L*Lam_Pgrad_ann_surgeop;
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgeop = fsolve(@(f_pipe_surgeop)(sqrt(1/f_pipe_surgeop))-...
((4/(n^0.75))*log10(NRe_pipe_surgeop*(f_pipe_surgeop^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgeop = fsolve(@(f_ann_surgeop)(sqrt(1/f_ann_surgeop))...
-((4/(n^0.75))*log10(NRe_ann_surgeop*(f_ann_surgeop^(1-(n/2)))))...
+(0.395/(n^1.2)),1);
if NRe_pipe_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgeop=(f_pipe_surgeop*rho*(vbar_pipe_surgeop^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgeop = L*Tur_Pgrad_pipe_surgeop;
end
if NRe_ann_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgeop=(f_ann_surgeop*rho*(vbar_ann_surgeop^2))/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgeop = L*Tur_Pgrad_ann_surgeop;
end
if deltaPa_surgeop - deltaPp_surgeop <1
fa_final=fa;
end
end
qa_surgeop=fa_final*vp*((pi*(d1^2)/4)-Aeffopt);
qp_surgeop=(1-fa_final)*vp*((pi*(d1^2)/4)-Aeffopt);
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgeop=qp_surgeop/(2.448*(d^2))+(K_op*vp);
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgeop=qa_surgeop/(2.448*((d2^2)-(d1^2)))+(K_op*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgeop=(89100*rho*(vbar_pipe_surgeop^(2-n))/K)*...
((0.0416*d/(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgeop=(109000*rho*(vbar_ann_surgeop^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgeop=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgeop=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgeop=10^(log_ReC_surgeop);
end
end
9. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 9 of 13
if NRe_pipe_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgeop=K*(vbar_pipe_surgeop^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgeop = L*Lam_Pgrad_pipe_surgeop
end
if NRe_ann_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgeop=K*(vbar_ann_surgeop^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgeop = L*Lam_Pgrad_ann_surgeop
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgeop = fsolve(@(f_pipe_surgeop)(sqrt(1/f_pipe_surgeop))-...
((4/(n^0.75))*log10(NRe_pipe_surgeop*(f_pipe_surgeop^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgeop = fsolve(@(f_ann_surgeop)(sqrt(1/f_ann_surgeop))...
-((4/(n^0.75))*log10(NRe_ann_surgeop*(f_ann_surgeop^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
if NRe_pipe_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgeop=(f_pipe_surgeop*rho*(vbar_pipe_surgeop^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgeop = L*Tur_Pgrad_pipe_surgeop
end
if NRe_ann_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgeop=(f_ann_surgeop*rho*(vbar_ann_surgeop^2))/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgeop = L*Tur_Pgrad_ann_surgeop
end
disp('Calculating Equivalent Mud Weight for open pipe..')
rho_o=rho+(231/(12*deltaPa_surgeop))
end
if direction==2
disp('Calculating swab pressure for closed pipe..')
% For closed pipe
q_surgecp=vp*pi*(d1^2)/4;
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgecp=0;
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgecp=q_surgecp/(2.448*((d2^2)-(d1^2)))+(K_cp*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgecp=(89100*rho*(vbar_pipe_surgecp^(2-n))/K)*...
10. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 10 of 13
((0.0416*d/(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgecp=(109000*rho*(vbar_ann_surgecp^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgecp=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgecp=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgecp=10^(log_ReC_surgecp);
end
end
if NRe_pipe_surgecp<ReC_surgecp
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgecp=K*(vbar_pipe_surgecp^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgecp = L*Lam_Pgrad_pipe_surgecp
end
if NRe_ann_surgecp<ReC_surgecp
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgecp=K*(vbar_ann_surgecp^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgecp = L*Lam_Pgrad_ann_surgecp
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgecp = fsolve(@(f_pipe_surgecp)(sqrt(1/f_pipe_surgecp))-...
((4/(n^0.75))*log10(NRe_pipe_surgecp*(f_pipe_surgecp^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgecp = fsolve(@(f_ann_surgecp)(sqrt(1/f_ann_surgecp))-((4/(n^0.75))*...
log10(NRe_ann_surgecp*(f_ann_surgecp^(1-(n/2)))))+(0.395/(n^1.2)),1);
if NRe_pipe_surgecp>=ReC_surgecp
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgecp=(f_pipe_surgecp*rho*(vbar_pipe_surgecp^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgecp = L*Tur_Pgrad_pipe_surgecp
end
if NRe_ann_surgecp>=ReC_surgecp
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgecp=(f_ann_surgecp*rho*(vbar_ann_surgecp^2))...
/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgecp = L*Tur_Pgrad_ann_surgecp
end
disp('Calculating Equivalent Mud Weight for closed pipe..')
rho_c=rho-(231/(12*deltaPa_surgecp))
disp('Calculating swab pressure for open pipe..')
% For open pipe
K_op1=1.2;
K_op2=1.2;
for fa=0:0.01:1
11. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 11 of 13
qa_surgeop=fa*vp*((pi*(d1^2)/4)-Aeffopt);
qp_surgeop=(1-fa)*vp*((pi*(d1^2)/4)-Aeffopt);
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgeop=qp_surgeop/(2.448*(d^2))+(K_op1*vp);
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgeop=qa_surgeop/(2.448*((d2^2)-(d1^2)))+(K_op2*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgeop=(89100*rho*(vbar_pipe_surgeop^(2-n))/K)*((0.0416*d...
/(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgeop=(109000*rho*(vbar_ann_surgeop^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgeop=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgeop=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgeop=10^(log_ReC_surgeop);
end
end
if NRe_pipe_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgeop=K*(vbar_pipe_surgeop^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgeop = L*Lam_Pgrad_pipe_surgeop;
end
if NRe_ann_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgeop=K*(vbar_ann_surgeop^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgeop = L*Lam_Pgrad_ann_surgeop;
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgeop = fsolve(@(f_pipe_surgeop)(sqrt(1/f_pipe_surgeop))-...
((4/(n^0.75))*log10(NRe_pipe_surgeop*(f_pipe_surgeop^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgeop = fsolve(@(f_ann_surgeop)(sqrt(1/f_ann_surgeop))-...
((4/(n^0.75))*log10(NRe_ann_surgeop*(f_ann_surgeop^...
(1-(n/2)))))+(0.395/(n^1.2)),1);
if NRe_pipe_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgeop=(f_pipe_surgeop*rho*(vbar_pipe_surgeop^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgeop = L*Tur_Pgrad_pipe_surgeop;
end
if NRe_ann_surgeop>=ReC_surgeop
12. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 12 of 13
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgeop=(f_ann_surgeop*rho*(vbar_ann_surgeop^2))/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgeop = L*Tur_Pgrad_ann_surgeop;
end
if deltaPa_surgeop - deltaPp_surgeop <1
fa_final=fa;
end
end
qa_surgeop=fa_final*vp*((pi*(d1^2)/4)-Aeffopt);
qp_surgeop=(1-fa_final)*vp*((pi*(d1^2)/4)-Aeffopt);
% Average velocity of pipe, vbar_pipe (ft/sec)
vbar_pipe_surgeop=qp_surgeop/(2.448*(d^2))+(K_op1*vp);
% Average velocity of annulus, vbar_ann (ft/sec)
vbar_ann_surgeop=qa_surgeop/(2.448*((d2^2)-(d1^2)))+(K_op2*vp);
% Turbulence criteria of pipe, NRe_pipe
NRe_pipe_surgeop=(89100*rho*(vbar_pipe_surgeop^(2-n))/K)*((0.0416*d/...
(3+(1/n)))^n);
% Turbulence criteria of annulus, NRe_ann
NRe_ann_surgeop=(109000*rho*(vbar_ann_surgeop^(2-n))/K)*((0.0208*(d2-d1)...
/(2+(1/n)))^n);
% Define critical Reynold number, ReC
if n<=1 && n>=0.5
ReC_surgeop=2000;
else
if n<0.5 && n>=0.2
log_ReC_surgeop=((0.5-n)*(log10(2.1))/0.3)+log10(2000);
ReC_surgeop=10^(log_ReC_surgeop);
end
end
if NRe_pipe_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of pipe
Lam_Pgrad_pipe_surgeop=K*(vbar_pipe_surgeop^n)*(((3+(1/n))/0.0416)^n)...
/(144000*(d^(1+n)));
% Pump pressure, Pp
deltaPp_surgeop = L*Lam_Pgrad_pipe_surgeop
end
if NRe_ann_surgeop<ReC_surgeop
% If flow is laminar, frictional pressure loss gradient of annulus
Lam_Pgrad_ann_surgeop=K*(vbar_ann_surgeop^n)*(((2+(1/n))/0.0208)^n)/...
(144000*((d2-d1)^(1+n)));
% Annular pressure, Pa
deltaPa_surgeop = L*Lam_Pgrad_ann_surgeop
end
% Calculation of friction factor of pipe, f_pipe
f_pipe_surgeop = fsolve(@(f_pipe_surgeop)(sqrt(1/f_pipe_surgeop))-...
((4/(n^0.75))*log10(NRe_pipe_surgeop*(f_pipe_surgeop^(1-(n/2)))))...
+(0.395/(n^1.2)),1);
% Calculation of friction factor of annulus, f_ann
f_ann_surgeop = fsolve(@(f_ann_surgeop)(sqrt(1/f_ann_surgeop))-...
((4/(n^0.75))*log10(NRe_ann_surgeop*(f_ann_surgeop^(1-(n/2)))))...
+(0.395/(n^1.2)),1);
13. 7/3/12 2:53 PM C:UserskukrejankitDesktopCoursestribologys...code2.m 13 of 13
if NRe_pipe_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of pipe
Tur_Pgrad_pipe_surgeop=(f_pipe_surgeop*rho*(vbar_pipe_surgeop^2))/(25.8*d);
% Pump pressure, Pp
deltaPp_surgeop = L*Tur_Pgrad_pipe_surgeop
end
if NRe_ann_surgeop>=ReC_surgeop
% If flow is turbulent, frictional pressure loss gradient of annulus
Tur_Pgrad_ann_surgeop=(f_ann_surgeop*rho*(vbar_ann_surgeop^2))/(21.1*(d2-d1));
% Annular pressure, Pa
deltaPa_surgeop = L*Tur_Pgrad_ann_surgeop
end
disp('Calculating Equivalent Mud Weight for open pipe..')
rho_o=rho-(231/(12*deltaPa_surgeop))
end
% End of code