THEORY: The official record of thermodynamic values at different temperatures has been stored by NASA in the form of polynomials with specified constants ranging from one to fourteen for various species. In order to quantify the values, the polynomials can be solved with defined temperature values in accordance with our requirements.
The term ‘parsing’ refers to MATLAB reading an m-file (script or function) and translating it into an internal code that it stores in memory. It is this ‘parsed’ file in memory that is actually run when you execute the code.
GOVERNING EQUATIONS:
·SPECIFIC HEAT – C_P/R=a1+a2×T+a3×T^2+a4×T^3+a5×T^4CP/R=a1+a2×T+a3×T2+a4×T3+a5×T4
.ENTHALPY –
H/RT= a1+a2×T/2+a3×T^2/3+a4×T^3/4+a5×T^4/5+a6/TH/RT=a1+a2×T/2+a3×T2/3+a4×T3/4+a5×T4/5+a6/T
.ENTROPY –
S/R=a1×logT+a2×T+a3×T^2/2+a4×T^3/3+a5×T^4/4+a7S/R=a1×lnT+a2×T+a3×T2/2+a4×T3/3+a5×T4/4+a7
where,
CP = Specific Heat
H = Enthalpy
S = Entropy
R = Universal Gas Constant (8.314 J/mol.K)
T = Temperature
* The First 7 Coefficients are High Temperature Coefficients and the Second 7 Coefficients are Low Temperature Coefficients.
EXPLANATION OF PROGRAM:
·Initially, a code is written to read the desired data file and values are assigned. Here, comments and other data is read using respective commands.
·The coefficient values are determined and allotted to a constant.
·A new folder with the name ‘SPECIES’ is created to desired location. The coefficient function is called and plotting of graphs is carried out.
·Plots are saved in the specified folder and the process of determining molecular weight is carried out.
·The molecular weight function is called and the values are printed in the command window.
%FUNCTION PROGRAM 1: Calculating thermodynamic properties (specific heat, enthalpy, entropy)
function [cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
R = 8.314;
for j = 1:length(T)
if T(j) < 300
cp = (a1 + a2.*T + a3.*T.^2 + a4.*T.^3 + a5.*T.^4).*R;
h = (a1 + (a2.*T)./2 + (a3.*T.^2)./3 + (a4.*T.^3)./4 + (a5.*T.^4)./5 + (a6./T)).*R.*T;
s = (a1.*log(T) + a2.*T + (a3.*T.^2)./2 + (a4.*T.^3)./3 + (a5.*T.^4)./4 + a7).*R;
else
cp = (a8 + a9.*T + a10.*T.^2 + a11.*T.^3 + a12.*T.^4).*R;
h = (a8 + (a9.*T)./2 + (a10.*T.^2)./3 + (a11.*T.^3)./4 + (a12.*T.^4)./5 + (a13./T)).*R.*T;
s = (a8.*log(T) + a9.*T + (a10.*T.^2)./2 + (a11.*T.^3)./3 + (a12.*T.^4)./4 + a14).*R;
end
end
end
%FUNCTION PROGRAM 2: Calculating molecular weight of species mentioned in data file
function [molecular_weight] = mole_wt(species_name)
constituents = {'H','C','N','O','A'};
atomic_weight = [1 12 14 16 40];
molecular_weight = 0;
for i = 1:length(species_name)
for j = 1:length(constituents)
if strcmp(species_name(i),constituents(j))
molecular_weight = molecular_weight + atomic_weight(j);
u = j;
end
end
n = str2double(species_name(i));
if n > 1
molecular_weight = molecular_weight + atomic_weight(u)*(n-1);
end
end
fprintf('molecular_weight of %s:- ',species_name)
fprintf('%d',molecular_weight)
fprintf(' ')
fprintf('amu')
fprintf('\n')
end
% MAIN Script
clear
close
clc
% Reading the thermodynamic data file
f1 = fopen('THERMO.dat','r')
file_name = fgetl(f1);
t_line = fgetl(f1);
A = strsplit(t_line,' ');
% Defining the temperatures extracted from data file
global_low_temp = str2double(A{2});
global_mid_temp = str2double(A{3});
global_high_temp = str2double(A{4});
for i = (1:3)
comments = fgetl(f1);
end
for i = 1:53
% Extracting species name
species = fgetl(f1);
species_name = species(1:6);
% Extracting coefficients from first line
line_1 = fgetl(f1);
l1 = strfind(line_1,'E');
a1 = str2double(line_1(1:(l1(1)+3)));
a2 = str2double(line_1((l1(1)+4):(l1(2)+3)));
a3 = str2double(line_1((l1(2)+4):(l1(3)+3)));
a4 = str2double(line_1((l1(3)+4):(l1(4)+3)));
a5 = str2double(line_1((l1(4)+4):(l1(5)+3)));
% Extracting coefficients from second line
line_2 = fgetl(f1);
l2 = strfind(line_2,'E');
a6 = str2double(line_2(1:(l2(1)+3)));
a7 = str2double(line_2((l2(1)+4):(l2(2)+3)));
a8 = str2double(line_2((l2(2)+4):(l2(3)+3)));
a9 = str2double(line_2((l2(3)+4):(l2(4)+3)));
a10 = str2double(line_2((l2(4)+4):(l2(5)+3)));
% Extracting coefficients from third line
line_3 = fgetl(f1);
l3 = strfind(line_3,'E');
a11 = str2double(line_3(1:(l3(1)+3)));
a12 = str2double(line_3((l3(1)+4):(l3(2)+3)));
a13 = str2double(line_3((l3(2)+4):(l3(3)+3)));
a14 = str2double(line_3((l3(3)+4):(l3(4)+3)));
T = linspace(global_low_temp, global_high_temp, 500);
% calling the thermodynamic equations function
[cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);
mkdir(['C:\Users\Sahil Maniyar\Documents\MATLAB\File parsing\',species_name])
% Plotting
% Plot between Temperature and Specific Heat
figure(1)
plot(T,cp,'linewidth',3,'color','b')
title (species_name)
xlabel('TEMPERATURE')
ylabel('SPECIFIC HEAT')
% Plot between Temperature and Enthalpy
figure(2)
plot(T,h,'linewidth',3,'color','g')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTHALPY')
% Plot between Temperature and Entropy
figure(3)
plot(T,s,'linewidth',3,'color','c')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTROPY')
cd(['C:\Users\Sahil Maniyar\Documents\MATLAB\File parsing\',species_name])
% Saving plots
saveas(1,'specific_heat.png')
saveas(2,'enthalpy.png')
saveas(3,'entropy.png')
% Changing directory for calculating molecular weight
cd ..
molecular_weight = mole_wt(species_name);
end
fclose(f1)