Challenge

Project 1 - Parsing NASA thermodynamic data

Aim: - The file Parsing the NASA thermodynamic data and to calculate the molecular weight, specific heat,enthalpy,entropy for the local temperature range for O2,N2,CO2.

OBJECTIVE: - Write a function that extracts the 14 coefficients and calculates the enthalpy,entropy, and specific heat for all the species in the data file.

Calculating molecular weight of each species.

Plotting the specific heat, enthalpy and entropy for the local temperature range.

Saving the plots as images with appropriate names and dumping them in seperate folders for each species.

FILE PARSING: -

Different Organisations comes up with polynomials that cab be used to evaluate different properties for different environments for example. in case of thermodynammics such as cp, H and S. They also create a document file for the co-efficients that are required to evaluate these polynomials, for n no . of species.

So, file parsing is a method that helps us in decoding that data or in other words help us reading that that data and use it in calculation of several parameters that defines the state of that environment. And analise behaviour of different species changing with some varying inputs.

To do file parsing first we need to check whether the data is broken down into meaningful bits or not. if not that we should first break it down in a standard from so that reading for each species becomes similar.

NASA Thermodynamics Data: -

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.

Using file parsing we need to write a function that extracts the 14co-efficients by reading data file and calculate the enthalpy(H),entropy(s)and specific heat(cp) for all the species. we can also make plots for better understanding the behaviour of gas with respect to temperature.

FORMULA:-

Cp/R = a1+a2 T + a3 T^2 + a4 T^3 + a5 T^4

H/RT = a1 + a2 T/2 + a3 T^2/2 + a4 T^3/4 + a5 T^4/5 + a6/T

S/R = a1 lnT + a2 T + a3 T^2/2 + a4 T^3/3 + a5 T^4/4 + a7

Here , R is the universal gas constant, T is the temperature.

The First 7 coefficients are High temperature coefficients and the Second 7 coefficients are low temperature coefficients.

WHAT IS THERMODYNAMICS: -

Thermodynamics allows you to predict how chemical systems should behave from a super atomic. it says nothing about how chemical systems will behave. Thermodynamics also pertains to the state of system, and says nothing about the path taken by the system in changing from one state to another.

ENTHALPY: -

If any substance increases with temperature, which means both the products and the reactants enthalpies incrase The overall enthalpy of the reaction will change if the increase in the enthalpy of product5s and reactants is different.

ENTROPY: -

Several factors affect the amount of entropy in a system. if you increase temperature, you increase entropy.

SPECIFIC HEAT: -

As the substance heat up, the average kinetic energy of the molecules increases. The collisions impart enough energy to allow rotation to occour. rotation then contributes tp the internal energy and raises the specific heat.

KEY STEPS TO FOLLOW: -

Open data for matlab to read.

Read line by line.

Split line into parts for better access to data(as per requirements).

Take input from user to directly jumps to species name insted of reading whole data.

Search for matching string similar to the input user made.

Calculating and plot things for that input and make a folder of plots created for that species name to sort data.

CODE FUNCTIONS:

ENTHALPY : -

function [h]=enthalpy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T)


if(T>local_mid_temp)
h=(a1*T+(a2*(T.^2)/2)+(a3*(T.^3)/3)+(a4*(T.^4)/4)+(a5*(T.^5)/5)+a6);
else
h=(a8*T+(a9*(T.^2)/2)+(a10*(T.^3)/3)+(a11*(T.^4)/4)+(a12*(T.^5)/5)+a13);
end

ENTROPY : -

function [s]=entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T)

if(T>local_mid_temp)
s=(a1*log(T)+(a2*T)+(a3*(T.^2)/2)+(a4*(T.^3))+(a5*(T.^4)/4)+a7);
else
s=(a8*log(T)+(a9*T)+(a10*(T.^2)/2)+(a11*(T.^3))+(a12*(T.^4)/4)+a14);
end

SPECIFIC HEAT : -

function[c_p] = specific_heat_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T)
if (T>local_mid_temp)
c_p=(a1+(a2*T)+(a3*(T.^2))+(a4*(T.^3))+(a5*(T.^4)));
else
c_p=(a8+(a9*T)+(a10*(T.^2))+(a11*(T.^3))+(a12*(T.^4)));
end

MOLECULAR WEIGHT : -

function [M]=molecular_weight(species_name)

Atomic_mass=[15.999,1.008,12.011,14.007,39.948];
Elements=['O','H','C','N','A'];

Mol_wt=0;
for i=1:length(species_name)
for j=1:length(Elements)
if strcmpi(species_name(i),Elements(j))
Mol_wt=Mol_wt+Atomic_mass(j);
z=j;
end
end
var=str2double(species_name(i));
if(var>1)
Mol_wt=Mol_wt+(Atomic_mass(z)*(var-1));
end
end
M=Mol_wt;
end

MAIN CODE (THERMODYNAMIC) : -

%Nasa thermodynamic file parasing
clear all
close all
clc
%gas constant
R=8.314;
%reading first two lines
f1=fopen('THERMO.dat','r')
tline1=fgetl(f1);
tline2=fgetl(f1);
temp=strsplit(tline2,' ');
global_low_temp=str2num(temp{2});
global_mid_temp=str2num(temp{3});
global_high_temp=str2num(temp{4});
%skipping next three lines
for i=1:3
skippedlines=fgetl(f1);
end
for i=1:53
tline3=fgetl(f1);
S=strsplit(tline3,' ');
species_name= S{1};
A=strfind(tline3,'G');
temp_values=tline3(A+4:length(tline3));
B=strsplit(temp_values,' ');
local_low_temp=str2double(B{1});
local_mid_temp=str2double(B{3});
local_high_temp=str2double(B{2});

tline4=fgetl(f1);
f=strfind(tline4,'E');
a1=str2double(tline4(1:(f(1)+3)));
a2=str2double(tline4(f(1)+4:(f(2)+3)));
a3=str2double(tline4(f(2)+4:(f(3)+3)));
a4=str2double(tline4(f(3)+4:(f(4)+3)));
a5=str2double(tline4(f(4)+4:(f(5)+3)));


tline5=fgetl(f1);
a6=str2double(tline5(1:(f(1)+3)));
a7=str2double(tline5(f(1)+4:(f(2)+3)));
a8=str2double(tline5(f(2)+4:(f(3)+3)));
a9=str2double(tline5(f(3)+4:(f(4)+3)));
a10=str2double(tline5(f(4)+4:(f(5)+3)));


tline6=fgetl(f1);
a11=str2double(tline6(1:(f(1)+3)));
a12=str2double(tline5(f(1)+4:(f(2)+3)));
a13=str2double(tline5(f(2)+4:(f(3)+3)));
a14=str2double(tline5(f(3)+4:(f(4)+3)));


T=linspace(local_low_temp,local_high_temp,100);
c_p=R*specific_heat_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T);

s=R*entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T);

h=R*enthalpy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T);
%req_species=["02","N2","co2"];

%if(species_name==req_species(1))||(species_name==req_species(2))||(species_name==req_species(3))
mkdir('C:\Users\subrahmanyam yandra\Desktop\matlab\1',species_name);
cd(species_name)


figure(1)
plot(T,c_p)
title('specific heat vs temperature')
xlabel('temperature')
ylabel('specific heat')




figure(2)
plot(T,h)
title('enthalpy vs temperature')
xlabel('temperature')
ylabel('enthalpy')




figure(3)
plot(T,s)
title('entropy vs temperature')
xlabel('temperaature')
ylabel('entropy')
saveas(figure(1),'specific_heat.png')
saveas(figure(2),'enthalpy.png')
saveas(figure(3),'entropy.png')


cd ..
molecular_wt=molecular_weight(species_name);
k=sprintf('%s Mol_wt = %f',species_name,molecular_wt)
end

RESULT : -

Finally we got the results o2,n2,co2.

O2

CO2: -

N2 :-


'O2 Mol_wt = 31.998000'

'CO2 Mol_wt = 44.009000'

'N2 Mol_wt = 28.014000'

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.