Responsive Navbar with Google Search
Partial Differential Equations: Heat Diffusion

Heat Diffusion: Program 1

The 1D Heat Diffusion Equation

\[ \frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2} \]

Where:

  • \( u(x, t) \) is the temperature at position \( x \) and time \( t \),
  • \( k \) is the thermal diffusivity constant.

Python code using the finite difference method to simulate and visualize the diffusion of heat along a 1D rod over time. Consider the following conditions:

  • The rod has a length \( L = 1.0 \) and thermal diffusivity \( k = 1.0 \).
  • Use an array of 101 points to discretize the rod over the interval \( [0, L] \).
  • Set the initial temperature distribution as zero everywhere except at the middle point \( x = 0.5 \), where the temperature is set to \( 1.0 \).
  • Apply fixed boundary conditions where the temperature at both ends of the rod remains zero.
  • Simulate the heat diffusion over a total time period of \( t_f = 15.0 \) seconds.

Output 1

The Heat Equation in One Dimension

The heat equation in one dimension is:

\[ \frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2} \]

Step 1: Discretize the Space and Time Domains

Let:

\[ x_i = i \cdot h \quad \text{for } i = 0, 1, 2, \ldots, N \]

where \( h \) is the spatial step size.

\[ t_n = n \cdot \Delta t \quad \text{for } n = 0, 1, 2, \ldots \]

where \( \Delta t \) is the time step size.

\( u_{i}^{n} \) represents the temperature at position \( x_i \)
and time \( t_n \).

Step 2: Discretize the Spatial Derivative

The second spatial derivative can be approximated using the central difference method:

\[ \frac{\partial^2 u}{\partial x^2} \approx \frac{u_{i+1}^{n} - 2u_{i}^{n} + u_{i-1}^{n}}{h^2} \]

Step 3: Discretize the Time Derivative

The time derivative can be approximated using the forward difference method:

\[ \frac{\partial u}{\partial t} \approx \frac{u_{i}^{n+1} - u_{i}^{n}}{\Delta t} \]

Step 4: Substitute into the Heat Equation

Substituting the finite difference approximations of the time and space derivatives into the heat equation gives:

\[ \frac{u_{i}^{n+1} - u_{i}^{n}}{\Delta t} = k \frac{u_{i+1}^{n} - 2u_{i}^{n} + u_{i-1}^{n}}{h^2} \]

Step 5: Solve for \( u_{i}^{n+1} \)

To derive the recursive relation, solve the above equation for \( u_{i}^{n+1} \), the temperature at the next time step:

\[ u_{i}^{n+1} = u_{i}^{n} + \frac{k \Delta t}{h^2} \left( u_{i+1}^{n} - 2u_{i}^{n} + u_{i-1}^{n} \right) \]

Step 6: Stability Condition (CFL Condition)

To ensure numerical stability, the time step \( \Delta t \) must satisfy the Courant-Friedrichs-Lewy (CFL) condition:

\[ \Delta t \leq \frac{h^2}{2k} \]

Final Recursive Relation

Thus, the recursive relation for the 1D heat equation is:

\[ u_{i}^{n+1} = u_{i}^{n} + \alpha \left( u_{i+1}^{n} - 2u_{i}^{n} + u_{i-1}^{n} \right) \]

Where \( \alpha = \frac{k \Delta t}{h^2} \) is the constant that governs the diffusion rate.

Heat Diffusion: Program 2

Write a Python program to simulate the diffusion of heat along a one-dimensional rod and Plot the solution for 5 different time instances. The heat equation governing the temperature distribution \( U(x,t) \) along the rod is given by:

\[ \frac{\partial U}{\partial t} = k \frac{\partial^2 U}{\partial x^2} \]

where:

  • \( U(x,t) \) is the temperature at position \( x \) and time \( t \),
  • \( k \) is the thermal diffusivity constant.

Conditions:

  • The rod has a length \( L = 1.0 \).
  • The initial temperature distribution is set to zero everywhere, except for a spike at the middle point \( x = 0.5 \) where \( U(0.5,0) = 1.0 \).
  • The boundary conditions are fixed, with the temperature at both ends of the rod remaining zero.
  • The simulation runs for a total time period \( t_f = 15.0 \) seconds with a time step \( dt = 0.05 \) seconds.

Output 2