0% found this document useful (0 votes)
76 views5 pages

Modelling of Energy in Transit Using Python

In this paper, an attempt has been made to develop a Python module for evaluating energy in transit (viz., heat and work).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views5 pages

Modelling of Energy in Transit Using Python

In this paper, an attempt has been made to develop a Python module for evaluating energy in transit (viz., heat and work).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Volume 7, Issue 8, August – 2022 International Journal of Innovative Science and Research Technology

ISSN No:-2456-2165

Modelling of Energy in Transit Using Python


Krishna Gajula, Vikrant Sharma, Basant Sharma, Dhananjay R. Mishra, Pankaj Dumka *
Department of Mechanical Engineering
Jaypee University of Engineering and Technology
A.B. Road, Raghogarh-473226, Guna (India)

Abstract:- In this paper, an attempt has been made to on the direction, the work can be done by or on the system.
develop a Python module for evaluating energy in transit The former is considered positive, whereas the latter is
(viz., heat and work). The work considered in this article considered negative. Work is a path function because it not
is non-dissipative displacement work. Functions for only depends on the initial and final state but also on the path
constant pressure, volume, and temperature were followed between two states. The work can further be divided
developed, along with adiabatic and polytropic processes. into many parts; one such category of work is non-
Also, the sensible and latent heat were also transformed dissipative/displacement work. For a closed system, it's the
into functions. The modules NumPy and Matplotlib were area under the 𝑝 − 𝑣 graph as this is non-dissipative, so the
used to perform the stipulated task. The correctness of path is quasistatic/reversible.
codes was checked against four different numerical
problems, and it has been observed that the program For a general polytropic process represented by process
results match exactly with the results in the literature. As 𝑛
𝑝𝑣 = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡, the work done depends on the index 𝑛.
a result, the developed functions thus developed have
shown high accuracy with the least effort and error in all Fig. 1. Shows the impact of the variation of 𝑛 on the area under
the cases. the curve (work done by a closed system), whereas Table 1.
tells about the different processes based on the index 𝑛.
Keywords:- Energy in Transit; Thermodynamic Processes;
Heat; Work; Python Programming; NumPy; Matplotlib. TABLE I: Index 𝑛 and its equivalent process [1]
n Process 𝒑 − 𝒗 relation
I. INTRODUCTION 0 Isobaric process (p=constant) 𝑝=𝑐
1 Isothermal process for an ideal 𝑝𝑣 = 𝑐
The concept of energy in transit describes that the system gas (T=constant)
cannot store the energy in the form of work or heat it will be 1.4 Adiabatic process (no heat 𝑝𝑣 𝛾 = 𝑐
in a transition state, which means there will be an interaction interaction)
between the system and its surroundings. Here mainly ∞ Isochoric process (constant 𝑣=𝑐
discussion of work and heat interactions between the system volume)
and surroundings for a closed system has been done. In this
closed system, there will be a energy transfer, but no mass The general procedure is to integrate the process from
transfer occurs. On the other hand, in an open system, there some initial state to the final state to obtain the work
will be a transfer of mass; as the mass is being transferred, interaction, as shown in Eq. (1). Therefore, the final
there won't be a fixed amount of matter to gain or lose energy. expressions of work interaction in all the processes are listed
in Table 2.
2
𝑊 = ∫1 𝑝𝑑𝑣
(1)

TABLE II: Work in different processes


Process 𝒑 − 𝒗 relation
Isobaric process (𝑝 = 𝑐) 𝑃(𝑣2 − 𝑣1 )

Isothermal process for an 𝑣2 𝑝1


𝑝1 𝑣1 ln = 𝑝1 𝑣1 ln
ideal gas (𝑝𝑣 = 𝑐) 𝑣1 𝑝2

Polytropic process 𝑝1 𝑣1 − 𝑝2 𝑣2
(𝑝𝑣 𝑛 = 𝑐) 𝑛−1
Fig. 1: Variation of closed system work as a function of
index 𝑛 . Adiabatic process (𝑝𝑣 𝛾 = 𝑝1 𝑣1 − 𝑝2 𝑣2
𝑐) 𝛾−1
Thermodynamic work is said to be done by a system if
the sole effect on the things external to the system can be Isochoric process (𝑣 = 𝑐) 0
reduced to raising weight [1]. The weight may not be raised in
actual cases by the effect can be that of raising weights. Based

IJISRT22AUG1168 www.ijisrt.com 1152


Volume 7, Issue 8, August – 2022 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165
Heat transfer is defined as the energy transformation This research article uses Python programming to do
between the system and surroundings due to the temperature work and heat calculations. The functions were developed for
difference. It is majorly categorized into conduction, different processes, and the implementation has been
convection, and radiation. In conduction, heat transfer is explained. The developed functions will also plot the process.
caused without bulk motion of the matter. Whereas in This article will equip the readers with a basic understanding
convection, the movement of matter causes heat transfer. And of how-to implement the programming in basic
in radiation, the heat transfer is caused due to electromagnetic thermodynamics.
radiation. Moreover, it does not require any medium.
II. IMPLEMENTATION OF WORK AND HEAT IN
Heat is not a conservative property of a system, and it is PYTHON
a path function. The heat gained by the system is considered
positive, whereas the one who is leaving the system is Table 3 shows the different python program functions
negative. An adiabatic process is the one in which the system developed to obtain work and heat interaction.
does not interact with the surroundings in terms of heat.
Specific heat is the amount of energy in the form of heat TABLE III: Python code development
required to raise the temperature of a unit mass of a substance Explanation Code
by a unit degree. Eq. (2) shows the expression for specific heat. Pylab is imported from pylab import *
The product of mass and specific heat is called the heat Setting font and font font = {'family' : 'Times New
capacity of a substance, and it is denoted by 𝐶 (𝐶 = 𝑚 × 𝑐). size Roman','size' : 38}
The specific heat remains independent of the process for solids rc('font', **font)
and liquids, whereas, for gases, it must qualify the process. So, Function for constant #---------------------------------------
it is different for constant pressure and volume processes for a volume is created -
gas. # Constant Volume Process
#---------------------------------------
𝑄 = 𝑚𝑐∆𝑡 (2) -
def w_cv(p1,p2,v):
Latent heat is the amount of energy in the form of heat """
required to cause the phase change of the unit mass of a Function for constant volume
substance. During latent heat transformation, neither process
Input: Pressure limits p1 & p2 (in
temperature nor pressure changes. If 𝐿 is the latent heat, then
kPa) and volume (m^3)
the total heat interaction for a unit mass of a substance during
Output: Work output and p-v plot
the phase change is given by:
"""
figure(1,figsize=(20,15),dpi=300)
𝑄 = 𝑚𝐿 (3)
p=linspace(min(p1,p2),max(p1,p
Normally equations in Table 1 are solved using hand 2),30)
calculations. So, the chances of error flow into the calculations v=zeros(30)+v
are there. However, if the process of computations is
automated with the help of computer programmes, then the plot(v,p,'k-',linewidth=4)
chances of error in moving into the calculation can be xlabel('Volume (m$^3$)')
removed. Moreover, to better understand the process, one ylabel('Pressure (kPa)')
should also draw the equivalent p-v diagrams, which is
sometimes difficult to do by hand calculations. However, for show()
programs, it is just a matter of some data. return 0
Function for constant #---------------------------------------
Here comes the importance of Python programming, pressure is created ----# Constant Pressure
which is very easy to implement [2–5]. The strength of Python Process
lies in its modules, specially NumPy, Sympy, and Matplotlib, #---------------------------------------
which are capable of solving any problem numerically and ----
symbolically and plotting the data with only a few lines of def w_cp(p,v1,v2):
code [6–10]. The power of NumPy lies in its array of objects. """
With the help of NumPY, one can write an understandable Function for constant pressure
code which can be easily extended while keeping the code as process
simple as possible. The NumPy can do multiple tasks like limit Input : Volume limits v1 & v2
evaluation, derivative & integral computations, equation (m^3) and pressure
solutions, matrix operation, ordinary differential equation (kPa)
(ODE) solution and much more [11,12]. The module named Output: Work output and p-v plot
‘pylab’ [13–15] has both 'Numpy’ and ‘Matplotlib’ in it; """
hence, only one module has to be called to perform both the work = p*(v2-v1)
task of data calculation and visualization. figure(2,figsize=(20,15),dpi=300)

IJISRT22AUG1168 www.ijisrt.com 1153


Volume 7, Issue 8, August – 2022 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165

v=linspace(min(v1,v2),max(v1,v work = (p1*v1-p2*v2)/(n-1)


2),30) figure(2,figsize=(20,15),dpi=300)
p=zeros(30)+p
v=linspace(min(v1,v2),max(v1,v
plot(v,p,'k-',linewidth=4) 2),30)
fill_between(v,p,color='red',alpha c=p1*v1**n
=0.3) p=c/v**n
xlabel('Volume (m$^3$)')
ylabel('Pressure (kPa)') plot(v,p,'k-',linewidth=4)
fill_between(v,p,color='red',alpha
show() =0.3)
return round(work,3) xlabel('Volume (m$^3$)')
ylabel('Pressure (kPa)')
Function for constant #---------------------------------------
temperature is created ---- show()
# Constant Temperature return round(work,3)
Process
#--------------------------------------- Function for sensible #---------------------------------------
---- heat interaction ----
def w_ct(p1,v1,v2): # Sensible Heat Transfer
""" #---------------------------------------
Function for constant temperature ----
process def q_sh(m,c,T1,T2):
Input : Initial pressure (kPa) and """
volume (m^3) and final volume Function for the evaluation of
(m^3) sensible heat transfer
Output: Work output and p-v plot Input : mass (m), sp. heat (c),
""" initial temp (T1), final temp (T2)
Output: heat transfer
work = p1*v1*log(v2/v1) """
figure(2,figsize=(20,15),dpi=300) return m*c*(T2-T1)

v=linspace(min(v1,v2),max(v1,v Function for the heat #---------------------------------------


2),30) transfer process ----
c=p1*v1 involved in both # Heat transfer during phase
p=c/v sensible and latent heat change
#---------------------------------------
plot(v,p,'k-',linewidth=4) ----
fill_between(v,p,color='red',alpha def
=0.3) q_mel_sol(m,Ti,Tf,T_pc,c_bpc,c
xlabel('Volume (m$^3$)') _apc,L):
ylabel('Pressure (kPa)') """
Function for the evaluation of
show() heat transfer during phase change
return round(work,3) Input : mass (m), initial temp
(Ti), final temp (Tf),
Function for the #--------------------------------------- phase change temp (T_pc), sp.
polytropic process is ---- heat below phase change (c_bpc),
created # Polytropic Process sp. heat above phase change
#--------------------------------------- (c_apc), latent heat (L)
---- Output: heat interaction
def w_pol(p1,p2,v1,v2,n): """
"""
Function for polytropic process if Ti>Tf:
Input : p1 & p2 (kPa), v1 & v2 print('Process is either freezing or
(m^3), and n (m^3) condensation)
If the process is adiabatic write return m*(c_bpc*(T_pc-Ti)-
n=1.4 L+c_apc*(Tf-T_pc))
Output: Work output and p-v plot else:
"""

IJISRT22AUG1168 www.ijisrt.com 1154


Volume 7, Issue 8, August – 2022 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165
print('Process is either melting or Python Approach:
vaporization')
return m*(c_bpc*(T_pc- Code Program Output
Ti)+L+c_apc*(Tf-T_pc)) # Input Data
OR
Function for stream def stream_fun(ψ): p1=p2=100 #kPa 𝑤 = −50.0 kJ
function is developed u=diff(ψ,y) v1=0.7 #m^3
v=-diff(ψ,x) v2=0.2 #m^3
return u,v
# The process is isobaric
With the help of the above-developed functions, one can # The function used is
easily obtain the heat and work interactions for different w_cp
problems and plots. The following examples will demonstrate
the use of the developed functions. work = w_cp(p1,v1,v2)
work
Example 1: Air having a mass of 1.2 kg is compressed from
0.2 MPa to 0.9 MPa according to the process 𝑝𝑣 = 𝑐. The Example 3: A closed system performs two processes, viz.
initial gas density is 1.2 kg/m3. First, work done has to be isobaric followed by polytropic processes (having index 1.3).
obtained. The pressure at the beginning of the isobaric process is 50 bar,
and the volume is 0.3 m3 which increases to 0.4 m3 at the end
Python Approach: of the process. The volume at the end of a polytropic expansion
is 0.8 m3. Total work has to be obtained.
Code Program Output
# Input Data
m=1.2 #kg Python Approach:
OR
p1=0.2E3 #kPa
p2=0.9E3 #kPa 𝑤 = −300.815 kJ Code Program Output
ρ1=1.2 #kg/m^3 # Input data
# Volume p1=p2=50E2 #kPa OR
calculation at point v1=0.2 #m^3
v2=0.4 #m^3
𝑤 = 2251.651 kJ
1
v1=m/ρ1 v3=0.8 #m^3
# Calculation of n=1.3 #polytropic index
volume at point 2
v2=(p1*v1/p2) # evaluation of pressure at point
# The process is 3
isothermal p3=p2*(v2/v3)**n
# The function used
is w_ct # work has to be split into two
Work = parts
w_ct(p1,v1,v2) # One for isobaric and the other
print('Work output for polytropic
= ',Work) w_ib=w_cp(p1,v1,v2)
w_ib
w_pt=w_pol(p2,p3,v2,v3,n)
w_pt
Example 2: Air with a mass of 1.2 kg at a pressure of 100 kPa
is compressed isobarically from 0.7 m3 to 0.2 m3. Work done font = {'family' : 'Times New
has to be obtained. Roman','size' : 10}
rc('font', **font)
figure(3,dpi=300)
v=linspace(v1,v2,30)
p=ones(30)*p1
plot(v,p,'k-')
fill_between(v,p,color='red',alph
a=0.3)

v=linspace(v2,v3,30)
c=p2*v2**n
p=c/v**n

IJISRT22AUG1168 www.ijisrt.com 1155


Volume 7, Issue 8, August – 2022 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165
plot(v,p,'k-') [3]. Huei YC. Benefits and introduction to python
fill_between(v,p,color='red',alph programming for freshmore students using inexpensive
a=0.3) robots. Proc. IEEE Int. Conf. Teaching, Assess. Learn.
Eng. Learn. Futur. Now, TALE 2014, 2015, p. 12–7.
xlabel('Volume (m$^3$)') doi:10.1109/TALE.2014.7062611.
ylabel('Pressure (kPa)') [4]. Moruzzi G. Python Basics and the Interactive Mode.
savefig("Q3.jpg") Essent. Python Phys., Cham: Springer International
show() Publishing; 2020, p. 1–39. doi:10.1007/978-3-030-
45027-4_1.
work=w_ib+w_pt [5]. Dumka P, Pawar PS, Sauda A, Shukla G, Mishra DR.
work Application of He’s homotopy and perturbation method
to solve heat transfer equations: A python approach. Adv
Example 4: 650 kg of Tuna at 5°C are to be frozen and stored Eng Softw 2022;170:103160.
at -12°C. The specific heat above and below the freezing doi:10.1016/j.advengsoft.2022.103160.
points (-2°C) are 3.182 and 1.717 kJ/kg-K, respectively. For a [6]. Cywiak M, Cywiak D. SymPy. Multi-Platform Graph.
latent heat of fusion of 234.5 kJ/kg, the net heat removed from Program. with Kivy Basic Anal. Program. 2D, 3D,
Tuna is to be evaluated. Stereosc. Des., Berkeley, CA: Apress; 2021, p. 173–90.
doi:10.1007/978-1-4842-7113-1_11.
Python Approach: [7]. Meurer A, Smith CP, Paprocki M, Čertík O, Kirpichev
SB, Rocklin M, et al. SymPy: Symbolic computing in
Code Program Output python. PeerJ Comput Sci 2017;2017:1–27.
# Input data doi:10.7717/peerj-cs.103.
m=650 #kg [8]. Johansson R. Numerical python: Scientific computing
Ti=5 #deg C and data science applications with numpy, SciPy and
OR matplotlib, Second edition. Apress, Berkeley, CA; 2018.
Tf=-12 #deg C
T_pc=-2 #deg C
𝑄 = −178063.0 kJ doi:10.1007/978-1-4842-4246-9.
c_bpc=3.182 #kJ/kg [9]. Dumka P, Chauhan R, Singh A, Singh G, Mishra D.
c_apc=1.717 #kJ/kg Implementation of Buckingham ’ s Pi theorem using
L=234.5 Python. Adv Eng Softw 2022;173:103232.
# Function calling doi:10.1016/j.advengsoft.2022.103232.
Q_net=q_mel_sol(m,Ti,Tf,T_pc,c_ [10]. Dumka P, Rana K, Pratap S, Tomar S, Pawar PS, Mishra
bpc,c_apc,L) DR. Modelling air standard thermodynamic cycles using
Q_net python. Adv Eng Softw 2022;172:103186.
doi:10.1016/j.advengsoft.2022.103186.
III. CONCLUSION [11]. Huang C. Python Solver for Stochastic Differential
Equations 2011;34:1–13.
In this research article, an attempt has been made to [12]. Pawar PS, Mishra DR, Dumka P. Solving First Order
automate the process of heat and work for various Ordinary Differential Equations using Least Square
thermodynamic processes with the help of Python Method : A comparative study. Int J Innov Sci Res
programming. NumPy and Matplotlib (Pylab) have been used Technol 2022;7:857–64.
to develop functions for evaluating and plotting various heat [13]. Ranjani J, Sheela A, Pandi Meena K. Combination of
and work interactions. The developed functions were tested NumPy, SciPy and Matplotlib/Pylab-A good alternative
against four examples, and it has been observed that the methodology to MATLAB-A Comparative analysis.
program results match exactly with the literature. Therefore, Proc. 1st Int. Conf. Innov. Inf. Commun. Technol.
this research article will help beginners of thermodynamics to ICIICT 2019, 2019, p. 1–5.
solve the problems related to work and heat transfer using doi:10.1109/ICIICT1.2019.8741475.
Python. Furthermore, they can interpret the result using the [14]. Kanagachidambaresan GR, Manohar Vinoothna G.
article's approach. Visualizations. In: Prakash KB, Kanagachidambaresan
GR, editors. EAI/Springer Innov. Commun. Comput.,
REFERENCES Cham: Springer International Publishing; 2021, p. 15–
21. doi:10.1007/978-3-030-57077-4_3.
[1]. Nag PK. Engineering thermodynamics. Tata McGraw [15]. Pawar PS, Mishra DR, Dumka P, Pradesh M.
Hill; 2013. OBTAINING EXACT SOLUTIONS OF VISCO-
[2]. Dumka P, Sharma S, Gautam H, Mishra DR. Finite INCOMPRESSIBLE PARALLEL FLOWS USING
Volume Modelling of an Axisymmetric Cylindrical Fin PYTHON. Int J Eng Appl Sci Technol 2022;6:213–7.
using Python. Res Appl Therm Eng 2021;4:1–11.

IJISRT22AUG1168 www.ijisrt.com 1156

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy