Monday, February 25, 2019

Shortened Water from Air code

T1 is the temperature of the surrounding air in deg C, RH1 is the relative humidity in percent, P1 is the atmospheric pressure in kPa (at sea level it is about 101.325 kPa), T2 is the temperature to which the air will be cooled, V1 is the volume of air you are going to cool in cubic metres. Code below:

label 1;
var
EnthV1MWh,EnthV1kWh,EnthV1,NokgdaV1,Enthd,Psatw1,Psatw2,Tk1,Tk2,Mvpa1,Enth1,Enth2,Ma1,Mv1,HR1,HR2,
Pv1,PV2,T1,RH1,P1,P2,T2,V1,kgDryAir,EdpkgDA,EnthDV,HR1mHR2,HR1mHR2V,kgpkWh,Td,RH,Psat,Pv,Tdew:extended;
errors1:boolean;
calcstr2,calcstr1,calcstr3,calcstr4,calcstr5,calcstr6,calcstr7,
calcstr8,calcstr9,calcstr10,calcstr11,calcstr12,calcstr13,calcstr14,
calcstr15,calcstr16,calcstr17,calcstr18:string[30];
begin
errors1:=false;
form3.hide;
form3.show;
try
T1:=strtofloat(form3.edit1.Text);
RH1:=strtofloat(form3.edit2.Text);
P1:=strtofloat(form3.edit3.Text);
T2:=strtofloat(form3.edit4.Text);
V1:=strtofloat(form3.edit5.Text);
except
errors1:=true;
end;
if (errors1=true) or
(T1<1) or (T1>60) or (RH1<=0) or (RH1>100) or (P1<20) or (P1>120) or (T2<1) or
(T2>60) or (V1<0)
then begin
form3.canvas.textout(0,100,'CHECK ENTRIES.');
goto 1
end;
Tk1:=T1+273.15;
Tk2:=T2+273.15;

Td:=T1;
RH:=RH1;
Psat:=0.61121*exp((18.678-Td/234.5)*Td/(257.14+Td));
Pv:=(RH/100)*Psat;
Tdew:=Td;
repeat
Tdew:=Tdew-0.001;
Psat:=0.61121*exp((18.678-Tdew/234.5)*Tdew/(257.14+Tdew));
until (Psat<=Pv);
str(Tdew:12:2,calcstr18);


Psatw1:=0.61121*exp((18.678-T1/234.5)*T1/(257.14+T1));
Pv1:=Psatw1*RH1/100;
HR1:=0.622*Pv1/(P1-Pv1);
Ma1:=(P1-Pv1)/(0.287*Tk1);
Enth1:=(1.005*T1)+HR1*(2501.3+1.82*T1);
Psatw2:=0.61121*exp((18.678-T2/234.5)*T2/(257.14+T2));
HR2:=Hr1;
P2:=P1;
if (Psatw2<PV1) then begin
Pv2:=Psatw2;
HR2:=0.622*Pv2/(P2-Pv2);
form3.canvas.textout(0,120,'Water condenses out. Dew point is:'+calcstr18+' deg C');
end;
Enth2:=(1.005*T2)+HR2*(2501.3+1.82*T2);
kgDryAir:=V1*Ma1;
EdpkgDA:=(Enth2-Enth1);
EnthDV:=kgDryAir*EdpkgDA;
HR1mHR2:=HR1-HR2;
HR1mHR2V:=kgDryAir*HR1mHR2;
kgpkWh:=(-1)*HR1mHR2V/(EnthDV/3600);
str((EnthDV/3600),calcstr7);
str(HR1mHR2V,calcstr10);
str(kgpkWh:13:4,calcstr17);
form3.canvas.textout(0,150,'Total mass of water condensing out of the air is: '+calcstr10+' kg.');
form3.canvas.textout(0,180,'Total heat added to the air is: '+calcstr7+' kWh.');
form3.canvas.textout(0,210,'Number of kg of water produced per kWh of heat removed from air: '+calcstr17+' kg/kWh.');
form3.canvas.textout(0,240,'Dew point temperature is: '+calcstr18+' deg C.');
1: end;

4 comments:

  1. For your solution to be accepted, surely you must detail the approximation method you use? For example I can see it is not August Roche Magnus

    ReplyDelete
  2. Might I suggest that you put the code as functions rather than a slab? The art of code is re-use.
    If you for example take out the DewP calculation you could make it a function, passing it only the RH and T and it will return the DewP, makes elegant and also re-usable, essential for correct code.
    Also, you really should say you are using Buck Equation to calculate DewP

    ReplyDelete
    Replies
    1. The Buck equation is a well known equation and anyone looking for equations for vapour pressure is likely to find it at Wikipedia, etc

      Delete
  3. This comment has been removed by the author.

    ReplyDelete