![]() |
![]() |
![]() |
We consider the same example as in Lesson 2 with the following modifications:
The Finite Element Code A test We use here a finer mesh than in Lesson 2
except the line defining the material. We obtain the same solution
as Lesson 2 after 15 iterations.
The main program
Here is a description of the source code. The source file can be found in Example 3 in the examples directory.
#include "OFELI.h"
#include "Therm.h"
using namespace OFELI;
int main(int argc, char *argv[])
{
Mesh ms(argv[1]);
Element *el;
banner();
if (argc <= 1) {
cout << " Usage : ex3 <mesh_file>" << endl;
exit(1);
}
ms.Get(argv[1]);
ms.NumberEquations();
SpMatrix<double> a(ms);
Vect<double> b(ms.getNbEq()), x(ms.getNbEq());
Vect<double> bc(ms.getNbDOF());
for (ms.topElement(); (el=ms.getElement());) {
DC2DT3 eq(el);
eq.Diffusion();
eq.updateBC(bc);
a.Assembly(el,eq.A());
b.Assembly(el,eq.b());
}
double toler = 1.e-8;
int nb_it = CG(a,Prec<double>(a,ILU_PREC),b,x,100,toler,2);
Note that CG returns the number of performed iterations.
cout << "Nb. of iterations: " << nb_it << endl;
Vect<double> u(ms.getNbDOF());
u.insertBC(ms,x,bc);
cout << "\nSolution :\n" << u;
return 0;
}
How to declare a material ?
This is very simple: in the mesh data file, all elements have, in the present example,
the code 1. If we say nothing, then a generic material (precisely called
GenericMaterial with default properties is used. Otherwise, we can
assign, in the mesh file a material, here Aluminium to this code, by
the line
Material 1 Aluminium
This line must be given after all elements lines. Note that the file Aluminium.md
must be present in the material's directory.
We are now ready to test the package.


