KADATH
matrice.hpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef __MATRICE_HPP_
21 #define __MATRICE_HPP_
22 //fichiers includes
23 #include "headcpp.hpp"
24 #include "array.hpp"
25 
26 namespace Kadath {
38  class Matrice : public Memory_mapped {
39  //Elements
40  private:
41 
47 
48 
49  mutable int ku ;
50  mutable int kl ;
51 
58  mutable Array<double>* band ;
59 
60 
61  mutable Array<double>* lu ;
62  mutable Array<int>* permute ;
63 
64  // Constructeurs destructeurs
65  public:
71  Matrice (int size1, int size2 ) ;
72 
73  Matrice (const Matrice& ) ;
74 
83  Matrice (const Array<double>& tab) ;
84 
85  ~Matrice() ;
86 
87  //Gestion memoire
93  private:
94  void del_deriv() ;
95 
96  public:
100  void annule() ;
101 
102  public:
108  int get_dim(int i) const {return sizes(i) ;};
110  Array<double>* get_lu() {return lu ;} ;
114  const Array<double>& get_array() const {return *std; } ;
117 
118  // affectation
119  public:
124  void operator=(double x) ;
125 
126  void operator=(const Matrice& ) ;
127  void operator=(const Array<double>& ) ;
128 
130  friend ostream& operator<<(ostream& , const Matrice& ) ;
131 
132  // extraction d'un element :
133  public:
142  double& set(int i, int j) ;
143 
147  void copy_inside (int i, int j, const Matrice& so) ;
148 
154  double operator()(int i, int j) const ;
155 
156  // Passage matrice a bande
164  void set_band (int up, int low) const ;
165 
166  // Decomposition LU
171  void set_lu () const ;
172 
173  // Inversion de la matrice
180  Array<double> solve (const Array<double>& sec_membre) const ;
181 
182  // Les valeurs propres :
189  Array<double> val_propre() const ;
194  Matrice vect_propre() const ;
195 
199  Matrice transpose() const ;
200 
201 
202  // Member arithmetics
203  // ------------------
204  public:
205  void operator+=(const Matrice &) ;
206  void operator+=(double) ;
207  void operator-=(const Matrice &) ;
208  void operator-=(double) ;
209  void operator*=(double) ;
210  void operator/=(double) ;
211 
212  // Operateurs amis
213  friend Matrice operator+ (const Matrice&, const Matrice& ) ;
214  friend Matrice operator- (const Matrice&, const Matrice& ) ;
215  friend Matrice operator- (const Matrice& ) ;
216  friend Matrice operator* (const Matrice&, double ) ;
217  friend Matrice operator* (double, const Matrice& ) ;
218  friend Matrice operator* (const Matrice&, const Matrice& ) ;
219  friend Matrice operator/ (const Matrice&, double ) ;
220  } ;
221  ostream& operator<<(ostream& , const Matrice& ) ;
222 
223 
224  Matrice operator+ (const Matrice&, const Matrice& ) ;
225  Matrice operator- (const Matrice&, const Matrice& ) ;
226  Matrice operator- (const Matrice& ) ;
227  Matrice operator* (const Matrice&, double ) ;
228  Matrice operator* (double, const Matrice& ) ;
229  Matrice operator* (const Matrice&, const Matrice& ) ;
230  Matrice operator/ (const Matrice&, double ) ;
231 
232  // Lapack routines :
233  #define F77_dswap dswap_
234  #define F77_dgbtrf dgbtrf_
235  #define F77_dgbtrs dgbtrs_
236  #define F77_dgetrf dgetrf_
237  #define F77_dgetrs dgetrs_
238  #define F77_dgeev dgeev_
239 
240  extern "C" {
241  void F77_dgbtrf(int*, int*, int*, int*, double[], int*, int[], int *) ;
242  void F77_dgbtrs(char*, int*, int*, int*, int*,
243  double[], int*, int[], double [], int*, int *) ;
244  void F77_dgetrf(int*, int*, double[], int*, int[], int *) ;
245  void F77_dgetrs(char*, int*, int*, double[], int*, int[], double [], int*, int* ) ;
246  void F77_dgeev(char*, char*, int*, double[], int*, double[], double[],
247  double[], int*, double[], int*, double[], int*, int*) ;
248  }
249 
250 }
251 #endif
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
Matrix handling.
Definition: matrice.hpp:38
void copy_inside(int i, int j, const Matrice &so)
Copies the elements of so inside the matrice, starting at the position .
Definition: matrice.cpp:130
Array< double > & get_array()
Returns the array of matrix elements non const version.
Definition: matrice.hpp:116
friend ostream & operator<<(ostream &, const Matrice &)
Impression.
Definition: matrice.cpp:152
int kl
Number of lower-diagonals in the band representation.
Definition: matrice.hpp:50
void operator/=(double)
Operator /=.
Definition: matrice.cpp:405
Array< int > * permute
Pointer on the second array of the LU-representation.
Definition: matrice.hpp:62
Dim_array sizes
Dim_array of dimension 2 containing the size of the matrix.
Definition: matrice.hpp:45
void operator-=(const Matrice &)
Operator -=.
Definition: matrice.cpp:385
Array< double > * band
Pointer on the array of the band representation of a square matrix.
Definition: matrice.hpp:58
Array< double > solve(const Array< double > &sec_membre) const
Solves the linear system represented by the matrix.
Definition: matrice.cpp:221
Array< double > val_propre() const
Returns the eigenvalues of the matrix, calculated using LAPACK.
Definition: matrice.cpp:253
Array< double > * lu
Pointer on the first array of the LU-representation.
Definition: matrice.hpp:61
Matrice transpose() const
Computes the transpose matrix.
Definition: matrice.cpp:362
double & set(int i, int j)
Read/write of a particuliar element.
Definition: matrice.cpp:122
friend Matrice operator+(const Matrice &, const Matrice &)
Operator + (binary version)
Definition: matrice.cpp:411
const Array< double > & get_array() const
Returns the array of matrix elements.
Definition: matrice.hpp:114
Matrice(int size1, int size2)
Standard constructor.
Definition: matrice.cpp:45
void operator*=(double)
Operator *=.
Definition: matrice.cpp:400
Array< double > * get_lu()
Returns a pointer on the lu decomposition.
Definition: matrice.hpp:110
friend Matrice operator-(const Matrice &, const Matrice &)
Operator - (binary version)
Definition: matrice.cpp:417
void set_band(int up, int low) const
Calculate the band storage of *std.
Definition: matrice.cpp:165
~Matrice()
Destructor.
Definition: matrice.cpp:82
Matrice vect_propre() const
Returns the eigenvectors of the matrix, calculated using LAPACK.
Definition: matrice.cpp:308
friend Matrice operator/(const Matrice &, double)
Operator/.
Definition: matrice.cpp:463
void operator=(double x)
Sets all the element of *std to x.
Definition: matrice.cpp:88
Array< double > * std
Pointer on the array of the standard representation.
Definition: matrice.hpp:46
void del_deriv()
Logical destructor : dellocates the memory of the various used representations.
Definition: matrice.cpp:27
void operator+=(const Matrice &)
Operator +=.
Definition: matrice.cpp:380
void set_lu() const
Calculate the LU-representation, assuming the band-storage has been done.
Definition: matrice.cpp:192
int ku
Number of upper-diagonals in the band representation.
Definition: matrice.hpp:49
double operator()(int i, int j) const
Read-only of a particuliar element.
Definition: matrice.cpp:144
void annule()
Sets all the coeficients of the *std to 0.
Definition: matrice.cpp:37
Array< int > * get_permute()
Returns a pointer on the permutation array.
Definition: matrice.hpp:112
int get_dim(int i) const
Returns the dimension of the matrix.
Definition: matrice.hpp:108
friend Matrice operator*(const Matrice &, double)
Operator*.
Definition: matrice.cpp:430