Lesson 2: A 2-D steady state diffusion code

We consider here a 2-D steady state boundary value problem. We solve a Poisson equation (Diffusion) with "simple" data. Concerning boundary conditions, we impose a Dirichlet (essential) boundary condition on a portion of the domain and a homogeneous Neumann (natural) condition on the remaining boundary. Note that owing to the variational formulation the Neumann condition is implicit (We have nothing to do for it).

The Finite Element Code

Here is a description of the source code. The source file can be found Example 2 in the examples directory

A finite element mesh

To test this program we use a finite element mesh of a rectangle [0,3]x[0,1]. The imposed boundary conditions are

   u(x,0)=0, u(x,1)=1, 0<x<3

Homogeneous Neumann boundary conditions are "imposed" on the portions x=0 and x=3. The solution is then


The mesh file is test.m. Note, in this file, that a code equal to 1 is associated to nodes with y=0 and y=1.

You can now execute the code to obtain the exact solution.

Copyright © 1998-2016 Rachid Touzani