![]() |
![]() |
![]() |
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
#include "OFELI.h"
#include "Therm.h"
using namespace OFELI;
int main(int argc, char *argv[]) { |
banner(); if (argc <= 1) { cout << " Usage: lesson2 <mesh_file>" << endl; exit(1); } |
Mesh ms(argv[1]); |
SkSMatrix<double> A(ms); |
Vect<double> b(ms), bc(ms); |
bc.setNodeBC(ms,1,"y"); |
for (ms.topElement(); (theElement=ms.getElement());)For each element, we construct an instance of class DC2DT3 for diffusion-convection problems in 2-D using 3-node triangles. The member function Diffusion calculates the contribution to element matrix of diffusion term. We then assemble matrix and right-hand side (which is 0 here).
MeshElements(ms) { DC2DT3 eq(theElement); eq.Diffusion(); eq.ElementAssembly(A); eq.ElementAssembly(b); } |
Of course, in the present case, assembling the right-hand side is useless.
A.Prescribe(ms,b,bc); |
A.FactorAndSolve(b); |
Vector b contains now the solution.
cout << "\nSolution :\n" << b; return 0; } |
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
u(x,y)=yThe 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.
![]() |
![]() |
![]() |