2 * SparseMatrixPetsc.hxx
4 * Created on: 03/11/2017. 2017
8 #ifndef SOURCE_DIRECTORY__BASE_INC_SparseMatrixPetsc_HXX_
9 #define SOURCE_DIRECTORY__BASE_INC_SparseMatrixPetsc_HXX_
15 #include "MEDCouplingUMesh.hxx"
22 class SparseMatrixPetsc: public GenericMatrix {
26 virtual ~SparseMatrixPetsc();
29 * constructor for a block sparse matrix
30 * @param numberOfRows : The number of rows
31 * @param numberOfColumns : The number of columns
33 SparseMatrixPetsc( int numberOfRows, int numberOfColumns ) ;
36 * constructor for a block sparse matrix with number of non zero coefficients given
37 * @param numberOfRows : The number of rows
38 * @param numberOfColumns : The number of columns
39 * @param nnz : The maximum number of nonzeros coefficients per line (or an upper bound)
41 SparseMatrixPetsc( int numberOfRows, int numberOfColumns, int nnz ) ;
44 * constructor for a sparse matrix with block structure
45 * @param blockSize : The block size
46 * @param numberOfRows : The number of rows
47 * @param numberOfColumns : The number of columns
48 * @param nnz : The maximum number of nonzeros coefficients per line (or an upper bound)
49 * @comment blockSize should always divide numberOfRows and numberOfColumns
51 SparseMatrixPetsc( int blockSize, int numberOfRows, int numberOfColumns, int nnz );
55 * @param SparseMatrixPetsc : The SparseMatrixPetsc object to be copied
57 SparseMatrixPetsc ( const SparseMatrixPetsc& sparseMatrixPetsc ) ;
60 * constructor with data
61 * @param Petsc matris : mat
63 SparseMatrixPetsc(Mat mat);
65 SparseMatrixPetsc transpose() const ;
67 double operator()( int i, int j ) const ;
69 void setValue( int i, int j, double value ) ;
70 void addValue( int i, int j, double value ) ;
72 void setValue( int i, int j, Matrix M ) ;
73 void addValue( int i, int j, Matrix M ) ;
75 void setValuesBlocked( int i, int j, Matrix M ) ;
76 void addValuesBlocked( int i, int j, Matrix M ) ;
78 SparseMatrixPetsc& operator+= (const SparseMatrixPetsc& SparseMatrixPetsc) ;
80 SparseMatrixPetsc& operator-= (const SparseMatrixPetsc& SparseMatrixPetsc) ;
82 SparseMatrixPetsc& operator*= (double value) ;
84 SparseMatrixPetsc& operator/= (double value) ;
86 SparseMatrixPetsc& operator*= (const SparseMatrixPetsc& matrix) ;
88 Vector operator* (const Vector& vector) const ;
90 const SparseMatrixPetsc& operator= ( const SparseMatrixPetsc& SparseMatrixPetsc ) ;
92 friend SparseMatrixPetsc operator+ (const SparseMatrixPetsc& SparseMatrixPetsc1, const SparseMatrixPetsc& SparseMatrixPetsc2);
94 friend SparseMatrixPetsc operator- (const SparseMatrixPetsc& SparseMatrixPetsc1, const SparseMatrixPetsc& SparseMatrixPetsc2);
96 friend SparseMatrixPetsc operator* (double value , const SparseMatrixPetsc& SparseMatrixPetsc ) ;
98 friend SparseMatrixPetsc operator* (const SparseMatrixPetsc& SparseMatrixPetsc, double value ) ;
100 friend SparseMatrixPetsc operator/ (const SparseMatrixPetsc& SparseMatrixPetsc, double value) ;
102 friend SparseMatrixPetsc operator*(const SparseMatrixPetsc& M, const SparseMatrixPetsc& N) ;
104 void viewMatrix() const ;
105 //Save matrix coefficients into a file in ascii or binary mode
106 void saveMatrix(std::string filename, bool binaryMode=false) const ;
107 double getMatrixCoeff(int i, int j) const;
109 bool containsPetscMatrix() const;
110 Mat getPetscMatrix() const;
111 //returns the array of matrix coefficients
112 std::vector< double > getArray();
114 void diagonalShift(double lambda);
115 void zeroEntries();//sets the matrix coefficients to zero
117 std::vector< double > getEigenvalues( int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const;
118 std::vector< Vector > getEigenvectors(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const;
119 MEDCoupling::DataArrayDouble * getEigenvectorsDataArrayDouble(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const;
120 std::vector< double > getSingularValues( int nsv, SVDWhich which=SVD_SMALLEST, double tol=1e-6) const;
121 std::vector< Vector > getSingularVectors(int nsv, SVDWhich which=SVD_SMALLEST, double tol=1e-6) const;
122 double getConditionNumber(bool isSingular=false, double tol=1e-6) const;
124 bool isSymmetric(double tol=1.e-6) const ;
126 void leftDiagonalScale(Vector v);
127 void rightDiagonalScale(Vector v);
132 int _numberOfNonZeros ;//The maximum number of nonzeros coefficients per line (or an upper bound)
134 int computeSpectrum(int nev, double ** valP, double ***vecP, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const;
135 int computeSVD (int nsv, double ** valS, double ***vecS, SVDWhich which=SVD_SMALLEST , double tol=1e-6) const;
137 Vector vecToVector(const Vec& vec) const ;
138 Vec vectorToVec( const Vector& myVector ) const ;
142 #endif /* SOURCE_DIRECTORY__BASE_INC_SparseMatrixPetsc_HXX_ */