Heat Equation
Background knowledge
A. The Heat Equation in 1D
1. The differential equation
The heat equation in one dimension is given by:
where:
is the spatial coordinate, is the time, is the spatially-varying thermal diffusivity of the material, is the temperature distribution function, is a time dependent and spatially varying heat source.
2. Initial and boundary conditions
To solve the heat equation, we must specify initial and boundary conditions:
- Initial Condition: This refers to the temperature distribution at the initial time
. We need to know this temperature distribution in our entire domain .
- Boundary Conditions: We can specify different types of boundary conditions, i.e., conditions on the boundaries of our domain,
and .
Dirichlet Boundary Conditions: This boundary condition means that the temperature is specified at the boundaries of the domain.
Neumann Boundary Conditions: This boundary condition means that, instead of the temperature, the derivative of the temperature (which is called the heat flux) is specified at the boundaries of the domain.
3. Applications
A simplified example where the heat equation can be used is to find out how the temperature is distributed through the outside, insulating walls of your apartment. Look at the image below (source). 
The insulation wall is made up of several materials, each with their own thermal diffusivities
B. Solving the Heat Equation
1. Disadvantages of the above formulation
Now, if we want to compute the solution of the heat equation as stated above, we run into two difficulties:
Lack of exact solutions: For a general function
, finding out the exact, analytical solution is not an easy task. Well, this is not entirely true: finding the solution can be easy enough in one dimension on a domain as simple as , but in higher dimensions and on more complicated geometries (e.g., imagine the insulation wall of the Guggenheim museum) it is not possible. A restrictive set of solutions: For the above form of the heat equation to make sense, we must also assume that the second-derivatives of the solution
should exist, and that the first derivatives of the thermal diffusivity should exist. It turns out that this is too strong of a requirement that it not satisfied by many physical systems.
For example, think of the insulation wall - each material in the insulation wall has its own thermal diffusivity which is completely unrelated to the diffusivities of the other materials. As a result,
2. Tackling the above disadvantages using a discrete & weaker formulation
The above disadvantages are the reason why, in practice, the above strong formulation of the heat equation is not useful. Instead, we formulate a discrete, weak version of the equation which is much more useful in practice. The motivation is:
Discrete approximation of unknown exact solutions: Since we don't know the exact solution in general, we try to approximate it. This is the process called discretization. In this process, we fix a finite-dimensional vector space of spatially-varying functions
and say that, for any given time , we want to find a function which approximates the exact solution . Here, denotes the dimension of the vector space . We expect that as , the solution . Weak version of the equation: Since the original equation imposes too strong requirements on the smoothness of
and , we instead work with an integral formulation where only the first derivatives of should make sense, and where is allowed to be discontinuous.
ASSUMPTION: For the sake of simplifying the discussion, from now on we will assume that we are imposing Dirichlet boundary conditions at
and .
This discrete, weak version of the problem at a fixed time
where:
, .
Note the following important things:
The above problem tries to find the solution
at the fixed time instant . consists of spatially-varying functions in that satisfy the boundary conditions. We want the integral equation above to be satisfied for all functions
, where the function space consists of spatially-varying functions in that satisfy homogeneous (or, equivalently, zero) boundary conditions.
The finite element method
Now we are at a stage where, if we make a choice for
A. How to choose ?
1. Choosing
In the finite element method, we choose
Meshing the domain
We choose a set of
ASSUMPTION: In the following code, we will always assume that the mesh is uniform. In other words,
is equal to for all .
Defining
The space
on any element (i.e., on the interval
) it is a polynomial of degree , at each
, , the function is smooth for some .
Once we do this, the vector-space dimension of
In other words, there are
for some numbers
EXAMPLE:
with .
Consider the space of functions that are linear polynomials over each mesh element, and which are
So, we can find 5 basis functions,
using Mantis
using GLMakie
# The size of the domain where to solve our problem
L = 1.0
# The degree of the piecewise-polynomial basis functions
p = 1
# The number of elements in the mesh
N = 4
# The smoothness of the basis functions (must be smaller than the polynomial degree, and
# larger than -1)
k = 0
# The number of basis functions in the piecewise-polynomial function space
n = N * (p + 1) - (k + 1) * (N - 1)
# Create the mesh and the function space
breakpoints = LinRange(0.0, L, N+1)
line_geo = Geometry.CartesianGeometry((breakpoints,))
B = FunctionSpaces.BSplineSpace(line_geo, p, k)
# Create a Form Space.
BF = Forms.FormSpace(0, B, "b")
# Plot the basis functions.
n_plot_points_per_element = 25
fig = Figure()
ax = Axis(fig[1, 1],
title = "Basis functions of V_n",
xlabel = "x",
ylabel = "b_i(x)",
)
n_elements = Geometry.get_num_elements(line_geo)
xi = Points.CartesianPoints((LinRange(0.0, 1.0, n_plot_points_per_element),))
BFF = Forms.FormField(BF, " ")
dim_V = Forms.get_num_basis(BF)
colors = [:blue, :green, :red, :purple, :orange]
for basis_idx in 1:dim_V
BFF.coefficients[basis_idx] = 1.0
if basis_idx > 1
BFF.coefficients[basis_idx - 1] = 0.0
end
color_i = colors[basis_idx]
for element_idx in 1:n_elements
form_eval, _ = Forms.evaluate(BFF, element_idx, xi)
x = Geometry.evaluate(Forms.get_geometry(BF), element_idx, xi)
lines!(ax, x[:], form_eval[1], color=color_i, label=L"\phi_{%$basis_idx}")
scatter!(ax, x[:][[1, end]], [0.0, 0.0], color=:tomato)
end
end
fig[1, 2] = Legend(fig, ax, marge=true, unique=true)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
EXAMPLE:
with .
Consider now the space of functions that are quadratic polynomials over each mesh element, and which are
So, we can find 6 basis functions,
p = 2
k = 1
n = N * (p + 1) - (k + 1) * (N - 1)
B = FunctionSpaces.BSplineSpace(line_geo, p, k)
# Create a Form Space.
BF = Forms.FormSpace(0, B, "b")
fig = Figure()
ax = Axis(fig[1, 1],
title = "Basis functions of V_n",
xlabel = "x",
ylabel = "b_i(x)",
)
n_elements = Geometry.get_num_elements(line_geo)
xi = Points.CartesianPoints((LinRange(0.0, 1.0, n_plot_points_per_element),))
BFF = Forms.FormField(BF, " ")
dim_V = Forms.get_num_basis(BF)
colors = [:blue, :green, :red, :purple, :orange, :black]
for basis_idx in 1:dim_V
BFF.coefficients[basis_idx] = 1.0
if basis_idx > 1
BFF.coefficients[basis_idx - 1] = 0.0
end
color_i = colors[basis_idx]
for element_idx in 1:n_elements
form_eval, _ = Forms.evaluate(BFF, element_idx, xi)
x = Geometry.evaluate(Forms.get_geometry(BF), element_idx, xi)
lines!(ax, x[:], form_eval[1], color=color_i, label=L"\phi_{%$basis_idx}")
scatter!(ax, x[:][[1, end]], [0.0, 0.0], color=:tomato)
end
end
fig[1, 2] = Legend(fig, ax, marge=true, unique=true)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
Note: In both of the above examples, the only functions non-zero at
and are and . This means that, in particular, the functions form a basis for . We will use this fact later on.
Since, at each time instant
In other words, the coefficients of the linear combination are time-dependent. But we can say more! Since
That is, the only unknown coefficients in the above expression are
ASSUMPTION: For simplicity, we assume that
and are constants.
B. Assembling the System of ODEs
Now that we have arrived at an explicit form of our approximate solution to the weak problem, let us see how the discrete weak problem leads to a system of ODEs for the coefficients
where we have arranged the unknown coefficients
Some terminology: in the above system of ODEs,
The idea behind assembly is simple. We substitute the assumed form of our discrete solution
Since we need to satisfy the above equation for all
We can rearrange this equation as:
Then, it is easy to see that this equation represents the ODE system at the beginning of this section by defining:
, , , ,
To assemble the matrices
Before choosing our forcing term, it is relevant to briefly analyse the behavior of our solution. We saw that our weak form of the equation is
Since we have Dirichlet boundary conditions (i.e., we enforce the value of the temperature on both sides of our interval), if we prescribe a stationary heat source, the solution will evolve to a stationary state. This stationary state,
or in matrix form
Additionally, if
if the heat source is
We choose a finite element space with
This page was generated using Literate.jl.