Project 1 - Parsing NASA thermodynamic data
Aim:- Write a MATLAB code to implement the parse the NASA thermodynamic data file and then calculate the thermodynamic properties of various gas species.
Equations:- The equation is to determine for Specific heat , Entropy , Enthalpy & atomic weight.
`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) RT`
`S=(a1 lnT + a2 T + a3 T^2 /2 + a4 T^3/3 + a5 T^4/4 +a7) R`
MW= No of atoms x atomic weight
Where,
Cp= Specific heat
H=Enthalpy
S= Entropy
MW= Molecular weight
T=Temperature
R= Universal gas constant
ln=Log
a1 to a14 = Coefficients, Since The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.
Objective of this project:- The objective of this project is to extracts the 14 coefficients and calculates the enthalpy, entropy, and specific heats for all the species in the NASA thermodynamic data file "Thermo.dat" , with the help of file parsing,
File parsing:- It’s Basically refer , how the information can be read from the text file or any kind of file and that information can be used in the computer programme.
NASA Thermodynamic File:- THERMO.dat file is a data file which contains 14 coefficient and 53 species, These Coefficients can be used to determine the specific heat, entropy , enthalpy for each species which are present in these NASA file.
53 Species present in NASA file are,
|
AR C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CN CO CO2 H H2 H2CN H2O H2O2 HCCO CCOH HCN HCNN HCNO HCO HNCO HNO HO2 HOCN N N2 N2O NCO NH NH2 NH3 NNH NO NO2 O O2 OH |
Specific heat :- The heat required to raise the temperature of the unit mass of a given substance by a given amount (usually one degree).
Entropy :- It is defined as the measurement of the degree of disordered particles in a system.
Enthalpy:- Enthalpy is the sum of the internal energy. and pressure times volume.
- 1. Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file. You will be reading this file NASA thermodynamic data(Tip:use fopen and fgetl). The formulae are shown below.
Here R is the universal gas constant, T is the temeprature
The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.
Also use the LOCAL TEMPERATURE RANGES which is unique for each individual species, not the GLOBAL TEMPERATURE RANGE.
% A function for specific heat
function [cp]= Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,lmt,T,R)
% finding specific heat with low medium range temperature variables
if T<=lmt
cp = (a8+(a9*T)+(a10*T.^2)+(a11*T.^3)+(a12*T.^4))*R;
else
cp = (a1+(a2*T)+(a3*T.^2)+(a4*T.^3)+(a5*T.^4))*R;
end
end
% A function for Entropy
function S=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,lmt,R)
% finding entropy with low medium range temperature variables
if T<=lmt
S=(a8*log(T) + a9*T + (a10*T.^2).*0.5 + (a11*T.^3).*0.33 + (a12*T.^4).*0.25 + a14).*R;
else
S=(a1*log(T) + a2*T + (a3*T.^2).*0.5 + (a4*T.^3).*0.33 + (a5*T.^4).*0.25 + a7).*R;
end
end
% A function for Enthalpy
function [H]=enthalty(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,lmt,R)
% finding enthalpy with low medium range temperature variables
if T<=lmt
H=(a8 + (a9*T)*0.5 + (a10*T.^2).*0.33 +(a11*T.^3).*0.25 + (a12*T.^4).*0.2 + a13./T).*R.*T;
else
H=(a1 + (a2*T)*0.5 + (a3*T.^2).*0.33 +(a4*T.^3).*0.25 + (a5*T.^4).*0.2 + a6./T).*R.*T;
end
end
- 2. Calculate the molecular weight of each species and display it in the command window.
% Calculation of Molecular weight [MW]
atoms_names=['O','H','C','N','Ar'];
atomic_weight=[15.999,1.00784,12.0107,14.0067,39.948];
MW=0;
for i=1:length(sp)
for j=1:length(atoms_names)
if sp(i)==atoms_names(j)
MW=MW+atomic_weight(j);
position=j;
end
end
n=str2num(sp(i));
if n>=1
MW=MW+atomic_weight(position)*(n-1);
end
end
Body of the content :-
Main code ,
% A program for NASA Thermodynamics
clear all
close all
clc
%input
R=8.314; % universal gas constant J/mol-k
f1=fopen('THERMO.dat','r');
fgetl(f1)
fgetl(f1)
fgetl(f1)
fgetl(f1)
fgetl(f1)
for i=1:53
tline=fgetl(f1);
A = strsplit(tline,' ');
sp = A{1}; %sp=species
llt = str2num(A{end-3}); %llt=local low temp
lmt = str2num(A{end-1}); %lmt=local medium temp
lht = str2num(A{end-2}); %lht= local high temp
tline2=fgetl(f1);
B=findstr(tline2,'E');
a1=str2num(tline2(1:B(1)+3));
a2=str2num(tline2(B(1)+4:B(2)+3));
a3=str2num(tline2(B(2)+4:B(3)+3));
a4=str2num(tline2(B(3)+4:B(4)+3));
a5=str2num(tline2(B(4)+4:B(5)+3));
tline3=fgetl(f1);
C=findstr(tline3,'E');
a6=str2num(tline3(1:C(1)+3));
a7=str2num(tline3(C(1)+4:C(2)+3));
a8=str2num(tline3(C(2)+4:C(3)+3));
a9=str2num(tline3(C(3)+4:C(4)+3));
a10=str2num(tline3(C(4)+4:C(5)+3));
tline4=fgetl(f1);
D=findstr(tline4,'E');
a11=str2num(tline4(1:D(1)+3));
a12=str2num(tline4(D(1)+4:D(2)+3));
a13=str2num(tline4(D(2)+4:D(3)+3));
a14=str2num(tline4(D(3)+4:D(4)+3));
T=linspace(llt,lht,1000);
[cp]=Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,lmt,T,R);
[S]=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,lmt,R);
[H]=enthalty(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,lmt,R);
cd('C:\Users\Amitesh\Documents\MATLAB\nasa thermo\sp')
mkdir(sp);
cd(sp)
%Plotting for Specific_heat
figure(1)
plot(T,cp,'linewidth',2,'color','g')
xlabel('Temperature [K]')
ylabel('Specific_heat [kJ]')
%Plotting for entropy
figure(2)
plot(T,S,'linewidth',2,'color','r')
xlabel('Temperature [K]')
ylabel('entropy [kJ/(mol-K)]')
%Plotting for enthalpy
figure(3)
plot(T,H,'linewidth',2,'color','b')
xlabel('Temperature [K]')
ylabel('enthalpy [kJ/(mol)]')
saveas(figure(1),'specific_heat.jpg') % saveas - helps save images in the given folder
saveas(figure(2),'entropy.jpg')
saveas(figure(3),'enthalpy.jpg')
% Calculation of Molecular weight [MW]
atoms_names=['O','H','C','N','Ar'];
atomic_weight=[15.999,1.00784,12.0107,14.0067,39.948];
MW=0;
for i=1:length(sp)
for j=1:length(atoms_names)
if sp(i)==atoms_names(j)
MW=MW+atomic_weight(j);
position=j;
end
end
n=str2num(sp(i));
if n>=1
MW=MW+atomic_weight(position)*(n-1);
end
end
fprintf('MW of %s = %f',sp,MW);
disp('')
end
% A function for specific heat
function [cp]= Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,lmt,T,R)
% finding specific heat with low medium range temperature variables
if T<=lmt
cp = (a8+(a9*T)+(a10*T.^2)+(a11*T.^3)+(a12*T.^4))*R;
else
cp = (a1+(a2*T)+(a3*T.^2)+(a4*T.^3)+(a5*T.^4))*R;
end
end
% A function for Entropy
function S=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,lmt,R)
% finding entropy with low medium range temperature variables
if T<=lmt
S=(a8*log(T) + a9*T + (a10*T.^2).*0.5 + (a11*T.^3).*0.33 + (a12*T.^4).*0.25 + a14).*R;
else
S=(a1*log(T) + a2*T + (a3*T.^2).*0.5 + (a4*T.^3).*0.33 + (a5*T.^4).*0.25 + a7).*R;
end
end
% A function for Enthalpy
function [H]=enthalty(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,lmt,R)
% finding enthalpy with low medium range temperature variables
if T<=lmt
H=(a8 + (a9*T)*0.5 + (a10*T.^2).*0.33 +(a11*T.^3).*0.25 + (a12*T.^4).*0.2 + a13./T).*R.*T;
else
H=(a1 + (a2*T)*0.5 + (a3*T.^2).*0.33 +(a4*T.^3).*0.25 + (a5*T.^4).*0.2 + a6./T).*R.*T;
end
end
Here we can say that A program of NASA thermodynamics is ready to go with a proper execution, well in these we have used the commands like clc ,clear all , linspace , plot
Commands use for: -
- Clear all = used to clear the workspace.
- CLC = used to clear the command window.
- Close all = used to close the background program.
- Linspace = used to make sure the interval is constant.
- Plot = used for plotting a graph, terms used in bracket as shown above , always the same terms means exact words or letters used in Inputs so that we won’t get errors will running program.
- Function = used for recall
- For loop = To repeat the specified number of times.
- Nested For loop = It’s same as for loop but in this we inside a for loop a loop EG-
For {}
For { }
end
end
- Mkdir = used to location address.
- Fopen = used to open the file.
- ‘r’= used to read the file.
- ‘w’= used to write the file.
- Fgetl = used to read the line in the file.
- Strsplit= string split is used to split the command at specified delimiter.
- Str2num = used to convert character array to string numeric array.
- Strfid= used to find the one string within another.
- fprintf = used to print the file.
- Cd = used to change the working directory.
>output of Molecular weight
MW of O = 15.999000
MW of O2 = 31.998000
MW of H = 1.007840
MW of H2 = 2.015680
MW of OH = 17.006840
MW of H2O = 18.014680
MW of HO2 = 33.005840
MW of H2O2 = 34.013680
MW of C = 12.010700
MW of CH = 13.018540
MW of CH2 = 14.026380
MW of CH2(S) = 14.026380
MW of CH3 = 15.034220
MW of CH4 = 16.042060
MW of CO = 28.009700
MW of CO2 = 44.008700
MW of HCO = 29.017540
MW of CH2O = 30.025380
MW of CH2OH = 31.033220
MW of CH3O = 31.033220
MW of CH3OH = 32.041060
MW of C2H = 25.029240
MW of C2H2 = 26.037080
MW of C2H3 = 27.044920
MW of C2H4 = 28.052760
MW of C2H5 = 29.060600
MW of C2H6 = 30.068440
MW of CH2CO = 42.036080
MW of HCCO = 41.028240
MW of HCCOH = 42.036080
MW of H2CN = 28.033080
MW of HCN = 27.025240
MW of HNO = 31.013540
MW of N = 14.006700
MW of NNH = 29.021240
MW of N2O = 44.012400
MW of NH = 15.014540
MW of NH2 = 16.022380
MW of NH3 = 17.030220
MW of NO = 30.005700
MW of NO2 = 46.004700
MW of HCNO = 43.024240
MW of HOCN = 43.024240
MW of HNCO = 43.024240
MW of NCO = 42.016400
MW of CN = 26.017400
MW of HCNN = 41.031940
MW of N2 = 28.013400
MW of AR = 39.948000
MW of C3H8 = 44.094820
MW of C3H7 = 43.086980
MW of CH3CHO = 44.051760
MW of CH2CHO = 43.043920
>Attachment's:-






Screenshot of the window where all the folders are saved

1.Plots for O2
Enthalpy vs Temperature plot:-

Entropy vs Temperature plot:-

Specific heat vs Temperature plot:-

2.Plots for N2:-
Enthalpy vs Temperature plot:-

Entropy vs Temperature plot:-

Specific heat vs Temperature plot:-

3.Plots for CO2:-
Enthalpy vs Temperature plot:-

Entropy vs Temperature plot:-

Specific heat vs Temperature plot:-

Conclusion:- With the help of MATLAB Code i.e. File parsing we had find all the coefficient values and 53 species for specific heat ; entropy ; enthalpy with the local global temperature and we had calculated each molecular weight for 53 species.
Google Drive Link for Folders:
https://drive.google.com/drive/folders/1VTwb_jX-rMykr89NTMaiDzCfuD2QLZyZ?usp=share_link