The Inner Workings of grcalc.m

function
Gr=grcalc(B,T1,T2,index)

% Grashof number calculator for low density fluids
%
% function Gr = grcalc(B,T1,T2,index)
%
% Argument List:
% B [=] distance between regions of high T and low T, in meters
% T1,T2 [=] high and low temperature (order and units does not matter)
% index [=] index of compounds in cnms whose Gr are to be found
% (If this argument is omitted, all Gr numbers will be found.)
% Returns:
% Gr [=] unitless Gr number
%
% Ex: >> start301 (specify new session, E&M balances, ceng301 data base,
% K as temp, 1 compound: air)
% >> grcalc(1,298,350)
%ans =
% 1.9066e+07 Created April, 2005 by William Hoy, Taryn Roos


global
lrho cnms
format
short e

%determine the index assignments for a group of compounds
if
nargin==3
[nrow ncol]=size(cnms);
index=1:nrow;

end

%create initial values for variables
T1=at(T1); %convert to K
T2=at(T2);
filmT=.5*(T1+T2);
%film Temp
deltaT=abs(T1-T2); %change in temp over diffusional effect
Bbar=1/filmT; %coefficient of volume expansion from mean T
mu=mucalc(filmT,index); %mu from mucalc at mean T
g=9.80665; %gravitational constant, m/s^2

%compute rho values
rho=newrho(lrho,filmT,cnms,index);

%calculate and display Gr
Gr=(B^3*rho'.^2*deltaT*Bbar*g)./(mu.^2);

%This subfunction creates a linear relationship between the rho values
%given in the 301 database to extrapolate rho to any given temperature
%Also, it serves as a data checker for lrho in the database, returning
%error messages for missing values of rho
%input: lrho - automatically assigned by start301
%T - temperature of interest, automatically assigned in grcalc

function
rhocalc=newrho(lrho,T,cnms,index);

%stopgap air and water rho polynomials
AirP=[-3.568287e-8 4.527177654e-5 -.02146674838198 4.50618243631803]; %air polynomial rho
WaterP=[1.3469907e-5 -1.6687151736e-2 6.113507290203 300.648492221842]; %water polynomial rho
rhocalc=zeros(1,length(index));

for
i=index
%check for air or water for polynomial correlation
if
strcmp(cnms(i,1:3),'air')==1
rhocalc(i)=polyval(AirP,T);

continue

elseif
strcmp(cnms(i,1:5),'water')==1
rhocalc(i)=polyval(WaterP,T);

continue

%check for non-existance of rho data
elseif
isnan(lrho(i,1))==1
disp(['No rho value exists for ',cnms(i,:)])
rhocheck=input('Please input one, or press Enter for 0. ');

if
isempty(rhocheck)==1
rhocalc(i)=NaN;

else
rhocalc(i)=rhocheck;
end
continue

%check for single rho entry
elseif
isnan(lrho(i,2))==1
rhocalc(i)=lrho(i,1);
disp(['Rho data for ',cnms(i,:),' taken at: ',num2str(lrho(i,3)),...
'K'])

continue

%create a linear function for two entries
else
slp=((lrho(i,4)-lrho(i,3))/(lrho(i,2)-lrho(i,1)));
rhocalc(i)=slp*(T-lrho(i,3))+lrho(i,1);

end
end

Home