ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/solveur/src/matcreuse.h
Revision: 108
Committed: Tue Jun 17 13:01:28 2008 UTC (16 years, 11 months ago) by souaissa
Content type: text/plain
Original Path: magic/lib/solveur/solveur/src/matcreuse.h
File size: 3724 byte(s)
Log Message:
solveur version du 17 juin 2008

File Contents

# User Rev Content
1 souaissa 108
2     #include <vector.h>
3     #include <math.h>
4     //---------------------------------------------------------------------------
5    
6     #ifndef matcrH
7     #define matcrH
8     //---------------------------------------------------------------------------
9     #ifdef WINDOWS_VERSION
10     #ifdef BUILT_DLL_SOLVEUR
11     #define DLLPORTSOLVEUR __declspec(dllexport)
12     #else
13     #define DLLPORTSOLVEUR __declspec(dllimport)
14     #endif
15     #else
16     #define DLLPORTSOLVEUR
17     #endif
18     //class SL_CHARGE_GLOBALE_ARETE:public SL_CHARGE_GLOBALE
19    
20    
21    
22     class DLLPORTSOLVEUR MatCr {
23     public:
24     struct CRSMatrix {
25     int N ; // dimension de la matrice
26     int NNZ ; // nombre de coefficients non nuls
27     double* a ; // coefficients non nuls (tableau de taille NNZ)
28     int* col_ind ; // indices de colonnes (tableau de taille NNZ)
29     int* row_ptr ; // pointeurs de lignes (tableau de taille N+1)
30     double* diag ; // elements diagonaux (tableau de taille N)
31     } ;
32     struct Coeff {
33     Coeff() { }
34     Coeff(int j, double val) : index(j), a(val) { }
35     int index ;
36     double a ;
37     } ;
38    
39     class DLLPORTSOLVEUR Row : public std::vector<Coeff>
40     {
41     public:
42     void add(int index, double val) {
43     for(int i=0; i<size(); i++) {
44     if((*this)[i].index == index) {
45     (*this)[i].a += val ;
46     return ;
47     }
48     }
49     if(val!=0.)
50     std::vector<Coeff>::push_back(Coeff(index, val)) ;
51     }
52     double get(int j) {
53     for(int i=0; i<size(); i++) {
54     if((*this)[i].index == j)
55     return(*this)[i].a ;
56    
57     }
58     return 0.;
59     }
60     void set(int index, double val) {
61     for(int i=0; i<size(); i++) {
62     if((*this)[i].index == index) {
63     (*this)[i].a = val ;
64     return ;
65     }
66     }
67     if(val!=0.)
68     std::vector<Coeff>::push_back(Coeff(index, val)) ;
69     }
70     double row_max()
71     {
72     double max=fabs((*this)[0].a);
73     for(int i=0; i<size(); i++) {
74     if(fabs((*this)[i].a) > max) max=fabs((*this)[i].a);
75     return max;
76    
77     }
78     }
79     } ;
80    
81     MatCr(int dim) ;
82    
83     ~MatCr();
84    
85     // aij <- aij + val
86     void add(int i, int j, double val);
87     void set(int i, int j, double val);
88     double get(int i, int j) ;
89     void diag(double* tmp_diag);
90     void clear() ;
91     int nnz() const;
92     void mul(double* y, const double* x);
93     void convert_to_CRS(const MatCr& M, CRSMatrix& M_CRS,int array_base);
94     void mult(double* y, CRSMatrix* M, double* x);
95     void pcg(double* b,double*x,double eps);
96     MatCr& Get_LU(int*perm,double&d) ;
97     void Get_Solution(int*perm,const double* b,double* r1);
98     double get_max();
99     int dimension ;
100     Row* row ;
101     } ;
102    
103    
104     #endif