Project

Calculation of Thermodynamic Properties of Various Gas Species of NASA Thermodynamic Data File

Aim:

To calculate the thermodynamic properties of various gas species of the thermodynamic data file of NASA.

Description:

1. File Parsing:

File Parsing is the reading of the data stream in a memory model of the semantic content of the data.

2. Molecular Weight:

The molecular weight is also known as molecular mass calculating the mass of the substance based on 12 as the atomic weight of carbon is 12. It is calculated by summing the atomic weights of the atoms making up the molecular formula of the substance.

3. Specific Heat:

Specific heat is the amount of heat per unit mass required to raise the temperature by one degree celsius.

4. Enthalpy:

Enthalpy is the sum of the internal energy and the product of the pressure and volume of the thermodynamic system.

5. Entropy:

Entropy is the measure of a systems thermal energy per unit temperature that is unavailable for doing useful work.

Formula:

The formula for calculating the specific heat (cp), enthalpy (H) and entropy (S)

cp/R = a1 + a2 T +a3 T^2 + a4 T^3 + a5 T^4

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

S/R = a1 1nT + a2 T +a3 T^2/2 + a4 T^3/3 + a5 T^4/4 + a7

where R is the universal gas constant and T is the temperature.

Program:

1. Full Program:

f1 = fopen(\'THERMO.dat\',\'r\');
line_1 = fgetl(f1);
line_2 = fgetl(f1);
A = strsplit(line_2,\' \')
global_low_temp = str2num(A{2});
global_mid_temp = str2num(A{3});
global_high_temp = str2num(A{4});

for i = 1:3
    comments = fgetl(f1);
end

for i = 1:53
    % Line 3 Details
    line_3 = fgetl(f1);
    line3_split = strsplit(line_3,\' \');
    species= line3_split(1);
    species=species{1};
    
    splits = strsplit(line_3,\'G \');
    Hp = str2num(splits{2});
    Hp_low = Hp(1);
    Hp_mid = Hp(3);
    Hp_high = Hp(2);
    
    % Line 4 Details
    line_4 = fgetl(f1);
    b = findstr(line_4,\'E\');
    a1 = str2num(line_4(1:b(1)+3));
    a2 = str2num(line_4(b(1)+4:b(2)+3));
    a3 = str2num(line_4(b(2)+4:b(3)+3));
    a4 = str2num(line_4(b(3)+4:b(4)+3));
    a5 = str2num(line_4(b(4)+4:b(5)+3));
    
    % Line 5 Details
    line_5 = fgetl(f1);
    a6 = str2num(line_5(1:b(1)+3));
    a7 = str2num(line_5(b(1)+4:b(2)+3));
    a8 = str2num(line_5(b(2)+4:b(3)+3));
    a9 = str2num(line_5(b(3)+4:b(4)+3));
    a10 = str2num(line_5(b(4)+4:b(5)+3));
    
    % Line 6 Details
    line_6 = fgetl(f1);
    a11 = str2num(line_6(1:b(1)+3));
    a12 = str2num(line_6(b(1)+4:b(2)+3));
    a13 = str2num(line_6(b(2)+4:b(3)+3));
    a14 = str2num(line_6(b(3)+4:b(4)+3));
    

T = linspace(Hp_low,Hp_high,100);
R = 8.314;
cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R);
H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R);
S = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R);

% Plot
mkdir(species)

figure(1)
plot(T,cp,\'linewidth\',4,\'color\',\'black\')
xlabel(\'Temperature\')
ylabel(\'Specific Heat\')
title(species)

figure(2)
plot(T,H,\'linewidth\',4,\'color\',\'black\')
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')
title(species)

figure(3)
plot(T,S,\'linewidth\',4,\'color\',\'black\')
xlabel(\'Temperature\')
ylabel(\'Entropy\')
title(species)
cd(species)
saveas(figure(1),\'T vs Cp.jpg\')
saveas(figure(2),\'T vs H.jpg\')
saveas(figure(3),\'T vs S.jpg\')
cd(\'..\')

M = mol_weight(species);
P = sprintf(\'%s Molecular Weight = %f \\n\',species,M);
disp(P)

end

Explanation of Program:

  • The data file is read into the program by the command \'f1 = fopen(\'THERMO.dat\',\'r\')\'
  • The fgetl function is used to get the value of each line specifically.
  • The command strsplit is used to split the variables obtained from the data file.
  • The values available in the data are taken by using the command str2num in which it is taken is given in paranthesis bracket.
  • Each line is called in the same way and the values of data is obtained.
  • The lower value, middle value and higher value is retreived from the original data for each species.
  • The value of each variable is stored ina integer for the corresponding values.
  • Every values in the line is called for different variables.
  • The data to calculate the specific heat,enthalpy and entropy are given to the their responding characters.
  • The function program for each specific heat, enthalpy and entropy are given for their respective characters.
  • The function program is then attached to the main program and the graph is plotted for their respective values.
  • The graph obtained is then saved seperately in a new folder for each species by the command \'saveas\' so it gets saved in the respective folder.
  • The molecular weight function is then called to find out the molecular mass of the respective species.

2. Function Program for Specific Heat:

function cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R)
if(T>Hp_mid)
    cp =(a1+a2*T+a3*T.^2+a4*T.^3+a5*T.^4)*R
else
    cp = (a8+a9*T+a10*T.^2+a11*T.^3+a12*T.^4)*R
end
end

3. Function Program for Enthalpy:

function H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R)
if(T>Hp_mid)
    H = (a1+a2.T./2+a3*T.^2./3+a4*T.^3./4+a5*T.^4./5+a6./T)*R
else
    H = (a8+a9*T./2+a10*T.^2./3+a11*T.^3./4+a12*T.^4./5+a13./T)*R
end
end

4. Function Program for Entropy:

function S = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,Hp_mid,T,R)
if(T>Hp_mid)
    S = (a1*log(T)+a2.*T+a3*T.^2./2+a4*T.^3./3+a5*T.^4./4+a7)*R
else
    S = (a8*log(T)+a9.*T+a10*T.^2./2+a11*T.^3./3+a12*T.^4./4+a14)*R
end
end

5. Function Program for Molecular Weight:

function [M] = mol_weight(species)
atomic_mass = [15.999,1.008,12.011,32.065,14.007,39.948];
elements = [\'O\',\'H\',\'C\',\'S\',\'N\',\'A\'];

M = 0;
z = 0;

for i = 1:length(species)
    for j = 1:length(atomic_mass)
        if strcmp(species(i),elements(j))
            M = M+atomic_mass(j);
            z = j;
        end
    end
    var = str2double(species(i));
    if (var>1)
        M = M+(atomic_mass(z)*(var-1));
    end
end

end

Results:

1. Plot of O2:

2. Plot of N2:

3. Plot of CO2:

Screenshot of the folder containing the graph of every Species:

Molecular Weight:

Conclusion:

The data from the NASA thermodynamic function is read to the program and all the three graphs for specific heat, enthalpy and entropy are plotted and the data plots are saved seperately to different folder for individual species. The molecular weight of each species are also calculated in the program.

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.