%PARCIAL 2-4, PROBLEMA 1
clear all
clc

%Datos
Ntu=226;
Nt=2*Ntu;
Do=0.75*0.0254; %[m]
Di=0.62; %[m]
Lt=4.9; %[m]

Mo=30000; %[kg/h] Melp
Pep=3; %[bara]
Tep=110; %[°C]
Msvo=20500; %[kg/h]
deltaHvapo=720000; %[J/kg]
A=4.02023;
B=1263.909;
C=216.432;
klo=0.15; %[W/(m °C)]
Cplo=1840; %[J/(kg °C)]
vislo=0.2*10^(-3); %[Pa s]
denlo=869.6; %[kg/m^3]
denvo=1.3; %[kg/m^3]
teno=0.068; %[N/m]

Tser=160; %[°C]
Tss=155; %[°C]
hi=10000; %[W/(m^2 K)]
Cpser=5684; %[J/(kg °C)]

%INCISO A
Tsat=B/(A-log10(Pep))-C; %[°C]
%Userviciom
QI=Mo*Cplo*(Tsat-Tep) %[J/h]
x=Msvo/Mo 
QII=x*Mo*deltaHvapo %[J/h]
QT=QI+QII %[J/h]
Mser=QT/(Cpser*(Tser-Tss))
Tx=QI/(Mser*Cpser)+Tss
deltaTmlI=(Tss-Tep-(Tx-Tsat))/log((Tss-Tep)/(Tx-Tsat))
deltaTmlII=(Tx-Tsat-(Tser-Tsat))/log((Tx-Tsat)/(Tser-Tsat))

deltaTm=((1/QT)*(QI/deltaTmlI+QII/deltaTmlII))^(-1)
Adisp=pi*Do*Nt*Lt
Userviciom=QT/(Adisp*deltaTm*60^2) %[W/(m^2 K)]
%Ulimpiom
Db=25.375*0.0254; %[m]
fi=pi*Db*Lt/Adisp
Fb=1+0.1*((1-fi)/fi)^0.75
E=0.00122*Fb*((klo^0.79*Cplo^0.45*denlo^0.49)/(teno^0.5*vislo^0.29*(deltaHvapo*denvo)^0.24))
Tserm=(Tser+Tx)/2
Tw(1)=150; %valor inicial}
for i=1:10
    Pw(i,1)=10^(A-B./(Tw(i)+C)); %[bar]
    hoII(i,1)=E.*((Tw(i)-Tsat).^0.24)*(((Pw(i)-Pep).*100000).^0.75);
    Cc(i,1)=Do.*hoII(i)./(Di*hi);
    Twnuevo(i,1)=(Cc(i).*Tsat+Tserm)./(1+Cc(i));
    er=abs(Twnuevo(i)-Tw(i))./Tw(i)*100;
    if er<0.1
        break
    end
    Tw(i+1,1)=Twnuevo(i);
end
Resultados_iteracion=table(Tw,Pw,hoII,Cc,Twnuevo)
hoII=hoII(end);
q=QII/(60^2*Adisp) 
qcrit=0.131*deltaHvapo*(teno*(denlo-denvo)*9.81*denvo^2)^0.25
Ulimpiom=(Do/(hi*Di)+1/hoII)^(-1)
Rf=1/Userviciom-1/Ulimpiom

%INCISO B
QTlimpio=Adisp*Ulimpiom*deltaTm
QT=(Mo*deltaHvapo+Mo*Cplo*(Tsat-Tep))/60^2
x=(Adisp*Ulimpiom*deltaTm-Mo*Cplo*(Tsat-Tep)/60^2)/(Mo*deltaHvapo/60^2)


