I have a question about Galerkin method. I don't understand why the Galerkin method weights the residual by the shape functions and sets it equal to zero. I want to know what is reason of this. Why we must set weights residual functions equal to zero?
5 Answers
When I studied the finite element method in graduate school, this notion of multiplying by a weight function was also very alien to me. Eventually, I did find a nice (albeit non-rigorous) analogy that helped me understand it. This analogy is based on 3D vector geometry and an understanding of projections and dot-product.
3D Geometry
Imagine a 2D plane lying somewhere in 3D euclidean space. This plane can be though of as the span of two vectors $v_1$ and $v_2$. Thus, any vector $w$ in the plane can be written as a linear combination of these vectors; i.e. $w=c_1v_1+c_2v_2$
Now imagine a point $Q$ in 3D space that is not on the plane. Consider the question: Of all the points on the plane, which point is closest to $Q$? It is the one point $w$ (not shown in the image above) that lies on the line passing through the point $Q$ and perpendicular to the plane. The point $w$ is also known as the orthogonal projection of $Q$ onto the plane. Even though we don't know the coordinates of this point $w$, we do know that the vector between $Q$ and $w$ is perpendicular to all vectors that define the plane, i.e. $v_1$ and $v_2$. Perpendicular also means that the dot product is zero. If we denote the vector between $Q$ and $w$ as $\vec{Q}-\vec{w}$, then forcing $\vec{Q}-\vec{w}$ to be perpendicular to the plane also implies
$$(\vec{Q}-\vec{w})\cdot v_1=0$$
and
$$(\vec{Q}-\vec{w})\cdot v_2=0$$
This results in a system of equations which we can solve Also notice that to construct $\vec{Q}-\vec{w}$, we must know the coordinate of $Q$
Analogy for the Galerkin Method
Let's assume that the solution $u_h$ is a finite linear combination of functions $N_1$,..,$N_k$; thus, $u_h=C_1N_1+...+C_kN_k$. This linear combination acts like the plane in the discussion above.
Now, let's assume that there exists some exact solution $u$, which we don't know. This solution $u$ is like the point in 3D space which is not on the plane.
In the galerkin method, we're looking for the solution in a space (plane) that is closest to the true solution (point not in the plane). In this sense, the "best solution" is the choice of $u_h$ that the difference $u-u_h$ is perpendicular to the space $u_h$. Note that for function spaces, the "dot-product" is defined by the integral of their product, i.e. $<u,v>=\int_\Omega u v$. So, perpedicular implies that the dot product between the $u-u_h$ and all those basis functions $N_1$, ..., $N_k$ must be zero, i.e.
$$\int_\Omega (u-u_h)N_1 = 0$$ $$...$$ $$\int_\Omega (u-u_h)N_k = 0$$
Now, you may be saying to yourself, "This whole setup rests critically on the assumption that we know the exact solution $u$ ahead of time. But the truth is that we generally don't know $u$ a priori. In which case, how can we possibly compute $u-u_h$ in all these equations?" I'm so glad you asked!
The truth is that we can't and don't evaluate $u-u_h$ directly. But we do know what $u$ and $u_h$ are supposed to satisfy; i.e. the PDE.
Suppose your original PDE problem is $$-\nabla\cdot\left(k(x)\nabla u\right)=f$$
We could also rewrite this as
$$Au=f$$ where the operator $A$ is defined by the expression $Au=-\nabla\cdot\left(k(x) \nabla u \right)$
So instead of considering the absolute difference between the solutions $u-u_h$, we instead consider the residual difference $Au - Au_h$ in all of the (perpendicular) equations. That is, consider not what $u$ and $u_h$ are, but rather what $u$ and $u_h$ satisfy instead. By replacing the absolute difference with the residual difference in the (perpendicular) equations above, we can write
$$\int_\Omega (Au-Au_h)N_1 = 0$$ $$...$$ $$\int_\Omega (Au-Au_h)N_k = 0$$
Again, we still don't know what $u$ is, so this may not seem very helpful. But in fact, we can replace $Au$ with the known source term $f$ (since $Au=f$). Thus, we obtain the equations
$$\int_\Omega (f-Au_h)N_1 = 0$$ $$...$$ $$\int_\Omega (f-Au_h)N_k = 0$$
Thus, enforcing the residual to be orthogonal to the given space results in a system of equations that one can solve for the coefficients $C_1,...,C_k$.
Summary
The explanation above is a rough "analogy". I haven't really derived anything or given a reasonable proof that $u-u_h$ can be replaced by $Au-Au_h$ and still produce a close approximation. I've also not explained anything about obtaining a weak form of the PDE or how to choose the spaces where $N_1...N_k$ lie in.
But the whole idea behind galerkin method as a projection is that for all possible linear combinations of functions in a given (finite dimensional) space (span of $N_1$,...,$N_k$), we are looking for the one that is closest to a solution (point) which generally lies outside of the given space. Closest means that we're looking for the orthogonal projection from the true solution to the given space. If we don't know what the exact solution $u$ is, then we cannot use the absolute difference as a metric in our projection. Thus, we are forced to use the residual difference as the metric of our projection; In other words:
The galerkin projection is not about what $u$ is... it's about what $u$ satisfies.
Let's say you want to solve the Laplace equation, $-\Delta u = f$. Ideally, of course, you'd like to find a function $u$ so that the residual is zero: $r(u) = -\Delta u - f = 0$. But $u$ is an infinite dimensional object which in general we cannot represent on computers, so we have to find finite dimensional approximations $u_h$. Since $u_h$ is not the exact solution, we cannot expect that $r(u_h)=0$. The question is which set of equations we want $u_h$ to satisfy instead.
The Galerkin method chooses $u_h=\sum_i U_i \varphi_i$ to be a linear combination of $N$ shape functions $\varphi_i$ and then determines the coefficients $U_i$ by requiring the residual to satisfy the set of $N$ equations $\left<\varphi_i,r(u_h)\right>=0$.
But there are other choices that are possible. For example, the Petrov-Galerkin method requires that $\left<\psi_i,r(u_h)\right>=0$ where the test functions $\psi_i$ are a set of $N$ weighting functions separate from the trial functions $\varphi_i$.
I have a bit more material on this issue in lecture 4 at http://www.math.tamu.edu/~bangerth/videos.html .
-
$\begingroup$ It would be nice to add something about completeness of the vector space, projection onto a finite dimensional subspace, convergence and maybe positive operators. $\endgroup$– TobiasDec 1, 2014 at 9:18
-
1$\begingroup$ @Tobias: Sure, sure, but the question was about the most fundamental motivation. I didn't want to make it more complicated than necessary -- maybe one of the other answers (yours?) can add these issues. $\endgroup$ Dec 1, 2014 at 13:10
Boris Grigoryevich wants you not to be able to create residuals with the same functions you used to create the solution.
While this question is old and has been answered by plenty of smart people, I just want to jot down the intuition I use to explain the Galerkin method to people.
The goal in our situation is to find as close of a solution as we can to some continuous residual equation:
$$r(u) = 0$$.
Let us define the $i^{th}$ basis function as $\phi_{i}(x)$, define the approximate solution as $u_{h} = \sum_{i}^{n} a_{i} \phi_{i}(x)$, and define the residual as $r(u_{h}(x))$, the Galerkin projection ends up being:
$$ \int_{\Omega} r(u_{h}(x)) \phi_i(x) dx = 0 \;\;\; \forall i$$
This integral expression can be viewed as an inner product written as:
$$ \left< r(u_{h}), \phi_i\right> = 0 \;\;\; \forall i$$
From the perspective of this inner product, the Galerkin Projection forces the residual error to be orthogonal to the choice of basis functions. So while there might be true error associated with using a lower dimensional representation of the solution, the Galerkin Projection aims to minimize the error component associated with the chosen basis.
Remember that when you multiply the strong-form equation by the shape function, the shape function is arbitrary. Therefore, by requiring that the residual be orthogonal to any such shape function, such a residual is in fact very close to zero.
This is not the same as requiring that the residual be zero exactly, but rather a somewhat weakened requirement that the discrete solution can satisfy.