A More Interesting Example

Let's solve a larger and more interesting Laplacian problem: a simple sink and a source on a rectangular grid. It can be defined with the following boundary conditions and mesh.

(a)

(b)

Figure 3. A two-dimensional Laplacian problem: (a) Problem description and (b) the FEM mesh.

The mesh in Figure 3(b) is formed by the following regular grid:

Each node in the domain has only one degree-of-freedom ; therefore it has the same index as the node number. Providing the fixed dofs and their values as below, we solve the linear system of equations:

The FEM domain is represented by a regular grid. The result can be plotted with the built-in function `ListContourPlot.`

``````Needs["Graphics`Graphics3D`"];
Needs["Graphics`Legend`"];

HueMod[h_]   := Hue[1- 0.8*h];

ShowLegend[
ListContourPlot[Partition[ans,cols],Contours->19,
ContourSmoothing->Automatic,
ColorFunction->HueMod,
DisplayFunction->Identity],
{HueMod, 10, "0", " 10",
LegendPosition->{1.1,-0.4}}];``````

Figure 4. The contour plot for the scalar field approximated by the FEM solution.