1
// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
3
// See the LICENSE.txt file for license information. Please report all
4
// bugs and problems to <gmsh@geuz.org>.
6
#ifndef _LINEAR_SYSTEM_CSR_H_
7
#define _LINEAR_SYSTEM_CSR_H_
10
#include "GmshConfig.h"
11
#include "GmshMessage.h"
12
#include "linearSystem.h"
14
typedef int INDEX_TYPE ;
24
void CSRList_Add(CSRList_T *liste, void *data);
25
int CSRList_Nbr(CSRList_T *liste);
27
template <class scalar>
28
class linearSystemCSR : public linearSystem<scalar> {
32
CSRList_T *a_,*ai_,*ptr_,*jptr_;
33
std::vector<scalar> *_b, *_x;
36
: sorted(false), a_(0) {}
37
virtual bool isAllocated() const { return a_ != 0; }
38
virtual void allocate(int) ;
43
virtual ~linearSystemCSR()
47
virtual void addToMatrix ( int il, int ic, double val)
51
INDEX_TYPE *jptr = (INDEX_TYPE*) jptr_->array;
52
INDEX_TYPE *ptr = (INDEX_TYPE*) ptr_->array;
53
INDEX_TYPE *ai = (INDEX_TYPE*) ai_->array;
54
scalar *a = ( scalar * ) a_->array;
56
INDEX_TYPE position_ = jptr[il];
60
if(ai[position_] == ic){
62
// if (il == 0) printf("FOUND %d %d %d\n",il,ic,position_);
65
if (ptr[position_] == 0)break;
66
position_ = ptr[position_];
71
CSRList_Add (a_, &val);
72
CSRList_Add (ai_, &ic);
73
CSRList_Add (ptr_, &zero);
74
// The pointers may have been modified
75
// if there has been a reallocation in CSRList_Add
77
ptr = (INDEX_TYPE*) ptr_->array;
78
ai = (INDEX_TYPE*) ai_->array;
79
a = (scalar*) a_->array;
81
INDEX_TYPE n = CSRList_Nbr(a_) - 1;
87
else ptr[position_] = n;
90
virtual scalar getFromMatrix (int _row, int _col) const
94
virtual void addToRightHandSide(int _row, scalar _val)
96
if(_val != 0.0) (*_b)[_row] += _val;
98
virtual scalar getFromRightHandSide(int _row) const
102
virtual scalar getFromSolution(int _row) const
106
virtual void zeroMatrix()
108
int N=CSRList_Nbr(a_);
109
scalar *a = (scalar*) a_->array;
110
for (int i=0;i<N;i++)a[i]=0;
112
virtual void zeroRightHandSide()
114
for(unsigned int i = 0; i < _b->size(); i++) (*_b)[i] = 0.;
118
template <class scalar>
119
class linearSystemCSRGmm : public linearSystemCSR<scalar> {
125
: _prec(1.e-8), _noisy(0), _gmres(0) {}
126
virtual ~linearSystemCSRGmm()
128
void setPrec(double p){ _prec = p; }
129
void setNoisy(int n){ _noisy = n; }
130
void setGmres(int n){ _gmres = n; }
131
virtual int systemSolve()
132
#if defined(HAVE_GMM)
136
Msg::Error("Gmm++ is not available in this version of Gmsh");