matrice.h
/*
* Definition of Lorene class Matrice
*
*/
/*
* Copyright (c) 1999-2001 Philippe Grandclement
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __MATRICE_H_
#define __MATRICE_H_
/*
* $Id: matrice.h,v 1.14 2014/10/13 08:52:35 j_novak Exp $
* $Log: matrice.h,v $
* Revision 1.14 2014/10/13 08:52:35 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.13 2014/10/06 15:09:40 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.12 2005/10/24 09:22:21 p_grandclement
* addition of annule_hard for matrices
*
* Revision 1.11 2005/09/16 12:28:16 j_novak
* New method del_deriv() and shorter version for set(i,j).
*
* Revision 1.10 2005/01/25 12:47:32 j_novak
* Added some member arithmetic and operator=(Tbl).
*
* Revision 1.9 2004/12/29 12:27:35 j_novak
* permute is now a Itbl* which array is sent directly to the LAPACK routines.
* It is now possible to solve a general system (i.e. even if the Matrice
* is not in a banded form).
*
* Revision 1.8 2004/08/24 09:14:40 p_grandclement
* Addition of some new operators, like Poisson in 2d... It now requieres the
* GSL library to work.
*
* Also, the way a variable change is stored by a Param_elliptic is changed and
* no longer uses Change_var but rather 2 Scalars. The codes using that feature
* will requiere some modification. (It should concern only the ones about monopoles)
*
* Revision 1.7 2004/03/22 13:12:42 j_novak
* Modification of comments to use doxygen instead of doc++
*
* Revision 1.6 2002/09/24 10:49:41 e_gourgoulhon
*
* Modif commentaires.
*
* Revision 1.5 2002/09/24 08:34:12 e_gourgoulhon
*
* Added member function transpose()
* and matrix multiplication
*
* Revision 1.4 2002/09/13 09:17:33 j_novak
* Modif. commentaires
*
* Revision 1.3 2002/06/17 14:05:17 j_novak
* friend functions are now also declared outside the class definition
*
* Revision 1.2 2002/01/03 13:18:40 j_novak
* Optimization: the members set(i,j) and operator(i,j) of class Matrice are
* now defined inline. Matrice is a friend class of Tbl.
*
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
* LORENE
*
* Revision 2.12 1999/11/30 17:45:28 phil
* changement de prototypage
*
* Revision 2.11 1999/10/25 08:02:11 eric
* Changements commentaires.
*
* Revision 2.10 1999/10/12 16:04:06 phil
* Doc
*
* Revision 2.9 1999/10/12 15:59:09 phil
* Documentation
*
* Revision 2.8 1999/10/12 09:42:07 phil
* retour
*
* Revision 2.7 1999/10/12 09:39:38 phil
* passage en const
*
* Revision 2.6 1999/10/11 09:35:40 phil
* changement prototypage arithmetique
*
* Revision 2.5 1999/10/05 17:02:32 phil
* ajout de determinant et val_propre
*
* Revision 2.4 1999/09/20 11:25:25 phil
* passage en Doc++
*
* Revision 2.3 1999/09/20 11:18:53 phil
* *** empty log message ***
*
* Revision 2.2 1999/04/13 13:56:11 phil
* suppression de proto.h
*
* Revision 2.1 1999/04/07 14:53:38 phil
* Changement de prototypage
*
* Revision 2.0 1999/04/07 14:03:59 phil
* *** empty log message ***
*
*
* $Header: /cvsroot/Lorene/C++/Include/matrice.h,v 1.14 2014/10/13 08:52:35 j_novak Exp $
*
*/
//fichiers includes
#include <cstdio>
#include "type_parite.h"
#include "tbl.h"
#include "itbl.h"
namespace Lorene {
class Matrice {
//Elements
private:
int etat ;
Tbl* std ;
mutable int ku ;
mutable int kl ;
mutable Tbl* band ;
mutable Tbl* lu ;
mutable Itbl* permute ;
// Constructeurs destructeurs
public:
Matrice (int size1, int size2 ) ;
Matrice (const Matrice& ) ;
Matrice (const Tbl& tab) ;
~Matrice() ;
//Gestion memoire
private:
void del_t() ;
void del_deriv() ;
// manipulation des etats
public:
int get_etat() const { return etat ; };
void set_etat_qcq() ;
void set_etat_zero() ;
void set_etat_nondef() ;
void annule_hard() ;
public:
int get_dim(int i) const ;
Tbl get_array() const {return *std; } ;
// affectation
public:
void operator=(double x) ;
void operator=(const Matrice& ) ;
void operator=(const Tbl& ) ;
//Impression
friend ostream& operator<<(ostream& , const Matrice& ) ;
// extraction d'un element :
public:
double& set(int j, int i) {
assert (etat == ETATQCQ) ;
assert ((i>=0) && (i<std->dim.dim[0])) ;
assert( (j>=0) && (j<std->dim.dim[1]) ) ;
if ( (band != 0x0) || (lu != 0x0) ) del_deriv() ;
return std->t[std->dim.dim[0] * j + i] ;
} ;
double operator()(int j , int i) const {
assert(etat != ETATNONDEF) ;
assert( (i>=0) && (i<std->dim.dim[0]) ) ;
assert( (j>=0) && (j<std->dim.dim[1]) ) ;
if (etat == ETATZERO) {
double zero = 0. ;
return zero ;
}
else return std->t[std->dim.dim[0] * j + i] ;
};
// Passage matrice a bande
void set_band (int up, int low) const ;
// Decomposition LU
void set_lu () const ;
// Inversion de la matrice
Tbl inverse (const Tbl& sec_membre) const ;
// Les valeurs propres :
Tbl val_propre() const ;
Matrice vect_propre() const ;
double determinant() const ;
Matrice transpose() const ;
// Member arithmetics
// ------------------
public:
void operator+=(const Matrice &) ;
void operator+=(double) ;
void operator-=(const Matrice &) ;
void operator-=(double) ;
void operator*=(double) ;
void operator/=(double) ;
// Operateurs amis
friend Matrice operator+ (const Matrice&, const Matrice& ) ;
friend Matrice operator- (const Matrice&, const Matrice& ) ;
friend Matrice operator* (const Matrice&, double ) ;
friend Matrice operator* (double, const Matrice& ) ;
friend Matrice operator* (const Matrice&, const Matrice& ) ;
friend Matrice operator/ (const Matrice&, double ) ;
} ;
ostream& operator<<(ostream& , const Matrice& ) ;
Matrice operator+ (const Matrice&, const Matrice& ) ;
Matrice operator- (const Matrice&, const Matrice& ) ;
Matrice operator* (const Matrice&, double ) ;
Matrice operator* (double, const Matrice& ) ;
Matrice operator* (const Matrice&, const Matrice& ) ;
Matrice operator/ (const Matrice&, double ) ;
}
#endif
Lorene::Itbl
Basic integer array class.
Definition itbl.h:122
Lorene::Matrice
Matrix handling.
Definition matrice.h:152
Lorene::Matrice::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition matrice.C:175
Lorene::Matrice::operator=
void operator=(double x)
Sets all the element of *std to x.
Definition matrice.C:265
Lorene::Matrice::operator+=
void operator+=(const Matrice &)
Addition of a Matrice to this.
Definition matrice.C:602
Lorene::Matrice::val_propre
Tbl val_propre() const
Returns the eigenvalues of the matrix, calculated using LAPACK.
Definition matrice.C:457
Lorene::Matrice::operator*
friend Matrice operator*(const Matrice &, double)
Matrice * double
Definition matrice.C:646
Lorene::Matrice::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition matrice.C:181
Lorene::Matrice::ku
int ku
Number of upper-diagonals in the band representation.
Definition matrice.h:161
Lorene::Matrice::set
double & set(int j, int i)
Read/write of a particuliar element.
Definition matrice.h:277
Lorene::Matrice::~Matrice
~Matrice()
Destructor.
Definition matrice.C:255
Lorene::Matrice::get_etat
int get_etat() const
Returns the logical state.
Definition matrice.h:213
Lorene::Matrice::kl
int kl
Number of lower-diagonals in the band representation.
Definition matrice.h:162
Lorene::Matrice::operator/=
void operator/=(double)
Division of this by a double.
Definition matrice.C:627
Lorene::Matrice::set_etat_nondef
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined state).
Definition matrice.C:187
Lorene::Matrice::get_array
Tbl get_array() const
Returns the array of matrix elements.
Definition matrice.h:251
Lorene::Matrice::inverse
Tbl inverse(const Tbl &sec_membre) const
Solves the linear system represented by the matrix.
Definition matrice.C:424
Lorene::Matrice::permute
Itbl * permute
Pointer on the second array of the LU-representation.
Definition matrice.h:174
Lorene::Matrice::band
Tbl * band
Pointer on the array of the band representation of a square matrix.
Definition matrice.h:170
Lorene::Matrice::lu
Tbl * lu
Pointer on the first array of the LU-representation.
Definition matrice.h:173
Lorene::Matrice::annule_hard
void annule_hard()
Sets the logical state to ETATQCQ (undefined state).
Definition matrice.C:193
Lorene::Matrice::operator-
friend Matrice operator-(const Matrice &, const Matrice &)
Matrice - Matrice
Definition matrice.C:640
Lorene::Matrice::del_t
void del_t()
Logical destructor : dellocates the memory of the various used representations.
Definition matrice.C:156
Lorene::Matrice::determinant
double determinant() const
Computes the determinant of the matrix, using LAPACK and the standard decomposition.
Definition matrice.C:560
Lorene::Matrice::get_dim
int get_dim(int i) const
Returns the dimension of the matrix.
Definition matrice.C:260
Lorene::Matrice::operator()
double operator()(int j, int i) const
Read-only of a particuliar element.
Definition matrice.h:290
Lorene::Matrice::std
Tbl * std
Pointer on the array of the standard representation.
Definition matrice.h:158
Lorene::Matrice::operator+
friend Matrice operator+(const Matrice &, const Matrice &)
Matrice + Matrice
Definition matrice.C:634
Lorene::Matrice::transpose
Matrice transpose() const
Computes the transpose matrix.
Definition matrice.C:578
Lorene::Matrice::operator/
friend Matrice operator/(const Matrice &, double)
Matrice / double
Definition matrice.C:693
Lorene::Matrice::del_deriv
void del_deriv()
Deletes the (mutable) derived members: band, lu, permute.
Definition matrice.C:164
Lorene::Matrice::set_band
void set_band(int up, int low) const
Calculate the band storage of *std.
Definition matrice.C:364
Lorene::Matrice::operator*=
void operator*=(double)
Multiplication of this by a double.
Definition matrice.C:622
Lorene::Matrice::etat
int etat
logical state (ETATZERO, ETATQCQ or ETATNONDEF)
Definition matrice.h:156
Lorene::Matrice::operator-=
void operator-=(const Matrice &)
Subtraction of a Matrice to this.
Definition matrice.C:607
Lorene::Matrice::Matrice
Matrice(int size1, int size2)
Standard constructor.
Definition matrice.C:203
Lorene::Matrice::operator<<
friend ostream & operator<<(ostream &, const Matrice &)
Display.
Definition matrice.C:330
Lorene::Matrice::set_lu
void set_lu() const
Calculate the LU-representation, assuming the band-storage has been done.
Definition matrice.C:392
Lorene::Matrice::vect_propre
Matrice vect_propre() const
Returns the eigenvectors of the matrix, calculated using LAPACK.
Definition matrice.C:507
Lorene::Tbl
Basic array class.
Definition tbl.h:161
Lorene::operator*
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Definition base_val_mult.C:102
Lorene::operator-
Cmp operator-(const Cmp &)
- Cmp
Definition cmp_arithm.C:108
Lorene::operator/
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition cmp_arithm.C:457
Lorene::operator+
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:104
Lorene
Lorene prototypes.
Definition app_hor.h:64
Lorene::x
Coord x
x coordinate centered on the grid
Definition map.h:726