Assignment 5: One-Dimensional Transient Heat Conduction


Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due


Assignment 5: One-Dimensional Transient Heat Conduction

Overview

This assignment has you applying finite difference methods to solve a one-dimensional transient heat conduction problem from a uniform temperature initial condition with constant temperature boundary conditions. For example, this could be a very simplistic model for a pan on a stove where the base of the room-temperature pan is placed on the high temperature stove top at time zero and the inside of the pan remains at room temperature in the short term. The intent is to observe how heat propagates into the base of the pan over time to increase the temperature. (If you choose to take MANE-4730 Heat Transfer you will learn how to use more realistic – but also more complex – models for this situation.)

You will start from the partial differential equation (PDE) derived from Fourier’s Law in 1D as introduced in MATH-2400 Introduction to Differential Equations that models the temperature distribution through the stainless steel:

where

T(x, t) is the temperature [⁰C] at position x [m] and at time t [s] α is the thermal diffusivity [m2/s] of stainless steel

The initial temperature distribution through the material is: T(x, 0) = T0

The left boundary (touching the stove) is at constant temperature: T(0, t) = TLBC

The right boundary (in the pan) is assumed to remain at constant temperature: T(L, t) = TRBC where L is the length of the material (i.e., the thickness of the pan)

In this problem the thermal diffusivity, α, is a function of temperature. This function is a Lagrange polynomial computed from data in a comma separated values (.csv) file provided with this assignment.

There will be five deliverables in this assignment:

hw05.py
This module initializes the material data, establishes the spatial and temporal discretization, computes the temperature distribution at six
times, and plots the six distributions in a single plot.
hw05_aux.py
This module provides functions to solve the PDE. The solution is based on a discretization of the PDE in time and space.
hw05_alpha.py
This module provides a function to read data from a file, sets module variables to compute a Lagrange interpolating function from that data, and provides a function to return the interpolated thermal diffusivity as a function of temperature.
lagrange.py
This module provides an update of function interpolate.
hw05plot.png This plot illustrates the evolution of the temperature profile in the material over time.

The temperature distribution array

The primary variable you will use to solve this problem will be a 2D ndarray of temperatures: a temperature distribution array. This array will have six rows corresponding to the six moments in time at which to display the spatial temperature distribution in the material. The first time corresponds to the initial conditions at time zero, and thus the interior points of the first row will all be set equal to T 0.

The columns of the array correspond to the spatial nodes across the length of the material. E.g., if you use five spatial nodes (probably too few!), this temperature array will have five columns. All of the elements in the first column, including in the first row (the initial condition row) will be set to the left boundary condition temperature, TLBC. Similarly, all of the elements in the last column, including in the first row, will be set to the right boundary condition temperature, TRBC.

Thus, initially this temperature distribution array will look as follows:


The objective of solving the PDE over time is to fill in the zeros with the actual temperatures at that position in the material (column) at that time (row).

Discretizing the PDE

The PDE shown has a first derivative in time and a second derivative in space. One can discretize these using a forward difference in time and a centered difference in space as follows:
That is,and 

(You should verify the coefficients shown using the fd_formula function you wrote for ICE15_2.)
Index i refers to a spatial node: node i+1 is the spatial node to the right of node i and node i-1 is to the left of node i. There are nx of these nodes, each a constant distance L/(nx-1) apart, where L is the length of the material. In this problem L = 0.01 meters; nx is chosen by you such that the temperature curves you plot look reasonably smooth.

Index n refers to a time step: if time n is the present, then time n+1 is one time step of duration dt into the future. You will choose dt to satisfy a stability criterion, discussed later. Notice that you can solve the discretized equation for   This means that you can predict the future one time step of duration dt at a time. For example, given an initial time of 0.0 seconds and a final time of 0.1 seconds, you can loop through this discretized solution (0.1–0.0)/dt times to get the temperatures in the second row of the temperature distribution array. Note that this number of steps will need to be an integer quantity. NumPy function np.ceil() will return a rounded-up integer.

The stability criterion

If too-large a time step dt is chosen this numerical method becomes numerically “unstable”, meaning that the solution will increasingly overcorrect its solution at every step to produce chaotic useless results. Analysis that we leave to other courses gives the following stability criterion: where Δt is dt and Δx is L/(nx-1). Thus, your choice of nx will determine your choice of dt to not exceed some value that also depends on the thermal diffusivity, α. However, arbitrarily choosing dt to be unnecessarily small will increase your computation time to potentially annoying durations.

The plot
The plot should show length along the x axis and temperature on the y axis. As discussed above, there should be six curves plotted, corresponding to the six rows of the temperature distribution array.

By not specifying a color or line type, matplotlib will display the curves in different colors which can be labelled in a legend with a string built for each curve to specify the time that the curve corresponds to; e.g., something like:

time_label = "t = " + t_string[i] + " [s]"
plt.plot(x, y, label=time_label)

Your plot should conform to all of the specifications for a well presented informative plot.

Code Requirements and Deliverables

hw05.py
- dt must be a module variable that is the constant size of the time step in seconds you choose to use to advance your solution of the PDE in time. This must be small enough to satisfy numerical stability requirements (discussed later) but large enough that you can compute your solution relatively quickly. For full points in Submitty it must be close to but less than the maximum allowed time step for stability of your numerical solution.
- nx must be a module variable that is the number of equally-spaced spatial nodes you choose to use to discretize the 1D length of the material. Use enough spatial nodes that the curves on your plot look reasonably smooth (except for the discontinuity in the initial condition at the left boundary, discussed later).
- Set the length of the 1D material to 0.01 meters (1 cm) in the x direction.
- Create a 1D ndarray of uniformly spaced positions along the length of the material based on the number of spatial nodes you specified.
- Set the initial temperature constant T0 = 20 ⁰C (room temperature).
- Set the left boundary condition constant temperature TLBC = 170 ⁰C (a medium heat setting for a burner, approximately 350 ⁰F). - Set the right boundary condition constant temperature TRBC = 20 ⁰C (room temperature).
- Create the following 1D ndarray of times (in seconds) at which to display the temperature profile in the material: np.array([0.0, 0.1, 0.3, 1.0, 3.0, 10.0])
That is, you will plot curves of T(x, t) for t = 0.0 s, t = 0.1 s, t = 0.3 s, etc., on a single plot to show the thermal diffusion in the material over time. There will thus be six temperature curves on your plot.
- Initialize a 2D ndarray of temperatures with rows corresponding to time and columns corresponding to space using hw05_aux.initialize_T_distribution (discussed below).
- Loop five times to generate spatial temperature distributions at each of the five times after the initial condition.
hw05_aux.py
- initialize_T_distribution(nt, nx, T 0 , T LBC , T RBC )
o nt is a scalar integer number of rows, the number of curves (6 in this problem)
o nx is a scalar integer number of columns, the number of spatial nodes
o T 0 is the scalar float initial temperature of the material
o TLBC is the scalar float left boundary condition temperature
o TRBC is the scalar float right boundary condition temperature

This function returns the initial matrix shown previously.

- solve_PDE(T_old, t_initial, t_final, dt, dx)
o T_old is a 1D ndarray of floats that are the temperatures at a previous time step.
o t_initial is the time to start a calculation from.
o t_final is the time to stop the calculation. E.g., to go from 0.3 to 1.0 sections,
t_initial = 0.3 seconds and t_final = 1.0 seconds.
o dt is the time step you specify, and dx=L/(nx-1) based on the nx you specify.
o Right before you compute a time step (to compute  ) you must test the dt you selected in module hw05.py to verify that it satisfies the stability criterion for an alpha evaluated at   . If it does not, raise a ValueError with a useful error message.
hw05_alpha.py
- read_data(filename):
o filename is a string with the name of a .csv file to read data from
o You may add optional keyword parameters (e.g., “print_debug=False”), as long as they are optional parameters. You are not required to do so, and Submitty will not look for them.
o The function should return
 a 1D ndarray of float temperature data in degrees C, followed by
 a 1D ndarray of float thermal diffusivity data in m2/s
o You should look at the file to figure out how to access the correct data.
o After you read the data, you must assert that the first temperature is 0.0 and that the last temperature is 1000.0, indicating that you read the data correctly.
o Next you must assert that all of the alphas that you read are less than 1.0e-5, indicating that you read the correct column of thermal diffusivity data. - After you define function read_data, you should set three module variables
o One is the name of the file to read in as a string. For this assignment the filename of the data file is “ss304_thermal_diffusivity_data.csv”.
o The other two are the two variables returned from invoking read_data. This is why read_data must be defined first: so the function exists before you create these two module variables by calling the function.
- alpha(T):
o T is a scalar float temperature in degrees [C]
o This function returns the scalar float thermal diffusivity [m2/s] for stainless steel at the given temperature in degrees [C]
o It does so by using a Lagrange interpolating polynomial to compute alpha for the given temperature based on the data read in and saved in the module variables.
o Note that your function interpolate in module lagrange.py has parameter xeval as a 1D ndarray. However, this function alpha has a scalar parameter. You will need to convert the scalar to a one-element ndarray to use interpolate.
o Test the user input temperature to verify that it is a scalar. Function np.ndim should return zero if it is a scalar. If it is not a scalar, raise a TypeError with a useful message.
o Test the user input temperature to verify that it is between 0.0 and 1000.0, the range of the data used to make the Lagrange polynomial. If it is not, raise a ValueError with a useful message.

lagrange.py

- interpolate(xdata, ydata, xeval):
o This function is identical or nearly identical to what you wrote for ICE14_1.
o A difference may be in how you tested for a possible division by zero. In the version for this assignment you must verify that the denominator is larger than 1.0e-12 or raise a ZeroDivisionError with a useful message.

The plot

The plot should communicate the information well, with a useful title, legend, axis labels, etc. To give some extra room around the plotting area you can use something like
plt.xlim([-0.03*L, 1.03*L])
where L is the length of the material and the constants give a 3% padding on either side of the data. You can similarly constrain the y limit by noting that the temperatures will never be below zero and will never be greater that the maximum of the three input temperatures (from the initial condition and the boundary conditions).

You have learned everything you need to know to solve the problem in this assignment according to the specifications above. You are encouraged to reuse code you have written for other assignments and ICEs, making modifications to it as needed. Plan, organize, test small chunks of code, and use your debugging skills well. Finally, you are encouraged to think about what the results you get mean physically.

发表评论

电子邮件地址不会被公开。 必填项已用*标注