FORTRAN is used as a numerical and scientific computing language. The main objective of the lab work is to understand FORTRAN language using which we solve simple numerical problems and compare different methodologies. Through this project we make use of various functions of FORTRAN and solve a FDM simple heat equation problem applying different conditions viz. Dirichlet and Von Neumann. The given problems are solved analytically then built and compiled using a free integrated development environment called CODE::BLOCKS [1] which is an open source platform for FORTRAN and C.
Arduino_CSE ece ppt for working and principal of arduino.ppt
ย
Numerical Methods Lab Work
1. Numerical Methods Lab Work 2
By
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh
Submitted to
KOZHANOVA Ksenia
2. ABSTRACT
FORTRAN is used as a numerical and scientific computing language. The main objective
of the lab work is to understand FORTRAN language using which we solve simple
numerical problems and compare different methodologies. Through this project we make
use of various functions of FORTRAN and solve a FDM simple heat equation problem
applying different conditions viz. Dirichlet and Von Neumann. The given problems are
solved analytically then built and compiled using a free integrated development
environment called CODE::BLOCKS [1] which is an open source platform for FORTRAN
and C.
3. CONTENTS:
List of figures.
1. A simple heat flow experiment using 1D Heat Equation. 1
2. Finite Difference Explicit Method. 2
3. Finite Difference Implicit Method. 9
CONCLUSION 11
REFERENCE 12
4. LIST OF FIGURES.
๏ท Fig 1: Rod considered for the problem.
Dirichlet Boundary,
๏ท Fig 2: Temperature variation at each node of c value 0.25
๏ท Fig 3: Temperature variation at each node of C value 0.49
๏ท Fig 4: Temperature variation at each node of C value 0.51
๏ท Fig 5: Temperature variation at each node of C value 0.75
Von Neumann Boundary,
๏ท Fig 6: Temperature variation at each node of C value 0.25
๏ท Fig 7: Temperature variation at each node of C value 0.49
๏ท Fig 8: Temperature variation at each node of C value 0.55
๏ท Fig 9: Temperature variation at each node of C value 0.75
5. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 1 | P a g e
1. A simple heat flow experiment using 1D Heat Equation.
A Copper rod of length L = 1m and diameter is 1 cm with lateral sides insulated is subjected to
external temperature T0, until the temperature of the rod reaches T0. At time t=0, the ends of the rod
are subjected to T1 and T2 temperature with the given boundary conditions solve the heat equation
and write in non-dimensional form.
Fig 1: Rod considered for the problem.
Initial and boundary conditions,
T (0, x) = T0 = 400 Initial
T(t,0) = T1 = 300 Dirichlet condition
T (t, L) = T2 = 500 Dirichlet condition
๐๐ถ ๐
๐๐
๐๐ก
+
๐
๐๐ฅ
(โ๐
๐๐
๐๐ฅ
) = 0 โฆโฆโฆโฆ.(1)
Where,
๐ is Density (kg/m3
)
Cp is the Heat capacity
๐ is the conductivity.
Assuming ๐ as constant equation 1 can be written as,
๐๐
๐๐ก
= ๐ผ
๐2 ๐
๐๐ฅ2 โฆโฆโฆโฆโฆ..(2)
Where,
๐ผ =
๐
๐๐ถ ๐
Non Dimensionalization of the equation,
๐ฬ = T
๐ฅฬ = x
๐กฬ = t
6. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 2 | P a g e
๐๐ฬ
๐๐กฬ
=
๐2
๐ฬ
๐๐ฅฬ2
2. Finite Difference Explicit Method:
Using second order centered difference for space derivative and simple first order forward
difference for time derivative. The scheme results in,
๐ = T (t + ๐ฅ๐ก) - T (t)
๐๐ก ๐ฅ๐ก
Using the above scheme,
โT
โt
=
Tj
k+1
โTj
k
โt
.โฆโฆโฆโฆโฆโฆ... (3)
Substituting the equation no. 3,
๐2 ๐
๐๐ฅ2 =
๐๐+1
๐
โ2๐๐
๐
+๐๐โ1
๐
(โ๐ฅ)2 โฆโฆโฆโฆ. (4)
Using the equation no. 3 and 4,
๐๐
๐+1
โ ๐๐
๐
=
โ๐ก
โ๐ฅ2 (๐๐+1
๐
โ 2๐๐
๐
+ ๐๐โ1
๐
) โฆโฆโฆ. (5)
Considering,
๐ =
โ๐ก
โ๐ฅ2
This equation helps in finding the temperature evolution at different stages,
๐ป๐
๐+๐
= ๐. ๐ป๐โ๐
๐
+ (๐ โ ๐๐)๐ป๐
๐
+ ๐. ๐ป๐+๐
๐
Discretizing Boundary conditions:
Boundary conditions and initial conditions for the problem is given for two cases. Imposed
temperature in the two ends of the rod,
T(1,t)=300 indicating ๐ป ๐
๐
= ๐๐๐
T(L,t)=500 indicating ๐ป ๐ต
๐
= ๐๐๐
7. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 3 | P a g e
The initial condition is T(x, 1) = 400 indicating ๐๐
1
= 400
Applying the boundary conditions in the obtained equation 5 with j varying from 2 to N-1
๐๐
๐+1
= ๐๐๐โ1
๐
+ (1 โ 2๐)๐๐
๐
+ ๐๐๐+1
๐
The equation for the second node can be written as,
๐2
๐+1
= ๐๐1
๐
+ (1 โ 2๐)๐2
๐
+ ๐๐3
๐
๐2
๐+1
= 300๐ + (1 โ 2๐)๐2
๐
+ ๐๐3
๐
The equation for the last but one node can be written as,
๐ ๐โ1
๐+1
= ๐๐ ๐โ2
๐
+ (1 โ 2๐)๐ ๐โ1
๐
+ ๐๐ ๐
๐
๐ ๐โ1
๐+1
= ๐๐ ๐โ2
๐
+ (1 โ 2๐)๐ ๐โ1
๐
+ 500๐
Writing the system of equations in the matrix form:
๐ป ๐+๐
= ๐จ๐ป ๐
+ ๐ฉ
(
๐1
๐+1
โฎ
๐ ๐
๐+1
) = [
1 โ 2๐ ๐ 0
๐ โฑ โฑ
0 โฑ 1 โ 2๐
] (
๐1
๐
โฎ
๐ ๐
๐
) + [
300
โฎ
500
]
Here (1-2c) occupies the main diagonal and c the lower and upper diagonal. B is the boundary
condition matrix with only two entries at the extreme nodes and the other values are 0.
By applying the derived equation into program graphs for temperature values as function of time for
different length divisions can be obtained.
8. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 4 | P a g e
Fig 2: Temperature variation at each node of c value 0.25
Fig 3: Temperature variation at each node of C value 0.49
As shown in the graphs 1 and 2 the temperature at each node after some amount of time converges
showing that it gains equilibrium. This is considered true only when c value is less than 0.5 which is
evident from the graph 3 and 4. As c increased to 0.5, the system became marginally stable. The
reason of referring the system has been deduced from unstable solutions where c takes a value above
0.5.
290
340
390
440
490
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temparature(K)
LENGTH (L)
C = 0.25
270
320
370
420
470
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temperature(K)
LENGTH (L)
C = 0.49
9. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 5 | P a g e
Fig 4: Temperature variation at each node of C value 0.51
Fig 5: Temperature variation at each node of C value 0.75
For values of c > 0.5, the system becomes unstable. The resulting graphs are varying and dissimilar
when compared to graphs of stable system. Oscillations in temperature curves can be seen as time
progress occurs, which indicates instability in the system. In c = 0.75, instabilities begin to start
earlier which say that as c is increased further, oscillations occur rapidly.
Von Neumann Boundary condition:
Imposed temperature on one end of the rod and a flux on another end of the rod,
T (1, t) = 300 indicating,
-2E+30
-1.5E+30
-1E+30
-5E+29
0
5E+29
1E+30
1.5E+30
2E+30
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temperature(K)
LENGTH (L)
C = 0.51
-4E+38
-3E+38
-2E+38
-1E+38
0
1E+38
2E+38
3E+38
4E+38
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temperature(K)
LENGTH (L)
C = 0.75
10. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 6 | P a g e
๐1
๐
= 300 ๐๐๐
๐๐( ๐ก, ๐ฟ)
๐๐ฅ
= 50
This temperature is maintained at all time in this problem. The initial condition is same as the
previous case given by T(x, 1) = 400 indicating ๐๐
1
= 400
Applying the boundary conditions in the obtained with j varying from 2 to N-1:
๐๐
๐+1
= ๐๐๐โ1
๐
+ (1 โ 2๐)๐๐
๐
+ ๐๐๐+1
๐
The equation for the second node is same as the previous case:
๐2
๐+1
= 300๐ + (1 โ 2๐)๐2
๐
+ ๐๐3
๐
The equation for the second last node using the Von Neumann boundary condition:
๐๐(๐ก, ๐ฟ)
๐๐ฅ
= 50
Is expressed using backward scheme as follows:
๐ ๐
๐
= 50๐ฅ๐ฅ + ๐ ๐โ1
๐
We get the final equation asโถ
๐ ๐โ1
๐+1
= ๐๐ ๐โ2
๐
+ (1 โ 2๐)๐2
๐
+ 50๐ฅ๐ฅ + ๐ ๐โ1
๐
Applying center difference scheme to the boundary conditions we get,
๐๐
๐๐ฅ
=
๐๐+1
๐
โ ๐๐โ1
๐
2โ๐ฅ
= 50
Where ๐๐+1
๐
= 100 ร โ๐ฅ + ๐๐โ1
๐
is a ghost node that updates the values of Tn in the
equation.
By applying the derived equation into program graphs for temperature values as function of time for
different length divisions can be obtained.
11. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 7 | P a g e
Fig 6: Temperature variation at each node of C value 0.25
Fig 7: Temperature variation at each node of C value 0.49
290
310
330
350
370
390
410
430
0 0.2 0.4 0.6 0.8 1
Temperature(K)
LENGTH (L)
C = 0.25
290
310
330
350
370
390
410
430
0 0.2 0.4 0.6 0.8 1
Temperature(K)
LENGTH (L)
C = 0.49
12. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 8 | P a g e
Fig 8: Temperature variation at each node of C value 0.55
Fig 9: Temperature variation at each node of C value 0.75
From the obtained graphs, it can be seen that the effect of the Von Neumann boundary condition on
right end of the bar is observed from the plots. The temperature value at this end is drastically
decreased comparing with that of Dirichlet boundary condition. It can be observed that the solution
of temperature variation for von Neumann condition takes more time to intersect compared to
Dirichlet. From the stability point of view, for values of c > 0.5, oscillations occur with increasing
time resulting in instability.
-2.5E+38
-2E+38
-1.5E+38
-1E+38
-5E+37
0
5E+37
1E+38
1.5E+38
2E+38
2.5E+38
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temperature(K)
LENGTH (L)
C = 0.55
-3E+15
-2E+15
-1E+15
0
1E+15
2E+15
3E+15
-0.15 0.05 0.25 0.45 0.65 0.85 1.05
Temperature(K)
LENGTH (L)
C = 0.75
13. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 9 | P a g e
3. Finite difference implicit method:
In this method, the forward difference scheme is applied for time derivative and center second
difference scheme is applied for space derivative for the next time step as follows.
๐๐
๐๐ก
=
๐๐
๐+1
โ ๐๐
๐
โ๐ก
๐2
๐
๐๐ฅ2
=
๐๐+1
๐+1
โ 2๐๐
๐+1
+ ๐๐โ1
๐+1
(โ๐ฅ)2
Substituting the above equations in the equation no. 1, and considering,
๐ =
โ๐ก
(โ๐ฅ)2,
The following equation is obtained,
๐ป(๐) = โ๐. ๐ป๐โ๐
๐+๐
+ (๐ + ๐๐)๐ป๐
๐+๐
โ ๐. ๐ป๐+๐
๐+๐
โฆโฆโฆโฆโฆ(6)
The following boundary conditions are applied to the above stated equation. Boundary conditions
and initial conditions for the problem is given for two cases. Imposed temperature in the two ends
of the beam,
T(1,t)=300 indicating ๐ป ๐
๐
= ๐๐๐
T(L,t)=500 indicating ๐ป ๐ต
๐
= ๐๐๐
This temperature is maintained at all times for this problem. The initial condition is T(x, 1) =400
indicating ๐ป๐
๐
= ๐๐๐
Applying the boundary conditions in the obtained equation 6 with j varying from 2 to N-1
๐๐
๐
= โ๐๐๐โ1
๐+1
+ (1 + 2๐)๐๐
๐+1
โ ๐๐๐+1
๐+1
The equation for the second node can be written as,
๐2
๐
= โ๐๐1
๐+1
+ (1 + 2๐)๐2
๐+1
+ ๐๐3
๐+1
14. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 10 | P a g e
The equation for the last but one nod can be written as,
๐ ๐โ1
๐
= โ๐๐ ๐โ1
๐+1
+ (1 + 2๐)๐ ๐
๐+1
โ ๐๐ ๐+1
๐+1
This temperature is maintained at all times for this problem. The initial condition is same as the
previous one given by T(x, 1) = 400 indicating,
๐๐
1
= 400
Applying the boundary conditions in the obtained equation with j varying from 2 to N-1
๐๐
๐
= โ๐๐๐โ1
๐+1
+ (1 + 2๐)๐๐
๐+1
โ ๐๐๐+1
๐+1
Writing the system of equation in the matrix form
๐ด. ๐ ๐+1
= ๐ ๐
+ ๐ต
[
1 + 2๐ โ๐ 0
โ๐ โฑ โฑ
0 โฑ 1 + 2๐
] (
๐1
๐+1
โฎ
๐ ๐
๐+1
) = (
๐1
๐
โฎ
๐ ๐
๐
) + [
300
โฎ
500
]
Where A is tridiagonal matrix with 1+2c as the main diagonal and -c as the lower and upper diagonal.
B is the boundary condition matrix with only two entries at the extreme nodes and the other values
being 0.
15. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 11 | P a g e
CONCLUSION
Altogether in this lab work we used finite difference method to solve a heat equation and apply the
same to a rod which is heated from one end. Here application of two different boundary conditions
is done viz. Dirichlet and Von Neumann through which we solve the given problem. This task helped
in understanding application of FDM on heat equation analysis and also made us familiarize with
different boundary conditions. The implicit mode of solving is done analytically by which we obtain
the matrix form of the given problem as written in the report. In order to execute the program for
implicit it is required to make use of DGESV function which is not submitted in this lab work. We
tried programming the code where we got few errors which we were unable to rectify.
16. Numerical Methods Lab work 2
PENKULINTI Sai Sreenivas & NARASIMHA PRASAD Nagesh 12 | P a g e
REFERENCES
1. Team CODE::BLOCKS, http://www.codeblocks.org/downloads/26
Version 17.12, Dated 30 Dec 2017.
2. Tutorials Point โ Fortran Tutorials, https://www.tutorialspoint.com/fortran/index.htm
3. Stanford education - Learn Fortran, https://web.stanford.edu/class/me200c/tutorial_90/
4. Moodle ENSMA โ Numerical Methods Links, https://moodle.ensma.fr/course/
5. https://en.wikipedia.org/wiki/Talk%3ANeumann_boundary_condition for Vonn Neumann
condition.
6. https://en.wikipedia.org/wiki/Nondimensionalization for non dimensionalization.