clear
clc
Pr = 250
Pb = 240
Pwh = 30
pump = 0
Pp = 10
PandR = 0
Pplace = 300
GORS = 100;
g = 9.81;
Lh = 1000;
Lv = 2000;
Lp = 2000;
Lr = 300;
Dl = 10;
K = 1.3e-3;
Rol = 800;
Rog0 = 1.5;
Myl = 2e-3;
Nyg = 2e-5;
Dhor = 0.15;
Dver = 0.20;
Dpip = Dver;
Dris = Dver;
angleh = 0;
anglev = pi/2;
anglep = 0;
angler = pi/2;
sig = 30;
Pwiguess = Pr-15;
Pwi(1) = Pwiguess;
DT = 30;
if PandR ==1
Ltot = Lh+Lv+Lp+Lr;
else
Ltot = Lh+Lv;
end
Perfor = linspace(0,800,5);
Nper = length(Perfor);
Nhor = 1+Lh/Dl;
Nver = Lv/Dl;
Npip = Lp/Dl;
Nris = Lr/Dl;
Ntot = Nhor+Nver;
if PandR == 1
Ntot = Ntot+Npip+Nris;
end
Kxi = zeros(1,Ntot);
noit = 1;
ac = 0.0001;
error(1) = 1;
while abs(error(noit)) > ac
Pwi(1) = Pwi(1) - 0.1*error(noit);
noit = noit + 1;
for j = 1:Nhor
Lpos(j) = (j-1)*Dl;
for iper = 1:Nper
if Lpos(j) == Perfor(iper)
Kxi(j) = K;
end
end
end
for k = 1:Ntot
if k <= Nhor
angle(k) = angleh;
D(k) = Dhor;
elseif k > Nhor && k <= Nver
angle(k) = anglev;
D(k) =Dver;
elseif k > Nver && k <= Npip
angle(k) = anglep;
D(k) = Dpip;
else
angle(k) = angler;
D(k) = Dris;
end
end
Mtot = 0;
for i = 1:Ntot
if Kxi(i) > 0
if Pwi(i) > Pb
Minn = Rol*K*(Pr-Pwi(i));
else
Pvogel = Pwi(i);
Minn = vogel(Pvogel,K,Pr,Pb,Rol);
end
Mtot = Mtot+Minn;
end
kcem = 0.42;
ks = 26;
kesa = 1.06;
kesh = 0.7;
ko = 0.08;
Cpo = 0.65;
alphasa = 0.04;
alphash = 0.02;
Tinitial = 277.15+DT*Lv*10^(-3);
rto = 2.75;
rti= 2.446;
rw = 4;
gG1 = 0.0083;
gG2 = 0.015;
hdi = 2.45;
TVD = 2000;
depthi = 1800;
depthsa = 200;
t = 24*365*12;
rohw = 62.4;
So = Rol/1000;
MinnFU = Minn*2.2046;
myoFU = exp(7.296*(((So)^3)-3.095));
myo = myoFU*(((10^(-3))*2.2046)/(0.3048^(-1)));
tdwsa = (alphasa*t)/(rw^2);
tdwsh = (alphash*t)/(rw^2);
if tdwsa <= 1.5
ftsa = 1.1281*sqrt(tdwsa)*(1-0.3*sqrt(tdwsa));
else
ftsa = 0.4063+0.5*log(tdwsa)*(1+(0.6/tdwsa));
end
if tdwsh <= 1.5
ftsh = 1.1281*sqrt(tdwsh)*(1-0.3*sqrt(tdwsh));
else
ftsh = 0.4063+0.5*log(tdwsh)*(1+(0.6/tdwsh));
end
Nnu = 0.023*(((rohw*So*2*rti)/myo)^0.8)*((3600*Cpo*myo)/ko)^(1/3);
hf = (Nnu*2*rti)/ko;
if i < 130
Uo = ((rto/(rti*hf))+((rto*log(rto/rti))/ks)+((rto*log(rw/rto))/kcem)+(rto*ftsa)/kesa)^(-1);
else
Uo = ((rto/(rti*hf))+((rto*log(rto/rti))/ks)+((rto*log(rw/rto))/kcem)+(rto*ftsh)/kesh)^(-1);
end
A = (MinnFU*Cpo)/(pi*2*rto*Uo);
Tei(1) = (Tinitial-273.15)*9/5 + 32;
Tf(1) = (Tinitial-273.15)*9/5 + 32;
Tei(i+1) = Tei(i)-gG1*Dl*sin(angle(i));
if i < 131
Tf(i+1) = Tei(i)-gG1*Dl*sin(angle(i))+(Tf(i)-Tei(i))*exp(-Dl/A)+ gG1*sin(angle(i))*A*(1-(exp(-Dl/A)));
else
Tf(i+1) = Tei(i)-gG2*Dl*sin(angle(i))+(Tf(i)-Tei(i))*exp(-Dl/A)+ gG2*sin(angle(i))*A*(1-(exp(-Dl/A)));
end
T(i) = (Tf(i)-32)*5/9+273.15;
z = 1;
C = (Rog0*298.15);
Rog(i) = (Pwi(i)*C)/(z*T(i));
GOR(i) = GORS+10^-7+((GORS*(Pwh-Pwi(i))/(Pwi(1)-Pwh)));
Gfrak(i) = (1+Rol/(Rog(i)*GOR(i)))^(-1);
if Pwi(i) > Pb
Rom = Rol;
Mym = Myl;
Ulsi(i) = Mtot/(Rol*(pi*D(i)^2/4));
Umix = Ulsi(i);
Epsgi(i) = 0;
Gfrak(i) = 0;
Reyn = Rom*Umix*Dhor/Mym;
Frik = 0.046*Reyn^(-0.2);
Dpdxf = (4/Dhor)*Frik*.5*Rom*Umix^2;
Pwi(i+1) = Pwi(i) - Dpdxf*Dl*1e-5;
else
Mgi(i) = Gfrak(i)*Mtot;
Mli(i) = Mtot-Mgi(i);
Ugsi(i) = Mgi(i)/(Rog(i)*(pi*D(i)^2/4));
Ulsi(i) = Mli(i)/(Rol*(pi*D(i)^2/4));
Myg = Nyg*Rog(i);
Umix = Ulsi(i)+Ugsi(i);
Epsgi(i) = Ugsi(i)/Umix;
Pwi(i+1) = Pwi(i) - bb(Ulsi(i),Ugsi(i),Rol,Rog,Myl,Myg,sig,D(i),angle(i),g,Pwi(i),Dl)*1e-5;
if pump == 1 && i == Pplace
Pwi(i+1) = Pwi(i+1) + Pp;
end
end
end
Pwhout = Pwi(Ntot)
error(noit) = (Pwhout-Pwh)/(Pwh);
Mtot
figure(1)
subplot(3,1,1); plot(linspace(0,(Ltot),length(Pwi)),Pwi,'k-')
title('Pressure vs. Position')
ylabel('Pressure [bar]')
xlabel('Position from toe [m]')
subplot(3,1,2); plot(linspace(0,(Ltot),length(Epsgi)),Epsgi,'k-')
title('Epsgi')
ylabel('Fraction')
xlabel('Position from toe [m]')
subplot(3,1,3); plot(linspace(0,noit,noit),error,'k-')
ylabel('Error')
xlabel('Iterations')
drawnow
end