All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
OBJECTIVE To write a function that extracts the 14 coefficients and calculates the enthalpy, entropy, and specific heats for all the species in the data file. To calculate the molecular weight of each species. Tolot the Cp, Enthalpy, and Entropy for the local temperature range (low temperature: high temperature) specific…
Basanagouda K Mudigoudra
updated on 09 Dec 2020
OBJECTIVE
EQUATIONS USED
CPR=a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4
HRT=a1+a2⋅(T2)+a3⋅(T23)+a4⋅(T34)+a5⋅(T45)+a6T
SR=a1⋅lnT+a2⋅T+a3⋅(T22)+a4⋅(T33)+a5⋅(T44)+a7
where,
T is the temperature.
CP is the specific heat.
H is the enthalpy.
S is the entropy.
R is the universal gas constant.
PROCEDURE AND THE EXPLAINATION FOR THE CODE
path2 =sprintf('D:/Bassu/%s/temp_vs_H.png', species_name)
path3 =sprintf('D:/Bassu/%s/temp_vs_S.png', species_name)
saveas(P2,path2)
saveas(P3,path3), here P1, P2, P3 are the figure handles, and paths are assigned to save the images in the particular folder.
CODE EXPLAINED WITH THE COMMENTS
clear all
close all
clc
% we are going to open the file with the file handling variable f1.
f1=fopen('THERMO.dat','r');
gt=fgetl(f1); %reading the line here.
% here we are splitting the gt1 to convert it into a number.
k = 1; % we are assigning the k value as 1 this we can use in saving the figures.
gt1=fgetl(f1); % reading the line from where we can obtain the global temperature values.
gt1 = strsplit(gt1); %splitting the string to convert it into character.
% now converting the cell array into a number
global_low_temp=str2double(gt1{2}); % here we are using the str2double command to convert the cell array into numbers.
global_mid_temp=str2double(gt1{3});
global_high_temp=str2double(gt1{4});
% now skipping the next three lines which are not having the useful data
% to skip those we are using the below for loop.
for l=1:3
skip_line=fgetl(f1);
end
for j=1:53
% now we need to extract the lines from line6 in the file which are having the useful data.
line=fgetl(f1); % reading the sixth line.
% splitting the sixth line in the data file.
line_split=strsplit(line);
% converting the cell array into a number
atomic_num=str2double(line_split{4}); %in the line it is the atomic number.
local_low_temp=str2double(line_split{end-3}); % these are the local temperature values.
local_high_temp=str2double(line_split{end-2});
local_mid_temp=str2double(line_split{end-1});
%line_num=str2double(line_split{9});
species_name = line_split{1};
% now we need to get the 6th line where we are actually going to fetch the
% coefficients.
tline=fgetl(f1);
% we are going to get the locations of the E so that we can find out the
% coefficients of it.
a=findstr(tline,'E');
% we found the locations of E and with the help of these we can find the
% coefficients, we can get 3 numbers after E using that we can find the
% coefficients. The below 7coefficients are for high temperature.
a1=tline(1:a(1)+3);
a1=str2double(a1);
a2=tline(a(1)+4:a(2)+3);
a2=str2double(a2);
a3=tline(a(2)+4:a(3)+3);
a3=str2double(a3);
a4=tline(a(3)+4:a(4)+3);
a4=str2double(a4);
a5=tline(a(4)+4:a(5)+3);
a5=str2double(a5);
% another 2 coefficients are present in the next line so to read the next
% line we are taking it as tline_2.
tline_2=fgetl(f1);
b=findstr(tline_2,'E'); % finding the locations for E.
a6=tline_2(1:b(1)+3); % we got the locations of E so here we are fetching the coefficients again.
a6=str2double(a6);
a7=tline_2(b(1)+4:b(2)+3);
a7=str2double(a7);
% the below 7 coefficients are for low temperatures
a8=tline_2(b(2)+4:b(3)+3);
a8=str2double(a8);
a9=tline_2(b(3)+4:b(4)+3);
a9=str2double(a9);
a10=tline_2(b(4)+4:b(5)+3);
a10=str2double(a10);
% the below 4 coefficients are in the next line.
tline_3=fgetl(f1); % reading the line.
c=findstr(tline_3,'E'); % finding the location of the E.
a11=tline_3(1:c(1)+3); %we found the locations and again we are going to fetch the remaining coefficients.
a11=str2double(a11);
a12=tline_3(c(1)+4:c(2)+3);
a12=str2double(a12);
a13=tline_3(c(2)+4:c(3)+3);
a13=str2double(a13);
a14=tline_3(c(3)+4:c(4)+3);
a14=str2double(a14);
% assuming the temperature values from low to high global temperature as
% 1000
% taking the value for a universal gas constant.
R=8.314;
T=linspace(local_low_temp,local_high_temp,1000); % we are assigning the temperature values as 1000 intervals between local low temperature and local high temperature.
% calculating the specific heat, enthalpy, entropy
%we are creating a for loop to perform the calculation for specific heat,
%enthalpy, and entropy by using the equations as follows from 1 to length
%of the temperature. Here the 'if' condition is going to evaluate for high
%temperature and the 'else' condition will be for low temperatures.
for i=1:length(T)
if T(i)>local_mid_temp
cp(i)=(a1+a2.*T(i)+a3.*T(i)^2+a4.*T(i)^3+a5.*T(i)^4).*R;
H(i)=(a1+a2.*(T(i)./2)+a3.*(T(i)^2./3)+a4.*(T(i)^3./4)+a5.*(T(i)^4./5)+a6./T(i)).*R.*T(i);
S(i)=(a1*log(T(i))+a2.*T(i)+a3.*(T(i)^2./2)+a4.*(T(i)^3./3)+a5.*(T(i)^4./4)+a7);
else
cp(i)=(a8+a9.*T(i)+a10.*T(i)^2+a11.*T(i)^3+a12.*T(i)^4).*R;
H(i)=(a8+a9.*(T(i)./2)+a10.*(T(i)^2./3)+a11.*(T(i)^3./4)+a12.*(T(i)^4./5)+a13./T(i)).*R.*T(i);
S(i)=(a8*log(T(i))+a9.*T(i)+a10.*(T(i)^2./2)+a11.*(T(i)^3./3)+a12.*(T(i)^4./4)+a14);
end
end
%creating the folders with the name of the species to save the plots
% within the folder
mkdir('D:\Bassu',species_name) % here folders will be generated with respective species names.
% plotting the graph for temperature vs specific heat
P1 = figure(k); % here we are assigning the figure with the figure handle that we can use in the save as command to save the figures.
plot(T,cp); %plotting temperature vs cp
xlabel('Temperature'); % labeling x axis as temperature values.
ylabel('Specific heat'); %labeling y axis as speciifc heat values.
title('Temperature vs Specific heat for ',species_name); %giving some title to the plot.
% plotting the graph for temperature vs enthalpy
P2 = figure(k+1); % here we are assigning the figure with the figure handle that we can use in the save as command to save the figures.
plot(T,H) %plotting temperature vs H.
xlabel('Temperature') % labeling x axis as temperature values.
ylabel('Enthalpy')) %labeling y axis as Enthalpy values.
title('Temperature vs Enthalpy for ' ,species_name) %giving some title to the plot.
% plotting the graph for temperature vs entropy
P3 = figure(k+2); % here we are assigning the figure with the figure handle that we can use in the save as command to save the figures.
plot(T,S); %plotting temperature vs Entropy.
xlabel('Temperature'); % labeling x axis as temperature values.
ylabel('Entropy'); %labeling y axis as Entropy values.
title('Temperature vs Entropy for ' ,species_name); %giving some title to the plot.
% we are going to save the plots as images inside the respective folders
% of particular species by assigning the path and using the 'saveas' command
% to save the figure
k = k+3; % here we are giving some increment to k value so that it can get the next figures plotted with the respective number.
path1 =sprintf('D:/Bassu/%s/temp_vs_cp.png', species_name); %creating the paths to print the images in the particular species folder and in which format it should be.
path2 =sprintf('D:/Bassu/%s/temp_vs_H.png', species_name) ;
path3 =sprintf('D:/Bassu/%s/temp_vs_S.png', species_name);
saveas(P1,path1); % here we can save the images of plots by assigning the figure handle and path in the 'saveas' command.
saveas(P2,path2);
saveas(P3,path3);
% calculating the molecular weight of each species
disp(species_name) % it will display the particular species name to the respective molecular weight.
element={'O','C','H','A','R','N','S'}; % these are the only elements present in the thermo data so we are using these elements to compare with the species name to calculate the molecular weight.
Atomic_mass=[15.999,12.011,1.008,39.948,0,14.007,32.06]; % these are the respective atomic masses of the element.
m_wt=zeros(1,length(species_name)); %initializing the molecular weight of the array.
%using for loops to calculate the molecular weight of each species.
for p=1:length(species_name) % for p, it will be going to iterate from 1 to the length of the species name.
if isnan(str2double(species_name(p))) % here assigning the condition that if the character of the species name is letter then it will going to take the respective atomic mass of the element.
for q=1:length(element) % for 1 to the length of element here going to compare with the species name.
if strcmp(species_name(p),element(q))
m_wt(p)=m_wt(p)+Atomic_mass(q); %if the element matches with the species name it will going to get the respective mass.
end
end
else
m_wt(p-1)=m_wt(p-1)* str2double(species_name(p)); %in case it is a number it will be multiplied with the previous letter.
end
end
molecular_weight=sum(m_wt) %this will be the molecular weight of the particular species.
end
OUTPUT
The following screenshot is of the window where all the folders for particular species are saved or created in the directory.
The following plots for N2.
The following plots for CO2.
The screenshot attached here is of the molecular weights of some of the species displayed in the command window and we have calculated for all the 53 species.
ERRORS MADE
The following error was an incorrect dimension to a raising matrix and was corrected by using the dot before the rising power.
and also I made a lot of mistakes but couldn't be captured.
CONCLUSION
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...
Project - 2 - Meshing on the suspension Assembly
AIM: To perform Meshing on the suspension assembly using ANSA. Objective: To perform the pre-requisites such as, checking for the given CAD goemetry errors & perform the topology clean up. To Generate a 2D mesh with the tria elements for the tyre & rim components.(Because, the given quality criteria is same…
09 Nov 2021 02:23 AM IST
Project 1 - 2D meshing on the instrumental Panel
AIM: To perform geometrical cleanup and extracting the midsurface and to generate 2D mesh for the given component. OBJECTIVE: For the given component, check for the geometrical errors and mesh with the given element Quality criteria. After meshing the component the thickness has to be assigned. Write a detailed report…
04 Nov 2021 03:21 PM IST
Week - 8 - Morphing
AIM: To understand the basics of morphing. OBJECTIVES: 1) Practice all the Morphing techniques that were shown in the video for Model-1. 2) Perform morphing for the Model-2 and Increase the Height of the Dog houses and Ribs. MORPHING: Morphing is the process of modifying the design of the model…
31 Oct 2021 09:27 AM IST
Week 6 - Creating connection for Rear door
AIM:To learn how to make connections between parts of the FE model in ANSA. OBJECTIVE: To Create and Apply different PIDs for different components. By using the same technique and the elements as shown in the video, Perform suitable connections for the given Rear door FE model. PROCEDURE: Import the FE model into…
19 Oct 2021 11:24 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.