Parsing NASA thermodynamic data
1. OBJECTIVE : To parse the Thermodynamics data from NASA using MATLAB.
Data file: NASA thermodynamic data
2. 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 :
where,
`C_p` = 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.
3. BODY OF CONTENT :
Function program 1 : Calculating thermodynamics 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 the data file :
function [molecular_weight] = mole_wt(species_name)
SPECIES = upper(species_name)
constituents = {'H','C','N','O','A'};
atomic_weight = [1 12 14 16 40];
molecular_weight = 0;
for i = 1:length(SPECIES)
for j = 1:length(constituents)
if strcmp(SPECIES(i),constituents(j))
molecular_weight = molecular_weight + atomic_weight(j);
u = j;
end
end
n = str2double(SPECIES(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 code :
clear all
close all
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)));
% Creating a folder 'SPECIES' to save thermodynamic plots of species
mkdir(['D:Skill-Lync Courses1. MATLABParsing NASA thermodynamic dataSPECIES', species_name]);
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);
% 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')
directory = (['D:Skill-Lync Courses1. MATLABParsing NASA thermodynamic dataSPECIES',species_name]);
cd(directory)
% Saving plots
saveas(1,'specific_heat.png')
saveas(2,'enthalpy.png')
saveas(3,'entropy.png')
% Changing directory for calculating molecular weight
cd('D:Skill-Lync Courses1. MATLABParsing NASA thermodynamic dataSPECIES')
molecular_weight = mole_wt(species_name);
end
fclose(f1)
4. RESULTS :
plots for oxygen -