Salome HOME
Updated GUI documentation
[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 #include <cstring>
10
11 #include "GenericMatrix.hxx"
12 #include "CdmathException.hxx"
13
14 using namespace std;
15
16 GenericMatrix::GenericMatrix()
17 {
18         _numberOfRows = 0;
19         _numberOfColumns = 0;
20         _isSparseMatrix=false;
21 }
22
23 GenericMatrix::~GenericMatrix()
24 {
25 }
26
27 bool
28 GenericMatrix::isSparseMatrix( void ) const
29 {
30         return _isSparseMatrix;
31 }
32
33
34 int
35 GenericMatrix::getNumberOfRows() const
36 {
37         return _numberOfRows ;
38 }
39
40 int
41 GenericMatrix::getNumberOfColumns() const
42 {
43         return _numberOfColumns ;
44 }
45
46 bool
47 GenericMatrix::isSymmetric(double tol) const
48 {
49         if( ! isSquare() )
50                 throw "isSymmetric::Matrix is not square!!!";
51
52         bool res = true;
53
54         int dim = _numberOfRows;
55
56         for(int i=0; i<dim-1; i++)
57                 for(int j=i+1; j<dim; j++)
58                         if(fabs((*this)(i,j) - (*this)(j,i))> tol )
59                         {
60                                 res = false;
61                                 break;
62                         }
63         return res;
64 }
65
66 bool
67 GenericMatrix::isSquare() const
68 {
69         if(_numberOfRows == _numberOfColumns)
70                 return true;
71         return false;
72 }
73
74 void
75 GenericMatrix::view() const
76 {
77         for (int i=0; i<_numberOfRows;i++)
78         {
79                 for (int j=0;j<_numberOfColumns; j++)
80                 {
81                         cout.width(6);
82                         cout.precision(6);
83                         cout<<(*this)(i,j);
84                 }
85                 cout<<endl;
86         }
87 }