Assignment #09

Unit 09

Read through the material provided in Unit 9 and solve the following exercise.

This week’s exercise involves simulating heat conduction in a 2D matrix using NumPy. The exercise will involve many concepts and skills that you have acquired over the past weeks. It offers not only an excellent opportunity to prepare for the exam, but also provides a glimpse into the world of numerical simulation, something that might wait for you in your programming future. You’ll solve a discretized version of the heat equation, a partial differential equation that describes how heat distributes in a region over time.

Heat Conduction Simulation

Simulate transient heat conduction in a 2D rectangular domain until a steady state is reached. Visualize the final steady-state temperature distribution. Follow these steps:

1. Grid Initialization

Create a 2D NumPy array representing the temperature grid. Initially, set all temperatures to zero. (See Parameter section below for specifics on the grid.) Also create a 3D array that will store the 2D array at each time step.

2. Boundary Conditions
  • Bottom row: Constant temperature of 100 degrees.
  • Left and right boundary columns: Constant temperature of 50 degrees.
  • Top boundary row: Insulated (no heat loss), implemented by setting these cells equal to their neighboring cells. At every time step, the top row equals the second top row.
3. Simulation Loop
  • Iterate over time steps
  • At each time step, the new temperature matrix computes from the previous matrix using the discretized heat equation (see Background section below). You will have to iterate through all matrix cells in order to implement it.
  • Once you computed the new grid, you will have to update the boundary conditions of the top boundary cells.
  • At each time step, check for convergence, and break the loop if the rule is fulfilled (see Convergence Check below).
  • Store the grid state at each time step in a 3D NumPy array.
4. Convergence Check

Stop the simulation when the steady state is reached. The steady state is reached when the maximum temperature change between two consecutive time steps is below a certain threshold (see Parameters section below).

5. Visualization

Use Matplotlib to visualize the final temperature distribution. At which time step is steady state reached?

Parameters to Use
  • Matrix dimensions: 10x10
  • Maximum number of iterations: 1000
  • Convergence threshold: 0.01
  • Time step size (\(\Delta t\)): 0.1

The final result should look similar to this:

Background

Heat conduction equation

The heat equation in two dimensions is given by:

\[ \frac{\partial T}{\partial t} = \alpha \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} \right) \]

where ( T ) is temperature, ( t ) is time, and ( ) is the thermal diffusivity of the material.

Numerical discretization

Using the finite difference method, the heat equation can be approximated as:

\[ T_{i,j}^{new} = T_{i,j} + \Delta t \cdot \left( T_{i+1,j} + T_{i-1,j} + T_{i,j+1} + T_{i,j-1} - 4T_{i,j} \right) \]