Project 1 - Parsing NASA thermodynamic data
AIM:
- Write a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the data file.
- Calculate the molecular weight of each species and display it in the command window.
- Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature: high temperature) specific for each species.
NASA will be polynomials that can be used to evaluate thermodynamic properties such as Cp, H and S using polynomials. They have also documented the co-efficient that are required to evaluate these polynomials for 1000+ species.
Here R is the universal gas constant, T is the temperature
Formula
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.
- The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.
- Please write a detailed report to describe your logic.
Attachments needed:
- Screenshot of the window where all the folders are saved.
- Plots for o2, N2 and Co2 species.
MATLAB PROGRAMMING: -
close all
clear all
clc
%Opening the required file
filename = fopen('THERMO.dat','r')
%Heading
header1 = fgetl(filename)
%Global temperature values
header2 = fgetl(filename)
%Next three lines are comments
des_1 = fgetl(filename)
des_2 = fgetl(filename)
des_3 = fgetl(filename)
A = strsplit(header2,' ');
%Reading Global Temperature Line
Global_low_temperature = str2num(A{2})
Global_mid_temperature = str2num(A{3})
Global_high_temperature = str2num(A{4})
%using for loop to consider 53 elements
for i=1:53
%Reading the line
linespecies= fgetl(filename);
species_name = linespecies(1:6)
Line_1 = fgetl(filename);
L1 = strfind(Line_1,'E');
c1 = str2num(Line_1(1:(L1(1)+3)));
c2 = str2num(Line_1((L1(1)+4):(L1(2)+3)));
c3 = str2num(Line_1((L1(2)+4):(L1(3)+3)));
c4 = str2num(Line_1((L1(3)+4):(L1(4)+3)));
c5 = str2num(Line_1((L1(4)+4):(L1(5)+3)));
Line_2 = fgetl(filename);
L2 = strfind(Line_2,'E');
c6 = str2num(Line_2(1:(L2(1)+3)));
c7 = str2num(Line_2((L2(1)+4):(L2(2)+3)));
c8 = str2num(Line_2((L2(2)+4):(L2(3)+3)));
c9 = str2num(Line_2((L2(3)+4):(L2(4)+3)));
c10 = str2num(Line_2((L2(4)+4):(L2(5)+3)));
Line_3 = fgetl(filename);
L3 = strfind(Line_3,'E');
c11 = str2num(Line_3(1:(L3(1)+3)));
c12 = str2num(Line_3((L3(1)+4):(L3(2)+3)));
c13 = str2num(Line_3((L3(2)+4):(L3(3)+3)));
c14 = str2num(Line_3((L3(3)+4):(L3(4)+3)));
%creating folder for line species
mkdir(['C:\Users\Ramachal Pandey\Documents\MATLAB\',species_name]);
%Temperature ranges for calculation purpose
Temperature = linspace(300,5000,100);
%Universal gas constant
R =8.314;
%calculation of properties based on the lower and upper temperature
for j = 1:length(Temperature)
if Temperature(j)<3000
Cp = (c1+c2.*Temperature+c3.*Temperature.^2+c4.*Temperature.^3+c5.*Temperature.^4).*R;
H = (c1+(c2.*Temperature)./2+(c3.*Temperature.^2)/3+(c4.*Temperature.^3)/4+(c5.*Temperature.^4/5)+c6./Temperature).*Temperature.*R;
S = (c1*log(Temperature)+c2.*Temperature+(c3.*Temperature.^2)/2+(c4.*Temperature.^3)/3+(c5.*Temperature.^4)/4+c7).*R;
else
Cp = (c8+c9.*Temperature+c10.*Temperature.^2+c11.*Temperature.^3+c12.*Temperature.^4).*R;
H = (c8+(c9.*Temperature)/2+(c10.*Temperature.^2)/3+(c11.*Temperature.^3)/4+(c12.*Temperature.^4/5)+c13./Temperature).*Temperature.*R;
S = (c8.*log(Temperature)+c9.*Temperature+(c10.*Temperature.^2)/2+(c11.*Temperature.^3)/3+(c12.*Temperature.^4)/4+c14).*R;
end
end
%plot
%Temperature vs Entropy graph plot
figure(1)
plot(Temperature,S,'linewidth',4,'color','r')
title(species_name)
xlabel('Temperature')
ylabel('Entropy')
%Temperature vs Enthalpy
figure(2)
plot(Temperature,H,'linewidth',4,'color','y')
title(species_name)
xlabel('Temperature')
ylabel('Enthalpy')
%Temperature vs Specific heat
figure(3)
plot(Temperature,Cp,'linewidth',4,'color','b')
title(species_name)
xlabel('Temperature')
ylabel('Specific heat')
directory = (['C:\Users\Ramachal Pandey\Documents\MATLAB\',species_name]); %changing the filepath to save the plots
cd(directory)
%saving the plots
saveas(1,'Entropy.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'Specific heat.jpg');
cd('C:\Users\Ramachal Pandey\Documents\MATLAB\') %switching the directory back to read thermodat file for molecular mass calculation
MM = molecular_masses(species_name)
end
fclose(filename)
MOLECULAR WEIGHT FUNCTION
function MM = molecular_masses(species_name)
linespecies = upper(species_name);
Constituents = ['H', 'C', 'N', 'O', 'A'];
Atomic_weight = [1.00794 12.0107 14.0067 15.9994 39.948];
MM = 0;
for i=1:length(linespecies)
for j=1:length(Constituents)
if strcmp(linespecies(i),Constituents(j))
MM = MM + Atomic_weight(j);
u = j;
end
end
n = str2num(linespecies(i));
if n>1
MM = MM + Atomic_weight(u)*(n-1);
end
end
end
Explanation of Programing:
1) Initially open the given thermodynamic data file and read the data using fopen command. Calculate the specific heat, entropy and enthalpy.
2) Then reading the global temperature line of the thermodynamic data and calculate the global low, mid and high temperature from the second line of header file.
3.) fgetl command is used to go to the next line file or writing file. strsplit is used to split the value. By using fgetl(), strsplit() and str2num() command find out the global low,mid and high temperatures in the second line.
5.) Using the for loop for all the species
6.) Using the strfind() command, find out the number of exponential.
7.) Find out the convert coefficient from string form to number, using str2num() command.
8.) By doing the above steps calculate the 14 coefficients for all the species.
9.) When find the coefficients for a species after that find the entropy,enthalpy and specific heat.
10.) High temperature coefficients and calculate cp,H and s.
11.) Assuming universal gas constant R=8.314 J/mol-k and assuming temperature range from 300 to 5000 take 100 values by linspace() command.
12.) Once calculate the entropy, enthalpy and specific heat for all the species, plot the graph between: Temperature vs Entropy, Temperature vs Enthalpy and Temperature vs Specific heat.
13.) Store all the three plots for all the species in the file.
14.) Calculating the molecular weight and displayed in the command window.
15.) using the fclose command to close the operation.
. FUNCTION COMMAND EXPLANATION: -
- Function is used to calculate the molecular weight of the 53 species present in the thermo.dat file.
- Calculation is done by using molecular name, In the main function we already extracted the molecule name.
- Finding the common elements which comb inly forms a molecule.
- Atomic weights of the common elements and store in a vector.
- Initially we assume in for loop.
- If they match, then molecular weight of the element.
LOCATION OF SPECIES THERMODYNAMIC PROPERTIES
COMMAND WINDOWS RESULT: -
filename =
5
header1 =
'THERMO'
header2 =
' 300.000 1000.000 5000.000'
des_1 =
'! GRI-Mech Version 3.0 Thermodynamics released 7/30/99'
des_2 =
'! NASA Polynomial format for CHEMKIN-II'
des_3 =
'! see README file for disclaimer'
Global_low_temperature =
300
Global_mid_temperature =
1000
Global_high_temperature =
5000
species_name =
'O '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
15.9994
species_name =
'O2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
31.9988
species_name =
'H '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
1.0079
species_name =
'H2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
2.0159
species_name =
'OH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
17.0073
species_name =
'H2O '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
18.0153
species_name =
'HO2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
33.0067
species_name =
'H2O2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
34.0147
species_name =
'C '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
12.0107
species_name =
'CH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
13.0186
species_name =
'CH2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
14.0266
species_name =
'CH2(S)'
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
14.0266
species_name =
'CH3 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
15.0345
species_name =
'CH4 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
16.0425
species_name =
'CO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
28.0101
species_name =
'CO2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
44.0095
species_name =
'HCO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
29.0180
species_name =
'CH2O '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
30.0260
species_name =
'CH2OH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
31.0339
species_name =
'CH3O '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
31.0339
species_name =
'CH3OH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
32.0419
species_name =
'C2H '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
25.0293
species_name =
'C2H2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
26.0373
species_name =
'C2H3 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
27.0452
species_name =
'C2H4 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
28.0532
species_name =
'C2H5 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
29.0611
species_name =
'C2H6 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
30.0690
species_name =
'CH2CO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
42.036
species_name =
'HCCO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
41.0287
species_name =
'HCCOH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
42.0367
species_name =
'H2CN '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
28.033
species_name =
'HCN '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
27.0253
species_name =
'HNO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
31.0140
species_name =
'N '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
14.0067
species_name =
'NNH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
29.0213
species_name =
'N2O '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
44.0128
species_name =
'NH '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
15.0146
species_name =
'NH2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
16.0226
species_name =
'NH3 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
17.0305
species_name =
'NO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
30.0061
species_name =
'NO2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
46.0055
species_name =
'HCNO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
43.0247
species_name =
'HOCN '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
43.0247
species_name =
'HNCO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
43.0247
species_name =
'NCO '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
42.0168
species_name =
'CN '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
26.0174
species_name =
'HCNN '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
41.0320
species_name =
'N2 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
28.0134
species_name =
'AR '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
39.9480
species_name =
'C3H8 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
44.0956
species_name =
'C3H7 '
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
43.0877
species_name =
'CH3CHO'
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
44.0526
species_name =
'CH2CHO'
Warning: Directory already exists.
> In nasaspacepro (line 75)
MM =
43.0446
ans =
0
PLOTTED GRAPHS
- O2 Plots
Temperature vs Enthalpy
Temperature vs Entropy
Temperature vs Specific heat
- N2 Plot
Temperature vs Enthalpy
Temperature vs Entropy
Temperature vs Specific heat
- CO2 plots
Temperature vs Enthalpy
Temperature vs Entropy
Temperature vs Specific heat
Reference: -
- https://drive.google.com/file/d/1AikCHDlz9s_fu8whE81qee_GD4AyYpCP/view?usp=sharing
- https://skill-lync.com/projects
CONCLUSION
We are successfully done the all the iteration