6 #ifndef LINEAR_SYSTEM_GMM_H
7 #define LINEAR_SYSTEM_GMM_H
10 #include "GmshConfig.h"
16 #undef BB // can be defined by FlGui.h, and clashes with gmm arg name
22 std::vector<scalar> *_x;
23 std::vector<scalar> *_b;
24 gmm::row_matrix<gmm::wsvector<scalar> > *_a;
34 : _x(0), _b(0), _a(0), _method(method), _tol(tol), _noisy(noisy) {}
35 virtual bool isAllocated()
const {
return _a != 0; }
39 _a =
new gmm::row_matrix<gmm::wsvector<scalar> >(nbRows, nbRows);
40 _b =
new std::vector<scalar>(nbRows);
41 _x =
new std::vector<scalar>(nbRows);
53 virtual void addToMatrix(
int row,
int col,
const scalar &val)
55 if(val != 0.0) (*_a)(row, col) += val;
57 virtual void getFromMatrix(
int row,
int col, scalar &val)
const
59 val = (*_a)(row, col);
63 if(val != 0.0) (*_b)[row] += val;
71 if(val != 0.0) (*_x)[row] += val;
73 virtual void getFromSolution(
int row, scalar &val)
const { val = (*_x)[row]; }
77 for(std::size_t i = 0; i < _b->size(); i++) (*_b)[i] = 0.;
81 for(std::size_t i = 0; i < _x->size(); i++) (*_x)[i] = 0.;
87 for(std::size_t i = 0; i < _b->size(); i++) {
90 if(nor < temp) nor = temp;
94 void setPrec(
double p) { _tol = p; }
96 void setGmres(
int n) { _method = (n ?
"gmres" :
"cg"); }
99 #if defined(HAVE_MUMPS)
100 if(_method ==
"mumps"){
101 gmm::MUMPS_solve(*_a, *_x, *_b);
106 gmm::ildltt_precond<gmm::row_matrix<gmm::wsvector<scalar> > > P(*_a, 30, 1.e-10);
108 gmm::iteration iter(_tol);
109 iter.set_noisy(_noisy);
110 if(_method ==
"gmres")
111 gmm::gmres(*_a, *_x, *_b, P, 100, iter);
113 gmm::cg(*_a, *_x, *_b, P, iter);
114 if(!iter.converged())
115 Msg::Warning(
"Iterative linear solver has not converged (res = %g)",
129 Msg::Error(
"Gmm++ is not available in this version of Gmsh");