All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To write a code in Matlab to parse the NASA thermodynamic file. OBJECTIVE: To write a function that extracts 14 coefficient for a given species. Calculate the entropy, enthalpy and specific heat using NASA polynomials for the given species. Plot Cp, entropy…
Akash M
updated on 10 Jul 2021
AIM:
To write a code in Matlab to parse the NASA thermodynamic file.
OBJECTIVE:
To write a function that extracts 14 coefficient for a given species.
Calculate the entropy, enthalpy and specific heat using NASA polynomials for the given species.
Plot Cp, entropy and enthalpy of input species.
Calculate molecular weight of each species.
THEORY:
FILE PARSING:
File parsing is done to extract data from the file, it should be generic as possible to fetch the data and by using this we calculate enthalpy, entropy and specific heat for different species and condition is that the first 7 coefficients are high temperature coefficients and the second set of 7 coefficients are low temperature coefficients. Parsing can be defined as breaking the data block into smaller blocks by following a set of order. So that it can be more easily interpreted, managed and sent to computer NASA came up with the polynomials that can be used to evaluate thermodynamic properties such as entropy, enthalpy and specific heat using polynomials
SPECIFIC HEAT(Cp):
It is the amount of energy that must be added, in the form of heat, to one unit of mass of the substance in order to cause an increase of one unit in its temperature. Specific heat is the thermodynamic property, which states the amount of heat required for a single unit of mass of a substance to be raised by one degree of temperature . Varying ranges of specific heat values are seen for substances depending on the extend to which they absorb heat. The term heat capacity can be misleading since heat q is the term given to the addition or removal of energy.
ENTHALPY:
Enthalpy is a concept used in science and engineering when heat and work need to be calculated. When a substance changes at constant pressure, enthalpy tells how much heat and work was added or removed from the substance. Enthalpy, a property of a thermodynamic system, is equal to the system's internal energy plus the product of its pressure and volume.
ENTROPY:
Entropy is an extensive property of a thermodynamic system. It is closely related to the number Ω of microscopic configurations(known as miscrostates) that are constant with the macroscopic quantities that characterize the system (such as its volume, pressure and temperature). The entropy of an object is a measure of the amount of energy which is unavailable to do work. Entropy is also a measure of the number of possible arrangements the atoms in a system can have.
MOLECULAR WEIGHT:
The molecular mass is the mass of a given molecule. It is measured in daltons. Different molecules of the same compound may have different molecular masses bacause they have contain different isotopes of an element.
FORMULA:
Cp - specific heat (J/Kg.k)
H - enthalpy (J)
S - Entropy (J/K)
R - Universal gas constant (J/mol.K)
T - Temperature (K)
PROGRAM:
clear all
close all
clc
f1 = fopen('THERMO.dat','r');
for i = 1:5
tline = fgetl(f1);
end
for i = 1:53;
tline1 = fgetl(f1);
splitline1 = strsplit(tline1,' ');
species = char(splitline1(1));
dot = strfind(tline1,'.');
low_local_temp = str2double(tline1(49:51));
high_local_temp = str2double(tline1(58:61));
mid_local_temp = str2double(tline1(68:71));
tline2 = fgetl(f1);
a = strfind(tline2,'E');
a1 = str2double(tline2(1:(a(1)+3)));
a2 = str2double(tline2((a(1)+4):(a(2)+3)));
a3 = str2double(tline2((a(2)+4):(a(3)+3)));
a4 = str2double(tline2((a(3)+4):(a(4)+3)));
a5 = str2double(tline2((a(4)+4):(a(5)+3)));
tline3 = fgetl(f1);
b = strfind(tline3,'E');
a6 = str2double(tline3(1:(b(1)+3)));
a7 = str2double(tline3((b(1)+4):(b(2)+3)));
a8 = str2double(tline3((b(2)+4):(b(3)+3)));
a9 = str2double(tline3((b(3)+4):(b(4)+3)));
a10 = str2double(tline3((b(4)+4):(b(5)+3)));
tline4 = fgetl(f1);
c = strfind(tline4,'E');
a11 = str2double(tline4(1:(c(1)+3)));
a12 = str2double(tline4((c(1)+4):(c(2)+3)));
a13 = str2double(tline4((c(2)+4):(c(3)+3)));
a14 = str2double(tline4((c(3)+4):(c(4)+3)));
%calling molecular function
Molecular_weight = molecular(species);
sprintf('Molecular_weight of %s=%d',species,Molecular_weight)
R = 8.314;
temp = linspace(low_local_temp, high_local_temp, 100);
if temp > mid_local_temp
cp = R*(a1 + a2*(temp) + a3*((temp).^2) + a4*((temp).^3) + a5*((temp).^4));
H = (R*temp).*(a1 + (a2*temp/2) + (a3*(temp.^2)/3) + (a4*(temp.^3)/4) + (a5*(temp.^4)/5) + (a6*(temp)));
S = R*(a1*log(temp) + a2*(temp) + ((a3*(temp).^2)/2) + ((a4*(temp).^3)/3) + ((a5*(temp).^4)/4) + a7);
else
cp = R*(a8 + a9*(temp) + a10*((temp).^2) + a11*((temp).^3) + a12*((temp).^4));
H= (R*temp).*((a8 +(a9*temp/2))+ ((a10*(temp).^2)/3) + ((a11*(temp).^3)/4)+((a12*(temp).^4)/5) + (a13*(temp)));
S = R*(a8*log(temp) + a9*(temp) + ((a10*(temp).^2)/2) + ((a11*(temp).^3)/3) + ((a12*(temp).^4)/4) + a14);
end
t=sprintf('%s',species);
mkdir(t)
cd(t)
% plot cp vs temperature
figure(1)
plot(temp,cp,'linewidth',2);
xlabel('Temperature(K)');
ylabel('Specific heat(J/mol.K)');
title(['Temperature vs Specific heat for species ',species]);
saveas(gcf,'cp.jpg');
% plot H vs temperature
figure(2)
plot(temp,H,'linewidth',2);
xlabel('Temperature(K)');
ylabel('Enthalpy(J)');
title(['Temperature vs Enthalpy for species ',species]);
saveas(gcf,'H.jpg');
% plot cp vs temperature
figure(3)
plot(temp,S,'linewidth',2);
xlabel('Temperature(K)');
ylabel('Entropy(J/K)');
title(['Temperature vs Entropy for species ',species]);
saveas(gcf,'S.jpg');
cd ..
end
FUNCTION CODE:
function Molecular_weight = molecular(species)% calculating molecular weight
% Atoms available in data file
A = ['H','C','O','N','R','S'];
% Atomic weight of the molecules
A_W = [1.00784 12.0107 15.999 14.0067 39.948 32.065];
Molecular_weight = 0;
% converting string cells into character
for i = 1:length(species);
for j = 1:length(A_W);
if strcmp(species(i),A(j));
Molecular_weight = Molecular_weight + A_W(j);
p = j;
end
end
n = str2double(species(i));
if n>1
Molecular_weight = Molecular_weight + A_W(p)+(n-1);
end
end
end
PROCEDURE:
Read THERMO.DAT file to calculate enthalpy, entropy, specific heat.
To read the file assign the variable called f in order to get data with respect to the global temperature, local temperature and calculation of coefficients thermodynamic properties.
Use fgetl command to acces the next line.
First value of temperature is converted with the help of str2double command so that the number in a string can be converted into number.
Use fgetl command again to get the values from line2. Now we have to extract the 14 coefficent by using the command strfind.
By using the str2double commad we can find 14 coefficients for all the species.
The first seven species are high temperature coefficient and next seven coefficient are lower temperatures.
To find temperture ranges use linspace command and then calculate Cp,H and S for lower and higher temperature limits.
Assume, universal gas constant (R) = 8.134J/mol.K
Plot the graph for specific heat, enthalpy and entropy vs temperature by using plot command.
To save the graphs of al the species use saveas command.
Calculate the molecular weight for all the species by using calling the function.
RESULTS:
Plot cp, Enthalpy and Entropy for the temperature range for each species
Plot for O2:
Plot for N2:
Plot for CO2:
Save the plot as images with appropriate names and store them in seperate folders for each species with respective names.
MOLECULAR WEIGHTS:
ans =
'Molecular_weight of O=1.599900e+01'
ans =
'Molecular_weight of O2=3.299800e+01'
ans =
'Molecular_weight of H=1.007840e+00'
ans =
'Molecular_weight of H2=3.015680e+00'
ans =
'Molecular_weight of OH=1.700684e+01'
ans =
'Molecular_weight of H2O=1.901468e+01'
ans =
'Molecular_weight of HO2=3.400584e+01'
ans =
'Molecular_weight of H2O2=3.601368e+01'
ans =
'Molecular_weight of C=1.201070e+01'
ans =
'Molecular_weight of CH=1.301854e+01'
ans =
'Molecular_weight of CH2=1.502638e+01'
ans =
'Molecular_weight of CH2(S)=4.709138e+01'
ans =
'Molecular_weight of CH3=1.602638e+01'
ans =
'Molecular_weight of CH4=1.702638e+01'
ans =
'Molecular_weight of CO=2.800970e+01'
ans =
'Molecular_weight of CO2=4.500870e+01'
ans =
'Molecular_weight of HCO=2.901754e+01'
ans =
'Molecular_weight of CH2O=3.102538e+01'
ans =
'Molecular_weight of CH2OH=3.203322e+01'
ans =
'Molecular_weight of CH3O=3.202538e+01'
ans =
'Molecular_weight of CH3OH=3.303322e+01'
ans =
'Molecular_weight of C2H=2.602924e+01'
ans =
'Molecular_weight of C2H2=2.803708e+01'
ans =
'Molecular_weight of C2H3=2.903708e+01'
ans =
'Molecular_weight of C2H4=3.003708e+01'
ans =
'Molecular_weight of C2H5=3.103708e+01'
ans =
'Molecular_weight of C2H6=3.203708e+01'
ans =
'Molecular_weight of CH2CO=4.303608e+01'
ans =
'Molecular_weight of HCCO=4.102824e+01'
ans =
'Molecular_weight of HCCOH=4.203608e+01'
ans =
'Molecular_weight of H2CN=2.903308e+01'
ans =
'Molecular_weight of HCN=2.702524e+01'
ans =
'Molecular_weight of HNO=3.101354e+01'
ans =
'Molecular_weight of N=1.400670e+01'
ans =
'Molecular_weight of NNH=2.902124e+01'
ans =
'Molecular_weight of N2O=4.501240e+01'
ans =
'Molecular_weight of NH=1.501454e+01'
ans =
'Molecular_weight of NH2=1.702238e+01'
ans =
'Molecular_weight of NH3=1.802238e+01'
ans =
'Molecular_weight of NO=3.000570e+01'
ans =
'Molecular_weight of NO2=4.700470e+01'
ans =
'Molecular_weight of HCNO=4.302424e+01'
ans =
'Molecular_weight of HOCN=4.302424e+01'
ans =
'Molecular_weight of HNCO=4.302424e+01'
ans =
'Molecular_weight of NCO=4.201640e+01'
ans =
'Molecular_weight of CN=2.601740e+01'
ans =
'Molecular_weight of HCNN=4.103194e+01'
ans =
'Molecular_weight of N2=2.901340e+01'
ans =
'Molecular_weight of AR=3.994800e+01'
ans =
'Molecular_weight of C3H8=3.503708e+01'
ans =
'Molecular_weight of C3H7=3.403708e+01'
ans =
'Molecular_weight of CH3CHO=4.504392e+01'
ans =
'Molecular_weight of CH2CHO=4.404392e+01'
>>
CONCLUSION:
The file parsing of NASA thermodynamic data includes several models and we coverted them all into useful form, plotting the relations and saving them automatically into current location. The different plot for each species shows the relation between thermodynamic properties such as specific heat, enthalpy and entropy with respect to temperature.
Error faced :
I put M_w instead of Molecular_weight.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project - 2 - Generating the report for hypermesh file
Aim: To generate the report for hypermesh file Objective: To create an ergonomic and visually appealing excel (.xlsm) report that contains following information about your model: User name, date, time Profile/deck; count of component, prop, material, elements Count of empty comp/prop/mats Elements…
20 Dec 2021 07:48 AM IST
Project 1- Building a Master TCL/TK Macro
Aim: To create a master TCL/TK macro that performs several operations such as finding and correcting normals, final checks, creating components, reflecting geometry, creating connections and identify identical components. Objective: It should contain buttons that will call all utilities created as assignments during…
10 Dec 2021 05:13 AM IST
Week - 9 - Reflecting the geometry
Aim: To create a code that performs reflecting the geometry Objective: Create a macro that will reflect given multicomponent FE part with ease It should be independent of deck The inputs should be original CAD comp, reflected CAD comp and original FE comps …
07 Dec 2021 03:01 PM IST
Week - 12 - Creating the locator, writing and reading the node data
Aim: To create a code that performs connections, identify the identical components and reading nodes from a file. Objective: Create a macro that builds a GUI containing 4 buttons. Component creator, weld, xloc, yloc, zloc. Upon pressing the buttons corresponding 1D element must be created…
07 Dec 2021 12:35 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.