MECH 5315M - Engineering Computational Methods
Assignment 2
Copyright © 2020 University of Leeds UK. All rights reserved.
Please submit electronically via Minerva before 12.00 noon Tuesday 12 January 2021.
Your report should not be longer than 4 pages in total. Please use at least a font size of 11pt
and 2cm margins on all sides. All Matlab code should be attached to the report as an
appendix. The appendix does not count towards the 4 page limit. All figures in the report
must have captions, properly labelled axes, legends where necessary and must be
described and analysed in the text.
Problem. In this assignment we will study a combination of the transport and heat equation
called the advection-diffusion equation
(, ) + 0
(, ) =
2
2
(, ) (1)
For all numerical examples, please use 0 ≤ ≤ 2, a final time of tend=2.0 and a value of
0 = 1.5.
Task 1. (25 marks)
1. (3 x 5 = 15 marks) Derive the initial value problem in spectral space that arises when
solving equation (1) using the pseudo-spectral method. Proceed along the following
steps:
a) How does the equation for the residual R(u(x,t)) look like that comes out of
plugging the truncated Fourier series
(, ) =
1
∑ ̂()
−1
=0
into equation (1)?
b) What are the Nx equations that result from enforcing R(u(xn,t))=0 at Nx equidistant
mesh points
=
2
, = 0, … , − 1? (2)
c) How can those Nx equations be written compactly using the spectral
differentiation matrix ? You do not need to comment on the “trick” we use to
rewrite the second part of and may simply ignore the issue. However, in your
Matlab code, be sure to use the matrix that is defined in the previous
examples.
2. (5 marks for Matlab script plus 5 marks for graphs). Write a Matlab script that solves
the initial value problem coming out of Task 1.1 for = 0.1 using ode45 with
0() = (, 0) = cos (3) and then plots the solution at the end of the simulation in
both physical and spectral space using Nx=64. Modify your code to generate the
corresponding results for 0() = (, 0) = cos(7).
2
Task 2. (30 marks)
1. (5 marks) Apply the continuous Fourier transform in x to equation (1). Write down the
resulting equation in spectral space. Make sure to clearly explain what identities from
Fourier analysis you have used to obtain your result.
2. (5 marks) Write down the general solution of the differential equation arising from
Task 2.1.
3. (5 marks) Find a text book that tells you what the Fourier transform of cos(3x) is.
Write down the result and cite your source.
4. (5 marks) Obtain the solution of the differential equation from Task 2.2 for initial
values (, 0) = cos (3) and (, 0) = cos (7)?
5. (10 marks) Based on your results from 2.4, explain your observations in Task 1.2.
Task 3. (30 marks)
1. (5 marks) Write a Matlab function that solves equation (1) using the pseudo-spectral
method and explicit Euler and returns the approximate solution at the end of the
simulation in physical space. The function should have input variables Nx (number of
Fourier modes), tend (final time), v0 (transport velocity), (viscosity) and u0 (initial
value in physical space). You can use the explicit euler function provided on Minerva,
exp_euler.m:
function u = exp_euler(u0, tend, nsteps, f)
dt = tend/double(nsteps);
u = zeros(length(u0),nsteps+1);
u(:,1) = u0;
for i=1:nsteps
u(:,i+1) = u(:,i) + dt*f(u(:,i));
end
end
When calling the explicit euler function in your code, use 4 x Nx time steps.
2. (5 marks) Write a Matlab function that solves equation (1) using centred finite
differences for both
and
2
2
and explicit Euler (use the same code as in Task 3.1)
and returns the approximate solution at the end of the simulation. The function
should have input variables Nx (number of finite difference points), tend (final time), v0
(transport velocity), (viscosity) and u0 (initial value in physical space). You can copy
the code to generate the needed finite difference matrices from the examples
provided in Minerva. When calling the explicit euler function in your code, use 4 x Nx
time steps.
3. (5 marks) Write a Matlab script that calls your functions from 3.1 and 3.2 for initial
values
(, 0) = 0
(1)() =
(−
(−)2
0.52
)
and
(, 0) = 0
(2)() = ℎ ( −
2
3
) − ℎ( −
4
3
).
where heaviside refers to the Heaviside function. Your script should generate 4
figures, each containing the solution from the pseudo-spectral as well as from the
finite difference method. The 4 figures should show the resulting solutions
(in physical space) for 0
(1)
and 0
(2)
with = 1.0 and = 0.005. Use Nx=64
3
modes/nodes in all cases. For explicit Euler, use 4 x Nx = 256 time steps.
4. (15 marks) Show and describe the results generated by your code in Task 3.3.
Task 4. (15 marks)
1. Explain your observations in Task 3.3. Where necessary, you can generate new
figures to help your explanations. For example, it could be instructive to replace the
centred finite difference approximation of
with an upwind approximation and see
how the results change. Make sure that all figures clearly explain what they show and
are properly discussed in the text.