Engineering thermodynamics/Steam tables/Superheated (small)/Generating code
Jump to navigation
Jump to search
The Excel spreadsheet Parameters.xlsx, as well as two Matlab files (XSteam.m, TableGraphmaker.m) must be placed in a folder. Run TableGraphmaker.m to generate the table and figures. The first row of Parameters.xlsx contains the pressures (bars). Each column (after the first row) contains the temperatures (Celsius) for that column.
Click to view or hide the codes and tables
Parameters.xlsx[edit | edit source]
This spreadsheet is used to generate the table (not the actual pressures and temperatures used)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
TableGraphMaker.m[edit | edit source]
creates the graphs and the wikitext for the tables.
|
---|
clear all;close all;clc;
% On 4/16/2015 I changed tempfix from .09 to .001
tempfix = .001;%tempfix = .09; %ideal is zero. This is added to T so that T critical calculates parameters
presfix=.000001; %added so that pressure is above critical
Tmin =200; Tmax=500; %Is this needed?
Tphase = linspace(Tmin,373.9,500);
linewidth=1.2; markersize = 5;
% This makes a T_versus_s plot
% There are two user selected paramters that often seemed necessary. Make
% them as small as possible. The problem is that calling XSteam at a
% saturation value sometimes yields odd results.
%These cell arrays are used to call the various state variables
Call ={'v_pT', 'u_pT','h_pT','s_pT' };
%Label ={'v (m^3/kg)', 'u (kJ/kg)','h (kJ/kg)','s(kJ/kg)','T (°C)', 'p (bars)' };
Label ={'v', 'u','h','s','°C','bars' };
plotcall ={'v_pT', 'u_pT','h_pT','s_pT' };
phasecall ={'vL_T','uL_T','hL_T','sL_T'}; %For liquid-gas phase
phasecallG ={'vV_T','uV_T','hV_T','sV_T'}; %For liquid-gas phase
sigfigs = '%10.2E'; %Use '%10.3E' for big table and '%10.3E' for compact table.
%Here are some paramters we don't seem to need: %Rwater=461.526/100000; %Tcritical = 374; %Pcritical = 220.6395 %bar
%% Read parameters and replace NAN by -1
parameters= xlsread('parameters.xlsx'); %Omit saturation temperatures or they will be repeated
[NTfirst,Np]=size(parameters);
for nT=1:NTfirst %Fills non numbers with -1
for np=1:Np
if isnan( parameters(nT,np) )==1 % i.e., we are above saturation pressure '
parameters(nT,np)=-1;
end
end
end
% Define p as pressure array
p=parameters(1,:); %Defines p;
%% fill the first row of parameters with saturation temperatures, when they exist
% Also, define T: T(1) is large to ensure evaluation by XSteam, so we must
% subtract tempfix everytime we print the saturation temperature.
for np = 1:Np
if isnan( XSteam('Tsat_p',p(np)) )==0 % if Tsat exists
parameters(1,np)=XSteam('Tsat_p',p(np))+tempfix;%added tempfix to ensure return%
else parameters(1,np)=-1;
end
end
%% Make wikitable header
fout=fopen('wikitable.txt', 'w+');% creates wikitext
for np=1:Np
T=parameters(:,np); %need to define the temperatures after
stringp=num2str(p(np),'%10.0f'); % is the pressure Changed to float4/17/2015
if T(1)>0
stringT = num2str(T(1)-tempfix,'%10.0f'); % is the saturation temperature
%On 4/16/2015 the precision was changed from 10.1f to the above
%10.0f for saturation temperatures.
commentInHeader{np} = [' bars (T<sub>sat</sub> = ',stringT,' °C)===='];
belowCrit=true;
else %above critical pressure
belowCrit=false;
commentInHeader{np} = ' bars (above critical)====';
end
fprintf(fout,'%s\n',['====P = ',stringp,commentInHeader{np}]);
%fprintf(fout,'%s\n','{| class="wikitable" style="text-align:center; width:600px;" ');
fprintf(fout,'%s\n','{| class="wikitable" style="text-align:center; " ');
fprintf(fout,'%s\n','|-');
% fprintf(fout,'%s\n',['|',' ','||', ' ', '||', ' ', '||' ,' ', '||', stringp ]);fprintf(fout,'%s\n','|-');
string = ['|', Label{5}, '||' , Label{1}, '||', Label{2}, '||', Label{3}, '||', Label{4} ];
fprintf(fout,'%s\n',string);
%% print entries
for nT = 1:NTfirst
printline=0;
if nT==1 && T(nT)>0, printline=1; end;
if nT>1 && T(nT)>T(1), printline=1; end;
if printline==1
stringT = num2str(T(nT),'%10.0f');
if nT==1 stringT='Sat'; end;
stringv = num2str(XSteam('v_pT',p(np), T(nT)),sigfigs);
stringu = num2str(XSteam('u_pT', p(np), T(nT)),sigfigs);
stringh = num2str(XSteam('h_pT', p(np), T(nT)),sigfigs);
strings = num2str(XSteam('s_pT', p(np), T(nT)),sigfigs);
fprintf(fout,'%s\n','|-');
fprintf(fout,'%s\n',['|',stringT,'||', stringv, '||', stringu, '||' ,stringh, '||', strings ]);
if nT==1
T(nT)=T(nT)+tempfix; %restore, just in case
end
end
end
fprintf(fout,'%s\n','|}');
end
fclose(fout);
%%
for count=1:4 %try this breakup
what2plot = plotcall{count};
for np=1:Np %create Tplot and Xplot
clear Tplot Xplot; %and build up the temperatures for a contour
T=parameters(:,np);
%plotthis=0;
firstplot=1; %default values
for nT = 1:NTfirst %begin search of a point worth plotting
if T(nT)>=T(1),
% plothis=1;
if firstplot==1 %first element in both arrays
Xplot = XSteam(plotcall{count}, p(np), T(nT) );
Tplot =T(nT);
firstplot = 0; %on next iteration do the following else
else
Xnext = XSteam(plotcall{count}, p(np), T(nT) );
Tnext =T(nT);
Xplot = [Xplot,Xnext];
Tplot = [Tplot,Tnext];
end %if firstplot==1 xxx else xxx
end %if plotthis
end; %for nT
%%Make one countour of the subplot
subplot(2,2,count);
if np == 1
plot(Xplot,Tplot,':','LineWidth',linewidth)
else
plot(Xplot,Tplot,'-o','LineWidth',linewidth,'MarkerSize',markersize)
end
hold on; %Go to the next countour
end %for np % we are done with all the countours
% Add Liquid and Gas phase transition
for n = 1:size(Tphase,2)
Xphase(n) = XSteam(phasecall{count},Tphase(n) );
end
for n = 1:size(Tphase,2)
XphaseG(n) = XSteam(phasecallG{count},Tphase(n));
end
plot(Xphase,Tphase,'r', 'Linewidth',linewidth)
plot(XphaseG,Tphase,'m','Linewidth',linewidth)
xlabel(Label{count});
ylabel(['T=Temperature ( ^{\circ}C)']);
if count==1 xlim([0 .1]); else xlim auto; end;
ylim([Tmin Tmax+1]);
hold off;
end %for count
|
LongTableMaker.m=[edit | edit source]
creates the table in a single column
|
---|
%LongTableMaker creates the table in a single column
clear all;close all;clc;
%don't need: %Rwater=461.526/100000; %Tcritical = 374; %Pcritical = 220.6395 %bar
tempfix = .001; %ideal is zero. This is added to T so that T critical calculates parameters
presfix=.000001; %added so that pressure is above critical
sigfigs = '%10.2E'; %Use '%10.3E' for big table and '%10.3E' for compact table.
%% Read parameters and replace NAN by -1
parameters= xlsread('parameters.xlsx'); %saturation temperatures absent
[NTfirst,Np]=size(parameters);
for nT=1:NTfirst %Fills non numbers with -1
for np=1:Np
if isnan( parameters(nT,np) )==1 % i.e., we are above saturation pressure '
parameters(nT,np)=-1;
end
end
end
% Define p as pressure array
p=parameters(1,:); %Defines p;
%% fill the first row of parameters with saturation temperatures, when they exist
% Also, define T: T(1) is made slightly large to ensure evaluation by XSteam, so we must
% subtract tempfix everytime we print the saturation temperature.
count=1;
for np = 1:Np
if isnan( XSteam('Tsat_p',p(np)) )==0 % if Tsat exists
temp=XSteam('Tsat_p',p(np))+tempfix ;%added tempfix to ensure return%
parameters(1,np)= temp; % changed from str2num(sprintf('%.1f',temp))
%with above change the saturation temperature is a float
else parameters(1,np)=-1;
end
for nT = 1:NTfirst
T = parameters(:,np);
printline=0;
if nT==1 && T(nT)>0, printline=1; end;
if nT>1 && T(nT)>T(1), printline=1; end;
if printline==1
if T(nT)>0 %we have a value of T that we want to keep
stringT = num2str(T(1)-tempfix,'%10.0f');
longtable{count,1} = num2str(p(np),'%10.0f');
longtable{count,2} = num2str(T(nT),'%10.0f');
longtable{count,3}= num2str(XSteam('v_pT',p(np), T(nT)),sigfigs) ;
longtable{count,4}= num2str(XSteam('u_pT', p(np), T(nT)),sigfigs);
longtable{count,5}= num2str(XSteam('h_pT', p(np), T(nT)),sigfigs);
longtable{count,6}= num2str(XSteam('s_pT', p(np), T(nT)),sigfigs);
count = count + 1;
end
end
end
end
endcount=count-1;
|