![]() |
![]() |
![]() |
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 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
You can now execute the code to obtain the exact solution.
#include "OFELI.h"
#include "Therm.h"
using namespace OFELI;
int main(int argc, char *argv[])
{
Mesh ms;
Element *el;
banner();
if (argc <= 1) {
cout << " Usage : ex2 <mesh_file>" << endl;
exit(1);
}
ms.Get(argv[1]);
SkSMatrix<double> a(ms);
Vect<double> b(ms.getNbDOF());
Vect<double> bc(ms.getNbDOF());
void BC(const Mesh &ms, Vect<double> &bc);
BC(ms,bc);
for (ms.topElement(); (el=ms.getElement());) {
DC2DT3 eq(el);
eq.Diffusion();
a.Assembly(el,eq.A());
b.Assembly(el,eq.b());
}
Of course, in the present case, assembling the right-hand side is actually useless.
a.Prescribe(ms,b,bc);
a.Factor();
a.Solve(b);
Vector b contains now the solution.
cout << "\nSolution :\n" << b;
return 0;
}
void BC(const Mesh &ms, Vect<double> &bc)
{
const Node *nd;
for (ms.topNode(); (nd=ms.getNode());) {
if (nd->getCode(1)==2)
bc(nd->getLabel()) = 1.;
}
}
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
u(x,y)=y
The mesh file is ex2.m. Note, in this file, that a code equal to
0 is associated to nodes with y=0 and 1
is associated to nodes with y=1. The line starting with BC
gives the associated value to the code 1, the case of value 0 is by default.


