MWR solutions of the steady advection-diffusion equation
Let us explore the steady-state advection diffusion equation and find approximate solutions to it using the MWR. Find \(u(x)\) that satisfies
A scalar quantity \(u\) (e.g. temperature) is advected with velocity \(c\) and undergoes a diffusion dependent on K. The exact solution of this problem is:
By using the boundary conditions, we can find the integration constants.
Tip
Try to derive the constants yourself and check that \(u^{ex}\) really is the exact solution!
Let’s solve by the Method of Weighted Residuals using a polynomial function as a basis. That is, let the approximating function be
Application of the boundary conditions reveals
so that the approximating polynomial which also satisfies the boundary conditions is
To find the residual \(R(x)\), we need the first and second derivative of this function, which are
So the residual is
Collocation method
For the collocation method, the residual is forced to zero at a number of discrete points. Since there is only one unknown \(a_2\), only one collocation point is needed. We choose (arbitrarily, but from symmetry considerations) the collocation point \(x = 0.5\). Thus, the equation needed to evaluate the unknown \(a_2\) is
and the contant \(a_2\) is
Least-squares method
The weight function \(W_i\) is just the derivative of \(R(x)\) with respect to the unknown \(a_2\):
So the weighted residual statement becomes
the math is considerably more involved than before, but nothing more than integration of polynomial terms. Direct evaluation leads to the algebraic relation
Galerkin method
In the Galerkin Method, the weight function \(W_1\) is the derivative of the approximating function \(\tilde{u}\) with respect to the unknown coefficient \(a_2\):
So the weighted residual statement becomes
Again, the math is straightforward but tedious. Direct evaluation leads to the algebraic equation:
Note how this solution is, for this special case, exactly the same as the one for the collocation method.
Derivation of the coefficients
We can derive the coefficients for the different methods by using the sympy symbolic math package for python. Install into your course environment:
conda activate "your environment"
conda install sympy
Notebook - derivation of constants
Excercise: Go through the notebook and try to re-derive the functional forms of the \(a_2\) coefficient!
Discussion
Let us evaluate the different approximations by exploring an example. If both the velocity and the diffusion constants are set to 1, the exact solution looks like in Figure 1. We can plot the approximate solutions using the equations above or by quickly re-deriving them using Python/Matlab. For this Matlab’s Symbolic Math Toolbox, sympy for Python are extremely useful.
Before we start let us introduce a useful measure for the quality of the approximation. A reasonable scalar index for the closeness of two functions is the L2 norm, or Euclidian norm. This measure is often called the root-mean-squared (RMS) error in engineering. The RMS error can be defined
which in discrete terms can be evaluated as
where N is the number of grid points.