All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
The equations to calculate the properties of the species are: The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW- temperature coefficients. We have to use the Local Temperature Range instead of the Global Temperature Range, since Local Temperature…
Aravind Subramanian
updated on 23 Oct 2019
The equations to calculate the properties of the species are:
The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW- temperature coefficients. We have to use the Local Temperature Range instead of the Global Temperature Range, since Local Temperature Range is different for all the species.
Code for the Project:
1.) Program to extract the 14 coefficients and get the desired plots:
close all
clear all
clc
%universal gas constant
R=8.31;
f1=fopen(\'THERMO.dat\',\'r\');
line1=fgetl(f1);
%initial lines
for i=1:4
fgetl(f1)
end
T=linspace(300,5000,500);
for i=1:52
line=fgetl(f1);
A=strsplit(line,\' \');
species=A(1);
line2=fgetl(f1);
sf=strfind(line2,\'E\');
cf1=line2(1:sf(1)+3);
cf2=line2(sf(1)+4:sf(2)+3);
cf3=line2(sf(2)+4:sf(3)+3);
cf4=line2(sf(3)+4:sf(4)+3);
cf5=line2(sf(4)+4:sf(5)+3);
line3=fgetl(f1);
cf6=line3(1:sf(1)+3);
cf7=line3(sf(1)+4:sf(2)+3);
cfe1=line3(sf(2)+4:sf(3)+3);
cfe2=line3(sf(3)+4:sf(4)+3);
cfe3=line3(sf(4)+4:sf(5)+3);
line4=fgetl(f1);
cfe4=line4(1:sf(1)+3);
cfe5=line4(sf(1)+4:sf(2)+3);
cfe6=line4(sf(2)+4:sf(3)+3);
cfe7=line4(sf(3)+4:sf(4)+3);
%high temperature coefficients
hc1=str2double(cf1);
hc2=str2double(cf2);
hc3=str2double(cf3);
hc4=str2double(cf4);
hc5=str2double(cf5);
hc6=str2double(cf6);
hc7=str2double(cf7);
lc1=str2double(cfe1);
lc2=str2double(cfe2);
lc3=str2double(cfe3);
lc4=str2double(cfe4);
lc5=str2double(cfe5);
lc6=str2double(cfe6);
lc7=str2double(cfe7);
%low temperature coefficiemts
Cp=zeros(1,100);
H=zeros(1,100);
S=zeros(1,100);
lc=[lc1 lc2 lc3 lc4 lc5 lc6 lc7];
hc=[hc1 hc2 hc3 hc4 hc5 hc6 hc7];
for j=1:length(T)
t=1000;
if T(j)<=t
Cp(j) = R*(lc(1)+lc(2)*T(j)+lc(3)*(T(j))^2 +lc(4)*(T(j))^3 +lc(5)*(T(j))^4);
H(j) = R*T(j)*(lc(1)+lc(2)*T(j)/2 +lc(3)*((T(j))^2)/3 +lc(4)*((T(j))^3)/4 + lc(5)*((T(5))^4)/5 + lc(6)/T(j));
S(j) = R*(lc(1)*log(T(j))+lc(2)*T(j)+lc(3)*((T(j))^2)/2 +lc(4)*((T(j))^3)/3 + lc(5)*((T(j))^4)/4 + lc(7));
else
Cp(j) = R*(hc(1)+hc(2)*T(j)+hc(3)*(T(j))^2 +hc(4)*(T(j))^3 +hc(5)*(T(j))^4);
H(j) = R*T(j)*(hc(1)+hc(2)*T(j)/2 +hc(3)*((T(j))^2)/3 +hc(4)*((T(j))^3)/4 + hc(5)*((T(5))^4)/5 + hc(6)/T(j));
S(j) = R*(hc(1)*log(T(j))+hc(2)*T(j)+hc(3)*((T(j))^2)/2 +hc(4)*((T(j))^3)/3 + hc(5)*((T(j))^4)/4 + hc(7));
end
end
spec=char(species);
fd = sprintf(\'%s\',spec);
cur_dir=pwd;
cd(spec);
%Plot 1, Specific heat (Cp) vs Temperature (T)
figure(1);
plot(T,Cp);
xlabel(\'Temperature in K\');
ylabel(\'Specific heat in kJ\');
title(\'Specific heat vs Temperature\');
%Plot 2, Enthalpy (H) vs Temperature (T)
figure(2);
plot(T,H);
xlabel(\'Temperature in K\');
ylabel(\'Enthalpy in kJ/(mol)\');
title(\'Enthalpy vs Temperature\');
%Plot 3, Entropy (S) vs Temperature (T)
figure(3);
plot(T,S);
xlabel(\'Temperature in K\');
ylabel(\'Entropy in kJ/(mol K)\');
title(\'Entropy vs Temperature\');
% saving the plots that got generated
saveas(figure(1), \'cp.png\');
saveas(figure(2), \'h.png\');
saveas(figure(3), \'s.png\');
cd(\'D:\\skill_lync\\\')
%Molecular Weight of Particular Species
molecular_weight = Molecular_Weight(spec);
end
Explanation:
clear all: To clear all the variables from the workspace.
close all: To close all the outputs that are opened.
clc: To clear the command window.
F1 = fopen(\'THERMO.dat\',\'r\')
To open the file \'THERMO.dat\' that contains the data related to the properties of the species.
The command fopen is used to open and read the file and the file ID is stored in the variable Fid.
line1 = fgetl(F1);
Using fgetl command to read the file line by line using the File ID.
Storing the lines in a variable \'line1\'.
line1 = fgetl(F1);
Using fgetl command to read the file line by line using the File ID.
Storing the lines in a variable \'line1\'.
r = char(r,tline1);
Storing all the lines read by \'tline1\' in a character array \'r\' using the \'char\' function.
end
End of the while loop.
fclose(F1);
Closing the file using \'fclose\' command.
A=strsplit(line,\' \');
Extracting the values of the Global Temperatures from the second line of the character array.
\'strsplit\' function is used to split the second line of the charater array \'\' where ever there is a space in
the line. Then, the \'str2double\' function is used to convert the characters into numbers.
sf=strfind(line2,\'E\');
To separate out the co-efficients (i.e) find one string within another.
mkdir(spec);
To create folders for each speciesSpecific Heat, Enthalpy & Entropy are calculated using the above formulae
Plot - Graphs are plotted using this command \"xlabel\",\"ylabel\",\"linewidth\",\"color\"&\"title\" - name the sides and size of line in a Graphs
cd(spec);
To change the directory for graphsTo calculate molecular mass, another function was called
%Calculation of Enthaly, Specific Heat and Entropy
R = 8.314;
Assigning the value of the Universal Gas Constant \'R\' to a variable R.
for j = 1:length(T)
Starting for loop using the variable \'k\' from 1 to the length of the array \'T\'.
if T(j)<=t
Checking if the value of the temperature is lower than the medium temperature of the specie.
Cp(j) = R*(lc(1)+lc(2)*T(j)+lc(3)*(T(j))^2 +lc(4)*(T(j))^3 +lc(5)*(T(j))^4);
H(j) = R*T(j)*(lc(1)+lc(2)*T(j)/2 +lc(3)*((T(j))^2)/3 +lc(4)*((T(j))^3)/4 + lc(5)*((T(5))^4)/5 + lc(6)/T(j));
S(j) = R*(lc(1)*log(T(j))+lc(2)*T(j)+lc(3)*((T(j))^2)/2 +lc(4)*((T(j))^3)/3 + lc(5)*((T(j))^4)/4 + lc(7));
Calculating the values of Specific Heat, Enthalpy and Entropy for Least temperature of the specie
entered by the user using the equations given for the low temperature coefficients in the input.
end
End of if condition
if T(j)> t
Checking if the value of the temperature is greater than the medium temperature of the species.
Cp(j) = R*(hc(1)+hc(2)*T(j)+hc(3)*(T(j))^2 +hc(4)*(T(j))^3 +hc(5)*(T(j))^4);
H(j) = R*T(j)*(hc(1)+hc(2)*T(j)/2 +hc(3)*((T(j))^2)/3 +hc(4)*((T(j))^3)/4 + hc(5)*((T(5))^4)/5 + hc(6)/T(j));
S(j) = R*(hc(1)*log(T(j))+hc(2)*T(j)+hc(3)*((T(j))^2)/2 +hc(4)*((T(j))^3)/3 + hc(5)*((T(j))^4)/4 + hc(7));
Calculating the values of Specific Heat, Enthalpy and Entropy for high temperature of the species entered by the user using the equations given for the low temperature coefficients in the input.
end
End of if condition
end
End of for loop
disp(D);
Displaying the contents of the array \'D\'.
figure(1);
plot(T,Cp);
Plotting Specific Heat vs Temperature.
xlabel(\'Temperature in K\');
ylabel(\'Specific Heat in KJ\');
figure(2);
plot(T,H);
Plotting Enthalpy vs Temperature.
xlabel(\'Temperature in K\');
ylabel(\'Enthalpy in KJ/mol\');
figure(3);
plot(T,S);
Plotting Entropy vs Temperature.
xlabel(\'Temperature in K\');
ylabel(\'Entropy in KJ/mol k\');
2.) Program to calculate the Molecular mass of each species:
%Function_for_Molecular_Weight%
function M=Molecular_Weight(species_name)
atoms={\'H\',\'C\',\'N\',\'O\',\'AR\'};
AtomicWeight=[1 12 14 16 40];
M=0;
for i=1:length(species_name)
for j=1:length(atoms)
if strcmp(species_name(i),atoms(j))
M=M+AtomicWeight(j);
p=j;
end
n=str2double(species_name(i));
if n>1
M=M+(AtomicWeight(p)*(n-1));
end
end
end
1.) This function takes species_name as input and gives out its Molecular mass as output.
2.) Each species name is stored in a string called species.
3.) From the file given, it can be seen that the constituents that make up each species are Hydrogen(H), Carbon(C), Nitrogen(N), Oxygen(O) and Argon(Ar). So the starting letter of each element is stored as constituents .
4.) The atomic weights of each constituent is stored in an array called atomic_weight.
5.) The molecular weight is set to zero in the beginning,
6.) Using the nested for loop, molecular weight is calculated as follows:
i.) The first for loop runs for entire length of species name that has been determined by the for loop in the main program.
ii.) The second for loop runs for entire length of constituent array.
iii.) Using the strcmp command which compares2strings and returns 1 if they match, the molecular weight will be incremented by the corresponding value in the array\'atomic_weight\'.
iv.) Another if statement checks if a molecule in a specie has more than one molecule and increases its molecular weight correspondingly.
3.) Plots of O2, N2, and CO2 species:
i.) O2 plots:
ii.) N2 plots:
iii.) CO2 plots:
4.)Screenshot of all the plots are saved:
5.) ERRORS:
1.) The specific heat ,enthaply ,entropy the values were changing for each time of the iteration so preallocation of the variables are done to avoid this error.
2.) After the iteration the drive goes to the O2 tab where the cp, h, s graph tab so the function couldnt be used for the calculation of the values
the command to used to return the required drive
cd(\'D:\\skill_lync\\\')
3.) This is not the error according to matlab the molecular weight of all the values are not displayed since the function is used after the loop.
The correction is done by using the function with in the loop.
6.) Various results and Molecular weight values:
The molecular weight of all values are not displayed only some of values for grading is displayed.
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...
Week 11 - Louver/Grille characterization
Aim The objective of the project is to simulate a hexa grille placed at the center of the channel for a streamline flow and do a parametric optiization of the design. Task Define a parameter to optimize the design. Define trials. Define primary and compound functions that you want to report. Calculate parametric solutions.…
20 Sep 2021 12:41 PM IST
Week 12 - Final Project - Modelling and Analysis of a Datacenter
AIM The objective of the project is to create a data center model using macros in the Icepak. The main parts of the data center are Computer room air conditioning (CRAC), server cabinets, power distribution units and perforated tiles. Analyze the flow distribution and behaviour of temperature in the server stacks. Problem…
20 Sep 2021 12:41 PM IST
Week 10 - MRF project
Aim The objective of the project is to create a MRF model by importing the model to Ansys Icepak and setup the physics & solve the thermal model. Moving Reference Frame The Moving reference frame approach is a steady state method used in CFD to model problems with rotating parts. The MRF is a moving/sliding mesh…
24 Aug 2021 05:23 PM IST
Week 9 - PCB Thermal Simulation
PCB Board A printed circuit board (PCB) mechanically supports and electrically connects electronic components using conductive tracks, pads and other features etched from one or more sheet layers of copper laminated onto and/or between sheet layers of a non conductive substrate. Components are generally…
19 Jul 2021 11:56 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.