For it to be a well-posed mathematical problem, you also need the Cauchy data (boundary and initial conditions). From the order of the differential operators, we know that we need one boundary condition (constraint on u(xb) for all t ) and one initial condition (constraint on u(x) at t=0).
If we are solving the heat diffusion equation
∂t∂T=α∂x2∂2T
Then we need 1 initial condition and 2 boundary conditions.
Back to the linear advection equation, if we say
u(t=0,x)=f(x)andu(t,x=0)=gD(t)(Dirichlet BC)
For wave speeds less than 0 (a<0), then we would instead specify u(t,x=L).
The way boundary conditions are implemented in the Forward Euler algorithm (as an example):
ujn+1=ujn−ΔxaΔt(ujn−uj−1n)
We begin by specifying uj0=f(xj), i.e. we populate the solution at t=0.
Sweep through the domain starting at j=1 towards j=J
u1n+1=u1n−ΔxaΔt(u1n−u0n)
where
u0n=gD(tn)
Notice, at j=J
uJn+1=uJn−ΔxaΔt(uJn−uJ−1n)
There is no boundary condition required since there is no data required from outside of our domain. If we do require such data, we'll need to do something special here.
Leap-Frog BC
Recall our Leap-frog algorithm
ujn+1=ujn−1−ΔxaΔt(uj+1n−uj−1n)
With assumed given initial condition
uj0=f(x)=u(x,t=0)
What happens on the very first step from n=0 to n=1?
uj1=uj−1−ΔxaΔt(uj+10−uj−10)
We've got a starting problem: we need to know uj−1, which is outside of our problem domain. In order to take the first time step, we bootstrap the algorithm by any some other algorithm which is not centered in time. Generally we use Lax-Wendroff to give us an additional initial condition uj1. With both uj0 and uj1, we can proceed with any second-order time-centered algorithm.
How about the boundary conditions near the edges of the domain?
u1n+1=u1n−1−ΔxaΔt(u2n−u0n)(x=0)
uJn+1=uJn−1−ΔxaΔt(uJ+1n−uJ−1n)(x=L)
We're now being asked for information outside of the problem domain u0n and uJ+1n. This goes back to the modified PDE that we're actually solving. The linear advection equation is first-order in x so we only need a single boundary condition to solve it, but the modified PDE that we are solving with Leap-frog has a second-order diffusive term, so we require an additional boundary condition.
Our solution to the boundary problem is called a Numerical Boundary Scheme. As a zeroth-order scheme, we can just extend our solution at the boundary out one grid point
(j=J)uJ+1n=uJ→uJn+1−ΔxaΔt(uJn−uJ−1n)
We could also make use of a first-order extrapolation
Another method that's particularly well suited to leap-frog is
uJ+1n=uJn−1
The advantage of this method is that in a centered scheme it preserves information flow. It assumes that information from (n−1,J) will flow to (n,J+1), and we can use that information to compute (n+1,J). This helps to prevent unphysical reflections at the boundary.
Another concept which addresses unphysical boundary effects that we will cover later is called PML (Perfectly Matched Layer).
NBS are needed in all algorithms which use central difference operators.
Neumann Boundary Conditions
Instead of specifying the value of u at the boundary, we can specify the value of ∂x∂u instead
∂x∂u∣∣∣∣∣x=0=gN(t)
→Δxu1n−u0n=gN(t)→u0n=u1n−ΔxgN(t)
What happens when we put this into the Forward Euler algorithm
So the spatial difference has been entirely replaced by the boundary condition, which is about what we would expect. It means that we can essentially remove j=1 from our algorithm, since we can write down the value of u1n for all n only using the BC and IC.
Numerical BC in Implicit Algorithms
The way we implement boundary conditions in implicit algorithms is by incorporating the BC into the operator matrix. Looking at the θ-method:
When we have Dirichlet boundary conditions, the terms in square brackets u0n+1,u0n are the ones we would replace by our boundary condition. Writing out the operator matrix for the algorithm, the boundary condition is just an additional term we add
Note that now u0 does not appear in the solution vector, so whenever we need to go and plot the solution, we need to add the initial condition back in.
In comparison with Dirichlet BC, now we've actually changed both the operator matrix and the inhomogeneity vector (instead of just adding a term to the inhomogeneity vector).
Since the θ-method uses central difference operators, NBS is also required at the other end of the domain at j=J. We have the same options to choose from (0-th order or 1st-order extrapolation).