Challenge

Project 1 - Parsing NASA thermodynamic data

Introduction

Aim

To evaluate thermodynamic properties such as specific heat (cp), enthalpy (h), and entropy (S) from the NASA file for different spices with higher to lower temperatures and plot the Temperature vs thermodynamic properties for different spices in different folders.

Specific heat (CP)

specific heat, the quantity of heat required to raise the temperature of one gram of a substance by one Celsius degree. The units of specific heat are usually joules per gram per Celsius degree.

Q=mcp(T2-T1)

cp=Q/m(T2-T1)

Formula

In polynomial form

`Cp=(a1+a2T+a3T^2+a4T^3+a5T^4)*R`

Enthalpy (h)

enthalpy, the sum of the internal energy and the product of the pressure and volume of a thermodynamic system. Enthalpy is an energy-like property or state function—it has the dimensions of energy ( measured in units of joules), and its value is determined entirely by the temperature, pressure, and composition of the system.

H = E + PV.

enthalpy = H,

Internal energy = E

Pressure= P

volume= V

the amount of heat released or absorbed by a reaction when any work being done is PV work occurring at constant pressure.

Formula

In polynomial term

`H=(a1+a2T/2+a3T^2/3+a4T^3/4+a5T^4/5+a6/T)*RT`

Entropy (S)

a measure of the unavailable energy in a closed thermodynamic system that is also usually considered to be a measure of the system's disorder, that is a property of the system's state, and that varies directly with any reversible change in heat in the system and inversely with the temperature of the system

the degree of disorder or uncertainty in a system

`S=cp ln((T2)/(T1)),S=cpln((p2)/(p1))`

Formula

In polynomial term

`S=(a1InT+a2T+a3T^2/2+a4T^3/3+a5T^4/4+a7)*R`

Molecular weight

the molar mass of a chemical component is defined as the mass of a sample of that compound divided by the amount of substant in that sample, measured in moles.

The mole was defined in such a way that the molar mass of a compound, in g/mol, is numerically equal (for all practical purposes) to the average mass of one molecule.

Example

CH2CHO

molecules

C= 2, H=3, O=1

molecule weight

molecules * weight of each molecule

mw=(2*12)+(3*1)+(1*16)

the molecular weight of CH2CHO=43 g/mole

where

Universal gas constant

R=8.314 J/mol.k

a1...a7= polynomial co-efficient

T= Temperature

MATLAB

Main Program

clear all;
close all;
clc;

%opening Thermo.dat file and reading it
a=fopen('THERMO.dat','r')

%skipping header infomation
fgetl(a);

%reading global temperature
GT_str=fgetl(a);
% spliting global temperature
GT=strsplit(GT_str, ' ');

% lower temperature
LT=str2num(GT{end-2});
% medium temperature
MT=str2num(GT{end-1});
% higher temperature
HT=str2num(GT{end});


% skipping 3 line
for i=1:3
    fgetl(a)
end

% species numbers representing 
n=53; 

for i=1:n
%extrating species data
   s=fgetl(a);
   s_split=findstr(s, ' ');
   s_name=s(1:s_split(1));

   
%get local temperature from species line
    %Local Low Temperature
    b=findstr(s, '.');
    LLT = str2num(s(b(1)-3:b(1)+3));
    %Local High Temperature
    LHT = str2num(s(b(2)-4:b(2)+4));
    %Local Medium Temperture
    LMT= str2num(s(b(3)-4:b(3)+4));
   
% extracting temperature data   
    l1=fgetl(a); % second line polynomial value
    l2=fgetl(a); % third line polynomial value
    l3=fgetl(a); % fouth line polynomial value
    
% call co-efficient value function    
    [LC HC] = coef(l1,l2,l3);
    
% setting Boundaries for lower & higher temperature
    LTB= LLT:LMT;
    HTB= LMT:LHT;
    
%Cp,H,S value function
% higher temperature
    [cp_high,H_high,S_high] = TDC(HC,HTB);
%lower temperature
    [cp_low,H_low,S_low] = TDC(LC,LTB);
    
% molicular weight
w =molecular_weight(s_name);


 % making director to save file 
 mkdir(s_name)
 % make current directory
 cd(sprintf(s_name))


 % plotting specific heat vs Temperature
figure(1);
plot(LTB,cp_low,'b',HTB,cp_high,'r','linewidth',2);
title({'specific heat vs temperature',['species name=',s_name,'& molecular weight=',num2str(w),'u']});
xlabel('Temperature (k)');
ylabel('specific heat (j/kgk)');
legend('lower temperature value','higher temperature value','Location','best');
grid on;
saveas(figure(1),'cpvsTemp.jpeg');

 % plotting enthalphy vs Temperature
figure(2);
plot(LTB,H_low,'m',HTB,H_high,'g','linewidth',2);
title({'enthalpy vs temperature',['species name=',s_name,'& molecular weight=',num2str(w),'u']});
xlabel('Temperature (k)');
ylabel('enthalphy (j/kg)');
legend('lower temperature value','higher temperature value','Location','best');
grid on;
saveas(figure(2),'enthalpyvsTemp.jpeg');

 % plotting entropy vs Temperature
figure(3);
plot(LTB,S_low,'c',HTB,S_high,'k','linewidth',2);
title({'specific heat vs temperature',['species name=',s_name,'& molecular weight=',num2str(w),'u']});
xlabel('Temperature (k)');
ylabel('entropy(j/k)');
legend('lower temperature value','higher temperature value','Location','best');
grid on;
saveas(figure(3),'entropyvsTemp.jpeg');

% on level up command directory
cd('..')


% printing molecular weight
 sprintf('molecular weight of %s is %f u',s_name,w)

end



% main program

Commands

  1. fopen and r for reading files using variable
  2. reading file fgetl command consistent giving command can read next line continuously
  3. strsplit split the line with where it represents
  4. str2num to change the string to number
  5. findstr to find the string with specified
  6. mkdir create folder
  7. cd make as command directory
  8. Function creation with input & output condition
  9. plot result

Procedure

  • Import THERMO.dat using the 1st command and read in 'a' as a variable which is used for further
  • skipping header information using 2nd command
  • again reading with variable GT_str to read global temperature using 2nd command
  • split global temperature using 3rd command where space is given
  • converting string to a number using the 4th command and extracting the global temperature with a specified position
  • HT at the last variable inline
  • MT at last before variable inline
  • LT first position variable inline
  • skip in a loop using 2nd command
  • creating variables to solve the number of species in the loop
  • function import inside the loop to extract the variable
  • using the 6th command save in species name
  • getting inside species name using 7th command
  • create and save plot in respected figure with higher and lower temperature output

Function Program

CO-efficient Function

function [LC HC] = coef(l1,l2,l3)
%extracting higher co-efficient
al_H = str2num(l1(1:15));
a2_H = str2num(l1(16:30));
a3_H = str2num(l1(31:45));
a4_H = str2num(l1(46:60));
a5_H = str2num(l1(61:75));
a6_H = str2num(l2(1:15));
a7_H = str2num(l2(16:30));

%extracting lower co-efficient
a1_L= str2num(l2(31:45));
a2_L= str2num(l2(46:60));
a3_L= str2num(l2(61:75));
a4_L= str2num(l3(1:15));
a5_L= str2num(l3(16:30));
a6_L= str2num(l3(31:45));
a7_L= str2num(l3(46:60));

% arrange higher co-efficient
HC=[al_H,a2_H,a3_H,a4_H,a5_H,a6_H,a7_H];

% arrange lower co-efficient
LC=[a1_L,a2_L,a3_L,a4_L,a5_L,a6_L,a7_L];

end

% save co-efficient function file

creating a co-efficient function by extracting High Co-efficient (HC) first 7 co-efficient, Lower co-efficient (LC) rest 7 co-efficient inline extracted (l1,l2,l3) and assigning a variable with HC,LC

ThermoDynamic State calculation

function [Cp,H,S]= TDS(coef,t)
% extracting temperature and co-efficient value calculate output as CP H S

%gas constant R=8.314 j/mol.k
R=8.314;

% assign co-efficient values
a1=coef(1);
a2=coef(2);
a3=coef(3);
a4=coef(4);
a5=coef(5);
a6=coef(6);
a7=coef(7);

%calculating values
for i=1:length(t);
T=t(i);

%calculating specific heat Cp
Cp(i)= (a1+a2*T+a3*(T^2)+a4*(T^3)+a5*(T^4))*R;

%calculating Enthalphy H
H(i)= (a1+a2*T/2+a3*(T^2)/3+a4*(T^3)/4+a5*(T^4)/5+a6/T)*R*T;

%calculating Entropy S
S(i)= (a1*log(T)+a2*T+a3*(T^2)/2+a4*(T^3)/3+a5*(T^4)/4+a7)*R;
end

%save cp,H,S formula Function as TDC

CP

`Cp=(a1+a2T+a3T^2+a4T^3+a5T^4)*R`

H

`H=(a1+a2T/2+a3T^2/3+a4T^3/4+a5T^4/5+a6/T)*RT`

S

`S=(a1InT+a2T+a3T^2/2+a4T^3/3+a5T^4/4+a7)*R`

solve cp, H, S by using the polynomial formula by assigning a1...a7 assign as co-efficient value with a range of temperature lower and higher

molecular weight

function w =molecular_weight(s_name)
%molecular formula from single molecular to output molecular


% Atoms Element
E=['H','O','N','C','S','Ar'];
% Atomic weight
AW=[1,16,14,12,32,40];

%calculation of molecular weight
w=0;

for i=1:length(s_name)
    for j=1:length(AW)
        if strcmp(s_name(i),E(j))
           w=w+AW(j);
           p=j;
        end
    end
    n=str2double(s_name(i));
    if n>1
            w=w+AW(p)*(n-1);
    end
end


end

% save function file as molecular_weight.m

creating a function to solve molecular weight with a formula defined with loop and if statement

Result

Sample graph result

O2

Cp vs T

H vs T

S vs T

CH2CHO

Cp vs T

h vs T

S vs T

molecular weight output

folder created to save the plots

saved output graph with different species names automatically

Error

the above error is obtained due to the folder does not return to the main folder where the function is saved which can be troubleshot by a specific command directory one level up to save the file

there is a mismatch of brackets in function which is changed to troubleshoot it

while creating an image there is a misalignment of the figure in the folder and some figure are not generated and it is saved in a different name which can be rectified by the figure command before creating each plot

A typing error obtain while solving the file and it can be analyzed and rectified

Conclusion

thermodynamic property of different species is calculated and plotted in a folder with respected species name with molecular weight from NASA thermodynamic property

Reference

https://www.britannica.com/science/specific-heat

https://www.westfield.ma.edu/PersonalPages/cmasi/gen_chem1/Energy/enthalpy_definition_folder/enthalpy_definition.htm

https://en.wikipedia.org/wiki/Entropy

https://www.cmu.edu/gelfand/lgc-educational-media/polymers/what-is-polymer/molecular-weight-calculation.html

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.