Challenge

Project 1 - Parsing NASA thermodynamic data

Aim :

Using matlab to parse the nasa thermodynamic data file and then to calculate thermodynamic properties of various gas species .

Objective:

 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.

 Here R is the universal gas constant, T is the temperature

The documents in which these coefficients are stord we have to extract the 14 coefficients are from that documents.

The first 7 coefficient are HIGH temperature coefficients and the second 7 coefficient are low temperature coefficient

We have to extract local temperature ranges , unique for each individual species.

Finally we have to plot the curves for Cp,H,S.

a= fopen(‘thermo.dat’,’r’)

fgetl(a)

NASA thermos data file:

R- universal gas constant

T- temperature

Cp-specific g=hear(k)

S-entropy(kj/mol-k)

H-enpathy(kj/mol)

a(i)=coefficient where I 1 to 14

Specific heat:

It’s the quantity of heat required to rise the temperature of one gtam of substance by a celcius degree. Input of specific heat are uselly calories or joules per gram celcius degree.

Cp=R*(a1+(a2*T)+(a3*T^2)+(a4*T^3)+a5*T^4+

Enthalphy:

Its measurement of energy in a thermodynamic system. Quantity of enthalphy equals to the totel content heat of system. Internal energy plus the product of volume & pressure .

H/RT=a1+a2*/2+a3*T^2/3+a4*T^3/4+a5*T^4/5

Enthalphy: the second law of thermodynamic states that the total entrophy of a system either increase or remains constant in any spontenious. Never decreases

S/R=a1*longT+a2T+a3T^2/2+a4T^3/3+a5T^4/+a7

Steps:

Thernmo.dat file- input parameter.

Fgetl-read temperature & split the temperature

Strsplit-convert in cell array.

Str2num-to find lower & higher temperature.

Mkdir- create the file folder

cd- change in the directory

THERMO
   300.000  1000.000  5000.000
! GRI-Mech Version 3.0 Thermodynamics released 7/30/99
! NASA Polynomial format for CHEMKIN-II
! see README file for disclaimer
O                 L 1/90O   1               G   200.000  3500.000  1000.000    1
 2.56942078E8.59741137E-05 4.19484589E-08-1.00177799E-11 1.22833691E-15    2
 2.92175791E 4.78433864E 3.16826710E3.27931884E-03 6.64306396E-06    3
-6.12806624E-09 2.11265971E-12 2.91222592E 2.05193346E                   4
O2                TPIS89O   2               G   200.000  3500.000  1000.000    1
 3.28253784E 1.48308754E-03-7.57966669E-07 2.09470555E-10-2.16717794E-14    2
-1.08845772E 5.45323129E 3.78245636E2.99673416E-03 9.84730201E-06    3
-9.68129509E-09 3.24372837E-12-1.06394356E 3.65767573E                   4
   

reference:

main code:

clear all
close all
clc
%getting date file
f1=fopen('thermo.dat','r');
fgetl(f1);
%reading header information
tline=fgetl(f1);
A=strsplit(tline,' ');
global_low_temp=str2num(A{1});
global_mid_temp=str2num(A{2});
global_high_temp=str2num(A{3});
fget1(f1);
fget1(f1);
fget1(f1);
for i=1:53
    l1=fgetl(f1);
    m=strsplit(l1,' ');
    species_name= m(1);
    endl=length(m);
    
  local_low_temp=str2num(m{endl-3});
  local_high_temp=str2num(m{endl-2});
  local_mid_temp=str2num(m{endl-1});
  tline = fgetl(f1);
  a=findstr(tline,'E');
  
  a1=tline(1:a(l)+3);
  a1=str2num(a1);
  a2=tline(a(l)+4:a(2)+3);
  a2=str2num(a2);
  a3=tline(a(2)+4:a(3)+3);
  a3=str2num(a3);
  a4=tline(a(3)+4:a(4)+3);
  a4=str2num(a4);
  a5=tline(a(4)+4:a(5)+3);
  a5=str2num(a5);
  
  tline2=fgetl(f1);
  b=findstr(a5);
  
  a6=tline2(l:b(1)+3);
  a6=str2num(a6);
  a7=tline2(b(1)+4:b(2)+3);
  a7=str2nuum(a7);
  a8=tline2(b(2)+4:b(3)+3);
  a8=str2num(a8);
  a9=tline2(b(3)+4:b(4)+3);
  a9=str2num(a9);
  a10=tline2(b(4)+4:b(5)+3);
  a10=str2num(a10);
  tline3=fgetl(f1);
  c= strfind(tline3,'E');
  a11=tline3(1:c(1)+3);
  all=str2num(a11);
  a12=tline3(c(1)+4:c(2)+3);
  a12=str2num(a12);
  a13=tline3(c(2)+4:c(3)+3);
  a13=str2num(a13);
  a14=tline3(c(3)+4:c(4)+3);
  a14=str2num(a14);
  
  T=linespace(200,350,1000);
  R=8.314;
  %get array of specific heat,enthalphy,entrophy
  %for i =:length(T)
  %compare the species temperature to assign the co efficients
  %al-a7(high temperature co-efficients),a8-a14(low temperature co efficient)
  if(T>local_mid_temp)
   
      %high temperature co efficients
      cp=(a1+a2*T+a3*T^2+a4*T^3+a5*T^4)*R;
      H=(a1+(a2*T)/2+(a3*T^2)/3+(a4*T^3)/4+(a5*T^4)/5+(a6/T))*R*T;
      S=alog(T)+a2*T+(a3*T^3)/2+(a4*T^3)/3+(a5*T^4)/4+a7
      
      %lower temperature co efficient
  else
      cp=(a8+a9*T+a10*t^2+a11*T^3+a12*T^4)*R;
      H=(a8+(a9*T))/2+(a10*T^2)/3+(a11*T^3)/4+(a12*T^4)/5+(a13/T)*R*T;
      S=a8*log(T)+a9*T+(a10*T^2)/2+(a11*T^3)/3+(a12*T^4)/4+a14;
end

fig(1)
plot (t,cp)
xlabel('temp');
ylabel('specific heat');

fig(2)
plot(T,S)
xlabel('temp');
ylabel('entropy');

fig(3)
plot(T,H)
xlabel('temp');
ylabel('enthalphy');
grid on
mkdir(species_name);
cd(species_name);
saveas(1,'tempvscp','jpg');
saveas(2,'tempvsentropy','jpg');;
saveas(3,'tempvsenthalphy','jpg');
cd

%molecular_masscalculation

elements =['H','C','O','N','A'];
atomic_weight=[1.0079 12.0107 15.999 14.00673 39.948];
mol_mass=0;
for i=1:length(species_name)
    for m=1:length(atomic_weight)
    
if strcmp(species_name(1),elements(m));
    mol_mass=mol_mass+atomic_weight(m);
    position=m
end
    end
n=str2double(species_name(1));
ifn>1
mol_mass=mol_mass+atomic_weight(position)*(n-q);
end
end
sprintf('molecular weight of %s:%f u',species_name,mol_mass)
fclose(f1)

  
  
  
  
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.