Maths C42H 3042: Example code 

UP_cauchy.m
Scalar linear advection u_t + a u_x = 0 with "Cauchy" data on [0,1] (i.e. solution should always vanish outside [0,1]).

Uses first-order upwinding scheme.

LW_periodic.m
Scalar linear advection u_t + a u_x = 0 with periodic BCs on [0,1]. u(0,t) = u(1,t)

Uses Lax-Wendroff scheme.

Numerically, use u(M) for u(0), u(1) for u(M+1), etc on M grid points labelled 1 to M.

LF_2x2_system.m
Linear advection system u_t + A u_x = 0 for 2-vector u

The Lax-Friedrichs scheme is used here is stable for
|lambda_p|k/h < 1 ,
i.e. it handles waves going in either direction

Exercise: Use a symmetrized one-sided scheme instead.

exact.m
Returns exact scalar travelling wave solution (speed c) on n mesh-points (space h) at time t. Initial data for t = 0.

bc = BC type, only recognize value is 'periodic' Uses a "sufficiently smooth", compactly supported initial data function.

UP_flux_split.m
Linear advection system u_t + A u_x = 0 for 2-vector u

The first-order one-sided scheme requires all eigenvalues of the same sign (i.e. all waves travelling in the same direction). Finite differences are then on the "upwind" side.

The following uses flux-splitting:
- combines both one-sided schemes together
- right going waves are handled using differences on left (upwind)
- left going waves are handled using differences on right (upwind)

BW_flux_split.m
Linear advection system u_t + A u_x = 0 for 2-vector u

Standard Beam-Warming is a one-sided scheme hence requires all eigenvalues of the same sign (i.e. all waves travelling in the same direction). (Second-order for smooth data)

The following uses flux-splitting:
- right going waves are handled using differences on left (upwind)
- left going waves are handled using differences on right (upwind)

init.m
Compactly supported, initial data on M mesh-points x(1:M)

plot2vec.m
Plot 2 component vector u(x) at time t_n = n*k at points xj between x0 and xM. Amplitude of all components of u are assumed to be between umin and umax.

scalar_conserv.m
Scalar advection: u_t + a u_x = 0

Uses a conservative advected interpolation profile method.

- Find linear interpolation profile in each cell
- Find flux thru cell boundaries by advecting profile
(flux comes from different sides depending on the sign of a)
- Time-step numerical solution using conservative update

Solved for U(1:M) on [0,1]
- assumes Cauchy problem with compactly supported data
(leaves U(1) and U(M) fixed)
(for periodicity, need flux at j=1/2 (left end of cell 1))

limited_slope.m
Given the two one-sided derivatives at xj, returns a limited slope that gives a 2-nd order TVD scheme.

dum = Uj - Uj-1
dup = Uj+1 - Uj

Standard limited slopes are symmetric w.r.t. dum and dup

Only minmod limiter implemented - add others