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 program in MATLAB for parsing NASA thermodynamics data. OBJECTIVE : 1. Making of a MATLAB code to extracts 14 coefficients by reading NASA Polynomial format as a .dat file. 2. From the given DATA file calculating Molecular weight of each species…
Sourabh Lakhera
updated on 16 Jun 2020
AIM : -To write a program in MATLAB for parsing NASA thermodynamics data.
OBJECTIVE :
1. Making of a MATLAB code to extracts 14 coefficients by reading NASA Polynomial format as a .dat file.
2. From the given DATA file calculating Molecular weight of each species and display it as a result
3. To plot the Cp, Enthalpy and Entropy for the local temperature range specific for each species save the plots as images with appropriate names and dump them in separate folder.
THEORY : -
Thermodynamic data for individual species are necessary for performing equilibrium chemistry and finite-rate chemical kinetics calculations. These data typically provide the thermodynamic properties (enthalpy, entropy, and specific heat) of a species as a function of temperature. Thermodynamic data for individual species are required in many applications involving chemical reactions. For over 50 years the NASA Lewis (now Glenn) Research Center has been compiling and disseminating thermodynamic data for use in its chemical equilibrium programs. These data, widely used by the thermodynamic community, have grown from 42 species to the current 2000. For calculation purposes, the use of thermodynamic data in the form of simple empirical equations has some obvious advantages. First, it makes tabular interpolations unnecessary; second, it permits analytical integrations; and, third, it condenses all the tabulated information into a few constants that accurately reproduce the many thermodynamic data points.
Another sample :-
EQUATIONS
The NASA polynomials have the form:
Specific heat(Cp): :
Cp=(a1+a2⋅T+a3⋅T2+a4⋅⋅T3+a5⋅T4)⋅R
Specific heat, ratio of the quantity of heat required to raise the temperature of a body one degree to that required to raise the temperature of an equal mass of water one degree. The term is also used in a narrower sense to mean the amount of heat, in calories, required to raise the temperature of one gram of a substance by one Celsius degree.
Enthalpy(H) :
Enthalpy, a property of a thermodynamic system, is the sum of the system's internal energy and the product of its pressure and volume. In a system contained so as to prevent mass transfer, for processes at constant pressure, the heat absorbed or released equals the change in enthalpy.
H=R⋅T⋅(a1+a2⋅T2+(a3⋅T23+a4⋅T34+a5⋅T45+a6T)
Entropy
Entropy, the measure of a system's thermal energy per unit temperature that is unavailable for doing useful work. Because work is obtained from ordered molecular motion, the amount of entropy is also a measure of the molecular disorder, or randomness, of a system.
S=R⋅(a1⋅log(T)+a2⋅T+a3⋅T22+a4⋅T33+a5⋅T44+a7)
Here , a1,a2,a3,a4,a5,a6 and a7 are coefficients given in the NASA thermodynamic files.
The first 7 numbers starting on the second line of each species entry are the seven coefficients (a1 through a7, respectively) for the high-temperature range (above 1000 K). The following seven numbers are the coefficients (a1 through a7, respectively) for the low-temperature range (below 1000 K).
MATLAB PROGRAM
clear all
close all
clc
% change format of integer to long
format long
% Setting folder to use and save data
OutputFolder = ('Z:\IMPORTANT\local H\GENERAL STUDY\ONLINE LEARNING MODULE\SKILL LYNC\MATLAB FOR MECHANICAL\last week and final submit\PROJECT 1');
ProgramFolder = pwd;
% Open file contains data i.e locaton of parsing file
fileID = fopen('Z:\IMPORTANT\local H\GENERAL STUDY\ONLINE LEARNING MODULE\SKILL LYNC\MATLAB FOR MECHANICAL\last week and final submit\PROJECT 1\THERMO.dat');
%% Get Header (that has to be obselate)
Header = fgetl(fileID);
%Obtaining Temperature ranges according to min,mid and high
TempRange = fgetl(fileID);
lowestT = str2double(TempRange(1,1:10));
commonT = str2double(TempRange(1,11:20));
highestT = str2double(TempRange(1,21:30));
fileComment='';
%% Get data information and comments
while(1)
comment = fgetl(fileID);
fileComment = strcat(fileComment,' ',comment);
next = fgetl(fileID);
if (next(1,1) ~= '!')
fseek(fileID, -(length(next)+1), 0);
break
end
fseek(fileID, -(length(next)+1), 0);
end
%% Now extracting data 1 by 1 from the data file
while(1)
% Extract data from line1
line1 = fgetl(fileID);
[SpeciesName,Date,AtomicSymbolsAndFormula,Phase,LowTLoc,HighTLoc,CommonTLoc,optAtomicSymbolsAndFormula,Integer] = ExtractLine1(line1);
% Calculate molecular Weight
molecularWeight = calcMolecularWeight(SpeciesName);
% Extract data from line2
line2 = fgetl(fileID);
[a1, a2, a3, a4, a5] = ExtractLine23(line2);
% Extract data from line3
line3 = fgetl(fileID);
[a6, a7, a8, a9, a10] = ExtractLine23(line3);
% Extract data from line4
line4 = fgetl(fileID);
[a11, a12, a13, a14] = ExtractLine4(line4);
% Inputs to Generate thermodynamic data
TemperatureRangeLoc = [LowTLoc; HighTLoc; CommonTLoc];
coefficients = [a1; a2; a3; a4; a5; a6; a7; a8; a9; a10; a11; a12; a13; a14];
% Generate thermodynamic data
[Cp, H, S, Temperature] = CalcThermoProp(coefficients,TemperatureRangeLoc);
% Check for 'END' to complete parsing
next = fgetl(fileID);
if (strcmp(next,'END'))
disp('***Hurray SUCCESSFULL : Parsing THERMO Data COMPLETED***')
break
end
fseek(fileID, -(length(next)+1), 0);
% set folder to OutputFolder
mkdir(OutputFolder,SpeciesName);
SpeciesFolder = strcat(OutputFolder,'',SpeciesName);
cd(SpeciesName);
% plot Temperature vs Cp
figure(1)
plot(Temperature,Cp);
xlabel('Temperature in [K]');
ylabel('Cp in [J/(mol K)]');
title(strcat(SpeciesName,'-','Temperature vs Cp'));
saveas(gcf,'Temperature vs Cp','jpeg')
% plot Temperature vs Enthalpy
plot(Temperature,H);
xlabel('Temperature in [K]');
ylabel('Enthalpy in [J]');
title(strcat(SpeciesName,'-','Temperature vs Enthalpy'));
saveas(gcf,'Temperature vs Enthalpy','jpeg')
% plot Temperature vs Entropy
plot(Temperature,S);
xlabel('Temperature in [K]');
ylabel('Entropy in [J/K]');
title(strcat(SpeciesName,'-','Temperature vs Entropy '));
saveas(gcf,'Temperature vs Entropy ','jpeg')
% set folder to ProgramFolder
cd(ProgramFolder);
end
SOME SUB-FUNCTION THAT IS INVOLVED IN THE MAIN FUNCTION :-
%% data extration from Line 1
function [SpeciesName,Date,AtomicSymbolsAndFormula,Phase,LowT,HighT,CommonT,optAtomicSymbolsAndFormula,LineInteger] = ExtractLine1(line)
SpeciesName = strtrim(line(1,1:18));
Date = strtrim(line(1,19:24));
AtomicSymbolsAndFormula = strtrim(line(1,25:44));
Phase = strtrim(line(1,45));
LowT = str2double(line(1,46:55));
HighT = str2double(line(1,56:65));
CommonT = str2double(line(1,66:75));
optAtomicSymbolsAndFormula = strtrim(line(1,76:79));
LineInteger = str2double(line(1,80));
end
%% data extraction from Line2 and Line3
function [a1, a2, a3, a4, a5] = ExtractLine23(line)
a1 =str2double(line(1,1:15));
a2 =str2double(line(1,16:30));
a3 =str2double(line(1,31:45));
a4 =str2double(line(1,46:60));
a5 =str2double(line(1,61:75));
end
%% data extraction from Line4
function [a1, a2, a3, a4] = ExtractLine4(line)
a1 = str2double(line(1,1:15));
a2 = str2double(line(1,16:30));
a3 = str2double(line(1,31:45));
a4 = str2double(line(1,46:60));
end
%% function to calculate thermodynamic properties such as Cp, H and S
function [Cp, H, S, Temperature] = CalcThermoProp(coefficients,TemperatureRangeLoc);
% inputs
R = 1.987; % The gas constant R in J / mol·K
% set Temperature Range
LowTLoc = TemperatureRangeLoc(1,1);
HighTLoc = TemperatureRangeLoc(2,1);
loopCount = 1;
for i=LowTLoc:10:HighTLoc
T = i;
%
if (T>1000)
% high-temperature range (above 1000 K).
a1 = coefficients(1,1);
a2 = coefficients(2,1);
a3 = coefficients(3,1);
a4 = coefficients(4,1);
a5 = coefficients(5,1);
a6 = coefficients(6,1);
a7 = coefficients(7,1);
else
% low-temperature range (below 1000 K).
a1 = coefficients(8,1);
a2 = coefficients(9,1);
a3 = coefficients(10,1);
a4 = coefficients(11,1);
a5 = coefficients(12,1);
a6 = coefficients(13,1);
a7 = coefficients(14,1);
end
% Calculate the enthalpy, entropy and specific heat
Cp(loopCount) = (a1 + a2*T + a3*T^2 + a4*T^3 + a5*T^4)*R;
H(loopCount) = R*T*(a1 + (a2*T)/2 + (a3*T^2)/3 + (a4*T^3)/4 + (a5*T^4)/5 + a6/T);
S(loopCount) = R*(a1*log(T) + a2*T + (a3*T^2)/2 + (a4*T^3)/3 + (a5*T^4)/4 + a7);
Temperature(loopCount) = T;
loopCount = loopCount + 1;
end
end
%% Code to Extract molecular weight from chemical formula of 'H C N O A' atoms from DATA file
function [molecularWeight] = calcMolecularWeight(SpeciesName)
% To make search cases depending upon the species
SpeciesName = upper(SpeciesName);
% Atomic symbols and atomic weight Respectiely
AtomicSymbols = {'H','C','N','O','A'};
atomicWeight = [1 12 14 16 40];
% initializing molecularWeight with zero;
molecularWeight = 0;
% Calculating molecularWeight
for i = 1:length(SpeciesName)
% Calculating molecularWeight from atom character in chemical formula
for j = 1:length(AtomicSymbols)
if strcmp(SpeciesName(i),AtomicSymbols(j))
molecularWeight = molecularWeight + atomicWeight(j);
x = j;
% Storing last calculated atom character in chemical formula
end
end
n = str2double(SpeciesName(i));
% Calculating molecularWeight from atom count in chemical formula
if (isletter(SpeciesName(i))==0)
molecularWeight = molecularWeight + atomicWeight(x)*(n-1);
end
end
% display Molecular Weight
disp(sprintf('MolecularWeight of %10s is %d amu',SpeciesName,molecularWeight));
end
Arrangement Steps-
Result and Conclusions :-
Some sample results are as follows : -
For NH3 :-
FOR C : -
Finally we can conclude that the thermodynamic data was sucessfully extracted and plot of all thermodynamic properties such as Enthalpy,Entropy, and Specific Heat as shown above.
Error :-
=R⋅T⋅(a1+a2⋅T2+a3⋅T23+a4⋅T34+a5⋅T45+a6T)
Cp=(a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4)⋅R
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 1 - Data Cleaning and Transformation using Pivot table and Charts for the Report on requirement of Team Hiring
Project Documentation: Optimizing Team Hiring Insights through Data Cleaning and TransformationIntroductionIn today's data-driven environment, businesses thrive on informed decision-making. At ABC Private Limited, a manufacturer and seller of diverse products ranging from Classic Cars to Trucks and Buses, understanding…
26 Sep 2024 02:54 PM IST
Project 2
Project Documentation: Alumni Career Choices AnalysisAimThe aim of this project is to analyze the career choices of alumni from two universities with respect to their passing year and the courses they completed. This analysis helps in understanding the career growth of alumni, which plays a crucial role in the institute's…
10 Jul 2024 08:03 AM IST
Project 1
From the series of queries and actions conducted on the ecommerce database, several insights can be derived regarding the user demographics and their activities on the platform. Firstly, the database contains information about users' demographics, such as their gender, country, language, and usage of applications like…
28 Feb 2024 07:45 PM IST
Project 2 - EDA on Vehicle Insurance Customer Data
EDA on Vehicle Insurance Customer Data Aim: The aim of this project is to perform exploratory data analysis (EDA) and data cleaning on two datasets containing customer details and policy details. The objective is to prepare the data for future analysis and modeling, identify patterns, and derive insights to aid business…
19 Feb 2024 08:36 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.