0% found this document useful (0 votes)
11 views7 pages

Numerical Code - OneD SS Q FDM

The document outlines the application of the finite difference method to solve the one-dimensional steady-state heat diffusion equation for a copper rod with fixed boundary temperatures and uniform heat generation. It details the discretization of the governing equation, formulation of matrix equations, and the comparison of numerical and analytical solutions, confirming their accuracy. Additionally, it includes a code snippet for implementing the solution and visualizing the temperature distribution along the rod.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Numerical Code - OneD SS Q FDM

The document outlines the application of the finite difference method to solve the one-dimensional steady-state heat diffusion equation for a copper rod with fixed boundary temperatures and uniform heat generation. It details the discretization of the governing equation, formulation of matrix equations, and the comparison of numerical and analytical solutions, confirming their accuracy. Additionally, it includes a code snippet for implementing the solution and visualizing the temperature distribution along the rod.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Finite Difference Method: One-Dimensional Steady-State

Heat Diffusion with Uniform Heat Generation


Problem Statement
We aim to solve the one-dimensional steady-state heat diffusion equation for a copper rod of
length 0.1 m with fixed boundary temperatures and uniform heat generation.
The governing equation is:
2
d T Q
2
+ =0
dx k
where:

● Q : Uniform heat generation rate (W/m ​3)

● k : Thermal conductivity of copper ¿ 401 W /m⋅ K

Boundary Conditions
● Temperature at the left boundary T ( 0 )=0 ° C

● Temperature at the right boundary T ( 0.1 )=100 °C

Rod Properties
● Length L=0.1 m

● Thermal conductivity k =401 W /m ⋅ K


4 3
● Heat generation rate Q=5 × 10 W /m

1. Discretization of the Governing Equation


2
d T
We discretize the second derivative 2 using the finite difference method. Let the rod length
dx
L=0.1 m be divided into 4 equal segments, giving 5 equally spaced nodes (including boundary
points).

Grid and Nodal Representation


● Node 1: x 1=0 m (left boundary, T 1=0 ° C )

● Node 2: x 2=0.025 m
● Node 3: x 3=0.05 m

● Node 4: x 4 =0.075 m

● Node 5: x 5=0.1 m (right boundary, T 5=100 ° C )

Let $\Delta x$ be the grid spacing:


L
Δx= =0.025 m
4
The finite difference approximation for the second derivative is:

d T T i +1−2T i +T i−1
2

2

dx ( Δx )2

Substituting this into the governing equation:


T i +1−2T i +T i−1 Q
+ =0
( Δx )2 k

Simplify:
2
−Q⋅ ( Δx )
T i+1−2 T i+T i−1=
k

2. Writing Equations for 5 Nodes


Boundary conditions:

● T 1=0 ° C

● T 5=100 ° C

Using the finite difference approximation, write equations for internal nodes:

Node 2 (i=2):
2
−Q⋅ ( Δx )
T 3−2 T 2 +T 1=
k

Substitute T 1=0:
2
−Q ⋅ ( Δx )
T 3−2 T 2=
k

Node 3 (i=3):
2
−Q ⋅ ( Δx )
T 4−2 T 3+ T 2=
k

Node 4 (i=4):
2
−Q ⋅ ( Δx )
T 5−2 T 4+ T 3=
k

Substitute T 5=100:
2
−Q ⋅ ( Δx )
100−2T 4 +T 3=
k

3. Matrix Formulation
Express the equations for internal nodes in matrix form:

[ ]
2 2 2
−Q ⋅ ( Δx ) Q⋅ ( Δx ) Q ⋅ ( Δx )
[ −2 10 1−21 0 1−2 ] [ T 2 T 3 T 4 ]= − −100−
k k k

Let:

[ ]
2 2 2
−Q ⋅ ( Δx ) Q⋅ ( Δx ) Q ⋅ ( Δx )
A=[−21 0 1−2 1 01−2 ] ,T =[ T 2 T 3 T 4 ] , B= − −100−
k k k

The matrix equation becomes:


A ⋅T =B

4. Solving Using Matrix Inversion


Find T using the matrix inverse:
−1
T=A ⋅B

Inverse of Matrix A :
−1
A =[ −0.75−0.5−0.25−0.5−1−0.5−0.25−0.5−0.75 ]

Solution for T :
Substitute values:

● Δx=0.025 m

● k =401 W /mK
4 3
● Q=5 × 10 W /m
2 4 2
Q⋅ ( Δx ) 5 ×10 ⋅ ( 0.025 )
= =0.078 ° C
k 401
B=[ −0.078−0.078−100−0.078 ] =[ −0.078−0.078−100.078 ]

Perform matrix multiplication:


T =[ −0.75−0.5−0.25−0.5−1−0.5−0.25−0.5−0.75 ] ⋅ [ −0.078−0.078−100.078 ]

Solve for T :
T =[ 24.96 49.92 74.88 ]

Thus:
T 2=24.96 °C ,T 3=49.92° C ,T 4=74.88° C

5. Analytical Solution
2
d T Q
The general solution of 2
+ =0 is:
dx k
−Q 2
T ( x )= x +C 1 x +C2
2k
Using boundary conditions:

● At x=0 , T =0 : C 2=0

● At x=0.1 , T =100:
4
−5 ×10 ( )2
100= 0.1 +C 1 ⋅0.1
2⋅ 401
Solve for C1C_1:
100=−6.23+0.1 C 1 ⟹C 1=1062.3

Thus:
4
−5 ×10 2
T ( x )= x + 1062.3 x
2 ⋅ 401

Temperature at Nodes:
● T 1=T ( 0 )=0 ° C

● T 2=T ( 0.025 )=24.96 °C

● T 3=T ( 0.05 )=49.92 ° C


● T 4=T ( 0.075 )=74.88 ° C

● T 5=T ( 0.1 ) =100 ° C

6. Comparison of Solutions
Nod Numerical Solution (T Analytical Solution (T
e ) )
1 0 0
2 24.96 24.96
3 49.92 49.92
4 74.88 74.88
5 100 100

7. Conclusion
The numerical and analytical solutions match perfectly, even with uniform heat generation,
confirming the accuracy of the finite difference method for this problem.

8 . Code
import numpy as np
import matplotlib.pyplot as plt

# Parameters
L = 0.1 # Length of the rod (m)
k = 401 # Thermal conductivity (W/m·K)
Q = [5e7, 8e7, 5e4] # Heat generation rate (W/m^3)
T_left = 0 # Dirichlet boundary condition at x=0 (°C)
T_right = 100 # Dirichlet boundary condition at x=L (°C)
N = 25 # Number of nodes (including boundary nodes)

# Discretization
dx = L / (N - 1)
x = np.linspace(0, L, N)

# Markers and colors


markers = ['s', 'o', '^']
colors = ['hotpink', 'limegreen', 'orange']

# Plotting
plt.figure(figsize=(8, 8))

for i, q in enumerate(Q):
# Coefficient matrix A and right-hand side vector B
A = np.zeros((N, N))
B = np.zeros(N)
for j in range(1, N - 1):
A[j, j - 1] = 1
A[j, j] = -2
A[j, j + 1] = 1
B[j] = -q * dx**2 / k

# Apply boundary conditions


A[0, 0] = 1
B[0] = T_left
A[N - 1, N - 1] = 1
B[N - 1] = T_right

# Solve the system


T_numerical = np.linalg.solve(A, B)

# Analytical solution
C1 = (T_right - T_left + (q / (2 * k)) * L**2) / L
C2 = T_left
T_analytical = -(q / (2 * k)) * x**2 + C1 * x + C2

# Plotting with specified marker and color


plt.scatter(x, T_numerical, color=colors[i], marker=markers[i],
label=f'Numerical Solution {q} $W/m^3$')
plt.plot(x, T_analytical, color=colors[i], linestyle='-',
label=f'Analytical Solution {q} $W/m^3$')

plt.xlabel("Position (m)")
plt.ylabel("Temperature (°C)")
plt.title("Temperature Distribution in a Rod with Uniform Heat Generation")
plt.legend()
plt.grid()
plt.show()

You might also like