PHYS 306:  Computational Physics Lab

Winter 2009

Homework #5
(Due:  March 13, 2009)




  1. Write a program to find the numerical solution $u(x,t)$ of the 1-dimensional advection equation

    \begin{displaymath}
\frac{\partial u}{\partial t}
+ v \frac{\partial u}{\partial x} = 0\,,
\end{displaymath}

    for $-10\le x\le10$, subject to the initial condition

    \begin{displaymath}
u(x,0) = ~~e^{-2(x-2)^2}
\end{displaymath}

    using the Lax-Wendroff method:

    \begin{displaymath}
u_j^{n+1} = u_j^n - \alpha
\left[\textstyle\frac12 (u_{j+1...
...1}^n)
+\textstyle\frac12 \alpha(u_j^n-u_{j-1}^n)
\right]\,,
\end{displaymath}

    where $\alpha = v\Delta t/\Delta x$. Perform the calculation with $v=1$ on a grid of 201 points spanning the range $-10\le
x\le10$ (so $\Delta x = 0.1$), with time step $\Delta t =
0.1$.

    (a) How does your numerical solution compare with the analytical solution at times $t = 1$, $t = 2$, and $t = 8$? Plot the numerical and analytical solutions at each time on the same graph.

    (b) Repeat part (a) with a time step equal to half the Courant limit.

  2. As discussed in class, the wave equation

    \begin{displaymath}
\frac{\partial^2u}{\partial x^2}
- \frac{1}{c^2}\frac{\partial^2u}{\partial t^2}
= 0\,,
\end{displaymath}

    can be recast in a form similar to the advection equation by setting

    \begin{eqnarray*}
r &=& c\frac{\partial u}{\partial x}\\
s &=& \frac{\partial u}{\partial t}
\end{eqnarray*}

    to obtain

    \begin{eqnarray*}
\frac{\partial r}{\partial t}
&=& c\frac{\partial s}{\partia...
...rac{\partial s}{\partial t}
&=& c\frac{\partial r}{\partial x}
\end{eqnarray*}

    (a) Either derive (or look up in Numerical Recipes) the form of the Lax scheme for this problem, and write down the rule for advancing the system from time $n$ to time $n+1$.

    (b) Hence write a program to solve the wave equation on the same grid as in question 1, with initial conditions

    \begin{displaymath}
\begin{array}{lll}
u(x,0) &= ~~\sin(\pi x) & ~~~(-1\le x\l...
...t} &= ~~0 & ~~~(\mbox{\rm
for all {\em x}})\\ \,
\end{array} \end{displaymath}

    Choose $c=1$ and $\Delta t = \Delta x$, and plot the numerical and analytical solutions for $r$ and $u$ at time $t=5$ on the same graph. Turn in both your program and the resultant graph.

  3. Write a program to solve the two-dimensional version of problem 1, to determine the solution $u(x,y,t)$ of the equation

    \begin{displaymath}
\frac{\partial u}{\partial t}
+ ({\bf v}\cdot\nabla) u = 0\,,
\end{displaymath}

    where ${\bf v}=(v_x,v_y)$ is a constant flow vector. Work on a square $201\times201$ grid in $x$ and $y$ with $-10\le x,y\le
10$ and $\Delta x = \Delta y = \Delta = 0.01$. Take $u(x,y,0)
= \sin\pi r^\prime$ for $r^\prime < 2$ and $0$ otherwise, where $r^\prime = \sqrt{(x+3)^2+y^2}$, and let $v_x=\frac12\sqrt{3}, vy=0.5$. Use a time step $\Delta t =
\Delta/\sqrt{2}$. Turn in images of the $u(x,y)$ field at times $t=0,1,2,5$ and $10$. What happens if you set $\Delta t
= \Delta$, as in the 1-D case?









Steve McMillan 2010-04-22