Challenge

Project 1 - Parsing NASA thermodynamic data

AIM: 1. Write a function that extracts the 14 coefficients and calculates the enthalpy, entropy, and specific heats for all the species in the data file.file NASA thermodynamic data

OBJECTIVE:

  1. Calculate the molecular weight of each species and display it in the command window
  2. Plot the Cp, Enthalpy, and Entropy for the local temperature range (low temperature: high temperature) specific for each species.
  3. Save the plots as images with appropriate names and dump them in separate folders for each species with a suitable name. All of these should be generated automatically.
  4. The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H, and S plots.
  5. Please write a detailed report to describe your logic.

INTRODUCTION:

  • Molecular Weight

mean molecular weight (defined as the mass per unit mole of. material, or, alternatively, the mean mass of a particle in Atomic. Mass Units). Recall that a mole of any substance contains NA = 6.02252×1023 atoms. Reference ( en.wikipedia.org)

  • Specific Heat

The specific heat is the amount of heat per unit mass required to raise the temperature by one degree Celsius. The relationship between heat and temperature change is usually expressed in the form shown below where c is the specific heat. Reference ( en.wikipedia.org)

  • 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 were added or removed from the substance. Enthalpy is similar to energy, but not the same. Reference ( en.wikipedia.org)

  • Entropy

It is in this sense that entropy is a measure of the energy in a system that cannot be used to do work. An irreversible process degrades the performance of a thermodynamic system, designed to do work or produce cooling, and results in entropy production. The entropy generation during a reversible process is zero. Reference ( en.wikipedia.org)

FORMULA:

Where

R = universal gas constant

T = temperature

GIVEN DATA:

NASA data file = NASA thermodynamic data

it can be used to evaluate thermodynamic properties such as Cp, H, and S. They have also documented the coefficients that are required to evaluate these polynomials for 1000+ species.

CODING SECTION:

code-1: In this, we can extracting NASA data file and try to read this file, it can be used to evaluate thermodynamic properties such as Cp, H, and S

%In this we extracting NASA data file and try to read this file, that can be used to evaluate thermodynamic properties such as Cp, H, and S

close all
clear all
clc

file = fopen('THERMO.dat','r')
%Heading
line1 = fgetl(file)
%Global temperature values
line2 = fgetl(file)
%Next three lines are comments
des_1 = fgetl(file)
des_2 = fgetl(file)
des_3 = fgetl(file)
A = strsplit(line2,' ');
Global_low_temperature = str2num(A{2})
Global_mid_temperature = str2num(A{3})
Global_high_temperature = str2num(A{4})
%species information
for i=1:53
species= fgetl(file);
species_name = species(1:6)
Line_1 = fgetl(file);
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(file);
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(file);
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 each species

%Temperature ranges assumed 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;

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
%plotting
%Temperature vs Entropy
figure(1)
plot(Temperature,S,'linewidth',3,'color','r')
title(species_name)
xlabel('Temperature')
ylabel('Entropy')
%Temperature vs Enthalpy
figure(2)
plot(Temperature,H,'linewidth',4,'color','b')
title(species_name)
xlabel('Temperature')
ylabel('Enthalpy')
%Temperature vs Specific heat
figure(3)
plot(Temperature,Cp,'linewidth',4,'color','k')
title(species_name)
xlabel('Temperature')
ylabel('Specific heat')
 
%saving the plots
saveas(1,'Entropy.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'Specific heat.jpg');
 MM = func_mol(species_name)
end
fclose(file)

Code-2 : function for code-1

function MM = func_mol(species_name)
species = 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(species)
for j=1:length(Constituents)
if strcmp(species(i),Constituents(j))
MM = MM + Atomic_weight(j);
u = j;
end
end
n = str2num(species(i));
if n>1
MM = MM + Atomic_weight(u)*(n-1);
end
end
end

OutPut:

file =

     3


line1 =

    'THERMO'


line2 =

    '   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     '


MM =

   15.9994


species_name =

    'O2    '


MM =

   31.9988


species_name =

    'H     '


MM =

    1.0079


species_name =

    'H2    '


MM =

    2.0159


species_name =

    'OH    '


MM =

   17.0073


species_name =

    'H2O   '


MM =

   18.0153


species_name =

    'HO2   '


MM =

   33.0067


species_name =

    'H2O2  '


MM =

   34.0147


species_name =

    'C     '


MM =

   12.0107


species_name =

    'CH    '


MM =

   13.0186


species_name =

    'CH2   '


MM =

   14.0266


species_name =

    'CH2(S)'


MM =

   14.0266


species_name =

    'CH3   '


MM =

   15.0345


species_name =

    'CH4   '


MM =

   16.0425


species_name =

    'CO    '


MM =

   28.0101


species_name =

    'CO2   '


MM =

   44.0095


species_name =

    'HCO   '


MM =

   29.0180


species_name =

    'CH2O  '


MM =

   30.0260


species_name =

    'CH2OH '


MM =

   31.0339


species_name =

    'CH3O  '


MM =

   31.0339


species_name =

    'CH3OH '


MM =

   32.0419


species_name =

    'C2H   '


MM =

   25.0293


species_name =

    'C2H2  '


MM =

   26.0373


species_name =

    'C2H3  '


MM =

   27.0452


species_name =

    'C2H4  '


MM =

   28.0532


species_name =

    'C2H5  '


MM =

   29.0611


species_name =

    'C2H6  '


MM =

   30.0690


species_name =

    'CH2CO '


MM =

   42.0367


species_name =

    'HCCO  '


MM =

   41.0287


species_name =

    'HCCOH '


MM =

   42.0367


species_name =

    'H2CN  '


MM =

   28.0333


species_name =

    'HCN   '


MM =

   27.0253


species_name =

    'HNO   '


MM =

   31.0140


species_name =

    'N     '


MM =

   14.0067


species_name =

    'NNH   '


MM =

   29.0213


species_name =

    'N2O   '


MM =

   44.0128


species_name =

    'NH    '


MM =

   15.0146


species_name =

    'NH2   '


MM =

   16.0226


species_name =

    'NH3   '


MM =

   17.0305


species_name =

    'NO    '


MM =

   30.0061


species_name =

    'NO2   '


MM =

   46.0055


species_name =

    'HCNO  '


MM =

   43.0247


species_name =

    'HOCN  '


MM =

   43.0247


species_name =

    'HNCO  '


MM =

   43.0247


species_name =

    'NCO   '


MM =

   42.0168


species_name =

    'CN    '


MM =

   26.0174


species_name =

    'HCNN  '


MM =

   41.0320


species_name =

    'N2    '


MM =

   28.0134


species_name =

    'AR    '


MM =

   39.9480


species_name =

    'C3H8  '


MM =

   44.0956


species_name =

    'C3H7  '


MM =

   43.0877


species_name =

    'CH3CHO'


MM =

   44.0526


species_name =

    'CH2CHO'


MM =

   43.0446



>> 

Error1: I'm unable to show all folder because I use Matlab online In this having some trouble

Error2: I forgot to type "." Temperature^2+c4 after correction Temperature.^2+c4

Error : 3 this type of error comes because I type wrong command f1getl but the right command is fgetl

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.