Salome HOME
initial project version
[tools/solverlab.git] / CDMATH / base / src / GenericMatrix.cxx
1 /*
2  * Matrix.cxx
3  *
4  *  Created on: 13 April. 2013
5  *      Authors: CDMATH
6  */
7
8 #include <math.h> 
9
10 #include "GenericMatrix.hxx"
11 #include "CdmathException.hxx"
12
13 using namespace std;
14
15 GenericMatrix::GenericMatrix()
16 {
17         _numberOfRows = 0;
18         _numberOfColumns = 0;
19         _isSparseMatrix=false;
20 }
21
22 GenericMatrix::~GenericMatrix()
23 {
24 }
25
26 bool
27 GenericMatrix::isSparseMatrix( void ) const
28 {
29         return _isSparseMatrix;
30 }
31
32
33 int
34 GenericMatrix::getNumberOfRows() const
35 {
36         return _numberOfRows ;
37 }
38
39 int
40 GenericMatrix::getNumberOfColumns() const
41 {
42         return _numberOfColumns ;
43 }
44
45 const DoubleTab&
46 GenericMatrix::getValues( void ) const
47 {
48         return _values;
49 }
50
51 //----------------------------------------------------------------------
52 DoubleTab
53 GenericMatrix::getValues()
54 //----------------------------------------------------------------------
55 {
56         return _values;
57 }
58
59 void
60 GenericMatrix::setValues(const DoubleTab& values)
61 {
62         _values=values;
63 }
64
65 bool
66 GenericMatrix::isSymmetric(double tol) const
67 {
68         if( ! isSquare() )
69                 throw "isSymmetric::Matrix is not square!!!";
70
71         bool res = true;
72
73         int dim = _numberOfRows;
74
75         for(int i=0; i<dim-1; i++)
76                 for(int j=i+1; j<dim; j++)
77                         if(fabs((*this)(i,j) - (*this)(j,i))> tol )
78                         {
79                                 res = false;
80                                 break;
81                         }
82         return res;
83 }
84
85 bool
86 GenericMatrix::isSquare() const
87 {
88         if(_numberOfRows == _numberOfColumns)
89                 return true;
90         return false;
91 }
92
93 int
94 GenericMatrix::coefficient(int index) const
95 {
96         if(! (index % 2) )
97                 return (1);
98         return (-1);
99 }
100
101 void
102 GenericMatrix::view() const
103 {
104         for (int i=0; i<_numberOfRows;i++)
105         {
106                 for (int j=0;j<_numberOfColumns; j++)
107                 {
108                         cout.width(6);
109                         cout.precision(6);
110                         cout<<(*this)(i,j);
111                 }
112                 cout<<endl;
113         }
114 }