Exercises

Taken from the notes

Static, 1d

Problem: \(\partial_{xx} \psi = -S\) with \(\psi(0) = 0 = \partial_x \psi(1)\).

  1. Compute (analytically) \(K_{AB}\) for linear shape functions on three elements.
  2. Compute (analytically) \(F_B\) when \(S(x) = 1 - x\) on three elements.
  3. Solve (numerically) for \(\psi_A\); compare to \(\psi = x (x^2 - 3 x + 3) / 6\).

Static, 1d

  1. Write a numerical FE solver on an evenly spaced grid with \(N_e\) elements.
  2. First use simple BCs, check \(S = 1 - x\) again.
  3. Check \(S = (1 - x)^2\); compare to \(\psi = x (4 - 6 x + 4 x^2 - x^3) / 12\). Check convergence with \(N_e\).
  4. Implement non-trivial BCs. Check

\[ S = \begin{cases} 1 & |x - \tfrac{1}{2}| < \tfrac{1}{4}, \\ 0 & \text{otherwise} \end{cases} \]

for which the solution is in the notes.

  1. Use the method of manufactured solutions to create additional tests with non-trivial BCs.
  2. Extend your solver to use an arbitrary unstructured grid.

Static, 2d

The problem is \(\nabla^2 \psi = -S\). Focus on homogeneous boundaries again.

Write functions that

  1. returns shape functions given reference coordinates \(\symbf{\xi}\) in reference triangle;
  2. returns derivatives of shape functions wrt \(\symbf{\xi}\) in reference triangle;
  3. gives global \(\mathbf{x}\) of \(\symbf{\xi}\), given nodal \(\mathbf{x}\);
  4. gives Jacobian \(\partial_{\symbf{\xi}} \mathbf{x}\) at location \(\symbf{\xi}\);
  5. gives the Jacobian determinant at \(\symbf{\xi}\);
  6. gives \(\partial_{\mathbf{x}} N_a = J^{-1} \partial_{\symbf{\xi}} N_a\);
  7. integrates \(\phi(\symbf{\xi})\) over the reference triangle;
  8. integrates \(\psi(\mathbf{x})\) over an element;
  9. computes the local stiffness matrix;
  10. computes the local force vector.

Static, 2d

Use Neumann boundaries except where \(x=0\): there use Dirichlet. Use the grid generation code from the notes (or write similar.)

  1. Check \(S(x, y) = 1 \implies \psi = x (1 - x/2)\).
  2. Check the one-dimensional examples in 2d (where BCs allow).
  3. Check

\[ S = 2 x (x - 2) (3 y^2 - 3 y + \tfrac{1}{2}) + y^2 (y - 1)^2 \]

with solution

\[ \psi = x (1 - \tfrac{x}{2}) y^2 (1 - y)^2 . \]

Time evolution, 1d

  1. Compute the form of the stiffness matrix and force vector for an even grid for advection.
  2. Re-compute for advection-diffusion.
  3. Starting from the static code, write a function to compute the time derivative of \(\psi\) on the grid.
  4. Test with simple initial data and BCs as in previous examples.