Project 1 - Parsing NASA thermodynamic data
AIM: To write a code in Matlab to parse the NASA thermodynamic data file and then calculate the thermodynamic properties of various species of gases.
OBJECTIVE OF PROGRAM:
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.
2. Calculate the molecular weight of each species and display it in the command window.
3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.
5. The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.
6. Screenshot of the window where all the folders are saved.
7. Plots for o2, N2 and Co2 species (your program should be case insensitive, if it is going to take the species name as an input).
DESCRIPTION:
NASA THERMODYNAMIC FILE:
The file THERMO.dat in which there are tenperature ranges and 53 species are given and each species contains 14 coefficients and temperature ranges and we have to parse the 14coefficients by differentiating 7 coefficients as Higher temperature ones and 7 coefficients as lower temperature ones to find the Specific heat(Cp), Entropy,Enthalpy using the formula.
SPECIFIC HEAT:
Specific heat is the amount of hear per unit mass required to raise the temperature by one degree celcius.
The relationship between heat and temperature is shown below
Cp=R*(a1+(a2*T)+(a3*(T).^2)+(a4*(T).^3)+(a5*(T).^4)
where
Cp = specific heat [K]
R = Universal gas constant
a(i) = coefficients where i = 1 to 14
T = temperature
ENTROPY:
It is measure of system's thermal energy per unit temperature that is unavailable for doing the useful work (or) As work is obtained from ordered molecular motion, so entropy is the measure of molecular disorder or randomness of system.The expression to calculate entropy is as follows
S = R*(a1.*log(T)+(a2*T)+((a3*(T).^2)/2)+((a4*(T).^3)/3)+((a5*(T).^4)/$)+a7)
where S = Entropy
R= Universal gas constant
T= temperature
a(i) = coefficients
ENTHALPY:
A property of thermodynamic system is equal to the systems internal energy plus the product of its pressure and volume.The expression is as follows
H=R*T.*(a1+((a2*T)/2)+((a3*(T).^2/3)+((a4*(T).^3)/4)+((a5*(T).^4)/5)+((a6./T)))
MAIN PROGRAM OF NASA THERMODYNAMIC DATA FILE:
CODE:
STEPS:
- We put the input parameter R and we will open a file THERMO.dat file and read this file using 'fopen' command
- Secondly we will read first line THERMO using 'fgetl' command and we split the temperatures using the 'strsplit' command to convert it into cell array and than we convert it to string to number using 'str2num'.
- We assing the temparature range using 'linspace' command.
- Then we run the 'for loop' to skip the 3 text lines of the data file using 'fgetl' inside the loop.
- Now, we run the loop to find all the 53 elements contained in the data file by 'fgetl' command.
- Then after finding the 53 species we find the species line.
- Then we find the species name.
- The find the number of temperatures in the species i.e 14.
- Then we use 'strfind' to find the line using string attached 'E' to it to find the number of coefficients attached with string E.
- Then we split it into cell array using 'strsplit' command and 'str2num' for all the 14 coefficients i.e 7 high temperature coefficients and 7 low temperature coefficients.
- Now we give the functions for 'Specific heat','Entropy','Enthalpy' and calculate it using 14 coefficients.
- Then we specify the function for 'Molecular weight' to find molecular weight for different species.
- Then we write the 'Molecular weight.txt' file and 'fprintf' all the molecular weights of species and close the txt file using 'fclose' command.
- Now we change the directory folder using 'cd' command and creating directory folder to save our files using 'mkdir' command and then we change the directory to this crerated folder.
- Now the plotting of plots is left over. So, we plot Specific heat vs temperature for different species , Entropy vs temperature for different species and Enthalpy vs temperature of different species. We use 'title' command to give the title of the graph plotted for.
- The final step we use the 'saveas' command to save the plots of different species in the directory folder. Now we will change the directory to which the main code file runs in MATLAB.
PROGRAM FOR SPECIFIC HEAT FUNCTION:
CODE:
function Cp=Specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,R,Loc_Mid_temp);
STEPS:
- We find the specific heat by creating the specific heat function and assigning its related coefficients from 14 coefficients, gas constant, Temperature and global mid temperature.
- Now we will create the condition using the loop and make the temperature les than and equal to mid temperature to specify for lower temperatures.
- and we use else condition to specify for higher temperatures.
- Then we end the loop of function of specific heat.
PROGRAM FOR ENTROPY FUNCTION:
CODE:
%Entropy calculation
STEPS:
- We find the Entropy by creating the Entropy function and assigning its related coefficients from 14 coefficients, gas constant, Temperature and global mid temperature.
- Now we will create the condition using the loop and make the temperature les than and equal to mid temperature to specify for lower temperatures.
- and we use else condition to specify for higher temperatures.
- Then we end the loop of function of Entropy.
PROGRAM FOR ENTHALPY FUNCTION:
CODE:
%Enthalpy Calculation
STEPS:
- We find the Enthalpy by creating the Enthalpy function and assigning its related coefficients from 14 coefficients, gas constant, Temperature and global mid temperature.
- Now we will create the condition using the loop and make the temperature les than and equal to mid temperature to specify for lower temperatures.
- and we use else condition to specify for higher temperatures.
- Then we end the loop of function of Enthalpy.
PROGRAM FOR MOLECULAR WEIGHT FUNCTION FOR DIFFERENT SPECIES:
CODE:
%Function for Molecular weight
STEPS:
- First we create and Molecular_weight function 'W' and assign the species input to that.
- Then we define the main element of all 53 species in an array atomic_name that are H,C,O,N,Ar.
- The n we by taking the above main elements we create the atomic_weight array from source like internet for 1.008 12.011 15.999 14.007 39.948.
- we assign molecular starting range as 0.
- then create the loop which runs the length of the species and another nested loop for which runs the length of the atomic_name.
- Then we will create the condition using 'if condition' and use 'strcmp' command to compare the species and atomic_name strings to calculate molecular masses if by comparing both string found same them we assign the molecular weight.
- Now we will string the number using 'str2num' command assign to 'n'.
- Then we run the condition of 'if loop' to whether the species contaion more than one element.
- if there are more than 1 element that is n>1 then we will increment the atomic weight by the multiplication of position and n-1 to the atomic_weight array.
- Then we print the MOlecular weight using 'fprintf' command and display it sing 'disp' command.
OUTPUTS AND RESULTS:
Molecular weight ofO : molecular weight O : 15.999000
species n Molecular mass n 15.999000 nMolecular weight ofO2 : molecular weight O2 : 15.999000
Molecular weight ofO2 : molecular weight O2 : 15.999000
species n Molecular mass n 15.999000 nMolecular weight ofH : molecular weight H : 1.008000
Molecular weight ofH : molecular weight H : 1.008000
species n Molecular mass n 1.008000 nMolecular weight ofH2 : molecular weight H2 : 1.008000
Molecular weight ofH2 : molecular weight H2 : 1.008000
species n Molecular mass n 1.008000 nMolecular weight ofOH : molecular weight OH : 17.007000
Molecular weight ofOH : molecular weight OH : 17.007000
species n Molecular mass n 17.007000 nMolecular weight ofH2O : molecular weight H2O : 17.007000
Molecular weight ofH2O : molecular weight H2O : 17.007000
species n Molecular mass n 17.007000 nMolecular weight ofHO2 : molecular weight HO2 : 17.007000
Molecular weight ofHO2 : molecular weight HO2 : 17.007000
species n Molecular mass n 17.007000 nMolecular weight ofH2O2 : molecular weight H2O2 : 17.007000
Molecular weight ofH2O2 : molecular weight H2O2 : 17.007000
species n Molecular mass n 17.007000 nMolecular weight ofC : molecular weight C : 12.011000
Molecular weight ofC : molecular weight C : 12.011000
species n Molecular mass n 12.011000 nMolecular weight ofCH : molecular weight CH : 13.019000
Molecular weight ofCH : molecular weight CH : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH2 : molecular weight CH2 : 13.019000
Molecular weight ofCH2 : molecular weight CH2 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH2(S) : molecular weight CH2(S) : 13.019000
Molecular weight ofCH2(S) : molecular weight CH2(S) : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH3 : molecular weight CH3 : 13.019000
Molecular weight ofCH3 : molecular weight CH3 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH4 : molecular weight CH4 : 13.019000
Molecular weight ofCH4 : molecular weight CH4 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCO : molecular weight CO : 28.010000
Molecular weight ofCO : molecular weight CO : 28.010000
species n Molecular mass n 28.010000 nMolecular weight ofCO2 : molecular weight CO2 : 28.010000
Molecular weight ofCO2 : molecular weight CO2 : 28.010000
species n Molecular mass n 28.010000 nMolecular weight ofHCO : molecular weight HCO : 29.018000
Molecular weight ofHCO : molecular weight HCO : 29.018000
species n Molecular mass n 29.018000 nMolecular weight ofCH2O : molecular weight CH2O : 29.018000
Molecular weight ofCH2O : molecular weight CH2O : 29.018000
species n Molecular mass n 29.018000 nMolecular weight ofCH2OH : molecular weight CH2OH : 30.026000
Molecular weight ofCH2OH : molecular weight CH2OH : 30.026000
species n Molecular mass n 30.026000 nMolecular weight ofCH3O : molecular weight CH3O : 29.018000
Molecular weight ofCH3O : molecular weight CH3O : 29.018000
species n Molecular mass n 29.018000 nMolecular weight ofCH3OH : molecular weight CH3OH : 30.026000
Molecular weight ofCH3OH : molecular weight CH3OH : 30.026000
species n Molecular mass n 30.026000 nMolecular weight ofC2H : molecular weight C2H : 13.019000
Molecular weight ofC2H : molecular weight C2H : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC2H2 : molecular weight C2H2 : 13.019000
Molecular weight ofC2H2 : molecular weight C2H2 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC2H3 : molecular weight C2H3 : 13.019000
Molecular weight ofC2H3 : molecular weight C2H3 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC2H4 : molecular weight C2H4 : 13.019000
Molecular weight ofC2H4 : molecular weight C2H4 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC2H5 : molecular weight C2H5 : 13.019000
Molecular weight ofC2H5 : molecular weight C2H5 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC2H6 : molecular weight C2H6 : 13.019000
Molecular weight ofC2H6 : molecular weight C2H6 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH2CO : molecular weight CH2CO : 41.029000
Molecular weight ofCH2CO : molecular weight CH2CO : 41.029000
species n Molecular mass n 41.029000 nMolecular weight ofHCCO : molecular weight HCCO : 41.029000
Molecular weight ofHCCO : molecular weight HCCO : 41.029000
species n Molecular mass n 41.029000 nMolecular weight ofHCCOH : molecular weight HCCOH : 42.037000
Molecular weight ofHCCOH : molecular weight HCCOH : 42.037000
species n Molecular mass n 42.037000 nMolecular weight ofH2CN : molecular weight H2CN : 27.026000
Molecular weight ofH2CN : molecular weight H2CN : 27.026000
species n Molecular mass n 27.026000 nMolecular weight ofHCN : molecular weight HCN : 27.026000
Molecular weight ofHCN : molecular weight HCN : 27.026000
species n Molecular mass n 27.026000 nMolecular weight ofHNO : molecular weight HNO : 31.014000
Molecular weight ofHNO : molecular weight HNO : 31.014000
species n Molecular mass n 31.014000 nMolecular weight ofN : molecular weight N : 14.007000
Molecular weight ofN : molecular weight N : 14.007000
species n Molecular mass n 14.007000 nMolecular weight ofNNH : molecular weight NNH : 29.022000
Molecular weight ofNNH : molecular weight NNH : 29.022000
species n Molecular mass n 29.022000 nMolecular weight ofN2O : molecular weight N2O : 30.006000
Molecular weight ofN2O : molecular weight N2O : 30.006000
species n Molecular mass n 30.006000 nMolecular weight ofNH : molecular weight NH : 15.015000
Molecular weight ofNH : molecular weight NH : 15.015000
species n Molecular mass n 15.015000 nMolecular weight ofNH2 : molecular weight NH2 : 15.015000
Molecular weight ofNH2 : molecular weight NH2 : 15.015000
species n Molecular mass n 15.015000 nMolecular weight ofNH3 : molecular weight NH3 : 15.015000
Molecular weight ofNH3 : molecular weight NH3 : 15.015000
species n Molecular mass n 15.015000 nMolecular weight ofNO : molecular weight NO : 30.006000
Molecular weight ofNO : molecular weight NO : 30.006000
species n Molecular mass n 30.006000 nMolecular weight ofNO2 : molecular weight NO2 : 30.006000
Molecular weight ofNO2 : molecular weight NO2 : 30.006000
species n Molecular mass n 30.006000 nMolecular weight ofHCNO : molecular weight HCNO : 43.025000
Molecular weight ofHCNO : molecular weight HCNO : 43.025000
species n Molecular mass n 43.025000 nMolecular weight ofHOCN : molecular weight HOCN : 43.025000
Molecular weight ofHOCN : molecular weight HOCN : 43.025000
species n Molecular mass n 43.025000 nMolecular weight ofHNCO : molecular weight HNCO : 43.025000
Molecular weight ofHNCO : molecular weight HNCO : 43.025000
species n Molecular mass n 43.025000 nMolecular weight ofNCO : molecular weight NCO : 42.017000
Molecular weight ofNCO : molecular weight NCO : 42.017000
species n Molecular mass n 42.017000 nMolecular weight ofCN : molecular weight CN : 26.018000
Molecular weight ofCN : molecular weight CN : 26.018000
species n Molecular mass n 26.018000 nMolecular weight ofHCNN : molecular weight HCNN : 41.033000
Molecular weight ofHCNN : molecular weight HCNN : 41.033000
species n Molecular mass n 41.033000 nMolecular weight ofN2 : molecular weight N2 : 14.007000
Molecular weight ofN2 : molecular weight N2 : 14.007000
species n Molecular mass n 14.007000 nMolecular weight ofAR : molecular weight AR : 39.948000
Molecular weight ofAR : molecular weight AR : 39.948000
species n Molecular mass n 39.948000 nMolecular weight ofC3H8 : molecular weight C3H8 : 13.019000
Molecular weight ofC3H8 : molecular weight C3H8 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofC3H7 : molecular weight C3H7 : 13.019000
Molecular weight ofC3H7 : molecular weight C3H7 : 13.019000
species n Molecular mass n 13.019000 nMolecular weight ofCH3CHO : molecular weight CH3CHO : 42.037000
Molecular weight ofCH3CHO : molecular weight CH3CHO : 42.037000
species n Molecular mass n 42.037000 nMolecular weight ofCH2CHO : molecular weight CH2CHO : 42.037000
Molecular weight ofCH2CHO : molecular weight CH2CHO : 42.037000
SCREENSHOT OF WINDOW WHERE ALL FILES ARE SAVED:

PLOTS FOR O2 , N2 AND CO2:
Plot for O2
figure1: Specific heat Vs temperature range

figure2: Entropy Vs temperature range

figure3: Enthalpy vs Temperature range

Plot for N2:
figure1: Specific heat Vs temperature range

figure2: Entropy Vs temperature range

figure3: Enthalpy vs Temperature range

Plot for CO2:
figure1: Specific heat Vs temperature range

figure2: Entropy Vs temperature range

figure3: Enthalpy vs Temperature range

ERRORS FACED DURING THE PROGRAM:
1. Instead of using 'str2num' i have used 'str2double' which is more precise with decimals corrected and faster.
2. In the function of Specific heat, Entropy and Enthalpy i haved not used for loop as temp was 1x1000 but my Cp was just 1x1. So, corrected it using the for loop with i:legth(temp).