All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM : To parse the Thermodynamic data file and then Calculate the Specific Heat (Cp), Enthalpy(H),Entropy(S) and also calculate the Molecular Weight of each species. OBJECTIVE : 1. To write a program to extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for…
Kumarasamy N
updated on 06 Oct 2020
AIM :
To parse the Thermodynamic data file and then Calculate the Specific Heat (Cp), Enthalpy(H),Entropy(S) and also calculate the Molecular Weight of each species.
OBJECTIVE :
1. To write a program to extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.
2. Calculate the molecular weight of each species
3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
FILE PARSING :
File Parsing is reading a data from a file and performing some kind of transformation on the data.
It means, to a computer, about what “reading text” means to a human being. You scan it, from start to finish, and figure out what it means as you go - whether you’re” a person reading text or a computer parsing a file.
Use 'fopen' command to open the data file.
Syntax:
1." fileID = fopen(filename,'r')"
'r' - is used file reading
2. " fileID = fopen(filename,'w')"
'w' - is used to file writing.
SPECIFIC HEAT (Cp) :
The specific heat is the amount of heat per unit mass required to raise the temperature by one degree Celsius.
Q=Cpm△T
Q - Heat Added
Cp - Specific Heat
m - mass
△T - Change in Temperature
The relationship between heat and temperature change is usually expressed in the form shown above where c is the specific heat. The relationship does not apply if a phase change is encountered, because the heat added or removed during a phase change does not change the temperature.
ENTHALPY (H) :
Enthalpy is a thermodynamic property of a system. It is the sum of the internal energy added to the product of the pressure and volume of the system. It reflects the capacity to do non-mechanical work and the capacity to release heat.
H = E + PV
H - Enthalpy
E - Internal Energy
P - Pressure
V - Volume
△H - Change in Enthalpy
ENTROPY (S) :
Entropy is a thermodynamic function that we use to measure uncertainty or disorder of a system. The concept comes out of thermodynamics, which deals with the transfer of heat energy within a system.
There are many equations to calculate entropy, For example one equation is given below
1. If the happening process is at a constant temperature then entropy will be
△S=(qrev)/t
S - Entropy
△S - Change in Entropy
qrev - refers to the reverse of heat
t - refers to the temperature in Kelvin
Moreover, the entropy of solid (particle are closely packed) is more in comparison to the gas (particles are free to move).
GAS CONSTANT (R) :
The Gas Constant is the physical constant in the equation for the Ideal Gas Law
Units for the gas constant vary, depending on other units used in the equation.
One common value for Gas Constant is R = 8.3145 J/mol·K.
MOLECULAR WEIGHT :
Molecular weight is a measure of the sum of the atomic weight values of the atoms in a molecule.
The calculation for molecular weight is based on the molecular formula of a compound (i.e., not the simplest formula, which only includes the ratio of types of atoms and not the number). The number of each type of atom is multiplied by its atomic weight and then added to the weights of the other atoms.
For example, the molecular formula of hexane is C6H14. The subscripts indicate the number of each type of atom, so there are 6 carbon atoms and 14 hydrogen atoms in each hexane molecule. The atomic weight of carbon and hydrogen may be found on a periodic table.
molecular weight = (number of carbon atoms)(C atomic weight) + (number of H atoms)(H atomic weight) so we calculate as follows:
EXPLANATION OF PROGRAM FOR CALCULATING SPECIFIC HEAT(Cp),ENTHALPY(H),ENTROPY(S) AND MOLECULAR WEIGHT:
Step 1 : Use fopen('THERMO.dat','r') command to open the given data file.
Syntax - "fopen(filename,'r')"
fopen - command is used for the opening the data file.
'r' - command is used for file reading.
Step 2 : Use "fgetl(fileID)" to get the nextline from the data file.
Syntax - "m1 = tline(fgetl,fileID)"
- If the file is nonempty, then fgetl
returns tline
as a character vector.
- If the file is empty and contains only the end-of-file marker, then fgetl
returns tline
as a numeric value -1
.
Step 3 : Use A="strsplit(m1,' ')" to split character vector of values on specific delimeter.
Syntax:
"strsplit(m1,delimeter)" - split character vector of values on specific delimeter.
m1 - denotes the last line taken from the data file.
delimeter - is denotes the white space to split the character vector.
Step 4 : After Splitting the character vector of values, give name for species name.
Step 5 : Use "a = strfind(m1,'G')" to find the G pattern value in a line.
Synatx:
"a=strfind(m1,'G')" - searches m1 for occurrences of pattern
. The output, a, indicates the starting index of each occurrence of pattern in m1. If pattern is not found, then strfind
returns an empty array, []
. The strfind
function executes a case-sensitive search.
If str
is a character vector or a string scalar, then strfind
returns a vector of type double
.
If str
is a cell array of character vectors or a string array, then strfind
returns a cell array of vectors of type double
.
Step 6 : Use "str2double" to converts the text in str
to double precision values.
Step 7 : Using "strfind and strdouble" command extract the temperature values and store the temperature as Low,Mid,High Temperatures.
Step 8 : Give temperature range from minimum to maximum using "linspace" command.
Syntax:
"temp = linspace(Low_temp,high_temp,1000)" - returns a row vector of 1000 evenly spaced values between Low_temp and high_temp.
Step 9 : By Using "strfind and strdouble" command to extract the 14 Co-efficient values.
Step 10 : After getting 14 Co-efficient values, calling a function to find Specific Heat(Cp),Enthalpy(H),Entropy(S).
"[f1,f2] = nasa_func(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,mid_temp,temp);"
Step 11 : In Function Program use "If else" to find first 7 Co-efficients using High Temperature and next 7 Co-efficients using low twmperature.
Step 12 : After getting the values of Cp,H,S return to the main program and plot the Cp,H,S for local temperature range (low temperature : high temperature) for the required species.
Step 13 : Use "mkdir" command to store the output plots in the separate folder.
Syntax:
"mkdir parentfolder foldername" - creates folder name in parent folder. If parent folder does not exist, MATLAB attempts to create it.
Step 14 : Use "getframe" command to capture the plots.
Synatx:
"image = getframe(gcf)" - captures the figure identified by gcf. Specify a figure if you want to capture the entire interior of the figure window, including the axes title, labels, and tick marks. The captured movie frame does not include the figure menu and tool bars.
Step 15 : Use "imwrite" command to write a image data A to the file in specified by the file name, inferring the file format from the extension.
Syntax:
"imwrite(A,filename)" - imwrite creates the new file in your current folder. The bit depth of the output image depends on the data type of A
and the file format.
Step 16 : In next step Calling a Molecular Weight function program to calculate the molecular weight.
Step 17 : In Molecular Weight function program assign the atomic weight and elements for common species.
Step 18 : By using the Species and Elements in the "for loop" and "if" condition and substitute the atomic values in the molecular weight formula.
Step 19 : After finding the Molecular weight return to the main program and display the molecular weight for the required species.
Step 20 : Finally run the Program to get the Specific Heat(Cp),Enthalpy(H),Entropy(S) and Molecular Weight values for the required species and also plots of Cp,H,s for the temperature.
MAIN PROGRAM :
clear all
close all
clc
s1 = fopen('THERMO.dat','r');
for i=1:5
m = fgetl(s1);
end
for i = 1:53
m1 = fgetl(s1);
A = strsplit(m1,' ');
[Species] = [(A{1})];
a = strfind(m1,'G');
Low_temp = str2double(m1(a(1)+4:a(1)+10));
high_temp = str2double(m1(a(1)+13:a(1)+20));
mid_temp = str2double(m1(a(1)+23:a(1)+30));
temp = linspace(Low_temp,high_temp,200);
m2 = fgetl(s1);
a1 = strfind(m2,'E');
A1 = str2double(m2(1:a1(1)+3));
A2 = str2double(m2(a1(1)+4:a1(2)+3));
A3 = str2double(m2(a1(2)+4:a1(3)+3));
A4 = str2double(m2(a1(3)+4:a1(4)+3));
A5 = str2double(m2(a1(4)+4:a1(5)+3));
m3 = fgetl(s1);
a1 = strfind(m3,'E');
A6 = str2double(m3(1:a1(1)+3));
A7 = str2double(m3(a1(1)+4:a1(2)+3));
A8 = str2double(m3(a1(2)+4:a1(3)+3));
A9 = str2double(m3(a1(3)+4:a1(4)+3));
A10 = str2double(m3(a1(4)+4:a1(5)+3));
m4= fgetl(s1);
a1 = strfind(m4,'E');
A11 = str2double(m4(1:a1(1)+3));
A12 = str2double(m4(a1(1)+4:a1(2)+3));
A13 = str2double(m4(a1(2)+4:a1(3)+3));
A14 = str2double(m4(a1(3)+4:a1(4)+3));
[f1,f2] = nasa_func(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,mid_temp,temp);
req_species = ["O2","N2","CO2"];
if (Species == req_species(1)||Species == req_species(2)||Species == req_species(3))
mkdir(['C:UsersSkill-LyncDocumentsMATLABDAY 7',Species])
cd(Species)
Cp = [f1(1,:);f2(1,:)];
H = [f1(2,:);f2(2,:)];
S = [f1(3,:);f2(3,:)];
figure(1)
plot(temp,Cp)
xlabel('Temperature(K)')
ylabel('SpecificHeat(J/K)')
title('Temperature vs Specific Heat')
image = getframe(gcf);
imwrite(image.cdata,'TempvsSpecificheat.png')
figure(2)
plot(temp,H)
xlabel('Temperature(K)')
ylabel('Enthalpy(J)')
title('Temperature vs Enthalpy')
image = getframe(gcf);
imwrite(image.cdata,'Tempvsenthalpy.png')
figure(3)
plot(temp,S)
xlabel('Temperature(K)')
ylabel('Entropy(J/K)')
title('Temperature vs Entropy')
image = getframe(gcf);
imwrite(image.cdata,'Tempvsentropy.png')
cd ..
Molecular_Weight = molecular_weight(Species);
Q = sprintf ('%s Mol.wt=%f',Species,Molecular_Weight);
req_molecular_weight = ["O2","N2","CO2"]
if (Species == req_molecular_weight(1)||Species == req_molecular_weight(2)||Species == req_molecular_weight(3))
disp(Q)
end
end
end
FUNCTION PROGRAM FOR SPECIFIC HEAT(Cp), ENTHALPY(H), ENTROPY(S) :
function [f1,f2] = nasa_func(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,mid_temp,temp)
R = 8.314;
for i =1 : length(temp)
T = temp(i);
if(T < mid_temp)
cp(i) = (A8+(A9*T)+(A10*T^2)+(A11*T^3)+(A12*T^4))*R;
H(i) = (A8+(A9*(T/2))+(A10*(T^2/3))+(A11*(T^3/4))+(A12*(T^4/5))+(A13/T))*R*T;
S(i)= (A8*log(T)+(A9*T)+(A10*(T^2/2))+(A11*(T^3/3))+(A12*(T^4/4))+A14)*R;
else
cp(i) = (A1+(A2*T)+(A3*T^2)+(A4*T^3)+(A5*T^4))*R;
H(i) = (A1+(A2*(T/2))+(A3*(T^2/3))+(A4.*(T^3/4))+(A5*(T^4/5))+(A6/T))*R*T;
S(i) = (A1*log(T)+(A2*T)+(A3*(T^2/2))+(A4*(T^3/3))+(A5*(T^4/4))+A7)*R;
end
end
[f1] = [cp;H;S];
[f2] = [cp;H;S];
end
FUNCTION PROGRAM FOR CALCULATING MOLECULAR WEIGHT :
function Molecular_Weight = molecular_weight(Species)
Atomic_weight = [15.994,1.00794,12.0107,14.0067,39.948];
Elements = ["O","H","C","N","AR"];
Molecular_Weight = 0;
for i=1:length(Species)
for j=1:length(Elements)
if strcmpi(Species(i),Elements(j))
Molecular_Weight = Molecular_Weight + Atomic_weight(j)
r=j;
end
end
var = str2double(Species(i));
if (var>1)
Molecular_Weight = Molecular_Weight +(Atomic_weight(r)*(var-1));
end
end
end
OUTPUT :
ALL SPECIES FOLDER:
MOLECULAR WEIGHT FOR ALL GIVEN SPECIES:
PLOTS FOR O2 :
1. Temperature vs Specific Heat
2. Temperature vs Enthalpy
3.Temperature vs Entropy
PLOTS FOR N2 :
1. Temperature vs Specific Heat
2. Temperature vs Enthalpy
3.Temperature vs Entropy
PLOTS FOR CO2 :
1. Temperature vs Specific Heat
2. Temperature vs Enthalpy
3.Temperature vs Entropy
CONCLUSION :
Finally Specific Heat(Cp),Enthalpy(H),Entropy(S) and Molecular Weight has been calculated for all given species
Also plots for Cp,H,S for temperature has been plotted for required species and has been attached in this project.
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...
Bird Strike Simulation
AIM: To simulate a non-linear transient dynamic problem of a Bird Strike with a Jet Engine Blade and evaluate the results. OBJECTIVES: 1. The given file contains all the 4 parts which as to separate and save part wise. 2. The suitable material is to be created and saved in a subfolder. 3. The…
12 Jul 2021 07:17 AM IST
week-11 Joint creation and Demonstration
AIM: To demonstrate spherical, revolute, cylindrical, and translational joints between two rigid bodies and two deformable bodies. OBJECTIVE: 1. Demonstrate the different types of joints like Spherical, Revolute, Cylindrical & Translational joints. 2. For all the joints simulate with rigid & elastic…
06 Jul 2021 04:17 PM IST
Week - 10 Hyperelastic Material Models
Aim: 1) To calculate the Mooney Rivlin and Ogden material constants and compare both using stress-strain data from a Dogbone specimen tensile test with 100 percent strain. 2) The given material data is the engineering stress-strain in MPa/(mm/mm). 3) The comparison should be shown from the d3hsp file and using simulation.…
01 Jul 2021 12:24 PM IST
Week - 9 Material Modeling from Raw Data
AIM : 1) Using the diagram of the true stress-strain curve given for graphite iron casting, creating a material model for the Dogbone specimen. 2) Validating the material model by performing a tensile test on a Dogbone specimen. OBJECTIVE : By Using the diagram of the true stress-strain curve given for graphite…
28 Jun 2021 01:13 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.