Project

Parsing NASA thermodynamic data

AIM:

  • To parse the NASA thermodynamic data
  • To calculate the molecular weight of each species
  • To plot the Cp, Enthalpy and Entropy for the local temperature range for `N_2,O_2&CO_2`

Definitions:

File parsing:Parsing a file means reading in a data stream of some sort and building an in memory model of the semantic content of that data. This aims at facilitating perfoming some kind of transformation on the data.

It means, to a computer, about what “reading text” means to a human being. You scan it, from start to finish, and figure out what it means as you go - whether you’re” a person reading text or a computer parsing a file.

Specific heat:The specific heat is the amount of heat per unit mass required to raise the temperature by one degree Celsius.

Enthalpy:Enthalpy is a thermodynamic property of a system. It is the sum of the internal energy added to the product of the pressure and volume of the system. It reflects the capacity to do non-mechanical work and the capacity to release heat. Enthalpy is denoted as H; specific enthalpy denoted as h.

Entropy:The entropy of an object is a measure of the amount of energy which is unavailable to do work. Entropy is also a measure of the number of possible arrangements the atoms in a system can have. In this sense, entropy is a measure of uncertainty or randomness.

Molecular weight:Molecular weight is the weight of a given molecule.

Atomic mass:the mass of an atom of a chemical element expressed in atomic mass units. It is approximately equivalent to the number of protons and neutrons in the atom (the mass number).

Abstract: NASA came up with polynomials that can be used to evaluate thermodynamic properties such as Cp, H and S. They have also documented the co-efficients that are required to evaluate these polynomials for 1000+ species.

Here the problem is broken into meaningful bits.Libraries of thermodynamic data and transport properties
are given for individual species in the form of least-squares
coefficients. Values of heat capacity Cp(T), enthalpy
H°(T), and entropy S°(T) are available for 53 solid, liquid, and gaseous species.

Emperical equations given to find the thermodynamic properties are,

where,

`C_p`=Specific heat(J/(K kg))

Universal gas constant R = 8.314 J / (mol·K)

a1 to a4= co-effcients

H=Enthalpy(J)

S=Entropy(J/K)

T=Temperature(K)

Let's go to the parsing part of these thermodynamic data,

Code:

% Parsing NASA's Thermodynamic data
clear all
close all
clc

%Reading thr data from  NASA file
f1=fopen('THERMO.dat','r');
fgetl(f1);
tline=fgetl(f1);
A=strsplit(tline,' ');
%Intake of Global temperatures
global_low_temperature=str2double(A{2});
global_mid_temperature=str2double(A{3});
global_high_temperature=str2double(A{4});
%Input the Element Name
prompt = 'Enter the element name: ';
str = input(prompt,'s');

for i=1:3
    fgetl(f1);
end
j=0;
%Using while loop to work until it reaches end of file
 while ~feof(f1)
tline5=fgetl(f1);
%finding out the elements name
    b=strsplit(tline5,' ');
    elements=b{1};
     if(strcmp(b{1},'END'))
         break;
     end
%Intake local temperrtures
    local_low_temperature=str2double(b{end-3});
    local_high_temperature=str2double(b{end-2});
    local_med_temperature=str2double(b{end-1});

    tline1=fgetl(f1);
    %intializing function for specific heat,enthalpy & entropy
   [T,t,cp,cp1,H,H1,S,S1]=everything(f1,tline1, local_low_temperature,local_high_temperature,local_med_temperature);
%intializing function for molecular weight
molecule=molecular_weight(elements);
%comparing strings to get the plot
if(strcmpi(str,elements))
    sprintf('Molecular weight of %s is:%f',elements,molecule)
%    counter variable for figures 
    j=j+1;
%     defining the file path
    fname='D:\PGHEV-SUMANTH\MATLAB Programs\File parsing\';
%     creating a directory
    mkdir(fullfile(fname,elements))
%     plotting
h=figure(j);
hold on
plot(T,cp,'linewidth',2);
plot(t,cp1,'linewidth',2);
xlabel('Temperature(T)')
ylabel('Specific heat(C_p)')
legend('High Temperature','Low Temperature','location','northwest')
title(elements)
% saving the plots into sub folders
filename=fullfile(fname,elements,'Specific_heat.jpg');

saveas(h,filename,'jpeg')
 k=figure(j+1);hold on
plot(T,H,'linewidth',2);
plot(t,H1,'linewidth',2);
xlabel('Temperature(T)')
ylabel('Enthalpy(H)')
title(elements)
legend('High Temperature','Low Temperature','location','northwest')
filename1=fullfile(fname,elements,'Enthalpy.jpg');
saveas(k,filename1,'jpeg')
l=figure(j+2);
hold on
plot(T,S,'linewidth',2)
plot(t,S1,'linewidth',2)
xlabel('Temperature(T)')
ylabel('Entropy(S)')
title(elements)
legend('High Temperature','Low Temperature','location','northwest')
filename2=fullfile(fname,elements,'Entropy.jpg');
saveas(l,filename2,'jpeg')
j=j+2;


end 

 end


fclose(f1);

  1. First things first,We close,clear the older screens or files with clear all,close all & clc command.
  2. Then we load the NASA's data by using the MATLAB buit in command,'fopen'.
  3. After loading the data, we skip the unwanted lines from the data using another built in file command,'fgetl'
  4. Then global low,medium,high temperatures are converted to numbers which were in the form of numbers using 'str2double' and the values are defined into the variables.
  5. Then the file is fetched till its end using while loop.
  6. Then the species name are calculated using built in 'strsplit' command to split the strings into number of small bits.
  7. Then local temperatures also defined to the variables using the splitted strings.
  8. Now,we have to split and define the co-efficients,to do that we search for the common term in the given data.
  9. we find out that the letter 'E' is common in all the coefficients.
  10. Hence we define a function to find the coefficients & other thermodynamic properties.
  11. User defined function to find the thermodynamic co-efficients is
    function [T,t,cp,cp1,H,H1,S,S1]=everything(f1,tline1, local_low_temperature,local_high_temperature,local_med_temperature)
    
    l=tline1;
    % Universal gas constant,R = 8.314 J / (mol·K) or 8.3145 J / mol·K
    R=8.3145;
    low=local_low_temperature;
    high=local_high_temperature;
    med=local_med_temperature;
    % finding 14 co-efficients
    a=strfind(l,'E');
    a1=str2double(l(1:a(1)+3));
    a2=str2double(l(a(1)+4:a(2)+3));
    a3=str2double(l(a(2)+4:a(3)+3));
    a4=str2double(l(a(3)+4:a(4)+3));
    a5=str2double(l(a(4)+4:a(5)+3));
    
    tline2=fgetl(f1);
    
    a=strfind(tline2,'E');
    
    a6=str2double(tline2(1:a(1)+3));
    a7=str2double(tline2(a(1)+4:a(2)+3));
    a8=str2double(tline2(a(2)+4:a(3)+3));
    a9=str2double(tline2(a(3)+4:a(4)+3));
    a10=str2double(tline2(a(4)+4:a(5)+3));
    
    tline3=fgetl(f1);
    
    a=strfind(tline3,'E');
    
    a11=str2double(tline3(1:a(1)+3));
    a12=str2double(tline3(a(1)+4:a(2)+3));
    a13=str2double(tline3(a(2)+4:a(3)+3));
    a14=str2double(tline3(a(3)+4:a(4)+3));
    
    T=(med:1:high);
    t=(low:1:med);
    % finding specific heat,Enthalpy&Entropy
    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;
    cp1=(a8+a9.*t+a10.*t.^2+a11.*t.^3+a12.*t.^4).*R;
    H1=(a8+a9.*t./2+a10.*(t.^2)./3+a11.*(t.^3)./4+a12.*(t.^4)./5+a13./t).*R.*t;
    S1=(a8.*log(t)+a9.*t+a10.*(t.^2)./2+a11.*(t.^3)./3+a12.*(t.^4)./4+a14).*R;
    
    end​
  12. In this function'everything' we input the file, required lines and temperatures to find entropy,enthalpy & specific heat .
  13. The formula to find the specific heat,Enthalpy & entropy are given in the abstract part.
  14. As we find these thermodynamic properties for different range of temperatures ,we use an array to send all the thermodynamic values in to the main program.
  15. Now,Our next task is to find the molecular weight of the species that are in the given data.
  16. so we generate a user defined function to find the molecular weights.
  17. function k=molecular_weight(str)
    
    k=0;
    c=0;
    % finding molecular weights
    atomic_symbol={'H';'C';'N';'O';'A'};
    atomic_mass=[1.0079;12.0107;14.0067;15.994;39.948];
    
    for i=1:length(str)
    for j=1:length(atomic_mass)
        
    if(strcmpi(str(i),atomic_symbol(j)))
     
        
        k=k+atomic_mass(j);
        c = j;
    
    end
    end
    num=str2num(str(i));
    if (num >1)
    
     k=k+(atomic_mass(c)*(num-1));
    
    end
    
    end
    end​
  18. Here we define an array consisting of molecules and also defining the atomic mass.
  19. Now we compare the atomic symbols and atomic mass with the species using 'strcmpi command.
  20. we do the looping,we put conditions,we get the desired answer.
  21. then we make directory of species & we use 'mkdir, command to create a directory.
  22. Then we plot specific heat,enthalpy,entropy for desired species & save the plots inside its directory using 'save as' command.

The code work like this,

  1. Enter species name.
  2. Find the Enthalpy,specific heat & entropy.
  3. find molecular weight.
  4. Plot temperature vs enthalpy,temperature vs Entropy,temperature vs specific heat.
  5. Make a directory of species.
  6. Put the plot images into the directories.

Results:

Plot that we get from the element O2,

Temperature vs Specific heat:

Temperature vs Enthalpy:

Temperature vs Entropy:

Plot that we get from the element N2,

Temperature vs Specific heat:

Temperature vs Enthalpy:

Temperature vs Entropy:

Plot that we get from the element CO2,

Temperature vs Specific heat:

Temperature vs Enthalpy:

Temperature vs Entropy:

The folders created using the commands,

The plots saved inside the directories in jpg format,

The molecular weight displayed for O2,N2& CO2 are ,respectively

REFERENCES:

  1. https://ecourses.ou.edu/cgi-bin/ebook.cgi?doc=&topic=th&chap_sec=01.4&page=theory
  2. https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19940013151.pdf
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.