![]() |
![]() |
![]() |
In this example, we solve the Poisson equation (Laplace equation with a right-hand side) by the P1-finite element method and by using the Conjugate Gradient iterative method to solve the linear system.
#include "OFELI.h"
#include "Laplace.h"
using namespace OFELI;
int main(int argc, char *argv[])
{
Mesh ms(argv[1],true);
|
SpMatrix<double> A(ms); Vect<double> b(ms.getNbEq()), x(ms.getNbEq()), bc(ms), f(ms); f = "exp(-20*(x*x+y*y))"; bc = 0; |
MeshElements(ms) {
Laplace2DT3 eq(theElement);
eq.LHS();
eq.BodyRHS(f);
eq.updateBC(bc);
eq.ElementAssembly(A);
eq.ElementAssembly(b);
}
|
LinearSolver<double> ls(1000,1.e-8,0); int nb_it = ls.solve(A,b,x,CG_SOLVER,DIAG_PREC); cout << "Number of iterations: " << nb_it << endl; |
Vect<double> u(ms); u.insertBC(ms,x,bc); return 0; } |
![]() |
![]() |
![]() |