LORENE
matrice.h
1/*
2 * Definition of Lorene class Matrice
3 *
4 */
5
6/*
7 * Copyright (c) 1999-2001 Philippe Grandclement
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28#ifndef __MATRICE_H_
29#define __MATRICE_H_
30
31/*
32 * $Id: matrice.h,v 1.14 2014/10/13 08:52:35 j_novak Exp $
33 * $Log: matrice.h,v $
34 * Revision 1.14 2014/10/13 08:52:35 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.13 2014/10/06 15:09:40 j_novak
38 * Modified #include directives to use c++ syntax.
39 *
40 * Revision 1.12 2005/10/24 09:22:21 p_grandclement
41 * addition of annule_hard for matrices
42 *
43 * Revision 1.11 2005/09/16 12:28:16 j_novak
44 * New method del_deriv() and shorter version for set(i,j).
45 *
46 * Revision 1.10 2005/01/25 12:47:32 j_novak
47 * Added some member arithmetic and operator=(Tbl).
48 *
49 * Revision 1.9 2004/12/29 12:27:35 j_novak
50 * permute is now a Itbl* which array is sent directly to the LAPACK routines.
51 * It is now possible to solve a general system (i.e. even if the Matrice
52 * is not in a banded form).
53 *
54 * Revision 1.8 2004/08/24 09:14:40 p_grandclement
55 * Addition of some new operators, like Poisson in 2d... It now requieres the
56 * GSL library to work.
57 *
58 * Also, the way a variable change is stored by a Param_elliptic is changed and
59 * no longer uses Change_var but rather 2 Scalars. The codes using that feature
60 * will requiere some modification. (It should concern only the ones about monopoles)
61 *
62 * Revision 1.7 2004/03/22 13:12:42 j_novak
63 * Modification of comments to use doxygen instead of doc++
64 *
65 * Revision 1.6 2002/09/24 10:49:41 e_gourgoulhon
66 *
67 * Modif commentaires.
68 *
69 * Revision 1.5 2002/09/24 08:34:12 e_gourgoulhon
70 *
71 * Added member function transpose()
72 * and matrix multiplication
73 *
74 * Revision 1.4 2002/09/13 09:17:33 j_novak
75 * Modif. commentaires
76 *
77 * Revision 1.3 2002/06/17 14:05:17 j_novak
78 * friend functions are now also declared outside the class definition
79 *
80 * Revision 1.2 2002/01/03 13:18:40 j_novak
81 * Optimization: the members set(i,j) and operator(i,j) of class Matrice are
82 * now defined inline. Matrice is a friend class of Tbl.
83 *
84 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
85 * LORENE
86 *
87 * Revision 2.12 1999/11/30 17:45:28 phil
88 * changement de prototypage
89 *
90 * Revision 2.11 1999/10/25 08:02:11 eric
91 * Changements commentaires.
92 *
93 * Revision 2.10 1999/10/12 16:04:06 phil
94 * Doc
95 *
96 * Revision 2.9 1999/10/12 15:59:09 phil
97 * Documentation
98 *
99 * Revision 2.8 1999/10/12 09:42:07 phil
100 * retour
101 *
102 * Revision 2.7 1999/10/12 09:39:38 phil
103 * passage en const
104 *
105 * Revision 2.6 1999/10/11 09:35:40 phil
106 * changement prototypage arithmetique
107 *
108 * Revision 2.5 1999/10/05 17:02:32 phil
109 * ajout de determinant et val_propre
110 *
111 * Revision 2.4 1999/09/20 11:25:25 phil
112 * passage en Doc++
113 *
114 * Revision 2.3 1999/09/20 11:18:53 phil
115 * *** empty log message ***
116 *
117 * Revision 2.2 1999/04/13 13:56:11 phil
118 * suppression de proto.h
119 *
120 * Revision 2.1 1999/04/07 14:53:38 phil
121 * Changement de prototypage
122 *
123 * Revision 2.0 1999/04/07 14:03:59 phil
124 * *** empty log message ***
125 *
126 *
127 * $Header: /cvsroot/Lorene/C++/Include/matrice.h,v 1.14 2014/10/13 08:52:35 j_novak Exp $
128 *
129 */
130
131//fichiers includes
132#include <cstdio>
133
134#include "type_parite.h"
135#include "tbl.h"
136#include "itbl.h"
137
138namespace Lorene {
152class Matrice {
153 //Elements
154 private:
155
156 int etat ;
157
159
160
161 mutable int ku ;
162 mutable int kl ;
163
170 mutable Tbl* band ;
171
172
173 mutable Tbl* lu ;
174 mutable Itbl* permute ;
175
176 // Constructeurs destructeurs
177 public:
184 Matrice (int size1, int size2 ) ;
185
186 Matrice (const Matrice& ) ;
187
196 Matrice (const Tbl& tab) ;
197
198 ~Matrice() ;
199
200 //Gestion memoire
206 private:
207 void del_t() ;
208 void del_deriv() ;
209
210 // manipulation des etats
211 public:
213 int get_etat() const { return etat ; };
214
220 void set_etat_qcq() ;
221
227 void set_etat_zero() ;
228
233 void set_etat_nondef() ;
234
239 void annule_hard() ;
240
241
242 public:
248 int get_dim(int i) const ;
249
251 Tbl get_array() const {return *std; } ;
252
253 // affectation
254 public:
259 void operator=(double x) ;
260
261 void operator=(const Matrice& ) ;
262 void operator=(const Tbl& ) ;
263
264 //Impression
265 friend ostream& operator<<(ostream& , const Matrice& ) ;
266
267 // extraction d'un element :
268 public:
277 double& set(int j, int i) {
278 assert (etat == ETATQCQ) ;
279 assert ((i>=0) && (i<std->dim.dim[0])) ;
280 assert( (j>=0) && (j<std->dim.dim[1]) ) ;
281 if ( (band != 0x0) || (lu != 0x0) ) del_deriv() ;
282 return std->t[std->dim.dim[0] * j + i] ;
283 } ;
284
290 double operator()(int j , int i) const {
291 assert(etat != ETATNONDEF) ;
292 assert( (i>=0) && (i<std->dim.dim[0]) ) ;
293 assert( (j>=0) && (j<std->dim.dim[1]) ) ;
294 if (etat == ETATZERO) {
295 double zero = 0. ;
296 return zero ;
297 }
298 else return std->t[std->dim.dim[0] * j + i] ;
299 };
300
301 // Passage matrice a bande
309 void set_band (int up, int low) const ;
310
311 // Decomposition LU
316 void set_lu () const ;
317
318 // Inversion de la matrice
325 Tbl inverse (const Tbl& sec_membre) const ;
326
327 // Les valeurs propres :
334 Tbl val_propre() const ;
339 Matrice vect_propre() const ;
340
345 double determinant() const ;
346
350 Matrice transpose() const ;
351
352
353 // Member arithmetics
354 // ------------------
355 public:
357 void operator+=(const Matrice &) ;
358 void operator+=(double) ;
360 void operator-=(const Matrice &) ;
361 void operator-=(double) ;
362 void operator*=(double) ;
363 void operator/=(double) ;
364
365 // Operateurs amis
366 friend Matrice operator+ (const Matrice&, const Matrice& ) ;
367 friend Matrice operator- (const Matrice&, const Matrice& ) ;
368 friend Matrice operator* (const Matrice&, double ) ;
369 friend Matrice operator* (double, const Matrice& ) ;
370 friend Matrice operator* (const Matrice&, const Matrice& ) ;
371 friend Matrice operator/ (const Matrice&, double ) ;
372} ;
373ostream& operator<<(ostream& , const Matrice& ) ;
374
380Matrice operator+ (const Matrice&, const Matrice& ) ;
381Matrice operator- (const Matrice&, const Matrice& ) ;
382Matrice operator* (const Matrice&, double ) ;
383Matrice operator* (double, const Matrice& ) ;
384Matrice operator* (const Matrice&, const Matrice& ) ;
385Matrice operator/ (const Matrice&, double ) ;
386
389}
390#endif
int * dim
Array of dimensions (size: ndim).
Definition dim_tbl.h:102
Basic integer array class.
Definition itbl.h:122
Matrix handling.
Definition matrice.h:152
friend ostream & operator<<(ostream &, const Matrice &)
Display.
Definition matrice.C:330
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition matrice.C:175
void operator=(double x)
Sets all the element of *std to x.
Definition matrice.C:265
void operator+=(const Matrice &)
Addition of a Matrice to this.
Definition matrice.C:602
Tbl val_propre() const
Returns the eigenvalues of the matrix, calculated using LAPACK.
Definition matrice.C:457
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition matrice.C:181
int ku
Number of upper-diagonals in the band representation.
Definition matrice.h:161
double & set(int j, int i)
Read/write of a particuliar element.
Definition matrice.h:277
~Matrice()
Destructor.
Definition matrice.C:255
int get_etat() const
Returns the logical state.
Definition matrice.h:213
int kl
Number of lower-diagonals in the band representation.
Definition matrice.h:162
void operator/=(double)
Division of this by a double.
Definition matrice.C:627
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined state).
Definition matrice.C:187
Tbl get_array() const
Returns the array of matrix elements.
Definition matrice.h:251
Tbl inverse(const Tbl &sec_membre) const
Solves the linear system represented by the matrix.
Definition matrice.C:424
friend Matrice operator+(const Matrice &, const Matrice &)
Matrice + Matrice
Definition matrice.C:634
Itbl * permute
Pointer on the second array of the LU-representation.
Definition matrice.h:174
Tbl * band
Pointer on the array of the band representation of a square matrix.
Definition matrice.h:170
friend Matrice operator-(const Matrice &, const Matrice &)
Matrice - Matrice
Definition matrice.C:640
Tbl * lu
Pointer on the first array of the LU-representation.
Definition matrice.h:173
void annule_hard()
Sets the logical state to ETATQCQ (undefined state).
Definition matrice.C:193
void del_t()
Logical destructor : dellocates the memory of the various used representations.
Definition matrice.C:156
double determinant() const
Computes the determinant of the matrix, using LAPACK and the standard decomposition.
Definition matrice.C:560
int get_dim(int i) const
Returns the dimension of the matrix.
Definition matrice.C:260
double operator()(int j, int i) const
Read-only of a particuliar element.
Definition matrice.h:290
friend Matrice operator/(const Matrice &, double)
Matrice / double
Definition matrice.C:693
Tbl * std
Pointer on the array of the standard representation.
Definition matrice.h:158
Matrice transpose() const
Computes the transpose matrix.
Definition matrice.C:578
void del_deriv()
Deletes the (mutable) derived members: band, lu, permute.
Definition matrice.C:164
void set_band(int up, int low) const
Calculate the band storage of *std.
Definition matrice.C:364
void operator*=(double)
Multiplication of this by a double.
Definition matrice.C:622
int etat
logical state (ETATZERO, ETATQCQ or ETATNONDEF)
Definition matrice.h:156
void operator-=(const Matrice &)
Subtraction of a Matrice to this.
Definition matrice.C:607
void set_lu() const
Calculate the LU-representation, assuming the band-storage has been done.
Definition matrice.C:392
friend Matrice operator*(const Matrice &, double)
Matrice * double
Definition matrice.C:646
Matrice vect_propre() const
Returns the eigenvectors of the matrix, calculated using LAPACK.
Definition matrice.C:507
Basic array class.
Definition tbl.h:161
Dim_tbl dim
Number of dimensions, size,...
Definition tbl.h:172
double * t
The array of double.
Definition tbl.h:173
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Cmp operator-(const Cmp &)
- Cmp
Definition cmp_arithm.C:108
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition cmp_arithm.C:457
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:104
Lorene prototypes.
Definition app_hor.h:64