Parsing NASA thermodynamic data
PARSING NASA THERMODYNAMIC DATA
AIM :-
To create a program to read the thermodynamic data file of NASA and extract the data for further study and analysis.
PLATFORM USED :-
- Software – MATLAB R2019a
- Programming Language – C/C++
SYSTEM SPECIFICATIONS :-
- Manufacturer - DELL
- Model – Vostro 3478
- Operating System - Windows 10
- Processor - Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz 1.80GHz
- RAM – 8 GB
THEORY :-
NASA has researched and formed different types of polynomials to evaluate thermodynamic properties such as Cp (Specific Heat at Constant Pressure), H (Enthalpy) and S (Entropy) for 1000+ species.
OBJECTIVE :-
- To create a code for extracting all the 14 co-efficient from the data file and a code function to calculate the three thermodynamic properties such specific heat, enthalpy and entropy for all the species.
- Calculate molecular weight for all the species from the data file.
- Plot the Cp, Enthalpy and Entropy values to the local temperature range for all the species.
- Save all the plots to its appropriate species name as folder name automatically.
GOVERNING EQUATIONS :-
- Specific Heat at Constant Pressure (Cp),
`\frac{C_p}{R}\ =\ a_1\ +\ a_2\ast T\ +\ a_3\ast T^2\ +\ a_4\ast T^3\ +\ a_5\ast T^4`
Where,
`C_p` - Specific Heat at Constant Pressure (J/Kg-k)
R - Universal Gas Constant (R = 8.314 J/mol-k)
T - Temperature (Kelvin)
`(a_1….a_5)` - Co-Efficient of the species
2. Enthalpy (H),
`\frac{H}{R\ast T}\ =\ a_1\ +\ a_2\ast(\frac{T}{2}\ \)+\ a_3\ast(\frac{T^2}{3}\ \)\ +\ a_4\ast(\frac{T^3}{4}\ \)\ \ +\ a_5\ast(\frac{T^4}{5}\ \)\ \ +\ (\frac{a_6}{T}\ \)`
Where,
H - Enthalpy (Joules - J)
R - Universal Gas Constant (R = 8.314 J/mol-k)
T - Temperature (Kelvin)
`(a_1….a_6)` - Co-Efficient of the species
3. Entropy (S),
`\frac{S}{R}\ =\ a_1\ast\ ln(T)\ +\ a_2\ast\ T+\ \frac{a_3\ast\ \ T^2}{2}\ +\ \frac{a_4\ast\ \ T^3}{3}\ \ +\ \frac{a_5\ast\ \ T^4}{4}\ \ +\ a_7`
S - Entropy (J/K)
R - Universal Gas Constant (R = 8.314 J/mol-k)
T - Temperature (Kelvin)
`(a_1….a_7)` - Co-Efficient of the species
INPUT AND OUTPUT PARAMETERS :-
INPUT PARAMETERS :-
- Data file from NASA containing the co-efficient for many species.
- Formula for calculating thermodynamic properties like specific heat at constant pressure (, enthalpy (H) and entropy (S).
OUTPUT PARAMETERS :-
- Plots of , H and S vs Local temperature range for all the individual species.
- Molecular weight of all the species.
- Automatic saving of all the three plots for each species.
CODE :-
CODE FOR PARSING THE DATA AND EVALUATE MOLECULAR WEIGHT FOR SPECIES
CODE :-
% Clearing all previous memory in Workspace
clear all
% Terminating all the previous plots
close all
% Clearing all the values in Command Window
clc
% Importing the 'THERMO.dat' file contents
ntd = fopen('THERMO.dat','r');
% Skipping the first five lines from the data file
for i = 1:5
line_5 = fgetl(ntd);
end
% Loop for all the 53 species
for j = 1:53
% Getting to the 1st line of 1st species 'O'
line_6 = fgetl(ntd);
% Starting with the first species
% Separating the first line by delimiter
b = strsplit(line_6,' ');
% Obtaining the species name
species_name = (b{1});
% Finding the location of 'G' string
loc_1 = strfind(line_6,'G');
% Obtaining the Local Temperature Values
local_low_temp = str2double(line_6(loc_1+4:loc_1+10));
local_high_temp = str2double(line_6(loc_1+13:loc_1+20));
local_mid_temp = str2double(line_6(loc_1+23:loc_1+30));
% Local Temperature Range of the species
local_temp_range = linspace(local_low_temp,local_high_temp,250);
% EXTRACTING THE 14 CO_EFFICIENTS
% Getting the 1st line of co-efficients
line_7 = fgetl(ntd);
% Finding the location of 'E' string
loc_2 = strfind(line_7,'E');
% Extracting all the c-efficients from 1st line
c1 = str2double(line_7(1:loc_2(1)+3));
c2 = str2double(line_7(loc_2(1)+4:loc_2(2)+3));
c3 = str2double(line_7(loc_2(2)+4:loc_2(3)+3));
c4 = str2double(line_7(loc_2(3)+4:loc_2(4)+3));
c5 = str2double(line_7(loc_2(4)+4:loc_2(5)+3));
% Getting the 2nd line of co-efficients
line_8 = fgetl(ntd);
% Finding the location of 'E' string
loc_3 = strfind(line_8,'E');
% Extracting all the c-efficients from 2nd line
c6 = str2double(line_8(1:loc_3(1)+3));
c7 = str2double(line_8(loc_3(1)+4:loc_3(2)+3));
c8 = str2double(line_8(loc_3(2)+4:loc_3(3)+3));
c9 = str2double(line_8(loc_3(3)+4:loc_3(4)+3));
c10 = str2double(line_8(loc_3(4)+4:loc_3(5)+3));
% Getting the first line of co-efficients
line_9 = fgetl(ntd);
% Finding the location of 'E' string
loc_4 = strfind(line_9,'E');
% Extracting all the c-efficients from first line
c11 = str2double(line_9(1:loc_4(1)+3));
c12 = str2double(line_9(loc_4(1)+4:loc_4(2)+3));
c13 = str2double(line_9(loc_4(2)+4:loc_4(3)+3));
c14 = str2double(line_9(loc_4(3)+4:loc_4(4)+3));
% Function for calculating Cp, H & S values
[Cp,H,S] = thermodynamics(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,local_low_temp,local_mid_temp,local_high_temp,local_temp_range);
% To create folders for species & store the plots individually
Data=sprintf('%s',species_name);
% Assigning the current directory to a variable ‘c_d’
c_d = pwd;
% Make new directory under the current directory
% Also creating new folders in the current directory of species names
mkdir(Data);
% Setting current working directory as ‘Data’ for the plots
cd(Data);
% PLOTTING GRAPHS
% Cp vs Temperature
figure(1)
plot(local_temp_range,Cp,'linewidth',3,'color','r')
xlabel('Local Temperature Range')
ylabel('Cp - Specific Heat at Constant Pressure')
title('Cp vs Species Temperature')
grid on
getframe(gcf);
saveas(1,'Enthalpy Plot.png')
% Enthalpy vs Temperature
figure(2)
plot(local_temp_range,H,'linewidth',3,'color','b')
xlabel('Local Temperature Range')
ylabel('H - Enthalpy')
title('Enthalpy vs Species Temperature')
grid on
getframe(gcf);
saveas(2,'Entropy Plot.png')
% Entropy vs Temperature
figure(3)
plot(local_temp_range,S,'linewidth',3,'color','black')
xlabel('Local Temperature Range')
ylabel('S - Entropy')
title('Entropy vs Species Local Temperature')
grid on
getframe(gcf);
saveas(3,'Cp Plot.png')
% Setting current directory as ‘c_d’ (Original directory)
cd(c_d);
% FOR CALCULATING MOLECULAR WEIGHT OF THE SPECIES
species_elements={'H','C','N','O','A'};
atomic_weight=[1,12,14,16,40];
mol_weight=0;
% For single element
for k=1:length(species_name)
for l=1:length(species_elements)
if strcmp(species_name(k),species_elements(l))==1
mol_weight=mol_weight+atomic_weight(l);
position=l;
end
end
n=str2double(species_name(k));
% For combination of elements
if n>1
mol_weight = mol_weight+((atomic_weight(position))*(n-1));
end
end
% Printing the calculated molecular weights
fprintf('Molecular Weight of [%s] - %du \n',species_name,mol_weight)
end
PROGRAM PROCESS :-
- The compiler starts the program.
- Then the data file is being imported to MATLAB.
- Next the first five lines are being skipped.
- The loop starts for all the 53 species.
- The 6th line of data file is being read.
- The line is being split by ‘ ’ (space) delimiter.
- Next the species name is stored in variable ‘species_name’.
- Then the string ‘G’ is located.
- All three temperatures of the species are obtained.
- Then all the 14 co-efficient are obtained.
- The function is called to calculate Cp, H and S values.
- Then the folder is created in species name.
- Then the graphs are plotted for Cp, H and S vs Species temperature.
- The plots are saved individually in the folders.
- Next the molecular weight is calculated for each species.
- The compiler terminates the program.
CODE FOR CALCULATING THERMOYNAMIC PROPERTIES
(Cp, H & S)
CODE :-
function [Cp,H,S] = thermodynamics(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,local_low_temp,local_mid_temp,local_high_temp,local_temp_range)
% Universal Gas Constant (J/M.k)
R = 8.314;
% High Temperature Range
L_T = linspace(local_low_temp,local_mid_temp,250);
% Low Temperature Range
H_T = linspace(local_mid_temp,local_high_temp,250);
if (local_temp_range>=local_mid_temp)
% Calculating Cp,H & S for 1st seven (c1-c7) co-efficients
% Specific Heat at Constant Pressure
Cp = (c1+(c2.*H_T)+((c3.*(H_T.^2)))+((c4.*(H_T.^3)))+((c5.*(H_T.^4)))).*R;
% Enthalpy
H = (c1+((c2.*H_T)./2)+((c3.*((H_T).^2))./3)+((c4.*((H_T).^3))./4)+((c5.*((H_T).^4))./5)+(c6./H_T)).*(H_T.*R);
% Entropy
S = (c1.*log(H_T)+c2.*H_T+((c3.*((H_T).^2))./2)+((c4.*((H_T).^3))./3)+((c5.*((H_T).^4))./4)+c7).*R;
else
% Calculating Cp,H & S for 2nd seven (c8-c14) co-efficients
% Specific Heat at Constant Pressure
Cp = (c8+(c9.*L_T)+((c10.*(L_T.^2)))+((c11.*(L_T.^3)))+((c12.*(L_T.^4)))).*R;
% Enthalpy
H = (c8+((c9.*L_T)./2)+((c10.*((L_T).^2))./3)+((c11.*((L_T).^3))./4)+((c12.*((L_T).^4))./5)+(c13./L_T)).*(L_T.*R);
% Entropy
S = (c8.*log(L_T)+(c9.*L_T)+((c10.*((L_T).^2))./2)+((c11.*((L_T).^3))./3)+((c12.*((L_T).^4))./4)+c14).*R;
end
end
PROGRAM PROCESS :-
- The compiler starts the program.
- It checks for the input parameters from the main code.
- Low temperature range of species is generated.
- High temperature range of species is generated.
- Then according to conditional statements the values of Cp, H and S are calculated.
- The compiler terminates the program.
OUTPUT :-
The plots of all the 53 species were generated successfully and saved in their respective folders.
`O_2` PLOTS :-
`N_2` PLOTS :-
`CO_2` PLOTS :-
PLOTS FOLDER WINDOW :-
MOLECULAR WEIGHT :-
ERRORS :-
Molecular weight for ‘AR’ Argon was not dispalyed in the command window because while comparing the string and matching the atomic numbers there was an error.
CONCLUSION :-
The NASA data file was imported successfully and the thermodynamic properties were calculated successfully. Then the plots were plotted between species temperature and molecular weight for each species were calculaed successfully.