Challenge

Project 1 - Parsing NASA thermodynamic data

Aim: - 1. To extract the 14 coefficient and calculate the enthalpy entropy and specific heat for all species in the data

  1. To calculate the molecular weight of each species and display it in the command window
  2. Plot the Cp, Enthalpy and entropy for local temperature range i.e., for high-temperature range and low-temperature range.
  3. Save plots as images with appropriate names and save them in separate folders with the proper species name.

Theory: -

Enthalpy:-

Enthalpy is a property of a thermodynamic system, that is a convenient state function preferred in many measurements in chemical, biological, and physical systems at a constant pressure. It is defined as the sum of the system's internal energy and the product of its pressure and volume. The pressure-volume term expresses the work required to establish the system's physical dimensions, i.e. to make room for it by displacing its environment. As a state function, enthalpy depends only on the final configuration of internal energy, pressure, and volume, and not on the path taken to achieve it.

The unit of measurement for enthalpy in the International System of Units (SI) is the joule. Other historical conventional units still in use include the British thermal unit (BTU) and the calorie.

Entropy: - Entropy is an extensive property of the thermodynamic system. Entropy, the measure of a system’s thermal energy per unit temperature that is unavailable for doing useful work. Because work is obtained from ordered molecular motion, the amount of entropy is also a measure of the molecular disorder, or randomness, of a system

The idea of entropy provides a mathematical way to encode the intuitive notion of which processes are impossible, even though they would not violate the fundamental law of conservation of energy. For example, a block of ice placed on a hot stove surely melts, while the stove grows cooler. Such a process is called irreversible because no slight change will cause the melted water to turn back into the ice while the stove grows hotter.

Specific heat: - The specific heat is the amount of heat per unit mass required to raise the temperature by one degree Celsius. The relationship between heat and temperature change is usually expressed in the form shown below where c is the specific heat. The relationship does not apply if a phase change is encountered, because the heat added or removed during a phase change does not change the temperature.

File parsing

Parsing, syntax analysis, or syntactic analysis is the process of analysing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar.

Parsing in computer languages refers to the syntactic analysis of the input code into its components parts in order to facilitate the writing of compilers and interpreters. It can be used to describe split or separation.

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 performing some kind of transformation on the data.

Software used: - MATLAB 2020

The formula for calculating enthalpy, entropy and specific heat,

For lower ranges, the temperature considered is 300 else higher temperatures are considered

MATLAB Program

Function code for enthalpy, entropy and specific heat calculation.

The code includes the above mathematical formula for the calculation

Low Range Temperature considered is 300 k. Upto 7 variables starting from a1 till a7 are considered for lower ranges.

For Temperatures above 300 k Variables from a8 to a14 are considered based on the formula

function[cp,h,s]=variables(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t)

R=8.314
for j= 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)./3+(a11.*t.^3)./3+(a12.*t.^4)./4+a14)*R;
        
        

    end
end
end

Code for mole weight calculation

function [molecular_weight]=mole_wt(species_identity)
atomic_name={'H','C','N','O','A'};
atomic_weight=[1 12 14 16 40];

molecular_weight=0;

for i=1:length(species_identity)
    for j=1:length(atomic_name)
        if strcmpi(species_identity(i),atomic_name(j))
       molecular_weight=molecular_weight+atomic_weight(j);
       u=j;
        end
    end
    n=str2double(species_identity(i));
    
    if n>1
        molecular_weight=molecular_weight+atomic_weight(u)*(n-1);
  end
end


end

  

Main Program code

clear all 
close all
clc

f4=fopen('THERMO.dat','r');
File=fgetl(f4);
t_line=fgetl(f4);
A=strsplit(t_line,' ');

global_low_temp=str2double(A{2});
global_mid_temp=str2double(A{3});
global_high_temp=str2double(A{4});

for i=1:3
    comment=fgetl(f4);
end

for i=1:53
    
    %Extracting species name
    header=fgetl(f4);
    x=strsplit(header,' ');
    
    species_identity=(x{1});

    
    %Extracting line 1
    line_1=fgetl(f4);
    line1=strfind(line_1,'E');
    
    a1=str2num(line_1(1:(line1(1)+3)));
    a2=str2num(line_1((line1(1)+4):(line1(2)+3)));
    a3=str2num(line_1((line1(2)+4):(line1(3)+3)));
    a4=str2num(line_1((line1(3)+4):(line1(4)+3)));
    a5=str2num(line_1((line1(4)+4):(line1(5)+3)));
     
    %Extracting line 2
   line_2=fgetl(f4)
   line2=strfind(line_2,'E')
   a6=str2num(line_2(1:(line2(1)+3)));
    a7=str2num(line_2((line2(1)+4):(line2(2)+3)));
    a8=str2num(line_2((line2(2)+4):(line2(3)+3)));
    a9=str2num(line_2((line2(3)+4):(line2(4)+3)));
    a10=str2num(line_2((line2(4)+4):(line2(5)+3)));
    
    %Extracting line 3
    line_3=fgetl(f4);
    line3=strfind(line_3,'E')
    a11=str2num(line_3(1:(line3(1)+3)))
    a12=str2num(line_3((line3(1)+4):(line3(2)+3)))
    a13=str2num(line_3((line3(2)+4):(line3(3)+3)))
    a14=str2num(line_3((line3(3)+4):(line3(4)+3)))
    %Creating Directory Folder 
    
    mkdir(['G:File ParsingSpecies',species_identity])
    
   
    
    t=linspace(global_low_temp,global_high_temp,200);
    
   
    [cp,h,s]=variables(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t);
    
    m(1)=figure;
    plot(t,cp,'linewidth',3,'color','r')
    title(species_identity)
    xlabel('Temperature')
    ylabel('Specific Heat')
    
    m(2)=figure;
    plot(t,h,'linewidth',3,'color','b')
    title(species_identity)
    xlabel('Temperature')
    ylabel('Enthalpy')
    
    m(3)=figure;
    plot(t,s,'linewidth',3,'color','k')
    title(species_identity)
    xlabel('Temperature')
    ylabel('Entropy')
    
    cd(['G:File ParsingSpecies',species_identity])
     
    
    
    
    %saving plots
    saveas(m(1),'specific_heat.jpg')
    saveas(m(2),'Enthalpy.jpg')
    saveas(m(3),'Entropy.jpg')
    
    
  
    
    
    molecular_weight(i)=mole_wt(species_identity);
   
end
fclose(f4)
    

Plots for species

1. O2

2. N2

3. CO2

Molecular Weight of the 53 species in array form

The molecular weight of some of the species obtained from the command window

Directory Folder with saved plots

Conclusion: - The parsing of the thermodynamic data file by NASA is executed using the MATLAB commands. The plots are saved in the given formed directory using the directory command in MATLAB . The function has also been coded to calculate the mole weight of the 53 states species. Thus we can conclude that by using these commands, files of different types can be parsed.

References

Wikipedia

https://www.britannica.com/science/entropy-physics

http://hyperphysics.phy-astr.gsu.edu/hbase/thermo/spht.html#:~:text=The%20specific%20heat%20is%20the,c%20is%20the%20specific%20heat.

https://www.quora.com/What-does-it-means-to-parse-a-file#:~:text=Parsing%20a%20file%20means%20reading,of%20transformation%20on%20the%20data.

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.